• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisão846fbbacce3a4535b95d9557bcc580be12f327fa (tree)
Hora2020-04-01 06:15:04
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Mensagem de Log

patch 8.2.0487: Vim9: compiling not sufficiently tested

Commit: https://github.com/vim/vim/commit/bd5da371aafe5a2207065643502f4d1ff6b286c7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 31 23:13:10 2020 +0200

patch 8.2.0487: Vim9: compiling not sufficiently tested
Problem: Vim9: compiling not sufficiently tested.
Solution: Add more tests. Fix bug with PCALL.

Mudança Sumário

Diff

diff -r e517915a786d -r 846fbbacce3a src/testdir/test_vim9_disassemble.vim
--- a/src/testdir/test_vim9_disassemble.vim Mon Mar 30 23:00:05 2020 +0200
+++ b/src/testdir/test_vim9_disassemble.vim Tue Mar 31 23:15:04 2020 +0200
@@ -224,6 +224,31 @@
224224 enddef
225225
226226
227+def EchoArg(arg: string): string
228+ return arg
229+enddef
230+def RefThis(): func
231+ return function('EchoArg')
232+enddef
233+def s:ScriptPCall()
234+ RefThis()("text")
235+enddef
236+
237+def Test_disassemble_pcall()
238+ let res = execute('disass s:ScriptPCall')
239+ assert_match('<SNR>\d\+_ScriptPCall.*'
240+ \ .. 'RefThis()("text").*'
241+ \ .. '\d DCALL RefThis(argc 0).*'
242+ \ .. '\d PUSHS "text".*'
243+ \ .. '\d PCALL top (argc 1).*'
244+ \ .. '\d PCALL end.*'
245+ \ .. '\d DROP.*'
246+ \ .. '\d PUSHNR 0.*'
247+ \ .. '\d RETURN.*'
248+ \, res)
249+enddef
250+
251+
227252 def FuncWithForwardCall(): string
228253 return DefinedLater("yes")
229254 enddef
diff -r e517915a786d -r 846fbbacce3a src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Mon Mar 30 23:00:05 2020 +0200
+++ b/src/testdir/test_vim9_script.vim Tue Mar 31 23:15:04 2020 +0200
@@ -260,9 +260,10 @@
260260 echo a:arg
261261 endfunc
262262
263-def Test_call_wrong_arg_count()
263+def Test_call_wrong_args()
264264 call CheckDefFailure(['TakesOneArg()'], 'E119:')
265265 call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
266+ call CheckDefFailure(['bufnr(xxx)'], 'E1001:')
266267 enddef
267268
268269 " Default arg and varargs
@@ -1029,6 +1030,14 @@
10291030 assert_equal('1_3_', result)
10301031 enddef
10311032
1033+def Test_for_loop_fails()
1034+ call CheckDefFailure(['for # in range(5)'], 'E690:')
1035+ call CheckDefFailure(['for i In range(5)'], 'E690:')
1036+ call CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:')
1037+ call CheckScriptFailure(['def Func(arg)', 'for arg in range(5)', 'enddef'], 'E1006:')
1038+ call CheckDefFailure(['for i in "text"'], 'E1024:')
1039+enddef
1040+
10321041 def Test_interrupt_loop()
10331042 let caught = false
10341043 let x = 0
diff -r e517915a786d -r 846fbbacce3a src/version.c
--- a/src/version.c Mon Mar 30 23:00:05 2020 +0200
+++ b/src/version.c Tue Mar 31 23:15:04 2020 +0200
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 487,
743+/**/
742744 486,
743745 /**/
744746 485,
diff -r e517915a786d -r 846fbbacce3a src/vim9.h
--- a/src/vim9.h Mon Mar 30 23:00:05 2020 +0200
+++ b/src/vim9.h Tue Mar 31 23:15:04 2020 +0200
@@ -57,6 +57,7 @@
5757 ISN_DCALL, // call def function isn_arg.dfunc
5858 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
5959 ISN_PCALL, // call partial, use isn_arg.pfunc
60+ ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
6061 ISN_RETURN, // return, result is on top of stack
6162 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
6263
@@ -256,7 +257,7 @@
256257 // Functions defined with :def are stored in this growarray.
257258 // They are never removed, so that they can be found by index.
258259 // Deleted functions have the df_deleted flag set.
259-garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
260+garray_T def_functions = {0, 0, sizeof(dfunc_T), 200, NULL};
260261 #else
261262 extern garray_T def_functions;
262263 #endif
diff -r e517915a786d -r 846fbbacce3a src/vim9compile.c
--- a/src/vim9compile.c Mon Mar 30 23:00:05 2020 +0200
+++ b/src/vim9compile.c Tue Mar 31 23:15:04 2020 +0200
@@ -1196,6 +1196,11 @@
11961196 // drop the funcref/partial, get back the return value
11971197 ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_any;
11981198
1199+ // If partial is above the arguments it must be cleared and replaced with
1200+ // the return value.
1201+ if (at_top && generate_instr(cctx, ISN_PCALL_END) == NULL)
1202+ return FAIL;
1203+
11991204 return OK;
12001205 }
12011206
@@ -5200,7 +5205,7 @@
52005205 p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
52015206 ? ea.cmd + 1 : ea.cmd;
52025207 p = to_name_end(p, TRUE);
5203- if ((p > ea.cmd && *p != NUL) || *p == '(')
5208+ if (p > ea.cmd && *p != NUL)
52045209 {
52055210 int oplen;
52065211 int heredoc;
@@ -5538,6 +5543,7 @@
55385543 case ISN_OPFLOAT:
55395544 case ISN_OPANY:
55405545 case ISN_PCALL:
5546+ case ISN_PCALL_END:
55415547 case ISN_PUSHF:
55425548 case ISN_PUSHNR:
55435549 case ISN_PUSHBOOL:
diff -r e517915a786d -r 846fbbacce3a src/vim9execute.c
--- a/src/vim9execute.c Mon Mar 30 23:00:05 2020 +0200
+++ b/src/vim9execute.c Tue Mar 31 23:15:04 2020 +0200
@@ -345,7 +345,7 @@
345345 static int
346346 call_partial(typval_T *tv, int argcount, ectx_T *ectx)
347347 {
348- char_u *name;
348+ char_u *name = NULL;
349349 int called_emsg_before = called_emsg;
350350
351351 if (tv->v_type == VAR_PARTIAL)
@@ -356,9 +356,9 @@
356356 return call_ufunc(pt->pt_func, argcount, ectx, NULL);
357357 name = pt->pt_name;
358358 }
359- else
359+ else if (tv->v_type == VAR_FUNC)
360360 name = tv->vval.v_string;
361- if (call_by_name(name, argcount, ectx, NULL) == FAIL)
361+ if (name == NULL || call_by_name(name, argcount, ectx, NULL) == FAIL)
362362 {
363363 if (called_emsg == called_emsg_before)
364364 semsg(_(e_unknownfunc), name);
@@ -421,7 +421,6 @@
421421 typval_T *tv;
422422 int idx;
423423 int ret = FAIL;
424- dfunc_T *dfunc;
425424 int defcount = ufunc->uf_args.ga_len - argc;
426425
427426 // Get pointer to item in the stack.
@@ -467,13 +466,17 @@
467466 ++ectx.ec_stack.ga_len;
468467 }
469468
470- // Reserve space for local variables.
471- dfunc = ((dfunc_T *)def_functions.ga_data) + ufunc->uf_dfunc_idx;
472- for (idx = 0; idx < dfunc->df_varcount; ++idx)
473- STACK_TV_VAR(idx)->v_type = VAR_UNKNOWN;
474- ectx.ec_stack.ga_len += dfunc->df_varcount;
469+ {
470+ // Reserve space for local variables.
471+ dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
472+ + ufunc->uf_dfunc_idx;
475473
476- ectx.ec_instr = dfunc->df_instr;
474+ for (idx = 0; idx < dfunc->df_varcount; ++idx)
475+ STACK_TV_VAR(idx)->v_type = VAR_UNKNOWN;
476+ ectx.ec_stack.ga_len += dfunc->df_varcount;
477+
478+ ectx.ec_instr = dfunc->df_instr;
479+ }
477480
478481 // Decide where to start execution, handles optional arguments.
479482 init_instr_idx(ufunc, argc, &ectx);
@@ -1022,16 +1025,16 @@
10221025 clear_tv(&partial);
10231026 if (r == FAIL)
10241027 goto failed;
1028+ }
1029+ break;
10251030
1026- if (pfunc->cpf_top)
1027- {
1028- // Get the funcref from the stack, overwrite with the
1029- // return value.
1030- clear_tv(tv);
1031- --ectx.ec_stack.ga_len;
1032- *STACK_TV_BOT(-1) = *STACK_TV_BOT(0);
1033- }
1034- }
1031+ case ISN_PCALL_END:
1032+ // PCALL finished, arguments have been consumed and replaced by
1033+ // the return value. Now clear the funcref from the stack,
1034+ // and move the return value in its place.
1035+ --ectx.ec_stack.ga_len;
1036+ clear_tv(STACK_TV_BOT(-1));
1037+ *STACK_TV_BOT(-1) = *STACK_TV_BOT(0);
10351038 break;
10361039
10371040 // call a user defined function or funcref/partial
@@ -1078,6 +1081,7 @@
10781081 case ISN_FUNCREF:
10791082 {
10801083 partial_T *pt = NULL;
1084+ dfunc_T *dfunc;
10811085
10821086 pt = ALLOC_CLEAR_ONE(partial_T);
10831087 if (pt == NULL)
@@ -2005,6 +2009,9 @@
20052009 cpfunc->cpf_top ? " top" : "", cpfunc->cpf_argcount);
20062010 }
20072011 break;
2012+ case ISN_PCALL_END:
2013+ smsg("%4d PCALL end", current);
2014+ break;
20082015 case ISN_RETURN:
20092016 smsg("%4d RETURN", current);
20102017 break;
Show on old repository browser