2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2017-04-10 10:47:18 +02:00
|
|
|
|
2019-10-03 20:07:55 +02:00
|
|
|
# Base class for SlotMachine instructions
|
2018-03-19 16:49:46 +01:00
|
|
|
# At the base class level instructions are a linked list.
|
|
|
|
#
|
2019-10-03 23:36:49 +02:00
|
|
|
# SlotMachine::Instructions are created by the Sol level as an intermediate step
|
2018-03-19 16:49:46 +01:00
|
|
|
# towards the next level down, the Risc level.
|
2019-10-03 20:07:55 +02:00
|
|
|
# SlotMachine and Risc are both abstract machines (ie have instructions), so both
|
2018-03-26 19:05:30 +02:00
|
|
|
# share the linked list functionality (In Util::List)
|
2018-03-19 16:49:46 +01:00
|
|
|
#
|
2019-10-03 20:07:55 +02:00
|
|
|
# To convert a SlotMachine instruction to it's Risc equivalent to_risc is called
|
2018-03-19 16:49:46 +01:00
|
|
|
#
|
2017-04-10 10:47:18 +02:00
|
|
|
class Instruction
|
2018-03-26 19:05:30 +02:00
|
|
|
include Util::List
|
2017-09-04 20:00:08 +02:00
|
|
|
|
2019-08-06 19:44:39 +02:00
|
|
|
def initialize( source , nekst = nil )
|
|
|
|
@source = source
|
|
|
|
@next = nekst
|
|
|
|
return unless source
|
|
|
|
unless source.is_a?(String) or
|
2019-10-03 23:36:49 +02:00
|
|
|
source.is_a?(Sol::Statement)
|
2019-08-06 19:44:39 +02:00
|
|
|
raise "Source must be string or Instruction, not #{source.class}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
attr_reader :source
|
|
|
|
|
2018-03-19 16:49:46 +01:00
|
|
|
# to_risc, like the name says, converts the instruction to it's Risc equivalent.
|
|
|
|
# The Risc machine is basically a simple register machine (kind of arm).
|
2019-10-03 20:07:55 +02:00
|
|
|
# In other words SlotMachine is the higher abstraction and so slot instructions convert
|
2018-03-19 16:49:46 +01:00
|
|
|
# to many (1-10) risc instructions
|
|
|
|
#
|
2018-06-30 22:26:28 +02:00
|
|
|
# The argument that is passed is a MethodCompiler, which has the method and some
|
2018-03-19 16:49:46 +01:00
|
|
|
# state about registers used. (also provides helpers to generate risc instructions)
|
2018-03-13 11:46:06 +01:00
|
|
|
def to_risc(compiler)
|
2018-03-20 17:35:09 +01:00
|
|
|
raise self.class.name + "_todo"
|
2018-03-13 11:46:06 +01:00
|
|
|
end
|
2017-08-30 16:21:13 +02:00
|
|
|
end
|
2018-03-19 16:49:46 +01:00
|
|
|
|
2017-04-10 10:47:18 +02:00
|
|
|
end
|
2017-04-12 10:53:02 +02:00
|
|
|
|
2019-08-06 19:44:39 +02:00
|
|
|
require_relative "instruction/label"
|
|
|
|
require_relative "instruction/check"
|
|
|
|
require_relative "instruction/basic_values"
|
|
|
|
require_relative "instruction/simple_call"
|
|
|
|
require_relative "instruction/dynamic_call"
|
|
|
|
require_relative "instruction/block_yield"
|
|
|
|
require_relative "instruction/resolve_method"
|
|
|
|
require_relative "instruction/truth_check"
|
|
|
|
require_relative "instruction/not_same_check"
|
|
|
|
require_relative "instruction/jump"
|
|
|
|
require_relative "instruction/return_jump"
|
|
|
|
require_relative "instruction/slot_load"
|
|
|
|
require_relative "instruction/return_sequence"
|
|
|
|
require_relative "instruction/message_setup"
|
|
|
|
require_relative "instruction/argument_transfer"
|