diff --git a/lib/typed/ast/class_statement.rb b/lib/typed/ast/class_statement.rb index a1f3f8a7..48671542 100644 --- a/lib/typed/ast/class_statement.rb +++ b/lib/typed/ast/class_statement.rb @@ -1,9 +1,11 @@ module Typed - class ClassStatement < Statement - attr_accessor :name , :derives , :statements - end + module Tree + class ClassStatement < Statement + attr_accessor :name , :derives , :statements + end - class ClassField < Statement - attr_accessor :name , :type + class ClassField < Statement + attr_accessor :name , :type + end end end diff --git a/lib/typed/ast/function_statement.rb b/lib/typed/ast/function_statement.rb index 83a1017a..2f4ecbf3 100644 --- a/lib/typed/ast/function_statement.rb +++ b/lib/typed/ast/function_statement.rb @@ -1,5 +1,7 @@ module Typed - class FunctionStatement < Statement - attr_accessor :return_type , :name , :parameters, :statements , :receiver + module Tree + class FunctionStatement < Statement + attr_accessor :return_type , :name , :parameters, :statements , :receiver + end end end diff --git a/lib/typed/ast/to_code.rb b/lib/typed/ast/to_code.rb index 54accd53..dfb787c5 100644 --- a/lib/typed/ast/to_code.rb +++ b/lib/typed/ast/to_code.rb @@ -13,7 +13,7 @@ module Typed def on_class statement name , derives , statements = *statement - w = ClassStatement.new() + w = Tree::ClassStatement.new() w.name = name w.derives = derives.children.first w.statements = process(statements) @@ -22,7 +22,7 @@ module Typed def on_function statement return_type , name , parameters, statements , receiver = *statement - w = FunctionStatement.new() + w = Tree::FunctionStatement.new() w.return_type = return_type w.name = name.children.first w.parameters = parameters.to_a.collect do |p| diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index 12c39098..c790add5 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -1,7 +1,8 @@ module Typed - CompilerModules = [ "assignment" , "basic_values" , "call_site", "if_statement" , - "name_expression"] + CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , + "class_statement" , "if_statement" , "name_expression"] + CompilerModules.each do |mod| require_relative "compiler/" + mod end @@ -188,9 +189,6 @@ end require_relative "ast_helper" require_relative "ast/code" -require_relative "compiler/basic_values" -require_relative "compiler/class_field" -require_relative "compiler/class_statement" require_relative "compiler/collections" require_relative "compiler/field_def" require_relative "compiler/field_access" diff --git a/lib/typed/compiler/class_field.rb b/lib/typed/compiler/class_field.rb index b0acaaf7..c2926325 100644 --- a/lib/typed/compiler/class_field.rb +++ b/lib/typed/compiler/class_field.rb @@ -1,15 +1,14 @@ module Typed - Compiler.class_eval do + module ClassField def on_ClassField statement - #puts statement.inspect #type , name , value = *statement for_class = @clazz raise "no class" unless for_class index = for_class.instance_type.variable_index(statement.name) - #raise "class field already defined:#{name} for class #{for_class.name}" if index - #puts "Define field #{name} on class #{for_class.name}" + raise "class field already defined:#{name} for class #{for_class.name}" if index + for_class.instance_type.add_instance_variable( statement.name , statement.type ) return nil # statements don't reurn values, only expressions diff --git a/lib/typed/compiler/class_statement.rb b/lib/typed/compiler/class_statement.rb index 1a2dd9c9..4a26800e 100644 --- a/lib/typed/compiler/class_statement.rb +++ b/lib/typed/compiler/class_statement.rb @@ -1,9 +1,10 @@ module Typed - Compiler.class_eval do + module ClassStatement def on_ClassStatement statement - #puts statement.inspect + raise "classes dont yet play babushka, get coding #{name}" if @clazz + @clazz = Parfait::Space.object_space.get_class_by_name! statement.name #puts "Compiling class #{@clazz.name.inspect}" statement_value = process(statement.statements).last