diff --git a/lib/register/boot.rb b/lib/register/boot.rb index 5e00bb14..8eb5ff4b 100644 --- a/lib/register/boot.rb +++ b/lib/register/boot.rb @@ -51,14 +51,19 @@ module Register # once we have the types we can create the space by creating the instance variables # by hand (can't call new yet as that uses the space) def boot_space - space_dict = object_with_type Parfait::Dictionary - space_dict.keys = object_with_type Parfait::List - space_dict.values = object_with_type Parfait::List @space = object_with_type Parfait::Space - @space.classes = space_dict + @space.classes = make_dictionary + @space.types = make_dictionary Parfait::Space.set_object_space @space end + def make_dictionary + dict = object_with_type Parfait::Dictionary + dict.keys = object_with_type Parfait::List + dict.values = object_with_type Parfait::List + dict + end + # when running code instantiates a class, a type is created automatically # but even to get our space up, we have already instantiated all types # so we have to continue and allocate classes and fill the data by hand @@ -117,7 +122,7 @@ module Register :Object => {}, :Kernel => {}, #fix, kernel is a class, but should be a module :BinaryCode => {:char_length => :Integer} , - :Space => {:classes => :Dictionary , :first_message => :Message}, + :Space => {:classes => :Dictionary , :types => :Dictionary , :first_message => :Message}, :Frame => {:next_frame => :Frame, :indexed_length => :Integer}, :Type => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} , :Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word, diff --git a/lib/typed/parfait/space.rb b/lib/typed/parfait/space.rb index 4515b384..ec3f0e7e 100644 --- a/lib/typed/parfait/space.rb +++ b/lib/typed/parfait/space.rb @@ -24,7 +24,7 @@ module Parfait def initialize raise "Space can not be instantiated by new, you'd need a space to do so. Chicken and egg" end - attributes [:classes , :first_message] + attributes [:classes , :types, :first_message] # need a two phase init for the object space (and generally parfait) because the space # is an interconnected graph, so not everthing is ready @@ -36,12 +36,16 @@ module Parfait message.set_caller self.first_message message = self.first_message end + classes.each do |name , cl| + types[cl.instance_type.hash] = cl.instance_type + end end # Make the object space globally available def self.object_space @@object_space end + # TODO Must get rid of the setter def self.set_object_space space @@object_space = space diff --git a/test/typed/parfait/test_space.rb b/test/typed/parfait/test_space.rb index f24d0f11..fa5544be 100644 --- a/test/typed/parfait/test_space.rb +++ b/test/typed/parfait/test_space.rb @@ -29,6 +29,10 @@ class TestSpace < MiniTest::Test end end + def test_types + assert @machine.space.types.is_a? Parfait::Dictionary + end + def test_classes_type classes.each do |name| assert_equal Parfait::Type , @machine.space.classes[name].get_type.class diff --git a/test/typed/type/test_basic.rb b/test/typed/type/test_basic.rb index 3b49d14b..ccca952b 100644 --- a/test/typed/type/test_basic.rb +++ b/test/typed/type/test_basic.rb @@ -49,7 +49,7 @@ class BasicType < MiniTest::Test assert_equal Parfait::Class , oc.class type = oc.instance_type assert_equal Parfait::Type , type.class - assert_equal 1 , type.instance_names.get_length + assert_equal 1 , type.instance_names.get_length , type.instance_names.inspect assert_equal type.first , :type end @@ -59,7 +59,7 @@ class BasicType < MiniTest::Test assert_equal Parfait::Space , space.class type = space.get_type assert_equal Parfait::Type , type.class - assert_equal 3 , type.instance_names.get_length + assert_equal 4 , type.instance_names.get_length assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.name , :Space end