Skip to content

Commit ff80cb6

Browse files
committed
patch 8.2.0216: several Vim9 instructions are not tested
Problem: Several Vim9 instructions are not tested. Solution: Add more tests. Fix :disassamble output. Make catch with pattern work.
1 parent a78e9c6 commit ff80cb6

4 files changed

Lines changed: 78 additions & 7 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ def s:ScriptFuncLoad(arg: string)
474474
echo @z
475475
enddef
476476

477+
def s:ScriptFuncPush()
478+
let localbool = true
479+
let localspec = v:none
480+
let localblob = 0z1234
481+
if has('float')
482+
let localfloat = 1.234
483+
endif
484+
enddef
485+
477486
def s:ScriptFuncStore()
478487
let localnr = 1
479488
localnr = 2
@@ -487,6 +496,16 @@ def s:ScriptFuncStore()
487496
@z = 'rv'
488497
enddef
489498

499+
def s:ScriptFuncTry()
500+
try
501+
echo 'yes'
502+
catch /fail/
503+
echo 'no'
504+
finally
505+
echo 'end'
506+
endtry
507+
enddef
508+
490509
def Test_disassemble()
491510
assert_fails('disass NoFunc', 'E1061:')
492511
assert_fails('disass NotCompiled', 'E1062:')
@@ -504,9 +523,22 @@ def Test_disassemble()
504523
\ .. ' LOADREG @z.*'
505524
\, res)
506525

507-
" TODO:
508-
" v:char =
509-
" s:scriptvar =
526+
res = execute('disass s:ScriptFuncPush')
527+
assert_match('<SNR>\d*_ScriptFuncPush.*'
528+
\ .. 'localbool = true.*'
529+
\ .. ' PUSH v:true.*'
530+
\ .. 'localspec = v:none.*'
531+
\ .. ' PUSH v:none.*'
532+
\ .. 'localblob = 0z1234.*'
533+
\ .. ' PUSHBLOB 0z1234.*'
534+
\, res)
535+
if has('float')
536+
assert_match('<SNR>\d*_ScriptFuncPush.*'
537+
\ .. 'localfloat = 1.234.*'
538+
\ .. ' PUSHF 1.234.*'
539+
\, res)
540+
endif
541+
510542
res = execute('disass s:ScriptFuncStore')
511543
assert_match('<SNR>\d*_ScriptFuncStore.*'
512544
\ .. 'localnr = 2.*'
@@ -526,6 +558,23 @@ def Test_disassemble()
526558
\ .. '@z = ''rv''.*'
527559
\ .. ' STOREREG @z.*'
528560
\, res)
561+
562+
res = execute('disass s:ScriptFuncTry')
563+
assert_match('<SNR>\d*_ScriptFuncTry.*'
564+
\ .. 'try.*'
565+
\ .. 'TRY catch -> \d\+, finally -> \d\+.*'
566+
\ .. 'catch /fail/.*'
567+
\ .. ' JUMP -> \d\+.*'
568+
\ .. ' PUSH v:exception.*'
569+
\ .. ' PUSHS "fail".*'
570+
\ .. ' COMPARESTRING =\~.*'
571+
\ .. ' JUMP_IF_FALSE -> \d\+.*'
572+
\ .. ' CATCH.*'
573+
\ .. 'finally.*'
574+
\ .. ' PUSHS "end".*'
575+
\ .. 'endtry.*'
576+
\ .. ' ENDTRY.*'
577+
\, res)
529578
enddef
530579

531580

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ static char *(features[]) =
742742

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
216,
745747
/**/
746748
215,
747749
/**/

src/vim9compile.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,13 +4369,33 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
43694369
}
43704370
else
43714371
{
4372+
char_u *end;
4373+
char_u *pat;
4374+
char_u *tofree = NULL;
4375+
size_t len;
4376+
43724377
// Push v:exception, push {expr} and MATCH
43734378
generate_instr_type(cctx, ISN_PUSHEXC, &t_string);
43744379

4375-
if (compile_expr1(&p, cctx) == FAIL)
4376-
return NULL;
4380+
end = skip_regexp(p + 1, *p, TRUE, &tofree);
4381+
if (*end != *p)
4382+
{
4383+
semsg(_("E1067: Separator mismatch: %s"), p);
4384+
vim_free(tofree);
4385+
return FAIL;
4386+
}
4387+
if (tofree == NULL)
4388+
len = end - (p + 1);
4389+
else
4390+
len = end - (tofree + 1);
4391+
pat = vim_strnsave(p + 1, len);
4392+
vim_free(tofree);
4393+
p += len + 2;
4394+
if (pat == NULL)
4395+
return FAIL;
4396+
if (generate_PUSHS(cctx, pat) == FAIL)
4397+
return FAIL;
43774398

4378-
// TODO: check for strings?
43794399
if (generate_COMPARE(cctx, EXPR_MATCH, FALSE) == FAIL)
43804400
return NULL;
43814401

src/vim9execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ ex_disassemble(exarg_T *eap)
17261726
char_u *tofree;
17271727

17281728
r = blob2string(iptr->isn_arg.blob, &tofree, numbuf);
1729-
smsg("%4d PUSHBLOB \"%s\"", current, r);
1729+
smsg("%4d PUSHBLOB %s", current, r);
17301730
vim_free(tofree);
17311731
}
17321732
break;

0 commit comments

Comments
 (0)