comparison src/vim9execute.c @ 20528:489cb75c76b6 v8.2.0818

patch 8.2.0818: Vim9: using a discovery phase doesn't work well Commit: https://github.com/vim/vim/commit/822ba24743af9ee1b5e7f656a7a61a38f3638bca Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 24 23:00:18 2020 +0200 patch 8.2.0818: Vim9: using a discovery phase doesn't work well Problem: Vim9: using a discovery phase doesn't work well. Solution: Remove the discovery phase, instead compile a function only when it is used. Add :defcompile to compile def functions earlier.
author Bram Moolenaar <Bram@vim.org>
date Sun, 24 May 2020 23:15:04 +0200
parents 5950284a517f
children 9f921ba86d05
comparison
equal deleted inserted replaced
20527:37ac4c5b4d27 20528:489cb75c76b6
485 typval_T argvars[MAX_FUNC_ARGS]; 485 typval_T argvars[MAX_FUNC_ARGS];
486 funcexe_T funcexe; 486 funcexe_T funcexe;
487 int error; 487 int error;
488 int idx; 488 int idx;
489 489
490 if (ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED
491 && compile_def_function(ufunc, FALSE, NULL) == FAIL)
492 return FAIL;
490 if (ufunc->uf_dfunc_idx >= 0) 493 if (ufunc->uf_dfunc_idx >= 0)
491 { 494 {
492 // The function has been compiled, can call it quickly. For a function 495 // The function has been compiled, can call it quickly. For a function
493 // that was defined later: we can call it directly next time. 496 // that was defined later: we can call it directly next time.
494 if (iptr != NULL) 497 if (iptr != NULL)
665 #define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame_idx + STACK_FRAME_SIZE + idx) 668 #define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame_idx + STACK_FRAME_SIZE + idx)
666 669
667 // Like STACK_TV_VAR but use the outer scope 670 // Like STACK_TV_VAR but use the outer scope
668 #define STACK_OUT_TV_VAR(idx) (((typval_T *)ectx.ec_outer_stack->ga_data) + ectx.ec_outer_frame + STACK_FRAME_SIZE + idx) 671 #define STACK_OUT_TV_VAR(idx) (((typval_T *)ectx.ec_outer_stack->ga_data) + ectx.ec_outer_frame + STACK_FRAME_SIZE + idx)
669 672
673 if (ufunc->uf_dfunc_idx == UF_NOT_COMPILED
674 || (ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED
675 && compile_def_function(ufunc, FALSE, NULL) == FAIL))
676 return FAIL;
677
670 { 678 {
671 // Check the function was compiled, it is postponed in ex_vim9script(). 679 // Check the function was really compiled.
672 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) 680 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
673 + ufunc->uf_dfunc_idx; 681 + ufunc->uf_dfunc_idx;
674 if (dfunc->df_instr == NULL) 682 if (dfunc->df_instr == NULL)
675 return FAIL; 683 return FAIL;
676 } 684 }
2301 if (ufunc == NULL) 2309 if (ufunc == NULL)
2302 { 2310 {
2303 semsg(_("E1061: Cannot find function %s"), eap->arg); 2311 semsg(_("E1061: Cannot find function %s"), eap->arg);
2304 return; 2312 return;
2305 } 2313 }
2314 if (ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED
2315 && compile_def_function(ufunc, FALSE, NULL) == FAIL)
2316 return;
2306 if (ufunc->uf_dfunc_idx < 0) 2317 if (ufunc->uf_dfunc_idx < 0)
2307 { 2318 {
2308 semsg(_("E1062: Function %s is not compiled"), eap->arg); 2319 semsg(_("E1062: Function %s is not compiled"), eap->arg);
2309 return; 2320 return;
2310 } 2321 }