summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testdir/test_vim9_disassemble.vim32
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c48
3 files changed, 77 insertions, 5 deletions
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 20ad602f4..d9a2ad455 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -325,5 +325,37 @@ def Test_compile_and_or()
\, 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
diff --git a/src/version.c b/src/version.c
index 9b5682c1d..4b03add2a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 226,
+/**/
225,
/**/
224,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 1c76c8adb..0c72168f1 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3427,13 +3427,51 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
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);
+ 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 != '=')