rubyx/lib/slot_machine/macro_maker.rb
Torsten Rüger 8df2e4bf08 SlotLanguage reborn in the Machine
Just added the compiler, that can parse Slot directly into SlotMachine code (no language layer in between)
Still unclear wheather the Maker is a thing, but since it was in the Language layer i did not remove it (yet)
Otherwise just the compiler and all the tests, moved from the slot_language.
2020-02-19 02:19:14 +07:00

31 lines
895 B
Ruby

module SlotMachine
class MacroMaker
# a list of instructions
attr_reader :instructions
# load slot code from a file, in a subdir code/ + filename
# use load_string to compile the content
def self.load_file(relative_name)
path = File.expand_path( "../code/#{relative_name}" , __FILE__)
load_string( File.read(path))
end
# compile the given SlotLanguage source
# the compiler returns an array of Makers which a new MacroMaker
# instance stores
# return the MacroMaker that represents the source
def self.load_string(source_code)
MacroMaker.new( SlotCompiler.compile(source_code) )
end
# must initialize with an array of Makers, which is stored
def initialize( instructions )
@instructions = instructions
raise "undefined source #{instructions}" unless instructions.is_a?(Instruction)
end
end
end