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
|
|
|
|
factory! << Parfait.object_space.get_factory_for(:Message)
|
|
|
|
message << factory[:next_object]
|
|
|
|
next_message! << message[:next_message]
|
|
|
|
factory[:next_object] << next_message
|
|
|
|
end
|
|
|
|
builder.reset_names
|
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]
|
|
|
|
space? << Parfait.object_space
|
|
|
|
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}" )
|
|
|
|
ret_tmp = compiler.use_reg(:Label).set_builder(builder)
|
|
|
|
builder.build do
|
|
|
|
ret_tmp << exit_label
|
|
|
|
message[:return_address] << ret_tmp
|
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
|
|
|
|
compiler.reset_regs
|
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
|