From bc414fd3e8db313f01ef103d05d8d3dfbcca244c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 3 Nov 2015 11:20:49 +0200 Subject: [PATCH] function call now saves the return address before calling that means SaveReturn is obsolete (breaks loads of tests) first step towards multi - return which obviously can not have the callee save return address. In fact this would make FunctionCall redundant too, as it is really just a branch --- lib/register/instruction.rb | 1 - lib/register/instructions/function_call.rb | 5 ++++ lib/register/instructions/save_return.rb | 32 ---------------------- 3 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 lib/register/instructions/save_return.rb diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index 2123f7cf..857c2854 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -123,7 +123,6 @@ require_relative "instructions/load_constant" require_relative "instructions/syscall" require_relative "instructions/function_call" require_relative "instructions/function_return" -require_relative "instructions/save_return" require_relative "instructions/register_transfer" require_relative "instructions/label" require_relative "instructions/branch" diff --git a/lib/register/instructions/function_call.rb b/lib/register/instructions/function_call.rb index 0919dcc4..9d20bfa7 100644 --- a/lib/register/instructions/function_call.rb +++ b/lib/register/instructions/function_call.rb @@ -17,9 +17,14 @@ module Register def self.issue_call compiler , callee source = "_issue_call(#{callee.name})" + return_label = Label.new("_return_label" , "_return_label" ) + ret_tmp = compiler.use_reg(:Label) + compiler.add_code Register::LoadConstant.new(source, return_label , ret_tmp) + compiler.add_code Register.set_slot(source, ret_tmp , :new_message , :return_address) # move the current new_message to message compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg ) # do the register call compiler.add_code FunctionCall.new( source , callee ) + compiler.add_code return_label end end diff --git a/lib/register/instructions/save_return.rb b/lib/register/instructions/save_return.rb deleted file mode 100644 index 9eb41a1a..00000000 --- a/lib/register/instructions/save_return.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Register - - # save the return address of a call - # register and index specify where the return address is stored - - # This instruction exists mainly, so we don't have to hard-code where the machine stores the - # address. In arm that is a register, but intel may (?) push it, and who knows, what other machines do. - - class SaveReturn < Instruction - def initialize source , register , index - super(source) - @register = register - @index = index - end - attr_reader :register , :index - - def to_s - "SaveReturn: #{register} [#{index}]" - end - - end - - # Produce a SaveReturn instruction. - # From is a register or symbol that can be transformed to a register by resolve_to_register - # index resolves with resolve_index. - def self.save_return code, from , index - index = resolve_index( from , index) - from = resolve_to_register from - SaveReturn.new( code , from , index ) - end - -end