Skip to content

Commit 299f303

Browse files
committed
patch 8.2.2314: Vim9: returning zero takes two instructions
Problem: Vim9: returning zero takes two instructions. Solution: Add ISN_RETURN_ZERO.
1 parent ece0b87 commit 299f303

5 files changed

Lines changed: 42 additions & 50 deletions

File tree

src/testdir/test_vim9_disassemble.vim

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def Test_disassemble_exec_expr()
117117
'\d 2STRING stack\[-1\]\_s*' ..
118118
'\d\+ PUSHS ".txt"\_s*' ..
119119
'\d\+ EXECCONCAT 4\_s*' ..
120-
'\d\+ PUSHNR 0\_s*' ..
121-
'\d\+ RETURN',
120+
'\d\+ RETURN 0',
122121
res)
123122
enddef
124123

@@ -134,8 +133,7 @@ def Test_disassemble_yank_range()
134133
'\d EXEC norm! m\[jjm\]\_s*' ..
135134
' :''\[,''\]yank\_s*' ..
136135
'\d EXEC :''\[,''\]yank\_s*' ..
137-
'\d PUSHNR 0\_s*' ..
138-
'\d RETURN',
136+
'\d RETURN 0',
139137
res)
140138
enddef
141139

@@ -149,8 +147,7 @@ def Test_disassemble_put_expr()
149147
' :3put ="text"\_s*' ..
150148
'\d PUSHS "text"\_s*' ..
151149
'\d PUT = 3\_s*' ..
152-
'\d PUSHNR 0\_s*' ..
153-
'\d RETURN',
150+
'\d RETURN 0',
154151
res)
155152
enddef
156153

@@ -164,8 +161,7 @@ def Test_disassemble_put_range()
164161
' :$-2put a\_s*' ..
165162
'\d RANGE $-2\_s*' ..
166163
'\d PUT a range\_s*' ..
167-
'\d PUSHNR 0\_s*' ..
168-
'\d RETURN',
164+
'\d RETURN 0',
169165
res)
170166
enddef
171167

@@ -273,8 +269,7 @@ def Test_disassemble_store_member()
273269
'\d\+ PUSHS "a"\_s*' ..
274270
'\d\+ LOAD $1\_s*' ..
275271
'\d\+ STOREDICT\_s*' ..
276-
'\d\+ PUSHNR 0\_s*' ..
277-
'\d\+ RETURN',
272+
'\d\+ RETURN 0',
278273
res)
279274
enddef
280275

@@ -297,8 +292,7 @@ def Test_disassemble_store_index()
297292
'\d LOAD $0\_s*' ..
298293
'\d MEMBER dd\_s*' ..
299294
'\d STOREINDEX\_s*' ..
300-
'\d\+ PUSHNR 0\_s*' ..
301-
'\d\+ RETURN',
295+
'\d\+ RETURN 0',
302296
res)
303297
enddef
304298

@@ -333,8 +327,7 @@ def Test_disassemble_list_assign()
333327
'\d\+ STORE $1\_s*' ..
334328
'\d\+ SLICE 2\_s*' ..
335329
'\d\+ STORE $2\_s*' ..
336-
'\d\+ PUSHNR 0\_s*' ..
337-
'\d\+ RETURN',
330+
'\d\+ RETURN 0',
338331
res)
339332
enddef
340333

@@ -362,8 +355,7 @@ def Test_disassemble_list_add()
362355
'\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
363356
'\d\+ LISTAPPEND\_s*' ..
364357
'\d\+ DROP\_s*' ..
365-
'\d\+ PUSHNR 0\_s*' ..
366-
'\d\+ RETURN',
358+
'\d\+ RETURN 0',
367359
res)
368360
enddef
369361

@@ -390,8 +382,7 @@ def Test_disassemble_blob_add()
390382
'\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
391383
'\d\+ BLOBAPPEND\_s*' ..
392384
'\d\+ DROP\_s*' ..
393-
'\d\+ PUSHNR 0\_s*' ..
394-
'\d\+ RETURN',
385+
'\d\+ RETURN 0',
395386
res)
396387
enddef
397388

@@ -580,8 +571,7 @@ def Test_disassemble_closure()
580571
'\d LOAD arg\[-1\]\_s*' ..
581572
'\d CONCAT\_s*' ..
582573
'\d STOREOUTER $0\_s*' ..
583-
'\d PUSHNR 0\_s*' ..
584-
'\d RETURN',
574+
'\d RETURN 0',
585575
res)
586576

587577
res = execute('disass g:Get')
@@ -615,8 +605,7 @@ def Test_disassemble_pcall()
615605
'\d PCALL top (argc 1)\_s*' ..
616606
'\d PCALL end\_s*' ..
617607
'\d DROP\_s*' ..
618-
'\d PUSHNR 0\_s*' ..
619-
'\d RETURN',
608+
'\d RETURN 0',
620609
res)
621610
enddef
622611

@@ -865,8 +854,7 @@ def Test_disassemble_function()
865854
'\d PUSHS "UserFunc"\_s*' ..
866855
'\d BCALL funcref(argc 1)\_s*' ..
867856
'\d STORE $2\_s*' ..
868-
'\d PUSHNR 0\_s*' ..
869-
'\d RETURN',
857+
'\d RETURN 0',
870858
instr)
871859
enddef
872860

@@ -893,8 +881,7 @@ def Test_disassemble_channel()
893881
'var chan1: channel\_s*' ..
894882
'\d PUSHCHANNEL 0\_s*' ..
895883
'\d STORE $2\_s*' ..
896-
'\d PUSHNR 0\_s*' ..
897-
'\d RETURN',
884+
'\d RETURN 0',
898885
instr)
899886
enddef
900887

@@ -966,8 +953,7 @@ def Test_nested_func()
966953
'echomsg "inner"\_s*' ..
967954
'enddef\_s*' ..
968955
'\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
969-
'\d PUSHNR 0\_s*' ..
970-
'\d RETURN',
956+
'\d RETURN 0',
971957
instr)
972958
enddef
973959

@@ -989,8 +975,7 @@ def Test_nested_def_list()
989975
'\d DEF /Info\_s*' ..
990976
'def /Info/\_s*' ..
991977
'\d DEF /Info/\_s*' ..
992-
'\d PUSHNR 0\_s*' ..
993-
'\d RETURN',
978+
'\d RETURN 0',
994979
instr)
995980
enddef
996981

@@ -1122,8 +1107,7 @@ def Test_disassemble_for_loop_unpack()
11221107
'endfor\_s*' ..
11231108
'\d\+ JUMP -> 8\_s*' ..
11241109
'\d\+ DROP\_s*' ..
1125-
'\d\+ PUSHNR 0\_s*' ..
1126-
'\d\+ RETURN',
1110+
'\d\+ RETURN 0',
11271111
instr)
11281112
enddef
11291113

@@ -1143,8 +1127,7 @@ def Test_disassemble_typecast()
11431127
'\d NEWLIST size 2\_s*' ..
11441128
'\d SETTYPE list<number>\_s*' ..
11451129
'\d STORE $0\_s*' ..
1146-
'\d PUSHNR 0\_s*' ..
1147-
'\d RETURN\_s*',
1130+
'\d RETURN 0\_s*',
11481131
instr)
11491132
enddef
11501133

@@ -1631,8 +1614,7 @@ def Test_dsassemble_falsy_op()
16311614
'echo "" ?? "empty string"\_s*' ..
16321615
'\d\+ PUSHS "empty string"\_s*' ..
16331616
'\d\+ ECHO 1\_s*' ..
1634-
'\d\+ PUSHNR 0\_s*' ..
1635-
'\d\+ RETURN',
1617+
'\d\+ RETURN 0',
16361618
res)
16371619
enddef
16381620

@@ -1659,17 +1641,15 @@ def Test_disassemble_compare_const()
16591641
'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
16601642
'\d PUSHNR 42.*' ..
16611643
'\d ECHO 1.*' ..
1662-
'\d PUSHNR 0.*' ..
1663-
'\d RETURN.*',
1644+
'\d RETURN 0',
16641645
instr)
16651646
else
16661647
# condition false, function just returns
16671648
assert_match('TestCase' .. nr .. '.*' ..
16681649
'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
16691650
'echo 42[ \n]*' ..
16701651
'endif[ \n]*' ..
1671-
'\s*\d PUSHNR 0.*' ..
1672-
'\d RETURN.*',
1652+
'\d RETURN 0',
16731653
instr)
16741654
endif
16751655

@@ -1707,8 +1687,7 @@ def Test_disassemble_execute()
17071687
'\d\+ LOAD $1\_s*' ..
17081688
'\d\+ CONCAT\_s*' ..
17091689
'\d\+ EXECUTE 1\_s*' ..
1710-
'\d\+ PUSHNR 0\_s*' ..
1711-
'\d\+ RETURN',
1690+
'\d\+ RETURN 0',
17121691
res)
17131692
enddef
17141693

@@ -1727,8 +1706,7 @@ def Test_disassemble_echomsg()
17271706
"echoerr 'went' .. 'wrong'\\_s*" ..
17281707
'\d PUSHS "wentwrong"\_s*' ..
17291708
'\d ECHOERR 1\_s*' ..
1730-
'\d PUSHNR 0\_s*' ..
1731-
'\d RETURN',
1709+
'\d RETURN 0',
17321710
res)
17331711
enddef
17341712

@@ -1837,8 +1815,7 @@ def Test_shuffle()
18371815
'\d SHUFFLE 2 up 1\_s*' ..
18381816
'\d BCALL append(argc 2)\_s*' ..
18391817
'\d DROP\_s*' ..
1840-
'\d PUSHNR 0\_s*' ..
1841-
'\d RETURN',
1818+
'\d RETURN 0',
18421819
res)
18431820
enddef
18441821

@@ -1861,8 +1838,7 @@ def Test_silent()
18611838
'\d PUSHS "error"\_s*' ..
18621839
'\d ECHOERR 1\_s*' ..
18631840
'\d CMDMOD_REV\_s*' ..
1864-
'\d PUSHNR 0\_s*' ..
1865-
'\d RETURN',
1841+
'\d RETURN 0',
18661842
res)
18671843
enddef
18681844

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2314,
753755
/**/
754756
2313,
755757
/**/

src/vim9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef enum {
8484
ISN_PCALL, // call partial, use isn_arg.pfunc
8585
ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
8686
ISN_RETURN, // return, result is on top of stack
87+
ISN_RETURN_ZERO, // Push zero, then return
8788
ISN_FUNCREF, // push a function ref to dfunc isn_arg.funcref
8889
ISN_NEWFUNC, // create a global function from a lambda function
8990
ISN_DEF, // list functions

src/vim9compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8190,8 +8190,7 @@ compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx)
81908190
}
81918191

81928192
// Return zero if there is no return at the end.
8193-
generate_PUSHNR(&cctx, 0);
8194-
generate_instr(&cctx, ISN_RETURN);
8193+
generate_instr(&cctx, ISN_RETURN_ZERO);
81958194
}
81968195

81978196
{
@@ -8483,6 +8482,7 @@ delete_instr(isn_T *isn)
84838482
case ISN_PUSHSPEC:
84848483
case ISN_PUT:
84858484
case ISN_RETURN:
8485+
case ISN_RETURN_ZERO:
84868486
case ISN_SHUFFLE:
84878487
case ISN_SLICE:
84888488
case ISN_STORE:

src/vim9execute.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,16 @@ call_def_function(
22052205
break;
22062206

22072207
// return from a :def function call
2208+
case ISN_RETURN_ZERO:
2209+
if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
2210+
goto failed;
2211+
tv = STACK_TV_BOT(0);
2212+
++ectx.ec_stack.ga_len;
2213+
tv->v_type = VAR_NUMBER;
2214+
tv->vval.v_number = 0;
2215+
tv->v_lock = 0;
2216+
// FALLTHROUGH
2217+
22082218
case ISN_RETURN:
22092219
{
22102220
garray_T *trystack = &ectx.ec_trystack;
@@ -3804,6 +3814,9 @@ ex_disassemble(exarg_T *eap)
38043814
case ISN_RETURN:
38053815
smsg("%4d RETURN", current);
38063816
break;
3817+
case ISN_RETURN_ZERO:
3818+
smsg("%4d RETURN 0", current);
3819+
break;
38073820
case ISN_FUNCREF:
38083821
{
38093822
funcref_T *funcref = &iptr->isn_arg.funcref;

0 commit comments

Comments
 (0)