From 61a801b00c2fe6aceae08ce00b77dddaa40d983a Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 21 Mar 2018 15:48:50 +0530 Subject: [PATCH] Return to_risc remove the index from FunctionReturn, just jump to the register address --- lib/mom/instruction/return_sequence.rb | 14 ++++++++++++-- lib/risc/instructions/function_return.rb | 13 ++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) 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