From 1a9370ad14560a9fc4db67285903d5c036dca312 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 10 Sep 2017 13:33:32 +0300 Subject: [PATCH] fix moms ivar assignment --- lib/vool/statements/ivar_statement.rb | 2 +- test/vool/statements/test_ivar.rb | 5 +++++ test/vool/to_mom/test_assign.rb | 32 +++++++++++++++++---------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/vool/statements/ivar_statement.rb b/lib/vool/statements/ivar_statement.rb index a1130a97..66039240 100644 --- a/lib/vool/statements/ivar_statement.rb +++ b/lib/vool/statements/ivar_statement.rb @@ -18,7 +18,7 @@ module Vool end def to_mom( method ) - Mom::SlotConstant.new([:message , :self , @name] , @value) + @value.slot_class.new([:message , :self , @name] , @value) end end diff --git a/test/vool/statements/test_ivar.rb b/test/vool/statements/test_ivar.rb index 9ae8df32..f78ab1ec 100644 --- a/test/vool/statements/test_ivar.rb +++ b/test/vool/statements/test_ivar.rb @@ -21,6 +21,11 @@ module Vool assert_equal :foo , lst.name end + def test_const + lst = RubyCompiler.compile( "@foo = 5") + assert_equal IvarAssignment , lst.class + end + end end diff --git a/test/vool/to_mom/test_assign.rb b/test/vool/to_mom/test_assign.rb index 5d8478e3..f8a7e550 100644 --- a/test/vool/to_mom/test_assign.rb +++ b/test/vool/to_mom/test_assign.rb @@ -6,7 +6,7 @@ module Vool def setup Risc.machine.boot - @stats = compile_first_method( "arg = 5") + @stats = compile_first_method( "local = 5") @first = @stats.first end @@ -20,10 +20,10 @@ module Vool assert_equal :message , @first.left.known_object end def test_slot_gets_self - assert_equal :arguments , @first.left.slots[0] + assert_equal :frame , @first.left.slots[0] end def test_slot_assigns_to_local - assert_equal :arg , @first.left.slots[-1] + assert_equal :local , @first.left.slots[-1] end def test_slot_assigns_something assert @stats.first.right @@ -34,20 +34,19 @@ module Vool end #otherwise as above, but assigning instance, so should get a SlotMove - class TestAssignMomInstance < MiniTest::Test + class TestAssignMomInstanceToLocal < MiniTest::Test include MomCompile def setup Risc.machine.boot - @stats = compile_first_method( "arg = @a") + @stats = compile_first_method( "local = @a") end - def test_class_compiles assert_equal Mom::SlotMove , @stats.first.class , @stats end end - + #compiling to an argument should result in different second parameter in the slot array - class TestArgMom < MiniTest::Test + class TestAssignToArg < MiniTest::Test include MomCompile def setup @@ -71,11 +70,20 @@ module Vool def test_slot_assigns_to_local assert_equal :arg , @first.left.slots[-1] end - def test_slot_assigns_something - assert @first.right + end + + class TestAssignMomToInstance < MiniTest::Test + include MomCompile + def setup + Risc.machine.boot end - def test_slot_assigns_int - assert_equal IntegerStatement , @first.right.class + def test_assigns_const + @stats = compile_first_method( "@a = 5") + assert_equal Mom::SlotConstant , @stats.first.class , @stats + end + def test_assigns_move + @stats = compile_first_method( "@a = arg") + assert_equal Mom::SlotMove , @stats.first.class , @stats end end