Patch 8.2.0229

11 views
Skip to first unread message

Bram Moolenaar

unread,
Feb 7, 2020, 4:10:31 PM2/7/20
to vim...@googlegroups.com

Patch 8.2.0229
Problem: Compare instructions not tested.
Solution: Add test cases. Fix disassemble with line continuation.
Files: src/testdir/test_vim9_disassemble.vim, src/vim9execute.c,
src/vim9compile.c


*** ../vim-8.2.0228/src/testdir/test_vim9_disassemble.vim 2020-02-06 22:41:13.508061904 +0100
--- src/testdir/test_vim9_disassemble.vim 2020-02-07 22:08:20.655192974 +0100
***************
*** 20,26 ****
echo @z
enddef

! def Test_disassembleLoad()
assert_fails('disass NoFunc', 'E1061:')
assert_fails('disass NotCompiled', 'E1062:')

--- 20,26 ----
echo @z
enddef

! def Test_disassemble_load()
assert_fails('disass NoFunc', 'E1061:')
assert_fails('disass NotCompiled', 'E1062:')

***************
*** 47,53 ****
endif
enddef

! def Test_disassemblePush()
let res = execute('disass s:ScriptFuncPush')
assert_match('<SNR>\d*_ScriptFuncPush.*'
\ .. 'localbool = true.*'
--- 47,53 ----
endif
enddef

! def Test_disassemble_push()
let res = execute('disass s:ScriptFuncPush')
assert_match('<SNR>\d*_ScriptFuncPush.*'
\ .. 'localbool = true.*'
***************
*** 78,84 ****
@z = 'rv'
enddef

! def Test_disassembleStore()
let res = execute('disass s:ScriptFuncStore')
assert_match('<SNR>\d*_ScriptFuncStore.*'
\ .. 'localnr = 2.*'
--- 78,84 ----
@z = 'rv'
enddef

! def Test_disassemble_store()
let res = execute('disass s:ScriptFuncStore')
assert_match('<SNR>\d*_ScriptFuncStore.*'
\ .. 'localnr = 2.*'
***************
*** 110,116 ****
endtry
enddef

! def Test_disassembleTry()
let res = execute('disass s:ScriptFuncTry')
assert_match('<SNR>\d*_ScriptFuncTry.*'
\ .. 'try.*'
--- 110,116 ----
endtry
enddef

! def Test_disassemble_try()
let res = execute('disass s:ScriptFuncTry')
assert_match('<SNR>\d*_ScriptFuncTry.*'
\ .. 'try.*'
***************
*** 135,141 ****
let dd = #{one: 1, two: "val"}
enddef

! def Test_disassembleNew()
let res = execute('disass s:ScriptFuncNew')
assert_match('<SNR>\d*_ScriptFuncNew.*'
\ .. 'let ll = \[1, "two", 333].*'
--- 135,141 ----
let dd = #{one: 1, two: "val"}
enddef

! def Test_disassemble_new()
let res = execute('disass s:ScriptFuncNew')
assert_match('<SNR>\d*_ScriptFuncNew.*'
\ .. 'let ll = \[1, "two", 333].*'
***************
*** 167,173 ****
def s:ScriptFuncCall(): string
changenr()
char2nr("abc")
! Test_disassembleNew()
FuncWithArg(343)
ScriptFuncNew()
s:ScriptFuncNew()
--- 167,173 ----
def s:ScriptFuncCall(): string
changenr()
char2nr("abc")
! Test_disassemble_new()
FuncWithArg(343)
ScriptFuncNew()
s:ScriptFuncNew()
***************
*** 180,186 ****
return "yes"
enddef

! def Test_disassembleCall()
let res = execute('disass s:ScriptFuncCall')
assert_match('<SNR>\d\+_ScriptFuncCall.*'
\ .. 'changenr().*'
--- 180,186 ----
return "yes"
enddef

! def Test_disassemble_call()
let res = execute('disass s:ScriptFuncCall')
assert_match('<SNR>\d\+_ScriptFuncCall.*'
\ .. 'changenr().*'
***************
*** 188,195 ****
\ .. 'char2nr("abc").*'
\ .. ' PUSHS "abc".*'
\ .. ' BCALL char2nr(argc 1).*'
! \ .. 'Test_disassembleNew().*'
! \ .. ' DCALL Test_disassembleNew(argc 0).*'
\ .. 'FuncWithArg(343).*'
\ .. ' PUSHNR 343.*'
\ .. ' DCALL FuncWithArg(argc 1).*'
--- 188,195 ----
\ .. 'char2nr("abc").*'
\ .. ' PUSHS "abc".*'
\ .. ' BCALL char2nr(argc 1).*'
! \ .. 'Test_disassemble_new().*'
! \ .. ' DCALL Test_disassemble_new(argc 0).*'
\ .. 'FuncWithArg(343).*'
\ .. ' PUSHNR 343.*'
\ .. ' DCALL FuncWithArg(argc 1).*'
***************
*** 245,251 ****
endif
enddef

! def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
assert_match('HasEval.*'
--- 245,251 ----
endif
enddef

! def Test_disassemble_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
assert_match('HasEval.*'
***************
*** 284,290 ****
return F("x")
enddef

! def Test_compile_lambda()
assert_equal("XxX", WithLambda())
let instr = execute('disassemble WithLambda')
assert_match('WithLambda.*'
--- 284,290 ----
return F("x")
enddef

! def Test_disassemble_lambda()
assert_equal("XxX", WithLambda())
let instr = execute('disassemble WithLambda')
assert_match('WithLambda.*'
***************
*** 304,310 ****
return 'no'
enddef

! def Test_compile_and_or()
assert_equal("yes", AndOr(1))
assert_equal("no", AndOr(2))
assert_equal("yes", AndOr(4))
--- 304,310 ----
return 'no'
enddef

! def Test_disassemble_and_or()
assert_equal("yes", AndOr(1))
assert_equal("no", AndOr(2))
assert_equal("yes", AndOr(4))
***************
*** 334,340 ****
return res
enddef

! def Test_compile_for_loop()
assert_equal([0, 1, 2], ForLoop())
let instr = execute('disassemble ForLoop')
assert_match('ForLoop.*'
--- 334,340 ----
return res
enddef

! def Test_disassemble_for_loop()
assert_equal([0, 1, 2], ForLoop())
let instr = execute('disassemble ForLoop')
assert_match('ForLoop.*'
***************
*** 383,389 ****
endif
enddef

! def Test_computing()
let instr = execute('disassemble Computing')
assert_match('Computing.*'
\ .. 'let nr = 3.*'
--- 383,389 ----
endif
enddef

! def Test_disassemble_computing()
let instr = execute('disassemble Computing')
assert_match('Computing.*'
\ .. 'let nr = 3.*'
***************
*** 435,438 ****
--- 435,533 ----
endif
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-8.2.0228/src/vim9execute.c 2020-02-06 21:27:05.158175180 +0100
--- src/vim9execute.c 2020-02-07 21:14:29.258241394 +0100
***************
*** 1622,1627 ****
--- 1622,1628 ----
for (current = 0; current < dfunc->df_instr_count; ++current)
{
isn_T *iptr = &instr[current];
+ char *line;

while (line_idx < iptr->isn_lnum && line_idx < ufunc->uf_lines.ga_len)
{
***************
*** 1630,1636 ****
msg_puts("\n\n");
prev_current = current;
}
! msg(((char **)ufunc->uf_lines.ga_data)[line_idx++]);
}

switch (iptr->isn_type)
--- 1631,1639 ----
msg_puts("\n\n");
prev_current = current;
}
! line = ((char **)ufunc->uf_lines.ga_data)[line_idx++];
! if (line != NULL)
! msg(line);
}

switch (iptr->isn_type)
*** ../vim-8.2.0228/src/vim9compile.c 2020-02-06 22:06:49.224799080 +0100
--- src/vim9compile.c 2020-02-07 21:23:19.849004113 +0100
***************
*** 2342,2348 ****
emsg(_(e_missbrac));
return FAIL;
}
! *arg = skipwhite(*arg + 1);

if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
return FAIL;
--- 2342,2348 ----
emsg(_(e_missbrac));
return FAIL;
}
! *arg = *arg + 1;

if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL)
return FAIL;
*** ../vim-8.2.0228/src/version.c 2020-02-07 20:50:03.652182318 +0100
--- src/version.c 2020-02-07 21:14:15.274262137 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 229,
/**/

--
I wonder how much deeper the ocean would be without sponges.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages