]> granicus.if.org Git - vim/commitdiff
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature v8.2.2238
authorBram Moolenaar <Bram@vim.org>
Mon, 28 Dec 2020 17:26:00 +0000 (18:26 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 28 Dec 2020 17:26:00 +0000 (18:26 +0100)
Problem:    Vim9: cannot load a Vim9 script without the +eval feature.
Solution:   Support Vim9 script syntax without the +eval feature.

13 files changed:
src/autocmd.c
src/buffer.c
src/errors.h
src/ex_docmd.c
src/globals.h
src/main.c
src/menu.c
src/proto.h
src/scriptfile.c
src/structs.h
src/usercmd.c
src/version.c
src/vim9script.c

index c3aa324b34b77d2c57440d98baf870ab059a8b41..f7ca41de4426485270a4657187b172553f97c830 100644 (file)
@@ -55,9 +55,7 @@ typedef struct AutoCmd
     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;
 
@@ -1249,8 +1247,8 @@ do_autocmd_event(
            if (ac == NULL)
                return FAIL;
            ac->cmd = vim_strsave(cmd);
-#ifdef FEAT_EVAL
            ac->script_ctx = current_sctx;
+#ifdef FEAT_EVAL
            ac->script_ctx.sc_lnum += SOURCING_LNUM;
 #endif
            if (ac->cmd == NULL)
@@ -1819,8 +1817,8 @@ apply_autocmds_group(
     static int nesting = 0;
     AutoPatCmd patcmd;
     AutoPat    *ap;
-#ifdef FEAT_EVAL
     sctx_T     save_current_sctx;
+#ifdef FEAT_EVAL
     funccal_entry_T funccal_entry;
     char_u     *save_cmdarg;
     long       save_cmdbang;
@@ -2029,9 +2027,9 @@ apply_autocmds_group(
     estack_push(ETYPE_AUCMD, NULL, 0);
     ESTACK_CHECK_SETUP
 
-#ifdef FEAT_EVAL
     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,8 +2136,8 @@ apply_autocmds_group(
     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;
+#ifdef FEAT_EVAL
     restore_funccal();
 # ifdef FEAT_PROFILE
     if (do_profiling == PROF_YES)
@@ -2370,9 +2368,7 @@ getnextac(
     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
index b3889b79d89f526005b004234b291f983f0cf200..c14aefb0e3cf137aab9cd4e65470121e7f43abf6 100644 (file)
@@ -5371,9 +5371,8 @@ chk_modeline(
     int                vers;
     int                end;
     int                retval = OK;
-#ifdef FEAT_EVAL
     sctx_T     save_current_sctx;
-#endif
+
     ESTACK_CHECK_DECLARATION
 
     prev = -1;
@@ -5457,22 +5456,22 @@ chk_modeline(
            if (*s != NUL)              // skip over an empty "::"
            {
                int secure_save = secure;
-#ifdef FEAT_EVAL
+
                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;
-               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;
            }
index 65450cefd248455a1f4ec8efcca4c5363ffd57a1..4b4245a1bdb62ca7219c2066227756374c71b15d 100644 (file)
@@ -31,8 +31,10 @@ EXTERN char e_assert_fails_second_arg[]
        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"));
+#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,8 +115,10 @@ EXTERN char e_vim9script_can_only_be_used_in_script[]
        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[]
index efbf9a3cf7f3ff742b4c8b2e5c76c91ed76515bd..91d56d71ffdfbb8cccdbc3a56036f5f303b67d53 100644 (file)
@@ -304,7 +304,6 @@ static void ex_tag_cmd(exarg_T *eap, char_u *name);
 # 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
@@ -8011,10 +8010,9 @@ save_current_state(save_state_T *sst)
     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"
@@ -8038,9 +8036,7 @@ restore_current_state(save_state_T *sst)
     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.
index 39ef83e495670d05f43c857f97c7841cfe796e1f..dcb0f63243f70dd747cefff39b52c16660ef3952 100644 (file)
@@ -290,6 +290,14 @@ EXTERN garray_T    exestack INIT5(0, 0, sizeof(estack_T), 50, NULL);
 // 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,9 +400,6 @@ EXTERN int  may_garbage_collect INIT(= FALSE);
 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);
index 6c591b0a9f58a96337213b01248f11be9d65eeb5..ef53b3373b24d74c125b1448a4a6eed7337632c5 100644 (file)
@@ -3269,9 +3269,8 @@ process_env(
     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)
@@ -3280,20 +3279,19 @@ process_env(
            vimrc_found(NULL, NULL);
        estack_push(ETYPE_ENV, env, 0);
        ESTACK_CHECK_SETUP
-#ifdef FEAT_EVAL
        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;
-       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;
index fd811de065556bb026e403c39ac1daa52dfba0c2..4f5e26b3d6dece1586f1100b5562ddabb769a8a9 100644 (file)
@@ -2310,11 +2310,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
     if (idx < 0)
     {
        // Use the Insert mode entry when returning to Insert mode.
-       if (restart_edit
-#ifdef FEAT_EVAL
-               && !current_sctx.sc_sid
-#endif
-               )
+       if (restart_edit && !current_sctx.sc_sid)
        {
            idx = MENU_INDEX_INSERT;
        }
@@ -2384,11 +2380,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
        // 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
-          )
+       if (eap == NULL || current_sctx.sc_sid != 0)
        {
            save_state_T save_state;
 
index 5923d231d26ec03cfa5855ae3784e4bea90db1ed..686a3d63ad9a0594ef3d3e4d1a5b828f211cb96c 100644 (file)
@@ -233,10 +233,10 @@ void mbyte_im_set_active(int active_arg);
 # include "usercmd.pro"
 # include "userfunc.pro"
 # include "version.pro"
+# include "vim9script.pro"
 # ifdef FEAT_EVAL
 #  include "vim9compile.pro"
 #  include "vim9execute.pro"
-#  include "vim9script.pro"
 #  include "vim9type.pro"
 # endif
 # include "window.pro"
index a9b382590acf01ab357e45c5ee51e1588ffaedb4..0f9d5ef8ac9561c9f48156a783fd054bc9a6f094 100644 (file)
@@ -1135,8 +1135,8 @@ do_source(
     char_u                 *fname_exp;
     char_u                 *firstline = NULL;
     int                            retval = FAIL;
-#ifdef FEAT_EVAL
     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,6 +1300,9 @@ do_source(
        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,9 +1313,7 @@ do_source(
     // 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.
@@ -1326,7 +1327,6 @@ do_source(
 
        // 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.
@@ -1484,13 +1484,14 @@ almosttheend:
        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
+    current_sctx = save_current_sctx;
+
     fclose(cookie.fp);
     vim_free(cookie.nextline);
     vim_free(firstline);
@@ -1903,7 +1904,6 @@ ex_scriptencoding(exarg_T *eap)
     void
 ex_scriptversion(exarg_T *eap UNUSED)
 {
-#ifdef FEAT_EVAL
     int                nr;
 
     if (!getline_equal(eap->getline, eap->cookie, getsourceline))
@@ -1925,9 +1925,10 @@ ex_scriptversion(exarg_T *eap UNUSED)
     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)
index ba2bec650fc2730fb79f28d3dc0a3ac44929b401..a6cd34631d834d754d79185d4fe94d2efe5b24a6 100644 (file)
@@ -83,9 +83,11 @@ typedef struct VimMenu vimmenu_T;
  * 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,8 +1226,8 @@ struct mapblock
     char       m_silent;       // <silent> used, don't echo commands
     char       m_nowait;       // <nowait> used
 #ifdef FEAT_EVAL
-    char       m_expr;         // <expr> used, m_str is an expression
     sctx_T     m_script_ctx;   // SCTX where map was defined
+    char       m_expr;         // <expr> used, m_str is an expression
 #endif
 };
 
@@ -1567,6 +1569,8 @@ typedef enum {
     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,13 +1770,13 @@ struct sallvar_S {
 /*
  * Entry for "sn_var_vals".  Used for script-local variables.
  */
-typedef struct {
+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"
-} svar_T;
+};
 
 typedef struct {
     char_u     *imp_name;          // name imported as (allocated)
@@ -4164,9 +4168,7 @@ typedef struct {
     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;
 
index 82b19bb04d918d6e17748645bdac7fe52ed9478c..03e7b245d3840da6ab2a0888ba9248c190805329 100644 (file)
@@ -21,8 +21,8 @@ typedef struct ucmd
     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
+# ifdef FEAT_EVAL
     char_u     *uc_compl_arg;  // completion argument if any
 # endif
 } ucmd_T;
@@ -954,8 +954,8 @@ uc_add_command(
     cmd->uc_argt = argt;
     cmd->uc_def = def;
     cmd->uc_compl = compl;
-#ifdef FEAT_EVAL
     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,9 +1573,7 @@ do_ucmd(exarg_T *eap)
     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);
@@ -1674,15 +1672,13 @@ do_ucmd(exarg_T *eap)
        }
     }
 
+    current_sctx.sc_version = cmd->uc_script_ctx.sc_version;
 #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);
 }
index 89e6afceefe6d9951434b9af3f7f1a46f9302067..04a0f130c2009855743b8c1e0434c48431e345a5 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2238,
 /**/
     2237,
 /**/
index e423b1c8028503ccfea4ced00fcd485b4c1f5106..a2f8ff932b6e19f4fd29a591d8b99f26627bc107 100644 (file)
@@ -13,9 +13,9 @@
 
 #include "vim.h"
 
-#if defined(FEAT_EVAL) || defined(PROTO)
-
-#include "vim9.h"
+#if defined(FEAT_EVAL)
+# include "vim9.h"
+#endif
 
     int
 in_vim9script(void)
@@ -30,8 +30,9 @@ in_vim9script(void)
  * ":vim9script".
  */
     void
-ex_vim9script(exarg_T *eap)
+ex_vim9script(exarg_T *eap UNUSED)
 {
+#ifdef FEAT_EVAL
     int                    sid = current_sctx.sc_sid;
     scriptitem_T    *si;
 
@@ -75,6 +76,10 @@ ex_vim9script(exarg_T *eap)
        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,13 +96,15 @@ not_in_vim9(exarg_T *eap)
            case CMD_insert:
            case CMD_t:
            case CMD_xit:
-               semsg(_(e_missing_var_str), eap->cmd);
+               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"