Patch 8.2.0226
Problem: Compiling for loop not tested.
Solution: Add a test. Make variable initialization work for more types.
Files: src/testdir/test_vim9_disassemble.vim, src/vim9compile.c
*** ../vim-8.2.0225/src/testdir/test_vim9_disassemble.vim 2020-02-06
21:27:05.158175180 +0100
--- src/testdir/test_vim9_disassemble.vim 2020-02-06 22:05:53.505031943
+0100
***************
*** 325,329 ****
--- 325,361 ----
\, instr)
enddef
+ def ForLoop(): list<number>
+ let res: list<number>
+ for i in range(3)
+ res->add(i)
+ endfor
+ return res
+ enddef
+
+ def Test_compile_for_loop()
+ assert_equal([0, 1, 2], ForLoop())
+ let instr = execute('disassemble ForLoop')
+ assert_match('ForLoop.*'
+ \ .. 'let res: list<number>.*'
+ \ .. ' NEWLIST size 0.*'
+ \ .. '\d STORE $0.*'
+ \ .. 'for i in range(3).*'
+ \ .. '\d STORE -1 in $1.*'
+ \ .. '\d PUSHNR 3.*'
+ \ .. '\d BCALL range(argc 1).*'
+ \ .. '\d FOR $1 -> \d\+.*'
+ \ .. '\d STORE $2.*'
+ \ .. 'res->add(i).*'
+ \ .. '\d LOAD $0.*'
+ \ .. '\d LOAD $2.*'
+ \ .. '\d BCALL add(argc 2).*'
+ \ .. '\d DROP.*'
+ \ .. 'endfor.*'
+ \ .. '\d JUMP -> \d\+.*'
+ \ .. '\d DROP.*'
+ \, instr)
+ enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.0225/src/vim9compile.c 2020-02-06 20:39:41.485183084 +0100
--- src/vim9compile.c 2020-02-06 21:57:38.011180818 +0100
***************
*** 3427,3439 ****
else
{
// variables are always initialized
- // TODO: support more types
if (ga_grow(instr, 1) == FAIL)
goto theend;
! if (type->tt_type == VAR_STRING)
! generate_PUSHS(cctx, vim_strsave((char_u *)""));
! else
! generate_PUSHNR(cctx, 0);
}
if (oplen > 0 && *op != '=')
--- 3427,3477 ----
else
{
// variables are always initialized
if (ga_grow(instr, 1) == FAIL)
goto theend;
! switch (type->tt_type)
! {
! case VAR_BOOL:
! generate_PUSHBOOL(cctx, VVAL_FALSE);
! break;
! case VAR_SPECIAL:
! generate_PUSHSPEC(cctx, VVAL_NONE);
! break;
! case VAR_FLOAT:
! #ifdef FEAT_FLOAT
! generate_PUSHF(cctx, 0.0);
! #endif
! break;
! case VAR_STRING:
! generate_PUSHS(cctx, NULL);
! break;
! case VAR_BLOB:
! generate_PUSHBLOB(cctx, NULL);
! break;
! case VAR_FUNC:
! // generate_PUSHS(cctx, NULL); TODO
! break;
! case VAR_PARTIAL:
! // generate_PUSHS(cctx, NULL); TODO
! break;
! case VAR_LIST:
! generate_NEWLIST(cctx, 0);
! break;
! case VAR_DICT:
! generate_NEWDICT(cctx, 0);
! break;
! case VAR_JOB:
! // generate_PUSHS(cctx, NULL); TODO
! break;
! case VAR_CHANNEL:
! // generate_PUSHS(cctx, NULL); TODO
! break;
! case VAR_NUMBER:
! case VAR_UNKNOWN:
! case VAR_VOID:
! generate_PUSHNR(cctx, 0);
! break;
! }
}
if (oplen > 0 && *op != '=')
*** ../vim-8.2.0225/src/version.c 2020-02-06 21:27:05.158175180 +0100
--- src/version.c 2020-02-06 21:48:42.725537479 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 226,
/**/
--
A day without sunshine is like, well, night.
/// 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/202002062107.016L7NAD021754%40masaka.moolenaar.net.