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
This commit is contained in:
Torsten Ruger 2015-11-03 11:20:49 +02:00
parent cffbc91821
commit bc414fd3e8
3 changed files with 5 additions and 33 deletions

View File

@ -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"

View File

@ -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

View File

@ -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