comparison src/vim9compile.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 1634ca41e4d3
comparison
equal deleted inserted replaced
22271:0440d470ae70 22272:eb1f5f618c75
1103 if ((isn = generate_instr(cctx, isn_type)) == NULL) 1103 if ((isn = generate_instr(cctx, isn_type)) == NULL)
1104 return FAIL; 1104 return FAIL;
1105 isn->isn_arg.unlet.ul_name = vim_strsave(name); 1105 isn->isn_arg.unlet.ul_name = vim_strsave(name);
1106 isn->isn_arg.unlet.ul_forceit = forceit; 1106 isn->isn_arg.unlet.ul_forceit = forceit;
1107 1107
1108 return OK;
1109 }
1110
1111 /*
1112 * Generate an ISN_LOCKCONST instruction.
1113 */
1114 static int
1115 generate_LOCKCONST(cctx_T *cctx)
1116 {
1117 isn_T *isn;
1118
1119 RETURN_OK_IF_SKIP(cctx);
1120 if ((isn = generate_instr(cctx, ISN_LOCKCONST)) == NULL)
1121 return FAIL;
1108 return OK; 1122 return OK;
1109 } 1123 }
1110 1124
1111 /* 1125 /*
1112 * Generate an ISN_LOADS instruction. 1126 * Generate an ISN_LOADS instruction.
4340 char_u *lambda_name; 4354 char_u *lambda_name;
4341 lvar_T *lvar; 4355 lvar_T *lvar;
4342 ufunc_T *ufunc; 4356 ufunc_T *ufunc;
4343 int r; 4357 int r;
4344 4358
4345 if (*name_start == '!') 4359 if (eap->forceit)
4346 { 4360 {
4347 emsg(_(e_cannot_use_bang_with_nested_def)); 4361 emsg(_(e_cannot_use_bang_with_nested_def));
4348 return NULL; 4362 return NULL;
4349 } 4363 }
4350 4364
5230 goto theend; 5244 goto theend;
5231 } 5245 }
5232 } 5246 }
5233 else 5247 else
5234 { 5248 {
5249 if (is_decl && eap->forceit && cmdidx == CMD_const
5250 && (dest == dest_script || dest == dest_local))
5251 // ":const! var": lock the value, but not referenced variables
5252 generate_LOCKCONST(cctx);
5253
5235 switch (dest) 5254 switch (dest)
5236 { 5255 {
5237 case dest_option: 5256 case dest_option:
5238 generate_STOREOPT(cctx, skip_option_env_lead(name), 5257 generate_STOREOPT(cctx, skip_option_env_lead(name),
5239 opt_flags); 5258 opt_flags);
6360 compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx) 6379 compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx)
6361 { 6380 {
6362 char_u *line = arg; 6381 char_u *line = arg;
6363 linenr_T lnum; 6382 linenr_T lnum;
6364 char *errormsg; 6383 char *errormsg;
6365 int above = FALSE; 6384 int above = eap->forceit;
6366 6385
6367 if (*arg == '!')
6368 {
6369 above = TRUE;
6370 line = skipwhite(arg + 1);
6371 }
6372 eap->regname = *line; 6386 eap->regname = *line;
6373 6387
6374 if (eap->regname == '=') 6388 if (eap->regname == '=')
6375 { 6389 {
6376 char_u *p = line + 1; 6390 char_u *p = line + 1;
6409 if (cctx->ctx_skip == SKIP_YES) 6423 if (cctx->ctx_skip == SKIP_YES)
6410 goto theend; 6424 goto theend;
6411 6425
6412 if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE) 6426 if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
6413 { 6427 {
6414 long argt = excmd_get_argt(eap->cmdidx); 6428 long argt = eap->argt;
6415 int usefilter = FALSE; 6429 int usefilter = FALSE;
6416 6430
6417 has_expr = argt & (EX_XFILE | EX_EXPAND); 6431 has_expr = argt & (EX_XFILE | EX_EXPAND);
6418 6432
6419 // If the command can be followed by a bar, find the bar and truncate 6433 // If the command can be followed by a bar, find the bar and truncate
6868 iemsg("Command from find_ex_command() not handled"); 6882 iemsg("Command from find_ex_command() not handled");
6869 goto erret; 6883 goto erret;
6870 } 6884 }
6871 } 6885 }
6872 6886
6873 p = skipwhite(p);
6874
6875 if (cctx.ctx_had_return 6887 if (cctx.ctx_had_return
6876 && ea.cmdidx != CMD_elseif 6888 && ea.cmdidx != CMD_elseif
6877 && ea.cmdidx != CMD_else 6889 && ea.cmdidx != CMD_else
6878 && ea.cmdidx != CMD_endif 6890 && ea.cmdidx != CMD_endif
6879 && ea.cmdidx != CMD_endfor 6891 && ea.cmdidx != CMD_endfor
6882 && ea.cmdidx != CMD_finally 6894 && ea.cmdidx != CMD_finally
6883 && ea.cmdidx != CMD_endtry) 6895 && ea.cmdidx != CMD_endtry)
6884 { 6896 {
6885 emsg(_(e_unreachable_code_after_return)); 6897 emsg(_(e_unreachable_code_after_return));
6886 goto erret; 6898 goto erret;
6899 }
6900
6901 p = skipwhite(p);
6902 if (ea.cmdidx != CMD_SIZE
6903 && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read)
6904 {
6905 ea.argt = excmd_get_argt(ea.cmdidx);
6906 if ((ea.argt & EX_BANG) && *p == '!')
6907 {
6908 ea.forceit = TRUE;
6909 p = skipwhite(p + 1);
6910 }
6887 } 6911 }
6888 6912
6889 switch (ea.cmdidx) 6913 switch (ea.cmdidx)
6890 { 6914 {
6891 case CMD_def: 6915 case CMD_def:
7307 case ISN_LOADREG: 7331 case ISN_LOADREG:
7308 case ISN_LOADSCRIPT: 7332 case ISN_LOADSCRIPT:
7309 case ISN_LOADTDICT: 7333 case ISN_LOADTDICT:
7310 case ISN_LOADV: 7334 case ISN_LOADV:
7311 case ISN_LOADWDICT: 7335 case ISN_LOADWDICT:
7336 case ISN_LOCKCONST:
7312 case ISN_MEMBER: 7337 case ISN_MEMBER:
7313 case ISN_NEGATENR: 7338 case ISN_NEGATENR:
7314 case ISN_NEWDICT: 7339 case ISN_NEWDICT:
7315 case ISN_NEWLIST: 7340 case ISN_NEWLIST:
7316 case ISN_OPANY: 7341 case ISN_OPANY: