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