SlotLanguageExploration

This commit is contained in:
Torsten Rüger 2019-10-04 21:06:22 +03:00
parent 901f7b0132
commit 9885841eb4
5 changed files with 69 additions and 5 deletions

View File

@ -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

View File

@ -16,12 +16,30 @@ module SlotLanguage
not_implemented(node) not_implemented(node)
end end
def on_send(statement) def on_send(statement)
#puts 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
raise "Kids #{kids}" unless kids.empty? return label(name) if(name.to_s.end_with?("_label"))
SlotMaker.new( name , receiver ) SlotMaker.new( name , receiver )
end 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
end end
require_relative "named_slot" require_relative "named_slot"

View File

@ -1,7 +1,8 @@
module SlotLanguage module SlotLanguage
class SlotMaker class SlotMaker
attr_reader :name
def initialize(name , more) def initialize(name , more)
@name = name
end end
end end
end end

View File

@ -2,14 +2,24 @@ require_relative "helper"
module SlotLanguage module SlotLanguage
class TestSlotCompiler < MiniTest::Test class TestSlotCompiler < MiniTest::Test
include SlotHelper
def test_init def test_init
assert SlotCompiler.new assert SlotCompiler.new
end end
def test_compile def test_compile
assert_equal SlotMaker , SlotCompiler.compile("a").class assert_equal SlotMaker , compile("a").class
end end
def test_fail_args # def test_fail_args
assert_raises{ SlotCompiler.compile("a(1)")} # 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 end
end end

View File

@ -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