diff options
Diffstat (limited to 'src/vim9cmds.c')
-rw-r--r-- | src/vim9cmds.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/vim9cmds.c b/src/vim9cmds.c index 9651801ed0..c294d70a85 100644 --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -1685,6 +1685,27 @@ compile_eval(char_u *arg, cctx_T *cctx) } /* + * Get the local variable index for deferred function calls. + * Reserve it when not done already. + * Returns zero for failure. + */ + int +get_defer_var_idx(cctx_T *cctx) +{ + dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + + cctx->ctx_ufunc->uf_dfunc_idx; + if (dfunc->df_defer_var_idx == 0) + { + lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, + TRUE, &t_list_any); + if (lvar == NULL) + return 0; + dfunc->df_defer_var_idx = lvar->lv_idx + 1; + } + return dfunc->df_defer_var_idx; +} + +/* * Compile "defer func(arg)". */ char_u * @@ -1693,7 +1714,7 @@ compile_defer(char_u *arg_start, cctx_T *cctx) char_u *p; char_u *arg = arg_start; int argcount = 0; - dfunc_T *dfunc; + int defer_var_idx; type_T *type; int func_idx; @@ -1730,16 +1751,10 @@ compile_defer(char_u *arg_start, cctx_T *cctx) // TODO: check argument count with "type" - dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx; - if (dfunc->df_defer_var_idx == 0) - { - lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, - TRUE, &t_list_any); - if (lvar == NULL) - return NULL; - dfunc->df_defer_var_idx = lvar->lv_idx + 1; - } - if (generate_DEFER(cctx, dfunc->df_defer_var_idx - 1, argcount) == FAIL) + defer_var_idx = get_defer_var_idx(cctx); + if (defer_var_idx == 0) + return NULL; + if (generate_DEFER(cctx, defer_var_idx - 1, argcount) == FAIL) return NULL; return skipwhite(arg); |