• R/O
  • SSH

vim: 提交

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

修訂3b026343f39872ecebb958fe5b82e819d16fc613 (tree)
時間2020-02-27 02:30:04
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0321: Vim9: ":execute" does not work yet

Commit: https://github.com/vim/vim/commit/ad39c094d261109a695aba2c4f19fe336736cc55
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 26 18:23:43 2020 +0100

patch 8.2.0321: Vim9: ":execute" does not work yet
Problem: Vim9: ":execute" does not work yet.
Solution: Add ISN_EXECUTE. (closes https://github.com/vim/vim/issues/5699) Also make :echo work with more
than one argument.

Change Summary

差異

diff -r b4e703999a84 -r 3b026343f398 src/testdir/test_vim9_disassemble.vim
--- a/src/testdir/test_vim9_disassemble.vim Wed Feb 26 16:30:05 2020 +0100
+++ b/src/testdir/test_vim9_disassemble.vim Wed Feb 26 18:30:04 2020 +0100
@@ -690,4 +690,37 @@
690690 " delete('Xdisassemble')
691691 enddef
692692
693+def s:Execute()
694+ execute 'help vim9.txt'
695+ let cmd = 'help vim9.txt'
696+ execute cmd
697+ let tag = 'vim9.txt'
698+ execute 'help ' .. tag
699+enddef
700+
701+def Test_disassemble_execute()
702+ let res = execute('disass s:Execute')
703+ assert_match('\<SNR>\d*_Execute.*'
704+ \ .. "execute 'help vim9.txt'.*"
705+ \ .. '\d PUSHS "help vim9.txt".*'
706+ \ .. '\d EXECUTE 1.*'
707+ \ .. "let cmd = 'help vim9.txt'.*"
708+ \ .. '\d PUSHS "help vim9.txt".*'
709+ \ .. '\d STORE $0.*'
710+ \ .. 'execute cmd.*'
711+ \ .. '\d LOAD $0.*'
712+ \ .. '\d EXECUTE 1.*'
713+ \ .. "let tag = 'vim9.txt'.*"
714+ \ .. '\d PUSHS "vim9.txt".*'
715+ \ .. '\d STORE $1.*'
716+ \ .. "execute 'help ' .. tag.*"
717+ \ .. '\d PUSHS "help ".*'
718+ \ .. '\d LOAD $1.*'
719+ \ .. '\d CONCAT.*'
720+ \ .. '\d EXECUTE 1.*'
721+ \ .. '\d PUSHNR 0.*'
722+ \ .. '\d RETURN'
723+ \, res)
724+enddef
725+
693726 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff -r b4e703999a84 -r 3b026343f398 src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Wed Feb 26 16:30:05 2020 +0100
+++ b/src/testdir/test_vim9_script.vim Wed Feb 26 18:30:04 2020 +0100
@@ -1,6 +1,7 @@
11 " Test various aspects of the Vim9 script language.
22
33 source check.vim
4+source view_util.vim
45
56 " Check that "lines" inside ":def" results in an "error" message.
67 func CheckDefFailure(lines, error)
@@ -692,5 +693,33 @@
692693 delete('Xvim9lines')
693694 enddef
694695
696+def Test_execute_cmd()
697+ new
698+ setline(1, 'default')
699+ execute 'call setline(1, "execute-string")'
700+ assert_equal('execute-string', getline(1))
701+ let cmd1 = 'call setline(1,'
702+ let cmd2 = '"execute-var")'
703+ execute cmd1 cmd2
704+ assert_equal('execute-var', getline(1))
705+ execute cmd1 cmd2 '|call setline(1, "execute-var-string")'
706+ assert_equal('execute-var-string', getline(1))
707+ let cmd_first = 'call '
708+ let cmd_last = 'setline(1, "execute-var-var")'
709+ execute cmd_first .. cmd_last
710+ assert_equal('execute-var-var', getline(1))
711+ bwipe!
712+enddef
713+
714+def Test_echo_cmd()
715+ echo 'something'
716+ assert_match('^something$', Screenline(&lines))
717+
718+ let str1 = 'some'
719+ let str2 = 'more'
720+ echo str1 str2
721+ assert_match('^some more$', Screenline(&lines))
722+enddef
723+
695724
696725 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff -r b4e703999a84 -r 3b026343f398 src/version.c
--- a/src/version.c Wed Feb 26 16:30:05 2020 +0100
+++ b/src/version.c Wed Feb 26 18:30:04 2020 +0100
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 321,
743+/**/
742744 320,
743745 /**/
744746 319,
diff -r b4e703999a84 -r 3b026343f398 src/vim9.h
--- a/src/vim9.h Wed Feb 26 16:30:05 2020 +0100
+++ b/src/vim9.h Wed Feb 26 18:30:04 2020 +0100
@@ -13,7 +13,8 @@
1313
1414 typedef enum {
1515 ISN_EXEC, // execute Ex command line isn_arg.string
16- ISN_ECHO, // echo isn_arg.number items on top of stack
16+ ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
17+ ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
1718
1819 // get and set variables
1920 ISN_LOAD, // push local variable isn_arg.number
diff -r b4e703999a84 -r 3b026343f398 src/vim9compile.c
--- a/src/vim9compile.c Wed Feb 26 16:30:05 2020 +0100
+++ b/src/vim9compile.c Wed Feb 26 18:30:04 2020 +0100
@@ -1116,6 +1116,21 @@
11161116 return OK;
11171117 }
11181118
1119+/*
1120+ * Generate an ISN_EXECUTE instruction.
1121+ */
1122+ static int
1123+generate_EXECUTE(cctx_T *cctx, int count)
1124+{
1125+ isn_T *isn;
1126+
1127+ if ((isn = generate_instr_drop(cctx, ISN_EXECUTE, count)) == NULL)
1128+ return FAIL;
1129+ isn->isn_arg.number = count;
1130+
1131+ return OK;
1132+}
1133+
11191134 static int
11201135 generate_EXEC(cctx_T *cctx, char_u *line)
11211136 {
@@ -4671,14 +4686,40 @@
46714686 char_u *p = arg;
46724687 int count = 0;
46734688
4674- // for ()
4689+ for (;;)
46754690 {
46764691 if (compile_expr1(&p, cctx) == FAIL)
46774692 return NULL;
46784693 ++count;
4694+ p = skipwhite(p);
4695+ if (ends_excmd(*p))
4696+ break;
46794697 }
46804698
46814699 generate_ECHO(cctx, with_white, count);
4700+ return p;
4701+}
4702+
4703+/*
4704+ * compile "execute expr"
4705+ */
4706+ static char_u *
4707+compile_execute(char_u *arg, cctx_T *cctx)
4708+{
4709+ char_u *p = arg;
4710+ int count = 0;
4711+
4712+ for (;;)
4713+ {
4714+ if (compile_expr1(&p, cctx) == FAIL)
4715+ return NULL;
4716+ ++count;
4717+ p = skipwhite(p);
4718+ if (ends_excmd(*p))
4719+ break;
4720+ }
4721+
4722+ generate_EXECUTE(cctx, count);
46824723
46834724 return p;
46844725 }
@@ -5017,12 +5058,14 @@
50175058 case CMD_echon:
50185059 line = compile_echo(p, FALSE, &cctx);
50195060 break;
5061+ case CMD_execute:
5062+ line = compile_execute(p, &cctx);
5063+ break;
50205064
50215065 default:
50225066 // Not recognized, execute with do_cmdline_cmd().
50235067 // TODO:
50245068 // CMD_echomsg
5025- // CMD_execute
50265069 // etc.
50275070 generate_EXEC(&cctx, line);
50285071 line = (char_u *)"";
@@ -5150,6 +5193,7 @@
51505193 case ISN_DCALL:
51515194 case ISN_DROP:
51525195 case ISN_ECHO:
5196+ case ISN_EXECUTE:
51535197 case ISN_ENDTRY:
51545198 case ISN_FOR:
51555199 case ISN_FUNCREF:
diff -r b4e703999a84 -r 3b026343f398 src/vim9execute.c
--- a/src/vim9execute.c Wed Feb 26 16:30:05 2020 +0100
+++ b/src/vim9execute.c Wed Feb 26 18:30:04 2020 +0100
@@ -533,6 +533,48 @@
533533 }
534534 break;
535535
536+ // execute :execute {string} ...
537+ case ISN_EXECUTE:
538+ {
539+ int count = iptr->isn_arg.number;
540+ garray_T ga;
541+ char_u buf[NUMBUFLEN];
542+ char_u *p;
543+ int len;
544+ int failed = FALSE;
545+
546+ ga_init2(&ga, 1, 80);
547+ for (idx = 0; idx < count; ++idx)
548+ {
549+ tv = STACK_TV_BOT(idx - count);
550+ if (tv->v_type == VAR_CHANNEL || tv->v_type == VAR_JOB)
551+ {
552+ emsg(_(e_inval_string));
553+ break;
554+ }
555+ else
556+ p = tv_get_string_buf(tv, buf);
557+
558+ len = (int)STRLEN(p);
559+ if (ga_grow(&ga, len + 2) == FAIL)
560+ failed = TRUE;
561+ else
562+ {
563+ if (ga.ga_len > 0)
564+ ((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
565+ STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
566+ ga.ga_len += len;
567+ }
568+ clear_tv(tv);
569+ }
570+ ectx.ec_stack.ga_len -= count;
571+
572+ if (!failed && ga.ga_data != NULL)
573+ do_cmdline_cmd((char_u *)ga.ga_data);
574+ ga_clear(&ga);
575+ }
576+ break;
577+
536578 // load local variable or argument
537579 case ISN_LOAD:
538580 if (ga_grow(&ectx.ec_stack, 1) == FAIL)
@@ -1666,6 +1708,9 @@
16661708 echo->echo_count);
16671709 }
16681710 break;
1711+ case ISN_EXECUTE:
1712+ smsg("%4d EXECUTE %d", current, iptr->isn_arg.number);
1713+ break;
16691714 case ISN_LOAD:
16701715 if (iptr->isn_arg.number < 0)
16711716 smsg("%4d LOAD arg[%lld]", current,
Show on old repository browser