add types hash to space
This commit is contained in:
parent
fe195df10e
commit
266a04040b
@ -51,14 +51,19 @@ module Register
|
|||||||
# once we have the types we can create the space by creating the instance variables
|
# 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)
|
# by hand (can't call new yet as that uses the space)
|
||||||
def boot_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 = object_with_type Parfait::Space
|
||||||
@space.classes = space_dict
|
@space.classes = make_dictionary
|
||||||
|
@space.types = make_dictionary
|
||||||
Parfait::Space.set_object_space @space
|
Parfait::Space.set_object_space @space
|
||||||
end
|
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
|
# when running code instantiates a class, a type is created automatically
|
||||||
# but even to get our space up, we have already instantiated all types
|
# 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
|
# so we have to continue and allocate classes and fill the data by hand
|
||||||
@ -117,7 +122,7 @@ module Register
|
|||||||
:Object => {},
|
:Object => {},
|
||||||
:Kernel => {}, #fix, kernel is a class, but should be a module
|
:Kernel => {}, #fix, kernel is a class, but should be a module
|
||||||
:BinaryCode => {:char_length => :Integer} ,
|
: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},
|
:Frame => {:next_frame => :Frame, :indexed_length => :Integer},
|
||||||
:Type => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} ,
|
:Type => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} ,
|
||||||
:Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word,
|
:Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word,
|
||||||
|
@ -24,7 +24,7 @@ module Parfait
|
|||||||
def initialize
|
def initialize
|
||||||
raise "Space can not be instantiated by new, you'd need a space to do so. Chicken and egg"
|
raise "Space can not be instantiated by new, you'd need a space to do so. Chicken and egg"
|
||||||
end
|
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
|
# need a two phase init for the object space (and generally parfait) because the space
|
||||||
# is an interconnected graph, so not everthing is ready
|
# is an interconnected graph, so not everthing is ready
|
||||||
@ -36,12 +36,16 @@ module Parfait
|
|||||||
message.set_caller self.first_message
|
message.set_caller self.first_message
|
||||||
message = self.first_message
|
message = self.first_message
|
||||||
end
|
end
|
||||||
|
classes.each do |name , cl|
|
||||||
|
types[cl.instance_type.hash] = cl.instance_type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make the object space globally available
|
# Make the object space globally available
|
||||||
def self.object_space
|
def self.object_space
|
||||||
@@object_space
|
@@object_space
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO Must get rid of the setter
|
# TODO Must get rid of the setter
|
||||||
def self.set_object_space space
|
def self.set_object_space space
|
||||||
@@object_space = space
|
@@object_space = space
|
||||||
|
@ -29,6 +29,10 @@ class TestSpace < MiniTest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_types
|
||||||
|
assert @machine.space.types.is_a? Parfait::Dictionary
|
||||||
|
end
|
||||||
|
|
||||||
def test_classes_type
|
def test_classes_type
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
assert_equal Parfait::Type , @machine.space.classes[name].get_type.class
|
assert_equal Parfait::Type , @machine.space.classes[name].get_type.class
|
||||||
|
@ -49,7 +49,7 @@ class BasicType < MiniTest::Test
|
|||||||
assert_equal Parfait::Class , oc.class
|
assert_equal Parfait::Class , oc.class
|
||||||
type = oc.instance_type
|
type = oc.instance_type
|
||||||
assert_equal Parfait::Type , type.class
|
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
|
assert_equal type.first , :type
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class BasicType < MiniTest::Test
|
|||||||
assert_equal Parfait::Space , space.class
|
assert_equal Parfait::Space , space.class
|
||||||
type = space.get_type
|
type = space.get_type
|
||||||
assert_equal Parfait::Type , type.class
|
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.class , Parfait::Class
|
||||||
assert_equal type.object_class.name , :Space
|
assert_equal type.object_class.name , :Space
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user