blob: 57cbfead331e268dbe6f83cb307789702dcd4408 [file] [log] [blame]
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * vim9.h: types and globals used for Vim9 script.
12 */
13
14typedef enum {
15 ISN_EXEC, // execute Ex command line isn_arg.string
Bram Moolenaarad39c092020-02-26 18:23:43 +010016 ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
17 ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010018
19 // get and set variables
20 ISN_LOAD, // push local variable isn_arg.number
21 ISN_LOADV, // push v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010022 ISN_LOADG, // push g: variable isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010023 ISN_LOADS, // push s: variable isn_arg.loadstore
24 ISN_LOADSCRIPT, // push script-local variable isn_arg.script.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010025 ISN_LOADOPT, // push option isn_arg.string
26 ISN_LOADENV, // push environment variable isn_arg.string
27 ISN_LOADREG, // push register isn_arg.number
28
29 ISN_STORE, // pop into local variable isn_arg.number
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010030 ISN_STOREV, // pop into v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010031 ISN_STOREG, // pop into global variable isn_arg.string
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +020032 ISN_STORES, // pop into script variable isn_arg.loadstore
33 ISN_STORESCRIPT, // pop into script variable isn_arg.script
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010034 ISN_STOREOPT, // pop into option isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010035 ISN_STOREENV, // pop into environment variable isn_arg.string
36 ISN_STOREREG, // pop into register isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010037 // ISN_STOREOTHER, // pop into other script variable isn_arg.other.
38
Bram Moolenaara471eea2020-03-04 22:20:26 +010039 ISN_STORENR, // store number into local variable isn_arg.storenr.stnr_idx
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010040
41 // constants
Bram Moolenaar42a480b2020-02-29 23:23:47 +010042 ISN_PUSHNR, // push number isn_arg.number
43 ISN_PUSHBOOL, // push bool value isn_arg.number
44 ISN_PUSHSPEC, // push special value isn_arg.number
45 ISN_PUSHF, // push float isn_arg.fnumber
46 ISN_PUSHS, // push string isn_arg.string
47 ISN_PUSHBLOB, // push blob isn_arg.blob
48 ISN_PUSHFUNC, // push func isn_arg.string
Bram Moolenaar42a480b2020-02-29 23:23:47 +010049 ISN_PUSHCHANNEL, // push channel isn_arg.channel
50 ISN_PUSHJOB, // push channel isn_arg.job
51 ISN_NEWLIST, // push list from stack items, size is isn_arg.number
52 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010053
54 // function call
55 ISN_BCALL, // call builtin function isn_arg.bfunc
56 ISN_DCALL, // call def function isn_arg.dfunc
57 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
58 ISN_PCALL, // call partial, use isn_arg.pfunc
Bram Moolenaarbd5da372020-03-31 23:13:10 +020059 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010060 ISN_RETURN, // return, result is on top of stack
61 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
62
63 // expression operations
64 ISN_JUMP, // jump if condition is matched isn_arg.jump
65
66 // loop
67 ISN_FOR, // get next item from a list, uses isn_arg.forloop
68
69 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
70 ISN_THROW, // pop value of stack, store in v:exception
71 ISN_PUSHEXC, // push v:exception
72 ISN_CATCH, // drop v:exception
73 ISN_ENDTRY, // take entry off from ec_trystack
74
75 // moreexpression operations
76 ISN_ADDLIST,
77 ISN_ADDBLOB,
78
79 // operation with two arguments; isn_arg.op.op_type is exptype_T
80 ISN_OPNR,
81 ISN_OPFLOAT,
82 ISN_OPANY,
83
84 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
85 ISN_COMPAREBOOL,
86 ISN_COMPARESPECIAL,
87 ISN_COMPARENR,
88 ISN_COMPAREFLOAT,
89 ISN_COMPARESTRING,
90 ISN_COMPAREBLOB,
91 ISN_COMPARELIST,
92 ISN_COMPAREDICT,
93 ISN_COMPAREFUNC,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010094 ISN_COMPAREANY,
95
96 // expression operations
97 ISN_CONCAT,
98 ISN_INDEX, // [expr] list index
99 ISN_MEMBER, // dict.member using isn_arg.string
100 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
101 ISN_2STRING, // convert value to string at isn_arg.number on stack
102 ISN_NEGATENR, // apply "-" to number
103
104 ISN_CHECKNR, // check value can be used as a number
105 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
106
107 ISN_DROP // pop stack and discard value
108} isntype_T;
109
110
111// arguments to ISN_BCALL
112typedef struct {
113 int cbf_idx; // index in "global_functions"
114 int cbf_argcount; // number of arguments on top of stack
115} cbfunc_T;
116
117// arguments to ISN_DCALL
118typedef struct {
119 int cdf_idx; // index in "def_functions" for ISN_DCALL
120 int cdf_argcount; // number of arguments on top of stack
121} cdfunc_T;
122
123// arguments to ISN_PCALL
124typedef struct {
125 int cpf_top; // when TRUE partial is above the arguments
126 int cpf_argcount; // number of arguments on top of stack
127} cpfunc_T;
128
129// arguments to ISN_UCALL and ISN_XCALL
130typedef struct {
131 char_u *cuf_name;
132 int cuf_argcount; // number of arguments on top of stack
133} cufunc_T;
134
135typedef enum {
136 JUMP_ALWAYS,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100137 JUMP_IF_FALSE, // pop and jump if false
138 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
139 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
140} jumpwhen_T;
141
142// arguments to ISN_JUMP
143typedef struct {
144 jumpwhen_T jump_when;
145 int jump_where; // position to jump to
146} jump_T;
147
148// arguments to ISN_FOR
149typedef struct {
150 int for_idx; // loop variable index
151 int for_end; // position to jump to after done
152} forloop_T;
153
154// arguments to ISN_TRY
155typedef struct {
156 int try_catch; // position to jump to on throw
157 int try_finally; // position to jump to for return
158} try_T;
159
160// arguments to ISN_ECHO
161typedef struct {
162 int echo_with_white; // :echo instead of :echon
163 int echo_count; // number of expressions
164} echo_T;
165
166// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
167typedef struct {
168 exptype_T op_type;
169 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
170} opexpr_T;
171
172// arguments to ISN_CHECKTYPE
173typedef struct {
174 vartype_T ct_type;
175 int ct_off; // offset in stack, -1 is bottom
176} checktype_T;
177
178// arguments to ISN_STORENR
179typedef struct {
Bram Moolenaara471eea2020-03-04 22:20:26 +0100180 int stnr_idx;
181 varnumber_T stnr_val;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100182} storenr_T;
183
184// arguments to ISN_STOREOPT
185typedef struct {
186 char_u *so_name;
187 int so_flags;
188} storeopt_T;
189
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100190// arguments to ISN_LOADS and ISN_STORES
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100191typedef struct {
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +0200192 char_u *ls_name; // variable name (with s: for ISN_STORES)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100193 int ls_sid; // script ID
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100194} loadstore_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100195
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100196// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100197typedef struct {
198 int script_sid; // script ID
199 int script_idx; // index in sn_var_vals
200} script_T;
201
202/*
203 * Instruction
204 */
Bram Moolenaar20431c92020-03-20 18:39:46 +0100205struct isn_S {
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100206 isntype_T isn_type;
207 int isn_lnum;
208 union {
209 char_u *string;
210 varnumber_T number;
211 blob_T *blob;
212#ifdef FEAT_FLOAT
213 float_T fnumber;
214#endif
Bram Moolenaar42a480b2020-02-29 23:23:47 +0100215 channel_T *channel;
216 job_T *job;
Bram Moolenaar087d2e12020-03-01 15:36:42 +0100217 partial_T *partial;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100218 jump_T jump;
219 forloop_T forloop;
220 try_T try;
221 cbfunc_T bfunc;
222 cdfunc_T dfunc;
223 cpfunc_T pfunc;
224 cufunc_T ufunc;
225 echo_T echo;
226 opexpr_T op;
227 checktype_T type;
228 storenr_T storenr;
229 storeopt_T storeopt;
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100230 loadstore_T loadstore;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100231 script_T script;
232 } isn_arg;
Bram Moolenaar20431c92020-03-20 18:39:46 +0100233};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100234
235/*
236 * Info about a function defined with :def. Used in "def_functions".
237 */
238struct dfunc_S {
239 ufunc_T *df_ufunc; // struct containing most stuff
240 int df_idx; // index in def_functions
241 int df_deleted; // if TRUE function was deleted
242
243 garray_T df_def_args_isn; // default argument instructions
244 isn_T *df_instr; // function body to be executed
245 int df_instr_count;
246
247 int df_varcount; // number of local variables
248};
249
250// Number of entries used by stack frame for a function call.
251#define STACK_FRAME_SIZE 3
252
253
254#ifdef DEFINE_VIM9_GLOBALS
255// Functions defined with :def are stored in this growarray.
256// They are never removed, so that they can be found by index.
257// Deleted functions have the df_deleted flag set.
Bram Moolenaar05afcee2020-03-31 23:32:31 +0200258garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100259#else
260extern garray_T def_functions;
261#endif
262