getting back into it
This commit is contained in:
parent
5b27ae7ddf
commit
df4fd409c1
@ -1,8 +1,8 @@
|
|||||||
# passed in? name and cache_entry
|
# passed in? name and cache_entry
|
||||||
word! << name_
|
word! = name_
|
||||||
cache_entry! << cache_entry_
|
cache_entry! = cache_entry_
|
||||||
# local var assignment
|
# local var assignment
|
||||||
callable_method << cache_entry.cached_type.methods
|
callable_method = cache_entry.cached_type.methods
|
||||||
|
|
||||||
while_start_label
|
while_start_label
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
module SlotLanguage
|
module SlotLanguage
|
||||||
class MessageSlot
|
class MessageSlot
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"message"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ require "ast"
|
|||||||
|
|
||||||
module SlotLanguage
|
module SlotLanguage
|
||||||
class SlotCompiler < AST::Processor
|
class SlotCompiler < AST::Processor
|
||||||
|
DEBUG = false
|
||||||
|
|
||||||
def self.compile(input)
|
def self.compile(input)
|
||||||
ast = Parser::CurrentRuby.parse( input )
|
ast = Parser::CurrentRuby.parse( input )
|
||||||
@ -16,7 +17,6 @@ module SlotLanguage
|
|||||||
not_implemented(node)
|
not_implemented(node)
|
||||||
end
|
end
|
||||||
def on_send(statement)
|
def on_send(statement)
|
||||||
#puts "Send #{statement}"
|
|
||||||
kids = statement.children.dup
|
kids = statement.children.dup
|
||||||
receiver = process(kids.shift) || MessageSlot.new
|
receiver = process(kids.shift) || MessageSlot.new
|
||||||
name = kids.shift
|
name = kids.shift
|
||||||
@ -24,12 +24,15 @@ module SlotLanguage
|
|||||||
return goto(name,kids) if(name == :goto)
|
return goto(name,kids) if(name == :goto)
|
||||||
return check(name,receiver, kids) if(name == :==)
|
return check(name,receiver, kids) if(name == :==)
|
||||||
return assign(receiver, name , kids) if(name.to_s.end_with?("="))
|
return assign(receiver, name , kids) if(name.to_s.end_with?("="))
|
||||||
|
puts "Send #{name} , #{receiver} kids=#{kids}" if DEBUG
|
||||||
SlotMaker.new( name )
|
SlotMaker.new( name )
|
||||||
end
|
end
|
||||||
def on_lvar(lvar)
|
def on_lvar(lvar)
|
||||||
|
puts "lvar #{lvar}" if DEBUG
|
||||||
SlotMaker.new(lvar.children.first )
|
SlotMaker.new(lvar.children.first )
|
||||||
end
|
end
|
||||||
def on_lvasgn( expression)
|
def on_lvasgn( expression)
|
||||||
|
puts "lvasgn #{expression}" if DEBUG
|
||||||
name = expression.children[0]
|
name = expression.children[0]
|
||||||
value = process(expression.children[1])
|
value = process(expression.children[1])
|
||||||
LoadMaker.new(SlotMaker.new(name),value)
|
LoadMaker.new(SlotMaker.new(name),value)
|
||||||
@ -37,6 +40,7 @@ module SlotLanguage
|
|||||||
alias :on_ivasgn :on_lvasgn
|
alias :on_ivasgn :on_lvasgn
|
||||||
|
|
||||||
def on_if(expression)
|
def on_if(expression)
|
||||||
|
puts "if #{expression}" if DEBUG
|
||||||
condition = process(expression.children[0])
|
condition = process(expression.children[0])
|
||||||
condition.set_goto( process(expression.children[1]) )
|
condition.set_goto( process(expression.children[1]) )
|
||||||
condition
|
condition
|
||||||
@ -48,7 +52,8 @@ module SlotLanguage
|
|||||||
process_all(exp)
|
process_all(exp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def on_ivar expression
|
def on_ivar( expression)
|
||||||
|
puts "ivar #{expression}" if DEBUG
|
||||||
SlotMaker.new(expression.children.first)
|
SlotMaker.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,20 +63,22 @@ module SlotLanguage
|
|||||||
end
|
end
|
||||||
def goto(name , args)
|
def goto(name , args)
|
||||||
# error handling would not hurt
|
# error handling would not hurt
|
||||||
|
puts "goto #{name} , #{args}" if DEBUG
|
||||||
label = process(args.first)
|
label = process(args.first)
|
||||||
SlotMachine::Jump.new( label )
|
SlotMachine::Jump.new( label )
|
||||||
end
|
end
|
||||||
def check(name , receiver , kids)
|
def check(name , receiver , kids)
|
||||||
raise "Only ==, not #{name}" unless name == :==
|
raise "Only ==, not #{name}" unless name == :==
|
||||||
raise "Familiy too large #{kids}" if kids.length > 1
|
raise "Familiy too large #{kids}" if kids.length > 1
|
||||||
#puts "Kids " + kids.to_s
|
puts "Kids " + kids.to_s if DEBUG
|
||||||
right = process(kids.first)
|
right = process(kids.first)
|
||||||
CheckMaker.new(name , receiver , right)
|
CheckMaker.new(name , receiver , right)
|
||||||
end
|
end
|
||||||
def assign(receiver , name , kids)
|
def assign(receiver , name , kids)
|
||||||
name = name.to_s[0...-1].to_sym
|
name = name.to_s[0...-1].to_sym
|
||||||
receiver.add_slot_name(name)
|
receiver.add_slot_name(name)
|
||||||
right = process kids.first
|
right = process kids.shift
|
||||||
|
puts "Assign #{name} , #{receiver}" if DEBUG
|
||||||
LoadMaker.new(receiver,right)
|
LoadMaker.new(receiver,right)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,5 +20,9 @@ module SlotLanguage
|
|||||||
def slot_def(compiler)
|
def slot_def(compiler)
|
||||||
SlotMachine::SlotDefinition.new(:message , leaps)
|
SlotMachine::SlotDefinition.new(:message , leaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"message." + leaps.join(",")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,5 +56,11 @@ module SlotLanguage
|
|||||||
assert_equal SlotMachine::Label , multi.first.class
|
assert_equal SlotMachine::Label , multi.first.class
|
||||||
assert_equal SlotMachine::Jump , multi.last.class
|
assert_equal SlotMachine::Jump , multi.last.class
|
||||||
end
|
end
|
||||||
|
def test_shift
|
||||||
|
load = compile("word = name.member")
|
||||||
|
assert_equal LoadMaker , load.class
|
||||||
|
assert_equal :word , load.left.leaps.first
|
||||||
|
assert_equal SlotMaker , load.right.class
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user