diff src/vim9compile.c @ 23233:657216220293 v8.2.2162

patch 8.2.2162: Vim9: Cannot load or store autoload variables Commit: https://github.com/vim/vim/commit/03290b8444b69c6d7307755770467bc488384e1a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 19 16:30:44 2020 +0100 patch 8.2.2162: Vim9: Cannot load or store autoload variables Problem: Vim9: Cannot load or store autoload variables. Solution: Add ISN_LOADAUTO and ISN_STOREAUTO. (closes https://github.com/vim/vim/issues/7485)
author Bram Moolenaar <Bram@vim.org>
date Sat, 19 Dec 2020 16:45:06 +0100
parents b545334ae654
children ac934fbacc0e
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2535,7 +2535,17 @@ compile_load(
 		case 's': res = compile_load_scriptvar(cctx, name,
 							    NULL, NULL, error);
 			  break;
-		case 'g': isn_type = ISN_LOADG; break;
+		case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
+			      isn_type = ISN_LOADG;
+			  else
+			  {
+			      isn_type = ISN_LOADAUTO;
+			      vim_free(name);
+			      name = vim_strnsave(*arg, end - *arg);
+			      if (name == NULL)
+				  return FAIL;
+			  }
+			  break;
 		case 'w': isn_type = ISN_LOADW; break;
 		case 't': isn_type = ISN_LOADT; break;
 		case 'b': isn_type = ISN_LOADB; break;
@@ -2738,7 +2748,7 @@ compile_call(
     if (compile_arguments(arg, cctx, &argcount) == FAIL)
 	goto theend;
 
-    is_autoload = vim_strchr(name, '#') != NULL;
+    is_autoload = vim_strchr(name, AUTOLOAD_CHAR) != NULL;
     if (ASCII_ISLOWER(*name) && name[1] != ':' && !is_autoload)
     {
 	int	    idx;
@@ -4986,7 +4996,10 @@ generate_loadvar(
 	    generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
 	    break;
 	case dest_global:
-	    generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
+	    if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
+		generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
+	    else
+		generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
 	    break;
 	case dest_buffer:
 	    generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type);
@@ -5198,7 +5211,8 @@ generate_store_var(
 								    opt_flags);
 	case dest_global:
 	    // include g: with the name, easier to execute that way
-	    return generate_STORE(cctx, ISN_STOREG, 0, name);
+	    return generate_STORE(cctx, vim_strchr(name, AUTOLOAD_CHAR) == NULL
+					? ISN_STOREG : ISN_STOREAUTO, 0, name);
 	case dest_buffer:
 	    // include b: with the name, easier to execute that way
 	    return generate_STORE(cctx, ISN_STOREB, 0, name);
@@ -8007,6 +8021,7 @@ delete_instr(isn_T *isn)
     {
 	case ISN_DEF:
 	case ISN_EXEC:
+	case ISN_LOADAUTO:
 	case ISN_LOADB:
 	case ISN_LOADENV:
 	case ISN_LOADG:
@@ -8017,6 +8032,7 @@ delete_instr(isn_T *isn)
 	case ISN_PUSHFUNC:
 	case ISN_PUSHS:
 	case ISN_RANGE:
+	case ISN_STOREAUTO:
 	case ISN_STOREB:
 	case ISN_STOREENV:
 	case ISN_STOREG: