2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2014-10-03 13:32:54 +02:00
|
|
|
# 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
|
2018-03-21 14:35:53 +01:00
|
|
|
def initialize( source , method , register)
|
2015-07-27 11:13:39 +02:00
|
|
|
super(source)
|
2014-10-03 13:32:54 +02:00
|
|
|
@method = method
|
2018-03-21 14:35:53 +01:00
|
|
|
@register = register
|
2014-10-03 13:32:54 +02:00
|
|
|
end
|
2018-03-21 14:35:53 +01:00
|
|
|
attr_reader :method , :register
|
2015-07-24 12:23:56 +02:00
|
|
|
|
|
|
|
def to_s
|
2018-03-22 17:38:19 +01:00
|
|
|
class_source 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
|
|
|
|
2018-03-21 14:35:53 +01:00
|
|
|
def self.function_call( source , method , register)
|
|
|
|
Risc::FunctionCall.new( source , method , register)
|
2016-12-28 18:01:58 +01:00
|
|
|
end
|
|
|
|
|
2016-12-14 12:23:46 +01:00
|
|
|
def self.issue_call( compiler , callee )
|
2017-01-19 08:02:29 +01:00
|
|
|
return_label = Risc.label("_return_label #{callee.name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
2015-11-03 10:20:49 +01:00
|
|
|
ret_tmp = compiler.use_reg(:Label)
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_load_constant("#{callee.name} load ret", return_label , ret_tmp)
|
|
|
|
compiler.add_reg_to_slot("#{callee.name} store ret", ret_tmp , :new_message , :return_address)
|
2017-01-19 08:02:29 +01:00
|
|
|
compiler.add_transfer("#{callee.name} move new message", Risc.new_message_reg , Risc.message_reg )
|
|
|
|
compiler.add_code Risc.function_call( "#{callee.name} call" , callee )
|
2015-11-03 10:20:49 +01:00
|
|
|
compiler.add_code return_label
|
2017-01-19 08:02:29 +01:00
|
|
|
compiler.add_transfer("#{callee.name} remove new message", Risc.message_reg , Risc.new_message_reg )
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_slot_to_reg("#{callee.name} restore message" , :new_message , :caller , :message )
|
2014-10-03 13:32:54 +02:00
|
|
|
end
|
2015-07-24 12:23:56 +02:00
|
|
|
end
|