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 ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack 19 ISN_ECHOERR, // echo Ex commands isn_arg.number items on top of stack 20 21 // get and set variables 22 ISN_LOAD, // push local variable isn_arg.number 23 ISN_LOADV, // push v: variable isn_arg.number 24 ISN_LOADG, // push g: variable isn_arg.string 25 ISN_LOADB, // push b: variable isn_arg.string 26 ISN_LOADW, // push w: variable isn_arg.string 27 ISN_LOADT, // push t: variable isn_arg.string 28 ISN_LOADS, // push s: variable isn_arg.loadstore 29 ISN_LOADSCRIPT, // push script-local variable isn_arg.script. 30 ISN_LOADOPT, // push option isn_arg.string 31 ISN_LOADENV, // push environment variable isn_arg.string 32 ISN_LOADREG, // push register isn_arg.number 33 34 ISN_STORE, // pop into local variable isn_arg.number 35 ISN_STOREV, // pop into v: variable isn_arg.number 36 ISN_STOREG, // pop into global variable isn_arg.string 37 ISN_STOREB, // pop into buffer-local variable isn_arg.string 38 ISN_STOREW, // pop into window-local variable isn_arg.string 39 ISN_STORET, // pop into tab-local variable isn_arg.string 40 ISN_STORES, // pop into script variable isn_arg.loadstore 41 ISN_STORESCRIPT, // pop into script variable isn_arg.script 42 ISN_STOREOPT, // pop into option isn_arg.string 43 ISN_STOREENV, // pop into environment variable isn_arg.string 44 ISN_STOREREG, // pop into register isn_arg.number 45 // ISN_STOREOTHER, // pop into other script variable isn_arg.other. 46 47 ISN_STORENR, // store number into local variable isn_arg.storenr.stnr_idx 48 49 ISN_UNLET, // unlet variable isn_arg.unlet.ul_name 50 ISN_UNLETENV, // unlet environment variable isn_arg.unlet.ul_name 51 52 // constants 53 ISN_PUSHNR, // push number isn_arg.number 54 ISN_PUSHBOOL, // push bool value isn_arg.number 55 ISN_PUSHSPEC, // push special value isn_arg.number 56 ISN_PUSHF, // push float isn_arg.fnumber 57 ISN_PUSHS, // push string isn_arg.string 58 ISN_PUSHBLOB, // push blob isn_arg.blob 59 ISN_PUSHFUNC, // push func isn_arg.string 60 ISN_PUSHCHANNEL, // push channel isn_arg.channel 61 ISN_PUSHJOB, // push channel isn_arg.job 62 ISN_NEWLIST, // push list from stack items, size is isn_arg.number 63 ISN_NEWDICT, // push dict from stack items, size is isn_arg.number 64 65 // function call 66 ISN_BCALL, // call builtin function isn_arg.bfunc 67 ISN_DCALL, // call def function isn_arg.dfunc 68 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc 69 ISN_PCALL, // call partial, use isn_arg.pfunc 70 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set 71 ISN_RETURN, // return, result is on top of stack 72 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number 73 74 // expression operations 75 ISN_JUMP, // jump if condition is matched isn_arg.jump 76 77 // loop 78 ISN_FOR, // get next item from a list, uses isn_arg.forloop 79 80 ISN_TRY, // add entry to ec_trystack, uses isn_arg.try 81 ISN_THROW, // pop value of stack, store in v:exception 82 ISN_PUSHEXC, // push v:exception 83 ISN_CATCH, // drop v:exception 84 ISN_ENDTRY, // take entry off from ec_trystack 85 86 // moreexpression operations 87 ISN_ADDLIST, 88 ISN_ADDBLOB, 89 90 // operation with two arguments; isn_arg.op.op_type is exptype_T 91 ISN_OPNR, 92 ISN_OPFLOAT, 93 ISN_OPANY, 94 95 // comparative operations; isn_arg.op.op_type is exptype_T, op_ic used 96 ISN_COMPAREBOOL, 97 ISN_COMPARESPECIAL, 98 ISN_COMPARENR, 99 ISN_COMPAREFLOAT, 100 ISN_COMPARESTRING, 101 ISN_COMPAREBLOB, 102 ISN_COMPARELIST, 103 ISN_COMPAREDICT, 104 ISN_COMPAREFUNC, 105 ISN_COMPAREANY, 106 107 // expression operations 108 ISN_CONCAT, 109 ISN_INDEX, // [expr] list index 110 ISN_MEMBER, // dict.member using isn_arg.string 111 ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0 112 ISN_2STRING, // convert value to string at isn_arg.number on stack 113 ISN_NEGATENR, // apply "-" to number 114 115 ISN_CHECKNR, // check value can be used as a number 116 ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type 117 118 ISN_DROP // pop stack and discard value 119 } isntype_T; 120 121 122 // arguments to ISN_BCALL 123 typedef struct { 124 int cbf_idx; // index in "global_functions" 125 int cbf_argcount; // number of arguments on top of stack 126 } cbfunc_T; 127 128 // arguments to ISN_DCALL 129 typedef struct { 130 int cdf_idx; // index in "def_functions" for ISN_DCALL 131 int cdf_argcount; // number of arguments on top of stack 132 } cdfunc_T; 133 134 // arguments to ISN_PCALL 135 typedef struct { 136 int cpf_top; // when TRUE partial is above the arguments 137 int cpf_argcount; // number of arguments on top of stack 138 } cpfunc_T; 139 140 // arguments to ISN_UCALL and ISN_XCALL 141 typedef struct { 142 char_u *cuf_name; 143 int cuf_argcount; // number of arguments on top of stack 144 } cufunc_T; 145 146 typedef enum { 147 JUMP_ALWAYS, 148 JUMP_IF_FALSE, // pop and jump if false 149 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not 150 JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not 151 } jumpwhen_T; 152 153 // arguments to ISN_JUMP 154 typedef struct { 155 jumpwhen_T jump_when; 156 int jump_where; // position to jump to 157 } jump_T; 158 159 // arguments to ISN_FOR 160 typedef struct { 161 int for_idx; // loop variable index 162 int for_end; // position to jump to after done 163 } forloop_T; 164 165 // arguments to ISN_TRY 166 typedef struct { 167 int try_catch; // position to jump to on throw 168 int try_finally; // position to jump to for return 169 } try_T; 170 171 // arguments to ISN_ECHO 172 typedef struct { 173 int echo_with_white; // :echo instead of :echon 174 int echo_count; // number of expressions 175 } echo_T; 176 177 // arguments to ISN_OPNR, ISN_OPFLOAT, etc. 178 typedef struct { 179 exptype_T op_type; 180 int op_ic; // TRUE with '#', FALSE with '?', else MAYBE 181 } opexpr_T; 182 183 // arguments to ISN_CHECKTYPE 184 typedef struct { 185 vartype_T ct_type; 186 int ct_off; // offset in stack, -1 is bottom 187 } checktype_T; 188 189 // arguments to ISN_STORENR 190 typedef struct { 191 int stnr_idx; 192 varnumber_T stnr_val; 193 } storenr_T; 194 195 // arguments to ISN_STOREOPT 196 typedef struct { 197 char_u *so_name; 198 int so_flags; 199 } storeopt_T; 200 201 // arguments to ISN_LOADS and ISN_STORES 202 typedef struct { 203 char_u *ls_name; // variable name (with s: for ISN_STORES) 204 int ls_sid; // script ID 205 } loadstore_T; 206 207 // arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT 208 typedef struct { 209 int script_sid; // script ID 210 int script_idx; // index in sn_var_vals 211 } script_T; 212 213 // arguments to ISN_UNLET 214 typedef struct { 215 char_u *ul_name; // variable name with g:, w:, etc. 216 int ul_forceit; // forceit flag 217 } unlet_T; 218 219 /* 220 * Instruction 221 */ 222 struct isn_S { 223 isntype_T isn_type; 224 int isn_lnum; 225 union { 226 char_u *string; 227 varnumber_T number; 228 blob_T *blob; 229 #ifdef FEAT_FLOAT 230 float_T fnumber; 231 #endif 232 channel_T *channel; 233 job_T *job; 234 partial_T *partial; 235 jump_T jump; 236 forloop_T forloop; 237 try_T try; 238 cbfunc_T bfunc; 239 cdfunc_T dfunc; 240 cpfunc_T pfunc; 241 cufunc_T ufunc; 242 echo_T echo; 243 opexpr_T op; 244 checktype_T type; 245 storenr_T storenr; 246 storeopt_T storeopt; 247 loadstore_T loadstore; 248 script_T script; 249 unlet_T unlet; 250 } isn_arg; 251 }; 252 253 /* 254 * Info about a function defined with :def. Used in "def_functions". 255 */ 256 struct dfunc_S { 257 ufunc_T *df_ufunc; // struct containing most stuff 258 int df_idx; // index in def_functions 259 int df_deleted; // if TRUE function was deleted 260 261 garray_T df_def_args_isn; // default argument instructions 262 isn_T *df_instr; // function body to be executed 263 int df_instr_count; 264 265 int df_varcount; // number of local variables 266 }; 267 268 // Number of entries used by stack frame for a function call. 269 #define STACK_FRAME_SIZE 3 270 271 272 #ifdef DEFINE_VIM9_GLOBALS 273 // Functions defined with :def are stored in this growarray. 274 // They are never removed, so that they can be found by index. 275 // Deleted functions have the df_deleted flag set. 276 garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL}; 277 #else 278 extern garray_T def_functions; 279 #endif 280 281