diff --git a/lib/slot_language/code/resolve_method.slot b/lib/slot_language/code/resolve_method.slot index 7fc665a0..f777898b 100644 --- a/lib/slot_language/code/resolve_method.slot +++ b/lib/slot_language/code/resolve_method.slot @@ -1,8 +1,8 @@ # passed in? name and cache_entry -word! << name_ -cache_entry! << cache_entry_ +word! = name_ +cache_entry! = cache_entry_ # local var assignment -callable_method << cache_entry.cached_type.methods +callable_method = cache_entry.cached_type.methods while_start_label diff --git a/lib/slot_language/message_slot.rb b/lib/slot_language/message_slot.rb index b40418b7..81eb97ca 100644 --- a/lib/slot_language/message_slot.rb +++ b/lib/slot_language/message_slot.rb @@ -1,5 +1,8 @@ module SlotLanguage class MessageSlot + def to_s + "message" + end end end diff --git a/lib/slot_language/slot_compiler.rb b/lib/slot_language/slot_compiler.rb index e2b633df..f0489ca4 100644 --- a/lib/slot_language/slot_compiler.rb +++ b/lib/slot_language/slot_compiler.rb @@ -3,6 +3,7 @@ require "ast" module SlotLanguage class SlotCompiler < AST::Processor + DEBUG = false def self.compile(input) ast = Parser::CurrentRuby.parse( input ) @@ -16,7 +17,6 @@ module SlotLanguage not_implemented(node) end def on_send(statement) - #puts "Send #{statement}" kids = statement.children.dup receiver = process(kids.shift) || MessageSlot.new name = kids.shift @@ -24,12 +24,15 @@ module SlotLanguage return goto(name,kids) if(name == :goto) return check(name,receiver, kids) if(name == :==) return assign(receiver, name , kids) if(name.to_s.end_with?("=")) + puts "Send #{name} , #{receiver} kids=#{kids}" if DEBUG SlotMaker.new( name ) end def on_lvar(lvar) + puts "lvar #{lvar}" if DEBUG SlotMaker.new(lvar.children.first ) end def on_lvasgn( expression) + puts "lvasgn #{expression}" if DEBUG name = expression.children[0] value = process(expression.children[1]) LoadMaker.new(SlotMaker.new(name),value) @@ -37,6 +40,7 @@ module SlotLanguage alias :on_ivasgn :on_lvasgn def on_if(expression) + puts "if #{expression}" if DEBUG condition = process(expression.children[0]) condition.set_goto( process(expression.children[1]) ) condition @@ -48,7 +52,8 @@ module SlotLanguage process_all(exp) end end - def on_ivar expression + def on_ivar( expression) + puts "ivar #{expression}" if DEBUG SlotMaker.new(expression.children.first) end @@ -58,20 +63,22 @@ module SlotLanguage end def goto(name , args) # error handling would not hurt + puts "goto #{name} , #{args}" if DEBUG label = process(args.first) SlotMachine::Jump.new( label ) end def check(name , receiver , kids) raise "Only ==, not #{name}" unless name == :== 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) CheckMaker.new(name , receiver , right) end def assign(receiver , name , kids) name = name.to_s[0...-1].to_sym receiver.add_slot_name(name) - right = process kids.first + right = process kids.shift + puts "Assign #{name} , #{receiver}" if DEBUG LoadMaker.new(receiver,right) end end diff --git a/lib/slot_language/slot_maker.rb b/lib/slot_language/slot_maker.rb index e7b722a3..07c5b3f2 100644 --- a/lib/slot_language/slot_maker.rb +++ b/lib/slot_language/slot_maker.rb @@ -20,5 +20,9 @@ module SlotLanguage def slot_def(compiler) SlotMachine::SlotDefinition.new(:message , leaps) end + + def to_s + "message." + leaps.join(",") + end end end diff --git a/test/slot_language/test_slot_compiler.rb b/test/slot_language/test_slot_compiler.rb index ca7d898d..9f3cf136 100644 --- a/test/slot_language/test_slot_compiler.rb +++ b/test/slot_language/test_slot_compiler.rb @@ -56,5 +56,11 @@ module SlotLanguage assert_equal SlotMachine::Label , multi.first.class assert_equal SlotMachine::Jump , multi.last.class 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