diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index 12d54652..e6e0e4fe 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -29,7 +29,6 @@ module Vool vars.each { |var| ivar_hash[var] = :Object } @clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) ) end - puts "BODY is #{body.class}" body.collect([]).each {|node| node.set_class(@clazz) } body.create_objects end diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index 4bfe910a..8c1591b7 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -27,7 +27,7 @@ module Vool def make_type( ) type_hash = {} - @args.each {|arg| type_hash[arg.children[0]] = :Object } + @args.each {|arg| type_hash[arg] = :Object } Parfait::NamedList.type_for( type_hash ) end diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index 9b78c4ae..864c5b2a 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -21,6 +21,10 @@ module Vool @statements.each { |s| s.collect(arr) } super end + + def create_objects + @statements.each{ |s| s.create_objects } + end end class ScopeStatement < Statements diff --git a/test/vool/compilers/test_class_compiler.rb b/test/vool/compilers/test_class_compiler.rb index b5a9f416..7eb413b5 100644 --- a/test/vool/compilers/test_class_compiler.rb +++ b/test/vool/compilers/test_class_compiler.rb @@ -25,5 +25,40 @@ module Vool assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect end + def test_doesnt_create_existing_clas + space_class = Parfait.object_space.get_class_by_name(:Space) + VoolCompiler.compile "class Space ; end" + clazz = Parfait.object_space.get_class_by_name(:Space) + assert_equal clazz , space_class + end + + def test_creates_class_without_deriviation + VoolCompiler.compile "class Testing ; end" + clazz = Parfait.object_space.get_class_by_name(:Testing) + assert clazz , "No classes created" + assert_equal :Object , clazz.super_class_name + end + + def test_creates_class_with_deriviation + VoolCompiler.compile "class Test2 < List ;end" + clazz = Parfait.object_space.get_class_by_name(:Test2) + assert clazz, "No classes created" + assert_equal :List , clazz.super_class_name + end + + def test_space_is_unchanged_by_compile + space1 = Parfait.object_space.get_class_by_name(:Space) + VoolCompiler.compile "class Space ;end" + space2 = Parfait.object_space.get_class_by_name(:Space) + assert_equal space1 , space2 + end + + def test_space_type_is_unchanged_by_compile + space1 = Parfait.object_space.get_class_by_name(:Space).instance_type + VoolCompiler.compile "class Space ;end" + space2 = Parfait.object_space.get_class_by_name(:Space).instance_type + assert_equal space1 , space2 + end + end end diff --git a/test/vool/compilers/test_method_compiler.rb b/test/vool/compilers/test_method_compiler.rb index 386e1153..0f2c808c 100644 --- a/test/vool/compilers/test_method_compiler.rb +++ b/test/vool/compilers/test_method_compiler.rb @@ -14,29 +14,34 @@ module Vool test.get_method(:meth) end - def test_method_statement_has_class - clazz = VoolCompiler.compile in_Test("def meth; @ivar ;end") - assert_equal Parfait::Class , clazz.body.clazz.class - end - def test_creates_method_in_class - method = create_method - assert method , "No method created" - assert_equal Rubyx::RubyMethod , method.class - end def test_method_has_source method = create_method assert_equal Vool::InstanceVariable , method.source.class end + def test_method_has_no_locals + method = create_method + assert_equal 1 , method.locals_type.instance_length + end + def test_method_has_no_args method = create_method assert_equal 1 , method.args_type.instance_length end - def test_method_has_no_locals + def test_creates_method_in_class method = create_method - assert_equal 1 , method.locals_type.instance_length + assert method , "No method created" + assert_equal Rubyx::RubyMethod , method.class end + + def test_method_statement_has_class + clazz = VoolCompiler.compile in_Test("def meth; @ivar ;end") + assert_equal ScopeStatement , clazz.body.class + assert_equal MethodStatement , clazz.body.statements.first.class + assert_equal Parfait::Class , clazz.body.statements.first.clazz.class + end + def test_method_has_one_local VoolCompiler.compile in_Test("def meth; local = 5 ;end") test = Parfait.object_space.get_class_by_name(:Test)