diff src/vim9execute.c @ 19283:9dc843109c97 v8.2.0200

patch 8.2.0200: Vim9 script commands not sufficiently tested Commit: https://github.com/vim/vim/commit/b283a8a6802ef8a46b17cb439f9514840c03698f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 2 22:24:04 2020 +0100 patch 8.2.0200: Vim9 script commands not sufficiently tested Problem: Vim9 script commands not sufficiently tested. Solution: Add more tests. Fix storing global variable. Make script variables work.
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Feb 2020 22:30:04 +0100
parents 9fcdeaa18bd1
children 2a63b7f5802a
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -488,7 +488,7 @@ call_def_function(
 		++ectx.ec_stack.ga_len;
 		break;
 
-	    // load s: variable in vim9script
+	    // load s: variable in Vim9 script
 	    case ISN_LOADSCRIPT:
 		{
 		    scriptitem_T *si =
@@ -507,12 +507,13 @@ call_def_function(
 	    // load s: variable in old script
 	    case ISN_LOADS:
 		{
-		    hashtab_T	*ht = &SCRIPT_VARS(iptr->isn_arg.loads.ls_sid);
-		    char_u	*name = iptr->isn_arg.loads.ls_name;
+		    hashtab_T	*ht = &SCRIPT_VARS(
+					       iptr->isn_arg.loadstore.ls_sid);
+		    char_u	*name = iptr->isn_arg.loadstore.ls_name;
 		    dictitem_T	*di = find_var_in_ht(ht, 0, name, TRUE);
 		    if (di == NULL)
 		    {
-			semsg(_("E121: Undefined variable: s:%s"), name);
+			semsg(_(e_undefvar), name);
 			goto failed;
 		    }
 		    else
@@ -601,7 +602,26 @@ call_def_function(
 		*tv = *STACK_TV_BOT(0);
 		break;
 
-	    // store script-local variable
+	    // store s: variable in old script
+	    case ISN_STORES:
+		{
+		    hashtab_T	*ht = &SCRIPT_VARS(
+					       iptr->isn_arg.loadstore.ls_sid);
+		    char_u	*name = iptr->isn_arg.loadstore.ls_name;
+		    dictitem_T	*di = find_var_in_ht(ht, 0, name, TRUE);
+
+		    if (di == NULL)
+		    {
+			semsg(_(e_undefvar), name);
+			goto failed;
+		    }
+		    --ectx.ec_stack.ga_len;
+		    clear_tv(&di->di_tv);
+		    di->di_tv = *STACK_TV_BOT(0);
+		}
+		break;
+
+	    // store script-local variable in Vim9 script
 	    case ISN_STORESCRIPT:
 		{
 		    scriptitem_T *si = SCRIPT_ITEM(
@@ -648,6 +668,32 @@ call_def_function(
 		}
 		break;
 
+	    // store $ENV
+	    case ISN_STOREENV:
+		--ectx.ec_stack.ga_len;
+		vim_setenv_ext(iptr->isn_arg.string,
+					       tv_get_string(STACK_TV_BOT(0)));
+		break;
+
+	    // store @r
+	    case ISN_STOREREG:
+		{
+		    int	reg = iptr->isn_arg.number;
+
+		    --ectx.ec_stack.ga_len;
+		    write_reg_contents(reg == '@' ? '"' : reg,
+				    tv_get_string(STACK_TV_BOT(0)), -1, FALSE);
+		}
+		break;
+
+	    // store v: variable
+	    case ISN_STOREV:
+		--ectx.ec_stack.ga_len;
+		if (set_vim_var_tv(iptr->isn_arg.number, STACK_TV_BOT(0))
+								       == FAIL)
+		    goto failed;
+		break;
+
 	    // store g: variable
 	    case ISN_STOREG:
 		{
@@ -1583,7 +1629,8 @@ ex_disassemble(exarg_T *eap)
 		break;
 	    case ISN_LOADS:
 		{
-		    scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.loads.ls_sid);
+		    scriptitem_T *si = SCRIPT_ITEM(
+					       iptr->isn_arg.loadstore.ls_sid);
 
 		    smsg("%4d LOADS s:%s from %s", current,
 					    iptr->isn_arg.string, si->sn_name);
@@ -1605,8 +1652,21 @@ ex_disassemble(exarg_T *eap)
 	    case ISN_STORE:
 		smsg("%4d STORE $%lld", current, iptr->isn_arg.number);
 		break;
+	    case ISN_STOREV:
+		smsg("%4d STOREV v:%s", current,
+				       get_vim_var_name(iptr->isn_arg.number));
+		break;
 	    case ISN_STOREG:
-		smsg("%4d STOREG g:%s", current, iptr->isn_arg.string);
+		smsg("%4d STOREG %s", current, iptr->isn_arg.string);
+		break;
+	    case ISN_STORES:
+		{
+		    scriptitem_T *si = SCRIPT_ITEM(
+					       iptr->isn_arg.loadstore.ls_sid);
+
+		    smsg("%4d STORES s:%s in %s", current,
+					    iptr->isn_arg.string, si->sn_name);
+		}
 		break;
 	    case ISN_STORESCRIPT:
 		{
@@ -1623,7 +1683,12 @@ ex_disassemble(exarg_T *eap)
 		smsg("%4d STOREOPT &%s", current,
 					       iptr->isn_arg.storeopt.so_name);
 		break;
-
+	    case ISN_STOREENV:
+		smsg("%4d STOREENV $%s", current, iptr->isn_arg.string);
+		break;
+	    case ISN_STOREREG:
+		smsg("%4d STOREREG @%c", current, iptr->isn_arg.number);
+		break;
 	    case ISN_STORENR:
 		smsg("%4d STORE %lld in $%d", current,
 				iptr->isn_arg.storenr.str_val,