Fix ruby receiver to vool
for chained calls to be normalized correctly
This commit is contained in:
parent
c213cf874b
commit
dee1e24c28
@ -44,13 +44,10 @@ module Ruby
|
|||||||
"self"
|
"self"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SuperExpression < Statement
|
class SuperExpression < Constant
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"super"
|
"super"
|
||||||
end
|
end
|
||||||
def to_vool
|
|
||||||
vool_brother.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class StringConstant < ValueConstant
|
class StringConstant < ValueConstant
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
@ -20,14 +20,15 @@ module Ruby
|
|||||||
# we "normalize" or flatten any complex argument expressions into a list
|
# we "normalize" or flatten any complex argument expressions into a list
|
||||||
def to_vool
|
def to_vool
|
||||||
statements = Vool::Statements.new([])
|
statements = Vool::Statements.new([])
|
||||||
|
receiver = normalize_arg(@receiver , statements)
|
||||||
arguments = []
|
arguments = []
|
||||||
@arguments.each_with_index do |arg , index |
|
@arguments.each_with_index do |arg , index |
|
||||||
normalize_arg(arg , arguments , statements)
|
arguments << normalize_arg(arg , statements)
|
||||||
end
|
end
|
||||||
if statements.empty?
|
if statements.empty?
|
||||||
return vool_brother.new(@name, @receiver.to_vool , arguments)
|
return vool_brother.new(@name, receiver , arguments)
|
||||||
else
|
else
|
||||||
statements << vool_brother.new(@name, @receiver.to_vool , arguments)
|
statements << vool_brother.new(@name, receiver , arguments)
|
||||||
return statements
|
return statements
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -36,11 +37,10 @@ module Ruby
|
|||||||
# we create a tmp variable and assign to that, hoising all the calls.
|
# we create a tmp variable and assign to that, hoising all the calls.
|
||||||
# the effect is of walking the call tree now,
|
# the effect is of walking the call tree now,
|
||||||
# rather than using a stack to do that at runtime
|
# rather than using a stack to do that at runtime
|
||||||
def normalize_arg(arg , arguments , statements)
|
def normalize_arg(arg , statements)
|
||||||
vool_arg = arg.to_vool
|
vool_arg = arg.to_vool
|
||||||
if arg.is_a?(Constant)
|
if arg.is_a?(Constant)
|
||||||
arguments << vool_arg
|
return vool_arg
|
||||||
return
|
|
||||||
end
|
end
|
||||||
if( vool_arg.is_a?(Vool::Statements))
|
if( vool_arg.is_a?(Vool::Statements))
|
||||||
while(vool_arg.length > 1)
|
while(vool_arg.length > 1)
|
||||||
@ -50,7 +50,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, vool_arg)
|
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, vool_arg)
|
||||||
statements << assign
|
statements << assign
|
||||||
arguments << Vool::LocalVariable.new(assign.name)
|
return Vool::LocalVariable.new(assign.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,8 @@ module Vool
|
|||||||
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
|
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
|
||||||
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
|
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
|
||||||
|
|
||||||
head = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label)
|
head = @condition.to_mom(compiler) if @condition.is_a?(SendStatement)
|
||||||
|
head << Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label)
|
||||||
head << true_label
|
head << true_label
|
||||||
head << if_true.to_mom(compiler) if @if_true
|
head << if_true.to_mom(compiler) if @if_true
|
||||||
head << Mom::Jump.new(merge_label) if @if_false
|
head << Mom::Jump.new(merge_label) if @if_false
|
||||||
@ -40,8 +41,9 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
parts = ["if (#{@condition})" , @body.to_s(depth + 1) ]
|
parts = ["if (#{@condition.to_s(0)})" ]
|
||||||
parts += ["else" , "@if_false.to_s(depth + 1)"] if(@false)
|
parts << " #{@if_true}" if @if_true
|
||||||
|
parts += [ "else" , " #{@if_false}"] if(@false)
|
||||||
parts << "end"
|
parts << "end"
|
||||||
at_depth(depth , *parts )
|
at_depth(depth , *parts )
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user