test correct instance_type creation

so ivar collection happens
and a type is created from the names
This commit is contained in:
Torsten Ruger 2017-04-08 19:20:11 +03:00
parent 96f8bf61ca
commit af196c17d3
5 changed files with 41 additions and 16 deletions

View File

@ -16,11 +16,14 @@ module Vool
@clazz = Parfait.object_space.get_class_by_name(@name ) @clazz = Parfait.object_space.get_class_by_name(@name )
if(@clazz) if(@clazz)
#FIXME super class check with "sup" #FIXME super class check with "sup"
else #existing class, don't overwrite type (parfait only?) #existing class, don't overwrite type (parfait only?)
else
@clazz = Parfait.object_space.create_class(@name , @super_class_name ) @clazz = Parfait.object_space.create_class(@name , @super_class_name )
#FIXME vars = []
# ivar_hash = Passes::TypeCollector.new.collect(body) @body.collect([]).each { |node| node.add_ivar(vars) }
# @clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) ) ivar_hash = {}
vars.each { |var| ivar_hash[var] = :Object }
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end end
body.collect([]).each {|node| node.set_class(@clazz) } body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects body.create_objects

View File

@ -7,7 +7,6 @@ module Vool
end end
def collect(arr) def collect(arr)
@args.each{ |arg| arg.collect(arr)}
@body.collect(arr) @body.collect(arr)
super super
end end
@ -28,22 +27,15 @@ module Vool
def make_type( ) def make_type( )
type_hash = {} type_hash = {}
@args.each do |arg| @args.each {|arg| type_hash[arg.children[0]] = :Object }
puts "ARG #{arg}"
type_hash[arg.children[0]] = :Object
end
Parfait::NamedList.type_for( type_hash ) Parfait::NamedList.type_for( type_hash )
end end
def make_locals def make_locals
type_hash = {} type_hash = {}
vars = [] vars = []
@body.collect([]).each do |node| @body.collect([]).each { |node| node.add_local(vars) }
node.add_local(vars) vars.each { |var| type_hash[var] = :Object }
end
vars.each do |var|
type_hash[var] = :Object
end
Parfait::NamedList.type_for( type_hash ) Parfait::NamedList.type_for( type_hash )
end end

View File

@ -1,4 +1,5 @@
require_relative "helper" require_relative "helper"
require_relative "test_ivar_collect" require_relative "test_ivar_collect"
require_relative "test_local_collect" require_relative "test_local_collect"
require_relative "test_class_compiler"
require_relative "test_method_compiler" require_relative "test_method_compiler"

View File

@ -0,0 +1,29 @@
require_relative "helper"
module Vool
class TestClassCompiler < MiniTest::Test
include CompilerHelper
def setup
Risc.machine.boot
end
def compile_in_test input
VoolCompiler.compile in_Test(input)
itest = Parfait.object_space.get_class_by_name(:Test)
assert itest
itest
end
def test_compile_class_one
itest = compile_in_test "def meth; @ivar; end"
assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
end
def test_compile_class_two
itest = compile_in_test "def meth; @ivar; end;def meth2(arg); @trivar = 5; end"
assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect
end
end
end

View File

@ -1,7 +1,7 @@
require_relative "helper" require_relative "helper"
module Vool module Vool
class TestVoolCompiler < MiniTest::Test class TestMethodCompiler < MiniTest::Test
include CompilerHelper include CompilerHelper
def setup def setup