From 172327f0452cf98fe5f5002be42b406ed97d4153 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 20 Jul 2018 18:13:58 +0300 Subject: [PATCH] fix assignments which was letting ruby instances through also rename the doubious copy --- lib/ruby/assignment.rb | 22 +++++++++++++--------- test/ruby/test_assignment.rb | 36 ++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/lib/ruby/assignment.rb b/lib/ruby/assignment.rb index 9b3304f9..df338f1b 100644 --- a/lib/ruby/assignment.rb +++ b/lib/ruby/assignment.rb @@ -10,7 +10,7 @@ module Ruby raise "not named left #{name.class}" unless name.is_a?(Symbol) case value when Named , Constant - return copy + return self.vool_brother.new(name,@value.to_vool) when SendStatement return normalize_send else @@ -18,19 +18,23 @@ module Ruby end end - def copy(value = nil) - value ||= @value - self.vool_brother.new(name,value) - end - + # sends may have complex args that get hoisted in vool:ing them + # in which case we have to assign the simplified, otherwise the + # plain send def normalize_send statements = value.to_vool - return copy( statements ) if statements.is_a?(Vool::SendStatement) - assign = statements.statements.pop - statements << copy(assign) + return assignment( statements ) if statements.is_a?(Vool::SendStatement) + # send has hoisted assigns, so we make an assign out of the "pure" send + statements << assignment(statements.statements.pop) statements end + # create same type assignment with the value (a send) + def assignment(value) + value ||= @value + self.vool_brother.new(name,value) + end + def to_s(depth = 0) at_depth(depth , "#{@name} = #{@value}") end diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index 17473ffd..d9bdf4e6 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -25,28 +25,40 @@ module Ruby assert_equal IvarAssignment , lst.class end end - class TestAssignmentVool < MiniTest::Test + class TestAssignmentVoolBar < MiniTest::Test include RubyTests - + def setup + @lst = compile( "foo = bar").to_vool + end def test_local - lst = compile( "foo = bar").to_vool - assert_equal Vool::LocalAssignment , lst.class + assert_equal Vool::LocalAssignment , @lst.class + end + def test_bar + assert_equal Vool::SendStatement , @lst.value.class end def test_local_name - lst = compile( "foo = bar").to_vool - assert_equal :foo , lst.name + assert_equal :foo , @lst.name + end + end + class TestAssignmentVoolInst < MiniTest::Test + include RubyTests + def setup + @lst = compile( "@foo = bar").to_vool end def test_instance - lst = compile( "@foo = bar").to_vool - assert_equal Vool::IvarAssignment , lst.class + assert_equal Vool::IvarAssignment , @lst.class end def test_instance_name - lst = compile( "@foo = bar").to_vool - assert_equal :foo , lst.name + assert_equal :foo , @lst.name + end + end + class TestAssignmentVoolConst < MiniTest::Test + include RubyTests + def setup + @lst = compile( "foo = 5").to_vool end def test_const - lst = compile( "@foo = 5").to_vool - assert_equal Vool::IvarAssignment , lst.class + assert_equal Vool::IntegerConstant , @lst.value.class end end end