Introduce singleton types
Just for future, as this gives us a way to know immediately in the type, which represent normal, and which singleton classes Also instantiate singleton class lazily (with singleton type) This makes the type of class single, ie unique, immediately when it is used, ie methods or variables defined. Fixes a design mistake, where all singletonn classes shared the same type, and thus unique methods per class were impossible (Also some misc in commit)
This commit is contained in:
@ -48,6 +48,20 @@ module Parfait
|
||||
@space.get_class.add_instance_variable(:counter , :Integer)
|
||||
assert before != @space.get_class.instance_type.hash
|
||||
end
|
||||
|
||||
def test_has_single
|
||||
assert_equal SingletonClass , @try.single_class.class
|
||||
end
|
||||
def test_before_not_single_type
|
||||
assert_equal false , @try.type.is_single?
|
||||
end
|
||||
def test_single_type_not_class
|
||||
hash_after = @try.single_class.instance_type.hash
|
||||
assert_equal @try.type.hash , hash_after
|
||||
end
|
||||
def test_single_type_not_class_before
|
||||
hash_before = @try.type.hash
|
||||
hash_after = @try.single_class.instance_type.hash
|
||||
refute_equal hash_before , hash_after
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -49,5 +49,11 @@ module Parfait
|
||||
@try.add_instance_variable(:counter , :Integer)
|
||||
assert_equal @try.clazz.type , @try.instance_type
|
||||
end
|
||||
def test_name
|
||||
assert_equal :"Try.Single" , @try.name
|
||||
end
|
||||
def test_type_is_single
|
||||
assert_equal true , @try.instance_type.is_single?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -13,35 +13,29 @@ module Parfait
|
||||
def test_type_index
|
||||
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess"
|
||||
end
|
||||
|
||||
def test_type_is_first
|
||||
type = @mess.get_type
|
||||
assert_equal 0 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert @mess
|
||||
assert @mess.get_type
|
||||
assert_equal 31 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
end
|
||||
|
||||
def test_names
|
||||
assert @type.names
|
||||
end
|
||||
def test_types
|
||||
assert @type.types
|
||||
end
|
||||
|
||||
def test_type_length
|
||||
assert_equal 31 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
end
|
||||
|
||||
def test_type_length_index
|
||||
type = @mess.get_type.get_type
|
||||
assert_equal 4 , type.variable_index(:methods)
|
||||
assert_equal type.object_class , type.get_internal_word(3)
|
||||
end
|
||||
|
||||
def test_no_index_below_0
|
||||
type = @mess.get_type
|
||||
names = type.names
|
||||
@ -50,12 +44,10 @@ module Parfait
|
||||
assert type.variable_index(n) >= 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_attribute_set
|
||||
@mess.set_receiver( 55)
|
||||
assert_equal 55 , @mess.receiver
|
||||
end
|
||||
|
||||
def test_variable_index
|
||||
assert_equal 1 , @type.variable_index(:next_message)
|
||||
end
|
||||
@ -68,7 +60,6 @@ module Parfait
|
||||
def test_type_for
|
||||
assert_equal :Message , @type.type_for(:next_message)
|
||||
end
|
||||
|
||||
def test_remove_me
|
||||
type = @mess.get_type
|
||||
assert_equal type , @mess.get_internal_word(0)
|
||||
@ -83,5 +74,9 @@ module Parfait
|
||||
int_class = @space.get_type_by_class_name(:Integer)
|
||||
assert_equal :Integer, int_class.object_class.name
|
||||
end
|
||||
def test_create_single
|
||||
single = Type.for_hash( {} , :Object ,1)
|
||||
assert_equal true , single.is_single?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user