add types hash to space

This commit is contained in:
Torsten Ruger 2016-12-07 23:34:45 +02:00
parent fe195df10e
commit 266a04040b
4 changed files with 21 additions and 8 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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