comparison src/vim9compile.c @ 20091:a64c16ff98b8 v8.2.0601

patch 8.2.0601: Vim9: :unlet is not compiled Commit: https://github.com/vim/vim/commit/d72c1bf0a6784afdc8d8ceab4a007cd76d5b81e1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 19 16:28:59 2020 +0200 patch 8.2.0601: Vim9: :unlet is not compiled Problem: Vim9: :unlet is not compiled. Solution: Implement :unlet instruction and check for errors.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Apr 2020 16:30:04 +0200
parents 7fc5d62fe2a5
children 058b41f85bcb
comparison
equal deleted inserted replaced
20090:b2225a10b777 20091:a64c16ff98b8
982 return FAIL; 982 return FAIL;
983 } 983 }
984 type = typval2type(get_vim_var_tv(vidx)); 984 type = typval2type(get_vim_var_tv(vidx));
985 985
986 return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type); 986 return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
987 }
988
989 /*
990 * Generate an ISN_UNLET instruction.
991 */
992 static int
993 generate_UNLET(cctx_T *cctx, char_u *name, int forceit)
994 {
995 isn_T *isn;
996
997 RETURN_OK_IF_SKIP(cctx);
998 if ((isn = generate_instr(cctx, ISN_UNLET)) == NULL)
999 return FAIL;
1000 isn->isn_arg.unlet.ul_name = vim_strsave(name);
1001 isn->isn_arg.unlet.ul_forceit = forceit;
1002
1003 return OK;
987 } 1004 }
988 1005
989 /* 1006 /*
990 * Generate an ISN_LOADS instruction. 1007 * Generate an ISN_LOADS instruction.
991 */ 1008 */
4541 vim_free(name); 4558 vim_free(name);
4542 return ret; 4559 return ret;
4543 } 4560 }
4544 4561
4545 /* 4562 /*
4563 * Check if "name" can be "unlet".
4564 */
4565 int
4566 check_vim9_unlet(char_u *name)
4567 {
4568 if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
4569 {
4570 semsg(_("E1081: Cannot unlet %s"), name);
4571 return FAIL;
4572 }
4573 return OK;
4574 }
4575
4576 /*
4577 * Callback passed to ex_unletlock().
4578 */
4579 static int
4580 compile_unlet(
4581 lval_T *lvp,
4582 char_u *name_end,
4583 exarg_T *eap,
4584 int deep UNUSED,
4585 void *coookie)
4586 {
4587 cctx_T *cctx = coookie;
4588
4589 if (lvp->ll_tv == NULL)
4590 {
4591 char_u *p = lvp->ll_name;
4592 int cc = *name_end;
4593 int ret = OK;
4594
4595 // Normal name. Only supports g:, w:, t: and b: namespaces.
4596 *name_end = NUL;
4597 if (check_vim9_unlet(p) == FAIL)
4598 ret = FAIL;
4599 else
4600 ret = generate_UNLET(cctx, p, eap->forceit);
4601
4602 *name_end = cc;
4603 return ret;
4604 }
4605
4606 // TODO: unlet {list}[idx]
4607 // TODO: unlet {dict}[key]
4608 emsg("Sorry, :unlet not fully implemented yet");
4609 return FAIL;
4610 }
4611
4612 /*
4613 * compile "unlet var", "lock var" and "unlock var"
4614 * "arg" points to "var".
4615 */
4616 static char_u *
4617 compile_unletlock(char_u *arg, exarg_T *eap, cctx_T *cctx)
4618 {
4619 char_u *p = arg;
4620
4621 if (eap->cmdidx != CMD_unlet)
4622 {
4623 emsg("Sorry, :lock and unlock not implemented yet");
4624 return NULL;
4625 }
4626
4627 if (*p == '!')
4628 {
4629 p = skipwhite(p + 1);
4630 eap->forceit = TRUE;
4631 }
4632
4633 ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD, compile_unlet, cctx);
4634 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
4635 }
4636
4637 /*
4546 * Compile an :import command. 4638 * Compile an :import command.
4547 */ 4639 */
4548 static char_u * 4640 static char_u *
4549 compile_import(char_u *arg, cctx_T *cctx) 4641 compile_import(char_u *arg, cctx_T *cctx)
4550 { 4642 {
6029 case CMD_let: 6121 case CMD_let:
6030 case CMD_const: 6122 case CMD_const:
6031 line = compile_assignment(p, &ea, ea.cmdidx, &cctx); 6123 line = compile_assignment(p, &ea, ea.cmdidx, &cctx);
6032 break; 6124 break;
6033 6125
6126 case CMD_unlet:
6127 case CMD_unlockvar:
6128 case CMD_lockvar:
6129 line = compile_unletlock(p, &ea, &cctx);
6130 break;
6131
6034 case CMD_import: 6132 case CMD_import:
6035 line = compile_import(p, &cctx); 6133 line = compile_import(p, &cctx);
6036 break; 6134 break;
6037 6135
6038 case CMD_if: 6136 case CMD_if:
6260 break; 6358 break;
6261 6359
6262 case ISN_LOADS: 6360 case ISN_LOADS:
6263 case ISN_STORES: 6361 case ISN_STORES:
6264 vim_free(isn->isn_arg.loadstore.ls_name); 6362 vim_free(isn->isn_arg.loadstore.ls_name);
6363 break;
6364
6365 case ISN_UNLET:
6366 vim_free(isn->isn_arg.unlet.ul_name);
6265 break; 6367 break;
6266 6368
6267 case ISN_STOREOPT: 6369 case ISN_STOREOPT:
6268 vim_free(isn->isn_arg.storeopt.so_name); 6370 vim_free(isn->isn_arg.storeopt.so_name);
6269 break; 6371 break;