blob: 9269aa938813658302b1fc14f5b2a33742d569d4 [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 Moolenaarcfe435d2020-04-25 20:02:55 +020016 ISN_EXECCONCAT, // execute Ex command from isn_arg.number items on stack
Bram Moolenaarad39c092020-02-26 18:23:43 +010017 ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
18 ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
Bram Moolenaarf93c7fe2020-04-23 22:16:53 +020019 ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack
20 ISN_ECHOERR, // echo Ex commands isn_arg.number items on top of stack
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010021
22 // get and set variables
23 ISN_LOAD, // push local variable isn_arg.number
24 ISN_LOADV, // push v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010025 ISN_LOADG, // push g: variable isn_arg.string
Bram Moolenaard3aac292020-04-19 14:32:17 +020026 ISN_LOADB, // push b: variable isn_arg.string
27 ISN_LOADW, // push w: variable isn_arg.string
28 ISN_LOADT, // push t: variable isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010029 ISN_LOADS, // push s: variable isn_arg.loadstore
Bram Moolenaarc8cd2b32020-05-01 19:29:08 +020030 ISN_LOADOUTER, // push variable from outer scope isn_arg.number
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010031 ISN_LOADSCRIPT, // push script-local variable isn_arg.script.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010032 ISN_LOADOPT, // push option isn_arg.string
33 ISN_LOADENV, // push environment variable isn_arg.string
34 ISN_LOADREG, // push register isn_arg.number
35
36 ISN_STORE, // pop into local variable isn_arg.number
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010037 ISN_STOREV, // pop into v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010038 ISN_STOREG, // pop into global variable isn_arg.string
Bram Moolenaard3aac292020-04-19 14:32:17 +020039 ISN_STOREB, // pop into buffer-local variable isn_arg.string
40 ISN_STOREW, // pop into window-local variable isn_arg.string
41 ISN_STORET, // pop into tab-local variable isn_arg.string
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +020042 ISN_STORES, // pop into script variable isn_arg.loadstore
43 ISN_STORESCRIPT, // pop into script variable isn_arg.script
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010044 ISN_STOREOPT, // pop into option isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010045 ISN_STOREENV, // pop into environment variable isn_arg.string
46 ISN_STOREREG, // pop into register isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010047 // ISN_STOREOTHER, // pop into other script variable isn_arg.other.
48
Bram Moolenaara471eea2020-03-04 22:20:26 +010049 ISN_STORENR, // store number into local variable isn_arg.storenr.stnr_idx
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010050
Bram Moolenaard72c1bf2020-04-19 16:28:59 +020051 ISN_UNLET, // unlet variable isn_arg.unlet.ul_name
Bram Moolenaar7bdaea62020-04-19 18:27:26 +020052 ISN_UNLETENV, // unlet environment variable isn_arg.unlet.ul_name
Bram Moolenaard72c1bf2020-04-19 16:28:59 +020053
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010054 // constants
Bram Moolenaar42a480b2020-02-29 23:23:47 +010055 ISN_PUSHNR, // push number isn_arg.number
56 ISN_PUSHBOOL, // push bool value isn_arg.number
57 ISN_PUSHSPEC, // push special value isn_arg.number
58 ISN_PUSHF, // push float isn_arg.fnumber
59 ISN_PUSHS, // push string isn_arg.string
60 ISN_PUSHBLOB, // push blob isn_arg.blob
61 ISN_PUSHFUNC, // push func isn_arg.string
Bram Moolenaar42a480b2020-02-29 23:23:47 +010062 ISN_PUSHCHANNEL, // push channel isn_arg.channel
63 ISN_PUSHJOB, // push channel isn_arg.job
64 ISN_NEWLIST, // push list from stack items, size is isn_arg.number
65 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010066
67 // function call
68 ISN_BCALL, // call builtin function isn_arg.bfunc
69 ISN_DCALL, // call def function isn_arg.dfunc
70 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
71 ISN_PCALL, // call partial, use isn_arg.pfunc
Bram Moolenaarbd5da372020-03-31 23:13:10 +020072 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010073 ISN_RETURN, // return, result is on top of stack
74 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
75
76 // expression operations
77 ISN_JUMP, // jump if condition is matched isn_arg.jump
78
79 // loop
80 ISN_FOR, // get next item from a list, uses isn_arg.forloop
81
82 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
83 ISN_THROW, // pop value of stack, store in v:exception
84 ISN_PUSHEXC, // push v:exception
85 ISN_CATCH, // drop v:exception
86 ISN_ENDTRY, // take entry off from ec_trystack
87
88 // moreexpression operations
89 ISN_ADDLIST,
90 ISN_ADDBLOB,
91
92 // operation with two arguments; isn_arg.op.op_type is exptype_T
93 ISN_OPNR,
94 ISN_OPFLOAT,
95 ISN_OPANY,
96
97 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
98 ISN_COMPAREBOOL,
99 ISN_COMPARESPECIAL,
100 ISN_COMPARENR,
101 ISN_COMPAREFLOAT,
102 ISN_COMPARESTRING,
103 ISN_COMPAREBLOB,
104 ISN_COMPARELIST,
105 ISN_COMPAREDICT,
106 ISN_COMPAREFUNC,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100107 ISN_COMPAREANY,
108
109 // expression operations
110 ISN_CONCAT,
111 ISN_INDEX, // [expr] list index
112 ISN_MEMBER, // dict.member using isn_arg.string
113 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
114 ISN_2STRING, // convert value to string at isn_arg.number on stack
115 ISN_NEGATENR, // apply "-" to number
116
117 ISN_CHECKNR, // check value can be used as a number
118 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
119
120 ISN_DROP // pop stack and discard value
121} isntype_T;
122
123
124// arguments to ISN_BCALL
125typedef struct {
126 int cbf_idx; // index in "global_functions"
127 int cbf_argcount; // number of arguments on top of stack
128} cbfunc_T;
129
130// arguments to ISN_DCALL
131typedef struct {
132 int cdf_idx; // index in "def_functions" for ISN_DCALL
133 int cdf_argcount; // number of arguments on top of stack
134} cdfunc_T;
135
136// arguments to ISN_PCALL
137typedef struct {
138 int cpf_top; // when TRUE partial is above the arguments
139 int cpf_argcount; // number of arguments on top of stack
140} cpfunc_T;
141
142// arguments to ISN_UCALL and ISN_XCALL
143typedef struct {
144 char_u *cuf_name;
145 int cuf_argcount; // number of arguments on top of stack
146} cufunc_T;
147
148typedef enum {
149 JUMP_ALWAYS,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100150 JUMP_IF_FALSE, // pop and jump if false
151 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
152 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
153} jumpwhen_T;
154
155// arguments to ISN_JUMP
156typedef struct {
157 jumpwhen_T jump_when;
158 int jump_where; // position to jump to
159} jump_T;
160
161// arguments to ISN_FOR
162typedef struct {
163 int for_idx; // loop variable index
164 int for_end; // position to jump to after done
165} forloop_T;
166
167// arguments to ISN_TRY
168typedef struct {
169 int try_catch; // position to jump to on throw
170 int try_finally; // position to jump to for return
171} try_T;
172
173// arguments to ISN_ECHO
174typedef struct {
175 int echo_with_white; // :echo instead of :echon
176 int echo_count; // number of expressions
177} echo_T;
178
179// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
180typedef struct {
181 exptype_T op_type;
182 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
183} opexpr_T;
184
185// arguments to ISN_CHECKTYPE
186typedef struct {
187 vartype_T ct_type;
188 int ct_off; // offset in stack, -1 is bottom
189} checktype_T;
190
191// arguments to ISN_STORENR
192typedef struct {
Bram Moolenaara471eea2020-03-04 22:20:26 +0100193 int stnr_idx;
194 varnumber_T stnr_val;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100195} storenr_T;
196
197// arguments to ISN_STOREOPT
198typedef struct {
199 char_u *so_name;
200 int so_flags;
201} storeopt_T;
202
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100203// arguments to ISN_LOADS and ISN_STORES
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100204typedef struct {
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +0200205 char_u *ls_name; // variable name (with s: for ISN_STORES)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100206 int ls_sid; // script ID
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100207} loadstore_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100208
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100209// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100210typedef struct {
211 int script_sid; // script ID
212 int script_idx; // index in sn_var_vals
213} script_T;
214
Bram Moolenaard72c1bf2020-04-19 16:28:59 +0200215// arguments to ISN_UNLET
216typedef struct {
217 char_u *ul_name; // variable name with g:, w:, etc.
218 int ul_forceit; // forceit flag
219} unlet_T;
220
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100221/*
222 * Instruction
223 */
Bram Moolenaar20431c92020-03-20 18:39:46 +0100224struct isn_S {
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100225 isntype_T isn_type;
226 int isn_lnum;
227 union {
228 char_u *string;
229 varnumber_T number;
230 blob_T *blob;
231#ifdef FEAT_FLOAT
232 float_T fnumber;
233#endif
Bram Moolenaar42a480b2020-02-29 23:23:47 +0100234 channel_T *channel;
235 job_T *job;
Bram Moolenaar087d2e12020-03-01 15:36:42 +0100236 partial_T *partial;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100237 jump_T jump;
238 forloop_T forloop;
239 try_T try;
240 cbfunc_T bfunc;
241 cdfunc_T dfunc;
242 cpfunc_T pfunc;
243 cufunc_T ufunc;
244 echo_T echo;
245 opexpr_T op;
246 checktype_T type;
247 storenr_T storenr;
248 storeopt_T storeopt;
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100249 loadstore_T loadstore;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100250 script_T script;
Bram Moolenaard72c1bf2020-04-19 16:28:59 +0200251 unlet_T unlet;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100252 } isn_arg;
Bram Moolenaar20431c92020-03-20 18:39:46 +0100253};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100254
255/*
256 * Info about a function defined with :def. Used in "def_functions".
257 */
258struct dfunc_S {
259 ufunc_T *df_ufunc; // struct containing most stuff
260 int df_idx; // index in def_functions
261 int df_deleted; // if TRUE function was deleted
262
263 garray_T df_def_args_isn; // default argument instructions
264 isn_T *df_instr; // function body to be executed
265 int df_instr_count;
266
267 int df_varcount; // number of local variables
268};
269
270// Number of entries used by stack frame for a function call.
271#define STACK_FRAME_SIZE 3
272
273
274#ifdef DEFINE_VIM9_GLOBALS
275// Functions defined with :def are stored in this growarray.
276// They are never removed, so that they can be found by index.
277// Deleted functions have the df_deleted flag set.
Bram Moolenaar05afcee2020-03-31 23:32:31 +0200278garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100279#else
280extern garray_T def_functions;
281#endif
282