Patch 8.2.0199
Problem: Vim9 script commands not sufficiently tested.
Solution: Add more tests. Fix script-local function use.
Files: src/vim9execute.c, src/testdir/test_vim9_script.vim,
src/userfunc.c
*** ../vim-8.2.0198/src/vim9execute.c 2020-01-28 22:59:42.214388111 +0100
--- src/vim9execute.c 2020-02-02 16:56:45.207783658 +0100
***************
*** 1502,1522 ****
ex_disassemble(exarg_T *eap)
{
#ifdef DISASSEMBLE
! ufunc_T *ufunc = find_func(eap->arg, NULL);
dfunc_T *dfunc;
isn_T *instr;
int current;
int line_idx = 0;
int prev_current = 0;
if (ufunc == NULL)
{
! semsg("Cannot find function %s", eap->arg);
return;
}
if (ufunc->uf_dfunc_idx < 0)
{
! semsg("Function %s is not compiled", eap->arg);
return;
}
if (ufunc->uf_name_exp != NULL)
--- 1502,1527 ----
ex_disassemble(exarg_T *eap)
{
#ifdef DISASSEMBLE
! char_u *fname;
! ufunc_T *ufunc;
dfunc_T *dfunc;
isn_T *instr;
int current;
int line_idx = 0;
int prev_current = 0;
+ fname = trans_function_name(&eap->arg, FALSE,
+ TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF, NULL, NULL);
+ ufunc = find_func(fname, NULL);
+ vim_free(fname);
if (ufunc == NULL)
{
! semsg("E1061: Cannot find function %s", eap->arg);
return;
}
if (ufunc->uf_dfunc_idx < 0)
{
! semsg("E1062: Function %s is not compiled", eap->arg);
return;
}
if (ufunc->uf_name_exp != NULL)
*** ../vim-8.2.0198/src/testdir/test_vim9_script.vim 2020-01-31 20:10:46.754021052 +0100
--- src/testdir/test_vim9_script.vim 2020-02-02 17:20:54.102370152 +0100
***************
*** 106,112 ****
Increment()
" works with and without :call
assert_equal(4, g:counter)
! call assert_equal(4, g:counter)
unlet g:counter
enddef
--- 106,112 ----
Increment()
" works with and without :call
assert_equal(4, g:counter)
! assert_equal(4, g:counter)
unlet g:counter
enddef
***************
*** 354,360 ****
l->remove(0)
l->add(5)
l->insert(99, 1)
! call assert_equal([2, 99, 3, 4, 5], l)
enddef
" Test that inside :function a Python function can be defined, :def is not
--- 354,360 ----
l->remove(0)
l->add(5)
l->insert(99, 1)
! assert_equal([2, 99, 3, 4, 5], l)
enddef
" Test that inside :function a Python function can be defined, :def is not
***************
*** 387,401 ****
def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
! call assert_match('PUSHS "yes"', instr)
! call assert_notmatch('PUSHS "no"', instr)
! call assert_notmatch('JUMP', instr)
assert_equal("\nno", execute('call HasNothing()'))
instr = execute('disassemble HasNothing')
! call assert_notmatch('PUSHS "yes"', instr)
! call assert_match('PUSHS "no"', instr)
! call assert_notmatch('JUMP', instr)
enddef
--- 387,438 ----
def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
! assert_match('PUSHS "yes"', instr)
! assert_notmatch('PUSHS "no"', instr)
! assert_notmatch('JUMP', instr)
assert_equal("\nno", execute('call HasNothing()'))
instr = execute('disassemble HasNothing')
! assert_notmatch('PUSHS "yes"', instr)
! assert_match('PUSHS "no"', instr)
! assert_notmatch('JUMP', instr)
! enddef
!
! func NotCompiled()
! echo "not"
! endfunc
!
! let s:scriptvar = 4
! let g:globalvar = 'g'
!
! def s:ScriptFunc(arg: string)
! let local = 1
! buffers
! echo arg
! echo local
! echo v:version
! echo s:scriptvar
! echo g:globalvar
! echo &tabstop
! echo $ENVVAR
! echo @z
! enddef
!
! def Test_disassemble()
! assert_fails('disass NoFunc', 'E1061:')
! assert_fails('disass NotCompiled', 'E1062:')
!
! let res = execute('disass s:ScriptFunc')
! assert_match('<SNR>\d*_ScriptFunc.*'
! \ .. 'buffers.*'
! \ .. ' EXEC \+buffers.*'
! \ .. ' LOAD arg\[-1\].*'
! \ .. ' LOAD $0.*'
! \ .. ' LOADV v:version.*'
! \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*'
! \ .. ' LOADG g:globalvar.*'
! \ .. ' LOADENV $ENVVAR.*'
! \ .. ' LOADREG @z.*', res)
enddef
*** ../vim-8.2.0198/src/userfunc.c 2020-01-31 20:10:46.754021052 +0100
--- src/userfunc.c 2020-02-02 17:07:42.113253531 +0100
***************
*** 1060,1065 ****
--- 1060,1067 ----
if (fp->uf_dfunc_idx >= 0)
{
estack_push_ufunc(ETYPE_UFUNC, fp, 1);
+ save_current_sctx = current_sctx;
+ current_sctx = fp->uf_script_ctx;
// Execute the compiled function.
call_def_function(fp, argcount, argvars, rettv);
***************
*** 1067,1072 ****
--- 1069,1075 ----
current_funccal = fc->caller;
estack_pop();
+ current_sctx = save_current_sctx;
free_funccal(fc);
return;
}
*** ../vim-8.2.0198/src/version.c 2020-02-02 15:55:16.072876269 +0100
--- src/version.c 2020-02-02 16:46:37.210196883 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 199,
/**/
--
How To Keep A Healthy Level Of Insanity:
4. Put your garbage can on your desk and label it "in".
/// 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 ///