blob: 38286b32a1f2d58b2e68b516361ff93e04a3eb19 [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 Moolenaarb283a8a2020-02-02 22:24:04 +010032 ISN_STORES, // pop into scirpt variable isn_arg.loadstore
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010033 ISN_STORESCRIPT, // pop into scirpt variable isn_arg.script
34 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
49 ISN_PUSHPARTIAL, // push partial ?
50 ISN_PUSHCHANNEL, // push channel isn_arg.channel
51 ISN_PUSHJOB, // push channel isn_arg.job
52 ISN_NEWLIST, // push list from stack items, size is isn_arg.number
53 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010054
55 // function call
56 ISN_BCALL, // call builtin function isn_arg.bfunc
57 ISN_DCALL, // call def function isn_arg.dfunc
58 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
59 ISN_PCALL, // call partial, use isn_arg.pfunc
60 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,
94 ISN_COMPAREPARTIAL,
95 ISN_COMPAREANY,
96
97 // expression operations
98 ISN_CONCAT,
99 ISN_INDEX, // [expr] list index
100 ISN_MEMBER, // dict.member using isn_arg.string
101 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
102 ISN_2STRING, // convert value to string at isn_arg.number on stack
103 ISN_NEGATENR, // apply "-" to number
104
105 ISN_CHECKNR, // check value can be used as a number
106 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
107
108 ISN_DROP // pop stack and discard value
109} isntype_T;
110
111
112// arguments to ISN_BCALL
113typedef struct {
114 int cbf_idx; // index in "global_functions"
115 int cbf_argcount; // number of arguments on top of stack
116} cbfunc_T;
117
118// arguments to ISN_DCALL
119typedef struct {
120 int cdf_idx; // index in "def_functions" for ISN_DCALL
121 int cdf_argcount; // number of arguments on top of stack
122} cdfunc_T;
123
124// arguments to ISN_PCALL
125typedef struct {
126 int cpf_top; // when TRUE partial is above the arguments
127 int cpf_argcount; // number of arguments on top of stack
128} cpfunc_T;
129
130// arguments to ISN_UCALL and ISN_XCALL
131typedef struct {
132 char_u *cuf_name;
133 int cuf_argcount; // number of arguments on top of stack
134} cufunc_T;
135
136typedef enum {
137 JUMP_ALWAYS,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100138 JUMP_IF_FALSE, // pop and jump if false
139 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
140 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
141} jumpwhen_T;
142
143// arguments to ISN_JUMP
144typedef struct {
145 jumpwhen_T jump_when;
146 int jump_where; // position to jump to
147} jump_T;
148
149// arguments to ISN_FOR
150typedef struct {
151 int for_idx; // loop variable index
152 int for_end; // position to jump to after done
153} forloop_T;
154
155// arguments to ISN_TRY
156typedef struct {
157 int try_catch; // position to jump to on throw
158 int try_finally; // position to jump to for return
159} try_T;
160
161// arguments to ISN_ECHO
162typedef struct {
163 int echo_with_white; // :echo instead of :echon
164 int echo_count; // number of expressions
165} echo_T;
166
167// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
168typedef struct {
169 exptype_T op_type;
170 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
171} opexpr_T;
172
173// arguments to ISN_CHECKTYPE
174typedef struct {
175 vartype_T ct_type;
176 int ct_off; // offset in stack, -1 is bottom
177} checktype_T;
178
179// arguments to ISN_STORENR
180typedef struct {
Bram Moolenaara471eea2020-03-04 22:20:26 +0100181 int stnr_idx;
182 varnumber_T stnr_val;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100183} storenr_T;
184
185// arguments to ISN_STOREOPT
186typedef struct {
187 char_u *so_name;
188 int so_flags;
189} storeopt_T;
190
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100191// arguments to ISN_LOADS and ISN_STORES
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100192typedef struct {
193 char_u *ls_name; // variable name
194 int ls_sid; // script ID
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100195} loadstore_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100196
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100197// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100198typedef struct {
199 int script_sid; // script ID
200 int script_idx; // index in sn_var_vals
201} script_T;
202
203/*
204 * Instruction
205 */
206typedef struct {
207 isntype_T isn_type;
208 int isn_lnum;
209 union {
210 char_u *string;
211 varnumber_T number;
212 blob_T *blob;
213#ifdef FEAT_FLOAT
214 float_T fnumber;
215#endif
Bram Moolenaar42a480b2020-02-29 23:23:47 +0100216 channel_T *channel;
217 job_T *job;
Bram Moolenaar087d2e12020-03-01 15:36:42 +0100218 partial_T *partial;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100219 jump_T jump;
220 forloop_T forloop;
221 try_T try;
222 cbfunc_T bfunc;
223 cdfunc_T dfunc;
224 cpfunc_T pfunc;
225 cufunc_T ufunc;
226 echo_T echo;
227 opexpr_T op;
228 checktype_T type;
229 storenr_T storenr;
230 storeopt_T storeopt;
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100231 loadstore_T loadstore;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100232 script_T script;
233 } isn_arg;
234} isn_T;
235
236/*
237 * Info about a function defined with :def. Used in "def_functions".
238 */
239struct dfunc_S {
240 ufunc_T *df_ufunc; // struct containing most stuff
241 int df_idx; // index in def_functions
242 int df_deleted; // if TRUE function was deleted
243
244 garray_T df_def_args_isn; // default argument instructions
245 isn_T *df_instr; // function body to be executed
246 int df_instr_count;
247
248 int df_varcount; // number of local variables
249};
250
251// Number of entries used by stack frame for a function call.
252#define STACK_FRAME_SIZE 3
253
254
255#ifdef DEFINE_VIM9_GLOBALS
256// Functions defined with :def are stored in this growarray.
257// They are never removed, so that they can be found by index.
258// Deleted functions have the df_deleted flag set.
259garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
260#else
261extern garray_T def_functions;
262#endif
263