adds instance and class variables to vool
This commit is contained in:
parent
83ab197d03
commit
5f70067fa0
@ -92,6 +92,15 @@ module Vool
|
|||||||
def on_lvar expression
|
def on_lvar expression
|
||||||
LocalVariable.new(expression.children.first)
|
LocalVariable.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_ivar expression
|
||||||
|
InstanceVariable.new(expression.children.first.to_s[1 .. -1].to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_cvar expression
|
||||||
|
ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
def on_lvasgn expression
|
def on_lvasgn expression
|
||||||
name = expression.children[0]
|
name = expression.children[0]
|
||||||
value = process(expression.children[1])
|
value = process(expression.children[1])
|
||||||
|
@ -9,4 +9,13 @@ module Vool
|
|||||||
class LocalVariable < Statement
|
class LocalVariable < Statement
|
||||||
include Named
|
include Named
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class InstanceVariable < Statement
|
||||||
|
include Named
|
||||||
|
end
|
||||||
|
|
||||||
|
class ClassVariable < Statement
|
||||||
|
include Named
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,5 +10,26 @@ module Vool
|
|||||||
# assert_equal SendStatement , lst.class
|
# assert_equal SendStatement , lst.class
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
def test_instance_basic
|
||||||
|
lst = Compiler.compile( "@var" )
|
||||||
|
assert_equal InstanceVariable , lst.class
|
||||||
|
assert_equal :var , lst.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_instance_return
|
||||||
|
lst = Compiler.compile( "return @var" )
|
||||||
|
assert_equal InstanceVariable , lst.return_value.class
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_class_basic
|
||||||
|
lst = Compiler.compile( "@@var" )
|
||||||
|
assert_equal ClassVariable , lst.class
|
||||||
|
assert_equal :var , lst.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_class_return
|
||||||
|
lst = Compiler.compile( "return @@var" )
|
||||||
|
assert_equal ClassVariable , lst.return_value.class
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user