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_LOADG, // push g: variable isn_arg.string 22 ISN_LOADS, // push s: variable isn_arg.loadstore 23 ISN_LOADSCRIPT, // push script-local variable isn_arg.script. 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_STOREV, // pop into v: variable isn_arg.number 30 ISN_STOREG, // pop into global variable isn_arg.string 31 ISN_STORES, // pop into scirpt variable isn_arg.loadstore 32 ISN_STORESCRIPT, // pop into scirpt variable isn_arg.script 33 ISN_STOREOPT, // pop into option isn_arg.string 34 ISN_STOREENV, // pop into environment variable isn_arg.string 35 ISN_STOREREG, // pop into register isn_arg.number 36 // 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 108 typedef 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 114 typedef 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 120 typedef 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 126 typedef struct { 127 char_u *cuf_name; 128 int cuf_argcount; // number of arguments on top of stack 129 } cufunc_T; 130 131 typedef enum { 132 JUMP_ALWAYS, 133 JUMP_IF_FALSE, // pop and jump if false 134 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not 135 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not 136 } jumpwhen_T; 137 138 // arguments to ISN_JUMP 139 typedef struct { 140 jumpwhen_T jump_when; 141 int jump_where; // position to jump to 142 } jump_T; 143 144 // arguments to ISN_FOR 145 typedef struct { 146 int for_idx; // loop variable index 147 int for_end; // position to jump to after done 148 } forloop_T; 149 150 // arguments to ISN_TRY 151 typedef struct { 152 int try_catch; // position to jump to on throw 153 int try_finally; // position to jump to for return 154 } try_T; 155 156 // arguments to ISN_ECHO 157 typedef struct { 158 int echo_with_white; // :echo instead of :echon 159 int echo_count; // number of expressions 160 } echo_T; 161 162 // arguments to ISN_OPNR, ISN_OPFLOAT, etc. 163 typedef struct { 164 exptype_T op_type; 165 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE 166 } opexpr_T; 167 168 // arguments to ISN_CHECKTYPE 169 typedef struct { 170 vartype_T ct_type; 171 int ct_off; // offset in stack, -1 is bottom 172 } checktype_T; 173 174 // arguments to ISN_STORENR 175 typedef struct { 176 int str_idx; 177 varnumber_T str_val; 178 } storenr_T; 179 180 // arguments to ISN_STOREOPT 181 typedef struct { 182 char_u *so_name; 183 int so_flags; 184 } storeopt_T; 185 186 // arguments to ISN_LOADS and ISN_STORES 187 typedef struct { 188 char_u *ls_name; // variable name 189 int ls_sid; // script ID 190 } loadstore_T; 191 192 // arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT 193 typedef struct { 194 int script_sid; // script ID 195 int script_idx; // index in sn_var_vals 196 } script_T; 197 198 /* 199 * Instruction 200 */ 201 typedef struct { 202 isntype_T isn_type; 203 int isn_lnum; 204 union { 205 char_u *string; 206 varnumber_T number; 207 blob_T *blob; 208 #ifdef FEAT_FLOAT 209 float_T fnumber; 210 #endif 211 jump_T jump; 212 forloop_T forloop; 213 try_T try; 214 cbfunc_T bfunc; 215 cdfunc_T dfunc; 216 cpfunc_T pfunc; 217 cufunc_T ufunc; 218 echo_T echo; 219 opexpr_T op; 220 checktype_T type; 221 storenr_T storenr; 222 storeopt_T storeopt; 223 loadstore_T loadstore; 224 script_T script; 225 } isn_arg; 226 } isn_T; 227 228 /* 229 * Info about a function defined with :def. Used in "def_functions". 230 */ 231 struct dfunc_S { 232 ufunc_T *df_ufunc; // struct containing most stuff 233 int df_idx; // index in def_functions 234 int df_deleted; // if TRUE function was deleted 235 236 garray_T df_def_args_isn; // default argument instructions 237 isn_T *df_instr; // function body to be executed 238 int df_instr_count; 239 240 int df_varcount; // number of local variables 241 }; 242 243 // Number of entries used by stack frame for a function call. 244 #define STACK_FRAME_SIZE 3 245 246 247 #ifdef DEFINE_VIM9_GLOBALS 248 // Functions defined with :def are stored in this growarray. 249 // They are never removed, so that they can be found by index. 250 // Deleted functions have the df_deleted flag set. 251 garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL}; 252 #else 253 extern garray_T def_functions; 254 #endif 255 256