Skip to content

Commit

Permalink
Support global variable target in for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Jun 23, 2024
1 parent f323e7f commit ae5ea19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/natalie/compiler/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def transform_arg(arg)
transform_instance_variable_arg(arg)
when ::Prism::ClassVariableTargetNode
transform_class_variable_arg(arg)
when ::Prism::GlobalVariableTargetNode
transform_global_variable_arg(arg)
when ::Prism::ConstantTargetNode
transform_constant_arg(arg)
when ::Prism::RequiredParameterNode
Expand Down Expand Up @@ -174,6 +176,11 @@ def transform_class_variable_arg(arg)
@instructions << ClassVariableSetInstruction.new(arg.name)
end

def transform_global_variable_arg(arg)
@instructions << ArrayShiftInstruction.new
@instructions << GlobalVariableSetInstruction.new(arg.name)
end

def transform_constant_arg(arg)
@instructions << ArrayShiftInstruction.new
@instructions << PushSelfInstruction.new
Expand Down
1 change: 1 addition & 0 deletions lib/natalie/compiler/pass1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,7 @@ def maximum_arg_count(args)
%i[
class_variable_target_node
constant_target_node
global_variable_target_node
instance_variable_target_node
local_variable_target_node
multi_target_node
Expand Down

0 comments on commit ae5ea19

Please sign in to comment.