comparison src/vim9compile.c @ 21399:5cb6e676defd v8.2.1250

patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces Commit: https://github.com/vim/vim/commit/2f8ce0ae8a8247563be0a77a308130e767e0566e Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 19 19:47:35 2020 +0200 patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces Problem: Vim9: cannot use the g:, b:, t: and w: namespaces. Solution: Add instructions to push a dict for the namespaces. (closes https://github.com/vim/vim/issues/6480)
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jul 2020 20:00:04 +0200
parents 320581a133d9
children e1aeb986712f
comparison
equal deleted inserted replaced
21398:5f89f2a27c66 21399:5cb6e676defd
145 145
146 static char e_var_notfound[] = N_("E1001: variable not found: %s"); 146 static char e_var_notfound[] = N_("E1001: variable not found: %s");
147 static char e_syntax_at[] = N_("E1002: Syntax error at %s"); 147 static char e_syntax_at[] = N_("E1002: Syntax error at %s");
148 static char e_used_as_arg[] = N_("E1006: %s is used as an argument"); 148 static char e_used_as_arg[] = N_("E1006: %s is used as an argument");
149 static char e_cannot_use_void[] = N_("E1031: Cannot use void value"); 149 static char e_cannot_use_void[] = N_("E1031: Cannot use void value");
150 static char e_namespace[] = N_("E1075: Namespace not supported: %s");
150 151
151 static void delete_def_function_contents(dfunc_T *dfunc); 152 static void delete_def_function_contents(dfunc_T *dfunc);
152 static void arg_type_mismatch(type_T *expected, type_T *actual, int argidx); 153 static void arg_type_mismatch(type_T *expected, type_T *actual, int argidx);
153 154
154 /* 155 /*
2779 */ 2780 */
2780 static int 2781 static int
2781 compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error) 2782 compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
2782 { 2783 {
2783 type_T *type; 2784 type_T *type;
2784 char_u *name; 2785 char_u *name = NULL;
2785 char_u *end = end_arg; 2786 char_u *end = end_arg;
2786 int res = FAIL; 2787 int res = FAIL;
2787 int prev_called_emsg = called_emsg; 2788 int prev_called_emsg = called_emsg;
2788 2789
2789 if (*(*arg + 1) == ':') 2790 if (*(*arg + 1) == ':')
2790 { 2791 {
2791 // load namespaced variable 2792 // load namespaced variable
2792 if (end <= *arg + 2) 2793 if (end <= *arg + 2)
2793 name = vim_strsave((char_u *)"[empty]"); 2794 {
2795 isntype_T isn_type;
2796
2797 switch (**arg)
2798 {
2799 case 'g': isn_type = ISN_LOADGDICT; break;
2800 case 'w': isn_type = ISN_LOADWDICT; break;
2801 case 't': isn_type = ISN_LOADTDICT; break;
2802 case 'b': isn_type = ISN_LOADBDICT; break;
2803 default:
2804 semsg(_(e_namespace), *arg);
2805 goto theend;
2806 }
2807 if (generate_instr_type(cctx, isn_type, &t_dict_any) == NULL)
2808 goto theend;
2809 res = OK;
2810 }
2794 else 2811 else
2812 {
2813 isntype_T isn_type = ISN_DROP;
2814
2795 name = vim_strnsave(*arg + 2, end - (*arg + 2)); 2815 name = vim_strnsave(*arg + 2, end - (*arg + 2));
2796 if (name == NULL) 2816 if (name == NULL)
2797 return FAIL; 2817 return FAIL;
2798 2818
2799 if (**arg == 'v') 2819 switch (**arg)
2800 { 2820 {
2801 res = generate_LOADV(cctx, name, error); 2821 case 'v': res = generate_LOADV(cctx, name, error);
2802 } 2822 break;
2803 else if (**arg == 'g') 2823 case 's': res = compile_load_scriptvar(cctx, name,
2804 { 2824 NULL, NULL, error);
2805 // Global variables can be defined later, thus we don't check if it 2825 break;
2806 // exists, give error at runtime. 2826 case 'g': isn_type = ISN_LOADG; break;
2807 res = generate_LOAD(cctx, ISN_LOADG, 0, name, &t_any); 2827 case 'w': isn_type = ISN_LOADW; break;
2808 } 2828 case 't': isn_type = ISN_LOADT; break;
2809 else if (**arg == 's') 2829 case 'b': isn_type = ISN_LOADB; break;
2810 { 2830 default: semsg(_(e_namespace), *arg);
2811 res = compile_load_scriptvar(cctx, name, NULL, NULL, error); 2831 goto theend;
2812 } 2832 }
2813 else if (**arg == 'b') 2833 if (isn_type != ISN_DROP)
2814 { 2834 {
2815 // Buffer-local variables can be defined later, thus we don't check 2835 // Global, Buffer-local, Window-local and Tabpage-local
2816 // if it exists, give error at runtime. 2836 // variables can be defined later, thus we don't check if it
2817 res = generate_LOAD(cctx, ISN_LOADB, 0, name, &t_any); 2837 // exists, give error at runtime.
2818 } 2838 res = generate_LOAD(cctx, isn_type, 0, name, &t_any);
2819 else if (**arg == 'w') 2839 }
2820 {
2821 // Window-local variables can be defined later, thus we don't check
2822 // if it exists, give error at runtime.
2823 res = generate_LOAD(cctx, ISN_LOADW, 0, name, &t_any);
2824 }
2825 else if (**arg == 't')
2826 {
2827 // Tabpage-local variables can be defined later, thus we don't
2828 // check if it exists, give error at runtime.
2829 res = generate_LOAD(cctx, ISN_LOADT, 0, name, &t_any);
2830 }
2831 else
2832 {
2833 semsg("E1075: Namespace not supported: %s", *arg);
2834 goto theend;
2835 } 2840 }
2836 } 2841 }
2837 else 2842 else
2838 { 2843 {
2839 size_t len = end - *arg; 2844 size_t len = end - *arg;
7554 case ISN_GETITEM: 7559 case ISN_GETITEM:
7555 case ISN_SLICE: 7560 case ISN_SLICE:
7556 case ISN_MEMBER: 7561 case ISN_MEMBER:
7557 case ISN_JUMP: 7562 case ISN_JUMP:
7558 case ISN_LOAD: 7563 case ISN_LOAD:
7564 case ISN_LOADBDICT:
7565 case ISN_LOADGDICT:
7559 case ISN_LOADOUTER: 7566 case ISN_LOADOUTER:
7567 case ISN_LOADREG:
7560 case ISN_LOADSCRIPT: 7568 case ISN_LOADSCRIPT:
7561 case ISN_LOADREG: 7569 case ISN_LOADTDICT:
7562 case ISN_LOADV: 7570 case ISN_LOADV:
7571 case ISN_LOADWDICT:
7563 case ISN_NEGATENR: 7572 case ISN_NEGATENR:
7564 case ISN_NEWDICT: 7573 case ISN_NEWDICT:
7565 case ISN_NEWLIST: 7574 case ISN_NEWLIST:
7566 case ISN_OPNR: 7575 case ISN_OPNR:
7567 case ISN_OPFLOAT: 7576 case ISN_OPFLOAT: