comparison src/vim9instr.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 30c642c58cd4
children d45ee1f829ba
comparison
equal deleted inserted replaced
30064:a8f1fbaa43c8 30065:6cf788ab844c
614 break; 614 break;
615 #endif 615 #endif
616 case VAR_FUNC: 616 case VAR_FUNC:
617 if (tv->vval.v_string != NULL) 617 if (tv->vval.v_string != NULL)
618 iemsg("non-null function constant not supported"); 618 iemsg("non-null function constant not supported");
619 generate_PUSHFUNC(cctx, NULL, &t_func_unknown); 619 generate_PUSHFUNC(cctx, NULL, &t_func_unknown, TRUE);
620 break; 620 break;
621 case VAR_PARTIAL: 621 case VAR_PARTIAL:
622 if (tv->vval.v_partial != NULL) 622 if (tv->vval.v_partial != NULL)
623 iemsg("non-null partial constant not supported"); 623 iemsg("non-null partial constant not supported");
624 if (generate_instr_type(cctx, ISN_NEWPARTIAL, &t_func_unknown) 624 if (generate_instr_type(cctx, ISN_NEWPARTIAL, &t_func_unknown)
794 return OK; 794 return OK;
795 } 795 }
796 796
797 /* 797 /*
798 * Generate an ISN_PUSHFUNC instruction with name "name". 798 * Generate an ISN_PUSHFUNC instruction with name "name".
799 */ 799 * When "may_prefix" is TRUE prefix "g:" unless "name" is script-local or
800 int 800 * autoload.
801 generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type) 801 */
802 int
803 generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type, int may_prefix)
802 { 804 {
803 isn_T *isn; 805 isn_T *isn;
804 char_u *funcname; 806 char_u *funcname;
805 807
806 RETURN_OK_IF_SKIP(cctx); 808 RETURN_OK_IF_SKIP(cctx);
807 if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL) 809 if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
808 return FAIL; 810 return FAIL;
809 if (name == NULL) 811 if (name == NULL)
810 funcname = NULL; 812 funcname = NULL;
811 else if (*name == K_SPECIAL // script-local 813 else if (!may_prefix
814 || *name == K_SPECIAL // script-local
812 || vim_strchr(name, AUTOLOAD_CHAR) != NULL) // autoload 815 || vim_strchr(name, AUTOLOAD_CHAR) != NULL) // autoload
813 funcname = vim_strsave(name); 816 funcname = vim_strsave(name);
814 else 817 else
815 { 818 {
816 funcname = alloc(STRLEN(name) + 3); 819 funcname = alloc(STRLEN(name) + 3);
1677 1680
1678 return OK; 1681 return OK;
1679 } 1682 }
1680 1683
1681 /* 1684 /*
1685 * Generate an ISN_DEFER instruction.
1686 */
1687 int
1688 generate_DEFER(cctx_T *cctx, int var_idx, int argcount)
1689 {
1690 isn_T *isn;
1691
1692 RETURN_OK_IF_SKIP(cctx);
1693 if ((isn = generate_instr_drop(cctx, ISN_DEFER, argcount + 1)) == NULL)
1694 return FAIL;
1695 isn->isn_arg.defer.defer_var_idx = var_idx;
1696 isn->isn_arg.defer.defer_argcount = argcount;
1697 return OK;
1698 }
1699
1700 /*
1682 * Generate an ISN_STRINGMEMBER instruction. 1701 * Generate an ISN_STRINGMEMBER instruction.
1683 */ 1702 */
1684 int 1703 int
1685 generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len) 1704 generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len)
1686 { 1705 {
2238 case ISN_COMPARESPECIAL: 2257 case ISN_COMPARESPECIAL:
2239 case ISN_COMPARESTRING: 2258 case ISN_COMPARESTRING:
2240 case ISN_CONCAT: 2259 case ISN_CONCAT:
2241 case ISN_COND2BOOL: 2260 case ISN_COND2BOOL:
2242 case ISN_DEBUG: 2261 case ISN_DEBUG:
2262 case ISN_DEFER:
2243 case ISN_DROP: 2263 case ISN_DROP:
2244 case ISN_ECHO: 2264 case ISN_ECHO:
2245 case ISN_ECHOCONSOLE: 2265 case ISN_ECHOCONSOLE:
2246 case ISN_ECHOERR: 2266 case ISN_ECHOERR:
2247 case ISN_ECHOMSG: 2267 case ISN_ECHOMSG:
2294 case ISN_SLICE: 2314 case ISN_SLICE:
2295 case ISN_STORE: 2315 case ISN_STORE:
2296 case ISN_STOREINDEX: 2316 case ISN_STOREINDEX:
2297 case ISN_STORENR: 2317 case ISN_STORENR:
2298 case ISN_SOURCE: 2318 case ISN_SOURCE:
2299 case ISN_STOREOUTER: 2319 case ISN_STOREOUTER:
2300 case ISN_STORERANGE: 2320 case ISN_STORERANGE:
2301 case ISN_STOREREG: 2321 case ISN_STOREREG:
2302 case ISN_STOREV: 2322 case ISN_STOREV:
2303 case ISN_STRINDEX: 2323 case ISN_STRINDEX:
2304 case ISN_STRSLICE: 2324 case ISN_STRSLICE:
2305 case ISN_THROW: 2325 case ISN_THROW:
2306 case ISN_TRYCONT: 2326 case ISN_TRYCONT:
2307 case ISN_UNLETINDEX: 2327 case ISN_UNLETINDEX:
2308 case ISN_UNLETRANGE: 2328 case ISN_UNLETRANGE:
2309 case ISN_UNPACK: 2329 case ISN_UNPACK:
2310 case ISN_USEDICT: 2330 case ISN_USEDICT:
2311 // nothing allocated 2331 // nothing allocated
2312 break; 2332 break;
2313 } 2333 }
2314 } 2334 }
2315 2335
2316 void 2336 void
2317 clear_instr_ga(garray_T *gap) 2337 clear_instr_ga(garray_T *gap)
2318 { 2338 {