Skip to content

Commit

Permalink
Merge pull request #2216 from herwinw/constant_path_operator_write_stack
Browse files Browse the repository at this point in the history
Don't do a second ConstFindInstruction in ConstantPathOperatorNode
  • Loading branch information
herwinw committed Jul 24, 2024
2 parents cfd7967 + 393ac1c commit 7c412a8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/natalie/compiler/pass1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,6 @@ def transform_constant_path_operator_write_node(node, used:)
instructions = [
prep_instruction,
DupInstruction.new, # For the const_set
]
instructions << DupInstruction.new if used # For the return value
instructions.append(
ConstFindInstruction.new(name, strict: true),
transform_expression(node.value, used: true),
PushArgcInstruction.new(1),
Expand All @@ -1043,10 +1040,16 @@ def transform_constant_path_operator_write_node(node, used:)
file: @file.path,
line: node.location.start_line,
),
SwapInstruction.new,
ConstSetInstruction.new(name),
)
instructions << ConstFindInstruction.new(name, strict: true) if used
]
if used
instructions.append(
DupInstruction.new,
MoveRelInstruction.new(2),
)
else
instructions << SwapInstruction.new
end
instructions << ConstSetInstruction.new(name)
instructions
end

Expand Down

0 comments on commit 7c412a8

Please sign in to comment.