From 1ddbde1191b026b37064d934bfdf12ea79b54800 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 6 Apr 2018 22:54:54 +0300 Subject: [PATCH] return single message for "message" ie r0 other names, like next_message allocate a new register --- lib/mom/instruction/message_setup.rb | 3 ++- lib/risc/builder.rb | 8 ++++++-- test/mom/send/test_setup_simple.rb | 27 +++++++++++++++++---------- test/risc/test_builder.rb | 17 ++++++++++++++--- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index ce3521de..9046e7e5 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -40,7 +40,8 @@ module Mom end # get the next message from space and unlink it there - # also put it into next_message of current message + # also put it into next_message of current message (and reverse) + # set name and type data in the message, from the method loaded def build_message_data( builder ) builder.build do space << Parfait.object_space diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index ebf6de8a..4ec0ed0a 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -13,8 +13,12 @@ module Risc super if args.length != 1 name = args[0] return @names[name] if @names.has_key?(name) - type = Risc.resolve_type(name , @compiler) #checking - reg = @compiler.use_reg( type.object_class.name ) + if name == :message + reg = Risc.message_reg + else + type = Risc.resolve_type(name , @compiler) #checking + reg = @compiler.use_reg( type.object_class.name ) + end @names[name] = reg reg.builder = self reg diff --git a/test/mom/send/test_setup_simple.rb b/test/mom/send/test_setup_simple.rb index b0f865b1..ca0a94f8 100644 --- a/test/mom/send/test_setup_simple.rb +++ b/test/mom/send/test_setup_simple.rb @@ -8,14 +8,15 @@ module Risc def setup super @input = "5.mod4" - @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, - RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, - SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall, - Label] + @expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot, + LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label] @produced = produce_body end - def pest_send_instructions + def test_send_instructions assert_nil msg = check_nil , msg end def test_load_method @@ -27,22 +28,28 @@ module Risc space = @produced.next(1) assert_load( space , Parfait::Space , :r2 ) end - def test_load_message #from space (ie r2) + def test_load_first_message #from space (ie r2) sl = @produced.next( 2 ) assert_slot_to_reg( sl , :r2 , 4 , :r3 ) end - def pest_load_next_message + def test_store_message_in_current sl = @produced.next( 3 ) - assert_slot_to_reg( sl , :r2 , 2 , :r4 ) + assert_reg_to_slot( sl , :r3 , :r0 , 2 ) end - def pest_store_next_message + def pest_store_message_in_current sl = @produced.next( 4 ) - assert_reg_to_slot( sl , :r4 , :r3 , 4 ) + assert_reg_to_slot( sl , :r4 , :r3 , 7 ) end def pest_store_current_message sl = @produced.next( 5 ) assert_reg_to_slot( sl , :r2 , :r0 , 2 ) end + + def pest_load_next_message + sl = @produced.next( 3 ) + assert_slot_to_reg( sl , :r2 , 2 , :r4 ) + end + end end diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index db9998dd..5b7e55a9 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -9,16 +9,21 @@ module Risc compiler = Risc::MethodCompiler.new( init ) @builder = Builder.new(compiler) end - def test_register_alloc_space + def test_alloc_space reg = @builder.space assert_equal RiscValue , reg.class assert_equal :Space , reg.type end - def test_register_alloc_message - reg = @builder.message + def test_next_message + reg = @builder.next_message assert_equal :r1 , reg.symbol assert_equal :Message , reg.type end + def test_message + reg = @builder.message + assert_equal :r0 , reg.symbol + assert_equal :Message , reg.type + end def test_returns_built r1 = RiscValue.new(:r1 , :Space) built = @builder.build{ space << r1 } @@ -48,6 +53,12 @@ module Risc built = @builder.build{ space << r1 ; space << r1} assert_equal built.to.symbol , built.next.to.symbol end + def test_uses_message_as_message + r1 = RiscValue.new(:r1 , :Space) + built = @builder.build{ message[:receiver] << r1} + assert_equal RegToSlot , built.class + assert_equal :r0 , built.array.symbol + end end class TestBuilderNoBoot < MiniTest::Test