diff --git a/lib/mom/instruction/return_sequence.rb b/lib/mom/instruction/return_sequence.rb index e37bbb21..ce5ddf36 100644 --- a/lib/mom/instruction/return_sequence.rb +++ b/lib/mom/instruction/return_sequence.rb @@ -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 diff --git a/test/mom/instruction/test_return_sequence.rb b/test/mom/instruction/test_return_sequence.rb new file mode 100644 index 00000000..5355b5d3 --- /dev/null +++ b/test/mom/instruction/test_return_sequence.rb @@ -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