making types private in space
turned out to be unnecessary, but still better
This commit is contained in:
parent
ef66a87527
commit
7f06e00ccd
@ -42,6 +42,8 @@ module Parfait
|
|||||||
message = @first_message
|
message = @first_message
|
||||||
end
|
end
|
||||||
@classes.each do |name , cl|
|
@classes.each do |name , cl|
|
||||||
|
raise "upps #{cl.instance_type.hash}" unless cl.instance_type.hash.is_a?(Fixnum)
|
||||||
|
|
||||||
@types[cl.instance_type.hash] = cl.instance_type
|
@types[cl.instance_type.hash] = cl.instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -50,7 +52,7 @@ module Parfait
|
|||||||
[:classes , :types, :first_message]
|
[:classes , :types, :first_message]
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :types , :classes , :first_message
|
attr_reader :classes , :first_message
|
||||||
|
|
||||||
def each_type
|
def each_type
|
||||||
@types.values.each do |type|
|
@types.values.each do |type|
|
||||||
@ -58,6 +60,18 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_type(type)
|
||||||
|
hash = type.hash
|
||||||
|
raise "upps #{hash}" unless hash.is_a?(Fixnum)
|
||||||
|
was = @types[hash]
|
||||||
|
return was if was
|
||||||
|
@types[hash] = type
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_type_for( hash )
|
||||||
|
@types[hash]
|
||||||
|
end
|
||||||
|
|
||||||
# all methods form all types
|
# all methods form all types
|
||||||
def collect_methods
|
def collect_methods
|
||||||
methods = []
|
methods = []
|
||||||
|
@ -42,9 +42,7 @@ module Parfait
|
|||||||
def self.for_hash( object_class , hash)
|
def self.for_hash( object_class , hash)
|
||||||
hash = {type: object_class.name }.merge(hash) unless hash[:type]
|
hash = {type: object_class.name }.merge(hash) unless hash[:type]
|
||||||
new_type = Type.new( object_class , hash)
|
new_type = Type.new( object_class , hash)
|
||||||
code = hash_code_for_hash( hash )
|
Parfait.object_space.add_type(new_type)
|
||||||
Parfait.object_space.types[code] = new_type
|
|
||||||
new_type
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hash_code_for_hash( dict )
|
def self.hash_code_for_hash( dict )
|
||||||
@ -152,9 +150,6 @@ module Parfait
|
|||||||
raise "No nil type" unless type
|
raise "No nil type" unless type
|
||||||
hash = to_hash
|
hash = to_hash
|
||||||
hash[name] = type
|
hash[name] = type
|
||||||
code = Type.hash_code_for_hash( hash )
|
|
||||||
existing = Parfait.object_space.types[code]
|
|
||||||
return existing if existing
|
|
||||||
return Type.for_hash( @object_class , hash)
|
return Type.for_hash( @object_class , hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ class TestSpace < MiniTest::Test
|
|||||||
@machine = Register.machine.boot
|
@machine = Register.machine.boot
|
||||||
@space = Parfait.object_space
|
@space = Parfait.object_space
|
||||||
end
|
end
|
||||||
|
|
||||||
def classes
|
def classes
|
||||||
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
||||||
end
|
end
|
||||||
@ -16,6 +17,7 @@ class TestSpace < MiniTest::Test
|
|||||||
def test_global_space
|
def test_global_space
|
||||||
assert_equal Parfait::Space , Parfait.object_space.class
|
assert_equal Parfait::Space , Parfait.object_space.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_integer
|
def test_integer
|
||||||
int = Parfait.object_space.get_class_by_name :Integer
|
int = Parfait.object_space.get_class_by_name :Integer
|
||||||
assert_equal 3, int.instance_type.method_names.get_length
|
assert_equal 3, int.instance_type.method_names.get_length
|
||||||
@ -29,7 +31,7 @@ class TestSpace < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_types
|
def test_types
|
||||||
assert @space.types.is_a? Parfait::Dictionary
|
assert @space.instance_variable_get("@types").is_a? Parfait::Dictionary
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_types_each
|
def test_types_each
|
||||||
@ -38,6 +40,13 @@ class TestSpace < MiniTest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_types_hashes
|
||||||
|
types = @space.instance_variable_get("@types")
|
||||||
|
types.each do |has , type|
|
||||||
|
assert has.is_a?(Fixnum) , has.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_classes_type
|
def test_classes_type
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
assert_equal Parfait::Type , @space.classes[name].get_type.class
|
assert_equal Parfait::Type , @space.classes[name].get_type.class
|
||||||
|
@ -5,7 +5,7 @@ class TypeHash < MiniTest::Test
|
|||||||
def setup
|
def setup
|
||||||
Register.machine.boot
|
Register.machine.boot
|
||||||
@space = Parfait.object_space
|
@space = Parfait.object_space
|
||||||
@types = @space.types
|
@types = @space.instance_variable_get("@types")
|
||||||
@first = @types.values.first
|
@first = @types.values.first
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ class TypeHash < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_length
|
def test_length
|
||||||
assert @types.length > 16
|
assert @types.length > 11
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_two_hashs_not_equal
|
def test_two_hashs_not_equal
|
||||||
@ -22,12 +22,12 @@ class TypeHash < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal "Word_Type" , @types.values.first.name
|
assert_equal "BinaryCode_Type" , @types.values.first.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_hash
|
def test_to_hash
|
||||||
assert_equal "Word_Type" , @first.name
|
assert_equal "BinaryCode_Type" , @first.name
|
||||||
assert_equal :Word , @first.object_class.name
|
assert_equal :BinaryCode , @first.object_class.name
|
||||||
hash = @first.to_hash
|
hash = @first.to_hash
|
||||||
assert_equal :Type , @first.types.first
|
assert_equal :Type , @first.types.first
|
||||||
assert_equal hash[:type] , :Type
|
assert_equal hash[:type] , :Type
|
||||||
|
Loading…
Reference in New Issue
Block a user