cleaned up chained assignment and conditional
Making this almost usable
This commit is contained in:
parent
a153fde3f0
commit
24ceb20281
@ -1,8 +0,0 @@
|
||||
module SlotLanguage
|
||||
class MessageSlot
|
||||
|
||||
def to_s
|
||||
"message"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +0,0 @@
|
||||
module SlotLanguage
|
||||
class NamedSlot
|
||||
|
||||
end
|
||||
end
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user