2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2019-09-15 14:13:11 +02:00
|
|
|
# Init "method" is the first thing that happens in the machine
|
|
|
|
# There is an inital jump to it, but that's it, no setup, no nothing
|
|
|
|
#
|
|
|
|
# The method is in quotes, because it is not really a method, it does not return!!
|
|
|
|
# This is common to all double underscore "methods", but __init also does not
|
|
|
|
# rely on the message. In fact it's job is to set up the first message
|
|
|
|
# and to call the main (possibly later _init_ , single undescrore)
|
|
|
|
#
|
2019-09-11 19:17:43 +02:00
|
|
|
class Init < Macro
|
2019-09-11 17:43:20 +02:00
|
|
|
def to_risc(compiler)
|
|
|
|
builder = compiler.builder(compiler.source)
|
2019-09-15 11:58:43 +02:00
|
|
|
main = Parfait.object_space.get_method!(:Space, :main)
|
2019-09-15 14:13:11 +02:00
|
|
|
# Set up the first message, but advance one, so main has somewhere to return to
|
2019-09-11 17:43:20 +02:00
|
|
|
builder.build do
|
2020-03-10 16:21:49 +01:00
|
|
|
factory = load_object Parfait.object_space.get_factory_for(:Message)
|
2019-09-11 17:43:20 +02:00
|
|
|
message << factory[:next_object]
|
2020-03-10 16:21:49 +01:00
|
|
|
factory[:next_object] << message[:next_message]
|
2019-09-11 17:43:20 +02:00
|
|
|
end
|
2019-09-15 14:13:11 +02:00
|
|
|
# Set up the call to main, with space as receiver
|
2019-10-03 20:07:55 +02:00
|
|
|
SlotMachine::MessageSetup.new(main).build_with( builder )
|
2019-09-11 17:43:20 +02:00
|
|
|
builder.build do
|
|
|
|
message << message[:next_message]
|
2020-03-10 16:21:49 +01:00
|
|
|
space = load_object Parfait.object_space
|
2019-09-11 17:43:20 +02:00
|
|
|
message[:receiver] << space
|
|
|
|
end
|
2019-09-15 14:13:11 +02:00
|
|
|
# set up return address and jump to main
|
2019-09-11 17:43:20 +02:00
|
|
|
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
|
|
|
|
builder.build do
|
2020-03-10 16:21:49 +01:00
|
|
|
message[:return_address] << load_object(exit_label)
|
2019-09-15 11:58:43 +02:00
|
|
|
add_code Risc.function_call( "__init__ issue call" , main)
|
2019-09-11 17:43:20 +02:00
|
|
|
add_code exit_label
|
|
|
|
end
|
2019-09-15 14:13:11 +02:00
|
|
|
Macro.exit_sequence(builder) # exit will use mains return_value as exit_code
|
2019-09-11 17:43:20 +02:00
|
|
|
return compiler
|
|
|
|
end
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
end
|