comparison src/vim9execute.c @ 19283:9dc843109c97 v8.2.0200

patch 8.2.0200: Vim9 script commands not sufficiently tested Commit: https://github.com/vim/vim/commit/b283a8a6802ef8a46b17cb439f9514840c03698f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 2 22:24:04 2020 +0100 patch 8.2.0200: Vim9 script commands not sufficiently tested Problem: Vim9 script commands not sufficiently tested. Solution: Add more tests. Fix storing global variable. Make script variables work.
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Feb 2020 22:30:04 +0100
parents 9fcdeaa18bd1
children 2a63b7f5802a
comparison
equal deleted inserted replaced
19282:0d513180baa1 19283:9dc843109c97
486 goto failed; 486 goto failed;
487 copy_tv(get_vim_var_tv(iptr->isn_arg.number), STACK_TV_BOT(0)); 487 copy_tv(get_vim_var_tv(iptr->isn_arg.number), STACK_TV_BOT(0));
488 ++ectx.ec_stack.ga_len; 488 ++ectx.ec_stack.ga_len;
489 break; 489 break;
490 490
491 // load s: variable in vim9script 491 // load s: variable in Vim9 script
492 case ISN_LOADSCRIPT: 492 case ISN_LOADSCRIPT:
493 { 493 {
494 scriptitem_T *si = 494 scriptitem_T *si =
495 SCRIPT_ITEM(iptr->isn_arg.script.script_sid); 495 SCRIPT_ITEM(iptr->isn_arg.script.script_sid);
496 svar_T *sv; 496 svar_T *sv;
505 break; 505 break;
506 506
507 // load s: variable in old script 507 // load s: variable in old script
508 case ISN_LOADS: 508 case ISN_LOADS:
509 { 509 {
510 hashtab_T *ht = &SCRIPT_VARS(iptr->isn_arg.loads.ls_sid); 510 hashtab_T *ht = &SCRIPT_VARS(
511 char_u *name = iptr->isn_arg.loads.ls_name; 511 iptr->isn_arg.loadstore.ls_sid);
512 char_u *name = iptr->isn_arg.loadstore.ls_name;
512 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE); 513 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
513 if (di == NULL) 514 if (di == NULL)
514 { 515 {
515 semsg(_("E121: Undefined variable: s:%s"), name); 516 semsg(_(e_undefvar), name);
516 goto failed; 517 goto failed;
517 } 518 }
518 else 519 else
519 { 520 {
520 if (ga_grow(&ectx.ec_stack, 1) == FAIL) 521 if (ga_grow(&ectx.ec_stack, 1) == FAIL)
599 tv = STACK_TV_VAR(iptr->isn_arg.number); 600 tv = STACK_TV_VAR(iptr->isn_arg.number);
600 clear_tv(tv); 601 clear_tv(tv);
601 *tv = *STACK_TV_BOT(0); 602 *tv = *STACK_TV_BOT(0);
602 break; 603 break;
603 604
604 // store script-local variable 605 // store s: variable in old script
606 case ISN_STORES:
607 {
608 hashtab_T *ht = &SCRIPT_VARS(
609 iptr->isn_arg.loadstore.ls_sid);
610 char_u *name = iptr->isn_arg.loadstore.ls_name;
611 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
612
613 if (di == NULL)
614 {
615 semsg(_(e_undefvar), name);
616 goto failed;
617 }
618 --ectx.ec_stack.ga_len;
619 clear_tv(&di->di_tv);
620 di->di_tv = *STACK_TV_BOT(0);
621 }
622 break;
623
624 // store script-local variable in Vim9 script
605 case ISN_STORESCRIPT: 625 case ISN_STORESCRIPT:
606 { 626 {
607 scriptitem_T *si = SCRIPT_ITEM( 627 scriptitem_T *si = SCRIPT_ITEM(
608 iptr->isn_arg.script.script_sid); 628 iptr->isn_arg.script.script_sid);
609 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) 629 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
644 emsg(_(msg)); 664 emsg(_(msg));
645 goto failed; 665 goto failed;
646 } 666 }
647 clear_tv(tv); 667 clear_tv(tv);
648 } 668 }
669 break;
670
671 // store $ENV
672 case ISN_STOREENV:
673 --ectx.ec_stack.ga_len;
674 vim_setenv_ext(iptr->isn_arg.string,
675 tv_get_string(STACK_TV_BOT(0)));
676 break;
677
678 // store @r
679 case ISN_STOREREG:
680 {
681 int reg = iptr->isn_arg.number;
682
683 --ectx.ec_stack.ga_len;
684 write_reg_contents(reg == '@' ? '"' : reg,
685 tv_get_string(STACK_TV_BOT(0)), -1, FALSE);
686 }
687 break;
688
689 // store v: variable
690 case ISN_STOREV:
691 --ectx.ec_stack.ga_len;
692 if (set_vim_var_tv(iptr->isn_arg.number, STACK_TV_BOT(0))
693 == FAIL)
694 goto failed;
649 break; 695 break;
650 696
651 // store g: variable 697 // store g: variable
652 case ISN_STOREG: 698 case ISN_STOREG:
653 { 699 {
1581 sv->sv_name, si->sn_name); 1627 sv->sv_name, si->sn_name);
1582 } 1628 }
1583 break; 1629 break;
1584 case ISN_LOADS: 1630 case ISN_LOADS:
1585 { 1631 {
1586 scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.loads.ls_sid); 1632 scriptitem_T *si = SCRIPT_ITEM(
1633 iptr->isn_arg.loadstore.ls_sid);
1587 1634
1588 smsg("%4d LOADS s:%s from %s", current, 1635 smsg("%4d LOADS s:%s from %s", current,
1589 iptr->isn_arg.string, si->sn_name); 1636 iptr->isn_arg.string, si->sn_name);
1590 } 1637 }
1591 break; 1638 break;
1603 break; 1650 break;
1604 1651
1605 case ISN_STORE: 1652 case ISN_STORE:
1606 smsg("%4d STORE $%lld", current, iptr->isn_arg.number); 1653 smsg("%4d STORE $%lld", current, iptr->isn_arg.number);
1607 break; 1654 break;
1655 case ISN_STOREV:
1656 smsg("%4d STOREV v:%s", current,
1657 get_vim_var_name(iptr->isn_arg.number));
1658 break;
1608 case ISN_STOREG: 1659 case ISN_STOREG:
1609 smsg("%4d STOREG g:%s", current, iptr->isn_arg.string); 1660 smsg("%4d STOREG %s", current, iptr->isn_arg.string);
1661 break;
1662 case ISN_STORES:
1663 {
1664 scriptitem_T *si = SCRIPT_ITEM(
1665 iptr->isn_arg.loadstore.ls_sid);
1666
1667 smsg("%4d STORES s:%s in %s", current,
1668 iptr->isn_arg.string, si->sn_name);
1669 }
1610 break; 1670 break;
1611 case ISN_STORESCRIPT: 1671 case ISN_STORESCRIPT:
1612 { 1672 {
1613 scriptitem_T *si = 1673 scriptitem_T *si =
1614 SCRIPT_ITEM(iptr->isn_arg.script.script_sid); 1674 SCRIPT_ITEM(iptr->isn_arg.script.script_sid);
1621 break; 1681 break;
1622 case ISN_STOREOPT: 1682 case ISN_STOREOPT:
1623 smsg("%4d STOREOPT &%s", current, 1683 smsg("%4d STOREOPT &%s", current,
1624 iptr->isn_arg.storeopt.so_name); 1684 iptr->isn_arg.storeopt.so_name);
1625 break; 1685 break;
1626 1686 case ISN_STOREENV:
1687 smsg("%4d STOREENV $%s", current, iptr->isn_arg.string);
1688 break;
1689 case ISN_STOREREG:
1690 smsg("%4d STOREREG @%c", current, iptr->isn_arg.number);
1691 break;
1627 case ISN_STORENR: 1692 case ISN_STORENR:
1628 smsg("%4d STORE %lld in $%d", current, 1693 smsg("%4d STORE %lld in $%d", current,
1629 iptr->isn_arg.storenr.str_val, 1694 iptr->isn_arg.storenr.str_val,
1630 iptr->isn_arg.storenr.str_idx); 1695 iptr->isn_arg.storenr.str_idx);
1631 break; 1696 break;