Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2115177

Browse files
committed
Fix opt table to use labels
1 parent f87fc56 commit 2115177

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

lib/syntax_tree/yarv/compiler.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,12 +1278,17 @@ def visit_params(node)
12781278
iseq.argument_size += 1
12791279

12801280
unless iseq.argument_options.key?(:opt)
1281-
iseq.argument_options[:opt] = [iseq.label_at_index]
1281+
start_label = iseq.label
1282+
iseq.push(start_label)
1283+
iseq.argument_options[:opt] = [start_label]
12821284
end
12831285

12841286
visit(value)
12851287
iseq.setlocal(index, 0)
1286-
iseq.argument_options[:opt] << iseq.label_at_index
1288+
1289+
arg_given_label = iseq.label
1290+
iseq.push(arg_given_label)
1291+
iseq.argument_options[:opt] << arg_given_label
12871292
end
12881293

12891294
visit(node.rest) if node.rest

lib/syntax_tree/yarv/instruction_sequence.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ def to_a
235235
end
236236
end
237237

238+
dumped_options = argument_options.dup
239+
dumped_options[:opt].map!(&:name) if dumped_options[:opt]
240+
238241
# Next, return the instruction sequence as an array.
239242
[
240243
MAGIC,
@@ -252,7 +255,7 @@ def to_a
252255
location.start_line,
253256
type,
254257
local_table.names,
255-
argument_options,
258+
dumped_options,
256259
[],
257260
dumped
258261
]
@@ -308,10 +311,6 @@ def push(insn)
308311
end
309312
end
310313

311-
def label_at_index
312-
push(:"label_#{length}")
313-
end
314-
315314
def event(name)
316315
push(name)
317316
end
@@ -767,6 +766,11 @@ def toregexp(options, length)
767766
def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
768767
iseq = new(source[9], source[5], parent_iseq, Location.default, options)
769768

769+
# set up the labels object so that the labels are shared between the
770+
# location in the instruction sequence and the instructions that
771+
# reference them
772+
labels = Hash.new { |hash, name| hash[name] = Label.new(name) }
773+
770774
# set up the correct argument size
771775
iseq.argument_size = source[4][:arg_size]
772776

@@ -775,11 +779,9 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
775779

776780
# set up the argument options
777781
iseq.argument_options.merge!(source[11])
778-
779-
# set up the labels object so that the labels are shared between the
780-
# location in the instruction sequence and the instructions that
781-
# reference them
782-
labels = Hash.new { |hash, name| hash[name] = Label.new(name) }
782+
if iseq.argument_options[:opt]
783+
iseq.argument_options[:opt].map! { |opt| labels[opt] }
784+
end
783785

784786
# set up all of the instructions
785787
source[13].each do |insn|

0 commit comments

Comments
 (0)