diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-09-14 21:39:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-09-14 21:39:44 +0200 |
commit | 0b4c66c67a083f25816b9cdb8e76a41e02d9f560 (patch) | |
tree | b371efc32dbbbda792f5177e1269c0eb7f2a3d64 /src/vim9compile.c | |
parent | efd5d8a967ba80f9e2826c35be98344d8f00af77 (diff) | |
download | vim-git-0b4c66c67a083f25816b9cdb8e76a41e02d9f560.tar.gz |
patch 8.2.1685: Vim9: cannot declare a constant valuev8.2.1685
Problem: Vim9: cannot declare a constant value.
Solution: Introduce ":const!".
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r-- | src/vim9compile.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c index dd3eff49c..103e696bf 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1109,6 +1109,20 @@ generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit) } /* + * 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. */ static int @@ -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: |