@@ -404,8 +404,8 @@ def to_a
404
404
def serialize ( insn )
405
405
case insn [ 0 ]
406
406
when :checkkeyword , :getblockparam , :getblockparamproxy ,
407
- :getlocal_WC_0 , :getlocal_WC_1 , :getlocal ,
408
- :setlocal_WC_0 , : setlocal_WC_1, :setlocal
407
+ :getlocal_WC_0 , :getlocal_WC_1 , :getlocal , :setlocal_WC_0 ,
408
+ :setlocal_WC_1 , :setlocal
409
409
iseq = self
410
410
411
411
case insn [ 0 ]
@@ -480,6 +480,11 @@ def branchif(index)
480
480
iseq . push ( [ :branchif , index ] )
481
481
end
482
482
483
+ def branchnil ( index )
484
+ stack . change_by ( -1 )
485
+ iseq . push ( [ :branchnil , index ] )
486
+ end
487
+
483
488
def branchunless ( index )
484
489
stack . change_by ( -1 )
485
490
iseq . push ( [ :branchunless , index ] )
@@ -1268,14 +1273,16 @@ def visit_bodystmt(node)
1268
1273
1269
1274
def visit_call ( node )
1270
1275
if node . is_a? ( CallNode )
1271
- return visit_call (
1272
- CommandCall . new (
1273
- receiver : node . receiver ,
1274
- operator : node . operator ,
1275
- message : node . message ,
1276
- arguments : node . arguments ,
1277
- block : nil ,
1278
- location : node . location
1276
+ return (
1277
+ visit_call (
1278
+ CommandCall . new (
1279
+ receiver : node . receiver ,
1280
+ operator : node . operator ,
1281
+ message : node . message ,
1282
+ arguments : node . arguments ,
1283
+ block : nil ,
1284
+ location : node . location
1285
+ )
1279
1286
)
1280
1287
)
1281
1288
end
@@ -1319,7 +1326,11 @@ def visit_call(node)
1319
1326
end
1320
1327
1321
1328
if node . receiver
1322
- if node . receiver . is_a? ( VarRef ) && ( lookup = current_iseq . local_variable ( node . receiver . value . value . to_sym ) ) && lookup . local . is_a? ( LocalTable ::BlockLocal )
1329
+ if node . receiver . is_a? ( VarRef ) &&
1330
+ (
1331
+ lookup =
1332
+ current_iseq . local_variable ( node . receiver . value . value . to_sym )
1333
+ ) && lookup . local . is_a? ( LocalTable ::BlockLocal )
1323
1334
builder . getblockparamproxy ( lookup . index , lookup . level )
1324
1335
else
1325
1336
visit ( node . receiver )
@@ -1328,6 +1339,12 @@ def visit_call(node)
1328
1339
builder . putself
1329
1340
end
1330
1341
1342
+ branchnil =
1343
+ if node . operator &.value == "&."
1344
+ builder . dup
1345
+ builder . branchnil ( -1 )
1346
+ end
1347
+
1331
1348
flag = 0
1332
1349
1333
1350
arg_parts . each do |arg_part |
@@ -1361,6 +1378,7 @@ def visit_call(node)
1361
1378
flag |= VM_CALL_FCALL if node . receiver . nil?
1362
1379
1363
1380
builder . send ( node . message . value . to_sym , argc , flag , block_iseq )
1381
+ branchnil [ 1 ] = builder . label if branchnil
1364
1382
end
1365
1383
1366
1384
def visit_case ( node )
@@ -1390,11 +1408,7 @@ def visit_case(node)
1390
1408
1391
1409
builder . pop
1392
1410
1393
- if else_clause
1394
- visit ( else_clause )
1395
- else
1396
- builder . putnil
1397
- end
1411
+ else_clause ? visit ( else_clause ) : builder . putnil
1398
1412
1399
1413
builder . leave
1400
1414
@@ -1701,7 +1715,12 @@ def visit_label(node)
1701
1715
1702
1716
def visit_lambda ( node )
1703
1717
lambda_iseq =
1704
- with_instruction_sequence ( :block , "block in #{ current_iseq . name } " , current_iseq , node ) do
1718
+ with_instruction_sequence (
1719
+ :block ,
1720
+ "block in #{ current_iseq . name } " ,
1721
+ current_iseq ,
1722
+ node
1723
+ ) do
1705
1724
visit ( node . params )
1706
1725
visit ( node . statements )
1707
1726
builder . leave
@@ -1746,9 +1765,7 @@ def visit_mlhs(node)
1746
1765
1747
1766
builder . expandarray ( lookups . length , 0 )
1748
1767
1749
- lookups . each do |lookup |
1750
- builder . setlocal ( lookup . index , lookup . level )
1751
- end
1768
+ lookups . each { |lookup | builder . setlocal ( lookup . index , lookup . level ) }
1752
1769
end
1753
1770
1754
1771
def visit_module ( node )
@@ -1944,10 +1961,14 @@ def visit_params(node)
1944
1961
if node . keyword_rest . is_a? ( ArgsForward )
1945
1962
current_iseq . local_table . plain ( :* )
1946
1963
current_iseq . local_table . plain ( :& )
1947
-
1948
- current_iseq . argument_options [ :rest_start ] = current_iseq . argument_size
1949
- current_iseq . argument_options [ :block_start ] = current_iseq . argument_size + 1
1950
-
1964
+
1965
+ current_iseq . argument_options [
1966
+ :rest_start
1967
+ ] = current_iseq . argument_size
1968
+ current_iseq . argument_options [
1969
+ :block_start
1970
+ ] = current_iseq . argument_size + 1
1971
+
1951
1972
current_iseq . argument_size += 2
1952
1973
elsif node . keyword_rest
1953
1974
visit ( node . keyword_rest )
@@ -2042,12 +2063,21 @@ def visit_sclass(node)
2042
2063
builder . putnil
2043
2064
2044
2065
singleton_iseq =
2045
- with_instruction_sequence ( :class , "singleton class" , current_iseq , node ) do
2066
+ with_instruction_sequence (
2067
+ :class ,
2068
+ "singleton class" ,
2069
+ current_iseq ,
2070
+ node
2071
+ ) do
2046
2072
visit ( node . bodystmt )
2047
2073
builder . leave
2048
2074
end
2049
2075
2050
- builder . defineclass ( :singletonclass , singleton_iseq , VM_DEFINECLASS_TYPE_SINGLETON_CLASS )
2076
+ builder . defineclass (
2077
+ :singletonclass ,
2078
+ singleton_iseq ,
2079
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS
2080
+ )
2051
2081
end
2052
2082
2053
2083
def visit_statements ( node )
0 commit comments