Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 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 | * vim9instr.c: Dealing with instructions of a compiled function |
| 12 | */ |
| 13 | |
| 14 | #define USING_FLOAT_STUFF |
| 15 | #include "vim.h" |
| 16 | |
| 17 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 18 | |
| 19 | // When not generating protos this is included in proto.h |
| 20 | #ifdef PROTO |
| 21 | # include "vim9.h" |
| 22 | #endif |
| 23 | |
| 24 | |
| 25 | ///////////////////////////////////////////////////////////////////// |
| 26 | // Following generate_ functions expect the caller to call ga_grow(). |
| 27 | |
| 28 | #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL |
| 29 | #define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return OK |
| 30 | |
| 31 | /* |
| 32 | * Generate an instruction without arguments. |
| 33 | * Returns a pointer to the new instruction, NULL if failed. |
| 34 | */ |
| 35 | isn_T * |
| 36 | generate_instr(cctx_T *cctx, isntype_T isn_type) |
| 37 | { |
| 38 | garray_T *instr = &cctx->ctx_instr; |
| 39 | isn_T *isn; |
| 40 | |
| 41 | RETURN_NULL_IF_SKIP(cctx); |
| 42 | if (GA_GROW_FAILS(instr, 1)) |
| 43 | return NULL; |
| 44 | isn = ((isn_T *)instr->ga_data) + instr->ga_len; |
| 45 | isn->isn_type = isn_type; |
| 46 | isn->isn_lnum = cctx->ctx_lnum + 1; |
| 47 | ++instr->ga_len; |
| 48 | |
| 49 | return isn; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Generate an instruction without arguments. |
| 54 | * "drop" will be removed from the stack. |
| 55 | * Returns a pointer to the new instruction, NULL if failed. |
| 56 | */ |
| 57 | isn_T * |
| 58 | generate_instr_drop(cctx_T *cctx, isntype_T isn_type, int drop) |
| 59 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 60 | RETURN_NULL_IF_SKIP(cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 61 | cctx->ctx_type_stack.ga_len -= drop; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 62 | return generate_instr(cctx, isn_type); |
| 63 | } |
| 64 | |
| 65 | /* |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 66 | * Generate instruction "isn_type" and put "type" on the type stack, |
| 67 | * use "decl_type" for the declared type. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 68 | */ |
Yegappan Lakshmanan | 782b43d | 2022-01-08 18:43:40 +0000 | [diff] [blame] | 69 | static isn_T * |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 70 | generate_instr_type2( |
| 71 | cctx_T *cctx, |
| 72 | isntype_T isn_type, |
| 73 | type_T *type, |
| 74 | type_T *decl_type) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 75 | { |
| 76 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 77 | |
| 78 | if ((isn = generate_instr(cctx, isn_type)) == NULL) |
| 79 | return NULL; |
| 80 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 81 | if (push_type_stack2(cctx, type == NULL ? &t_any : type, |
| 82 | decl_type == NULL ? &t_any : decl_type) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 83 | return NULL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 84 | |
| 85 | return isn; |
| 86 | } |
| 87 | |
| 88 | /* |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 89 | * Generate instruction "isn_type" and put "type" on the type stack. |
| 90 | * Uses "any" for the declared type, which works for constants. For declared |
| 91 | * variables use generate_instr_type2(). |
| 92 | */ |
| 93 | isn_T * |
| 94 | generate_instr_type(cctx_T *cctx, isntype_T isn_type, type_T *type) |
| 95 | { |
| 96 | return generate_instr_type2(cctx, isn_type, type, &t_any); |
| 97 | } |
| 98 | |
| 99 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 100 | * Generate an ISN_DEBUG instruction. |
| 101 | */ |
| 102 | isn_T * |
| 103 | generate_instr_debug(cctx_T *cctx) |
| 104 | { |
| 105 | isn_T *isn; |
| 106 | dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
| 107 | + cctx->ctx_ufunc->uf_dfunc_idx; |
| 108 | |
| 109 | if ((isn = generate_instr(cctx, ISN_DEBUG)) == NULL) |
| 110 | return NULL; |
| 111 | isn->isn_arg.debug.dbg_var_names_len = dfunc->df_var_names.ga_len; |
| 112 | isn->isn_arg.debug.dbg_break_lnum = cctx->ctx_prev_lnum; |
| 113 | return isn; |
| 114 | } |
| 115 | |
| 116 | /* |
Bram Moolenaar | 00b28d6 | 2022-12-08 15:32:33 +0000 | [diff] [blame] | 117 | * Generate an ISN_CONSTRUCT instruction. |
| 118 | * The object will have "size" members. |
| 119 | */ |
| 120 | int |
| 121 | generate_CONSTRUCT(cctx_T *cctx, class_T *cl) |
| 122 | { |
| 123 | isn_T *isn; |
| 124 | |
| 125 | RETURN_OK_IF_SKIP(cctx); |
| 126 | if ((isn = generate_instr(cctx, ISN_CONSTRUCT)) == NULL) |
| 127 | return FAIL; |
| 128 | isn->isn_arg.construct.construct_size = sizeof(object_T) |
| 129 | + cl->class_obj_member_count * sizeof(typval_T); |
| 130 | isn->isn_arg.construct.construct_class = cl; |
| 131 | return OK; |
| 132 | } |
| 133 | |
| 134 | /* |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 135 | * Generate ISN_GET_OBJ_MEMBER - access member of object at bottom of stack by |
| 136 | * index. |
Bram Moolenaar | ffdaca9 | 2022-12-09 21:41:48 +0000 | [diff] [blame] | 137 | */ |
| 138 | int |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 139 | generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type) |
Bram Moolenaar | ffdaca9 | 2022-12-09 21:41:48 +0000 | [diff] [blame] | 140 | { |
| 141 | RETURN_OK_IF_SKIP(cctx); |
| 142 | |
| 143 | // drop the object type |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 144 | isn_T *isn = generate_instr_drop(cctx, ISN_GET_OBJ_MEMBER, 1); |
Bram Moolenaar | ffdaca9 | 2022-12-09 21:41:48 +0000 | [diff] [blame] | 145 | if (isn == NULL) |
| 146 | return FAIL; |
| 147 | |
| 148 | isn->isn_arg.number = idx; |
| 149 | return push_type_stack2(cctx, type, &t_any); |
| 150 | } |
| 151 | |
| 152 | /* |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 153 | * Generate ISN_STORE_THIS - store value in member of "this" object with member |
| 154 | * index "idx". |
| 155 | */ |
| 156 | int |
| 157 | generate_STORE_THIS(cctx_T *cctx, int idx) |
| 158 | { |
| 159 | RETURN_OK_IF_SKIP(cctx); |
| 160 | |
| 161 | // drop the value type |
| 162 | isn_T *isn = generate_instr_drop(cctx, ISN_STORE_THIS, 1); |
| 163 | if (isn == NULL) |
| 164 | return FAIL; |
| 165 | |
| 166 | isn->isn_arg.number = idx; |
| 167 | return OK; |
| 168 | } |
| 169 | |
| 170 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 171 | * If type at "offset" isn't already VAR_STRING then generate ISN_2STRING. |
| 172 | * But only for simple types. |
| 173 | * When "tolerant" is TRUE convert most types to string, e.g. a List. |
| 174 | */ |
| 175 | int |
| 176 | may_generate_2STRING(int offset, int tolerant, cctx_T *cctx) |
| 177 | { |
| 178 | isn_T *isn; |
| 179 | isntype_T isntype = ISN_2STRING; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 180 | type_T *type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 181 | |
| 182 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 183 | type = get_type_on_stack(cctx, -1 - offset); |
| 184 | switch (type->tt_type) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 185 | { |
| 186 | // nothing to be done |
| 187 | case VAR_STRING: return OK; |
| 188 | |
| 189 | // conversion possible |
| 190 | case VAR_SPECIAL: |
| 191 | case VAR_BOOL: |
| 192 | case VAR_NUMBER: |
| 193 | case VAR_FLOAT: |
| 194 | break; |
| 195 | |
| 196 | // conversion possible (with runtime check) |
| 197 | case VAR_ANY: |
| 198 | case VAR_UNKNOWN: |
| 199 | isntype = ISN_2STRING_ANY; |
| 200 | break; |
| 201 | |
| 202 | // conversion possible when tolerant |
| 203 | case VAR_LIST: |
| 204 | if (tolerant) |
| 205 | { |
| 206 | isntype = ISN_2STRING_ANY; |
| 207 | break; |
| 208 | } |
| 209 | // FALLTHROUGH |
| 210 | |
| 211 | // conversion not possible |
| 212 | case VAR_VOID: |
| 213 | case VAR_BLOB: |
| 214 | case VAR_FUNC: |
| 215 | case VAR_PARTIAL: |
| 216 | case VAR_DICT: |
| 217 | case VAR_JOB: |
| 218 | case VAR_CHANNEL: |
| 219 | case VAR_INSTR: |
Bram Moolenaar | 00b28d6 | 2022-12-08 15:32:33 +0000 | [diff] [blame] | 220 | case VAR_CLASS: |
| 221 | case VAR_OBJECT: |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 222 | to_string_error(type->tt_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 223 | return FAIL; |
| 224 | } |
| 225 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 226 | set_type_on_stack(cctx, &t_string, -1 - offset); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 227 | if ((isn = generate_instr(cctx, isntype)) == NULL) |
| 228 | return FAIL; |
| 229 | isn->isn_arg.tostring.offset = offset; |
| 230 | isn->isn_arg.tostring.tolerant = tolerant; |
| 231 | |
| 232 | return OK; |
| 233 | } |
| 234 | |
| 235 | static int |
| 236 | check_number_or_float(vartype_T type1, vartype_T type2, char_u *op) |
| 237 | { |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 238 | if (!((type1 == VAR_NUMBER || type1 == VAR_FLOAT |
| 239 | || type1 == VAR_ANY || type1 == VAR_UNKNOWN) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 240 | && (type2 == VAR_NUMBER || type2 == VAR_FLOAT |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 241 | || type2 == VAR_ANY || type2 == VAR_UNKNOWN))) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 242 | { |
| 243 | if (*op == '+') |
| 244 | emsg(_(e_wrong_argument_type_for_plus)); |
| 245 | else |
| 246 | semsg(_(e_char_requires_number_or_float_arguments), *op); |
| 247 | return FAIL; |
| 248 | } |
| 249 | return OK; |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * Generate instruction for "+". For a list this creates a new list. |
| 254 | */ |
| 255 | int |
| 256 | generate_add_instr( |
| 257 | cctx_T *cctx, |
| 258 | vartype_T vartype, |
| 259 | type_T *type1, |
| 260 | type_T *type2, |
| 261 | exprtype_T expr_type) |
| 262 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 263 | isn_T *isn = generate_instr_drop(cctx, |
| 264 | vartype == VAR_NUMBER ? ISN_OPNR |
| 265 | : vartype == VAR_LIST ? ISN_ADDLIST |
| 266 | : vartype == VAR_BLOB ? ISN_ADDBLOB |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 267 | : vartype == VAR_FLOAT ? ISN_OPFLOAT |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 268 | : ISN_OPANY, 1); |
| 269 | |
| 270 | if (vartype != VAR_LIST && vartype != VAR_BLOB |
| 271 | && type1->tt_type != VAR_ANY |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 272 | && type1->tt_type != VAR_UNKNOWN |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 273 | && type2->tt_type != VAR_ANY |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 274 | && type2->tt_type != VAR_UNKNOWN |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 275 | && check_number_or_float( |
| 276 | type1->tt_type, type2->tt_type, (char_u *)"+") == FAIL) |
| 277 | return FAIL; |
| 278 | |
| 279 | if (isn != NULL) |
| 280 | { |
| 281 | if (isn->isn_type == ISN_ADDLIST) |
| 282 | isn->isn_arg.op.op_type = expr_type; |
| 283 | else |
| 284 | isn->isn_arg.op.op_type = EXPR_ADD; |
| 285 | } |
| 286 | |
| 287 | // When concatenating two lists with different member types the member type |
| 288 | // becomes "any". |
| 289 | if (vartype == VAR_LIST |
| 290 | && type1->tt_type == VAR_LIST && type2->tt_type == VAR_LIST |
| 291 | && type1->tt_member != type2->tt_member) |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 292 | set_type_on_stack(cctx, &t_list_any, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 293 | |
| 294 | return isn == NULL ? FAIL : OK; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Get the type to use for an instruction for an operation on "type1" and |
| 299 | * "type2". If they are matching use a type-specific instruction. Otherwise |
| 300 | * fall back to runtime type checking. |
| 301 | */ |
| 302 | vartype_T |
| 303 | operator_type(type_T *type1, type_T *type2) |
| 304 | { |
| 305 | if (type1->tt_type == type2->tt_type |
| 306 | && (type1->tt_type == VAR_NUMBER |
| 307 | || type1->tt_type == VAR_LIST |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 308 | || type1->tt_type == VAR_FLOAT |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 309 | || type1->tt_type == VAR_BLOB)) |
| 310 | return type1->tt_type; |
| 311 | return VAR_ANY; |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * Generate an instruction with two arguments. The instruction depends on the |
| 316 | * type of the arguments. |
| 317 | */ |
| 318 | int |
| 319 | generate_two_op(cctx_T *cctx, char_u *op) |
| 320 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 321 | type_T *type1; |
| 322 | type_T *type2; |
| 323 | vartype_T vartype; |
| 324 | isn_T *isn; |
| 325 | |
| 326 | RETURN_OK_IF_SKIP(cctx); |
| 327 | |
| 328 | // Get the known type of the two items on the stack. |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 329 | type1 = get_type_on_stack(cctx, 1); |
| 330 | type2 = get_type_on_stack(cctx, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 331 | vartype = operator_type(type1, type2); |
| 332 | |
| 333 | switch (*op) |
| 334 | { |
| 335 | case '+': |
| 336 | if (generate_add_instr(cctx, vartype, type1, type2, |
| 337 | EXPR_COPY) == FAIL) |
| 338 | return FAIL; |
| 339 | break; |
| 340 | |
| 341 | case '-': |
| 342 | case '*': |
| 343 | case '/': if (check_number_or_float(type1->tt_type, type2->tt_type, |
| 344 | op) == FAIL) |
| 345 | return FAIL; |
| 346 | if (vartype == VAR_NUMBER) |
| 347 | isn = generate_instr_drop(cctx, ISN_OPNR, 1); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 348 | else if (vartype == VAR_FLOAT) |
| 349 | isn = generate_instr_drop(cctx, ISN_OPFLOAT, 1); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 350 | else |
| 351 | isn = generate_instr_drop(cctx, ISN_OPANY, 1); |
| 352 | if (isn != NULL) |
| 353 | isn->isn_arg.op.op_type = *op == '*' |
| 354 | ? EXPR_MULT : *op == '/'? EXPR_DIV : EXPR_SUB; |
| 355 | break; |
| 356 | |
| 357 | case '%': if ((type1->tt_type != VAR_ANY |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 358 | && type1->tt_type != VAR_UNKNOWN |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 359 | && type1->tt_type != VAR_NUMBER) |
| 360 | || (type2->tt_type != VAR_ANY |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 361 | && type2->tt_type != VAR_UNKNOWN |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 362 | && type2->tt_type != VAR_NUMBER)) |
| 363 | { |
| 364 | emsg(_(e_percent_requires_number_arguments)); |
| 365 | return FAIL; |
| 366 | } |
| 367 | isn = generate_instr_drop(cctx, |
| 368 | vartype == VAR_NUMBER ? ISN_OPNR : ISN_OPANY, 1); |
| 369 | if (isn != NULL) |
| 370 | isn->isn_arg.op.op_type = EXPR_REM; |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | // correct type of result |
| 375 | if (vartype == VAR_ANY) |
| 376 | { |
| 377 | type_T *type = &t_any; |
| 378 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 379 | // float+number and number+float results in float |
| 380 | if ((type1->tt_type == VAR_NUMBER || type1->tt_type == VAR_FLOAT) |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 381 | && (type2->tt_type == VAR_NUMBER || type2->tt_type == VAR_FLOAT)) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 382 | type = &t_float; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 383 | set_type_on_stack(cctx, type, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | return OK; |
| 387 | } |
| 388 | |
| 389 | /* |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 390 | * Get the instruction to use for comparing two values with specified types. |
| 391 | * Either "tv1" and "tv2" are passed or "type1" and "type2". |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 392 | * Return ISN_DROP when failed. |
| 393 | */ |
| 394 | static isntype_T |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 395 | get_compare_isn( |
| 396 | exprtype_T exprtype, |
| 397 | typval_T *tv1, |
| 398 | typval_T *tv2, |
| 399 | type_T *type1, |
| 400 | type_T *type2) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 401 | { |
| 402 | isntype_T isntype = ISN_DROP; |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 403 | vartype_T vartype1 = tv1 != NULL ? tv1->v_type : type1->tt_type; |
| 404 | vartype_T vartype2 = tv2 != NULL ? tv2->v_type : type2->tt_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 405 | |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 406 | if (vartype1 == vartype2) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 407 | { |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 408 | switch (vartype1) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 409 | { |
| 410 | case VAR_BOOL: isntype = ISN_COMPAREBOOL; break; |
| 411 | case VAR_SPECIAL: isntype = ISN_COMPARESPECIAL; break; |
| 412 | case VAR_NUMBER: isntype = ISN_COMPARENR; break; |
| 413 | case VAR_FLOAT: isntype = ISN_COMPAREFLOAT; break; |
| 414 | case VAR_STRING: isntype = ISN_COMPARESTRING; break; |
| 415 | case VAR_BLOB: isntype = ISN_COMPAREBLOB; break; |
| 416 | case VAR_LIST: isntype = ISN_COMPARELIST; break; |
| 417 | case VAR_DICT: isntype = ISN_COMPAREDICT; break; |
| 418 | case VAR_FUNC: isntype = ISN_COMPAREFUNC; break; |
| 419 | default: isntype = ISN_COMPAREANY; break; |
| 420 | } |
| 421 | } |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 422 | else if (vartype1 == VAR_ANY || vartype2 == VAR_ANY |
| 423 | || ((vartype1 == VAR_NUMBER || vartype1 == VAR_FLOAT) |
| 424 | && (vartype2 == VAR_NUMBER || vartype2 == VAR_FLOAT)) |
| 425 | || (vartype1 == VAR_FUNC && vartype2 == VAR_PARTIAL) |
| 426 | || (vartype1 == VAR_PARTIAL && vartype2 == VAR_FUNC)) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 427 | isntype = ISN_COMPAREANY; |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 428 | else if (vartype1 == VAR_SPECIAL || vartype2 == VAR_SPECIAL) |
Bram Moolenaar | 7a22224 | 2022-03-01 19:23:24 +0000 | [diff] [blame] | 429 | { |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 430 | if ((vartype1 == VAR_SPECIAL |
| 431 | && (tv1 != NULL ? tv1->vval.v_number == VVAL_NONE |
| 432 | : type1 == &t_none) |
| 433 | && vartype2 != VAR_STRING) |
| 434 | || (vartype2 == VAR_SPECIAL |
| 435 | && (tv2 != NULL ? tv2->vval.v_number == VVAL_NONE |
| 436 | : type2 == &t_none) |
| 437 | && vartype1 != VAR_STRING)) |
| 438 | { |
| 439 | semsg(_(e_cannot_compare_str_with_str), |
| 440 | vartype_name(vartype1), vartype_name(vartype2)); |
| 441 | return ISN_DROP; |
| 442 | } |
Bram Moolenaar | 0566781 | 2022-03-15 20:21:33 +0000 | [diff] [blame] | 443 | // although comparing null with number, float or bool is not useful, we |
| 444 | // allow it |
Bram Moolenaar | 7a22224 | 2022-03-01 19:23:24 +0000 | [diff] [blame] | 445 | isntype = ISN_COMPARENULL; |
| 446 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 447 | |
| 448 | if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT) |
| 449 | && (isntype == ISN_COMPAREBOOL |
| 450 | || isntype == ISN_COMPARESPECIAL |
| 451 | || isntype == ISN_COMPARENR |
| 452 | || isntype == ISN_COMPAREFLOAT)) |
| 453 | { |
| 454 | semsg(_(e_cannot_use_str_with_str), |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 455 | exprtype == EXPR_IS ? "is" : "isnot" , vartype_name(vartype1)); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 456 | return ISN_DROP; |
| 457 | } |
| 458 | if (isntype == ISN_DROP |
| 459 | || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 460 | && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL |
| 461 | || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL))) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 462 | || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL |
Bram Moolenaar | 7a22224 | 2022-03-01 19:23:24 +0000 | [diff] [blame] | 463 | && exprtype != EXPR_IS && exprtype != EXPR_ISNOT |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 464 | && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB |
| 465 | || vartype1 == VAR_LIST || vartype2 == VAR_LIST)))) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 466 | { |
| 467 | semsg(_(e_cannot_compare_str_with_str), |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 468 | vartype_name(vartype1), vartype_name(vartype2)); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 469 | return ISN_DROP; |
| 470 | } |
| 471 | return isntype; |
| 472 | } |
| 473 | |
| 474 | int |
| 475 | check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2) |
| 476 | { |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 477 | if (get_compare_isn(type, tv1, tv2, NULL, NULL) == ISN_DROP) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 478 | return FAIL; |
| 479 | return OK; |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * Generate an ISN_COMPARE* instruction with a boolean result. |
| 484 | */ |
| 485 | int |
| 486 | generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic) |
| 487 | { |
| 488 | isntype_T isntype; |
| 489 | isn_T *isn; |
| 490 | garray_T *stack = &cctx->ctx_type_stack; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 491 | |
| 492 | RETURN_OK_IF_SKIP(cctx); |
| 493 | |
| 494 | // Get the known type of the two items on the stack. If they are matching |
| 495 | // use a type-specific instruction. Otherwise fall back to runtime type |
| 496 | // checking. |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 497 | isntype = get_compare_isn(exprtype, NULL, NULL, |
| 498 | get_type_on_stack(cctx, 1), get_type_on_stack(cctx, 0)); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 499 | if (isntype == ISN_DROP) |
| 500 | return FAIL; |
| 501 | |
| 502 | if ((isn = generate_instr(cctx, isntype)) == NULL) |
| 503 | return FAIL; |
| 504 | isn->isn_arg.op.op_type = exprtype; |
| 505 | isn->isn_arg.op.op_ic = ic; |
| 506 | |
| 507 | // takes two arguments, puts one bool back |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 508 | --stack->ga_len; |
| 509 | set_type_on_stack(cctx, &t_bool, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 510 | |
| 511 | return OK; |
| 512 | } |
| 513 | |
| 514 | /* |
LemonBoy | 372bcce | 2022-04-25 12:43:20 +0100 | [diff] [blame] | 515 | * Generate an ISN_CONCAT instruction. |
| 516 | * "count" is the number of stack elements to join together and it must be |
| 517 | * greater or equal to one. |
| 518 | * The caller ensures all the "count" elements on the stack have the right type. |
| 519 | */ |
| 520 | int |
| 521 | generate_CONCAT(cctx_T *cctx, int count) |
| 522 | { |
| 523 | isn_T *isn; |
| 524 | garray_T *stack = &cctx->ctx_type_stack; |
| 525 | |
| 526 | RETURN_OK_IF_SKIP(cctx); |
| 527 | |
LemonBoy | 372bcce | 2022-04-25 12:43:20 +0100 | [diff] [blame] | 528 | if ((isn = generate_instr(cctx, ISN_CONCAT)) == NULL) |
| 529 | return FAIL; |
| 530 | isn->isn_arg.number = count; |
| 531 | |
| 532 | // drop the argument types |
| 533 | stack->ga_len -= count - 1; |
| 534 | |
| 535 | return OK; |
| 536 | } |
| 537 | |
| 538 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 539 | * Generate an ISN_2BOOL instruction. |
| 540 | * "offset" is the offset in the type stack. |
| 541 | */ |
| 542 | int |
| 543 | generate_2BOOL(cctx_T *cctx, int invert, int offset) |
| 544 | { |
| 545 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 546 | |
| 547 | RETURN_OK_IF_SKIP(cctx); |
| 548 | if ((isn = generate_instr(cctx, ISN_2BOOL)) == NULL) |
| 549 | return FAIL; |
| 550 | isn->isn_arg.tobool.invert = invert; |
| 551 | isn->isn_arg.tobool.offset = offset; |
| 552 | |
| 553 | // type becomes bool |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 554 | set_type_on_stack(cctx, &t_bool, -1 - offset); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 555 | |
| 556 | return OK; |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Generate an ISN_COND2BOOL instruction. |
| 561 | */ |
| 562 | int |
| 563 | generate_COND2BOOL(cctx_T *cctx) |
| 564 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 565 | RETURN_OK_IF_SKIP(cctx); |
Yegappan Lakshmanan | 6b085b9 | 2022-09-04 12:47:21 +0100 | [diff] [blame] | 566 | if (generate_instr(cctx, ISN_COND2BOOL) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 567 | return FAIL; |
| 568 | |
| 569 | // type becomes bool |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 570 | set_type_on_stack(cctx, &t_bool, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 571 | |
| 572 | return OK; |
| 573 | } |
| 574 | |
| 575 | int |
| 576 | generate_TYPECHECK( |
| 577 | cctx_T *cctx, |
| 578 | type_T *expected, |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 579 | int number_ok, // add TTFLAG_NUMBER_OK flag |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 580 | int offset, |
Bram Moolenaar | bd3a9d2 | 2022-05-17 16:12:39 +0100 | [diff] [blame] | 581 | int is_var, |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 582 | int argidx) |
| 583 | { |
| 584 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 585 | |
| 586 | RETURN_OK_IF_SKIP(cctx); |
| 587 | if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL) |
| 588 | return FAIL; |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 589 | type_T *tt; |
| 590 | if (expected->tt_type == VAR_FLOAT && number_ok) |
| 591 | { |
| 592 | // always allocate, also for static types |
| 593 | tt = ALLOC_ONE(type_T); |
| 594 | if (tt != NULL) |
| 595 | { |
| 596 | *tt = *expected; |
| 597 | tt->tt_flags |= TTFLAG_NUMBER_OK; |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | tt = alloc_type(expected); |
| 602 | |
| 603 | isn->isn_arg.type.ct_type = tt; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 604 | isn->isn_arg.type.ct_off = (int8_T)offset; |
Bram Moolenaar | bd3a9d2 | 2022-05-17 16:12:39 +0100 | [diff] [blame] | 605 | isn->isn_arg.type.ct_is_var = is_var; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 606 | isn->isn_arg.type.ct_arg_idx = (int8_T)argidx; |
| 607 | |
| 608 | // type becomes expected |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 609 | set_type_on_stack(cctx, expected, -1 - offset); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 610 | |
| 611 | return OK; |
| 612 | } |
| 613 | |
| 614 | int |
| 615 | generate_SETTYPE( |
| 616 | cctx_T *cctx, |
| 617 | type_T *expected) |
| 618 | { |
| 619 | isn_T *isn; |
| 620 | |
| 621 | RETURN_OK_IF_SKIP(cctx); |
| 622 | if ((isn = generate_instr(cctx, ISN_SETTYPE)) == NULL) |
| 623 | return FAIL; |
| 624 | isn->isn_arg.type.ct_type = alloc_type(expected); |
| 625 | return OK; |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | * Generate a PUSH instruction for "tv". |
| 630 | * "tv" will be consumed or cleared. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 631 | */ |
| 632 | int |
| 633 | generate_tv_PUSH(cctx_T *cctx, typval_T *tv) |
| 634 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 635 | switch (tv->v_type) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 636 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 637 | case VAR_BOOL: |
| 638 | generate_PUSHBOOL(cctx, tv->vval.v_number); |
| 639 | break; |
| 640 | case VAR_SPECIAL: |
| 641 | generate_PUSHSPEC(cctx, tv->vval.v_number); |
| 642 | break; |
| 643 | case VAR_NUMBER: |
| 644 | generate_PUSHNR(cctx, tv->vval.v_number); |
| 645 | break; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 646 | case VAR_FLOAT: |
| 647 | generate_PUSHF(cctx, tv->vval.v_float); |
| 648 | break; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 649 | case VAR_BLOB: |
| 650 | generate_PUSHBLOB(cctx, tv->vval.v_blob); |
| 651 | tv->vval.v_blob = NULL; |
| 652 | break; |
| 653 | case VAR_LIST: |
| 654 | if (tv->vval.v_list != NULL) |
| 655 | iemsg("non-empty list constant not supported"); |
| 656 | generate_NEWLIST(cctx, 0, TRUE); |
| 657 | break; |
| 658 | case VAR_DICT: |
| 659 | if (tv->vval.v_dict != NULL) |
| 660 | iemsg("non-empty dict constant not supported"); |
| 661 | generate_NEWDICT(cctx, 0, TRUE); |
| 662 | break; |
Bram Moolenaar | 8acb9cc | 2022-03-08 13:18:55 +0000 | [diff] [blame] | 663 | #ifdef FEAT_JOB_CHANNEL |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 664 | case VAR_JOB: |
| 665 | if (tv->vval.v_job != NULL) |
| 666 | iemsg("non-null job constant not supported"); |
| 667 | generate_PUSHJOB(cctx); |
| 668 | break; |
| 669 | case VAR_CHANNEL: |
| 670 | if (tv->vval.v_channel != NULL) |
| 671 | iemsg("non-null channel constant not supported"); |
| 672 | generate_PUSHCHANNEL(cctx); |
| 673 | break; |
Bram Moolenaar | 8acb9cc | 2022-03-08 13:18:55 +0000 | [diff] [blame] | 674 | #endif |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 675 | case VAR_FUNC: |
| 676 | if (tv->vval.v_string != NULL) |
| 677 | iemsg("non-null function constant not supported"); |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 678 | generate_PUSHFUNC(cctx, NULL, &t_func_unknown, TRUE); |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 679 | break; |
| 680 | case VAR_PARTIAL: |
| 681 | if (tv->vval.v_partial != NULL) |
| 682 | iemsg("non-null partial constant not supported"); |
| 683 | if (generate_instr_type(cctx, ISN_NEWPARTIAL, &t_func_unknown) |
| 684 | == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 685 | return FAIL; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 686 | break; |
| 687 | case VAR_STRING: |
| 688 | generate_PUSHS(cctx, &tv->vval.v_string); |
| 689 | tv->vval.v_string = NULL; |
| 690 | break; |
| 691 | default: |
| 692 | siemsg("constant type %d not supported", tv->v_type); |
| 693 | clear_tv(tv); |
| 694 | return FAIL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 695 | } |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 696 | tv->v_type = VAR_UNKNOWN; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 697 | return OK; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Generate an ISN_PUSHNR instruction. |
| 702 | */ |
| 703 | int |
| 704 | generate_PUSHNR(cctx_T *cctx, varnumber_T number) |
| 705 | { |
| 706 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 707 | |
| 708 | RETURN_OK_IF_SKIP(cctx); |
| 709 | if ((isn = generate_instr_type(cctx, ISN_PUSHNR, &t_number)) == NULL) |
| 710 | return FAIL; |
| 711 | isn->isn_arg.number = number; |
| 712 | |
| 713 | if (number == 0 || number == 1) |
| 714 | // A 0 or 1 number can also be used as a bool. |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 715 | set_type_on_stack(cctx, &t_number_bool, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 716 | return OK; |
| 717 | } |
| 718 | |
| 719 | /* |
| 720 | * Generate an ISN_PUSHBOOL instruction. |
| 721 | */ |
| 722 | int |
| 723 | generate_PUSHBOOL(cctx_T *cctx, varnumber_T number) |
| 724 | { |
| 725 | isn_T *isn; |
| 726 | |
| 727 | RETURN_OK_IF_SKIP(cctx); |
| 728 | if ((isn = generate_instr_type(cctx, ISN_PUSHBOOL, &t_bool)) == NULL) |
| 729 | return FAIL; |
| 730 | isn->isn_arg.number = number; |
| 731 | |
| 732 | return OK; |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * Generate an ISN_PUSHSPEC instruction. |
| 737 | */ |
| 738 | int |
| 739 | generate_PUSHSPEC(cctx_T *cctx, varnumber_T number) |
| 740 | { |
| 741 | isn_T *isn; |
| 742 | |
| 743 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 744 | if ((isn = generate_instr_type(cctx, ISN_PUSHSPEC, |
| 745 | number == VVAL_NULL ? &t_null : &t_none)) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 746 | return FAIL; |
| 747 | isn->isn_arg.number = number; |
| 748 | |
| 749 | return OK; |
| 750 | } |
| 751 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 752 | /* |
| 753 | * Generate an ISN_PUSHF instruction. |
| 754 | */ |
| 755 | int |
| 756 | generate_PUSHF(cctx_T *cctx, float_T fnumber) |
| 757 | { |
| 758 | isn_T *isn; |
| 759 | |
| 760 | RETURN_OK_IF_SKIP(cctx); |
| 761 | if ((isn = generate_instr_type(cctx, ISN_PUSHF, &t_float)) == NULL) |
| 762 | return FAIL; |
| 763 | isn->isn_arg.fnumber = fnumber; |
| 764 | |
| 765 | return OK; |
| 766 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * Generate an ISN_PUSHS instruction. |
| 770 | * Consumes "*str". When freed *str is set to NULL, unless "str" is NULL. |
Bram Moolenaar | 0abc287 | 2022-05-10 13:24:30 +0100 | [diff] [blame] | 771 | * Note that if "str" is used in the instruction OK is returned and "*str" is |
| 772 | * not set to NULL. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 773 | */ |
| 774 | int |
| 775 | generate_PUSHS(cctx_T *cctx, char_u **str) |
| 776 | { |
| 777 | isn_T *isn; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 778 | int ret = OK; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 779 | |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 780 | if (cctx->ctx_skip != SKIP_YES) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 781 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 782 | if ((isn = generate_instr_type(cctx, ISN_PUSHS, &t_string)) == NULL) |
| 783 | ret = FAIL; |
| 784 | else |
| 785 | { |
| 786 | isn->isn_arg.string = str == NULL ? NULL : *str; |
| 787 | return OK; |
| 788 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 789 | } |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 790 | if (str != NULL) |
| 791 | VIM_CLEAR(*str); |
| 792 | return ret; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 796 | * Generate an ISN_PUSHCHANNEL instruction. Channel is always NULL. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 797 | */ |
| 798 | int |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 799 | generate_PUSHCHANNEL(cctx_T *cctx) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 800 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 801 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | c9af617 | 2022-05-04 16:46:54 +0100 | [diff] [blame] | 802 | #ifdef FEAT_JOB_CHANNEL |
Yegappan Lakshmanan | 6b085b9 | 2022-09-04 12:47:21 +0100 | [diff] [blame] | 803 | if (generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 804 | return FAIL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 805 | return OK; |
Bram Moolenaar | c9af617 | 2022-05-04 16:46:54 +0100 | [diff] [blame] | 806 | #else |
| 807 | emsg(_(e_channel_job_feature_not_available)); |
| 808 | return FAIL; |
| 809 | #endif |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 813 | * Generate an ISN_PUSHJOB instruction. Job is always NULL. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 814 | */ |
| 815 | int |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 816 | generate_PUSHJOB(cctx_T *cctx) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 817 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 818 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | c9af617 | 2022-05-04 16:46:54 +0100 | [diff] [blame] | 819 | #ifdef FEAT_JOB_CHANNEL |
Yegappan Lakshmanan | 6b085b9 | 2022-09-04 12:47:21 +0100 | [diff] [blame] | 820 | if (generate_instr_type(cctx, ISN_PUSHJOB, &t_job) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 821 | return FAIL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 822 | return OK; |
Bram Moolenaar | c9af617 | 2022-05-04 16:46:54 +0100 | [diff] [blame] | 823 | #else |
| 824 | emsg(_(e_channel_job_feature_not_available)); |
| 825 | return FAIL; |
| 826 | #endif |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /* |
| 830 | * Generate an ISN_PUSHBLOB instruction. |
| 831 | * Consumes "blob". |
| 832 | */ |
| 833 | int |
| 834 | generate_PUSHBLOB(cctx_T *cctx, blob_T *blob) |
| 835 | { |
| 836 | isn_T *isn; |
| 837 | |
| 838 | RETURN_OK_IF_SKIP(cctx); |
| 839 | if ((isn = generate_instr_type(cctx, ISN_PUSHBLOB, &t_blob)) == NULL) |
| 840 | return FAIL; |
| 841 | isn->isn_arg.blob = blob; |
| 842 | |
| 843 | return OK; |
| 844 | } |
| 845 | |
| 846 | /* |
| 847 | * Generate an ISN_PUSHFUNC instruction with name "name". |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 848 | * When "may_prefix" is TRUE prefix "g:" unless "name" is script-local or |
| 849 | * autoload. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 850 | */ |
| 851 | int |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 852 | generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type, int may_prefix) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 853 | { |
| 854 | isn_T *isn; |
| 855 | char_u *funcname; |
| 856 | |
| 857 | RETURN_OK_IF_SKIP(cctx); |
| 858 | if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL) |
| 859 | return FAIL; |
| 860 | if (name == NULL) |
| 861 | funcname = NULL; |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 862 | else if (!may_prefix |
| 863 | || *name == K_SPECIAL // script-local |
Bram Moolenaar | d041f42 | 2022-01-12 19:54:00 +0000 | [diff] [blame] | 864 | || vim_strchr(name, AUTOLOAD_CHAR) != NULL) // autoload |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 865 | funcname = vim_strsave(name); |
| 866 | else |
| 867 | { |
| 868 | funcname = alloc(STRLEN(name) + 3); |
| 869 | if (funcname != NULL) |
| 870 | { |
| 871 | STRCPY(funcname, "g:"); |
| 872 | STRCPY(funcname + 2, name); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | isn->isn_arg.string = funcname; |
| 877 | return OK; |
| 878 | } |
| 879 | |
| 880 | /* |
Bram Moolenaar | 06b7722 | 2022-01-25 15:51:56 +0000 | [diff] [blame] | 881 | * Generate an ISN_AUTOLOAD instruction. |
| 882 | */ |
| 883 | int |
| 884 | generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type) |
| 885 | { |
| 886 | isn_T *isn; |
| 887 | |
| 888 | RETURN_OK_IF_SKIP(cctx); |
| 889 | if ((isn = generate_instr_type(cctx, ISN_AUTOLOAD, type)) == NULL) |
| 890 | return FAIL; |
| 891 | isn->isn_arg.string = vim_strsave(name); |
| 892 | if (isn->isn_arg.string == NULL) |
| 893 | return FAIL; |
| 894 | return OK; |
| 895 | } |
| 896 | |
| 897 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 898 | * Generate an ISN_GETITEM instruction with "index". |
| 899 | * "with_op" is TRUE for "+=" and other operators, the stack has the current |
| 900 | * value below the list with values. |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 901 | * Caller must check the type is a list. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 902 | */ |
| 903 | int |
| 904 | generate_GETITEM(cctx_T *cctx, int index, int with_op) |
| 905 | { |
| 906 | isn_T *isn; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 907 | type_T *type = get_type_on_stack(cctx, with_op ? 1 : 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 908 | type_T *item_type = &t_any; |
| 909 | |
| 910 | RETURN_OK_IF_SKIP(cctx); |
| 911 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 912 | item_type = type->tt_member; |
| 913 | if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL) |
| 914 | return FAIL; |
| 915 | isn->isn_arg.getitem.gi_index = index; |
| 916 | isn->isn_arg.getitem.gi_with_op = with_op; |
| 917 | |
| 918 | // add the item type to the type stack |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 919 | return push_type_stack(cctx, item_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Generate an ISN_SLICE instruction with "count". |
| 924 | */ |
| 925 | int |
| 926 | generate_SLICE(cctx_T *cctx, int count) |
| 927 | { |
| 928 | isn_T *isn; |
| 929 | |
| 930 | RETURN_OK_IF_SKIP(cctx); |
| 931 | if ((isn = generate_instr(cctx, ISN_SLICE)) == NULL) |
| 932 | return FAIL; |
| 933 | isn->isn_arg.number = count; |
| 934 | return OK; |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * Generate an ISN_CHECKLEN instruction with "min_len". |
| 939 | */ |
| 940 | int |
| 941 | generate_CHECKLEN(cctx_T *cctx, int min_len, int more_OK) |
| 942 | { |
| 943 | isn_T *isn; |
| 944 | |
| 945 | RETURN_OK_IF_SKIP(cctx); |
| 946 | |
| 947 | if ((isn = generate_instr(cctx, ISN_CHECKLEN)) == NULL) |
| 948 | return FAIL; |
| 949 | isn->isn_arg.checklen.cl_min_len = min_len; |
| 950 | isn->isn_arg.checklen.cl_more_OK = more_OK; |
| 951 | |
| 952 | return OK; |
| 953 | } |
| 954 | |
| 955 | /* |
| 956 | * Generate an ISN_STORE instruction. |
| 957 | */ |
| 958 | int |
| 959 | generate_STORE(cctx_T *cctx, isntype_T isn_type, int idx, char_u *name) |
| 960 | { |
| 961 | isn_T *isn; |
| 962 | |
| 963 | RETURN_OK_IF_SKIP(cctx); |
| 964 | if ((isn = generate_instr_drop(cctx, isn_type, 1)) == NULL) |
| 965 | return FAIL; |
| 966 | if (name != NULL) |
| 967 | isn->isn_arg.string = vim_strsave(name); |
| 968 | else |
| 969 | isn->isn_arg.number = idx; |
| 970 | |
| 971 | return OK; |
| 972 | } |
| 973 | |
| 974 | /* |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 975 | * Generate an ISN_LOAD_CLASSMEMBER ("load" == TRUE) or ISN_STORE_CLASSMEMBER |
| 976 | * ("load" == FALSE) instruction. |
| 977 | */ |
| 978 | int |
| 979 | generate_CLASSMEMBER( |
| 980 | cctx_T *cctx, |
| 981 | int load, |
| 982 | class_T *cl, |
| 983 | int idx) |
| 984 | { |
| 985 | isn_T *isn; |
| 986 | |
| 987 | RETURN_OK_IF_SKIP(cctx); |
| 988 | if (load) |
| 989 | { |
| 990 | ocmember_T *m = &cl->class_class_members[idx]; |
| 991 | isn = generate_instr_type(cctx, ISN_LOAD_CLASSMEMBER, m->ocm_type); |
| 992 | } |
| 993 | else |
| 994 | { |
| 995 | isn = generate_instr_drop(cctx, ISN_STORE_CLASSMEMBER, 1); |
| 996 | } |
| 997 | if (isn == NULL) |
| 998 | return FAIL; |
| 999 | isn->isn_arg.classmember.cm_class = cl; |
| 1000 | ++cl->class_refcount; |
| 1001 | isn->isn_arg.classmember.cm_idx = idx; |
| 1002 | |
| 1003 | return OK; |
| 1004 | } |
| 1005 | |
| 1006 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1007 | * Generate an ISN_STOREOUTER instruction. |
| 1008 | */ |
Yegappan Lakshmanan | 782b43d | 2022-01-08 18:43:40 +0000 | [diff] [blame] | 1009 | static int |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1010 | generate_STOREOUTER(cctx_T *cctx, int idx, int level, int loop_idx) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1011 | { |
| 1012 | isn_T *isn; |
| 1013 | |
| 1014 | RETURN_OK_IF_SKIP(cctx); |
| 1015 | if ((isn = generate_instr_drop(cctx, ISN_STOREOUTER, 1)) == NULL) |
| 1016 | return FAIL; |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1017 | if (level == 1 && loop_idx >= 0 && idx >= loop_idx) |
| 1018 | { |
| 1019 | // Store a variable defined in a loop. A copy will be made at the end |
| 1020 | // of the loop. TODO: how about deeper nesting? |
| 1021 | isn->isn_arg.outer.outer_idx = idx - loop_idx; |
| 1022 | isn->isn_arg.outer.outer_depth = OUTER_LOOP_DEPTH; |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | isn->isn_arg.outer.outer_idx = idx; |
| 1027 | isn->isn_arg.outer.outer_depth = level; |
| 1028 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1029 | |
| 1030 | return OK; |
| 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | * Generate an ISN_STORENR instruction (short for ISN_PUSHNR + ISN_STORE) |
| 1035 | */ |
| 1036 | int |
| 1037 | generate_STORENR(cctx_T *cctx, int idx, varnumber_T value) |
| 1038 | { |
| 1039 | isn_T *isn; |
| 1040 | |
| 1041 | RETURN_OK_IF_SKIP(cctx); |
| 1042 | if ((isn = generate_instr(cctx, ISN_STORENR)) == NULL) |
| 1043 | return FAIL; |
| 1044 | isn->isn_arg.storenr.stnr_idx = idx; |
| 1045 | isn->isn_arg.storenr.stnr_val = value; |
| 1046 | |
| 1047 | return OK; |
| 1048 | } |
| 1049 | |
| 1050 | /* |
| 1051 | * Generate an ISN_STOREOPT or ISN_STOREFUNCOPT instruction |
| 1052 | */ |
Yegappan Lakshmanan | 782b43d | 2022-01-08 18:43:40 +0000 | [diff] [blame] | 1053 | static int |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1054 | generate_STOREOPT( |
| 1055 | cctx_T *cctx, |
| 1056 | isntype_T isn_type, |
| 1057 | char_u *name, |
| 1058 | int opt_flags) |
| 1059 | { |
| 1060 | isn_T *isn; |
| 1061 | |
| 1062 | RETURN_OK_IF_SKIP(cctx); |
| 1063 | if ((isn = generate_instr_drop(cctx, isn_type, 1)) == NULL) |
| 1064 | return FAIL; |
| 1065 | isn->isn_arg.storeopt.so_name = vim_strsave(name); |
| 1066 | isn->isn_arg.storeopt.so_flags = opt_flags; |
| 1067 | |
| 1068 | return OK; |
| 1069 | } |
| 1070 | |
| 1071 | /* |
| 1072 | * Generate an ISN_LOAD or similar instruction. |
| 1073 | */ |
| 1074 | int |
| 1075 | generate_LOAD( |
| 1076 | cctx_T *cctx, |
| 1077 | isntype_T isn_type, |
| 1078 | int idx, |
| 1079 | char_u *name, |
| 1080 | type_T *type) |
| 1081 | { |
| 1082 | isn_T *isn; |
| 1083 | |
| 1084 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1085 | if ((isn = generate_instr_type2(cctx, isn_type, type, type)) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1086 | return FAIL; |
| 1087 | if (name != NULL) |
| 1088 | isn->isn_arg.string = vim_strsave(name); |
| 1089 | else |
| 1090 | isn->isn_arg.number = idx; |
| 1091 | |
| 1092 | return OK; |
| 1093 | } |
| 1094 | |
| 1095 | /* |
| 1096 | * Generate an ISN_LOADOUTER instruction |
| 1097 | */ |
| 1098 | int |
| 1099 | generate_LOADOUTER( |
| 1100 | cctx_T *cctx, |
| 1101 | int idx, |
| 1102 | int nesting, |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1103 | int loop_depth, |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1104 | int loop_idx, |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1105 | type_T *type) |
| 1106 | { |
| 1107 | isn_T *isn; |
| 1108 | |
| 1109 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1110 | if ((isn = generate_instr_type2(cctx, ISN_LOADOUTER, type, type)) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1111 | return FAIL; |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1112 | if (nesting == 1 && loop_idx >= 0 && idx >= loop_idx) |
| 1113 | { |
| 1114 | // Load a variable defined in a loop. A copy will be made at the end |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1115 | // of the loop. |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1116 | isn->isn_arg.outer.outer_idx = idx - loop_idx; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1117 | isn->isn_arg.outer.outer_depth = -loop_depth - 1; |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1118 | } |
| 1119 | else |
| 1120 | { |
| 1121 | isn->isn_arg.outer.outer_idx = idx; |
| 1122 | isn->isn_arg.outer.outer_depth = nesting; |
| 1123 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1124 | |
| 1125 | return OK; |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | * Generate an ISN_LOADV instruction for v:var. |
| 1130 | */ |
| 1131 | int |
| 1132 | generate_LOADV( |
| 1133 | cctx_T *cctx, |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1134 | char_u *name) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1135 | { |
| 1136 | int di_flags; |
| 1137 | int vidx = find_vim_var(name, &di_flags); |
| 1138 | type_T *type; |
| 1139 | |
| 1140 | RETURN_OK_IF_SKIP(cctx); |
| 1141 | if (vidx < 0) |
| 1142 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1143 | semsg(_(e_variable_not_found_str), name); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1144 | return FAIL; |
| 1145 | } |
Bram Moolenaar | d787e40 | 2021-12-24 21:36:12 +0000 | [diff] [blame] | 1146 | type = get_vim_var_type(vidx, cctx->ctx_type_list); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1147 | return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type); |
| 1148 | } |
| 1149 | |
| 1150 | /* |
| 1151 | * Generate an ISN_UNLET instruction. |
| 1152 | */ |
| 1153 | int |
| 1154 | generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit) |
| 1155 | { |
| 1156 | isn_T *isn; |
| 1157 | |
| 1158 | RETURN_OK_IF_SKIP(cctx); |
| 1159 | if ((isn = generate_instr(cctx, isn_type)) == NULL) |
| 1160 | return FAIL; |
| 1161 | isn->isn_arg.unlet.ul_name = vim_strsave(name); |
| 1162 | isn->isn_arg.unlet.ul_forceit = forceit; |
| 1163 | |
| 1164 | return OK; |
| 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | * Generate an ISN_LOCKCONST instruction. |
| 1169 | */ |
| 1170 | int |
| 1171 | generate_LOCKCONST(cctx_T *cctx) |
| 1172 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1173 | RETURN_OK_IF_SKIP(cctx); |
Yegappan Lakshmanan | 6b085b9 | 2022-09-04 12:47:21 +0100 | [diff] [blame] | 1174 | if (generate_instr(cctx, ISN_LOCKCONST) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1175 | return FAIL; |
| 1176 | return OK; |
| 1177 | } |
| 1178 | |
| 1179 | /* |
| 1180 | * Generate an ISN_LOADS instruction. |
| 1181 | */ |
| 1182 | int |
| 1183 | generate_OLDSCRIPT( |
| 1184 | cctx_T *cctx, |
| 1185 | isntype_T isn_type, |
| 1186 | char_u *name, |
| 1187 | int sid, |
| 1188 | type_T *type) |
| 1189 | { |
| 1190 | isn_T *isn; |
| 1191 | |
| 1192 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 1193 | if (isn_type == ISN_LOADS || isn_type == ISN_LOADEXPORT) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1194 | isn = generate_instr_type(cctx, isn_type, type); |
| 1195 | else |
| 1196 | isn = generate_instr_drop(cctx, isn_type, 1); |
| 1197 | if (isn == NULL) |
| 1198 | return FAIL; |
| 1199 | isn->isn_arg.loadstore.ls_name = vim_strsave(name); |
| 1200 | isn->isn_arg.loadstore.ls_sid = sid; |
| 1201 | |
| 1202 | return OK; |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * Generate an ISN_LOADSCRIPT or ISN_STORESCRIPT instruction. |
| 1207 | */ |
| 1208 | int |
| 1209 | generate_VIM9SCRIPT( |
| 1210 | cctx_T *cctx, |
| 1211 | isntype_T isn_type, |
| 1212 | int sid, |
| 1213 | int idx, |
| 1214 | type_T *type) |
| 1215 | { |
| 1216 | isn_T *isn; |
| 1217 | scriptref_T *sref; |
| 1218 | scriptitem_T *si = SCRIPT_ITEM(sid); |
| 1219 | |
| 1220 | RETURN_OK_IF_SKIP(cctx); |
| 1221 | if (isn_type == ISN_LOADSCRIPT) |
Bram Moolenaar | 160afdb | 2022-02-06 17:17:02 +0000 | [diff] [blame] | 1222 | isn = generate_instr_type2(cctx, isn_type, type, type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1223 | else |
| 1224 | isn = generate_instr_drop(cctx, isn_type, 1); |
| 1225 | if (isn == NULL) |
| 1226 | return FAIL; |
| 1227 | |
| 1228 | // This requires three arguments, which doesn't fit in an instruction, thus |
| 1229 | // we need to allocate a struct for this. |
| 1230 | sref = ALLOC_ONE(scriptref_T); |
| 1231 | if (sref == NULL) |
| 1232 | return FAIL; |
| 1233 | isn->isn_arg.script.scriptref = sref; |
| 1234 | sref->sref_sid = sid; |
| 1235 | sref->sref_idx = idx; |
| 1236 | sref->sref_seq = si->sn_script_seq; |
| 1237 | sref->sref_type = type; |
| 1238 | return OK; |
| 1239 | } |
| 1240 | |
| 1241 | /* |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1242 | * Generate an ISN_NEWLIST instruction for "count" items. |
| 1243 | * "use_null" is TRUE for null_list. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1244 | */ |
| 1245 | int |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1246 | generate_NEWLIST(cctx_T *cctx, int count, int use_null) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1247 | { |
| 1248 | isn_T *isn; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1249 | type_T *member_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1250 | type_T *type; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1251 | type_T *decl_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1252 | |
| 1253 | RETURN_OK_IF_SKIP(cctx); |
| 1254 | if ((isn = generate_instr(cctx, ISN_NEWLIST)) == NULL) |
| 1255 | return FAIL; |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1256 | isn->isn_arg.number = use_null ? -1 : count; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1257 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1258 | // Get the member type and the declared member type from all the items on |
| 1259 | // the stack. |
Bram Moolenaar | 2626d6a | 2022-02-06 15:49:35 +0000 | [diff] [blame] | 1260 | member_type = get_member_type_from_stack(count, 1, cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1261 | type = get_list_type(member_type, cctx->ctx_type_list); |
Bram Moolenaar | 2626d6a | 2022-02-06 15:49:35 +0000 | [diff] [blame] | 1262 | decl_type = get_list_type(&t_any, cctx->ctx_type_list); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1263 | |
| 1264 | // drop the value types |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1265 | cctx->ctx_type_stack.ga_len -= count; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1266 | |
| 1267 | // add the list type to the type stack |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1268 | return push_type_stack2(cctx, type, decl_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /* |
| 1272 | * Generate an ISN_NEWDICT instruction. |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1273 | * "use_null" is TRUE for null_dict. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1274 | */ |
| 1275 | int |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1276 | generate_NEWDICT(cctx_T *cctx, int count, int use_null) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1277 | { |
| 1278 | isn_T *isn; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1279 | type_T *member_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1280 | type_T *type; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1281 | type_T *decl_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1282 | |
| 1283 | RETURN_OK_IF_SKIP(cctx); |
| 1284 | if ((isn = generate_instr(cctx, ISN_NEWDICT)) == NULL) |
| 1285 | return FAIL; |
Bram Moolenaar | ec15b1c | 2022-03-27 16:29:53 +0100 | [diff] [blame] | 1286 | isn->isn_arg.number = use_null ? -1 : count; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1287 | |
Bram Moolenaar | 2626d6a | 2022-02-06 15:49:35 +0000 | [diff] [blame] | 1288 | member_type = get_member_type_from_stack(count, 2, cctx); |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1289 | type = get_dict_type(member_type, cctx->ctx_type_list); |
Bram Moolenaar | 2626d6a | 2022-02-06 15:49:35 +0000 | [diff] [blame] | 1290 | decl_type = get_dict_type(&t_any, cctx->ctx_type_list); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1291 | |
| 1292 | // drop the key and value types |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1293 | cctx->ctx_type_stack.ga_len -= 2 * count; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1294 | |
| 1295 | // add the dict type to the type stack |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1296 | return push_type_stack2(cctx, type, decl_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /* |
| 1300 | * Generate an ISN_FUNCREF instruction. |
Bram Moolenaar | a915fa0 | 2022-03-23 11:29:15 +0000 | [diff] [blame] | 1301 | * "isnp" is set to the instruction, so that fr_dfunc_idx can be set later. |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1302 | * If variables were declared inside a loop "loop_var_idx" is the index of the |
| 1303 | * first one and "loop_var_count" the number of variables declared. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1304 | */ |
| 1305 | int |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1306 | generate_FUNCREF( |
| 1307 | cctx_T *cctx, |
| 1308 | ufunc_T *ufunc, |
| 1309 | isn_T **isnp) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1310 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1311 | isn_T *isn; |
| 1312 | type_T *type; |
| 1313 | funcref_extra_T *extra; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1314 | loopvarinfo_T loopinfo; |
| 1315 | int has_vars; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1316 | |
| 1317 | RETURN_OK_IF_SKIP(cctx); |
| 1318 | if ((isn = generate_instr(cctx, ISN_FUNCREF)) == NULL) |
| 1319 | return FAIL; |
Bram Moolenaar | a915fa0 | 2022-03-23 11:29:15 +0000 | [diff] [blame] | 1320 | if (isnp != NULL) |
| 1321 | *isnp = isn; |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1322 | |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1323 | has_vars = get_loop_var_info(cctx, &loopinfo); |
| 1324 | if (ufunc->uf_def_status == UF_NOT_COMPILED || has_vars) |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1325 | { |
| 1326 | extra = ALLOC_CLEAR_ONE(funcref_extra_T); |
| 1327 | if (extra == NULL) |
| 1328 | return FAIL; |
| 1329 | isn->isn_arg.funcref.fr_extra = extra; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1330 | extra->fre_loopvar_info = loopinfo; |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1331 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1332 | if (ufunc->uf_def_status == UF_NOT_COMPILED) |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1333 | extra->fre_func_name = vim_strsave(ufunc->uf_name); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1334 | else |
| 1335 | isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1336 | |
| 1337 | // Reserve an extra variable to keep track of the number of closures |
| 1338 | // created. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1339 | cctx->ctx_has_closure = 1; |
| 1340 | |
| 1341 | // If the referenced function is a closure, it may use items further up in |
Bram Moolenaar | 139575d | 2022-03-15 19:29:30 +0000 | [diff] [blame] | 1342 | // the nested context, including this one. But not a function defined at |
| 1343 | // the script level. |
| 1344 | if ((ufunc->uf_flags & FC_CLOSURE) |
| 1345 | && func_name_refcount(cctx->ctx_ufunc->uf_name)) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1346 | cctx->ctx_ufunc->uf_flags |= FC_CLOSURE; |
| 1347 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1348 | type = ufunc->uf_func_type == NULL ? &t_func_any : ufunc->uf_func_type; |
| 1349 | return push_type_stack(cctx, type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | /* |
| 1353 | * Generate an ISN_NEWFUNC instruction. |
| 1354 | * "lambda_name" and "func_name" must be in allocated memory and will be |
| 1355 | * consumed. |
| 1356 | */ |
| 1357 | int |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1358 | generate_NEWFUNC( |
| 1359 | cctx_T *cctx, |
| 1360 | char_u *lambda_name, |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1361 | char_u *func_name) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1362 | { |
| 1363 | isn_T *isn; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1364 | int ret = OK; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1365 | |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1366 | if (cctx->ctx_skip != SKIP_YES) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1367 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1368 | if ((isn = generate_instr(cctx, ISN_NEWFUNC)) == NULL) |
| 1369 | ret = FAIL; |
| 1370 | else |
| 1371 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1372 | newfuncarg_T *arg = ALLOC_CLEAR_ONE(newfuncarg_T); |
| 1373 | |
| 1374 | if (arg == NULL) |
| 1375 | ret = FAIL; |
| 1376 | else |
| 1377 | { |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1378 | // Reserve an extra variable to keep track of the number of |
| 1379 | // closures created. |
| 1380 | cctx->ctx_has_closure = 1; |
| 1381 | |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1382 | isn->isn_arg.newfunc.nf_arg = arg; |
| 1383 | arg->nfa_lambda = lambda_name; |
| 1384 | arg->nfa_global = func_name; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1385 | (void)get_loop_var_info(cctx, &arg->nfa_loopvar_info); |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 1386 | return OK; |
| 1387 | } |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1388 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1389 | } |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 1390 | vim_free(lambda_name); |
| 1391 | vim_free(func_name); |
| 1392 | return ret; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Generate an ISN_DEF instruction: list functions |
| 1397 | */ |
| 1398 | int |
| 1399 | generate_DEF(cctx_T *cctx, char_u *name, size_t len) |
| 1400 | { |
| 1401 | isn_T *isn; |
| 1402 | |
| 1403 | RETURN_OK_IF_SKIP(cctx); |
| 1404 | if ((isn = generate_instr(cctx, ISN_DEF)) == NULL) |
| 1405 | return FAIL; |
| 1406 | if (len > 0) |
| 1407 | { |
| 1408 | isn->isn_arg.string = vim_strnsave(name, len); |
| 1409 | if (isn->isn_arg.string == NULL) |
| 1410 | return FAIL; |
| 1411 | } |
| 1412 | return OK; |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * Generate an ISN_JUMP instruction. |
| 1417 | */ |
| 1418 | int |
| 1419 | generate_JUMP(cctx_T *cctx, jumpwhen_T when, int where) |
| 1420 | { |
| 1421 | isn_T *isn; |
| 1422 | garray_T *stack = &cctx->ctx_type_stack; |
| 1423 | |
| 1424 | RETURN_OK_IF_SKIP(cctx); |
| 1425 | if ((isn = generate_instr(cctx, ISN_JUMP)) == NULL) |
| 1426 | return FAIL; |
| 1427 | isn->isn_arg.jump.jump_when = when; |
| 1428 | isn->isn_arg.jump.jump_where = where; |
| 1429 | |
| 1430 | if (when != JUMP_ALWAYS && stack->ga_len > 0) |
| 1431 | --stack->ga_len; |
| 1432 | |
| 1433 | return OK; |
| 1434 | } |
| 1435 | |
| 1436 | /* |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 1437 | * Generate an ISN_WHILE instruction. Similar to ISN_JUMP for :while |
| 1438 | */ |
| 1439 | int |
| 1440 | generate_WHILE(cctx_T *cctx, int funcref_idx) |
| 1441 | { |
| 1442 | isn_T *isn; |
| 1443 | garray_T *stack = &cctx->ctx_type_stack; |
| 1444 | |
| 1445 | RETURN_OK_IF_SKIP(cctx); |
| 1446 | if ((isn = generate_instr(cctx, ISN_WHILE)) == NULL) |
| 1447 | return FAIL; |
| 1448 | isn->isn_arg.whileloop.while_funcref_idx = funcref_idx; |
| 1449 | isn->isn_arg.whileloop.while_end = 0; // filled in later |
| 1450 | |
| 1451 | if (stack->ga_len > 0) |
| 1452 | --stack->ga_len; |
| 1453 | |
| 1454 | return OK; |
| 1455 | } |
| 1456 | |
| 1457 | /* |
Bram Moolenaar | 65b0d16 | 2022-12-13 18:43:22 +0000 | [diff] [blame] | 1458 | * Generate an ISN_JUMP_IF_ARG_SET or ISN_JUMP_IF_ARG_NOT_SET instruction. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1459 | */ |
| 1460 | int |
Bram Moolenaar | 65b0d16 | 2022-12-13 18:43:22 +0000 | [diff] [blame] | 1461 | generate_JUMP_IF_ARG(cctx_T *cctx, isntype_T isn_type, int arg_off) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1462 | { |
| 1463 | isn_T *isn; |
| 1464 | |
| 1465 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 65b0d16 | 2022-12-13 18:43:22 +0000 | [diff] [blame] | 1466 | if ((isn = generate_instr(cctx, isn_type)) == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1467 | return FAIL; |
| 1468 | isn->isn_arg.jumparg.jump_arg_off = arg_off; |
| 1469 | // jump_where is set later |
| 1470 | return OK; |
| 1471 | } |
| 1472 | |
| 1473 | int |
| 1474 | generate_FOR(cctx_T *cctx, int loop_idx) |
| 1475 | { |
| 1476 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1477 | |
| 1478 | RETURN_OK_IF_SKIP(cctx); |
| 1479 | if ((isn = generate_instr(cctx, ISN_FOR)) == NULL) |
| 1480 | return FAIL; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1481 | isn->isn_arg.forloop.for_loop_idx = loop_idx; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1482 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1483 | // type doesn't matter, will be stored next |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1484 | return push_type_stack(cctx, &t_any); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1485 | } |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 1486 | |
| 1487 | int |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1488 | generate_ENDLOOP(cctx_T *cctx, loop_info_T *loop_info) |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 1489 | { |
| 1490 | isn_T *isn; |
| 1491 | |
| 1492 | RETURN_OK_IF_SKIP(cctx); |
| 1493 | if ((isn = generate_instr(cctx, ISN_ENDLOOP)) == NULL) |
| 1494 | return FAIL; |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1495 | isn->isn_arg.endloop.end_depth = loop_info->li_depth; |
| 1496 | isn->isn_arg.endloop.end_funcref_idx = loop_info->li_funcref_idx; |
| 1497 | isn->isn_arg.endloop.end_var_idx = loop_info->li_local_count; |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 1498 | isn->isn_arg.endloop.end_var_count = |
Bram Moolenaar | cc34181 | 2022-09-19 15:54:34 +0100 | [diff] [blame] | 1499 | cctx->ctx_locals.ga_len - loop_info->li_local_count; |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 1500 | return OK; |
| 1501 | } |
| 1502 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1503 | /* |
| 1504 | * Generate an ISN_TRYCONT instruction. |
| 1505 | */ |
| 1506 | int |
| 1507 | generate_TRYCONT(cctx_T *cctx, int levels, int where) |
| 1508 | { |
| 1509 | isn_T *isn; |
| 1510 | |
| 1511 | RETURN_OK_IF_SKIP(cctx); |
| 1512 | if ((isn = generate_instr(cctx, ISN_TRYCONT)) == NULL) |
| 1513 | return FAIL; |
| 1514 | isn->isn_arg.trycont.tct_levels = levels; |
| 1515 | isn->isn_arg.trycont.tct_where = where; |
| 1516 | |
| 1517 | return OK; |
| 1518 | } |
| 1519 | |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1520 | /* |
| 1521 | * Check "argount" arguments and their types on the type stack. |
| 1522 | * Give an error and return FAIL if something is wrong. |
| 1523 | * When "method_call" is NULL no code is generated. |
| 1524 | */ |
| 1525 | int |
| 1526 | check_internal_func_args( |
| 1527 | cctx_T *cctx, |
| 1528 | int func_idx, |
| 1529 | int argcount, |
| 1530 | int method_call, |
| 1531 | type2_T **argtypes, |
| 1532 | type2_T *shuffled_argtypes) |
| 1533 | { |
| 1534 | garray_T *stack = &cctx->ctx_type_stack; |
| 1535 | int argoff = check_internal_func(func_idx, argcount); |
| 1536 | |
| 1537 | if (argoff < 0) |
| 1538 | return FAIL; |
| 1539 | |
| 1540 | if (method_call && argoff > 1) |
| 1541 | { |
| 1542 | isn_T *isn = generate_instr(cctx, ISN_SHUFFLE); |
| 1543 | |
| 1544 | if (isn == NULL) |
| 1545 | return FAIL; |
| 1546 | isn->isn_arg.shuffle.shfl_item = argcount; |
| 1547 | isn->isn_arg.shuffle.shfl_up = argoff - 1; |
| 1548 | } |
| 1549 | |
| 1550 | if (argcount > 0) |
| 1551 | { |
| 1552 | type2_T *typep = ((type2_T *)stack->ga_data) + stack->ga_len - argcount; |
| 1553 | |
| 1554 | // Check the types of the arguments. |
| 1555 | if (method_call && argoff > 1) |
| 1556 | { |
| 1557 | int i; |
| 1558 | |
| 1559 | for (i = 0; i < argcount; ++i) |
| 1560 | shuffled_argtypes[i] = (i < argoff - 1) |
| 1561 | ? typep[i + 1] |
| 1562 | : (i == argoff - 1) ? typep[0] : typep[i]; |
| 1563 | *argtypes = shuffled_argtypes; |
| 1564 | } |
| 1565 | else |
| 1566 | { |
| 1567 | int i; |
| 1568 | |
| 1569 | for (i = 0; i < argcount; ++i) |
| 1570 | shuffled_argtypes[i] = typep[i]; |
| 1571 | *argtypes = shuffled_argtypes; |
| 1572 | } |
| 1573 | if (internal_func_check_arg_types(*argtypes, func_idx, argcount, |
| 1574 | cctx) == FAIL) |
| 1575 | return FAIL; |
| 1576 | } |
| 1577 | return OK; |
| 1578 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1579 | |
| 1580 | /* |
| 1581 | * Generate an ISN_BCALL instruction. |
| 1582 | * "method_call" is TRUE for "value->method()" |
| 1583 | * Return FAIL if the number of arguments is wrong. |
| 1584 | */ |
| 1585 | int |
| 1586 | generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call) |
| 1587 | { |
| 1588 | isn_T *isn; |
| 1589 | garray_T *stack = &cctx->ctx_type_stack; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1590 | type2_T *argtypes = NULL; |
| 1591 | type2_T shuffled_argtypes[MAX_FUNC_ARGS]; |
| 1592 | type2_T *maptype = NULL; |
| 1593 | type_T *type; |
Bram Moolenaar | 8133018 | 2022-02-01 12:11:58 +0000 | [diff] [blame] | 1594 | type_T *decl_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1595 | |
| 1596 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1597 | |
| 1598 | if (check_internal_func_args(cctx, func_idx, argcount, method_call, |
| 1599 | &argtypes, shuffled_argtypes) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1600 | return FAIL; |
| 1601 | |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1602 | if (internal_func_is_map(func_idx)) |
| 1603 | maptype = argtypes; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1604 | |
| 1605 | if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL) |
| 1606 | return FAIL; |
| 1607 | isn->isn_arg.bfunc.cbf_idx = func_idx; |
| 1608 | isn->isn_arg.bfunc.cbf_argcount = argcount; |
| 1609 | |
| 1610 | // Drop the argument types and push the return type. |
| 1611 | stack->ga_len -= argcount; |
Bram Moolenaar | 8133018 | 2022-02-01 12:11:58 +0000 | [diff] [blame] | 1612 | type = internal_func_ret_type(func_idx, argcount, argtypes, &decl_type); |
| 1613 | if (push_type_stack2(cctx, type, decl_type) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1614 | return FAIL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1615 | |
Bram Moolenaar | 35c807d | 2022-01-27 16:36:29 +0000 | [diff] [blame] | 1616 | if (maptype != NULL && maptype[0].type_decl->tt_member != NULL |
| 1617 | && maptype[0].type_decl->tt_member != &t_any) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1618 | // Check that map() didn't change the item types. |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 1619 | generate_TYPECHECK(cctx, maptype[0].type_decl, FALSE, -1, FALSE, 1); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1620 | |
| 1621 | return OK; |
| 1622 | } |
| 1623 | |
| 1624 | /* |
| 1625 | * Generate an ISN_LISTAPPEND instruction. Works like add(). |
| 1626 | * Argument count is already checked. |
| 1627 | */ |
| 1628 | int |
| 1629 | generate_LISTAPPEND(cctx_T *cctx) |
| 1630 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1631 | type_T *list_type; |
| 1632 | type_T *item_type; |
| 1633 | type_T *expected; |
| 1634 | |
| 1635 | // Caller already checked that list_type is a list. |
Bram Moolenaar | 8133018 | 2022-02-01 12:11:58 +0000 | [diff] [blame] | 1636 | // For checking the item type we use the declared type of the list and the |
| 1637 | // current type of the added item, adding a string to [1, 2] is OK. |
| 1638 | list_type = get_decl_type_on_stack(cctx, 1); |
Bram Moolenaar | fa10397 | 2022-09-29 19:14:42 +0100 | [diff] [blame] | 1639 | if (arg_type_modifiable(list_type, 1) == FAIL) |
| 1640 | return FAIL; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1641 | item_type = get_type_on_stack(cctx, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1642 | expected = list_type->tt_member; |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 1643 | if (need_type(item_type, expected, FALSE, -1, 0, cctx, FALSE, FALSE) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1644 | return FAIL; |
| 1645 | |
| 1646 | if (generate_instr(cctx, ISN_LISTAPPEND) == NULL) |
| 1647 | return FAIL; |
| 1648 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1649 | --cctx->ctx_type_stack.ga_len; // drop the argument |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1650 | return OK; |
| 1651 | } |
| 1652 | |
| 1653 | /* |
| 1654 | * Generate an ISN_BLOBAPPEND instruction. Works like add(). |
| 1655 | * Argument count is already checked. |
| 1656 | */ |
| 1657 | int |
| 1658 | generate_BLOBAPPEND(cctx_T *cctx) |
| 1659 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1660 | type_T *item_type; |
| 1661 | |
Bram Moolenaar | fa10397 | 2022-09-29 19:14:42 +0100 | [diff] [blame] | 1662 | // Caller already checked that blob_type is a blob, check it is modifiable. |
| 1663 | if (arg_type_modifiable(get_decl_type_on_stack(cctx, 1), 1) == FAIL) |
| 1664 | return FAIL; |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1665 | item_type = get_type_on_stack(cctx, 0); |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 1666 | if (need_type(item_type, &t_number, FALSE, |
| 1667 | -1, 0, cctx, FALSE, FALSE) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1668 | return FAIL; |
| 1669 | |
| 1670 | if (generate_instr(cctx, ISN_BLOBAPPEND) == NULL) |
| 1671 | return FAIL; |
| 1672 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1673 | --cctx->ctx_type_stack.ga_len; // drop the argument |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1674 | return OK; |
| 1675 | } |
| 1676 | |
| 1677 | /* |
| 1678 | * Generate an ISN_DCALL or ISN_UCALL instruction. |
| 1679 | * Return FAIL if the number of arguments is wrong. |
| 1680 | */ |
| 1681 | int |
| 1682 | generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount) |
| 1683 | { |
| 1684 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1685 | int regular_args = ufunc->uf_args.ga_len; |
| 1686 | int argcount = pushed_argcount; |
| 1687 | |
| 1688 | RETURN_OK_IF_SKIP(cctx); |
| 1689 | if (argcount > regular_args && !has_varargs(ufunc)) |
| 1690 | { |
| 1691 | semsg(_(e_too_many_arguments_for_function_str), |
| 1692 | printable_func_name(ufunc)); |
| 1693 | return FAIL; |
| 1694 | } |
| 1695 | if (argcount < regular_args - ufunc->uf_def_args.ga_len) |
| 1696 | { |
| 1697 | semsg(_(e_not_enough_arguments_for_function_str), |
| 1698 | printable_func_name(ufunc)); |
| 1699 | return FAIL; |
| 1700 | } |
| 1701 | |
| 1702 | if (ufunc->uf_def_status != UF_NOT_COMPILED |
| 1703 | && ufunc->uf_def_status != UF_COMPILE_ERROR) |
| 1704 | { |
| 1705 | int i; |
Bram Moolenaar | 139575d | 2022-03-15 19:29:30 +0000 | [diff] [blame] | 1706 | compiletype_T compile_type; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1707 | |
| 1708 | for (i = 0; i < argcount; ++i) |
| 1709 | { |
| 1710 | type_T *expected; |
| 1711 | type_T *actual; |
| 1712 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1713 | actual = get_type_on_stack(cctx, argcount - i - 1); |
Bram Moolenaar | 53ba6ca | 2022-03-10 19:23:28 +0000 | [diff] [blame] | 1714 | if (actual->tt_type == VAR_SPECIAL |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1715 | && i >= regular_args - ufunc->uf_def_args.ga_len) |
| 1716 | { |
| 1717 | // assume v:none used for default argument value |
| 1718 | continue; |
| 1719 | } |
| 1720 | if (i < regular_args) |
| 1721 | { |
| 1722 | if (ufunc->uf_arg_types == NULL) |
| 1723 | continue; |
| 1724 | expected = ufunc->uf_arg_types[i]; |
| 1725 | } |
| 1726 | else if (ufunc->uf_va_type == NULL |
| 1727 | || ufunc->uf_va_type == &t_list_any) |
| 1728 | // possibly a lambda or "...: any" |
| 1729 | expected = &t_any; |
| 1730 | else |
| 1731 | expected = ufunc->uf_va_type->tt_member; |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 1732 | if (need_type(actual, expected, FALSE, |
| 1733 | -argcount + i, i + 1, cctx, TRUE, FALSE) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1734 | { |
| 1735 | arg_type_mismatch(expected, actual, i + 1); |
| 1736 | return FAIL; |
| 1737 | } |
| 1738 | } |
Bram Moolenaar | 139575d | 2022-03-15 19:29:30 +0000 | [diff] [blame] | 1739 | compile_type = get_compile_type(ufunc); |
| 1740 | if (func_needs_compiling(ufunc, compile_type) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1741 | && compile_def_function(ufunc, ufunc->uf_ret_type == NULL, |
Bram Moolenaar | 139575d | 2022-03-15 19:29:30 +0000 | [diff] [blame] | 1742 | compile_type, NULL) == FAIL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1743 | return FAIL; |
| 1744 | } |
| 1745 | if (ufunc->uf_def_status == UF_COMPILE_ERROR) |
| 1746 | { |
Bram Moolenaar | a6c18d3 | 2022-03-31 20:02:56 +0100 | [diff] [blame] | 1747 | emsg_funcname(e_call_to_function_that_failed_to_compile_str, |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1748 | ufunc->uf_name); |
| 1749 | return FAIL; |
| 1750 | } |
| 1751 | |
| 1752 | if ((isn = generate_instr(cctx, |
| 1753 | ufunc->uf_def_status != UF_NOT_COMPILED ? ISN_DCALL |
| 1754 | : ISN_UCALL)) == NULL) |
| 1755 | return FAIL; |
| 1756 | if (isn->isn_type == ISN_DCALL) |
| 1757 | { |
| 1758 | isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx; |
| 1759 | isn->isn_arg.dfunc.cdf_argcount = argcount; |
| 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | // A user function may be deleted and redefined later, can't use the |
| 1764 | // ufunc pointer, need to look it up again at runtime. |
| 1765 | isn->isn_arg.ufunc.cuf_name = vim_strsave(ufunc->uf_name); |
| 1766 | isn->isn_arg.ufunc.cuf_argcount = argcount; |
| 1767 | } |
| 1768 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1769 | // drop the argument types |
| 1770 | cctx->ctx_type_stack.ga_len -= argcount; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1771 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1772 | // add return type |
| 1773 | return push_type_stack(cctx, ufunc->uf_ret_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /* |
| 1777 | * Generate an ISN_UCALL instruction when the function isn't defined yet. |
| 1778 | */ |
| 1779 | int |
| 1780 | generate_UCALL(cctx_T *cctx, char_u *name, int argcount) |
| 1781 | { |
| 1782 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1783 | |
| 1784 | RETURN_OK_IF_SKIP(cctx); |
| 1785 | if ((isn = generate_instr(cctx, ISN_UCALL)) == NULL) |
| 1786 | return FAIL; |
| 1787 | isn->isn_arg.ufunc.cuf_name = vim_strsave(name); |
| 1788 | isn->isn_arg.ufunc.cuf_argcount = argcount; |
| 1789 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1790 | // drop the argument types |
| 1791 | cctx->ctx_type_stack.ga_len -= argcount; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1792 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1793 | // add return value |
| 1794 | return push_type_stack(cctx, &t_any); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | /* |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1798 | * Check the arguments of function "type" against the types on the stack. |
| 1799 | * Returns OK or FAIL; |
| 1800 | */ |
| 1801 | int |
| 1802 | check_func_args_from_type( |
| 1803 | cctx_T *cctx, |
| 1804 | type_T *type, |
| 1805 | int argcount, |
| 1806 | int at_top, |
| 1807 | char_u *name) |
| 1808 | { |
| 1809 | if (type->tt_argcount != -1) |
| 1810 | { |
| 1811 | int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; |
| 1812 | |
| 1813 | if (argcount < type->tt_min_argcount - varargs) |
| 1814 | { |
| 1815 | emsg_funcname(e_not_enough_arguments_for_function_str, name); |
| 1816 | return FAIL; |
| 1817 | } |
| 1818 | if (!varargs && argcount > type->tt_argcount) |
| 1819 | { |
| 1820 | emsg_funcname(e_too_many_arguments_for_function_str, name); |
| 1821 | return FAIL; |
| 1822 | } |
| 1823 | if (type->tt_args != NULL) |
| 1824 | { |
| 1825 | int i; |
| 1826 | |
| 1827 | for (i = 0; i < argcount; ++i) |
| 1828 | { |
| 1829 | int offset = -argcount + i - (at_top ? 0 : 1); |
| 1830 | type_T *actual = get_type_on_stack(cctx, -1 - offset); |
| 1831 | type_T *expected; |
| 1832 | |
| 1833 | if (varargs && i >= type->tt_argcount - 1) |
| 1834 | expected = type->tt_args[type->tt_argcount - 1]->tt_member; |
| 1835 | else if (i >= type->tt_min_argcount |
| 1836 | && actual->tt_type == VAR_SPECIAL) |
| 1837 | expected = &t_any; |
| 1838 | else |
| 1839 | expected = type->tt_args[i]; |
Bram Moolenaar | c6951a7 | 2022-12-29 20:56:24 +0000 | [diff] [blame^] | 1840 | if (need_type(actual, expected, FALSE, |
| 1841 | offset, i + 1, cctx, TRUE, FALSE) == FAIL) |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1842 | { |
| 1843 | arg_type_mismatch(expected, actual, i + 1); |
| 1844 | return FAIL; |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | return OK; |
| 1851 | } |
| 1852 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1853 | * Generate an ISN_PCALL instruction. |
| 1854 | * "type" is the type of the FuncRef. |
| 1855 | */ |
| 1856 | int |
| 1857 | generate_PCALL( |
| 1858 | cctx_T *cctx, |
| 1859 | int argcount, |
| 1860 | char_u *name, |
| 1861 | type_T *type, |
| 1862 | int at_top) |
| 1863 | { |
| 1864 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1865 | type_T *ret_type; |
| 1866 | |
| 1867 | RETURN_OK_IF_SKIP(cctx); |
| 1868 | |
Bram Moolenaar | 59618fe | 2021-12-21 12:32:17 +0000 | [diff] [blame] | 1869 | if (type->tt_type == VAR_ANY || type->tt_type == VAR_UNKNOWN) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1870 | ret_type = &t_any; |
| 1871 | else if (type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL) |
| 1872 | { |
Bram Moolenaar | 1690032 | 2022-09-08 19:51:45 +0100 | [diff] [blame] | 1873 | if (check_func_args_from_type(cctx, type, argcount, at_top, name) == FAIL) |
| 1874 | return FAIL; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1875 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1876 | ret_type = type->tt_member; |
| 1877 | if (ret_type == &t_unknown) |
| 1878 | // return type not known yet, use a runtime check |
| 1879 | ret_type = &t_any; |
| 1880 | } |
| 1881 | else |
| 1882 | { |
| 1883 | semsg(_(e_not_callable_type_str), name); |
| 1884 | return FAIL; |
| 1885 | } |
| 1886 | |
| 1887 | if ((isn = generate_instr(cctx, ISN_PCALL)) == NULL) |
| 1888 | return FAIL; |
| 1889 | isn->isn_arg.pfunc.cpf_top = at_top; |
| 1890 | isn->isn_arg.pfunc.cpf_argcount = argcount; |
| 1891 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1892 | // drop the arguments and the funcref/partial |
| 1893 | cctx->ctx_type_stack.ga_len -= argcount + 1; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1894 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1895 | // push the return value |
| 1896 | push_type_stack(cctx, ret_type); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1897 | |
| 1898 | // If partial is above the arguments it must be cleared and replaced with |
| 1899 | // the return value. |
| 1900 | if (at_top && generate_instr(cctx, ISN_PCALL_END) == NULL) |
| 1901 | return FAIL; |
| 1902 | |
| 1903 | return OK; |
| 1904 | } |
| 1905 | |
| 1906 | /* |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 1907 | * Generate an ISN_DEFER instruction. |
| 1908 | */ |
| 1909 | int |
| 1910 | generate_DEFER(cctx_T *cctx, int var_idx, int argcount) |
| 1911 | { |
| 1912 | isn_T *isn; |
| 1913 | |
| 1914 | RETURN_OK_IF_SKIP(cctx); |
| 1915 | if ((isn = generate_instr_drop(cctx, ISN_DEFER, argcount + 1)) == NULL) |
| 1916 | return FAIL; |
| 1917 | isn->isn_arg.defer.defer_var_idx = var_idx; |
| 1918 | isn->isn_arg.defer.defer_argcount = argcount; |
| 1919 | return OK; |
| 1920 | } |
| 1921 | |
| 1922 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1923 | * Generate an ISN_STRINGMEMBER instruction. |
| 1924 | */ |
| 1925 | int |
| 1926 | generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len) |
| 1927 | { |
| 1928 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1929 | type_T *type; |
| 1930 | |
| 1931 | RETURN_OK_IF_SKIP(cctx); |
| 1932 | if ((isn = generate_instr(cctx, ISN_STRINGMEMBER)) == NULL) |
| 1933 | return FAIL; |
| 1934 | isn->isn_arg.string = vim_strnsave(name, len); |
| 1935 | |
| 1936 | // check for dict type |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1937 | type = get_type_on_stack(cctx, 0); |
Bram Moolenaar | 0089ce2 | 2022-10-08 14:39:36 +0100 | [diff] [blame] | 1938 | if (type->tt_type != VAR_DICT |
| 1939 | && type->tt_type != VAR_ANY && type->tt_type != VAR_UNKNOWN) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1940 | { |
| 1941 | char *tofree; |
| 1942 | |
| 1943 | semsg(_(e_expected_dictionary_for_using_key_str_but_got_str), |
| 1944 | name, type_name(type, &tofree)); |
| 1945 | vim_free(tofree); |
| 1946 | return FAIL; |
| 1947 | } |
| 1948 | // change dict type to dict member type |
| 1949 | if (type->tt_type == VAR_DICT) |
| 1950 | { |
Bram Moolenaar | 0089ce2 | 2022-10-08 14:39:36 +0100 | [diff] [blame] | 1951 | type_T *ntype = type->tt_member->tt_type == VAR_UNKNOWN |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 1952 | ? &t_any : type->tt_member; |
| 1953 | set_type_on_stack(cctx, ntype, 0); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | return OK; |
| 1957 | } |
| 1958 | |
| 1959 | /* |
| 1960 | * Generate an ISN_ECHO instruction. |
| 1961 | */ |
| 1962 | int |
| 1963 | generate_ECHO(cctx_T *cctx, int with_white, int count) |
| 1964 | { |
| 1965 | isn_T *isn; |
| 1966 | |
| 1967 | RETURN_OK_IF_SKIP(cctx); |
| 1968 | if ((isn = generate_instr_drop(cctx, ISN_ECHO, count)) == NULL) |
| 1969 | return FAIL; |
| 1970 | isn->isn_arg.echo.echo_with_white = with_white; |
| 1971 | isn->isn_arg.echo.echo_count = count; |
| 1972 | |
| 1973 | return OK; |
| 1974 | } |
| 1975 | |
| 1976 | /* |
| 1977 | * Generate an ISN_EXECUTE/ISN_ECHOMSG/ISN_ECHOERR instruction. |
| 1978 | */ |
| 1979 | int |
| 1980 | generate_MULT_EXPR(cctx_T *cctx, isntype_T isn_type, int count) |
| 1981 | { |
| 1982 | isn_T *isn; |
| 1983 | |
Bram Moolenaar | 2eae3d2 | 2022-10-07 15:09:27 +0100 | [diff] [blame] | 1984 | RETURN_OK_IF_SKIP(cctx); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1985 | if ((isn = generate_instr_drop(cctx, isn_type, count)) == NULL) |
| 1986 | return FAIL; |
| 1987 | isn->isn_arg.number = count; |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 1988 | return OK; |
| 1989 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 1990 | |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 1991 | /* |
| 1992 | * Generate an ISN_ECHOWINDOW instruction |
| 1993 | */ |
| 1994 | int |
| 1995 | generate_ECHOWINDOW(cctx_T *cctx, int count, long time) |
| 1996 | { |
| 1997 | isn_T *isn; |
| 1998 | |
| 1999 | if ((isn = generate_instr_drop(cctx, ISN_ECHOWINDOW, count)) == NULL) |
| 2000 | return FAIL; |
| 2001 | isn->isn_arg.echowin.ewin_count = count; |
| 2002 | isn->isn_arg.echowin.ewin_time = time; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2003 | return OK; |
| 2004 | } |
| 2005 | |
| 2006 | /* |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2007 | * Generate an ISN_SOURCE instruction. |
| 2008 | */ |
| 2009 | int |
| 2010 | generate_SOURCE(cctx_T *cctx, int sid) |
| 2011 | { |
| 2012 | isn_T *isn; |
| 2013 | |
| 2014 | if ((isn = generate_instr(cctx, ISN_SOURCE)) == NULL) |
| 2015 | return FAIL; |
| 2016 | isn->isn_arg.number = sid; |
| 2017 | |
| 2018 | return OK; |
| 2019 | } |
| 2020 | |
| 2021 | /* |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2022 | * Generate an ISN_PUT instruction. |
| 2023 | */ |
| 2024 | int |
| 2025 | generate_PUT(cctx_T *cctx, int regname, linenr_T lnum) |
| 2026 | { |
| 2027 | isn_T *isn; |
| 2028 | |
| 2029 | RETURN_OK_IF_SKIP(cctx); |
| 2030 | if ((isn = generate_instr(cctx, ISN_PUT)) == NULL) |
| 2031 | return FAIL; |
| 2032 | isn->isn_arg.put.put_regname = regname; |
| 2033 | isn->isn_arg.put.put_lnum = lnum; |
| 2034 | return OK; |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * Generate an EXEC instruction that takes a string argument. |
| 2039 | * A copy is made of "line". |
| 2040 | */ |
| 2041 | int |
| 2042 | generate_EXEC_copy(cctx_T *cctx, isntype_T isntype, char_u *line) |
| 2043 | { |
| 2044 | isn_T *isn; |
| 2045 | |
| 2046 | RETURN_OK_IF_SKIP(cctx); |
| 2047 | if ((isn = generate_instr(cctx, isntype)) == NULL) |
| 2048 | return FAIL; |
| 2049 | isn->isn_arg.string = vim_strsave(line); |
| 2050 | return OK; |
| 2051 | } |
| 2052 | |
| 2053 | /* |
| 2054 | * Generate an EXEC instruction that takes a string argument. |
| 2055 | * "str" must be allocated, it is consumed. |
| 2056 | */ |
| 2057 | int |
| 2058 | generate_EXEC(cctx_T *cctx, isntype_T isntype, char_u *str) |
| 2059 | { |
| 2060 | isn_T *isn; |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 2061 | int ret = OK; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2062 | |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 2063 | if (cctx->ctx_skip != SKIP_YES) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2064 | { |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 2065 | if ((isn = generate_instr(cctx, isntype)) == NULL) |
| 2066 | ret = FAIL; |
| 2067 | else |
| 2068 | { |
| 2069 | isn->isn_arg.string = str; |
| 2070 | return OK; |
| 2071 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2072 | } |
Bram Moolenaar | c3caa7f | 2022-05-25 19:15:10 +0100 | [diff] [blame] | 2073 | vim_free(str); |
| 2074 | return ret; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | int |
| 2078 | generate_LEGACY_EVAL(cctx_T *cctx, char_u *line) |
| 2079 | { |
| 2080 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2081 | |
| 2082 | RETURN_OK_IF_SKIP(cctx); |
| 2083 | if ((isn = generate_instr(cctx, ISN_LEGACY_EVAL)) == NULL) |
| 2084 | return FAIL; |
| 2085 | isn->isn_arg.string = vim_strsave(line); |
| 2086 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 2087 | return push_type_stack(cctx, &t_any); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | int |
| 2091 | generate_EXECCONCAT(cctx_T *cctx, int count) |
| 2092 | { |
| 2093 | isn_T *isn; |
| 2094 | |
| 2095 | if ((isn = generate_instr_drop(cctx, ISN_EXECCONCAT, count)) == NULL) |
| 2096 | return FAIL; |
| 2097 | isn->isn_arg.number = count; |
| 2098 | return OK; |
| 2099 | } |
| 2100 | |
| 2101 | /* |
| 2102 | * Generate ISN_RANGE. Consumes "range". Return OK/FAIL. |
| 2103 | */ |
| 2104 | int |
| 2105 | generate_RANGE(cctx_T *cctx, char_u *range) |
| 2106 | { |
| 2107 | isn_T *isn; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2108 | |
| 2109 | if ((isn = generate_instr(cctx, ISN_RANGE)) == NULL) |
| 2110 | return FAIL; |
| 2111 | isn->isn_arg.string = range; |
| 2112 | |
Bram Moolenaar | 078a461 | 2022-01-04 15:17:03 +0000 | [diff] [blame] | 2113 | return push_type_stack(cctx, &t_number); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | int |
| 2117 | generate_UNPACK(cctx_T *cctx, int var_count, int semicolon) |
| 2118 | { |
| 2119 | isn_T *isn; |
| 2120 | |
| 2121 | RETURN_OK_IF_SKIP(cctx); |
| 2122 | if ((isn = generate_instr(cctx, ISN_UNPACK)) == NULL) |
| 2123 | return FAIL; |
| 2124 | isn->isn_arg.unpack.unp_count = var_count; |
| 2125 | isn->isn_arg.unpack.unp_semicolon = semicolon; |
| 2126 | return OK; |
| 2127 | } |
| 2128 | |
| 2129 | /* |
| 2130 | * Generate an instruction for any command modifiers. |
| 2131 | */ |
| 2132 | int |
| 2133 | generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod) |
| 2134 | { |
| 2135 | isn_T *isn; |
| 2136 | |
| 2137 | if (has_cmdmod(cmod, FALSE)) |
| 2138 | { |
| 2139 | cctx->ctx_has_cmdmod = TRUE; |
| 2140 | |
| 2141 | if ((isn = generate_instr(cctx, ISN_CMDMOD)) == NULL) |
| 2142 | return FAIL; |
| 2143 | isn->isn_arg.cmdmod.cf_cmdmod = ALLOC_ONE(cmdmod_T); |
| 2144 | if (isn->isn_arg.cmdmod.cf_cmdmod == NULL) |
| 2145 | return FAIL; |
| 2146 | mch_memmove(isn->isn_arg.cmdmod.cf_cmdmod, cmod, sizeof(cmdmod_T)); |
| 2147 | // filter program now belongs to the instruction |
| 2148 | cmod->cmod_filter_regmatch.regprog = NULL; |
| 2149 | } |
| 2150 | |
| 2151 | return OK; |
| 2152 | } |
| 2153 | |
| 2154 | int |
| 2155 | generate_undo_cmdmods(cctx_T *cctx) |
| 2156 | { |
| 2157 | if (cctx->ctx_has_cmdmod && generate_instr(cctx, ISN_CMDMOD_REV) == NULL) |
| 2158 | return FAIL; |
| 2159 | cctx->ctx_has_cmdmod = FALSE; |
| 2160 | return OK; |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | * Generate a STORE instruction for "dest", not being "dest_local". |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 2165 | * "lhs" might be NULL. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2166 | * Return FAIL when out of memory. |
| 2167 | */ |
| 2168 | int |
| 2169 | generate_store_var( |
| 2170 | cctx_T *cctx, |
| 2171 | assign_dest_T dest, |
| 2172 | int opt_flags, |
| 2173 | int vimvaridx, |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2174 | type_T *type, |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 2175 | char_u *name, |
| 2176 | lhs_T *lhs) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2177 | { |
| 2178 | switch (dest) |
| 2179 | { |
| 2180 | case dest_option: |
| 2181 | return generate_STOREOPT(cctx, ISN_STOREOPT, |
| 2182 | skip_option_env_lead(name), opt_flags); |
| 2183 | case dest_func_option: |
| 2184 | return generate_STOREOPT(cctx, ISN_STOREFUNCOPT, |
| 2185 | skip_option_env_lead(name), opt_flags); |
| 2186 | case dest_global: |
| 2187 | // include g: with the name, easier to execute that way |
| 2188 | return generate_STORE(cctx, vim_strchr(name, AUTOLOAD_CHAR) == NULL |
| 2189 | ? ISN_STOREG : ISN_STOREAUTO, 0, name); |
| 2190 | case dest_buffer: |
| 2191 | // include b: with the name, easier to execute that way |
| 2192 | return generate_STORE(cctx, ISN_STOREB, 0, name); |
| 2193 | case dest_window: |
| 2194 | // include w: with the name, easier to execute that way |
| 2195 | return generate_STORE(cctx, ISN_STOREW, 0, name); |
| 2196 | case dest_tab: |
| 2197 | // include t: with the name, easier to execute that way |
| 2198 | return generate_STORE(cctx, ISN_STORET, 0, name); |
| 2199 | case dest_env: |
| 2200 | return generate_STORE(cctx, ISN_STOREENV, 0, name + 1); |
| 2201 | case dest_reg: |
| 2202 | return generate_STORE(cctx, ISN_STOREREG, |
| 2203 | name[1] == '@' ? '"' : name[1], NULL); |
| 2204 | case dest_vimvar: |
| 2205 | return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL); |
| 2206 | case dest_script: |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2207 | { |
Bram Moolenaar | c336ae3 | 2022-12-18 22:01:42 +0000 | [diff] [blame] | 2208 | int scriptvar_idx = lhs->lhs_scriptvar_idx; |
| 2209 | int scriptvar_sid = lhs->lhs_scriptvar_sid; |
| 2210 | if (scriptvar_idx < 0) |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2211 | { |
Bram Moolenaar | c336ae3 | 2022-12-18 22:01:42 +0000 | [diff] [blame] | 2212 | isntype_T isn_type = ISN_STORES; |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2213 | |
Bram Moolenaar | c336ae3 | 2022-12-18 22:01:42 +0000 | [diff] [blame] | 2214 | if (SCRIPT_ID_VALID(scriptvar_sid) |
| 2215 | && SCRIPT_ITEM(scriptvar_sid)->sn_import_autoload |
| 2216 | && SCRIPT_ITEM(scriptvar_sid)->sn_autoload_prefix |
| 2217 | == NULL) |
| 2218 | { |
| 2219 | // "import autoload './dir/script.vim'" - load script |
| 2220 | // first |
| 2221 | if (generate_SOURCE(cctx, scriptvar_sid) == FAIL) |
| 2222 | return FAIL; |
| 2223 | isn_type = ISN_STOREEXPORT; |
| 2224 | } |
| 2225 | |
| 2226 | // "s:" may be included in the name. |
| 2227 | return generate_OLDSCRIPT(cctx, isn_type, name, |
| 2228 | scriptvar_sid, type); |
| 2229 | } |
| 2230 | return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT, |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2231 | scriptvar_sid, scriptvar_idx, type); |
Bram Moolenaar | c336ae3 | 2022-12-18 22:01:42 +0000 | [diff] [blame] | 2232 | } |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 2233 | case dest_class_member: |
| 2234 | return generate_CLASSMEMBER(cctx, FALSE, |
| 2235 | lhs->lhs_class, lhs->lhs_classmember_idx); |
| 2236 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2237 | case dest_local: |
| 2238 | case dest_expr: |
| 2239 | // cannot happen |
| 2240 | break; |
| 2241 | } |
| 2242 | return FAIL; |
| 2243 | } |
| 2244 | |
Bram Moolenaar | 38ecd97 | 2022-01-15 21:44:44 +0000 | [diff] [blame] | 2245 | /* |
| 2246 | * Return TRUE when inside a "for" or "while" loop. |
| 2247 | */ |
| 2248 | int |
| 2249 | inside_loop_scope(cctx_T *cctx) |
| 2250 | { |
| 2251 | scope_T *scope = cctx->ctx_scope; |
| 2252 | |
| 2253 | for (;;) |
| 2254 | { |
| 2255 | if (scope == NULL) |
| 2256 | break; |
| 2257 | if (scope->se_type == FOR_SCOPE || scope->se_type == WHILE_SCOPE) |
| 2258 | return TRUE; |
| 2259 | scope = scope->se_outer; |
| 2260 | } |
| 2261 | return FALSE; |
| 2262 | } |
| 2263 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2264 | int |
Bram Moolenaar | 5cd6479 | 2021-12-25 18:23:24 +0000 | [diff] [blame] | 2265 | generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count, int is_decl) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2266 | { |
| 2267 | if (lhs->lhs_dest != dest_local) |
| 2268 | return generate_store_var(cctx, lhs->lhs_dest, |
| 2269 | lhs->lhs_opt_flags, lhs->lhs_vimvaridx, |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 2270 | lhs->lhs_type, lhs->lhs_name, lhs); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2271 | |
| 2272 | if (lhs->lhs_lvar != NULL) |
| 2273 | { |
| 2274 | garray_T *instr = &cctx->ctx_instr; |
| 2275 | isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; |
| 2276 | |
Bram Moolenaar | 5cd6479 | 2021-12-25 18:23:24 +0000 | [diff] [blame] | 2277 | // Optimization: turn "var = 123" from ISN_PUSHNR + ISN_STORE into |
| 2278 | // ISN_STORENR. |
| 2279 | // And "var = 0" does not need any instruction. |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2280 | if (lhs->lhs_lvar->lv_from_outer == 0 |
| 2281 | && instr->ga_len == instr_count + 1 |
| 2282 | && isn->isn_type == ISN_PUSHNR) |
| 2283 | { |
| 2284 | varnumber_T val = isn->isn_arg.number; |
| 2285 | garray_T *stack = &cctx->ctx_type_stack; |
| 2286 | |
Bram Moolenaar | 38ecd97 | 2022-01-15 21:44:44 +0000 | [diff] [blame] | 2287 | if (val == 0 && is_decl && !inside_loop_scope(cctx)) |
Bram Moolenaar | 5cd6479 | 2021-12-25 18:23:24 +0000 | [diff] [blame] | 2288 | { |
Bram Moolenaar | 38ecd97 | 2022-01-15 21:44:44 +0000 | [diff] [blame] | 2289 | // zero is the default value, no need to do anything |
Bram Moolenaar | 5cd6479 | 2021-12-25 18:23:24 +0000 | [diff] [blame] | 2290 | --instr->ga_len; |
| 2291 | } |
| 2292 | else |
| 2293 | { |
| 2294 | isn->isn_type = ISN_STORENR; |
| 2295 | isn->isn_arg.storenr.stnr_idx = lhs->lhs_lvar->lv_idx; |
| 2296 | isn->isn_arg.storenr.stnr_val = val; |
| 2297 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2298 | if (stack->ga_len > 0) |
| 2299 | --stack->ga_len; |
| 2300 | } |
| 2301 | else if (lhs->lhs_lvar->lv_from_outer > 0) |
| 2302 | generate_STOREOUTER(cctx, lhs->lhs_lvar->lv_idx, |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2303 | lhs->lhs_lvar->lv_from_outer, lhs->lhs_lvar->lv_loop_idx); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2304 | else |
| 2305 | generate_STORE(cctx, ISN_STORE, lhs->lhs_lvar->lv_idx, NULL); |
| 2306 | } |
| 2307 | return OK; |
| 2308 | } |
| 2309 | |
| 2310 | #if defined(FEAT_PROFILE) || defined(PROTO) |
| 2311 | void |
| 2312 | may_generate_prof_end(cctx_T *cctx, int prof_lnum) |
| 2313 | { |
| 2314 | if (cctx->ctx_compile_type == CT_PROFILE && prof_lnum >= 0) |
| 2315 | generate_instr(cctx, ISN_PROF_END); |
| 2316 | } |
| 2317 | #endif |
| 2318 | |
| 2319 | |
| 2320 | /* |
| 2321 | * Delete an instruction, free what it contains. |
| 2322 | */ |
| 2323 | void |
| 2324 | delete_instr(isn_T *isn) |
| 2325 | { |
| 2326 | switch (isn->isn_type) |
| 2327 | { |
Bram Moolenaar | 06b7722 | 2022-01-25 15:51:56 +0000 | [diff] [blame] | 2328 | case ISN_AUTOLOAD: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2329 | case ISN_DEF: |
| 2330 | case ISN_EXEC: |
| 2331 | case ISN_EXECRANGE: |
| 2332 | case ISN_EXEC_SPLIT: |
| 2333 | case ISN_LEGACY_EVAL: |
| 2334 | case ISN_LOADAUTO: |
| 2335 | case ISN_LOADB: |
| 2336 | case ISN_LOADENV: |
| 2337 | case ISN_LOADG: |
| 2338 | case ISN_LOADOPT: |
| 2339 | case ISN_LOADT: |
| 2340 | case ISN_LOADW: |
| 2341 | case ISN_LOCKUNLOCK: |
| 2342 | case ISN_PUSHEXC: |
| 2343 | case ISN_PUSHFUNC: |
| 2344 | case ISN_PUSHS: |
| 2345 | case ISN_RANGE: |
| 2346 | case ISN_STOREAUTO: |
| 2347 | case ISN_STOREB: |
| 2348 | case ISN_STOREENV: |
| 2349 | case ISN_STOREG: |
| 2350 | case ISN_STORET: |
| 2351 | case ISN_STOREW: |
| 2352 | case ISN_STRINGMEMBER: |
| 2353 | vim_free(isn->isn_arg.string); |
| 2354 | break; |
| 2355 | |
| 2356 | case ISN_SUBSTITUTE: |
| 2357 | { |
| 2358 | int idx; |
| 2359 | isn_T *list = isn->isn_arg.subs.subs_instr; |
| 2360 | |
| 2361 | vim_free(isn->isn_arg.subs.subs_cmd); |
| 2362 | for (idx = 0; list[idx].isn_type != ISN_FINISH; ++idx) |
| 2363 | delete_instr(list + idx); |
| 2364 | vim_free(list); |
| 2365 | } |
| 2366 | break; |
| 2367 | |
| 2368 | case ISN_INSTR: |
| 2369 | { |
| 2370 | int idx; |
| 2371 | isn_T *list = isn->isn_arg.instr; |
| 2372 | |
| 2373 | for (idx = 0; list[idx].isn_type != ISN_FINISH; ++idx) |
| 2374 | delete_instr(list + idx); |
| 2375 | vim_free(list); |
| 2376 | } |
| 2377 | break; |
| 2378 | |
| 2379 | case ISN_LOADS: |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2380 | case ISN_LOADEXPORT: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2381 | case ISN_STORES: |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2382 | case ISN_STOREEXPORT: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2383 | vim_free(isn->isn_arg.loadstore.ls_name); |
| 2384 | break; |
| 2385 | |
| 2386 | case ISN_UNLET: |
| 2387 | case ISN_UNLETENV: |
| 2388 | vim_free(isn->isn_arg.unlet.ul_name); |
| 2389 | break; |
| 2390 | |
| 2391 | case ISN_STOREOPT: |
| 2392 | case ISN_STOREFUNCOPT: |
| 2393 | vim_free(isn->isn_arg.storeopt.so_name); |
| 2394 | break; |
| 2395 | |
| 2396 | case ISN_PUSHBLOB: // push blob isn_arg.blob |
| 2397 | blob_unref(isn->isn_arg.blob); |
| 2398 | break; |
| 2399 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2400 | case ISN_UCALL: |
| 2401 | vim_free(isn->isn_arg.ufunc.cuf_name); |
| 2402 | break; |
| 2403 | |
| 2404 | case ISN_FUNCREF: |
| 2405 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2406 | funcref_T *funcref = &isn->isn_arg.funcref; |
| 2407 | funcref_extra_T *extra = funcref->fr_extra; |
| 2408 | |
| 2409 | if (extra == NULL || extra->fre_func_name == NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2410 | { |
| 2411 | dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2412 | + funcref->fr_dfunc_idx; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2413 | ufunc_T *ufunc = dfunc->df_ufunc; |
| 2414 | |
| 2415 | if (ufunc != NULL && func_name_refcount(ufunc->uf_name)) |
| 2416 | func_ptr_unref(ufunc); |
| 2417 | } |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2418 | if (extra != NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2419 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2420 | char_u *name = extra->fre_func_name; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2421 | |
| 2422 | if (name != NULL) |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2423 | { |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2424 | func_unref(name); |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2425 | vim_free(name); |
| 2426 | } |
| 2427 | vim_free(extra); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | break; |
| 2431 | |
| 2432 | case ISN_DCALL: |
| 2433 | { |
| 2434 | dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2435 | + isn->isn_arg.dfunc.cdf_idx; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2436 | |
| 2437 | if (dfunc->df_ufunc != NULL |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2438 | && func_name_refcount(dfunc->df_ufunc->uf_name)) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2439 | func_ptr_unref(dfunc->df_ufunc); |
| 2440 | } |
| 2441 | break; |
| 2442 | |
| 2443 | case ISN_NEWFUNC: |
| 2444 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2445 | newfuncarg_T *arg = isn->isn_arg.newfunc.nf_arg; |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2446 | |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2447 | if (arg != NULL) |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2448 | { |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2449 | ufunc_T *ufunc = find_func_even_dead( |
| 2450 | arg->nfa_lambda, FFED_IS_GLOBAL); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2451 | |
Bram Moolenaar | 8fa745e | 2022-09-16 19:04:24 +0100 | [diff] [blame] | 2452 | if (ufunc != NULL) |
| 2453 | { |
| 2454 | unlink_def_function(ufunc); |
| 2455 | func_ptr_unref(ufunc); |
| 2456 | } |
| 2457 | |
| 2458 | vim_free(arg->nfa_lambda); |
| 2459 | vim_free(arg->nfa_global); |
| 2460 | vim_free(arg); |
| 2461 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | |
| 2465 | case ISN_CHECKTYPE: |
| 2466 | case ISN_SETTYPE: |
| 2467 | free_type(isn->isn_arg.type.ct_type); |
| 2468 | break; |
| 2469 | |
| 2470 | case ISN_CMDMOD: |
| 2471 | vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2472 | ->cmod_filter_regmatch.regprog); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2473 | vim_free(isn->isn_arg.cmdmod.cf_cmdmod); |
| 2474 | break; |
| 2475 | |
| 2476 | case ISN_LOADSCRIPT: |
| 2477 | case ISN_STORESCRIPT: |
| 2478 | vim_free(isn->isn_arg.script.scriptref); |
| 2479 | break; |
| 2480 | |
Bram Moolenaar | d505d17 | 2022-12-18 21:42:55 +0000 | [diff] [blame] | 2481 | case ISN_LOAD_CLASSMEMBER: |
| 2482 | case ISN_STORE_CLASSMEMBER: |
| 2483 | class_unref(isn->isn_arg.classmember.cm_class); |
| 2484 | break; |
| 2485 | |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2486 | case ISN_TRY: |
Bram Moolenaar | 0d80710 | 2021-12-21 09:42:09 +0000 | [diff] [blame] | 2487 | vim_free(isn->isn_arg.tryref.try_ref); |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2488 | break; |
| 2489 | |
| 2490 | case ISN_CEXPR_CORE: |
| 2491 | vim_free(isn->isn_arg.cexpr.cexpr_ref->cer_cmdline); |
| 2492 | vim_free(isn->isn_arg.cexpr.cexpr_ref); |
| 2493 | break; |
| 2494 | |
| 2495 | case ISN_2BOOL: |
| 2496 | case ISN_2STRING: |
| 2497 | case ISN_2STRING_ANY: |
| 2498 | case ISN_ADDBLOB: |
| 2499 | case ISN_ADDLIST: |
| 2500 | case ISN_ANYINDEX: |
| 2501 | case ISN_ANYSLICE: |
| 2502 | case ISN_BCALL: |
| 2503 | case ISN_BLOBAPPEND: |
| 2504 | case ISN_BLOBINDEX: |
| 2505 | case ISN_BLOBSLICE: |
| 2506 | case ISN_CATCH: |
| 2507 | case ISN_CEXPR_AUCMD: |
| 2508 | case ISN_CHECKLEN: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2509 | case ISN_CLEARDICT: |
| 2510 | case ISN_CMDMOD_REV: |
| 2511 | case ISN_COMPAREANY: |
| 2512 | case ISN_COMPAREBLOB: |
| 2513 | case ISN_COMPAREBOOL: |
| 2514 | case ISN_COMPAREDICT: |
| 2515 | case ISN_COMPAREFLOAT: |
| 2516 | case ISN_COMPAREFUNC: |
| 2517 | case ISN_COMPARELIST: |
| 2518 | case ISN_COMPARENR: |
Bram Moolenaar | 7a22224 | 2022-03-01 19:23:24 +0000 | [diff] [blame] | 2519 | case ISN_COMPARENULL: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2520 | case ISN_COMPARESPECIAL: |
| 2521 | case ISN_COMPARESTRING: |
| 2522 | case ISN_CONCAT: |
Bram Moolenaar | 00b28d6 | 2022-12-08 15:32:33 +0000 | [diff] [blame] | 2523 | case ISN_CONSTRUCT: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2524 | case ISN_COND2BOOL: |
| 2525 | case ISN_DEBUG: |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 2526 | case ISN_DEFER: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2527 | case ISN_DROP: |
| 2528 | case ISN_ECHO: |
| 2529 | case ISN_ECHOCONSOLE: |
| 2530 | case ISN_ECHOERR: |
| 2531 | case ISN_ECHOMSG: |
Bram Moolenaar | 68a635a | 2022-09-01 17:26:17 +0100 | [diff] [blame] | 2532 | case ISN_ECHOWINDOW: |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 2533 | case ISN_ENDLOOP: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2534 | case ISN_ENDTRY: |
| 2535 | case ISN_EXECCONCAT: |
| 2536 | case ISN_EXECUTE: |
| 2537 | case ISN_FINALLY: |
| 2538 | case ISN_FINISH: |
| 2539 | case ISN_FOR: |
| 2540 | case ISN_GETITEM: |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 2541 | case ISN_GET_OBJ_MEMBER: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2542 | case ISN_JUMP: |
Bram Moolenaar | 65b0d16 | 2022-12-13 18:43:22 +0000 | [diff] [blame] | 2543 | case ISN_JUMP_IF_ARG_NOT_SET: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2544 | case ISN_JUMP_IF_ARG_SET: |
| 2545 | case ISN_LISTAPPEND: |
| 2546 | case ISN_LISTINDEX: |
| 2547 | case ISN_LISTSLICE: |
| 2548 | case ISN_LOAD: |
| 2549 | case ISN_LOADBDICT: |
| 2550 | case ISN_LOADGDICT: |
| 2551 | case ISN_LOADOUTER: |
| 2552 | case ISN_LOADREG: |
| 2553 | case ISN_LOADTDICT: |
| 2554 | case ISN_LOADV: |
| 2555 | case ISN_LOADWDICT: |
| 2556 | case ISN_LOCKCONST: |
| 2557 | case ISN_MEMBER: |
| 2558 | case ISN_NEGATENR: |
| 2559 | case ISN_NEWDICT: |
| 2560 | case ISN_NEWLIST: |
Bram Moolenaar | 8acb9cc | 2022-03-08 13:18:55 +0000 | [diff] [blame] | 2561 | case ISN_NEWPARTIAL: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2562 | case ISN_OPANY: |
| 2563 | case ISN_OPFLOAT: |
| 2564 | case ISN_OPNR: |
| 2565 | case ISN_PCALL: |
| 2566 | case ISN_PCALL_END: |
| 2567 | case ISN_PROF_END: |
| 2568 | case ISN_PROF_START: |
| 2569 | case ISN_PUSHBOOL: |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 2570 | case ISN_PUSHCHANNEL: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2571 | case ISN_PUSHF: |
Bram Moolenaar | 397a87a | 2022-03-20 21:14:15 +0000 | [diff] [blame] | 2572 | case ISN_PUSHJOB: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2573 | case ISN_PUSHNR: |
| 2574 | case ISN_PUSHSPEC: |
| 2575 | case ISN_PUT: |
| 2576 | case ISN_REDIREND: |
| 2577 | case ISN_REDIRSTART: |
| 2578 | case ISN_RETURN: |
Bram Moolenaar | 00b28d6 | 2022-12-08 15:32:33 +0000 | [diff] [blame] | 2579 | case ISN_RETURN_OBJECT: |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 2580 | case ISN_RETURN_VOID: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2581 | case ISN_SHUFFLE: |
| 2582 | case ISN_SLICE: |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 2583 | case ISN_SOURCE: |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2584 | case ISN_STORE: |
| 2585 | case ISN_STOREINDEX: |
| 2586 | case ISN_STORENR: |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 2587 | case ISN_STOREOUTER: |
Bram Moolenaar | 7ce7daf | 2022-12-10 18:42:12 +0000 | [diff] [blame] | 2588 | case ISN_STORE_THIS: |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 2589 | case ISN_STORERANGE: |
| 2590 | case ISN_STOREREG: |
| 2591 | case ISN_STOREV: |
| 2592 | case ISN_STRINDEX: |
| 2593 | case ISN_STRSLICE: |
| 2594 | case ISN_THROW: |
| 2595 | case ISN_TRYCONT: |
| 2596 | case ISN_UNLETINDEX: |
| 2597 | case ISN_UNLETRANGE: |
| 2598 | case ISN_UNPACK: |
| 2599 | case ISN_USEDICT: |
Bram Moolenaar | b46c083 | 2022-09-15 17:19:37 +0100 | [diff] [blame] | 2600 | case ISN_WHILE: |
Bram Moolenaar | c0ceeeb | 2022-03-30 21:12:27 +0100 | [diff] [blame] | 2601 | // nothing allocated |
| 2602 | break; |
Bram Moolenaar | 1d84f76 | 2022-09-03 21:35:53 +0100 | [diff] [blame] | 2603 | } |
Bram Moolenaar | dc7c366 | 2021-12-20 15:04:29 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | void |
| 2607 | clear_instr_ga(garray_T *gap) |
| 2608 | { |
| 2609 | int idx; |
| 2610 | |
| 2611 | for (idx = 0; idx < gap->ga_len; ++idx) |
| 2612 | delete_instr(((isn_T *)gap->ga_data) + idx); |
| 2613 | ga_clear(gap); |
| 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | #endif // defined(FEAT_EVAL) |