Skip to content

Commit f2460a3

Browse files
committed
patch 8.2.0229: compare instructions not tested
Problem: Compare instructions not tested. Solution: Add test cases. Fix disassemble with line continuation.
1 parent 348808f commit f2460a3

File tree

4 files changed

+116
-16
lines changed

4 files changed

+116
-16
lines changed

src/testdir/test_vim9_disassemble.vim

Lines changed: 109 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def s:ScriptFuncLoad(arg: string)
2020
echo @z
2121
enddef
2222

23-
def Test_disassembleLoad()
23+
def Test_disassemble_load()
2424
assert_fails('disass NoFunc', 'E1061:')
2525
assert_fails('disass NotCompiled', 'E1062:')
2626

@@ -47,7 +47,7 @@ def s:ScriptFuncPush()
4747
endif
4848
enddef
4949

50-
def Test_disassemblePush()
50+
def Test_disassemble_push()
5151
let res = execute('disass s:ScriptFuncPush')
5252
assert_match('<SNR>\d*_ScriptFuncPush.*'
5353
\ .. 'localbool = true.*'
@@ -78,7 +78,7 @@ def s:ScriptFuncStore()
7878
@z = 'rv'
7979
enddef
8080

81-
def Test_disassembleStore()
81+
def Test_disassemble_store()
8282
let res = execute('disass s:ScriptFuncStore')
8383
assert_match('<SNR>\d*_ScriptFuncStore.*'
8484
\ .. 'localnr = 2.*'
@@ -110,7 +110,7 @@ def s:ScriptFuncTry()
110110
endtry
111111
enddef
112112

113-
def Test_disassembleTry()
113+
def Test_disassemble_try()
114114
let res = execute('disass s:ScriptFuncTry')
115115
assert_match('<SNR>\d*_ScriptFuncTry.*'
116116
\ .. 'try.*'
@@ -135,7 +135,7 @@ def s:ScriptFuncNew()
135135
let dd = #{one: 1, two: "val"}
136136
enddef
137137

138-
def Test_disassembleNew()
138+
def Test_disassemble_new()
139139
let res = execute('disass s:ScriptFuncNew')
140140
assert_match('<SNR>\d*_ScriptFuncNew.*'
141141
\ .. 'let ll = \[1, "two", 333].*'
@@ -167,7 +167,7 @@ endfunc
167167
def s:ScriptFuncCall(): string
168168
changenr()
169169
char2nr("abc")
170-
Test_disassembleNew()
170+
Test_disassemble_new()
171171
FuncWithArg(343)
172172
ScriptFuncNew()
173173
s:ScriptFuncNew()
@@ -180,16 +180,16 @@ def s:ScriptFuncCall(): string
180180
return "yes"
181181
enddef
182182

183-
def Test_disassembleCall()
183+
def Test_disassemble_call()
184184
let res = execute('disass s:ScriptFuncCall')
185185
assert_match('<SNR>\d\+_ScriptFuncCall.*'
186186
\ .. 'changenr().*'
187187
\ .. ' BCALL changenr(argc 0).*'
188188
\ .. 'char2nr("abc").*'
189189
\ .. ' PUSHS "abc".*'
190190
\ .. ' BCALL char2nr(argc 1).*'
191-
\ .. 'Test_disassembleNew().*'
192-
\ .. ' DCALL Test_disassembleNew(argc 0).*'
191+
\ .. 'Test_disassemble_new().*'
192+
\ .. ' DCALL Test_disassemble_new(argc 0).*'
193193
\ .. 'FuncWithArg(343).*'
194194
\ .. ' PUSHNR 343.*'
195195
\ .. ' DCALL FuncWithArg(argc 1).*'
@@ -245,7 +245,7 @@ def HasSomething()
245245
endif
246246
enddef
247247

248-
def Test_compile_const_expr()
248+
def Test_disassemble_const_expr()
249249
assert_equal("\nyes", execute('call HasEval()'))
250250
let instr = execute('disassemble HasEval')
251251
assert_match('HasEval.*'
@@ -284,7 +284,7 @@ def WithLambda(): string
284284
return F("x")
285285
enddef
286286

287-
def Test_compile_lambda()
287+
def Test_disassemble_lambda()
288288
assert_equal("XxX", WithLambda())
289289
let instr = execute('disassemble WithLambda')
290290
assert_match('WithLambda.*'
@@ -304,7 +304,7 @@ def AndOr(arg): string
304304
return 'no'
305305
enddef
306306

307-
def Test_compile_and_or()
307+
def Test_disassemble_and_or()
308308
assert_equal("yes", AndOr(1))
309309
assert_equal("no", AndOr(2))
310310
assert_equal("yes", AndOr(4))
@@ -334,7 +334,7 @@ def ForLoop(): list<number>
334334
return res
335335
enddef
336336

337-
def Test_compile_for_loop()
337+
def Test_disassemble_for_loop()
338338
assert_equal([0, 1, 2], ForLoop())
339339
let instr = execute('disassemble ForLoop')
340340
assert_match('ForLoop.*'
@@ -383,7 +383,7 @@ def Computing()
383383
endif
384384
enddef
385385

386-
def Test_computing()
386+
def Test_disassemble_computing()
387387
let instr = execute('disassemble Computing')
388388
assert_match('Computing.*'
389389
\ .. 'let nr = 3.*'
@@ -435,4 +435,99 @@ def Test_computing()
435435
endif
436436
enddef
437437

438+
def Test_disassemble_compare()
439+
" TODO: COMPAREFUNC
440+
let cases = [
441+
\ ['true == false', 'COMPAREBOOL =='],
442+
\ ['true != false', 'COMPAREBOOL !='],
443+
\ ['v:none == v:null', 'COMPARESPECIAL =='],
444+
\ ['v:none != v:null', 'COMPARESPECIAL !='],
445+
\
446+
\ ['111 == 222', 'COMPARENR =='],
447+
\ ['111 != 222', 'COMPARENR !='],
448+
\ ['111 > 222', 'COMPARENR >'],
449+
\ ['111 < 222', 'COMPARENR <'],
450+
\ ['111 >= 222', 'COMPARENR >='],
451+
\ ['111 <= 222', 'COMPARENR <='],
452+
\ ['111 =~ 222', 'COMPARENR =\~'],
453+
\ ['111 !~ 222', 'COMPARENR !\~'],
454+
\
455+
\ ['"xx" == "yy"', 'COMPARESTRING =='],
456+
\ ['"xx" != "yy"', 'COMPARESTRING !='],
457+
\ ['"xx" > "yy"', 'COMPARESTRING >'],
458+
\ ['"xx" < "yy"', 'COMPARESTRING <'],
459+
\ ['"xx" >= "yy"', 'COMPARESTRING >='],
460+
\ ['"xx" <= "yy"', 'COMPARESTRING <='],
461+
\ ['"xx" =~ "yy"', 'COMPARESTRING =\~'],
462+
\ ['"xx" !~ "yy"', 'COMPARESTRING !\~'],
463+
\ ['"xx" is "yy"', 'COMPARESTRING is'],
464+
\ ['"xx" isnot "yy"', 'COMPARESTRING isnot'],
465+
\
466+
\ ['0z11 == 0z22', 'COMPAREBLOB =='],
467+
\ ['0z11 != 0z22', 'COMPAREBLOB !='],
468+
\ ['0z11 is 0z22', 'COMPAREBLOB is'],
469+
\ ['0z11 isnot 0z22', 'COMPAREBLOB isnot'],
470+
\
471+
\ ['[1,2] == [3,4]', 'COMPARELIST =='],
472+
\ ['[1,2] != [3,4]', 'COMPARELIST !='],
473+
\ ['[1,2] is [3,4]', 'COMPARELIST is'],
474+
\ ['[1,2] isnot [3,4]', 'COMPARELIST isnot'],
475+
\
476+
\ ['#{a:1} == #{x:2}', 'COMPAREDICT =='],
477+
\ ['#{a:1} != #{x:2}', 'COMPAREDICT !='],
478+
\ ['#{a:1} is #{x:2}', 'COMPAREDICT is'],
479+
\ ['#{a:1} isnot #{x:2}', 'COMPAREDICT isnot'],
480+
\
481+
\ ['{->33} == {->44}', 'COMPAREPARTIAL =='],
482+
\ ['{->33} != {->44}', 'COMPAREPARTIAL !='],
483+
\ ['{->33} is {->44}', 'COMPAREPARTIAL is'],
484+
\ ['{->33} isnot {->44}', 'COMPAREPARTIAL isnot'],
485+
\
486+
\ ['77 == g:xx', 'COMPAREANY =='],
487+
\ ['77 != g:xx', 'COMPAREANY !='],
488+
\ ['77 > g:xx', 'COMPAREANY >'],
489+
\ ['77 < g:xx', 'COMPAREANY <'],
490+
\ ['77 >= g:xx', 'COMPAREANY >='],
491+
\ ['77 <= g:xx', 'COMPAREANY <='],
492+
\ ['77 =~ g:xx', 'COMPAREANY =\~'],
493+
\ ['77 !~ g:xx', 'COMPAREANY !\~'],
494+
\ ['77 is g:xx', 'COMPAREANY is'],
495+
\ ['77 isnot g:xx', 'COMPAREANY isnot'],
496+
\ ]
497+
if has('float')
498+
cases->extend([
499+
\ ['1.1 == 2.2', 'COMPAREFLOAT =='],
500+
\ ['1.1 != 2.2', 'COMPAREFLOAT !='],
501+
\ ['1.1 > 2.2', 'COMPAREFLOAT >'],
502+
\ ['1.1 < 2.2', 'COMPAREFLOAT <'],
503+
\ ['1.1 >= 2.2', 'COMPAREFLOAT >='],
504+
\ ['1.1 <= 2.2', 'COMPAREFLOAT <='],
505+
\ ['1.1 =~ 2.2', 'COMPAREFLOAT =\~'],
506+
\ ['1.1 !~ 2.2', 'COMPAREFLOAT !\~'],
507+
\ ])
508+
endif
509+
510+
let nr = 1
511+
for case in cases
512+
writefile(['def TestCase' .. nr .. '()',
513+
\ ' if ' .. case[0],
514+
\ ' echo 42'
515+
\ ' endif',
516+
\ 'enddef'], 'Xdisassemble')
517+
source Xdisassemble
518+
let instr = execute('disassemble TestCase' .. nr)
519+
assert_match('TestCase' .. nr .. '.*'
520+
\ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*'
521+
\ .. '\d \(PUSH\|FUNCREF\).*'
522+
\ .. '\d \(PUSH\|FUNCREF\|LOADG\).*'
523+
\ .. '\d ' .. case[1] .. '.*'
524+
\ .. '\d JUMP_IF_FALSE -> \d\+.*'
525+
\, instr)
526+
527+
nr += 1
528+
endfor
529+
530+
" delete('Xdisassemble')
531+
enddef
532+
438533
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

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+
229,
745747
/**/
746748
228,
747749
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ compile_subscript(
23422342
emsg(_(e_missbrac));
23432343
return FAIL;
23442344
}
2345-
*arg = skipwhite(*arg + 1);
2345+
*arg = *arg + 1;
23462346

23472347
if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
23482348
return FAIL;

src/vim9execute.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ ex_disassemble(exarg_T *eap)
16221622
for (current = 0; current < dfunc->df_instr_count; ++current)
16231623
{
16241624
isn_T *iptr = &instr[current];
1625+
char *line;
16251626

16261627
while (line_idx < iptr->isn_lnum && line_idx < ufunc->uf_lines.ga_len)
16271628
{
@@ -1630,7 +1631,9 @@ ex_disassemble(exarg_T *eap)
16301631
msg_puts("\n\n");
16311632
prev_current = current;
16321633
}
1633-
msg(((char **)ufunc->uf_lines.ga_data)[line_idx++]);
1634+
line = ((char **)ufunc->uf_lines.ga_data)[line_idx++];
1635+
if (line != NULL)
1636+
msg(line);
16341637
}
16351638

16361639
switch (iptr->isn_type)

0 commit comments

Comments
 (0)