0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.1685: Vim9: cannot declare a constant value

Problem:    Vim9: cannot declare a constant value.
Solution:   Introduce ":const!".
This commit is contained in:
Bram Moolenaar
2020-09-14 21:39:44 +02:00
parent efd5d8a967
commit 0b4c66c67a
12 changed files with 204 additions and 38 deletions

View File

@@ -1108,6 +1108,20 @@ generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit)
return OK;
}
/*
* Generate an ISN_LOCKCONST instruction.
*/
static int
generate_LOCKCONST(cctx_T *cctx)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr(cctx, ISN_LOCKCONST)) == NULL)
return FAIL;
return OK;
}
/*
* Generate an ISN_LOADS instruction.
*/
@@ -4342,7 +4356,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
ufunc_T *ufunc;
int r;
if (*name_start == '!')
if (eap->forceit)
{
emsg(_(e_cannot_use_bang_with_nested_def));
return NULL;
@@ -5232,6 +5246,11 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
}
else
{
if (is_decl && eap->forceit && cmdidx == CMD_const
&& (dest == dest_script || dest == dest_local))
// ":const! var": lock the value, but not referenced variables
generate_LOCKCONST(cctx);
switch (dest)
{
case dest_option:
@@ -6362,13 +6381,8 @@ compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx)
char_u *line = arg;
linenr_T lnum;
char *errormsg;
int above = FALSE;
int above = eap->forceit;
if (*arg == '!')
{
above = TRUE;
line = skipwhite(arg + 1);
}
eap->regname = *line;
if (eap->regname == '=')
@@ -6411,7 +6425,7 @@ compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
{
long argt = excmd_get_argt(eap->cmdidx);
long argt = eap->argt;
int usefilter = FALSE;
has_expr = argt & (EX_XFILE | EX_EXPAND);
@@ -6870,8 +6884,6 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
}
}
p = skipwhite(p);
if (cctx.ctx_had_return
&& ea.cmdidx != CMD_elseif
&& ea.cmdidx != CMD_else
@@ -6886,6 +6898,18 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
goto erret;
}
p = skipwhite(p);
if (ea.cmdidx != CMD_SIZE
&& ea.cmdidx != CMD_write && ea.cmdidx != CMD_read)
{
ea.argt = excmd_get_argt(ea.cmdidx);
if ((ea.argt & EX_BANG) && *p == '!')
{
ea.forceit = TRUE;
p = skipwhite(p + 1);
}
}
switch (ea.cmdidx)
{
case CMD_def:
@@ -7309,6 +7333,7 @@ delete_instr(isn_T *isn)
case ISN_LOADTDICT:
case ISN_LOADV:
case ISN_LOADWDICT:
case ISN_LOCKCONST:
case ISN_MEMBER:
case ISN_NEGATENR:
case ISN_NEWDICT: