blob: 77bf626d6f583f1c158fa43731ca21ff2e7679d8 [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
39 ISN_STORENR, // store number into local variable isn_arg.storenr.str_idx
40
41 // constants
42 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_NEWLIST, // push list from stack items, size is isn_arg.number
49 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
50
51 // function call
52 ISN_BCALL, // call builtin function isn_arg.bfunc
53 ISN_DCALL, // call def function isn_arg.dfunc
54 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
55 ISN_PCALL, // call partial, use isn_arg.pfunc
56 ISN_RETURN, // return, result is on top of stack
57 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
58
59 // expression operations
60 ISN_JUMP, // jump if condition is matched isn_arg.jump
61
62 // loop
63 ISN_FOR, // get next item from a list, uses isn_arg.forloop
64
65 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
66 ISN_THROW, // pop value of stack, store in v:exception
67 ISN_PUSHEXC, // push v:exception
68 ISN_CATCH, // drop v:exception
69 ISN_ENDTRY, // take entry off from ec_trystack
70
71 // moreexpression operations
72 ISN_ADDLIST,
73 ISN_ADDBLOB,
74
75 // operation with two arguments; isn_arg.op.op_type is exptype_T
76 ISN_OPNR,
77 ISN_OPFLOAT,
78 ISN_OPANY,
79
80 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
81 ISN_COMPAREBOOL,
82 ISN_COMPARESPECIAL,
83 ISN_COMPARENR,
84 ISN_COMPAREFLOAT,
85 ISN_COMPARESTRING,
86 ISN_COMPAREBLOB,
87 ISN_COMPARELIST,
88 ISN_COMPAREDICT,
89 ISN_COMPAREFUNC,
90 ISN_COMPAREPARTIAL,
91 ISN_COMPAREANY,
92
93 // expression operations
94 ISN_CONCAT,
95 ISN_INDEX, // [expr] list index
96 ISN_MEMBER, // dict.member using isn_arg.string
97 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
98 ISN_2STRING, // convert value to string at isn_arg.number on stack
99 ISN_NEGATENR, // apply "-" to number
100
101 ISN_CHECKNR, // check value can be used as a number
102 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
103
104 ISN_DROP // pop stack and discard value
105} isntype_T;
106
107
108// arguments to ISN_BCALL
109typedef struct {
110 int cbf_idx; // index in "global_functions"
111 int cbf_argcount; // number of arguments on top of stack
112} cbfunc_T;
113
114// arguments to ISN_DCALL
115typedef struct {
116 int cdf_idx; // index in "def_functions" for ISN_DCALL
117 int cdf_argcount; // number of arguments on top of stack
118} cdfunc_T;
119
120// arguments to ISN_PCALL
121typedef struct {
122 int cpf_top; // when TRUE partial is above the arguments
123 int cpf_argcount; // number of arguments on top of stack
124} cpfunc_T;
125
126// arguments to ISN_UCALL and ISN_XCALL
127typedef struct {
128 char_u *cuf_name;
129 int cuf_argcount; // number of arguments on top of stack
130} cufunc_T;
131
132typedef enum {
133 JUMP_ALWAYS,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100134 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