Start nexr level p i SlotLanguage, calling it MacroMaker

Since we already have Macros. Macros are nothing more than a list of SlotMachine Instructions. This is what we are aiming to create (which is also what is created in Sol .to_slot)

So the idea came to slot the MacroMaker in there after its done
This commit is contained in:
2019-10-06 19:49:53 +03:00
parent cbbb0c2f07
commit 8cac5c064d
7 changed files with 108 additions and 7 deletions

View File

@ -0,0 +1,23 @@
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)
@source.first
end
end
end

View File

@ -29,27 +29,30 @@ module SlotLanguage
def on_lvar(lvar)
SlotMaker.new(lvar.children.first , nil)
end
def on_lvasgn expression
def on_lvasgn( expression)
name = expression.children[0]
value = process(expression.children[1])
LoadMaker.new(SlotMaker.new(name,nil),value)
end
alias :on_ivasgn :on_lvasgn
def on_if(expression)
condition = process(expression.children[0])
condition.set_goto( process(expression.children[1]) )
condition
end
def on_begin(exp)
process(exp.first)
if( exp.children.length == 1)
process(exp.first)
else
process_all(exp)
end
end
def on_ivar expression
SlotMaker.new(instance_name(expression.children.first),nil)
SlotMaker.new(expression.children.first,nil)
end
private
def instance_name(sym)
sym.to_s[1 .. -1].to_sym
end
def label(name)
SlotMachine::Label.new(name.to_s , name)
end
@ -78,3 +81,4 @@ require_relative "message_slot"
require_relative "slot_maker"
require_relative "load_maker"
require_relative "check_maker"
require_relative "macro_maker"