From dee1e24c285375605c5ab5cfd5834adefb3b1a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Fri, 16 Aug 2019 16:05:45 +0300 Subject: [PATCH] Fix ruby receiver to vool for chained calls to be normalized correctly --- lib/ruby/basic_values.rb | 5 +---- lib/ruby/call_statement.rb | 14 +++++++------- lib/vool/if_statement.rb | 8 +++++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/ruby/basic_values.rb b/lib/ruby/basic_values.rb index 2bce4f32..f7040e98 100644 --- a/lib/ruby/basic_values.rb +++ b/lib/ruby/basic_values.rb @@ -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 diff --git a/lib/ruby/call_statement.rb b/lib/ruby/call_statement.rb index 17496c14..3cb7d8ac 100644 --- a/lib/ruby/call_statement.rb +++ b/lib/ruby/call_statement.rb @@ -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 diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index 92ed69a5..59e1970a 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -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