Patch 8.2.2314
Problem:    Vim9: returning zero takes two instructions.
Solution:   Add ISN_RETURN_ZERO.
Files:      src/vim9.h, src/vim9compile.c, src/vim9execute.c,
            src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.2313/src/vim9.h  2021-01-04 21:57:08.088222062 +0100
--- src/vim9.h  2021-01-08 20:45:13.657526043 +0100
***************
*** 84,89 ****
--- 84,90 ----
      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
*** ../vim-8.2.2313/src/vim9compile.c   2021-01-07 22:02:58.684149001 +0100
--- src/vim9compile.c   2021-01-08 20:47:11.249244178 +0100
***************
*** 8190,8197 ****
        }
  
        // Return zero if there is no return at the end.
!       generate_PUSHNR(&cctx, 0);
!       generate_instr(&cctx, ISN_RETURN);
      }
  
      {
--- 8190,8196 ----
        }
  
        // Return zero if there is no return at the end.
!       generate_instr(&cctx, ISN_RETURN_ZERO);
      }
  
      {
***************
*** 8483,8488 ****
--- 8482,8488 ----
        case ISN_PUSHSPEC:
        case ISN_PUT:
        case ISN_RETURN:
+       case ISN_RETURN_ZERO:
        case ISN_SHUFFLE:
        case ISN_SLICE:
        case ISN_STORE:
*** ../vim-8.2.2313/src/vim9execute.c   2021-01-08 20:40:41.958161849 +0100
--- src/vim9execute.c   2021-01-08 20:48:57.920985987 +0100
***************
*** 2205,2210 ****
--- 2205,2220 ----
                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,3809 ****
--- 3814,3822 ----
            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;
*** ../vim-8.2.2313/src/testdir/test_vim9_disassemble.vim       2021-01-02 
15:41:00.193079024 +0100
--- src/testdir/test_vim9_disassemble.vim       2021-01-08 20:52:13.388519800 
+0100
***************
*** 117,124 ****
          '\d 2STRING stack\[-1\]\_s*' ..
          '\d\+ PUSHS ".txt"\_s*' ..
          '\d\+ EXECCONCAT 4\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 117,123 ----
          '\d 2STRING stack\[-1\]\_s*' ..
          '\d\+ PUSHS ".txt"\_s*' ..
          '\d\+ EXECCONCAT 4\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 134,141 ****
          '\d EXEC   norm! m\[jjm\]\_s*' ..
          '  :''\[,''\]yank\_s*' ..
          '\d EXEC   :''\[,''\]yank\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 133,139 ----
          '\d EXEC   norm! m\[jjm\]\_s*' ..
          '  :''\[,''\]yank\_s*' ..
          '\d EXEC   :''\[,''\]yank\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 149,156 ****
          ' :3put ="text"\_s*' ..
          '\d PUSHS "text"\_s*' ..
          '\d PUT = 3\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 147,153 ----
          ' :3put ="text"\_s*' ..
          '\d PUSHS "text"\_s*' ..
          '\d PUT = 3\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 164,171 ****
          ' :$-2put a\_s*' ..
          '\d RANGE $-2\_s*' ..
          '\d PUT a range\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 161,167 ----
          ' :$-2put a\_s*' ..
          '\d RANGE $-2\_s*' ..
          '\d PUT a range\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 273,280 ****
          '\d\+ PUSHS "a"\_s*' ..
          '\d\+ LOAD $1\_s*' ..
          '\d\+ STOREDICT\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 269,275 ----
          '\d\+ PUSHS "a"\_s*' ..
          '\d\+ LOAD $1\_s*' ..
          '\d\+ STOREDICT\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 297,304 ****
          '\d LOAD $0\_s*' ..
          '\d MEMBER dd\_s*' ..
          '\d STOREINDEX\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 292,298 ----
          '\d LOAD $0\_s*' ..
          '\d MEMBER dd\_s*' ..
          '\d STOREINDEX\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 333,340 ****
          '\d\+ STORE $1\_s*' ..
          '\d\+ SLICE 2\_s*' ..
          '\d\+ STORE $2\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 327,333 ----
          '\d\+ STORE $1\_s*' ..
          '\d\+ SLICE 2\_s*' ..
          '\d\+ STORE $2\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 362,369 ****
          '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
          '\d\+ LISTAPPEND\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 355,361 ----
          '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
          '\d\+ LISTAPPEND\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 390,397 ****
          '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
          '\d\+ BLOBAPPEND\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 382,388 ----
          '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
          '\d\+ BLOBAPPEND\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 580,587 ****
          '\d LOAD arg\[-1\]\_s*' ..
          '\d CONCAT\_s*' ..
          '\d STOREOUTER $0\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  
    res = execute('disass g:Get')
--- 571,577 ----
          '\d LOAD arg\[-1\]\_s*' ..
          '\d CONCAT\_s*' ..
          '\d STOREOUTER $0\_s*' ..
!         '\d RETURN 0',
          res)
  
    res = execute('disass g:Get')
***************
*** 615,622 ****
          '\d PCALL top (argc 1)\_s*' ..
          '\d PCALL end\_s*' ..
          '\d DROP\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 605,611 ----
          '\d PCALL top (argc 1)\_s*' ..
          '\d PCALL end\_s*' ..
          '\d DROP\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 865,872 ****
          '\d PUSHS "UserFunc"\_s*' ..
          '\d BCALL funcref(argc 1)\_s*' ..
          '\d STORE $2\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          instr)
  enddef
  
--- 854,860 ----
          '\d PUSHS "UserFunc"\_s*' ..
          '\d BCALL funcref(argc 1)\_s*' ..
          '\d STORE $2\_s*' ..
!         '\d RETURN 0',
          instr)
  enddef
  
***************
*** 893,900 ****
          'var chan1: channel\_s*' ..
          '\d PUSHCHANNEL 0\_s*' ..
          '\d STORE $2\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          instr)
  enddef
  
--- 881,887 ----
          'var chan1: channel\_s*' ..
          '\d PUSHCHANNEL 0\_s*' ..
          '\d STORE $2\_s*' ..
!         '\d RETURN 0',
          instr)
  enddef
  
***************
*** 966,973 ****
          'echomsg "inner"\_s*' ..
          'enddef\_s*' ..
          '\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          instr)
  enddef
  
--- 953,959 ----
          'echomsg "inner"\_s*' ..
          'enddef\_s*' ..
          '\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
!         '\d RETURN 0',
          instr)
  enddef
  
***************
*** 989,996 ****
          '\d DEF /Info\_s*' ..
          'def /Info/\_s*' ..
          '\d DEF /Info/\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          instr)
  enddef
  
--- 975,981 ----
          '\d DEF /Info\_s*' ..
          'def /Info/\_s*' ..
          '\d DEF /Info/\_s*' ..
!         '\d RETURN 0',
          instr)
  enddef
  
***************
*** 1122,1129 ****
          'endfor\_s*' ..
          '\d\+ JUMP -> 8\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          instr)
  enddef
  
--- 1107,1113 ----
          'endfor\_s*' ..
          '\d\+ JUMP -> 8\_s*' ..
          '\d\+ DROP\_s*' ..
!         '\d\+ RETURN 0',
          instr)
  enddef
  
***************
*** 1143,1150 ****
          '\d NEWLIST size 2\_s*' ..
          '\d SETTYPE list<number>\_s*' ..
          '\d STORE $0\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN\_s*',
          instr)
  enddef
  
--- 1127,1133 ----
          '\d NEWLIST size 2\_s*' ..
          '\d SETTYPE list<number>\_s*' ..
          '\d STORE $0\_s*' ..
!         '\d RETURN 0\_s*',
          instr)
  enddef
  
***************
*** 1631,1638 ****
        'echo "" ?? "empty string"\_s*' ..
        '\d\+ PUSHS "empty string"\_s*' ..
        '\d\+ ECHO 1\_s*' ..
!       '\d\+ PUSHNR 0\_s*' ..
!       '\d\+ RETURN',
        res)
  enddef
  
--- 1614,1620 ----
        'echo "" ?? "empty string"\_s*' ..
        '\d\+ PUSHS "empty string"\_s*' ..
        '\d\+ ECHO 1\_s*' ..
!       '\d\+ RETURN 0',
        res)
  enddef
  
***************
*** 1659,1666 ****
            'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
            '\d PUSHNR 42.*' ..
            '\d ECHO 1.*' ..
!           '\d PUSHNR 0.*' ..
!           '\d RETURN.*',
            instr)
      else
        # condition false, function just returns
--- 1641,1647 ----
            'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
            '\d PUSHNR 42.*' ..
            '\d ECHO 1.*' ..
!           '\d RETURN 0',
            instr)
      else
        # condition false, function just returns
***************
*** 1668,1675 ****
            'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
            'echo 42[ \n]*' ..
            'endif[ \n]*' ..
!           '\s*\d PUSHNR 0.*' ..
!           '\d RETURN.*',
            instr)
      endif
  
--- 1649,1655 ----
            'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
            'echo 42[ \n]*' ..
            'endif[ \n]*' ..
!           '\d RETURN 0',
            instr)
      endif
  
***************
*** 1707,1714 ****
          '\d\+ LOAD $1\_s*' ..
          '\d\+ CONCAT\_s*' ..
          '\d\+ EXECUTE 1\_s*' ..
!         '\d\+ PUSHNR 0\_s*' ..
!         '\d\+ RETURN',
          res)
  enddef
  
--- 1687,1693 ----
          '\d\+ LOAD $1\_s*' ..
          '\d\+ CONCAT\_s*' ..
          '\d\+ EXECUTE 1\_s*' ..
!         '\d\+ RETURN 0',
          res)
  enddef
  
***************
*** 1727,1734 ****
          "echoerr 'went' .. 'wrong'\\_s*" ..
          '\d PUSHS "wentwrong"\_s*' ..
          '\d ECHOERR 1\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 1706,1712 ----
          "echoerr 'went' .. 'wrong'\\_s*" ..
          '\d PUSHS "wentwrong"\_s*' ..
          '\d ECHOERR 1\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 1837,1844 ****
          '\d SHUFFLE 2 up 1\_s*' ..
          '\d BCALL append(argc 2)\_s*' ..
          '\d DROP\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 1815,1821 ----
          '\d SHUFFLE 2 up 1\_s*' ..
          '\d BCALL append(argc 2)\_s*' ..
          '\d DROP\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
***************
*** 1861,1868 ****
          '\d PUSHS "error"\_s*' ..
          '\d ECHOERR 1\_s*' ..
          '\d CMDMOD_REV\_s*' ..
!         '\d PUSHNR 0\_s*' ..
!         '\d RETURN',
          res)
  enddef
  
--- 1838,1844 ----
          '\d PUSHS "error"\_s*' ..
          '\d ECHOERR 1\_s*' ..
          '\d CMDMOD_REV\_s*' ..
!         '\d RETURN 0',
          res)
  enddef
  
*** ../vim-8.2.2313/src/version.c       2021-01-08 20:40:41.958161849 +0100
--- src/version.c       2021-01-08 20:46:29.885343715 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2314,
  /**/

-- 
Nobody will ever need more than 640 kB RAM.
                -- Bill Gates, 1983
Windows 98 requires 16 MB RAM.
                -- Bill Gates, 1999
Logical conclusion: Nobody will ever need Windows 98.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202101081953.108JraDf951729%40masaka.moolenaar.net.

Raspunde prin e-mail lui