continue to rewrite message_setup
message come from space already. next types
This commit is contained in:
parent
f09086e524
commit
d52e14d201
@ -55,7 +55,7 @@ module Mom
|
|||||||
|
|
||||||
# get the next message from space and unlink it there
|
# 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
|
||||||
# use given message regster
|
# use given message register
|
||||||
# return instructions to do this
|
# return instructions to do this
|
||||||
def get_message_to( compiler , message)
|
def get_message_to( compiler , message)
|
||||||
space = compiler.use_reg(:Space)
|
space = compiler.use_reg(:Space)
|
||||||
@ -63,6 +63,8 @@ module Mom
|
|||||||
risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
|
risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
|
||||||
next_message = compiler.use_reg( :Message )
|
next_message = compiler.use_reg( :Message )
|
||||||
risc << Risc.slot_to_reg(source + "get next message" , message , :next_message , next_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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ module Parfait
|
|||||||
raise "not type #{@type.class}" unless @type.is_a?(Type)
|
raise "not type #{@type.class}" unless @type.is_a?(Type)
|
||||||
name = @type.name_at(index)
|
name = @type.name_at(index)
|
||||||
#return value unless name
|
#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)
|
instance_variable_set("@#{name}".to_sym, value)
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,10 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "5.mod4"
|
@input = "5.mod4"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, LoadConstant,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
||||||
SlotToReg, LoadConstant, FunctionCall, Label]
|
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
|
||||||
|
Label]
|
||||||
@produced = produce_body
|
@produced = produce_body
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,6 +35,14 @@ module Risc
|
|||||||
sl = @produced.next( 3 )
|
sl = @produced.next( 3 )
|
||||||
assert_slot_to_reg( sl , :r2 , 2 , :r4 )
|
assert_slot_to_reg( sl , :r2 , 2 , :r4 )
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
@ -2,14 +2,20 @@ module Risc
|
|||||||
module Assertions
|
module Assertions
|
||||||
def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
|
def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
|
||||||
assert_equal SlotToReg , slot.class
|
assert_equal SlotToReg , slot.class
|
||||||
assert_equal( array , slot.array.symbol) if array
|
assert_equal( array , slot.array.symbol , "wrong source register") if array
|
||||||
assert_equal( index , slot.index) if index
|
assert_equal( index , slot.index, "wrong source index") if index
|
||||||
assert_equal( register , slot.register.symbol) if register
|
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
|
end
|
||||||
def assert_load(load , clazz = nil , register = nil)
|
def assert_load(load , clazz = nil , register = nil)
|
||||||
assert_equal LoadConstant , load.class
|
assert_equal LoadConstant , load.class
|
||||||
assert_equal( clazz , load.constant.class) if clazz
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user