blob: a9f0710438c17adfc213fda3213930ce40d5c643 [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
16 ISN_ECHO, // echo isn_arg.number items on top of stack
17
18 // get and set variables
19 ISN_LOAD, // push local variable isn_arg.number
20 ISN_LOADV, // push v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010021 ISN_LOADG, // push g: variable isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010022 ISN_LOADS, // push s: variable isn_arg.loadstore
23 ISN_LOADSCRIPT, // push script-local variable isn_arg.script.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010024 ISN_LOADOPT, // push option isn_arg.string
25 ISN_LOADENV, // push environment variable isn_arg.string
26 ISN_LOADREG, // push register isn_arg.number
27
28 ISN_STORE, // pop into local variable isn_arg.number
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010029 ISN_STOREV, // pop into v: variable isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010030 ISN_STOREG, // pop into global variable isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010031 ISN_STORES, // pop into scirpt variable isn_arg.loadstore
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010032 ISN_STORESCRIPT, // pop into scirpt variable isn_arg.script
33 ISN_STOREOPT, // pop into option isn_arg.string
Bram Moolenaarb283a8a2020-02-02 22:24:04 +010034 ISN_STOREENV, // pop into environment variable isn_arg.string
35 ISN_STOREREG, // pop into register isn_arg.number
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010036 // ISN_STOREOTHER, // pop into other script variable isn_arg.other.
37
38 ISN_STORENR, // store number into local variable isn_arg.storenr.str_idx
39
40 // constants
41 ISN_PUSHNR, // push number isn_arg.number
42 ISN_PUSHBOOL, // push bool value isn_arg.number
43 ISN_PUSHSPEC, // push special value isn_arg.number
44 ISN_PUSHF, // push float isn_arg.fnumber
45 ISN_PUSHS, // push string isn_arg.string
46 ISN_PUSHBLOB, // push blob isn_arg.blob
47 ISN_NEWLIST, // push list from stack items, size is isn_arg.number
48 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
49
50 // function call
51 ISN_BCALL, // call builtin function isn_arg.bfunc
52 ISN_DCALL, // call def function isn_arg.dfunc
53 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
54 ISN_PCALL, // call partial, use isn_arg.pfunc
55 ISN_RETURN, // return, result is on top of stack
56 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
57
58 // expression operations
59 ISN_JUMP, // jump if condition is matched isn_arg.jump
60
61 // loop
62 ISN_FOR, // get next item from a list, uses isn_arg.forloop
63
64 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
65 ISN_THROW, // pop value of stack, store in v:exception
66 ISN_PUSHEXC, // push v:exception
67 ISN_CATCH, // drop v:exception
68 ISN_ENDTRY, // take entry off from ec_trystack
69
70 // moreexpression operations
71 ISN_ADDLIST,
72 ISN_ADDBLOB,
73
74 // operation with two arguments; isn_arg.op.op_type is exptype_T
75 ISN_OPNR,
76 ISN_OPFLOAT,
77 ISN_OPANY,
78
79 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
80 ISN_COMPAREBOOL,
81 ISN_COMPARESPECIAL,
82 ISN_COMPARENR,
83 ISN_COMPAREFLOAT,
84 ISN_COMPARESTRING,
85 ISN_COMPAREBLOB,
86 ISN_COMPARELIST,
87 ISN_COMPAREDICT,
88 ISN_COMPAREFUNC,
89 ISN_COMPAREPARTIAL,
90 ISN_COMPAREANY,
91
92 // expression operations
93 ISN_CONCAT,
94 ISN_INDEX, // [expr] list index
95 ISN_MEMBER, // dict.member using isn_arg.string
96 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
97 ISN_2STRING, // convert value to string at isn_arg.number on stack
98 ISN_NEGATENR, // apply "-" to number
99
100 ISN_CHECKNR, // check value can be used as a number
101 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
102
103 ISN_DROP // pop stack and discard value
104} isntype_T;
105
106
107// arguments to ISN_BCALL
108typedef struct {
109 int cbf_idx; // index in "global_functions"
110 int cbf_argcount; // number of arguments on top of stack
111} cbfunc_T;
112
113// arguments to ISN_DCALL
114typedef struct {
115 int cdf_idx; // index in "def_functions" for ISN_DCALL
116 int cdf_argcount; // number of arguments on top of stack
117} cdfunc_T;
118
119// arguments to ISN_PCALL
120typedef struct {
121 int cpf_top; // when TRUE partial is above the arguments
122 int cpf_argcount; // number of arguments on top of stack
123} cpfunc_T;
124
125// arguments to ISN_UCALL and ISN_XCALL
126typedef struct {
127 char_u *cuf_name;
128 int cuf_argcount; // number of arguments on top of stack
129} cufunc_T;
130
131typedef enum {
132 JUMP_ALWAYS,
133 JUMP_IF_TRUE, // pop and jump if true
134 JUMP_IF_FALSE, // pop and jump if false
135 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
136 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
137} jumpwhen_T;
138
139// arguments to ISN_JUMP
140typedef struct {
141 jumpwhen_T jump_when;
142 int jump_where; // position to jump to
143} jump_T;
144
145// arguments to ISN_FOR
146typedef struct {
147 int for_idx; // loop variable index
148 int for_end; // position to jump to after done
149} forloop_T;
150
151// arguments to ISN_TRY
152typedef struct {
153 int try_catch; // position to jump to on throw
154 int try_finally; // position to jump to for return
155} try_T;
156
157// arguments to ISN_ECHO
158typedef struct {
159 int echo_with_white; // :echo instead of :echon
160 int echo_count; // number of expressions
161} echo_T;
162
163// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
164typedef struct {
165 exptype_T op_type;
166 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
167} opexpr_T;
168
169// arguments to ISN_CHECKTYPE
170typedef struct {
171 vartype_T ct_type;
172 int ct_off; // offset in stack, -1 is bottom
173} checktype_T;
174
175// arguments to ISN_STORENR
176typedef struct {
177 int str_idx;
178 varnumber_T str_val;
179} storenr_T;
180
181// arguments to ISN_STOREOPT
182typedef struct {
183 char_u *so_name;
184 int so_flags;
185} storeopt_T;
186
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100187// arguments to ISN_LOADS and ISN_STORES
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100188typedef struct {
189 char_u *ls_name; // variable name
190 int ls_sid; // script ID
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100191} loadstore_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100192
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100193// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100194typedef struct {
195 int script_sid; // script ID
196 int script_idx; // index in sn_var_vals
197} script_T;
198
199/*
200 * Instruction
201 */
202typedef struct {
203 isntype_T isn_type;
204 int isn_lnum;
205 union {
206 char_u *string;
207 varnumber_T number;
208 blob_T *blob;
209#ifdef FEAT_FLOAT
210 float_T fnumber;
211#endif
212 jump_T jump;
213 forloop_T forloop;
214 try_T try;
215 cbfunc_T bfunc;
216 cdfunc_T dfunc;
217 cpfunc_T pfunc;
218 cufunc_T ufunc;
219 echo_T echo;
220 opexpr_T op;
221 checktype_T type;
222 storenr_T storenr;
223 storeopt_T storeopt;
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100224 loadstore_T loadstore;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100225 script_T script;
226 } isn_arg;
227} isn_T;
228
229/*
230 * Info about a function defined with :def. Used in "def_functions".
231 */
232struct dfunc_S {
233 ufunc_T *df_ufunc; // struct containing most stuff
234 int df_idx; // index in def_functions
235 int df_deleted; // if TRUE function was deleted
236
237 garray_T df_def_args_isn; // default argument instructions
238 isn_T *df_instr; // function body to be executed
239 int df_instr_count;
240
241 int df_varcount; // number of local variables
242};
243
244// Number of entries used by stack frame for a function call.
245#define STACK_FRAME_SIZE 3
246
247
248#ifdef DEFINE_VIM9_GLOBALS
249// Functions defined with :def are stored in this growarray.
250// They are never removed, so that they can be found by index.
251// Deleted functions have the df_deleted flag set.
252garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
253#else
254extern garray_T def_functions;
255#endif
256