Patch 8.2.0225
Problem: compiling lambda not tested yet.
Solution: Add test for lambda and funcref. Drop unused instruction arg.
Files: src/testdir/test_vim9_disassemble.vim, src/vim9.h,
src/vim9execute.c
*** ../vim-8.2.0224/src/testdir/test_vim9_disassemble.vim 2020-02-06
20:39:41.489183065 +0100
--- src/testdir/test_vim9_disassemble.vim 2020-02-06 21:22:42.634930382
+0100
***************
*** 278,282 ****
--- 278,329 ----
assert_notmatch('JUMP', instr)
enddef
+ def WithLambda(): string
+ let F = {a -> "X" .. a .. "X"}
+ return F("x")
+ enddef
+
+ def Test_compile_lambda()
+ assert_equal("XxX", WithLambda())
+ let instr = execute('disassemble WithLambda')
+ assert_match('WithLambda.*'
+ \ .. 'let F = {a -> "X" .. a .. "X"}.*'
+ \ .. ' FUNCREF <lambda>\d\+.*'
+ \ .. 'PUSHS "x".*'
+ \ .. ' LOAD $0.*'
+ \ .. ' PCALL (argc 1).*'
+ \ .. ' CHECKTYPE string stack\[-1].*'
+ \, instr)
+ enddef
+
+ def AndOr(arg): string
+ if arg == 1 && arg != 2 || arg == 4
+ return 'yes'
+ endif
+ return 'no'
+ enddef
+
+ def Test_compile_and_or()
+ assert_equal("yes", AndOr(1))
+ assert_equal("no", AndOr(2))
+ assert_equal("yes", AndOr(4))
+ let instr = execute('disassemble AndOr')
+ assert_match('AndOr.*'
+ \ .. 'if arg == 1 && arg != 2 || arg == 4.*'
+ \ .. '\d LOAD arg\[-1].*'
+ \ .. '\d PUSHNR 1.*'
+ \ .. '\d COMPAREANY ==.*'
+ \ .. '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*'
+ \ .. '\d LOAD arg\[-1].*'
+ \ .. '\d PUSHNR 2.*'
+ \ .. '\d COMPAREANY !=.*'
+ \ .. '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*'
+ \ .. '\d LOAD arg\[-1].*'
+ \ .. '\d PUSHNR 4.*'
+ \ .. '\d COMPAREANY ==.*'
+ \ .. '\d JUMP_IF_FALSE -> \d\+.*'
+ \, instr)
+ enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.0224/src/vim9.h 2020-02-02 22:24:00.624827188 +0100
--- src/vim9.h 2020-02-06 21:23:58.918724718 +0100
***************
*** 130,136 ****
typedef enum {
JUMP_ALWAYS,
- JUMP_IF_TRUE, // pop and jump if true
JUMP_IF_FALSE, // pop and jump if false
JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
--- 130,135 ----
*** ../vim-8.2.0224/src/vim9execute.c 2020-02-06 17:51:31.306336443 +0100
--- src/vim9execute.c 2020-02-06 21:24:27.954643159 +0100
***************
*** 1001,1008 ****
if (when == JUMP_IF_FALSE
|| when == JUMP_AND_KEEP_IF_FALSE)
jump = !jump;
! if (when == JUMP_IF_FALSE || when == JUMP_IF_TRUE
! || !jump)
{
// drop the value from the stack
clear_tv(tv);
--- 1001,1007 ----
if (when == JUMP_IF_FALSE
|| when == JUMP_AND_KEEP_IF_FALSE)
jump = !jump;
! if (when == JUMP_IF_FALSE || !jump)
{
// drop the value from the stack
clear_tv(tv);
***************
*** 1583,1597 ****
return ret;
}
- #define DISASSEMBLE 1
-
/*
* ":dissassemble".
*/
void
ex_disassemble(exarg_T *eap)
{
- #ifdef DISASSEMBLE
char_u *fname;
ufunc_T *ufunc;
dfunc_T *dfunc;
--- 1582,1595 ----
return ret;
}
/*
* ":dissassemble".
+ * We don't really need this at runtime, but we do have tests that require it,
+ * so always include this.
*/
void
ex_disassemble(exarg_T *eap)
{
char_u *fname;
ufunc_T *ufunc;
dfunc_T *dfunc;
***************
*** 1840,1848 ****
case JUMP_ALWAYS:
when = "JUMP";
break;
- case JUMP_IF_TRUE:
- when = "JUMP_IF_TRUE";
- break;
case JUMP_AND_KEEP_IF_TRUE:
when = "JUMP_AND_KEEP_IF_TRUE";
break;
--- 1838,1843 ----
***************
*** 1997,2003 ****
case ISN_DROP: smsg("%4d DROP", current); break;
}
}
- #endif
}
/*
--- 1992,1997 ----
*** ../vim-8.2.0224/src/version.c 2020-02-06 20:39:41.489183065 +0100
--- src/version.c 2020-02-06 21:15:06.604265225 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 225,
/**/
--
Everyone has a photographic memory. Some don't have film.
/// Bram Moolenaar -- [email protected] -- 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 ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202002062027.016KRaA2013434%40masaka.moolenaar.net.