diff --git a/lib/slot_language/code/resolve_method.slot b/lib/slot_language/code/resolve_method.slot new file mode 100644 index 00000000..6c05b06e --- /dev/null +++ b/lib/slot_language/code/resolve_method.slot @@ -0,0 +1,22 @@ +# passed in? name and cache_entry +word! << name_ +cache_entry! << cache_entry_ +# local var assignment +callable_method << cache_entry.cached_type.methods + +while_start_label + +goto(exit_label) if( nil == callable_method) + +goto(ok_label) if(callable_method.name == word) + +callable_method = callable_method.next_callable + +goto(while_start_label) + +exit_label + +MethodMissing.new(compiler.source_name , word.symbol).to_risc(compiler) + +ok_label +cache_entry.cached_method == callable_method diff --git a/lib/slot_language/slot_compiler.rb b/lib/slot_language/slot_compiler.rb index d8b488cc..bb7e3b20 100644 --- a/lib/slot_language/slot_compiler.rb +++ b/lib/slot_language/slot_compiler.rb @@ -16,12 +16,30 @@ module SlotLanguage not_implemented(node) end def on_send(statement) + #puts statement kids = statement.children.dup receiver = process(kids.shift) || MessageSlot.new name = kids.shift - raise "Kids #{kids}" unless kids.empty? + return label(name) if(name.to_s.end_with?("_label")) SlotMaker.new( name , receiver ) end + def on_lvasgn expression + #puts expression + name = expression.children[0] + value = process(expression.children[1]) + Sol::LocalAssignment.new(name,value) + end + def on_ivar expression + Sol::InstanceVariable.new(instance_name(expression.children.first)) + 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 end end require_relative "named_slot" diff --git a/lib/slot_language/slot_maker.rb b/lib/slot_language/slot_maker.rb index 767445a1..7fce2759 100644 --- a/lib/slot_language/slot_maker.rb +++ b/lib/slot_language/slot_maker.rb @@ -1,7 +1,8 @@ module SlotLanguage class SlotMaker + attr_reader :name def initialize(name , more) - + @name = name end end end diff --git a/test/slot_language/test_slot_compiler.rb b/test/slot_language/test_slot_compiler.rb index 5e851001..ce741a3d 100644 --- a/test/slot_language/test_slot_compiler.rb +++ b/test/slot_language/test_slot_compiler.rb @@ -2,14 +2,24 @@ require_relative "helper" module SlotLanguage class TestSlotCompiler < MiniTest::Test + include SlotHelper + def test_init assert SlotCompiler.new end def test_compile - assert_equal SlotMaker , SlotCompiler.compile("a").class + assert_equal SlotMaker , compile("a").class end - def test_fail_args - assert_raises{ SlotCompiler.compile("a(1)")} + # def test_fail_args + # assert_raises{ compile("a(1)")} + # end + def test_label + label = compile("while_label") + assert_equal SlotMachine::Label , label.class + assert_equal :while_label , label.name + end + def test_slot_load + compile("a = @b") end end end diff --git a/test/slot_language/test_slot_maker.rb b/test/slot_language/test_slot_maker.rb new file mode 100644 index 00000000..ad8b4064 --- /dev/null +++ b/test/slot_language/test_slot_maker.rb @@ -0,0 +1,13 @@ +require_relative "helper" + +module SlotLanguage + class TestSlotMaker < MiniTest::Test + include SlotHelper + + def test_label + label = compile("while_label") + assert_equal SlotMachine::Label , label.class + assert_equal :while_label , label.name + end + end +end