comparison src/vim9compile.c @ 20538:9f921ba86d05 v8.2.0823

patch 8.2.0823: Vim9: script reload test is disabled Commit: https://github.com/vim/vim/commit/25e0f5863e9010a75a1ff0d04e8f886403968755 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 25 22:36:50 2020 +0200 patch 8.2.0823: Vim9: script reload test is disabled Problem: Vim9: script reload test is disabled. Solution: Compile a function in the context of the script where it was defined. Set execution stack for compiled function. Add a test that an error is reported for the right file/function.
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 May 2020 22:45:03 +0200
parents ae758aa4ee5e
children 9064044fd4f6
comparison
equal deleted inserted replaced
20537:cceaa5ec43aa 20538:9f921ba86d05
2321 line = NULL; 2321 line = NULL;
2322 break; 2322 break;
2323 } 2323 }
2324 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; 2324 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
2325 cctx->ctx_line_start = line; 2325 cctx->ctx_line_start = line;
2326 SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum 2326 SOURCING_LNUM = cctx->ctx_lnum + 1;
2327 + cctx->ctx_lnum + 1;
2328 } while (line == NULL || *skipwhite(line) == NUL); 2327 } while (line == NULL || *skipwhite(line) == NUL);
2329 return line; 2328 return line;
2330 } 2329 }
2331 2330
2332 /* 2331 /*
6347 cctx_T cctx; 6346 cctx_T cctx;
6348 garray_T *instr; 6347 garray_T *instr;
6349 int called_emsg_before = called_emsg; 6348 int called_emsg_before = called_emsg;
6350 int ret = FAIL; 6349 int ret = FAIL;
6351 sctx_T save_current_sctx = current_sctx; 6350 sctx_T save_current_sctx = current_sctx;
6351 int do_estack_push;
6352 int emsg_before = called_emsg; 6352 int emsg_before = called_emsg;
6353 6353
6354 // When using a function that was compiled before: Free old instructions.
6355 // Otherwise add a new entry in "def_functions".
6354 if (ufunc->uf_dfunc_idx >= 0) 6356 if (ufunc->uf_dfunc_idx >= 0)
6355 { 6357 {
6356 // Redefining a function that was compiled before.
6357 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) 6358 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
6358 + ufunc->uf_dfunc_idx; 6359 + ufunc->uf_dfunc_idx;
6359 // Free old instructions.
6360 delete_def_function_contents(dfunc); 6360 delete_def_function_contents(dfunc);
6361 } 6361 }
6362 else if (add_def_function(ufunc) == FAIL) 6362 else if (add_def_function(ufunc) == FAIL)
6363 return FAIL; 6363 return FAIL;
6364 6364
6371 ga_init2(&cctx.ctx_imports, sizeof(imported_T), 10); 6371 ga_init2(&cctx.ctx_imports, sizeof(imported_T), 10);
6372 cctx.ctx_type_list = &ufunc->uf_type_list; 6372 cctx.ctx_type_list = &ufunc->uf_type_list;
6373 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50); 6373 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50);
6374 instr = &cctx.ctx_instr; 6374 instr = &cctx.ctx_instr;
6375 6375
6376 // Most modern script version. 6376 // Set the context to the function, it may be compiled when called from
6377 // another script. Set the script version to the most modern one.
6378 // The line number will be set in next_line_from_context().
6379 current_sctx = ufunc->uf_script_ctx;
6377 current_sctx.sc_version = SCRIPT_VERSION_VIM9; 6380 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
6381
6382 // Make sure error messages are OK.
6383 do_estack_push = !estack_top_is_ufunc(ufunc, 1);
6384 if (do_estack_push)
6385 estack_push_ufunc(ufunc, 1);
6378 6386
6379 if (ufunc->uf_def_args.ga_len > 0) 6387 if (ufunc->uf_def_args.ga_len > 0)
6380 { 6388 {
6381 int count = ufunc->uf_def_args.ga_len; 6389 int count = ufunc->uf_def_args.ga_len;
6382 int first_def_arg = ufunc->uf_args.ga_len - count; 6390 int first_def_arg = ufunc->uf_args.ga_len - count;
6793 else if (called_emsg == called_emsg_before) 6801 else if (called_emsg == called_emsg_before)
6794 emsg(_("E1028: compile_def_function failed")); 6802 emsg(_("E1028: compile_def_function failed"));
6795 } 6803 }
6796 6804
6797 current_sctx = save_current_sctx; 6805 current_sctx = save_current_sctx;
6806 if (do_estack_push)
6807 estack_pop();
6808
6798 free_imported(&cctx); 6809 free_imported(&cctx);
6799 free_locals(&cctx); 6810 free_locals(&cctx);
6800 ga_clear(&cctx.ctx_type_stack); 6811 ga_clear(&cctx.ctx_type_stack);
6801 return ret; 6812 return ret;
6802 } 6813 }