comparison src/vim9.h @ 19181:94eda51ba9ba v8.2.0149

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