adds instance and class variables to vool

This commit is contained in:
Torsten Ruger 2017-04-04 14:04:35 +03:00
parent 83ab197d03
commit 5f70067fa0
3 changed files with 39 additions and 0 deletions

View File

@ -92,6 +92,15 @@ module Vool
def on_lvar expression
LocalVariable.new(expression.children.first)
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
name = expression.children[0]
value = process(expression.children[1])

View File

@ -9,4 +9,13 @@ module Vool
class LocalVariable < Statement
include Named
end
class InstanceVariable < Statement
include Named
end
class ClassVariable < Statement
include Named
end
end

View File

@ -10,5 +10,26 @@ module Vool
# assert_equal SendStatement , lst.class
# 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