cleaned up chained assignment and conditional

Making this almost usable
This commit is contained in:
Torsten Rüger 2020-02-13 19:45:47 +07:00
parent a153fde3f0
commit 24ceb20281
5 changed files with 53 additions and 24 deletions

View File

@ -1,8 +0,0 @@
module SlotLanguage
class MessageSlot
def to_s
"message"
end
end
end

View File

@ -1,5 +0,0 @@
module SlotLanguage
class NamedSlot
end
end

View File

@ -110,17 +110,16 @@ module SlotLanguage
end end
def assign(receiver , name , kids) def assign(receiver , name , kids)
raise name.to_s receiver = process(receiver)
name = name.to_s[0...-1].to_sym
receiver.add_slot_name(name)
right = process kids.shift
puts "Assign #{name} , #{receiver}" if DEBUG 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) Assignment.new(receiver,right)
end end
end end
end end
require_relative "named_slot"
require_relative "message_slot"
require_relative "variable" require_relative "variable"
require_relative "assignment" require_relative "assignment"
require_relative "macro_maker" require_relative "macro_maker"

View File

@ -44,12 +44,21 @@ module SlotLanguage
class TestAssignment3 < MiniTest::Test class TestAssignment3 < MiniTest::Test
include SlotHelper include SlotHelper
def est_slot_load_linst_trav2 def test_inst_ass
assert_equal Assignment , compile_class("@a.c = b.c") 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 end
def est_assign2 def test_local_ass
assign = compile("c.next = d") assign = compile("a.b = c")
assert_equal Assignment , assign.class 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 end
end end

View File

@ -55,4 +55,38 @@ module SlotLanguage
assert_equal :c , @expr.last.right.name assert_equal :c , @expr.last.right.name
end end
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 end