1
0
forked from aniani/vim

patch 8.2.1023: Vim9: redefining a function uses a new index every time

Problem:    Vim9: redefining a function uses a new index every time.
Solution:   When redefining a function clear the contents and re-use the
            index.
This commit is contained in:
Bram Moolenaar
2020-06-20 18:19:09 +02:00
parent 845e0ee594
commit 0cb5bcf583
8 changed files with 57 additions and 37 deletions

View File

@@ -409,7 +409,7 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate)
fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
if (fp == NULL)
goto errret;
fp->uf_dfunc_idx = UF_NOT_COMPILED;
fp->uf_def_status = UF_NOT_COMPILED;
pt = ALLOC_CLEAR_ONE(partial_T);
if (pt == NULL)
goto errret;
@@ -1001,7 +1001,7 @@ func_remove(ufunc_T *fp)
{
// When there is a def-function index do not actually remove the
// function, so we can find the index when defining the function again.
if (fp->uf_dfunc_idx >= 0)
if (fp->uf_def_status == UF_COMPILED)
fp->uf_flags |= FC_DEAD;
else
hash_remove(&func_hashtab, hi);
@@ -1046,7 +1046,7 @@ func_clear(ufunc_T *fp, int force)
// clear this function
func_clear_items(fp);
funccal_unref(fp->uf_scoped, fp, force);
delete_def_function(fp);
clear_def_function(fp);
}
/*
@@ -1074,7 +1074,8 @@ func_free(ufunc_T *fp, int force)
func_clear_free(ufunc_T *fp, int force)
{
func_clear(fp, force);
func_free(fp, force);
if (force || fp->uf_dfunc_idx == 0)
func_free(fp, force);
}
@@ -1137,7 +1138,7 @@ call_user_func(
ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1);
func_ptr_ref(fp);
if (fp->uf_dfunc_idx != UF_NOT_COMPILED)
if (fp->uf_def_status != UF_NOT_COMPILED)
{
estack_push_ufunc(fp, 1);
save_current_sctx = current_sctx;
@@ -1662,7 +1663,7 @@ free_all_functions(void)
// clear the def function index now
fp = HI2UF(hi);
fp->uf_flags &= ~FC_DEAD;
fp->uf_dfunc_idx = UF_NOT_COMPILED;
fp->uf_def_status = UF_NOT_COMPILED;
// Only free functions that are not refcounted, those are
// supposed to be freed when no longer referenced.
@@ -2058,7 +2059,7 @@ list_func_head(ufunc_T *fp, int indent)
msg_start();
if (indent)
msg_puts(" ");
if (fp->uf_dfunc_idx != UF_NOT_COMPILED)
if (fp->uf_def_status != UF_NOT_COMPILED)
msg_puts("def ");
else
msg_puts("function ");
@@ -2107,7 +2108,7 @@ list_func_head(ufunc_T *fp, int indent)
}
msg_putchar(')');
if (fp->uf_dfunc_idx != UF_NOT_COMPILED)
if (fp->uf_def_status != UF_NOT_COMPILED)
{
if (fp->uf_ret_type != &t_void)
{
@@ -2624,7 +2625,7 @@ def_function(exarg_T *eap, char_u *name_arg)
if (!got_int)
{
msg_putchar('\n');
if (fp->uf_dfunc_idx != UF_NOT_COMPILED)
if (fp->uf_def_status != UF_NOT_COMPILED)
msg_puts(" enddef");
else
msg_puts(" endfunction");
@@ -3097,6 +3098,7 @@ def_function(exarg_T *eap, char_u *name_arg)
fp->uf_profiling = FALSE;
fp->uf_prof_initialized = FALSE;
#endif
clear_def_function(fp);
}
}
}
@@ -3162,7 +3164,7 @@ def_function(exarg_T *eap, char_u *name_arg)
fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
if (fp == NULL)
goto erret;
fp->uf_dfunc_idx = eap->cmdidx == CMD_def ? UF_TO_BE_COMPILED
fp->uf_def_status = eap->cmdidx == CMD_def ? UF_TO_BE_COMPILED
: UF_NOT_COMPILED;
if (fudi.fd_dict != NULL)
@@ -3219,7 +3221,7 @@ def_function(exarg_T *eap, char_u *name_arg)
{
int lnum_save = SOURCING_LNUM;
fp->uf_dfunc_idx = UF_TO_BE_COMPILED;
fp->uf_def_status = UF_TO_BE_COMPILED;
// error messages are for the first function line
SOURCING_LNUM = sourcing_lnum_top;
@@ -3289,7 +3291,7 @@ def_function(exarg_T *eap, char_u *name_arg)
SOURCING_LNUM = lnum_save;
}
else
fp->uf_dfunc_idx = UF_NOT_COMPILED;
fp->uf_def_status = UF_NOT_COMPILED;
fp->uf_lines = newlines;
if ((flags & FC_CLOSURE) != 0)
@@ -3372,7 +3374,7 @@ ex_defcompile(exarg_T *eap UNUSED)
--todo;
ufunc = HI2UF(hi);
if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid
&& ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED)
&& ufunc->uf_def_status == UF_TO_BE_COMPILED)
{
compile_def_function(ufunc, FALSE, NULL);