reqrote return sequence with builder
added test _before_ , same code, just much easier to read in preparation for returning messages
This commit is contained in:
parent
595e032edf
commit
fd25f997ce
@ -20,15 +20,23 @@ module Mom
|
|||||||
#
|
#
|
||||||
class ReturnSequence < Instruction
|
class ReturnSequence < Instruction
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
return_move = SlotLoad.new( [:message , :caller,:return_value] , [:message , :return_value],self)
|
|
||||||
moves = return_move.to_risc(compiler)
|
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
return_address = compiler.use_reg(:ReturnAddress)
|
builder = compiler.code_builder(self)
|
||||||
message = Risc.message_reg
|
builder.build do
|
||||||
moves << Risc.slot_to_reg(self,message, :return_address , return_address)
|
#space << Parfait.object_space
|
||||||
moves << Risc.slot_to_reg(self,return_address , Parfait::Integer.integer_index , return_address)
|
#next_message << space[:next_message]
|
||||||
moves << Risc.slot_to_reg(self,message , :caller , message)
|
object << message[:return_value]
|
||||||
moves << Risc::FunctionReturn.new(self, return_address)
|
caller_reg << message[:caller]
|
||||||
|
caller_reg[:return_value] << object
|
||||||
|
end
|
||||||
|
compiler.reset_regs
|
||||||
|
builder.build do
|
||||||
|
return_address << message[:return_address]
|
||||||
|
return_address << return_address[ Parfait::Integer.integer_index]
|
||||||
|
message << message[:caller]
|
||||||
|
return_address.function_return
|
||||||
|
end
|
||||||
|
builder.built
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
41
test/mom/instruction/test_return_sequence.rb
Normal file
41
test/mom/instruction/test_return_sequence.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require_relative "../helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestReturnSequence < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "5.div4"
|
||||||
|
@expect = "something"
|
||||||
|
@produced = produce_instructions
|
||||||
|
end
|
||||||
|
def main_ends
|
||||||
|
24
|
||||||
|
end
|
||||||
|
def test_postamble_classes
|
||||||
|
postamble.each_with_index do |ins , index|
|
||||||
|
assert_equal ins , @produced.next( main_ends + index).class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def test_main_label
|
||||||
|
assert_equal Label , @produced.next(main_ends).class
|
||||||
|
assert_equal "return_label" , @produced.next(main_ends).name
|
||||||
|
end
|
||||||
|
def test_move_ret
|
||||||
|
assert_slot_to_reg( @produced.next(main_ends + 1) , :r0 , 5 , :r1 )
|
||||||
|
end
|
||||||
|
def test_move_caller
|
||||||
|
assert_slot_to_reg( @produced.next(main_ends + 2) , :r0 , 6 , :r2 )
|
||||||
|
end
|
||||||
|
def test_save_ret
|
||||||
|
assert_reg_to_slot( @produced.next(main_ends + 3) , :r1 , :r2 , 5 )
|
||||||
|
end
|
||||||
|
def test_save_addr
|
||||||
|
assert_slot_to_reg( @produced.next(main_ends + 4) , :r0 , 4 , :r1 )
|
||||||
|
end
|
||||||
|
def test_reduce_addr
|
||||||
|
assert_slot_to_reg( @produced.next(main_ends + 5) , :r1 , 2 , :r1 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user