rubyx/lib/slot_language/macro_maker.rb

36 lines
816 B
Ruby
Raw Normal View History

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)
end
end
end