@@ -417,7 +417,8 @@ def visit_aryptn(node)
417
417
# First, check if the #deconstruct cache is nil. If it is, we're going
418
418
# to call #deconstruct on the object and cache the result.
419
419
iseq . topn ( 2 )
420
- branchnil = iseq . branchnil ( -1 )
420
+ deconstruct_label = iseq . label
421
+ iseq . branchnil ( deconstruct_label )
421
422
422
423
# Next, ensure that the cached value was cached correctly, otherwise
423
424
# fail the match.
@@ -432,7 +433,7 @@ def visit_aryptn(node)
432
433
433
434
# Check if the object responds to #deconstruct, fail the match
434
435
# otherwise.
435
- branchnil . patch! ( iseq )
436
+ iseq . event ( deconstruct_label )
436
437
iseq . dup
437
438
iseq . putobject ( :deconstruct )
438
439
iseq . send ( YARV . calldata ( :respond_to? , 1 ) )
@@ -634,11 +635,12 @@ def visit_binary(node)
634
635
visit ( node . left )
635
636
iseq . dup
636
637
637
- branchif = iseq . branchif ( -1 )
638
+ skip_right_label = iseq . label
639
+ iseq . branchif ( skip_right_label )
638
640
iseq . pop
639
641
640
642
visit ( node . right )
641
- branchif . patch! ( iseq )
643
+ iseq . push ( skip_right_label )
642
644
else
643
645
visit ( node . left )
644
646
visit ( node . right )
@@ -758,11 +760,12 @@ def visit_call(node)
758
760
iseq . putself
759
761
end
760
762
761
- branchnil =
762
- if node . operator &.value == "&."
763
- iseq . dup
764
- iseq . branchnil ( -1 )
765
- end
763
+ after_call_label = nil
764
+ if node . operator &.value == "&."
765
+ iseq . dup
766
+ after_call_label = iseq . label
767
+ iseq . branchnil ( after_call_label )
768
+ end
766
769
767
770
flag = 0
768
771
@@ -815,7 +818,7 @@ def visit_call(node)
815
818
YARV . calldata ( node . message . value . to_sym , argc , flag ) ,
816
819
block_iseq
817
820
)
818
- branchnil . patch! ( iseq ) if branchnil
821
+ iseq . event ( after_call_label ) if after_call_label
819
822
end
820
823
821
824
def visit_case ( node )
@@ -845,16 +848,19 @@ def visit_case(node)
845
848
CallData ::CALL_FCALL | CallData ::CALL_ARGS_SIMPLE
846
849
)
847
850
)
848
- [ clause , iseq . branchif ( :label_00 ) ]
851
+
852
+ label = iseq . label
853
+ iseq . branchif ( label )
854
+ [ clause , label ]
849
855
end
850
856
851
857
iseq . pop
852
858
else_clause ? visit ( else_clause ) : iseq . putnil
853
859
iseq . leave
854
860
855
- branches . each_with_index do |( clause , branchif ) , index |
861
+ branches . each_with_index do |( clause , label ) , index |
856
862
iseq . leave if index != 0
857
- branchif . patch! ( iseq )
863
+ iseq . push ( label )
858
864
iseq . pop
859
865
visit ( clause )
860
866
end
@@ -1100,26 +1106,28 @@ def visit_heredoc(node)
1100
1106
1101
1107
def visit_if ( node )
1102
1108
if node . predicate . is_a? ( RangeNode )
1109
+ true_label = iseq . label
1110
+
1103
1111
iseq . getspecial ( GetSpecial ::SVAR_FLIPFLOP_START , 0 )
1104
- branchif = iseq . branchif ( - 1 )
1112
+ iseq . branchif ( true_label )
1105
1113
1106
1114
visit ( node . predicate . left )
1107
- branchunless_true = iseq . branchunless ( -1 )
1115
+ end_branch = iseq . branchunless ( -1 )
1108
1116
1109
1117
iseq . putobject ( true )
1110
1118
iseq . setspecial ( GetSpecial ::SVAR_FLIPFLOP_START )
1111
- branchif . patch! ( iseq )
1112
1119
1120
+ iseq . push ( true_label )
1113
1121
visit ( node . predicate . right )
1114
- branchunless_false = iseq . branchunless ( -1 )
1122
+ false_branch = iseq . branchunless ( -1 )
1115
1123
1116
1124
iseq . putobject ( false )
1117
1125
iseq . setspecial ( GetSpecial ::SVAR_FLIPFLOP_START )
1118
- branchunless_false . patch! ( iseq )
1119
1126
1127
+ false_branch . patch! ( iseq )
1120
1128
visit ( node . statements )
1121
1129
iseq . leave
1122
- branchunless_true . patch! ( iseq )
1130
+ end_branch . patch! ( iseq )
1123
1131
iseq . putnil
1124
1132
else
1125
1133
visit ( node . predicate )
@@ -1317,22 +1325,22 @@ def visit_opassign(node)
1317
1325
[ Const , CVar , GVar ] . include? ( node . target . value . class )
1318
1326
opassign_defined ( node )
1319
1327
else
1320
- branchif = nil
1328
+ skip_value_label = iseq . label
1321
1329
1322
1330
with_opassign ( node ) do
1323
1331
iseq . dup
1324
- branchif = iseq . branchif ( - 1 )
1332
+ iseq . branchif ( skip_value_label )
1325
1333
iseq . pop
1326
1334
visit ( node . value )
1327
1335
end
1328
1336
1329
1337
if node . target . is_a? ( ARefField )
1330
1338
iseq . leave
1331
- branchif . patch! ( iseq )
1339
+ iseq . push ( skip_value_label )
1332
1340
iseq . setn ( 3 )
1333
1341
iseq . adjuststack ( 3 )
1334
1342
else
1335
- branchif . patch! ( iseq )
1343
+ iseq . push ( skip_value_label )
1336
1344
end
1337
1345
end
1338
1346
else
@@ -1363,13 +1371,11 @@ def visit_params(node)
1363
1371
iseq . local_table . plain ( name )
1364
1372
iseq . argument_size += 1
1365
1373
1366
- argument_options [ :opt ] = [ iseq . label ] unless argument_options . key? (
1367
- :opt
1368
- )
1374
+ argument_options [ :opt ] = [ iseq . label_at_index ] unless argument_options . key? ( :opt )
1369
1375
1370
1376
visit ( value )
1371
1377
iseq . setlocal ( index , 0 )
1372
- iseq . argument_options [ :opt ] << iseq . label
1378
+ iseq . argument_options [ :opt ] << iseq . label_at_index
1373
1379
end
1374
1380
1375
1381
visit ( node . rest ) if node . rest
@@ -1406,12 +1412,14 @@ def visit_params(node)
1406
1412
elsif ( compiled = RubyVisitor . compile ( value ) )
1407
1413
argument_options [ :keyword ] << [ name , compiled ]
1408
1414
else
1415
+ skip_value_label = iseq . label
1416
+
1409
1417
argument_options [ :keyword ] << [ name ]
1410
1418
iseq . checkkeyword ( keyword_bits_index , keyword_index )
1411
- branchif = iseq . branchif ( - 1 )
1419
+ iseq . branchif ( skip_value_label )
1412
1420
visit ( value )
1413
1421
iseq . setlocal ( index , 0 )
1414
- branchif . patch! ( iseq )
1422
+ iseq . push ( skip_value_label )
1415
1423
end
1416
1424
end
1417
1425
@@ -1558,13 +1566,15 @@ def visit_rassign(node)
1558
1566
jumps_to_match . concat ( visit ( node . pattern ) )
1559
1567
end
1560
1568
1569
+ no_key_label = iseq . label
1570
+
1561
1571
# First we're going to push the core onto the stack, then we'll check
1562
1572
# if the value to match is truthy. If it is, we'll jump down to raise
1563
1573
# NoMatchingPatternKeyError. Otherwise we'll raise
1564
1574
# NoMatchingPatternError.
1565
1575
iseq . putspecialobject ( PutSpecialObject ::OBJECT_VMCORE )
1566
1576
iseq . topn ( 4 )
1567
- branchif_no_key = iseq . branchif ( - 1 )
1577
+ iseq . branchif ( no_key_label )
1568
1578
1569
1579
# Here we're going to raise NoMatchingPatternError.
1570
1580
iseq . putobject ( NoMatchingPatternError )
@@ -1577,7 +1587,7 @@ def visit_rassign(node)
1577
1587
jump_to_exit = iseq . jump ( -1 )
1578
1588
1579
1589
# Here we're going to raise NoMatchingPatternKeyError.
1580
- branchif_no_key . patch! ( iseq )
1590
+ iseq . push ( no_key_label )
1581
1591
iseq . putobject ( NoMatchingPatternKeyError )
1582
1592
iseq . putspecialobject ( PutSpecialObject ::OBJECT_VMCORE )
1583
1593
iseq . putobject ( "%p: %s" )
@@ -1797,7 +1807,7 @@ def visit_unless(node)
1797
1807
jump = iseq . jump ( -1 )
1798
1808
branchunless . patch! ( iseq )
1799
1809
visit ( node . consequent )
1800
- jump . patch! ( iseq . label )
1810
+ jump . patch! ( iseq . label_at_index )
1801
1811
else
1802
1812
branchunless . patch! ( iseq )
1803
1813
end
@@ -1812,7 +1822,7 @@ def visit_until(node)
1812
1822
iseq . pop
1813
1823
jumps << iseq . jump ( -1 )
1814
1824
1815
- label = iseq . label
1825
+ label = iseq . label_at_index
1816
1826
visit ( node . statements )
1817
1827
iseq . pop
1818
1828
jumps . each { |jump | jump . patch! ( iseq ) }
@@ -1891,20 +1901,21 @@ def visit_when(node)
1891
1901
end
1892
1902
1893
1903
def visit_while ( node )
1904
+ repeat_label = iseq . label
1894
1905
jumps = [ ]
1895
1906
1896
1907
jumps << iseq . jump ( -1 )
1897
1908
iseq . putnil
1898
1909
iseq . pop
1899
1910
jumps << iseq . jump ( -1 )
1900
1911
1901
- label = iseq . label
1912
+ iseq . push ( repeat_label )
1902
1913
visit ( node . statements )
1903
1914
iseq . pop
1904
1915
jumps . each { |jump | jump . patch! ( iseq ) }
1905
1916
1906
1917
visit ( node . predicate )
1907
- iseq . branchif ( label )
1918
+ iseq . branchif ( repeat_label )
1908
1919
iseq . putnil if last_statement?
1909
1920
end
1910
1921
@@ -2060,7 +2071,8 @@ def opassign_defined(node)
2060
2071
end
2061
2072
2062
2073
iseq . dup
2063
- branchif = iseq . branchif ( -1 )
2074
+ skip_value_label = iseq . label
2075
+ iseq . branchif ( skip_value_label )
2064
2076
iseq . pop
2065
2077
2066
2078
branchunless . patch! ( iseq )
@@ -2085,7 +2097,7 @@ def opassign_defined(node)
2085
2097
end
2086
2098
end
2087
2099
2088
- branchif . patch! ( iseq )
2100
+ iseq . push ( skip_value_label )
2089
2101
end
2090
2102
2091
2103
# Whenever a value is interpolated into a string-like structure, these
0 commit comments