adds ivar collection with tests
This commit is contained in:
parent
8942f42310
commit
d00fbb233e
@ -1,9 +1,30 @@
|
||||
module Vool
|
||||
class ClassStatement
|
||||
class ClassStatement < Statement
|
||||
attr_reader :name, :super_class_name , :body
|
||||
attr_reader :clazz
|
||||
|
||||
def initialize( name , supe , body)
|
||||
@name , @super_class_name , @body = name , supe , body
|
||||
@name , @super_class_name , @body = name , supe , (body || [])
|
||||
end
|
||||
|
||||
def collect(arr)
|
||||
@body.collect(arr)
|
||||
super
|
||||
end
|
||||
|
||||
def create_objects
|
||||
@clazz = Parfait.object_space.get_class_by_name(@name )
|
||||
if(@clazz)
|
||||
#FIXME super class check with "sup"
|
||||
else #existing class, don't overwrite type (parfait only?)
|
||||
@clazz = Parfait.object_space.create_class(@name , @super_class_name )
|
||||
#FIXME
|
||||
# ivar_hash = Passes::TypeCollector.new.collect(body)
|
||||
# @clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
||||
end
|
||||
body.create_objects
|
||||
# methods = create_methods(clazz , body)
|
||||
# compile_methods(clazz,methods)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,6 +12,10 @@ module Vool
|
||||
|
||||
class InstanceVariable < Statement
|
||||
include Named
|
||||
# used to collect type information
|
||||
def add_ivar( array )
|
||||
array << @name
|
||||
end
|
||||
end
|
||||
|
||||
class ClassVariable < Statement
|
||||
|
12
lib/vool/vool_compiler.rb
Normal file
12
lib/vool/vool_compiler.rb
Normal file
@ -0,0 +1,12 @@
|
||||
require_relative "ruby_compiler"
|
||||
|
||||
module Vool
|
||||
class VoolCompiler
|
||||
|
||||
def self.compile( ruby_source )
|
||||
statements = RubyCompiler.compile( ruby_source )
|
||||
statements.create_objects
|
||||
statements
|
||||
end
|
||||
end
|
||||
end
|
32
test/vool/compilers/test_variables.rb
Normal file
32
test/vool/compilers/test_variables.rb
Normal file
@ -0,0 +1,32 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
module Compilers
|
||||
class TestIvarCollect < MiniTest::Test
|
||||
|
||||
def compile(input)
|
||||
lst = VoolCompiler.compile( input )
|
||||
vars = []
|
||||
lst.collect([]).each do |node|
|
||||
node.add_ivar(vars)
|
||||
end
|
||||
vars
|
||||
end
|
||||
|
||||
def test_instance_collect
|
||||
vars = compile( "@var" )
|
||||
assert_equal :var , vars.first
|
||||
end
|
||||
|
||||
def test_return_collect
|
||||
vars = compile( "return @var" )
|
||||
assert_equal :var , vars.first
|
||||
end
|
||||
|
||||
def ttest_assign_collect
|
||||
vars = compile( "@var = 5" )
|
||||
assert_equal :var , vars.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/vool/helper.rb
Normal file
18
test/vool/helper.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
module CompilerHelper
|
||||
|
||||
def in_Test(statements)
|
||||
"class Test ; #{statements} ; end"
|
||||
end
|
||||
|
||||
def in_Space(statements)
|
||||
"class Space ; #{statements} ; end"
|
||||
end
|
||||
|
||||
def as_main(statements)
|
||||
in_Space("def main ; #{statements}; end")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user