2019-02-16 22:24:16 +01:00
|
|
|
#
|
2019-09-23 19:57:33 +02:00
|
|
|
# In many respects a SingletonClass is like a Class. We haven't gone to the full ruby/oo level
|
|
|
|
# yet, where the singleton_class is actually a class instance, but someday.
|
2019-02-16 22:24:16 +01:00
|
|
|
|
|
|
|
# A Class in general can be viewed as a way to generate methods for a group of objects.
|
|
|
|
|
2019-09-23 19:57:33 +02:00
|
|
|
# A SingletonClass serves the same function, but just for one object, the class object that it
|
|
|
|
# is the singleton_class of.
|
2019-09-18 21:07:58 +02:00
|
|
|
# This is slightly different in the way that the type of the class must actually
|
2019-02-16 22:24:16 +01:00
|
|
|
# change, whereas for a class the instance type changes and only objects generated
|
|
|
|
# henceafter have a different type.
|
|
|
|
|
2019-09-23 19:57:33 +02:00
|
|
|
# Another current difference is that a singleton_class has no superclass. Also no name.
|
|
|
|
# There is a one to one relationship between a class instance and it's singleton_class instance.
|
2019-02-16 22:24:16 +01:00
|
|
|
|
|
|
|
module Parfait
|
2019-09-23 19:57:33 +02:00
|
|
|
class SingletonClass < Behaviour
|
2019-02-16 22:24:16 +01:00
|
|
|
|
2019-09-21 17:50:33 +02:00
|
|
|
attr_reader :clazz
|
2019-02-16 22:24:16 +01:00
|
|
|
|
|
|
|
def self.type_length
|
|
|
|
4
|
|
|
|
end
|
2019-09-09 23:18:20 +02:00
|
|
|
def self.memory_size
|
|
|
|
8
|
|
|
|
end
|
2019-02-16 22:24:16 +01:00
|
|
|
|
2019-09-30 16:09:13 +02:00
|
|
|
def initialize( clazz )
|
|
|
|
clazz_hash = clazz.type.to_hash
|
2019-09-09 19:26:54 +02:00
|
|
|
@clazz = clazz
|
2019-09-30 16:09:13 +02:00
|
|
|
super( Type.for_hash(clazz_hash , self , 1) )
|
|
|
|
@clazz.set_type( @instance_type )
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def rxf_reference_name
|
2019-09-09 19:26:54 +02:00
|
|
|
@clazz.name
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
|
2019-09-30 16:09:13 +02:00
|
|
|
def name
|
|
|
|
:"#{clazz.name}.Single"
|
|
|
|
end
|
|
|
|
|
2019-02-16 22:24:16 +01:00
|
|
|
def inspect
|
2019-09-23 19:57:33 +02:00
|
|
|
"SingletonClass(#{@clazz.name})"
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
|
2019-09-21 17:07:58 +02:00
|
|
|
def to_s
|
|
|
|
inspect
|
|
|
|
end
|
2019-02-16 22:24:16 +01:00
|
|
|
|
2019-09-23 19:42:46 +02:00
|
|
|
# adding an instance changes the instance_type to include that variable
|
|
|
|
def add_instance_variable( name , type)
|
|
|
|
super(name,type)
|
|
|
|
@clazz.set_type(@instance_type)
|
|
|
|
end
|
|
|
|
|
2019-02-17 13:37:50 +01:00
|
|
|
# Nil name means no superclass, and so nil returned
|
2019-02-16 22:24:16 +01:00
|
|
|
def super_class
|
2019-02-17 13:37:50 +01:00
|
|
|
return nil
|
2019-02-16 22:24:16 +01:00
|
|
|
end
|
|
|
|
|
2019-02-17 13:37:50 +01:00
|
|
|
# no superclass, return nil to signal
|
|
|
|
def super_class_name
|
|
|
|
nil
|
|
|
|
end
|
2019-02-16 22:24:16 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|