comparison src/vim9expr.c @ 30065:6cf788ab844c v9.0.0370

patch 9.0.0370: cleaning up afterwards can make a function messy Commit: https://github.com/vim/vim/commit/1d84f7608f1e41dad03b8cc7925895437775f7c0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 3 21:35:53 2022 +0100 patch 9.0.0370: cleaning up afterwards can make a function messy Problem: Cleaning up afterwards can make a function messy. Solution: Add the :defer command.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Sep 2022 22:45:03 +0200
parents 35cbea786334
children a542dfb1c1a2
comparison
equal deleted inserted replaced
30064:a8f1fbaa43c8 30065:6cf788ab844c
311 311
312 // autoload script must be loaded later, access by the autoload 312 // autoload script must be loaded later, access by the autoload
313 // name. If a '(' follows it must be a function. Otherwise we 313 // name. If a '(' follows it must be a function. Otherwise we
314 // don't know, it can be "script.Func". 314 // don't know, it can be "script.Func".
315 if (cc == '(' || paren_follows_after_expr) 315 if (cc == '(' || paren_follows_after_expr)
316 res = generate_PUSHFUNC(cctx, auto_name, &t_func_any); 316 res = generate_PUSHFUNC(cctx, auto_name, &t_func_any, TRUE);
317 else 317 else
318 res = generate_AUTOLOAD(cctx, auto_name, &t_any); 318 res = generate_AUTOLOAD(cctx, auto_name, &t_any);
319 vim_free(auto_name); 319 vim_free(auto_name);
320 done = TRUE; 320 done = TRUE;
321 } 321 }
327 if (cc == '(' || paren_follows_after_expr) 327 if (cc == '(' || paren_follows_after_expr)
328 { 328 {
329 char_u sid_name[MAX_FUNC_NAME_LEN]; 329 char_u sid_name[MAX_FUNC_NAME_LEN];
330 330
331 func_name_with_sid(exp_name, import->imp_sid, sid_name); 331 func_name_with_sid(exp_name, import->imp_sid, sid_name);
332 res = generate_PUSHFUNC(cctx, sid_name, &t_func_any); 332 res = generate_PUSHFUNC(cctx, sid_name, &t_func_any, TRUE);
333 } 333 }
334 else 334 else
335 res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name, 335 res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
336 import->imp_sid, &t_any); 336 import->imp_sid, &t_any);
337 done = TRUE; 337 done = TRUE;
351 if (idx < 0) 351 if (idx < 0)
352 { 352 {
353 if (ufunc != NULL) 353 if (ufunc != NULL)
354 { 354 {
355 // function call or function reference 355 // function call or function reference
356 generate_PUSHFUNC(cctx, ufunc->uf_name, NULL); 356 generate_PUSHFUNC(cctx, ufunc->uf_name, NULL, TRUE);
357 return OK; 357 return OK;
358 } 358 }
359 return FAIL; 359 return FAIL;
360 } 360 }
361 361
385 // Need to compile any default values to get the argument types. 385 // Need to compile any default values to get the argument types.
386 compile_type = get_compile_type(ufunc); 386 compile_type = get_compile_type(ufunc);
387 if (func_needs_compiling(ufunc, compile_type) 387 if (func_needs_compiling(ufunc, compile_type)
388 && compile_def_function(ufunc, TRUE, compile_type, NULL) == FAIL) 388 && compile_def_function(ufunc, TRUE, compile_type, NULL) == FAIL)
389 return FAIL; 389 return FAIL;
390 return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type); 390 return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type, TRUE);
391 } 391 }
392 392
393 /* 393 /*
394 * Compile a variable name into a load instruction. 394 * Compile a variable name into a load instruction.
395 * "end" points to just after the name. 395 * "end" points to just after the name.
608 isn->isn_arg.instr = instr; 608 isn->isn_arg.instr = instr;
609 return OK; 609 return OK;
610 } 610 }
611 611
612 /* 612 /*
613 * List of special functions for "compile_arguments".
614 */
615 typedef enum {
616 CA_NOT_SPECIAL,
617 CA_SEARCHPAIR, // {skip} in searchpair() and searchpairpos()
618 CA_SUBSTITUTE, // {sub} in substitute(), when prefixed with \=
619 } ca_special_T;
620
621 /*
622 * Compile the argument expressions. 613 * Compile the argument expressions.
623 * "arg" points to just after the "(" and is advanced to after the ")" 614 * "arg" points to just after the "(" and is advanced to after the ")"
624 */ 615 */
625 static int 616 int
626 compile_arguments( 617 compile_arguments(
627 char_u **arg, 618 char_u **arg,
628 cctx_T *cctx, 619 cctx_T *cctx,
629 int *argcount, 620 int *argcount,
630 ca_special_T special_fn) 621 ca_special_T special_fn)