comparison src/evalvars.c @ 22272:eb1f5f618c75 v8.2.1685

patch 8.2.1685: Vim9: cannot declare a constant value Commit: https://github.com/vim/vim/commit/0b4c66c67a083f25816b9cdb8e76a41e02d9f560 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 14 21:39:44 2020 +0200 patch 8.2.1685: Vim9: cannot declare a constant value Problem: Vim9: cannot declare a constant value. Solution: Introduce ":const!".
author Bram Moolenaar <Bram@vim.org>
date Mon, 14 Sep 2020 21:45:04 +0200
parents 23f5750146d9
children 07e48ee8c3bb
comparison
equal deleted inserted replaced
22271:0440d470ae70 22272:eb1f5f618c75
171 static void list_tab_vars(int *first); 171 static void list_tab_vars(int *first);
172 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); 172 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first);
173 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op); 173 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op);
174 static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); 174 static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie);
175 static int do_lock_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); 175 static int do_lock_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie);
176 static void item_lock(typval_T *tv, int deep, int lock, int check_refcount);
177 static void delete_var(hashtab_T *ht, hashitem_T *hi); 176 static void delete_var(hashtab_T *ht, hashitem_T *hi);
178 static void list_one_var(dictitem_T *v, char *prefix, int *first); 177 static void list_one_var(dictitem_T *v, char *prefix, int *first);
179 static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first); 178 static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first);
180 179
181 /* 180 /*
707 int vim9script = in_vim9script(); 706 int vim9script = in_vim9script();
708 707
709 // detect Vim9 assignment without ":let" or ":const" 708 // detect Vim9 assignment without ":let" or ":const"
710 if (eap->arg == eap->cmd) 709 if (eap->arg == eap->cmd)
711 flags |= LET_NO_COMMAND; 710 flags |= LET_NO_COMMAND;
711 if (eap->forceit)
712 flags |= LET_FORCEIT;
712 713
713 argend = skip_var_list(arg, TRUE, &var_count, &semicolon, FALSE); 714 argend = skip_var_list(arg, TRUE, &var_count, &semicolon, FALSE);
714 if (argend == NULL) 715 if (argend == NULL)
715 return; 716 return;
716 if (argend > arg && argend[-1] == '.') // for var.='str' 717 if (argend > arg && argend[-1] == '.') // for var.='str'
857 char_u *arg_start, 858 char_u *arg_start,
858 typval_T *tv, 859 typval_T *tv,
859 int copy, // copy values from "tv", don't move 860 int copy, // copy values from "tv", don't move
860 int semicolon, // from skip_var_list() 861 int semicolon, // from skip_var_list()
861 int var_count, // from skip_var_list() 862 int var_count, // from skip_var_list()
862 int flags, // LET_IS_CONST and/or LET_NO_COMMAND 863 int flags, // LET_IS_CONST, LET_FORCEIT, LET_NO_COMMAND
863 char_u *op) 864 char_u *op)
864 { 865 {
865 char_u *arg = arg_start; 866 char_u *arg = arg_start;
866 list_T *l; 867 list_T *l;
867 int i; 868 int i;
1212 static char_u * 1213 static char_u *
1213 ex_let_one( 1214 ex_let_one(
1214 char_u *arg, // points to variable name 1215 char_u *arg, // points to variable name
1215 typval_T *tv, // value to assign to variable 1216 typval_T *tv, // value to assign to variable
1216 int copy, // copy value from "tv" 1217 int copy, // copy value from "tv"
1217 int flags, // LET_IS_CONST and/or LET_NO_COMMAND 1218 int flags, // LET_IS_CONST, LET_FORCEIT, LET_NO_COMMAND
1218 char_u *endchars, // valid chars after variable name or NULL 1219 char_u *endchars, // valid chars after variable name or NULL
1219 char_u *op) // "+", "-", "." or NULL 1220 char_u *op) // "+", "-", "." or NULL
1220 { 1221 {
1221 int c1; 1222 int c1;
1222 char_u *name; 1223 char_u *name;
1739 /* 1740 /*
1740 * Lock or unlock an item. "deep" is nr of levels to go. 1741 * Lock or unlock an item. "deep" is nr of levels to go.
1741 * When "check_refcount" is TRUE do not lock a list or dict with a reference 1742 * When "check_refcount" is TRUE do not lock a list or dict with a reference
1742 * count larger than 1. 1743 * count larger than 1.
1743 */ 1744 */
1744 static void 1745 void
1745 item_lock(typval_T *tv, int deep, int lock, int check_refcount) 1746 item_lock(typval_T *tv, int deep, int lock, int check_refcount)
1746 { 1747 {
1747 static int recurse = 0; 1748 static int recurse = 0;
1748 list_T *l; 1749 list_T *l;
1749 listitem_T *li; 1750 listitem_T *li;
2935 set_var_const( 2936 set_var_const(
2936 char_u *name, 2937 char_u *name,
2937 type_T *type, 2938 type_T *type,
2938 typval_T *tv_arg, 2939 typval_T *tv_arg,
2939 int copy, // make copy of value in "tv" 2940 int copy, // make copy of value in "tv"
2940 int flags) // LET_IS_CONST and/or LET_NO_COMMAND 2941 int flags) // LET_IS_CONST, LET_FORCEIT, LET_NO_COMMAND
2941 { 2942 {
2942 typval_T *tv = tv_arg; 2943 typval_T *tv = tv_arg;
2943 typval_T bool_tv; 2944 typval_T bool_tv;
2944 dictitem_T *di; 2945 dictitem_T *di;
2945 char_u *varname; 2946 char_u *varname;
3122 di->di_tv = *tv; 3123 di->di_tv = *tv;
3123 di->di_tv.v_lock = 0; 3124 di->di_tv.v_lock = 0;
3124 init_tv(tv); 3125 init_tv(tv);
3125 } 3126 }
3126 3127
3127 // ":const var = val" locks the value, but not in Vim9 script 3128 // ":const var = val" locks the value; in Vim9 script only with ":const!"
3128 if ((flags & LET_IS_CONST) && !vim9script) 3129 if ((flags & LET_IS_CONST) && (!vim9script || (flags & LET_FORCEIT)))
3129 // Like :lockvar! name: lock the value and what it contains, but only 3130 // Like :lockvar! name: lock the value and what it contains, but only
3130 // if the reference count is up to one. That locks only literal 3131 // if the reference count is up to one. That locks only literal
3131 // values. 3132 // values.
3132 item_lock(&di->di_tv, DICT_MAXNEST, TRUE, TRUE); 3133 item_lock(&di->di_tv, DICT_MAXNEST, TRUE, TRUE);
3133 return; 3134 return;