]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2314: Vim9: returning zero takes two instructions v8.2.2314
authorBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 19:53:09 +0000 (20:53 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 19:53:09 +0000 (20:53 +0100)
Problem:    Vim9: returning zero takes two instructions.
Solution:   Add ISN_RETURN_ZERO.

src/testdir/test_vim9_disassemble.vim
src/version.c
src/vim9.h
src/vim9compile.c
src/vim9execute.c

index b0f84a6e1e961b26bfc2de2abb03aaea908f3be9..f25b04ae3bb3deb5d57d74559136e106cd949cc3 100644 (file)
@@ -117,8 +117,7 @@ def Test_disassemble_exec_expr()
         '\d 2STRING stack\[-1\]\_s*' ..
         '\d\+ PUSHS ".txt"\_s*' ..
         '\d\+ EXECCONCAT 4\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -134,8 +133,7 @@ def Test_disassemble_yank_range()
         '\d EXEC   norm! m\[jjm\]\_s*' ..
         '  :''\[,''\]yank\_s*' ..
         '\d EXEC   :''\[,''\]yank\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -149,8 +147,7 @@ def Test_disassemble_put_expr()
         ' :3put ="text"\_s*' ..
         '\d PUSHS "text"\_s*' ..
         '\d PUT = 3\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -164,8 +161,7 @@ def Test_disassemble_put_range()
         ' :$-2put a\_s*' ..
         '\d RANGE $-2\_s*' ..
         '\d PUT a range\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -273,8 +269,7 @@ def Test_disassemble_store_member()
         '\d\+ PUSHS "a"\_s*' ..
         '\d\+ LOAD $1\_s*' ..
         '\d\+ STOREDICT\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -297,8 +292,7 @@ def Test_disassemble_store_index()
         '\d LOAD $0\_s*' ..
         '\d MEMBER dd\_s*' ..
         '\d STOREINDEX\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -333,8 +327,7 @@ def Test_disassemble_list_assign()
         '\d\+ STORE $1\_s*' ..
         '\d\+ SLICE 2\_s*' ..
         '\d\+ STORE $2\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -362,8 +355,7 @@ def Test_disassemble_list_add()
         '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
         '\d\+ LISTAPPEND\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -390,8 +382,7 @@ def Test_disassemble_blob_add()
         '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
         '\d\+ BLOBAPPEND\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -580,8 +571,7 @@ def Test_disassemble_closure()
         '\d LOAD arg\[-1\]\_s*' ..
         '\d CONCAT\_s*' ..
         '\d STOREOUTER $0\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 
   res = execute('disass g:Get')
@@ -615,8 +605,7 @@ def Test_disassemble_pcall()
         '\d PCALL top (argc 1)\_s*' ..
         '\d PCALL end\_s*' ..
         '\d DROP\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -865,8 +854,7 @@ def Test_disassemble_function()
         '\d PUSHS "UserFunc"\_s*' ..
         '\d BCALL funcref(argc 1)\_s*' ..
         '\d STORE $2\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         instr)
 enddef
 
@@ -893,8 +881,7 @@ def Test_disassemble_channel()
         'var chan1: channel\_s*' ..
         '\d PUSHCHANNEL 0\_s*' ..
         '\d STORE $2\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         instr)
 enddef
 
@@ -966,8 +953,7 @@ def Test_nested_func()
         'echomsg "inner"\_s*' ..
         'enddef\_s*' ..
         '\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         instr)
 enddef
 
@@ -989,8 +975,7 @@ def Test_nested_def_list()
         '\d DEF /Info\_s*' ..
         'def /Info/\_s*' ..
         '\d DEF /Info/\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         instr)
 enddef
 
@@ -1122,8 +1107,7 @@ def Test_disassemble_for_loop_unpack()
         'endfor\_s*' ..
         '\d\+ JUMP -> 8\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         instr)
 enddef
 
@@ -1143,8 +1127,7 @@ def Test_disassemble_typecast()
         '\d NEWLIST size 2\_s*' ..
         '\d SETTYPE list<number>\_s*' ..
         '\d STORE $0\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN\_s*',
+        '\d RETURN 0\_s*',
         instr)
 enddef
 
@@ -1631,8 +1614,7 @@ def Test_dsassemble_falsy_op()
       'echo "" ?? "empty string"\_s*' ..
       '\d\+ PUSHS "empty string"\_s*' ..
       '\d\+ ECHO 1\_s*' ..
-      '\d\+ PUSHNR 0\_s*' ..
-      '\d\+ RETURN',
+      '\d\+ RETURN 0',
       res)
 enddef
 
@@ -1659,8 +1641,7 @@ def Test_disassemble_compare_const()
           'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
           '\d PUSHNR 42.*' ..
           '\d ECHO 1.*' ..
-          '\d PUSHNR 0.*' ..
-          '\d RETURN.*',
+          '\d RETURN 0',
           instr)
     else
       # condition false, function just returns
@@ -1668,8 +1649,7 @@ def Test_disassemble_compare_const()
           'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
           'echo 42[ \n]*' ..
           'endif[ \n]*' ..
-          '\s*\d PUSHNR 0.*' ..
-          '\d RETURN.*',
+          '\d RETURN 0',
           instr)
     endif
 
@@ -1707,8 +1687,7 @@ def Test_disassemble_execute()
         '\d\+ LOAD $1\_s*' ..
         '\d\+ CONCAT\_s*' ..
         '\d\+ EXECUTE 1\_s*' ..
-        '\d\+ PUSHNR 0\_s*' ..
-        '\d\+ RETURN',
+        '\d\+ RETURN 0',
         res)
 enddef
 
@@ -1727,8 +1706,7 @@ def Test_disassemble_echomsg()
         "echoerr 'went' .. 'wrong'\\_s*" ..
         '\d PUSHS "wentwrong"\_s*' ..
         '\d ECHOERR 1\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -1837,8 +1815,7 @@ def Test_shuffle()
         '\d SHUFFLE 2 up 1\_s*' ..
         '\d BCALL append(argc 2)\_s*' ..
         '\d DROP\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
@@ -1861,8 +1838,7 @@ def Test_silent()
         '\d PUSHS "error"\_s*' ..
         '\d ECHOERR 1\_s*' ..
         '\d CMDMOD_REV\_s*' ..
-        '\d PUSHNR 0\_s*' ..
-        '\d RETURN',
+        '\d RETURN 0',
         res)
 enddef
 
index 9e49e6ddaa0ad61f34f61b81417fbd119d80d150..7ab3b0142ccc7ca76077dbaa3179c8283ef0aa19 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2314,
 /**/
     2313,
 /**/
index 49103ba556ab75f1559acc40479eaf7f93ced033..440de278502b21f1226f38f5a658bd284452fdde 100644 (file)
@@ -84,6 +84,7 @@ typedef enum {
     ISN_PCALL,     // call partial, use isn_arg.pfunc
     ISN_PCALL_END,  // cleanup after ISN_PCALL with cpf_top set
     ISN_RETURN,            // return, result is on top of stack
+    ISN_RETURN_ZERO, // Push zero, then return
     ISN_FUNCREF,    // push a function ref to dfunc isn_arg.funcref
     ISN_NEWFUNC,    // create a global function from a lambda function
     ISN_DEF,       // list functions
index 7497e9cc09d61f1dfe8bc2e5f9be473d4e5748cd..376f306a41e25bc85d297ad14c2fa3d36f4dcd1d 100644 (file)
@@ -8190,8 +8190,7 @@ nextline:
        }
 
        // Return zero if there is no return at the end.
-       generate_PUSHNR(&cctx, 0);
-       generate_instr(&cctx, ISN_RETURN);
+       generate_instr(&cctx, ISN_RETURN_ZERO);
     }
 
     {
@@ -8483,6 +8482,7 @@ delete_instr(isn_T *isn)
        case ISN_PUSHSPEC:
        case ISN_PUT:
        case ISN_RETURN:
+       case ISN_RETURN_ZERO:
        case ISN_SHUFFLE:
        case ISN_SLICE:
        case ISN_STORE:
index 44180b8f19681c493ce3cb2e4614a777edfea79b..9a76cc9c36c90bcaab2d9a3ec98e8a05ae5705e9 100644 (file)
@@ -2205,6 +2205,16 @@ call_def_function(
                break;
 
            // return from a :def function call
+           case ISN_RETURN_ZERO:
+               if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
+                   goto failed;
+               tv = STACK_TV_BOT(0);
+               ++ectx.ec_stack.ga_len;
+               tv->v_type = VAR_NUMBER;
+               tv->vval.v_number = 0;
+               tv->v_lock = 0;
+               // FALLTHROUGH
+
            case ISN_RETURN:
                {
                    garray_T    *trystack = &ectx.ec_trystack;
@@ -3804,6 +3814,9 @@ ex_disassemble(exarg_T *eap)
            case ISN_RETURN:
                smsg("%4d RETURN", current);
                break;
+           case ISN_RETURN_ZERO:
+               smsg("%4d RETURN 0", current);
+               break;
            case ISN_FUNCREF:
                {
                    funcref_T   *funcref = &iptr->isn_arg.funcref;