2019-10-06 18:49:53 +02:00
|
|
|
|
|
|
|
module SlotLanguage
|
|
|
|
class MacroMaker
|
|
|
|
attr_reader :source
|
|
|
|
|
|
|
|
def self.load_file(relative_name)
|
|
|
|
path = File.expand_path( "../code/#{relative_name}" , __FILE__)
|
|
|
|
load_string( File.read(path))
|
|
|
|
end
|
|
|
|
def self.load_string(source_code)
|
|
|
|
MacroMaker.new( SlotCompiler.compile(source_code) )
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize( source )
|
|
|
|
@source = source
|
|
|
|
raise "undefined source #{source}" unless source.is_a?(Array)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_slot(compiler)
|
2019-10-07 19:14:40 +02:00
|
|
|
chain = do_link( @source.first , compiler)
|
|
|
|
rest = @source.dup
|
|
|
|
rest.shift
|
|
|
|
rest.each do |link|
|
|
|
|
chain << do_link(link , compiler)
|
|
|
|
end
|
|
|
|
chain
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def do_link(link,compiler)
|
|
|
|
return link if link.is_a?(SlotMachine::Instruction)
|
|
|
|
link.to_slot(compiler)
|
2019-10-06 18:49:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|