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