2017-04-15 19:58:39 +02:00
|
|
|
module Mom
|
|
|
|
|
|
|
|
# A SimpleCall is just that, a simple call. This could be called a function call too,
|
|
|
|
# meaning we managed to resolve the function at compile time and all we have to do is
|
|
|
|
# actually call it.
|
|
|
|
#
|
|
|
|
# As the call setup is done beforehand (for both simple and cached call), the
|
2018-03-21 14:24:42 +01:00
|
|
|
# calling really means mostly jumping to the address. Simple.
|
2017-04-15 19:58:39 +02:00
|
|
|
#
|
|
|
|
class SimpleCall < Instruction
|
|
|
|
attr_reader :method
|
2018-03-14 15:55:21 +01:00
|
|
|
|
2017-04-15 19:58:39 +02:00
|
|
|
def initialize(method)
|
|
|
|
@method = method
|
|
|
|
end
|
2018-03-21 14:24:42 +01:00
|
|
|
|
|
|
|
# To call the method, we determine the jumpable address (method.binary), move that
|
|
|
|
# into a register and issue a FunctionCall
|
|
|
|
#
|
|
|
|
# For returning, we add a label after the call, and load it's address into the
|
|
|
|
# return_address of the next_message, for the ReturnSequence to pick it up.
|
|
|
|
def to_risc(compiler)
|
2018-03-31 18:17:55 +02:00
|
|
|
jump_address = compiler.use_reg(:Object)
|
2018-03-21 17:35:51 +01:00
|
|
|
return_label = Risc::Label.new(self,"continue_#{object_id}")
|
2018-03-22 17:45:03 +01:00
|
|
|
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
|
2018-03-21 14:50:51 +01:00
|
|
|
moves = save_return.to_risc(compiler)
|
|
|
|
moves << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg)
|
2018-03-21 14:59:00 +01:00
|
|
|
moves << Risc.load_constant(self , method.binary , jump_address)
|
|
|
|
moves << Risc::FunctionCall.new(self, method ,jump_address)
|
2018-03-21 14:24:42 +01:00
|
|
|
moves << return_label
|
2018-03-14 15:55:21 +01:00
|
|
|
end
|
|
|
|
|
2017-04-15 19:58:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|