blob: a414caa63afbada638dd667661a451bc1f464709 [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
Bram Moolenaarbd5da372020-03-31 23:13:10 +020060 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010061 ISN_RETURN, // return, result is on top of stack
62 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number
63
64 // expression operations
65 ISN_JUMP, // jump if condition is matched isn_arg.jump
66
67 // loop
68 ISN_FOR, // get next item from a list, uses isn_arg.forloop
69
70 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
71 ISN_THROW, // pop value of stack, store in v:exception
72 ISN_PUSHEXC, // push v:exception
73 ISN_CATCH, // drop v:exception
74 ISN_ENDTRY, // take entry off from ec_trystack
75
76 // moreexpression operations
77 ISN_ADDLIST,
78 ISN_ADDBLOB,
79
80 // operation with two arguments; isn_arg.op.op_type is exptype_T
81 ISN_OPNR,
82 ISN_OPFLOAT,
83 ISN_OPANY,
84
85 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
86 ISN_COMPAREBOOL,
87 ISN_COMPARESPECIAL,
88 ISN_COMPARENR,
89 ISN_COMPAREFLOAT,
90 ISN_COMPARESTRING,
91 ISN_COMPAREBLOB,
92 ISN_COMPARELIST,
93 ISN_COMPAREDICT,
94 ISN_COMPAREFUNC,
95 ISN_COMPAREPARTIAL,
96 ISN_COMPAREANY,
97
98 // expression operations
99 ISN_CONCAT,
100 ISN_INDEX, // [expr] list index
101 ISN_MEMBER, // dict.member using isn_arg.string
102 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
103 ISN_2STRING, // convert value to string at isn_arg.number on stack
104 ISN_NEGATENR, // apply "-" to number
105
106 ISN_CHECKNR, // check value can be used as a number
107 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
108
109 ISN_DROP // pop stack and discard value
110} isntype_T;
111
112
113// arguments to ISN_BCALL
114typedef struct {
115 int cbf_idx; // index in "global_functions"
116 int cbf_argcount; // number of arguments on top of stack
117} cbfunc_T;
118
119// arguments to ISN_DCALL
120typedef struct {
121 int cdf_idx; // index in "def_functions" for ISN_DCALL
122 int cdf_argcount; // number of arguments on top of stack
123} cdfunc_T;
124
125// arguments to ISN_PCALL
126typedef struct {
127 int cpf_top; // when TRUE partial is above the arguments
128 int cpf_argcount; // number of arguments on top of stack
129} cpfunc_T;
130
131// arguments to ISN_UCALL and ISN_XCALL
132typedef struct {
133 char_u *cuf_name;
134 int cuf_argcount; // number of arguments on top of stack
135} cufunc_T;
136
137typedef enum {
138 JUMP_ALWAYS,
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100139 JUMP_IF_FALSE, // pop and jump if false
140 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
141 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
142} jumpwhen_T;
143
144// arguments to ISN_JUMP
145typedef struct {
146 jumpwhen_T jump_when;
147 int jump_where; // position to jump to
148} jump_T;
149
150// arguments to ISN_FOR
151typedef struct {
152 int for_idx; // loop variable index
153 int for_end; // position to jump to after done
154} forloop_T;
155
156// arguments to ISN_TRY
157typedef struct {
158 int try_catch; // position to jump to on throw
159 int try_finally; // position to jump to for return
160} try_T;
161
162// arguments to ISN_ECHO
163typedef struct {
164 int echo_with_white; // :echo instead of :echon
165 int echo_count; // number of expressions
166} echo_T;
167
168// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
169typedef struct {
170 exptype_T op_type;
171 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
172} opexpr_T;
173
174// arguments to ISN_CHECKTYPE
175typedef struct {
176 vartype_T ct_type;
177 int ct_off; // offset in stack, -1 is bottom
178} checktype_T;
179
180// arguments to ISN_STORENR
181typedef struct {
Bram Moolenaara471eea2020-03-04 22:20:26 +0100182 int stnr_idx;
183 varnumber_T stnr_val;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100184} storenr_T;
185
186// arguments to ISN_STOREOPT
187typedef struct {
188 char_u *so_name;
189 int so_flags;
190} storeopt_T;
191
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100192// arguments to ISN_LOADS and ISN_STORES
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100193typedef struct {
194 char_u *ls_name; // variable name
195 int ls_sid; // script ID
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100196} loadstore_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100197
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100198// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100199typedef struct {
200 int script_sid; // script ID
201 int script_idx; // index in sn_var_vals
202} script_T;
203
204/*
205 * Instruction
206 */
Bram Moolenaar20431c92020-03-20 18:39:46 +0100207struct isn_S {
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100208 isntype_T isn_type;
209 int isn_lnum;
210 union {
211 char_u *string;
212 varnumber_T number;
213 blob_T *blob;
214#ifdef FEAT_FLOAT
215 float_T fnumber;
216#endif
Bram Moolenaar42a480b2020-02-29 23:23:47 +0100217 channel_T *channel;
218 job_T *job;
Bram Moolenaar087d2e12020-03-01 15:36:42 +0100219 partial_T *partial;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100220 jump_T jump;
221 forloop_T forloop;
222 try_T try;
223 cbfunc_T bfunc;
224 cdfunc_T dfunc;
225 cpfunc_T pfunc;
226 cufunc_T ufunc;
227 echo_T echo;
228 opexpr_T op;
229 checktype_T type;
230 storenr_T storenr;
231 storeopt_T storeopt;
Bram Moolenaarb283a8a2020-02-02 22:24:04 +0100232 loadstore_T loadstore;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100233 script_T script;
234 } isn_arg;
Bram Moolenaar20431c92020-03-20 18:39:46 +0100235};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100236
237/*
238 * Info about a function defined with :def. Used in "def_functions".
239 */
240struct dfunc_S {
241 ufunc_T *df_ufunc; // struct containing most stuff
242 int df_idx; // index in def_functions
243 int df_deleted; // if TRUE function was deleted
244
245 garray_T df_def_args_isn; // default argument instructions
246 isn_T *df_instr; // function body to be executed
247 int df_instr_count;
248
249 int df_varcount; // number of local variables
250};
251
252// Number of entries used by stack frame for a function call.
253#define STACK_FRAME_SIZE 3
254
255
256#ifdef DEFINE_VIM9_GLOBALS
257// Functions defined with :def are stored in this growarray.
258// They are never removed, so that they can be found by index.
259// Deleted functions have the df_deleted flag set.
Bram Moolenaar05afcee2020-03-31 23:32:31 +0200260garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100261#else
262extern garray_T def_functions;
263#endif
264