diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index f37bb28d..ee76e694 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -55,7 +55,7 @@ module Mom # get the next message from space and unlink it there # also put it into next_message of current message - # use given message regster + # use given message register # return instructions to do this def get_message_to( compiler , message) space = compiler.use_reg(:Space) @@ -63,6 +63,8 @@ module Mom risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message) next_message = compiler.use_reg( :Message ) risc << Risc.slot_to_reg(source + "get next message" , message , :next_message , next_message) + risc << Risc.reg_to_slot(source + "store next message" , next_message , space , :first_message) + risc << Risc.reg_to_slot(source + "store message in current" , message , :message , :next_message) end end diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index e92e6f75..b57ac72f 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -43,7 +43,7 @@ module Parfait raise "not type #{@type.class}" unless @type.is_a?(Type) name = @type.name_at(index) #return value unless name - raise "object type (#{type}) has no name at index #{index} " unless name + raise "object type (#{@type}) has no name at index #{index} " unless name instance_variable_set("@#{name}".to_sym, value) value end diff --git a/test/mom/send/test_setup_simple.rb b/test/mom/send/test_setup_simple.rb index 536e92eb..41f89509 100644 --- a/test/mom/send/test_setup_simple.rb +++ b/test/mom/send/test_setup_simple.rb @@ -8,9 +8,10 @@ module Risc def setup super @input = "5.mod4" - @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, LoadConstant, - SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, - SlotToReg, LoadConstant, FunctionCall, Label] + @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall, + Label] @produced = produce_body end @@ -34,6 +35,14 @@ module Risc sl = @produced.next( 3 ) assert_slot_to_reg( sl , :r2 , 2 , :r4 ) end + def test_store_next_message + sl = @produced.next( 4 ) + assert_reg_to_slot( sl , :r4 , :r3 , 4 ) + end + def test_store_current_message + sl = @produced.next( 5 ) + assert_reg_to_slot( sl , :r2 , :r0 , 2 ) + end end end diff --git a/test/support/risc_assert.rb b/test/support/risc_assert.rb index 7c8bc56d..7a1cc752 100644 --- a/test/support/risc_assert.rb +++ b/test/support/risc_assert.rb @@ -2,14 +2,20 @@ module Risc module Assertions def assert_slot_to_reg( slot , array = nil, index = nil , register = nil) assert_equal SlotToReg , slot.class - assert_equal( array , slot.array.symbol) if array - assert_equal( index , slot.index) if index - assert_equal( register , slot.register.symbol) if register + assert_equal( array , slot.array.symbol , "wrong source register") if array + assert_equal( index , slot.index, "wrong source index") if index + assert_equal( register , slot.register.symbol, "wrong destination") if register + end + def assert_reg_to_slot( slot , register = nil, array = nil, index = nil ) + assert_equal RegToSlot , slot.class + assert_equal( register , slot.register.symbol, "wrong source register") if register + assert_equal( array , slot.array.symbol, "wrong destination register") if array + assert_equal( index , slot.index, "wrong destination index") if index end def assert_load(load , clazz = nil , register = nil) assert_equal LoadConstant , load.class assert_equal( clazz , load.constant.class) if clazz - assert_equal( register , load.register.symbol) if register + assert_equal( register , load.register.symbol, "wrong destination register") if register end end end