Fix ruby receiver to vool

for chained calls to be normalized correctly
This commit is contained in:
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