2014-10-03 13:32:54 +02:00
|
|
|
module Register
|
|
|
|
# name says it all really
|
|
|
|
# only arg is the method object we want to call
|
|
|
|
# assembly takes care of the rest (ie getting the address)
|
|
|
|
|
|
|
|
class FunctionCall < Instruction
|
2015-07-27 11:13:39 +02:00
|
|
|
def initialize source , method
|
|
|
|
super(source)
|
2014-10-03 13:32:54 +02:00
|
|
|
@method = method
|
|
|
|
end
|
|
|
|
attr_reader :method
|
2015-07-24 12:23:56 +02:00
|
|
|
|
|
|
|
def to_s
|
2015-07-25 08:30:58 +02:00
|
|
|
"FunctionCall: #{method.name}"
|
2015-07-24 12:23:56 +02:00
|
|
|
end
|
2015-10-18 18:27:46 +02:00
|
|
|
end
|
2015-07-24 12:23:56 +02:00
|
|
|
|
2016-12-14 12:23:46 +01:00
|
|
|
def self.issue_call( compiler , callee )
|
2015-10-29 21:31:28 +01:00
|
|
|
source = "_issue_call(#{callee.name})"
|
2016-12-14 12:23:46 +01:00
|
|
|
return_label = Label.new("_return_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
2015-11-03 10:20:49 +01:00
|
|
|
ret_tmp = compiler.use_reg(:Label)
|
|
|
|
compiler.add_code Register::LoadConstant.new(source, return_label , ret_tmp)
|
2016-12-25 17:02:39 +01:00
|
|
|
compiler.add_code Register.reg_to_slot(source, ret_tmp , :new_message , :return_address)
|
2015-10-18 18:27:46 +02:00
|
|
|
# move the current new_message to message
|
2015-10-29 21:31:28 +01:00
|
|
|
compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg )
|
2015-10-18 18:27:46 +02:00
|
|
|
# do the register call
|
2015-10-29 21:31:28 +01:00
|
|
|
compiler.add_code FunctionCall.new( source , callee )
|
2015-11-03 10:20:49 +01:00
|
|
|
compiler.add_code return_label
|
2015-11-07 20:59:39 +01:00
|
|
|
# move the current message to new_message
|
|
|
|
compiler.add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg )
|
|
|
|
# and restore the message from saved value in new_message
|
|
|
|
compiler.add_code Register.get_slot(source , :new_message , :caller , :message )
|
2014-10-03 13:32:54 +02:00
|
|
|
end
|
2015-07-24 12:23:56 +02:00
|
|
|
end
|