rubyx/lib/slot_machine/instruction/simple_call.rb
Torsten ff49ff50c0 Convert SimpleCall to new regs
Also fix bug in RegsiterValue/Slot with chain, where logic was dodgy and compiler not set
2020-03-22 14:31:43 +02:00

41 lines
1.2 KiB
Ruby

module SlotMachine
# 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
# calling really means mostly jumping to the address. Simple.
#
class SimpleCall < Instruction
attr_reader :method
def initialize(method)
@method = method
end
def to_s
"SimpleCall #{@method.name}"
end
# Calling a Method is basically jumping to the Binary (+ offset).
# We just swap in the new message and go.
#
# 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)
method = @method
return_label = Risc.label(self,"continue_#{object_id}")
return_address = compiler.load_object( return_label )
compiler.build(self.to_s) do
message[:next_message][:return_address] << return_address
message << message[:next_message]
add_code Risc.function_call(self.to_s, method )
add_code return_label
end
end
end
end