forked from aniani/vim
patch 8.2.0229: compare instructions not tested
Problem: Compare instructions not tested. Solution: Add test cases. Fix disassemble with line continuation.
This commit is contained in:
@@ -20,7 +20,7 @@ def s:ScriptFuncLoad(arg: string)
|
|||||||
echo @z
|
echo @z
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassembleLoad()
|
def Test_disassemble_load()
|
||||||
assert_fails('disass NoFunc', 'E1061:')
|
assert_fails('disass NoFunc', 'E1061:')
|
||||||
assert_fails('disass NotCompiled', 'E1062:')
|
assert_fails('disass NotCompiled', 'E1062:')
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ def s:ScriptFuncPush()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassemblePush()
|
def Test_disassemble_push()
|
||||||
let res = execute('disass s:ScriptFuncPush')
|
let res = execute('disass s:ScriptFuncPush')
|
||||||
assert_match('<SNR>\d*_ScriptFuncPush.*'
|
assert_match('<SNR>\d*_ScriptFuncPush.*'
|
||||||
\ .. 'localbool = true.*'
|
\ .. 'localbool = true.*'
|
||||||
@@ -78,7 +78,7 @@ def s:ScriptFuncStore()
|
|||||||
@z = 'rv'
|
@z = 'rv'
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassembleStore()
|
def Test_disassemble_store()
|
||||||
let res = execute('disass s:ScriptFuncStore')
|
let res = execute('disass s:ScriptFuncStore')
|
||||||
assert_match('<SNR>\d*_ScriptFuncStore.*'
|
assert_match('<SNR>\d*_ScriptFuncStore.*'
|
||||||
\ .. 'localnr = 2.*'
|
\ .. 'localnr = 2.*'
|
||||||
@@ -110,7 +110,7 @@ def s:ScriptFuncTry()
|
|||||||
endtry
|
endtry
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassembleTry()
|
def Test_disassemble_try()
|
||||||
let res = execute('disass s:ScriptFuncTry')
|
let res = execute('disass s:ScriptFuncTry')
|
||||||
assert_match('<SNR>\d*_ScriptFuncTry.*'
|
assert_match('<SNR>\d*_ScriptFuncTry.*'
|
||||||
\ .. 'try.*'
|
\ .. 'try.*'
|
||||||
@@ -135,7 +135,7 @@ def s:ScriptFuncNew()
|
|||||||
let dd = #{one: 1, two: "val"}
|
let dd = #{one: 1, two: "val"}
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassembleNew()
|
def Test_disassemble_new()
|
||||||
let res = execute('disass s:ScriptFuncNew')
|
let res = execute('disass s:ScriptFuncNew')
|
||||||
assert_match('<SNR>\d*_ScriptFuncNew.*'
|
assert_match('<SNR>\d*_ScriptFuncNew.*'
|
||||||
\ .. 'let ll = \[1, "two", 333].*'
|
\ .. 'let ll = \[1, "two", 333].*'
|
||||||
@@ -167,7 +167,7 @@ endfunc
|
|||||||
def s:ScriptFuncCall(): string
|
def s:ScriptFuncCall(): string
|
||||||
changenr()
|
changenr()
|
||||||
char2nr("abc")
|
char2nr("abc")
|
||||||
Test_disassembleNew()
|
Test_disassemble_new()
|
||||||
FuncWithArg(343)
|
FuncWithArg(343)
|
||||||
ScriptFuncNew()
|
ScriptFuncNew()
|
||||||
s:ScriptFuncNew()
|
s:ScriptFuncNew()
|
||||||
@@ -180,7 +180,7 @@ def s:ScriptFuncCall(): string
|
|||||||
return "yes"
|
return "yes"
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassembleCall()
|
def Test_disassemble_call()
|
||||||
let res = execute('disass s:ScriptFuncCall')
|
let res = execute('disass s:ScriptFuncCall')
|
||||||
assert_match('<SNR>\d\+_ScriptFuncCall.*'
|
assert_match('<SNR>\d\+_ScriptFuncCall.*'
|
||||||
\ .. 'changenr().*'
|
\ .. 'changenr().*'
|
||||||
@@ -188,8 +188,8 @@ def Test_disassembleCall()
|
|||||||
\ .. 'char2nr("abc").*'
|
\ .. 'char2nr("abc").*'
|
||||||
\ .. ' PUSHS "abc".*'
|
\ .. ' PUSHS "abc".*'
|
||||||
\ .. ' BCALL char2nr(argc 1).*'
|
\ .. ' BCALL char2nr(argc 1).*'
|
||||||
\ .. 'Test_disassembleNew().*'
|
\ .. 'Test_disassemble_new().*'
|
||||||
\ .. ' DCALL Test_disassembleNew(argc 0).*'
|
\ .. ' DCALL Test_disassemble_new(argc 0).*'
|
||||||
\ .. 'FuncWithArg(343).*'
|
\ .. 'FuncWithArg(343).*'
|
||||||
\ .. ' PUSHNR 343.*'
|
\ .. ' PUSHNR 343.*'
|
||||||
\ .. ' DCALL FuncWithArg(argc 1).*'
|
\ .. ' DCALL FuncWithArg(argc 1).*'
|
||||||
@@ -245,7 +245,7 @@ def HasSomething()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_compile_const_expr()
|
def Test_disassemble_const_expr()
|
||||||
assert_equal("\nyes", execute('call HasEval()'))
|
assert_equal("\nyes", execute('call HasEval()'))
|
||||||
let instr = execute('disassemble HasEval')
|
let instr = execute('disassemble HasEval')
|
||||||
assert_match('HasEval.*'
|
assert_match('HasEval.*'
|
||||||
@@ -284,7 +284,7 @@ def WithLambda(): string
|
|||||||
return F("x")
|
return F("x")
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_compile_lambda()
|
def Test_disassemble_lambda()
|
||||||
assert_equal("XxX", WithLambda())
|
assert_equal("XxX", WithLambda())
|
||||||
let instr = execute('disassemble WithLambda')
|
let instr = execute('disassemble WithLambda')
|
||||||
assert_match('WithLambda.*'
|
assert_match('WithLambda.*'
|
||||||
@@ -304,7 +304,7 @@ def AndOr(arg): string
|
|||||||
return 'no'
|
return 'no'
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_compile_and_or()
|
def Test_disassemble_and_or()
|
||||||
assert_equal("yes", AndOr(1))
|
assert_equal("yes", AndOr(1))
|
||||||
assert_equal("no", AndOr(2))
|
assert_equal("no", AndOr(2))
|
||||||
assert_equal("yes", AndOr(4))
|
assert_equal("yes", AndOr(4))
|
||||||
@@ -334,7 +334,7 @@ def ForLoop(): list<number>
|
|||||||
return res
|
return res
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_compile_for_loop()
|
def Test_disassemble_for_loop()
|
||||||
assert_equal([0, 1, 2], ForLoop())
|
assert_equal([0, 1, 2], ForLoop())
|
||||||
let instr = execute('disassemble ForLoop')
|
let instr = execute('disassemble ForLoop')
|
||||||
assert_match('ForLoop.*'
|
assert_match('ForLoop.*'
|
||||||
@@ -383,7 +383,7 @@ def Computing()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_computing()
|
def Test_disassemble_computing()
|
||||||
let instr = execute('disassemble Computing')
|
let instr = execute('disassemble Computing')
|
||||||
assert_match('Computing.*'
|
assert_match('Computing.*'
|
||||||
\ .. 'let nr = 3.*'
|
\ .. 'let nr = 3.*'
|
||||||
@@ -435,4 +435,99 @@ def Test_computing()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_disassemble_compare()
|
||||||
|
" TODO: COMPAREFUNC
|
||||||
|
let cases = [
|
||||||
|
\ ['true == false', 'COMPAREBOOL =='],
|
||||||
|
\ ['true != false', 'COMPAREBOOL !='],
|
||||||
|
\ ['v:none == v:null', 'COMPARESPECIAL =='],
|
||||||
|
\ ['v:none != v:null', 'COMPARESPECIAL !='],
|
||||||
|
\
|
||||||
|
\ ['111 == 222', 'COMPARENR =='],
|
||||||
|
\ ['111 != 222', 'COMPARENR !='],
|
||||||
|
\ ['111 > 222', 'COMPARENR >'],
|
||||||
|
\ ['111 < 222', 'COMPARENR <'],
|
||||||
|
\ ['111 >= 222', 'COMPARENR >='],
|
||||||
|
\ ['111 <= 222', 'COMPARENR <='],
|
||||||
|
\ ['111 =~ 222', 'COMPARENR =\~'],
|
||||||
|
\ ['111 !~ 222', 'COMPARENR !\~'],
|
||||||
|
\
|
||||||
|
\ ['"xx" == "yy"', 'COMPARESTRING =='],
|
||||||
|
\ ['"xx" != "yy"', 'COMPARESTRING !='],
|
||||||
|
\ ['"xx" > "yy"', 'COMPARESTRING >'],
|
||||||
|
\ ['"xx" < "yy"', 'COMPARESTRING <'],
|
||||||
|
\ ['"xx" >= "yy"', 'COMPARESTRING >='],
|
||||||
|
\ ['"xx" <= "yy"', 'COMPARESTRING <='],
|
||||||
|
\ ['"xx" =~ "yy"', 'COMPARESTRING =\~'],
|
||||||
|
\ ['"xx" !~ "yy"', 'COMPARESTRING !\~'],
|
||||||
|
\ ['"xx" is "yy"', 'COMPARESTRING is'],
|
||||||
|
\ ['"xx" isnot "yy"', 'COMPARESTRING isnot'],
|
||||||
|
\
|
||||||
|
\ ['0z11 == 0z22', 'COMPAREBLOB =='],
|
||||||
|
\ ['0z11 != 0z22', 'COMPAREBLOB !='],
|
||||||
|
\ ['0z11 is 0z22', 'COMPAREBLOB is'],
|
||||||
|
\ ['0z11 isnot 0z22', 'COMPAREBLOB isnot'],
|
||||||
|
\
|
||||||
|
\ ['[1,2] == [3,4]', 'COMPARELIST =='],
|
||||||
|
\ ['[1,2] != [3,4]', 'COMPARELIST !='],
|
||||||
|
\ ['[1,2] is [3,4]', 'COMPARELIST is'],
|
||||||
|
\ ['[1,2] isnot [3,4]', 'COMPARELIST isnot'],
|
||||||
|
\
|
||||||
|
\ ['#{a:1} == #{x:2}', 'COMPAREDICT =='],
|
||||||
|
\ ['#{a:1} != #{x:2}', 'COMPAREDICT !='],
|
||||||
|
\ ['#{a:1} is #{x:2}', 'COMPAREDICT is'],
|
||||||
|
\ ['#{a:1} isnot #{x:2}', 'COMPAREDICT isnot'],
|
||||||
|
\
|
||||||
|
\ ['{->33} == {->44}', 'COMPAREPARTIAL =='],
|
||||||
|
\ ['{->33} != {->44}', 'COMPAREPARTIAL !='],
|
||||||
|
\ ['{->33} is {->44}', 'COMPAREPARTIAL is'],
|
||||||
|
\ ['{->33} isnot {->44}', 'COMPAREPARTIAL isnot'],
|
||||||
|
\
|
||||||
|
\ ['77 == g:xx', 'COMPAREANY =='],
|
||||||
|
\ ['77 != g:xx', 'COMPAREANY !='],
|
||||||
|
\ ['77 > g:xx', 'COMPAREANY >'],
|
||||||
|
\ ['77 < g:xx', 'COMPAREANY <'],
|
||||||
|
\ ['77 >= g:xx', 'COMPAREANY >='],
|
||||||
|
\ ['77 <= g:xx', 'COMPAREANY <='],
|
||||||
|
\ ['77 =~ g:xx', 'COMPAREANY =\~'],
|
||||||
|
\ ['77 !~ g:xx', 'COMPAREANY !\~'],
|
||||||
|
\ ['77 is g:xx', 'COMPAREANY is'],
|
||||||
|
\ ['77 isnot g:xx', 'COMPAREANY isnot'],
|
||||||
|
\ ]
|
||||||
|
if has('float')
|
||||||
|
cases->extend([
|
||||||
|
\ ['1.1 == 2.2', 'COMPAREFLOAT =='],
|
||||||
|
\ ['1.1 != 2.2', 'COMPAREFLOAT !='],
|
||||||
|
\ ['1.1 > 2.2', 'COMPAREFLOAT >'],
|
||||||
|
\ ['1.1 < 2.2', 'COMPAREFLOAT <'],
|
||||||
|
\ ['1.1 >= 2.2', 'COMPAREFLOAT >='],
|
||||||
|
\ ['1.1 <= 2.2', 'COMPAREFLOAT <='],
|
||||||
|
\ ['1.1 =~ 2.2', 'COMPAREFLOAT =\~'],
|
||||||
|
\ ['1.1 !~ 2.2', 'COMPAREFLOAT !\~'],
|
||||||
|
\ ])
|
||||||
|
endif
|
||||||
|
|
||||||
|
let nr = 1
|
||||||
|
for case in cases
|
||||||
|
writefile(['def TestCase' .. nr .. '()',
|
||||||
|
\ ' if ' .. case[0],
|
||||||
|
\ ' echo 42'
|
||||||
|
\ ' endif',
|
||||||
|
\ 'enddef'], 'Xdisassemble')
|
||||||
|
source Xdisassemble
|
||||||
|
let instr = execute('disassemble TestCase' .. nr)
|
||||||
|
assert_match('TestCase' .. nr .. '.*'
|
||||||
|
\ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*'
|
||||||
|
\ .. '\d \(PUSH\|FUNCREF\).*'
|
||||||
|
\ .. '\d \(PUSH\|FUNCREF\|LOADG\).*'
|
||||||
|
\ .. '\d ' .. case[1] .. '.*'
|
||||||
|
\ .. '\d JUMP_IF_FALSE -> \d\+.*'
|
||||||
|
\, instr)
|
||||||
|
|
||||||
|
nr += 1
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" delete('Xdisassemble')
|
||||||
|
enddef
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -742,6 +742,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
229,
|
||||||
/**/
|
/**/
|
||||||
228,
|
228,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2342,7 +2342,7 @@ compile_subscript(
|
|||||||
emsg(_(e_missbrac));
|
emsg(_(e_missbrac));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
*arg = skipwhite(*arg + 1);
|
*arg = *arg + 1;
|
||||||
|
|
||||||
if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
|
if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
@@ -1622,6 +1622,7 @@ ex_disassemble(exarg_T *eap)
|
|||||||
for (current = 0; current < dfunc->df_instr_count; ++current)
|
for (current = 0; current < dfunc->df_instr_count; ++current)
|
||||||
{
|
{
|
||||||
isn_T *iptr = &instr[current];
|
isn_T *iptr = &instr[current];
|
||||||
|
char *line;
|
||||||
|
|
||||||
while (line_idx < iptr->isn_lnum && line_idx < ufunc->uf_lines.ga_len)
|
while (line_idx < iptr->isn_lnum && line_idx < ufunc->uf_lines.ga_len)
|
||||||
{
|
{
|
||||||
@@ -1630,7 +1631,9 @@ ex_disassemble(exarg_T *eap)
|
|||||||
msg_puts("\n\n");
|
msg_puts("\n\n");
|
||||||
prev_current = current;
|
prev_current = current;
|
||||||
}
|
}
|
||||||
msg(((char **)ufunc->uf_lines.ga_data)[line_idx++]);
|
line = ((char **)ufunc->uf_lines.ga_data)[line_idx++];
|
||||||
|
if (line != NULL)
|
||||||
|
msg(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (iptr->isn_type)
|
switch (iptr->isn_type)
|
||||||
|
Reference in New Issue
Block a user