Fix ruby receiver to vool

for chained calls to be normalized correctly
This commit is contained in:
Torsten Rüger 2019-08-16 16:05:45 +03:00
parent c213cf874b
commit dee1e24c28
3 changed files with 13 additions and 14 deletions

View File

@ -44,13 +44,10 @@ module Ruby
"self"
end
end
class SuperExpression < Statement
class SuperExpression < Constant
def to_s(depth = 0)
"super"
end
def to_vool
vool_brother.new
end
end
class StringConstant < ValueConstant
attr_reader :value

View File

@ -20,14 +20,15 @@ module Ruby
# we "normalize" or flatten any complex argument expressions into a list
def to_vool
statements = Vool::Statements.new([])
receiver = normalize_arg(@receiver , statements)
arguments = []
@arguments.each_with_index do |arg , index |
normalize_arg(arg , arguments , statements)
arguments << normalize_arg(arg , statements)
end
if statements.empty?
return vool_brother.new(@name, @receiver.to_vool , arguments)
return vool_brother.new(@name, receiver , arguments)
else
statements << vool_brother.new(@name, @receiver.to_vool , arguments)
statements << vool_brother.new(@name, receiver , arguments)
return statements
end
end
@ -36,11 +37,10 @@ module Ruby
# we create a tmp variable and assign to that, hoising all the calls.
# the effect is of walking the call tree now,
# 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
if arg.is_a?(Constant)
arguments << vool_arg
return
return vool_arg
end
if( vool_arg.is_a?(Vool::Statements))
while(vool_arg.length > 1)
@ -50,7 +50,7 @@ module Ruby
end
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, vool_arg)
statements << assign
arguments << Vool::LocalVariable.new(assign.name)
return Vool::LocalVariable.new(assign.name)
end
end

View File

@ -15,7 +15,8 @@ module Vool
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)}")
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 << if_true.to_mom(compiler) if @if_true
head << Mom::Jump.new(merge_label) if @if_false
@ -40,8 +41,9 @@ module Vool
end
def to_s(depth = 0)
parts = ["if (#{@condition})" , @body.to_s(depth + 1) ]
parts += ["else" , "@if_false.to_s(depth + 1)"] if(@false)
parts = ["if (#{@condition.to_s(0)})" ]
parts << " #{@if_true}" if @if_true
parts += [ "else" , " #{@if_false}"] if(@false)
parts << "end"
at_depth(depth , *parts )
end