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:
Torsten Ruger 2018-08-06 13:04:47 +03:00
parent 595e032edf
commit fd25f997ce
2 changed files with 57 additions and 8 deletions

View File

@ -20,15 +20,23 @@ module Mom
#
class ReturnSequence < Instruction
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
return_address = compiler.use_reg(:ReturnAddress)
message = Risc.message_reg
moves << Risc.slot_to_reg(self,message, :return_address , return_address)
moves << Risc.slot_to_reg(self,return_address , Parfait::Integer.integer_index , return_address)
moves << Risc.slot_to_reg(self,message , :caller , message)
moves << Risc::FunctionReturn.new(self, return_address)
builder = compiler.code_builder(self)
builder.build do
#space << Parfait.object_space
#next_message << space[:next_message]
object << message[:return_value]
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
def to_s

View 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