@@ -225,14 +225,17 @@ def visit_CHAR(node)
225
225
end
226
226
227
227
def visit_END ( node )
228
- name = "block in #{ iseq . name } "
229
228
once_iseq =
230
- with_instruction_sequence ( :block , name , node ) do
229
+ with_child_iseq ( iseq . block_child_iseq ( node . location ) ) do
231
230
postexe_iseq =
232
- with_instruction_sequence ( :block , name , node ) do
231
+ with_child_iseq ( iseq . block_child_iseq ( node . location ) ) do
232
+ iseq . event ( :RUBY_EVENT_B_CALL )
233
+
233
234
*statements , last_statement = node . statements . body
234
235
visit_all ( statements )
235
236
with_last_statement { visit ( last_statement ) }
237
+
238
+ iseq . event ( :RUBY_EVENT_B_RETURN )
236
239
iseq . leave
237
240
end
238
241
@@ -422,7 +425,7 @@ def visit_binary(node)
422
425
end
423
426
424
427
def visit_block ( node )
425
- with_instruction_sequence ( :block , "block in #{ iseq . name } " , node ) do
428
+ with_child_iseq ( iseq . block_child_iseq ( node . location ) ) do
426
429
iseq . event ( :RUBY_EVENT_B_CALL )
427
430
visit ( node . block_var )
428
431
visit ( node . bodystmt )
@@ -606,7 +609,7 @@ def visit_case(node)
606
609
def visit_class ( node )
607
610
name = node . constant . constant . value . to_sym
608
611
class_iseq =
609
- with_instruction_sequence ( :class , "<class: #{ name } >" , node ) do
612
+ with_child_iseq ( iseq . class_child_iseq ( name , node . location ) ) do
610
613
iseq . event ( :RUBY_EVENT_CLASS )
611
614
visit ( node . bodystmt )
612
615
iseq . event ( :RUBY_EVENT_END )
@@ -673,7 +676,7 @@ def visit_const_path_ref(node)
673
676
674
677
def visit_def ( node )
675
678
method_iseq =
676
- with_instruction_sequence ( :method , node . name . value , node ) do
679
+ with_child_iseq ( iseq . method_child_iseq ( node . name . value , node . location ) ) do
677
680
visit ( node . params ) if node . params
678
681
iseq . event ( :RUBY_EVENT_CALL )
679
682
visit ( node . bodystmt )
@@ -788,11 +791,7 @@ def visit_for(node)
788
791
iseq . local_table . plain ( name )
789
792
790
793
block_iseq =
791
- with_instruction_sequence (
792
- :block ,
793
- "block in #{ iseq . name } " ,
794
- node . statements
795
- ) do
794
+ with_child_iseq ( iseq . block_child_iseq ( node . statements . location ) ) do
796
795
iseq . argument_options [ :lead_num ] ||= 0
797
796
iseq . argument_options [ :lead_num ] += 1
798
797
iseq . argument_options [ :ambiguous_param0 ] = true
@@ -896,7 +895,7 @@ def visit_label(node)
896
895
897
896
def visit_lambda ( node )
898
897
lambda_iseq =
899
- with_instruction_sequence ( :block , "block in #{ iseq . name } " , node ) do
898
+ with_child_iseq ( iseq . block_child_iseq ( node . location ) ) do
900
899
iseq . event ( :RUBY_EVENT_B_CALL )
901
900
visit ( node . params )
902
901
visit ( node . statements )
@@ -947,7 +946,7 @@ def visit_mlhs(node)
947
946
def visit_module ( node )
948
947
name = node . constant . constant . value . to_sym
949
948
module_iseq =
950
- with_instruction_sequence ( :class , "<module: #{ name } >" , node ) do
949
+ with_child_iseq ( iseq . module_child_iseq ( name , node . location ) ) do
951
950
iseq . event ( :RUBY_EVENT_CLASS )
952
951
visit ( node . bodystmt )
953
952
iseq . event ( :RUBY_EVENT_END )
@@ -1168,7 +1167,18 @@ def visit_program(node)
1168
1167
end
1169
1168
end
1170
1169
1171
- with_instruction_sequence ( :top , "<compiled>" , node ) do
1170
+ top_iseq =
1171
+ YARV ::InstructionSequence . new (
1172
+ :top ,
1173
+ "<compiled>" ,
1174
+ nil ,
1175
+ node . location ,
1176
+ frozen_string_literal : frozen_string_literal ,
1177
+ operands_unification : operands_unification ,
1178
+ specialized_instruction : specialized_instruction
1179
+ )
1180
+
1181
+ with_child_iseq ( top_iseq ) do
1172
1182
visit_all ( preexes )
1173
1183
1174
1184
if statements . empty?
@@ -1231,7 +1241,7 @@ def visit_sclass(node)
1231
1241
iseq . putnil
1232
1242
1233
1243
singleton_iseq =
1234
- with_instruction_sequence ( :class , "singleton class" , node ) do
1244
+ with_child_iseq ( iseq . singleton_class_child_iseq ( node . location ) ) do
1235
1245
iseq . event ( :RUBY_EVENT_CLASS )
1236
1246
visit ( node . bodystmt )
1237
1247
iseq . event ( :RUBY_EVENT_END )
@@ -1702,24 +1712,13 @@ def visit_string_parts(node)
1702
1712
# on the compiler. When we descend into a node that has its own
1703
1713
# instruction sequence, this method can be called to temporarily set the
1704
1714
# new value of the instruction sequence, yield, and then set it back.
1705
- def with_instruction_sequence ( type , name , node )
1715
+ def with_child_iseq ( child_iseq )
1706
1716
parent_iseq = iseq
1707
1717
1708
1718
begin
1709
- iseq =
1710
- YARV ::InstructionSequence . new (
1711
- type ,
1712
- name ,
1713
- parent_iseq ,
1714
- node . location ,
1715
- frozen_string_literal : frozen_string_literal ,
1716
- operands_unification : operands_unification ,
1717
- specialized_instruction : specialized_instruction
1718
- )
1719
-
1720
- @iseq = iseq
1719
+ @iseq = child_iseq
1721
1720
yield
1722
- iseq
1721
+ child_iseq
1723
1722
ensure
1724
1723
@iseq = parent_iseq
1725
1724
end
0 commit comments