fix moms ivar assignment

This commit is contained in:
Torsten Ruger 2017-09-10 13:33:32 +03:00
parent c245acbdd3
commit 1a9370ad14
3 changed files with 26 additions and 13 deletions

View File

@ -18,7 +18,7 @@ module Vool
end end
def to_mom( method ) def to_mom( method )
Mom::SlotConstant.new([:message , :self , @name] , @value) @value.slot_class.new([:message , :self , @name] , @value)
end end
end end

View File

@ -21,6 +21,11 @@ module Vool
assert_equal :foo , lst.name assert_equal :foo , lst.name
end end
def test_const
lst = RubyCompiler.compile( "@foo = 5")
assert_equal IvarAssignment , lst.class
end
end end
end end

View File

@ -6,7 +6,7 @@ module Vool
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( "arg = 5") @stats = compile_first_method( "local = 5")
@first = @stats.first @first = @stats.first
end end
@ -20,10 +20,10 @@ module Vool
assert_equal :message , @first.left.known_object assert_equal :message , @first.left.known_object
end end
def test_slot_gets_self def test_slot_gets_self
assert_equal :arguments , @first.left.slots[0] assert_equal :frame , @first.left.slots[0]
end end
def test_slot_assigns_to_local def test_slot_assigns_to_local
assert_equal :arg , @first.left.slots[-1] assert_equal :local , @first.left.slots[-1]
end end
def test_slot_assigns_something def test_slot_assigns_something
assert @stats.first.right assert @stats.first.right
@ -34,20 +34,19 @@ module Vool
end end
#otherwise as above, but assigning instance, so should get a SlotMove #otherwise as above, but assigning instance, so should get a SlotMove
class TestAssignMomInstance < MiniTest::Test class TestAssignMomInstanceToLocal < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( "arg = @a") @stats = compile_first_method( "local = @a")
end end
def test_class_compiles def test_class_compiles
assert_equal Mom::SlotMove , @stats.first.class , @stats assert_equal Mom::SlotMove , @stats.first.class , @stats
end end
end end
#compiling to an argument should result in different second parameter in the slot array #compiling to an argument should result in different second parameter in the slot array
class TestArgMom < MiniTest::Test class TestAssignToArg < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
@ -71,11 +70,20 @@ module Vool
def test_slot_assigns_to_local def test_slot_assigns_to_local
assert_equal :arg , @first.left.slots[-1] assert_equal :arg , @first.left.slots[-1]
end end
def test_slot_assigns_something
assert @first.right
end end
def test_slot_assigns_int
assert_equal IntegerStatement , @first.right.class class TestAssignMomToInstance < MiniTest::Test
include MomCompile
def setup
Risc.machine.boot
end
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
end end