2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2017-04-15 19:58:39 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2018-04-17 19:26:15 +02:00
|
|
|
def to_s
|
|
|
|
"SimpleCall #{@method.name}"
|
|
|
|
end
|
2018-11-14 11:41:13 +01:00
|
|
|
|
2018-05-19 11:21:20 +02:00
|
|
|
# Calling a Method is basically jumping to the Binary (+ offset).
|
|
|
|
# We just swap in the new message and go.
|
2018-05-29 19:26:00 +02:00
|
|
|
#
|
2018-03-21 14:24:42 +01:00
|
|
|
# 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-08-16 19:28:42 +02:00
|
|
|
method = @method
|
2020-03-08 16:31:16 +01:00
|
|
|
return_label = Risc.label(self,"after_#{@method.name}_#{object_id}")
|
2020-03-01 22:38:23 +01:00
|
|
|
return_address = compiler.load_object( return_label )
|
|
|
|
compiler.build(self.to_s) do
|
|
|
|
message[:next_message][:return_address] << return_address
|
2018-08-16 19:28:42 +02:00
|
|
|
message << message[:next_message]
|
2020-03-01 22:38:23 +01:00
|
|
|
add_code Risc.function_call(self.to_s, method )
|
2018-08-16 19:28:42 +02:00
|
|
|
add_code return_label
|
|
|
|
end
|
2018-03-14 15:55:21 +01:00
|
|
|
end
|
|
|
|
|
2017-04-15 19:58:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|