To: vim_dev@googlegroups.com Subject: Patch 8.2.2238 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2238 Problem: Vim9: cannot load a Vim9 script without the +eval feature. Solution: Support Vim9 script syntax without the +eval feature. Files: src/ex_docmd.c, src/vim9script.c, src/globals.h, src/main.c, src/autocmd.c, src/buffer.c, src/structs.h, src/menu.c, src/scriptfile.c, src/usercmd.c, src/proto.h, src/errors.h *** ../vim-8.2.2237/src/ex_docmd.c 2020-12-27 19:17:52.507402031 +0100 --- src/ex_docmd.c 2020-12-28 18:01:16.018264652 +0100 *************** *** 304,310 **** # define ex_try ex_ni # define ex_unlet ex_ni # define ex_unlockvar ex_ni - # define ex_vim9script ex_ni # define ex_while ex_ni # define ex_import ex_ni # define ex_export ex_ni --- 304,309 ---- *************** *** 8011,8020 **** msg_scroll = FALSE; // no msg scrolling in Normal mode restart_edit = 0; // don't go to Insert mode p_im = FALSE; // don't use 'insertmode' ! #ifdef FEAT_EVAL sst->save_script_version = current_sctx.sc_version; current_sctx.sc_version = 1; // not in Vim9 script - #endif /* * Save the current typeahead. This is required to allow using ":normal" --- 8010,8018 ---- msg_scroll = FALSE; // no msg scrolling in Normal mode restart_edit = 0; // don't go to Insert mode p_im = FALSE; // don't use 'insertmode' ! sst->save_script_version = current_sctx.sc_version; current_sctx.sc_version = 1; // not in Vim9 script /* * Save the current typeahead. This is required to allow using ":normal" *************** *** 8038,8046 **** opcount = sst->save_opcount; reg_executing = sst->save_reg_executing; msg_didout |= sst->save_msg_didout; // don't reset msg_didout now - #ifdef FEAT_EVAL current_sctx.sc_version = sst->save_script_version; - #endif // Restore the state (needed when called from a function executed for // 'indentexpr'). Update the mouse and cursor, they may have changed. --- 8036,8042 ---- *** ../vim-8.2.2237/src/vim9script.c 2020-12-27 13:39:44.659044653 +0100 --- src/vim9script.c 2020-12-28 18:08:49.320558889 +0100 *************** *** 13,21 **** #include "vim.h" ! #if defined(FEAT_EVAL) || defined(PROTO) ! ! #include "vim9.h" int in_vim9script(void) --- 13,21 ---- #include "vim.h" ! #if defined(FEAT_EVAL) ! # include "vim9.h" ! #endif int in_vim9script(void) *************** *** 30,37 **** * ":vim9script". */ void ! ex_vim9script(exarg_T *eap) { int sid = current_sctx.sc_sid; scriptitem_T *si; --- 30,38 ---- * ":vim9script". */ void ! ex_vim9script(exarg_T *eap UNUSED) { + #ifdef FEAT_EVAL int sid = current_sctx.sc_sid; scriptitem_T *si; *************** *** 75,80 **** --- 76,85 ---- si->sn_save_cpo = vim_strsave(p_cpo); set_option_value((char_u *)"cpo", 0L, (char_u *)CPO_VIM, 0); } + #else + // No check for this being the first command, it doesn't matter. + current_sctx.sc_version = SCRIPT_VERSION_VIM9; + #endif } /* *************** *** 91,103 **** case CMD_insert: case CMD_t: case CMD_xit: ! semsg(_(e_missing_var_str), eap->cmd); return FAIL; default: break; } return OK; } /* * ":export let Name: type" * ":export const Name: type" --- 96,110 ---- case CMD_insert: case CMD_t: case CMD_xit: ! semsg(_(e_command_not_supported_in_vim9_script_missing_var_str), eap->cmd); return FAIL; default: break; } return OK; } + #if defined(FEAT_EVAL) || defined(PROTO) + /* * ":export let Name: type" * ":export const Name: type" *** ../vim-8.2.2237/src/globals.h 2020-12-25 13:20:36.795341032 +0100 --- src/globals.h 2020-12-28 18:10:22.084220080 +0100 *************** *** 290,295 **** --- 290,303 ---- // line number in the message source or zero #define SOURCING_LNUM (((estack_T *)exestack.ga_data)[exestack.ga_len - 1].es_lnum) + // Script CTX being sourced or was sourced to define the current function. + EXTERN sctx_T current_sctx + #ifdef FEAT_EVAL + INIT4(0, 0, 0, 0); + #else + INIT(= {0}); + #endif + #ifdef FEAT_EVAL // whether inside compile_def_function() EXTERN int estack_compiling INIT(= FALSE); *************** *** 392,400 **** EXTERN int want_garbage_collect INIT(= FALSE); EXTERN int garbage_collect_at_exit INIT(= FALSE); - // Script CTX being sourced or was sourced to define the current function. - EXTERN sctx_T current_sctx INIT4(0, 0, 0, 0); - // Commonly used types. EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL); --- 400,405 ---- *** ../vim-8.2.2237/src/main.c 2020-12-08 19:36:17.810905137 +0100 --- src/main.c 2020-12-28 18:12:20.803789724 +0100 *************** *** 3269,3277 **** int is_viminit) // when TRUE, called for VIMINIT { char_u *initstr; - #ifdef FEAT_EVAL sctx_T save_current_sctx; ! #endif ESTACK_CHECK_DECLARATION if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) --- 3269,3276 ---- int is_viminit) // when TRUE, called for VIMINIT { char_u *initstr; sctx_T save_current_sctx; ! ESTACK_CHECK_DECLARATION if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) *************** *** 3280,3299 **** vimrc_found(NULL, NULL); estack_push(ETYPE_ENV, env, 0); ESTACK_CHECK_SETUP - #ifdef FEAT_EVAL save_current_sctx = current_sctx; current_sctx.sc_sid = SID_ENV; current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; - current_sctx.sc_version = 1; #endif do_cmdline_cmd(initstr); ESTACK_CHECK_NOW estack_pop(); - #ifdef FEAT_EVAL current_sctx = save_current_sctx; - #endif return OK; } return FAIL; --- 3279,3297 ---- vimrc_found(NULL, NULL); estack_push(ETYPE_ENV, env, 0); ESTACK_CHECK_SETUP save_current_sctx = current_sctx; + current_sctx.sc_version = 1; + #ifdef FEAT_EVAL current_sctx.sc_sid = SID_ENV; current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; #endif + do_cmdline_cmd(initstr); ESTACK_CHECK_NOW estack_pop(); current_sctx = save_current_sctx; return OK; } return FAIL; *** ../vim-8.2.2237/src/autocmd.c 2020-12-11 19:30:26.785393308 +0100 --- src/autocmd.c 2020-12-28 17:57:49.767086151 +0100 *************** *** 55,63 **** char once; // "One shot": removed after execution char nested; // If autocommands nest here. char last; // last command in list - #ifdef FEAT_EVAL sctx_T script_ctx; // script context where defined - #endif struct AutoCmd *next; // next AutoCmd in list } AutoCmd; --- 55,61 ---- *************** *** 1249,1256 **** if (ac == NULL) return FAIL; ac->cmd = vim_strsave(cmd); - #ifdef FEAT_EVAL ac->script_ctx = current_sctx; ac->script_ctx.sc_lnum += SOURCING_LNUM; #endif if (ac->cmd == NULL) --- 1247,1254 ---- if (ac == NULL) return FAIL; ac->cmd = vim_strsave(cmd); ac->script_ctx = current_sctx; + #ifdef FEAT_EVAL ac->script_ctx.sc_lnum += SOURCING_LNUM; #endif if (ac->cmd == NULL) *************** *** 1819,1826 **** static int nesting = 0; AutoPatCmd patcmd; AutoPat *ap; - #ifdef FEAT_EVAL sctx_T save_current_sctx; funccal_entry_T funccal_entry; char_u *save_cmdarg; long save_cmdbang; --- 1817,1824 ---- static int nesting = 0; AutoPatCmd patcmd; AutoPat *ap; sctx_T save_current_sctx; + #ifdef FEAT_EVAL funccal_entry_T funccal_entry; char_u *save_cmdarg; long save_cmdbang; *************** *** 2029,2037 **** estack_push(ETYPE_AUCMD, NULL, 0); ESTACK_CHECK_SETUP - #ifdef FEAT_EVAL save_current_sctx = current_sctx; # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) prof_child_enter(&wait_time); // doesn't count for the caller itself --- 2027,2035 ---- estack_push(ETYPE_AUCMD, NULL, 0); ESTACK_CHECK_SETUP save_current_sctx = current_sctx; + #ifdef FEAT_EVAL # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) prof_child_enter(&wait_time); // doesn't count for the caller itself *************** *** 2138,2145 **** autocmd_fname_full = save_autocmd_fname_full; autocmd_bufnr = save_autocmd_bufnr; autocmd_match = save_autocmd_match; - #ifdef FEAT_EVAL current_sctx = save_current_sctx; restore_funccal(); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) --- 2136,2143 ---- autocmd_fname_full = save_autocmd_fname_full; autocmd_bufnr = save_autocmd_bufnr; autocmd_match = save_autocmd_match; current_sctx = save_current_sctx; + #ifdef FEAT_EVAL restore_funccal(); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) *************** *** 2370,2378 **** if (ac->once) au_del_cmd(ac); autocmd_nested = ac->nested; - #ifdef FEAT_EVAL current_sctx = ac->script_ctx; - #endif if (ac->last) acp->nextcmd = NULL; else --- 2368,2374 ---- *** ../vim-8.2.2237/src/buffer.c 2020-12-21 19:59:04.565197736 +0100 --- src/buffer.c 2020-12-28 17:58:13.182990787 +0100 *************** *** 5371,5379 **** int vers; int end; int retval = OK; - #ifdef FEAT_EVAL sctx_T save_current_sctx; ! #endif ESTACK_CHECK_DECLARATION prev = -1; --- 5371,5378 ---- int vers; int end; int retval = OK; sctx_T save_current_sctx; ! ESTACK_CHECK_DECLARATION prev = -1; *************** *** 5457,5478 **** if (*s != NUL) // skip over an empty "::" { int secure_save = secure; ! #ifdef FEAT_EVAL save_current_sctx = current_sctx; current_sctx.sc_sid = SID_MODELINE; current_sctx.sc_seq = 0; current_sctx.sc_lnum = lnum; - current_sctx.sc_version = 1; #endif // Make sure no risky things are executed as a side effect. secure = 1; retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); secure = secure_save; - #ifdef FEAT_EVAL current_sctx = save_current_sctx; - #endif if (retval == FAIL) // stop if error found break; } --- 5456,5477 ---- if (*s != NUL) // skip over an empty "::" { int secure_save = secure; ! save_current_sctx = current_sctx; + current_sctx.sc_version = 1; + #ifdef FEAT_EVAL current_sctx.sc_sid = SID_MODELINE; current_sctx.sc_seq = 0; current_sctx.sc_lnum = lnum; #endif + // Make sure no risky things are executed as a side effect. secure = 1; retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); secure = secure_save; current_sctx = save_current_sctx; if (retval == FAIL) // stop if error found break; } *** ../vim-8.2.2237/src/structs.h 2020-12-27 13:39:44.659044653 +0100 --- src/structs.h 2020-12-28 18:00:31.806437530 +0100 *************** *** 83,91 **** --- 83,93 ---- * sc_version is also here, for convenience. */ typedef struct { + #ifdef FEAT_EVAL scid_T sc_sid; // script ID int sc_seq; // sourcing sequence number linenr_T sc_lnum; // line number + #endif int sc_version; // :scriptversion } sctx_T; *************** *** 1224,1231 **** char m_silent; // used, don't echo commands char m_nowait; // used #ifdef FEAT_EVAL - char m_expr; // used, m_str is an expression sctx_T m_script_ctx; // SCTX where map was defined #endif }; --- 1226,1233 ---- char m_silent; // used, don't echo commands char m_nowait; // used #ifdef FEAT_EVAL sctx_T m_script_ctx; // SCTX where map was defined + char m_expr; // used, m_str is an expression #endif }; *************** *** 1567,1572 **** --- 1569,1576 ---- GETLINE_CONCAT_ALL // concatenate continuation and Vim9 # comment lines } getline_opt_T; + typedef struct svar_S svar_T; + #if defined(FEAT_EVAL) || defined(PROTO) typedef struct funccall_S funccall_T; *************** *** 1766,1778 **** /* * Entry for "sn_var_vals". Used for script-local variables. */ ! typedef struct { char_u *sv_name; // points into "sn_all_vars" di_key typval_T *sv_tv; // points into "sn_vars" or "sn_all_vars" di_tv type_T *sv_type; int sv_const; int sv_export; // "export let var = val" ! } svar_T; typedef struct { char_u *imp_name; // name imported as (allocated) --- 1770,1782 ---- /* * Entry for "sn_var_vals". Used for script-local variables. */ ! struct svar_S { char_u *sv_name; // points into "sn_all_vars" di_key typval_T *sv_tv; // points into "sn_vars" or "sn_all_vars" di_tv type_T *sv_type; int sv_const; int sv_export; // "export let var = val" ! }; typedef struct { char_u *imp_name; // name imported as (allocated) *************** *** 4164,4172 **** int save_finish_op; int save_opcount; int save_reg_executing; - #ifdef FEAT_EVAL int save_script_version; - #endif tasave_T tabuf; } save_state_T; --- 4168,4174 ---- *** ../vim-8.2.2237/src/menu.c 2020-09-28 22:29:25.421766301 +0200 --- src/menu.c 2020-12-28 17:35:48.247473972 +0100 *************** *** 2310,2320 **** if (idx < 0) { // Use the Insert mode entry when returning to Insert mode. ! if (restart_edit ! #ifdef FEAT_EVAL ! && !current_sctx.sc_sid ! #endif ! ) { idx = MENU_INDEX_INSERT; } --- 2310,2316 ---- if (idx < 0) { // Use the Insert mode entry when returning to Insert mode. ! if (restart_edit && !current_sctx.sc_sid) { idx = MENU_INDEX_INSERT; } *************** *** 2384,2394 **** // When executing a script or function execute the commands right now. // Also for the window toolbar. // Otherwise put them in the typeahead buffer. ! if (eap == NULL ! #ifdef FEAT_EVAL ! || current_sctx.sc_sid != 0 ! #endif ! ) { save_state_T save_state; --- 2380,2386 ---- // When executing a script or function execute the commands right now. // Also for the window toolbar. // Otherwise put them in the typeahead buffer. ! if (eap == NULL || current_sctx.sc_sid != 0) { save_state_T save_state; *** ../vim-8.2.2237/src/scriptfile.c 2020-12-28 15:41:37.167352395 +0100 --- src/scriptfile.c 2020-12-28 17:47:38.057211157 +0100 *************** *** 1135,1142 **** char_u *fname_exp; char_u *firstline = NULL; int retval = FAIL; - #ifdef FEAT_EVAL sctx_T save_current_sctx; static scid_T last_current_SID = 0; static int last_current_SID_seq = 0; funccal_entry_T funccalp_entry; --- 1135,1142 ---- char_u *fname_exp; char_u *firstline = NULL; int retval = FAIL; sctx_T save_current_sctx; + #ifdef FEAT_EVAL static scid_T last_current_SID = 0; static int last_current_SID_seq = 0; funccal_entry_T funccalp_entry; *************** *** 1300,1305 **** --- 1300,1308 ---- time_push(&tv_rel, &tv_start); #endif + save_current_sctx = current_sctx; + current_sctx.sc_version = 1; // default script version + #ifdef FEAT_EVAL # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) *************** *** 1310,1318 **** // Also starts profiling timer for nested script. save_funccal(&funccalp_entry); - save_current_sctx = current_sctx; current_sctx.sc_lnum = 0; - current_sctx.sc_version = 1; // default script version // Check if this script was sourced before to finds its SID. // Always use a new sequence number. --- 1313,1319 ---- *************** *** 1326,1332 **** // loading the same script again si->sn_state = SN_STATE_RELOAD; - si->sn_version = 1; current_sctx.sc_sid = sid; // Script-local variables remain but "const" can be set again. --- 1327,1332 ---- *************** *** 1484,1496 **** CLEAR_POINTER(si->sn_save_cpo); } - current_sctx = save_current_sctx; restore_funccal(); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) prof_child_exit(&wait_start); // leaving a child now # endif #endif fclose(cookie.fp); vim_free(cookie.nextline); vim_free(firstline); --- 1484,1497 ---- CLEAR_POINTER(si->sn_save_cpo); } restore_funccal(); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) prof_child_exit(&wait_start); // leaving a child now # endif #endif + current_sctx = save_current_sctx; + fclose(cookie.fp); vim_free(cookie.nextline); vim_free(firstline); *************** *** 1903,1909 **** void ex_scriptversion(exarg_T *eap UNUSED) { - #ifdef FEAT_EVAL int nr; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) --- 1904,1909 ---- *************** *** 1925,1933 **** else { current_sctx.sc_version = nr; SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = nr; - } #endif } #if defined(FEAT_EVAL) || defined(PROTO) --- 1925,1934 ---- else { current_sctx.sc_version = nr; + #ifdef FEAT_EVAL SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = nr; #endif + } } #if defined(FEAT_EVAL) || defined(PROTO) *** ../vim-8.2.2237/src/usercmd.c 2020-10-26 18:46:49.480589241 +0100 --- src/usercmd.c 2020-12-28 17:50:34.352629522 +0100 *************** *** 21,28 **** long uc_def; // The default value for a range/count int uc_compl; // completion type cmd_addr_T uc_addr_type; // The command's address type - # ifdef FEAT_EVAL sctx_T uc_script_ctx; // SCTX where the command was defined char_u *uc_compl_arg; // completion argument if any # endif } ucmd_T; --- 21,28 ---- long uc_def; // The default value for a range/count int uc_compl; // completion type cmd_addr_T uc_addr_type; // The command's address type sctx_T uc_script_ctx; // SCTX where the command was defined + # ifdef FEAT_EVAL char_u *uc_compl_arg; // completion argument if any # endif } ucmd_T; *************** *** 954,961 **** cmd->uc_argt = argt; cmd->uc_def = def; cmd->uc_compl = compl; - #ifdef FEAT_EVAL cmd->uc_script_ctx = current_sctx; cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; cmd->uc_compl_arg = compl_arg; #endif --- 954,961 ---- cmd->uc_argt = argt; cmd->uc_def = def; cmd->uc_compl = compl; cmd->uc_script_ctx = current_sctx; + #ifdef FEAT_EVAL cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; cmd->uc_compl_arg = compl_arg; #endif *************** *** 1573,1581 **** size_t split_len = 0; char_u *split_buf = NULL; ucmd_T *cmd; - #ifdef FEAT_EVAL sctx_T save_current_sctx = current_sctx; - #endif if (eap->cmdidx == CMD_USER) cmd = USER_CMD(eap->useridx); --- 1573,1579 ---- *************** *** 1674,1688 **** } } #ifdef FEAT_EVAL current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid; - current_sctx.sc_version = cmd->uc_script_ctx.sc_version; #endif (void)do_cmdline(buf, eap->getline, eap->cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); - #ifdef FEAT_EVAL current_sctx = save_current_sctx; - #endif vim_free(buf); vim_free(split_buf); } --- 1672,1684 ---- } } + current_sctx.sc_version = cmd->uc_script_ctx.sc_version; #ifdef FEAT_EVAL current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid; #endif (void)do_cmdline(buf, eap->getline, eap->cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); current_sctx = save_current_sctx; vim_free(buf); vim_free(split_buf); } *** ../vim-8.2.2237/src/proto.h 2020-09-05 15:48:32.469546692 +0200 --- src/proto.h 2020-12-28 17:59:20.718718993 +0100 *************** *** 233,242 **** # include "usercmd.pro" # include "userfunc.pro" # include "version.pro" # ifdef FEAT_EVAL # include "vim9compile.pro" # include "vim9execute.pro" - # include "vim9script.pro" # include "vim9type.pro" # endif # include "window.pro" --- 233,242 ---- # include "usercmd.pro" # include "userfunc.pro" # include "version.pro" + # include "vim9script.pro" # ifdef FEAT_EVAL # include "vim9compile.pro" # include "vim9execute.pro" # include "vim9type.pro" # endif # include "window.pro" *** ../vim-8.2.2237/src/errors.h 2020-12-26 20:09:11.282465257 +0100 --- src/errors.h 2020-12-28 18:08:54.588539578 +0100 *************** *** 31,38 **** INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings")); EXTERN char e_cannot_index_special_variable[] INIT(= N_("E909: Cannot index a special variable")); ! EXTERN char e_missing_var_str[] ! INIT(= N_("E1100: Missing :var: %s")); EXTERN char e_variable_not_found_str[] INIT(= N_("E1001: Variable not found: %s")); EXTERN char e_syntax_error_at_str[] --- 31,40 ---- INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings")); EXTERN char e_cannot_index_special_variable[] INIT(= N_("E909: Cannot index a special variable")); ! #endif ! EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[] ! INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s")); ! #ifdef FEAT_EVAL EXTERN char e_variable_not_found_str[] INIT(= N_("E1001: Variable not found: %s")); EXTERN char e_syntax_error_at_str[] *************** *** 113,120 **** --- 115,124 ---- INIT(= N_("E1038: \"vim9script\" can only be used in a script")); EXTERN char e_vim9script_must_be_first_command_in_script[] INIT(= N_("E1039: \"vim9script\" must be the first command in a script")); + #endif EXTERN char e_cannot_use_scriptversion_after_vim9script[] INIT(= N_("E1040: Cannot use :scriptversion after :vim9script")); + #ifdef FEAT_EVAL EXTERN char e_redefining_script_item_str[] INIT(= N_("E1041: Redefining script item %s")); EXTERN char e_export_can_only_be_used_in_vim9script[] *** ../vim-8.2.2237/src/version.c 2020-12-28 15:46:43.813922887 +0100 --- src/version.c 2020-12-28 18:23:33.921390391 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2238, /**/ -- Everyone has a photographic memory. Some don't have film. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///