return single message for "message" ie r0

other names, like next_message allocate  a new register
This commit is contained in:
Torsten Ruger 2018-04-06 22:54:54 +03:00
parent 22409c93ee
commit 1ddbde1191
4 changed files with 39 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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