Mercurial > vim
comparison src/vim9compile.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 | d54dfb5f12db |
children | cb4831fa7e25 |
comparison
equal
deleted
inserted
replaced
20527:37ac4c5b4d27 | 20528:489cb75c76b6 |
---|---|
1416 { | 1416 { |
1417 semsg(_(e_toofewarg), ufunc->uf_name); | 1417 semsg(_(e_toofewarg), ufunc->uf_name); |
1418 return FAIL; | 1418 return FAIL; |
1419 } | 1419 } |
1420 | 1420 |
1421 if (ufunc->uf_dfunc_idx >= 0) | 1421 if (ufunc->uf_dfunc_idx != UF_NOT_COMPILED) |
1422 { | 1422 { |
1423 int i; | 1423 int i; |
1424 | 1424 |
1425 for (i = 0; i < argcount; ++i) | 1425 for (i = 0; i < argcount; ++i) |
1426 { | 1426 { |
1440 { | 1440 { |
1441 arg_type_mismatch(expected, actual, i + 1); | 1441 arg_type_mismatch(expected, actual, i + 1); |
1442 return FAIL; | 1442 return FAIL; |
1443 } | 1443 } |
1444 } | 1444 } |
1445 if (ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED) | |
1446 if (compile_def_function(ufunc, TRUE, cctx) == FAIL) | |
1447 return FAIL; | |
1445 } | 1448 } |
1446 | 1449 |
1447 if ((isn = generate_instr(cctx, | 1450 if ((isn = generate_instr(cctx, |
1448 ufunc->uf_dfunc_idx >= 0 ? ISN_DCALL : ISN_UCALL)) == NULL) | 1451 ufunc->uf_dfunc_idx != UF_NOT_COMPILED ? ISN_DCALL |
1449 return FAIL; | 1452 : ISN_UCALL)) == NULL) |
1450 if (ufunc->uf_dfunc_idx >= 0) | 1453 return FAIL; |
1454 if (ufunc->uf_dfunc_idx != UF_NOT_COMPILED) | |
1451 { | 1455 { |
1452 isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx; | 1456 isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx; |
1453 isn->isn_arg.dfunc.cdf_argcount = argcount; | 1457 isn->isn_arg.dfunc.cdf_argcount = argcount; |
1454 } | 1458 } |
1455 else | 1459 else |
4452 eap->arg = name_end; | 4456 eap->arg = name_end; |
4453 eap->getline = exarg_getline; | 4457 eap->getline = exarg_getline; |
4454 eap->cookie = cctx; | 4458 eap->cookie = cctx; |
4455 eap->skip = cctx->ctx_skip == TRUE; | 4459 eap->skip = cctx->ctx_skip == TRUE; |
4456 eap->forceit = FALSE; | 4460 eap->forceit = FALSE; |
4457 ufunc = def_function(eap, name, cctx, TRUE); | 4461 ufunc = def_function(eap, name); |
4458 | 4462 |
4459 if (ufunc == NULL || ufunc->uf_dfunc_idx < 0) | 4463 if (ufunc == NULL) |
4464 return NULL; | |
4465 if (ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED | |
4466 && compile_def_function(ufunc, TRUE, cctx) == FAIL) | |
4460 return NULL; | 4467 return NULL; |
4461 | 4468 |
4462 // Define a local variable for the function reference. | 4469 // Define a local variable for the function reference. |
4463 lvar = reserve_local(cctx, name_start, name_end - name_start, | 4470 lvar = reserve_local(cctx, name_start, name_end - name_start, |
4464 TRUE, ufunc->uf_func_type); | 4471 TRUE, ufunc->uf_func_type); |
6300 | 6307 |
6301 /* | 6308 /* |
6302 * Add a function to the list of :def functions. | 6309 * Add a function to the list of :def functions. |
6303 * This "sets ufunc->uf_dfunc_idx" but the function isn't compiled yet. | 6310 * This "sets ufunc->uf_dfunc_idx" but the function isn't compiled yet. |
6304 */ | 6311 */ |
6305 int | 6312 static int |
6306 add_def_function(ufunc_T *ufunc) | 6313 add_def_function(ufunc_T *ufunc) |
6307 { | 6314 { |
6308 dfunc_T *dfunc; | 6315 dfunc_T *dfunc; |
6309 | 6316 |
6310 // Add the function to "def_functions". | 6317 // Add the function to "def_functions". |
6326 * When "set_return_type" is set then set ufunc->uf_ret_type to the type of the | 6333 * When "set_return_type" is set then set ufunc->uf_ret_type to the type of the |
6327 * return statement (used for lambda). | 6334 * return statement (used for lambda). |
6328 * "outer_cctx" is set for a nested function. | 6335 * "outer_cctx" is set for a nested function. |
6329 * This can be used recursively through compile_lambda(), which may reallocate | 6336 * This can be used recursively through compile_lambda(), which may reallocate |
6330 * "def_functions". | 6337 * "def_functions". |
6331 */ | 6338 * Returns OK or FAIL. |
6332 void | 6339 */ |
6340 int | |
6333 compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx) | 6341 compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx) |
6334 { | 6342 { |
6335 char_u *line = NULL; | 6343 char_u *line = NULL; |
6336 char_u *p; | 6344 char_u *p; |
6337 char *errormsg = NULL; // error message | 6345 char *errormsg = NULL; // error message |
6350 + ufunc->uf_dfunc_idx; | 6358 + ufunc->uf_dfunc_idx; |
6351 // Free old instructions. | 6359 // Free old instructions. |
6352 delete_def_function_contents(dfunc); | 6360 delete_def_function_contents(dfunc); |
6353 } | 6361 } |
6354 else if (add_def_function(ufunc) == FAIL) | 6362 else if (add_def_function(ufunc) == FAIL) |
6355 return; | 6363 return FAIL; |
6356 | 6364 |
6357 CLEAR_FIELD(cctx); | 6365 CLEAR_FIELD(cctx); |
6358 cctx.ctx_ufunc = ufunc; | 6366 cctx.ctx_ufunc = ufunc; |
6359 cctx.ctx_lnum = -1; | 6367 cctx.ctx_lnum = -1; |
6360 cctx.ctx_outer = outer_cctx; | 6368 cctx.ctx_outer = outer_cctx; |
6814 | 6822 |
6815 for (idx = 0; idx < instr->ga_len; ++idx) | 6823 for (idx = 0; idx < instr->ga_len; ++idx) |
6816 delete_instr(((isn_T *)instr->ga_data) + idx); | 6824 delete_instr(((isn_T *)instr->ga_data) + idx); |
6817 ga_clear(instr); | 6825 ga_clear(instr); |
6818 | 6826 |
6819 ufunc->uf_dfunc_idx = -1; | 6827 ufunc->uf_dfunc_idx = UF_NOT_COMPILED; |
6820 if (!dfunc->df_deleted) | 6828 if (!dfunc->df_deleted) |
6821 --def_functions.ga_len; | 6829 --def_functions.ga_len; |
6822 | 6830 |
6823 while (cctx.ctx_scope != NULL) | 6831 while (cctx.ctx_scope != NULL) |
6824 drop_scope(&cctx); | 6832 drop_scope(&cctx); |
6834 | 6842 |
6835 current_sctx = save_current_sctx; | 6843 current_sctx = save_current_sctx; |
6836 free_imported(&cctx); | 6844 free_imported(&cctx); |
6837 free_locals(&cctx); | 6845 free_locals(&cctx); |
6838 ga_clear(&cctx.ctx_type_stack); | 6846 ga_clear(&cctx.ctx_type_stack); |
6847 return ret; | |
6839 } | 6848 } |
6840 | 6849 |
6841 /* | 6850 /* |
6842 * Delete an instruction, free what it contains. | 6851 * Delete an instruction, free what it contains. |
6843 */ | 6852 */ |