Mercurial > vim
comparison src/vim9compile.c @ 23360:eb7d8f39363c v8.2.2223
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Commit: https://github.com/vim/vim/commit/cdc40c43f1008bda2f173d3a13606236679e8067
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 26 17:43:08 2020 +0100
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Problem: Vim9: Reloading marks a :def function as deleted.
Solution: Clear the function contents but keep the index.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Dec 2020 17:45:03 +0100 |
parents | 37118deff718 |
children | f181fe2150ab |
comparison
equal
deleted
inserted
replaced
23359:35b42d31593d | 23360:eb7d8f39363c |
---|---|
143 garray_T *ctx_type_list; // list of pointers to allocated types | 143 garray_T *ctx_type_list; // list of pointers to allocated types |
144 | 144 |
145 int ctx_has_cmdmod; // ISN_CMDMOD was generated | 145 int ctx_has_cmdmod; // ISN_CMDMOD was generated |
146 }; | 146 }; |
147 | 147 |
148 static void delete_def_function_contents(dfunc_T *dfunc); | 148 static void delete_def_function_contents(dfunc_T *dfunc, int mark_deleted); |
149 | 149 |
150 /* | 150 /* |
151 * Lookup variable "name" in the local scope and return it in "lvar". | 151 * Lookup variable "name" in the local scope and return it in "lvar". |
152 * "lvar->lv_from_outer" is set accordingly. | 152 * "lvar->lv_from_outer" is set accordingly. |
153 * If "lvar" is NULL only check if the variable can be found. | 153 * If "lvar" is NULL only check if the variable can be found. |
7496 int save_estack_compiling = estack_compiling; | 7496 int save_estack_compiling = estack_compiling; |
7497 int do_estack_push; | 7497 int do_estack_push; |
7498 int new_def_function = FALSE; | 7498 int new_def_function = FALSE; |
7499 | 7499 |
7500 // When using a function that was compiled before: Free old instructions. | 7500 // When using a function that was compiled before: Free old instructions. |
7501 // Otherwise add a new entry in "def_functions". | 7501 // The index is reused. Otherwise add a new entry in "def_functions". |
7502 if (ufunc->uf_dfunc_idx > 0) | 7502 if (ufunc->uf_dfunc_idx > 0) |
7503 { | 7503 { |
7504 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) | 7504 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
7505 + ufunc->uf_dfunc_idx; | 7505 + ufunc->uf_dfunc_idx; |
7506 delete_def_function_contents(dfunc); | 7506 delete_def_function_contents(dfunc, FALSE); |
7507 } | 7507 } |
7508 else | 7508 else |
7509 { | 7509 { |
7510 if (add_def_function(ufunc) == FAIL) | 7510 if (add_def_function(ufunc) == FAIL) |
7511 return FAIL; | 7511 return FAIL; |
8342 | 8342 |
8343 /* | 8343 /* |
8344 * Free all instructions for "dfunc" except df_name. | 8344 * Free all instructions for "dfunc" except df_name. |
8345 */ | 8345 */ |
8346 static void | 8346 static void |
8347 delete_def_function_contents(dfunc_T *dfunc) | 8347 delete_def_function_contents(dfunc_T *dfunc, int mark_deleted) |
8348 { | 8348 { |
8349 int idx; | 8349 int idx; |
8350 | 8350 |
8351 ga_clear(&dfunc->df_def_args_isn); | 8351 ga_clear(&dfunc->df_def_args_isn); |
8352 | 8352 |
8353 if (dfunc->df_instr != NULL) | 8353 if (dfunc->df_instr != NULL) |
8354 { | 8354 { |
8355 for (idx = 0; idx < dfunc->df_instr_count; ++idx) | 8355 for (idx = 0; idx < dfunc->df_instr_count; ++idx) |
8356 delete_instr(dfunc->df_instr + idx); | 8356 delete_instr(dfunc->df_instr + idx); |
8357 VIM_CLEAR(dfunc->df_instr); | 8357 VIM_CLEAR(dfunc->df_instr); |
8358 } | 8358 dfunc->df_instr = NULL; |
8359 | 8359 } |
8360 dfunc->df_deleted = TRUE; | 8360 |
8361 if (mark_deleted) | |
8362 dfunc->df_deleted = TRUE; | |
8363 if (dfunc->df_ufunc != NULL) | |
8364 dfunc->df_ufunc->uf_def_status = UF_NOT_COMPILED; | |
8361 } | 8365 } |
8362 | 8366 |
8363 /* | 8367 /* |
8364 * When a user function is deleted, clear the contents of any associated def | 8368 * When a user function is deleted, clear the contents of any associated def |
8365 * function, unless another user function still uses it. | 8369 * function, unless another user function still uses it. |
8372 { | 8376 { |
8373 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) | 8377 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
8374 + ufunc->uf_dfunc_idx; | 8378 + ufunc->uf_dfunc_idx; |
8375 | 8379 |
8376 if (--dfunc->df_refcount <= 0) | 8380 if (--dfunc->df_refcount <= 0) |
8377 delete_def_function_contents(dfunc); | 8381 delete_def_function_contents(dfunc, TRUE); |
8378 ufunc->uf_def_status = UF_NOT_COMPILED; | 8382 ufunc->uf_def_status = UF_NOT_COMPILED; |
8379 ufunc->uf_dfunc_idx = 0; | 8383 ufunc->uf_dfunc_idx = 0; |
8380 if (dfunc->df_ufunc == ufunc) | 8384 if (dfunc->df_ufunc == ufunc) |
8381 dfunc->df_ufunc = NULL; | 8385 dfunc->df_ufunc = NULL; |
8382 } | 8386 } |
8408 | 8412 |
8409 for (idx = 0; idx < def_functions.ga_len; ++idx) | 8413 for (idx = 0; idx < def_functions.ga_len; ++idx) |
8410 { | 8414 { |
8411 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx; | 8415 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx; |
8412 | 8416 |
8413 delete_def_function_contents(dfunc); | 8417 delete_def_function_contents(dfunc, TRUE); |
8414 vim_free(dfunc->df_name); | 8418 vim_free(dfunc->df_name); |
8415 } | 8419 } |
8416 | 8420 |
8417 ga_clear(&def_functions); | 8421 ga_clear(&def_functions); |
8418 } | 8422 } |