Skip to content

Commit 9b8d622

Browse files
committed
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Problem: Vim9: cannot load a Vim9 script without the +eval feature. Solution: Support Vim9 script syntax without the +eval feature.
1 parent ed1e4c9 commit 9b8d622

13 files changed

Lines changed: 63 additions & 65 deletions

File tree

src/autocmd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ typedef struct AutoCmd
5555
char once; // "One shot": removed after execution
5656
char nested; // If autocommands nest here.
5757
char last; // last command in list
58-
#ifdef FEAT_EVAL
5958
sctx_T script_ctx; // script context where defined
60-
#endif
6159
struct AutoCmd *next; // next AutoCmd in list
6260
} AutoCmd;
6361

@@ -1249,8 +1247,8 @@ do_autocmd_event(
12491247
if (ac == NULL)
12501248
return FAIL;
12511249
ac->cmd = vim_strsave(cmd);
1252-
#ifdef FEAT_EVAL
12531250
ac->script_ctx = current_sctx;
1251+
#ifdef FEAT_EVAL
12541252
ac->script_ctx.sc_lnum += SOURCING_LNUM;
12551253
#endif
12561254
if (ac->cmd == NULL)
@@ -1819,8 +1817,8 @@ apply_autocmds_group(
18191817
static int nesting = 0;
18201818
AutoPatCmd patcmd;
18211819
AutoPat *ap;
1822-
#ifdef FEAT_EVAL
18231820
sctx_T save_current_sctx;
1821+
#ifdef FEAT_EVAL
18241822
funccal_entry_T funccal_entry;
18251823
char_u *save_cmdarg;
18261824
long save_cmdbang;
@@ -2029,9 +2027,9 @@ apply_autocmds_group(
20292027
estack_push(ETYPE_AUCMD, NULL, 0);
20302028
ESTACK_CHECK_SETUP
20312029

2032-
#ifdef FEAT_EVAL
20332030
save_current_sctx = current_sctx;
20342031

2032+
#ifdef FEAT_EVAL
20352033
# ifdef FEAT_PROFILE
20362034
if (do_profiling == PROF_YES)
20372035
prof_child_enter(&wait_time); // doesn't count for the caller itself
@@ -2138,8 +2136,8 @@ apply_autocmds_group(
21382136
autocmd_fname_full = save_autocmd_fname_full;
21392137
autocmd_bufnr = save_autocmd_bufnr;
21402138
autocmd_match = save_autocmd_match;
2141-
#ifdef FEAT_EVAL
21422139
current_sctx = save_current_sctx;
2140+
#ifdef FEAT_EVAL
21432141
restore_funccal();
21442142
# ifdef FEAT_PROFILE
21452143
if (do_profiling == PROF_YES)
@@ -2370,9 +2368,7 @@ getnextac(
23702368
if (ac->once)
23712369
au_del_cmd(ac);
23722370
autocmd_nested = ac->nested;
2373-
#ifdef FEAT_EVAL
23742371
current_sctx = ac->script_ctx;
2375-
#endif
23762372
if (ac->last)
23772373
acp->nextcmd = NULL;
23782374
else

src/buffer.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,9 +5371,8 @@ chk_modeline(
53715371
int vers;
53725372
int end;
53735373
int retval = OK;
5374-
#ifdef FEAT_EVAL
53755374
sctx_T save_current_sctx;
5376-
#endif
5375+
53775376
ESTACK_CHECK_DECLARATION
53785377

53795378
prev = -1;
@@ -5457,22 +5456,22 @@ chk_modeline(
54575456
if (*s != NUL) // skip over an empty "::"
54585457
{
54595458
int secure_save = secure;
5460-
#ifdef FEAT_EVAL
5459+
54615460
save_current_sctx = current_sctx;
5461+
current_sctx.sc_version = 1;
5462+
#ifdef FEAT_EVAL
54625463
current_sctx.sc_sid = SID_MODELINE;
54635464
current_sctx.sc_seq = 0;
54645465
current_sctx.sc_lnum = lnum;
5465-
current_sctx.sc_version = 1;
54665466
#endif
5467+
54675468
// Make sure no risky things are executed as a side effect.
54685469
secure = 1;
54695470

54705471
retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
54715472

54725473
secure = secure_save;
5473-
#ifdef FEAT_EVAL
54745474
current_sctx = save_current_sctx;
5475-
#endif
54765475
if (retval == FAIL) // stop if error found
54775476
break;
54785477
}

src/errors.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ EXTERN char e_assert_fails_second_arg[]
3131
INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"));
3232
EXTERN char e_cannot_index_special_variable[]
3333
INIT(= N_("E909: Cannot index a special variable"));
34-
EXTERN char e_missing_var_str[]
35-
INIT(= N_("E1100: Missing :var: %s"));
34+
#endif
35+
EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[]
36+
INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s"));
37+
#ifdef FEAT_EVAL
3638
EXTERN char e_variable_not_found_str[]
3739
INIT(= N_("E1001: Variable not found: %s"));
3840
EXTERN char e_syntax_error_at_str[]
@@ -113,8 +115,10 @@ EXTERN char e_vim9script_can_only_be_used_in_script[]
113115
INIT(= N_("E1038: \"vim9script\" can only be used in a script"));
114116
EXTERN char e_vim9script_must_be_first_command_in_script[]
115117
INIT(= N_("E1039: \"vim9script\" must be the first command in a script"));
118+
#endif
116119
EXTERN char e_cannot_use_scriptversion_after_vim9script[]
117120
INIT(= N_("E1040: Cannot use :scriptversion after :vim9script"));
121+
#ifdef FEAT_EVAL
118122
EXTERN char e_redefining_script_item_str[]
119123
INIT(= N_("E1041: Redefining script item %s"));
120124
EXTERN char e_export_can_only_be_used_in_vim9script[]

src/ex_docmd.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ static void ex_tag_cmd(exarg_T *eap, char_u *name);
304304
# define ex_try ex_ni
305305
# define ex_unlet ex_ni
306306
# define ex_unlockvar ex_ni
307-
# define ex_vim9script ex_ni
308307
# define ex_while ex_ni
309308
# define ex_import ex_ni
310309
# define ex_export ex_ni
@@ -8011,10 +8010,9 @@ save_current_state(save_state_T *sst)
80118010
msg_scroll = FALSE; // no msg scrolling in Normal mode
80128011
restart_edit = 0; // don't go to Insert mode
80138012
p_im = FALSE; // don't use 'insertmode'
8014-
#ifdef FEAT_EVAL
8013+
80158014
sst->save_script_version = current_sctx.sc_version;
80168015
current_sctx.sc_version = 1; // not in Vim9 script
8017-
#endif
80188016

80198017
/*
80208018
* Save the current typeahead. This is required to allow using ":normal"
@@ -8038,9 +8036,7 @@ restore_current_state(save_state_T *sst)
80388036
opcount = sst->save_opcount;
80398037
reg_executing = sst->save_reg_executing;
80408038
msg_didout |= sst->save_msg_didout; // don't reset msg_didout now
8041-
#ifdef FEAT_EVAL
80428039
current_sctx.sc_version = sst->save_script_version;
8043-
#endif
80448040

80458041
// Restore the state (needed when called from a function executed for
80468042
// 'indentexpr'). Update the mouse and cursor, they may have changed.

src/globals.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ EXTERN garray_T exestack INIT5(0, 0, sizeof(estack_T), 50, NULL);
290290
// line number in the message source or zero
291291
#define SOURCING_LNUM (((estack_T *)exestack.ga_data)[exestack.ga_len - 1].es_lnum)
292292

293+
// Script CTX being sourced or was sourced to define the current function.
294+
EXTERN sctx_T current_sctx
295+
#ifdef FEAT_EVAL
296+
INIT4(0, 0, 0, 0);
297+
#else
298+
INIT(= {0});
299+
#endif
300+
293301
#ifdef FEAT_EVAL
294302
// whether inside compile_def_function()
295303
EXTERN int estack_compiling INIT(= FALSE);
@@ -392,9 +400,6 @@ EXTERN int may_garbage_collect INIT(= FALSE);
392400
EXTERN int want_garbage_collect INIT(= FALSE);
393401
EXTERN int garbage_collect_at_exit INIT(= FALSE);
394402

395-
// Script CTX being sourced or was sourced to define the current function.
396-
EXTERN sctx_T current_sctx INIT4(0, 0, 0, 0);
397-
398403

399404
// Commonly used types.
400405
EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL);

src/main.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,9 +3269,8 @@ process_env(
32693269
int is_viminit) // when TRUE, called for VIMINIT
32703270
{
32713271
char_u *initstr;
3272-
#ifdef FEAT_EVAL
32733272
sctx_T save_current_sctx;
3274-
#endif
3273+
32753274
ESTACK_CHECK_DECLARATION
32763275

32773276
if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL)
@@ -3280,20 +3279,19 @@ process_env(
32803279
vimrc_found(NULL, NULL);
32813280
estack_push(ETYPE_ENV, env, 0);
32823281
ESTACK_CHECK_SETUP
3283-
#ifdef FEAT_EVAL
32843282
save_current_sctx = current_sctx;
3283+
current_sctx.sc_version = 1;
3284+
#ifdef FEAT_EVAL
32853285
current_sctx.sc_sid = SID_ENV;
32863286
current_sctx.sc_seq = 0;
32873287
current_sctx.sc_lnum = 0;
3288-
current_sctx.sc_version = 1;
32893288
#endif
3289+
32903290
do_cmdline_cmd(initstr);
32913291

32923292
ESTACK_CHECK_NOW
32933293
estack_pop();
3294-
#ifdef FEAT_EVAL
32953294
current_sctx = save_current_sctx;
3296-
#endif
32973295
return OK;
32983296
}
32993297
return FAIL;

src/menu.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,11 +2310,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
23102310
if (idx < 0)
23112311
{
23122312
// Use the Insert mode entry when returning to Insert mode.
2313-
if (restart_edit
2314-
#ifdef FEAT_EVAL
2315-
&& !current_sctx.sc_sid
2316-
#endif
2317-
)
2313+
if (restart_edit && !current_sctx.sc_sid)
23182314
{
23192315
idx = MENU_INDEX_INSERT;
23202316
}
@@ -2384,11 +2380,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
23842380
// When executing a script or function execute the commands right now.
23852381
// Also for the window toolbar.
23862382
// Otherwise put them in the typeahead buffer.
2387-
if (eap == NULL
2388-
#ifdef FEAT_EVAL
2389-
|| current_sctx.sc_sid != 0
2390-
#endif
2391-
)
2383+
if (eap == NULL || current_sctx.sc_sid != 0)
23922384
{
23932385
save_state_T save_state;
23942386

src/proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ void mbyte_im_set_active(int active_arg);
233233
# include "usercmd.pro"
234234
# include "userfunc.pro"
235235
# include "version.pro"
236+
# include "vim9script.pro"
236237
# ifdef FEAT_EVAL
237238
# include "vim9compile.pro"
238239
# include "vim9execute.pro"
239-
# include "vim9script.pro"
240240
# include "vim9type.pro"
241241
# endif
242242
# include "window.pro"

src/scriptfile.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,8 @@ do_source(
11351135
char_u *fname_exp;
11361136
char_u *firstline = NULL;
11371137
int retval = FAIL;
1138-
#ifdef FEAT_EVAL
11391138
sctx_T save_current_sctx;
1139+
#ifdef FEAT_EVAL
11401140
static scid_T last_current_SID = 0;
11411141
static int last_current_SID_seq = 0;
11421142
funccal_entry_T funccalp_entry;
@@ -1300,6 +1300,9 @@ do_source(
13001300
time_push(&tv_rel, &tv_start);
13011301
#endif
13021302

1303+
save_current_sctx = current_sctx;
1304+
current_sctx.sc_version = 1; // default script version
1305+
13031306
#ifdef FEAT_EVAL
13041307
# ifdef FEAT_PROFILE
13051308
if (do_profiling == PROF_YES)
@@ -1310,9 +1313,7 @@ do_source(
13101313
// Also starts profiling timer for nested script.
13111314
save_funccal(&funccalp_entry);
13121315

1313-
save_current_sctx = current_sctx;
13141316
current_sctx.sc_lnum = 0;
1315-
current_sctx.sc_version = 1; // default script version
13161317

13171318
// Check if this script was sourced before to finds its SID.
13181319
// Always use a new sequence number.
@@ -1326,7 +1327,6 @@ do_source(
13261327

13271328
// loading the same script again
13281329
si->sn_state = SN_STATE_RELOAD;
1329-
si->sn_version = 1;
13301330
current_sctx.sc_sid = sid;
13311331

13321332
// Script-local variables remain but "const" can be set again.
@@ -1484,13 +1484,14 @@ do_source(
14841484
CLEAR_POINTER(si->sn_save_cpo);
14851485
}
14861486

1487-
current_sctx = save_current_sctx;
14881487
restore_funccal();
14891488
# ifdef FEAT_PROFILE
14901489
if (do_profiling == PROF_YES)
14911490
prof_child_exit(&wait_start); // leaving a child now
14921491
# endif
14931492
#endif
1493+
current_sctx = save_current_sctx;
1494+
14941495
fclose(cookie.fp);
14951496
vim_free(cookie.nextline);
14961497
vim_free(firstline);
@@ -1903,7 +1904,6 @@ ex_scriptencoding(exarg_T *eap)
19031904
void
19041905
ex_scriptversion(exarg_T *eap UNUSED)
19051906
{
1906-
#ifdef FEAT_EVAL
19071907
int nr;
19081908

19091909
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
@@ -1925,9 +1925,10 @@ ex_scriptversion(exarg_T *eap UNUSED)
19251925
else
19261926
{
19271927
current_sctx.sc_version = nr;
1928+
#ifdef FEAT_EVAL
19281929
SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = nr;
1929-
}
19301930
#endif
1931+
}
19311932
}
19321933

19331934
#if defined(FEAT_EVAL) || defined(PROTO)

src/structs.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ typedef struct VimMenu vimmenu_T;
8383
* sc_version is also here, for convenience.
8484
*/
8585
typedef struct {
86+
#ifdef FEAT_EVAL
8687
scid_T sc_sid; // script ID
8788
int sc_seq; // sourcing sequence number
8889
linenr_T sc_lnum; // line number
90+
#endif
8991
int sc_version; // :scriptversion
9092
} sctx_T;
9193

@@ -1224,8 +1226,8 @@ struct mapblock
12241226
char m_silent; // <silent> used, don't echo commands
12251227
char m_nowait; // <nowait> used
12261228
#ifdef FEAT_EVAL
1227-
char m_expr; // <expr> used, m_str is an expression
12281229
sctx_T m_script_ctx; // SCTX where map was defined
1230+
char m_expr; // <expr> used, m_str is an expression
12291231
#endif
12301232
};
12311233

@@ -1567,6 +1569,8 @@ typedef enum {
15671569
GETLINE_CONCAT_ALL // concatenate continuation and Vim9 # comment lines
15681570
} getline_opt_T;
15691571

1572+
typedef struct svar_S svar_T;
1573+
15701574
#if defined(FEAT_EVAL) || defined(PROTO)
15711575
typedef struct funccall_S funccall_T;
15721576

@@ -1766,13 +1770,13 @@ struct sallvar_S {
17661770
/*
17671771
* Entry for "sn_var_vals". Used for script-local variables.
17681772
*/
1769-
typedef struct {
1773+
struct svar_S {
17701774
char_u *sv_name; // points into "sn_all_vars" di_key
17711775
typval_T *sv_tv; // points into "sn_vars" or "sn_all_vars" di_tv
17721776
type_T *sv_type;
17731777
int sv_const;
17741778
int sv_export; // "export let var = val"
1775-
} svar_T;
1779+
};
17761780

17771781
typedef struct {
17781782
char_u *imp_name; // name imported as (allocated)
@@ -4164,9 +4168,7 @@ typedef struct {
41644168
int save_finish_op;
41654169
int save_opcount;
41664170
int save_reg_executing;
4167-
#ifdef FEAT_EVAL
41684171
int save_script_version;
4169-
#endif
41704172
tasave_T tabuf;
41714173
} save_state_T;
41724174

0 commit comments

Comments
 (0)