From 24ceb20281975bb13b83bddba3b445060817c8ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Thu, 13 Feb 2020 19:45:47 +0700 Subject: [PATCH] cleaned up chained assignment and conditional Making this almost usable --- lib/slot_language/message_slot.rb | 8 ------- lib/slot_language/named_slot.rb | 5 ---- lib/slot_language/slot_compiler.rb | 11 ++++----- test/slot_language/test_assignment.rb | 19 +++++++++++---- test/slot_language/test_equal_goto.rb | 34 +++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 24 deletions(-) delete mode 100644 lib/slot_language/message_slot.rb delete mode 100644 lib/slot_language/named_slot.rb diff --git a/lib/slot_language/message_slot.rb b/lib/slot_language/message_slot.rb deleted file mode 100644 index 81eb97ca..00000000 --- a/lib/slot_language/message_slot.rb +++ /dev/null @@ -1,8 +0,0 @@ -module SlotLanguage - class MessageSlot - - def to_s - "message" - end - end -end diff --git a/lib/slot_language/named_slot.rb b/lib/slot_language/named_slot.rb deleted file mode 100644 index 15ded2b6..00000000 --- a/lib/slot_language/named_slot.rb +++ /dev/null @@ -1,5 +0,0 @@ -module SlotLanguage - class NamedSlot - - end -end diff --git a/lib/slot_language/slot_compiler.rb b/lib/slot_language/slot_compiler.rb index c03430e2..dee609ac 100644 --- a/lib/slot_language/slot_compiler.rb +++ b/lib/slot_language/slot_compiler.rb @@ -110,17 +110,16 @@ module SlotLanguage end def assign(receiver , name , kids) - raise name.to_s - name = name.to_s[0...-1].to_sym - receiver.add_slot_name(name) - right = process kids.shift + receiver = process(receiver) puts "Assign #{name} , #{receiver}" if DEBUG + raise "Only one arg #{kids}" unless kids.length == 1 + right = process kids.shift + name = name.to_s[0...-1].to_sym + receiver.chained(Variable.new(name)) Assignment.new(receiver,right) end end end -require_relative "named_slot" -require_relative "message_slot" require_relative "variable" require_relative "assignment" require_relative "macro_maker" diff --git a/test/slot_language/test_assignment.rb b/test/slot_language/test_assignment.rb index a240437b..85e956c5 100644 --- a/test/slot_language/test_assignment.rb +++ b/test/slot_language/test_assignment.rb @@ -44,12 +44,21 @@ module SlotLanguage class TestAssignment3 < MiniTest::Test include SlotHelper - def est_slot_load_linst_trav2 - assert_equal Assignment , compile_class("@a.c = b.c") + def test_inst_ass + assign = compile("@a.b = c") + assert_equal Assignment , assign.class + assert_equal MessageVariable , assign.left.class + assert_equal :a , assign.left.name + assert_equal Variable , assign.left.chain.class + assert_equal :b , assign.left.chain.name end - def est_assign2 - assign = compile("c.next = d") - assert_equal Assignment , assign.class + def test_local_ass + assign = compile("a.b = c") + assert_equal Assignment , assign.class + assert_equal Variable , assign.left.class + assert_equal :a , assign.left.name + assert_equal Variable , assign.left.chain.class + assert_equal :b , assign.left.chain.name end end end diff --git a/test/slot_language/test_equal_goto.rb b/test/slot_language/test_equal_goto.rb index 12cc7903..92b63f0d 100644 --- a/test/slot_language/test_equal_goto.rb +++ b/test/slot_language/test_equal_goto.rb @@ -55,4 +55,38 @@ module SlotLanguage assert_equal :c , @expr.last.right.name end end + class TestEqualGotoChain < MiniTest::Test + include SlotHelper + def setup + @expr = compile("goto(start_label) if( a.b == c)") + end + def test_eq + assert_equal EqualGoto , @expr.class + end + def test_left + assert_equal Variable , @expr.left.class + assert_equal :a , @expr.left.name + end + def test_left_chain + assert_equal Variable , @expr.left.chain.class + assert_equal :b , @expr.left.chain.name + end + end + class TestEqualGotoChain2 < MiniTest::Test + include SlotHelper + def setup + @expr = compile("goto(start_label) if( a == @b.c)") + end + def test_eq + assert_equal EqualGoto , @expr.class + end + def test_left + assert_equal MessageVariable , @expr.right.class + assert_equal :b , @expr.right.name + end + def test_left_chain + assert_equal Variable , @expr.right.chain.class + assert_equal :c , @expr.right.chain.name + end + end end