comparison src/vim9compile.c @ 20089:7fc5d62fe2a5 v8.2.0600

patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables Commit: https://github.com/vim/vim/commit/d3aac2917db38f8590648ee76eebfa178fc4c069 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 19 14:32:17 2020 +0200 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables Problem: Vim9: cannot read or write w:, t: and b: variables. Solution: Implement load and store for w:, t: and b: variables. (closes #5950)
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Apr 2020 14:45:03 +0200
parents 336483164ca6
children a64c16ff98b8
comparison
equal deleted inserted replaced
20088:004788f1261e 20089:7fc5d62fe2a5
2233 { 2233 {
2234 res = compile_load_scriptvar(cctx, name, NULL, NULL, error); 2234 res = compile_load_scriptvar(cctx, name, NULL, NULL, error);
2235 } 2235 }
2236 else if (**arg == 'b') 2236 else if (**arg == 'b')
2237 { 2237 {
2238 semsg("Namespace b: not supported yet: %s", *arg); 2238 // Buffer-local variables can be defined later, thus we don't check
2239 goto theend; 2239 // if it exists, give error at runtime.
2240 res = generate_LOAD(cctx, ISN_LOADB, 0, name, &t_any);
2240 } 2241 }
2241 else if (**arg == 'w') 2242 else if (**arg == 'w')
2242 { 2243 {
2243 semsg("Namespace w: not supported yet: %s", *arg); 2244 // Window-local variables can be defined later, thus we don't check
2244 goto theend; 2245 // if it exists, give error at runtime.
2246 res = generate_LOAD(cctx, ISN_LOADW, 0, name, &t_any);
2245 } 2247 }
2246 else if (**arg == 't') 2248 else if (**arg == 't')
2247 { 2249 {
2248 semsg("Namespace t: not supported yet: %s", *arg); 2250 // Tabpage-local variables can be defined later, thus we don't
2249 goto theend; 2251 // check if it exists, give error at runtime.
2252 res = generate_LOAD(cctx, ISN_LOADT, 0, name, &t_any);
2250 } 2253 }
2251 else 2254 else
2252 { 2255 {
2253 semsg("E1075: Namespace not supported: %s", *arg); 2256 semsg("E1075: Namespace not supported: %s", *arg);
2254 goto theend; 2257 goto theend;
3956 typedef enum { 3959 typedef enum {
3957 dest_local, 3960 dest_local,
3958 dest_option, 3961 dest_option,
3959 dest_env, 3962 dest_env,
3960 dest_global, 3963 dest_global,
3964 dest_buffer,
3965 dest_window,
3966 dest_tab,
3961 dest_vimvar, 3967 dest_vimvar,
3962 dest_script, 3968 dest_script,
3963 dest_reg, 3969 dest_reg,
3964 } assign_dest_T; 3970 } assign_dest_T;
3965 3971
4085 { 4091 {
4086 semsg(_("E1016: Cannot declare a global variable: %s"), name); 4092 semsg(_("E1016: Cannot declare a global variable: %s"), name);
4087 goto theend; 4093 goto theend;
4088 } 4094 }
4089 } 4095 }
4096 else if (STRNCMP(arg, "b:", 2) == 0)
4097 {
4098 dest = dest_buffer;
4099 if (is_decl)
4100 {
4101 semsg(_("E1078: Cannot declare a buffer variable: %s"), name);
4102 goto theend;
4103 }
4104 }
4105 else if (STRNCMP(arg, "w:", 2) == 0)
4106 {
4107 dest = dest_window;
4108 if (is_decl)
4109 {
4110 semsg(_("E1079: Cannot declare a window variable: %s"), name);
4111 goto theend;
4112 }
4113 }
4114 else if (STRNCMP(arg, "t:", 2) == 0)
4115 {
4116 dest = dest_tab;
4117 if (is_decl)
4118 {
4119 semsg(_("E1080: Cannot declare a tab variable: %s"), name);
4120 goto theend;
4121 }
4122 }
4090 else if (STRNCMP(arg, "v:", 2) == 0) 4123 else if (STRNCMP(arg, "v:", 2) == 0)
4091 { 4124 {
4092 typval_T *vtv; 4125 typval_T *vtv;
4093 int di_flags; 4126 int di_flags;
4094 4127
4242 // TODO: check the option exists 4275 // TODO: check the option exists
4243 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); 4276 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
4244 break; 4277 break;
4245 case dest_global: 4278 case dest_global:
4246 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); 4279 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
4280 break;
4281 case dest_buffer:
4282 generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type);
4283 break;
4284 case dest_window:
4285 generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type);
4286 break;
4287 case dest_tab:
4288 generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type);
4247 break; 4289 break;
4248 case dest_script: 4290 case dest_script:
4249 compile_load_scriptvar(cctx, 4291 compile_load_scriptvar(cctx,
4250 name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE); 4292 name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE);
4251 break; 4293 break;
4408 break; 4450 break;
4409 case dest_global: 4451 case dest_global:
4410 // include g: with the name, easier to execute that way 4452 // include g: with the name, easier to execute that way
4411 generate_STORE(cctx, ISN_STOREG, 0, name); 4453 generate_STORE(cctx, ISN_STOREG, 0, name);
4412 break; 4454 break;
4455 case dest_buffer:
4456 // include b: with the name, easier to execute that way
4457 generate_STORE(cctx, ISN_STOREB, 0, name);
4458 break;
4459 case dest_window:
4460 // include w: with the name, easier to execute that way
4461 generate_STORE(cctx, ISN_STOREW, 0, name);
4462 break;
4463 case dest_tab:
4464 // include t: with the name, easier to execute that way
4465 generate_STORE(cctx, ISN_STORET, 0, name);
4466 break;
4413 case dest_env: 4467 case dest_env:
4414 generate_STORE(cctx, ISN_STOREENV, 0, name + 1); 4468 generate_STORE(cctx, ISN_STOREENV, 0, name + 1);
4415 break; 4469 break;
4416 case dest_reg: 4470 case dest_reg:
4417 generate_STORE(cctx, ISN_STOREREG, name[1], NULL); 4471 generate_STORE(cctx, ISN_STOREREG, name[1], NULL);
6187 switch (isn->isn_type) 6241 switch (isn->isn_type)
6188 { 6242 {
6189 case ISN_EXEC: 6243 case ISN_EXEC:
6190 case ISN_LOADENV: 6244 case ISN_LOADENV:
6191 case ISN_LOADG: 6245 case ISN_LOADG:
6246 case ISN_LOADB:
6247 case ISN_LOADW:
6248 case ISN_LOADT:
6192 case ISN_LOADOPT: 6249 case ISN_LOADOPT:
6193 case ISN_MEMBER: 6250 case ISN_MEMBER:
6194 case ISN_PUSHEXC: 6251 case ISN_PUSHEXC:
6195 case ISN_PUSHS: 6252 case ISN_PUSHS:
6196 case ISN_STOREENV: 6253 case ISN_STOREENV:
6197 case ISN_STOREG: 6254 case ISN_STOREG:
6255 case ISN_STOREB:
6256 case ISN_STOREW:
6257 case ISN_STORET:
6198 case ISN_PUSHFUNC: 6258 case ISN_PUSHFUNC:
6199 vim_free(isn->isn_arg.string); 6259 vim_free(isn->isn_arg.string);
6200 break; 6260 break;
6201 6261
6202 case ISN_LOADS: 6262 case ISN_LOADS: