diff --git a/lib/mom/instruction/return_sequence.rb b/lib/mom/instruction/return_sequence.rb index 25011726..9cd02b03 100644 --- a/lib/mom/instruction/return_sequence.rb +++ b/lib/mom/instruction/return_sequence.rb @@ -19,8 +19,18 @@ module Mom # set of lower level instructions. # class ReturnSequence < Instruction - def to_risc(context) - Risc::Label.new(self,"ReturnSequence") + def to_risc(compiler) + return_move = SlotLoad.new( [:message ,:return_value] , [:message , :next_message, :return_value]) + moves = return_move.to_risc(compiler) + caller_reg = compiler.use_reg(:int) + return_reg = compiler.use_reg(:int) + compiler.reset_regs + caller_index = Risc.resolve_to_index(:message , :caller) + return_index = Risc.resolve_to_index(:message , :return_address) + moves << Risc::SlotToReg.new(self, Risc.message_reg , caller_index , caller_reg) + moves << Risc::Transfer.new(self, caller_reg , Risc.message_reg) + moves << Risc::SlotToReg.new(self, Risc.message_reg, return_index , return_reg) + moves << Risc::FunctionReturn.new(self, return_reg) end end diff --git a/lib/risc/instructions/function_return.rb b/lib/risc/instructions/function_return.rb index 12030b56..b9894548 100644 --- a/lib/risc/instructions/function_return.rb +++ b/lib/risc/instructions/function_return.rb @@ -1,22 +1,21 @@ module Risc # return from a function call - # register and index specify where the return address is stored + # register specifes where the return address is stored class FunctionReturn < Instruction - def initialize( source , register , index) + def initialize( source , register ) super(source) @register = register - @index = index end - attr_reader :register , :index + attr_reader :register def to_s - "FunctionReturn: #{register} [#{index}]" + "FunctionReturn: #{register} " end end - def self.function_return( source , register , index) - FunctionReturn.new( source , register , index) + def self.function_return( source , register ) + FunctionReturn.new( source , register ) end end