2015-04-08 19:24:50 +02:00
|
|
|
# An Object is really a hash like structure. It is dynamic and
|
2015-05-14 18:54:38 +02:00
|
|
|
# you want to store values by name (instance variable names).
|
|
|
|
#
|
2015-04-08 19:24:50 +02:00
|
|
|
# One could (like mri), store the names in each object, but that is wasteful
|
|
|
|
# Instead we store only the values, and access them by index.
|
|
|
|
# The Layout allows the mapping of names to index.
|
|
|
|
|
|
|
|
# The Layout of an object describes the memory layout of the object
|
|
|
|
# The Layout is a simple list of the names of instance variables.
|
2015-05-11 17:55:49 +02:00
|
|
|
#
|
|
|
|
# As every object has a Layout to describe it, the name "layout" is the
|
2015-04-08 19:24:50 +02:00
|
|
|
# first name in the list for every Layout.
|
2015-05-17 13:40:02 +02:00
|
|
|
|
|
|
|
# But as we want every Object to have a class, the Layout carries that class.
|
|
|
|
# So the layout of layout has an entry "object_class"
|
2015-04-08 19:24:50 +02:00
|
|
|
|
|
|
|
# In other words, the Layout is a list of names that describe
|
|
|
|
# the values stored in an actual object.
|
2015-05-12 18:10:45 +02:00
|
|
|
# The object is an List of values of length n and
|
|
|
|
# the Layout is an List of names of length n
|
2015-05-11 17:55:49 +02:00
|
|
|
# Together they turn the object into a hash like structure
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
module Parfait
|
2015-05-14 18:54:38 +02:00
|
|
|
class Layout < List
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-16 13:01:48 +02:00
|
|
|
# set the names of the instance variables in one go
|
|
|
|
# used while booting the classes. At runtime the list would grow dynamically
|
|
|
|
def set_names list
|
2015-05-18 09:10:31 +02:00
|
|
|
self.set_length list.get_length
|
2015-05-16 13:01:48 +02:00
|
|
|
index = 0
|
2015-05-18 09:10:31 +02:00
|
|
|
while index < list.get_length do
|
2015-05-16 13:01:48 +02:00
|
|
|
list.set(index , array.get(index))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# beat the recursion! fixed known offset for class object in the layout
|
2015-05-16 11:53:10 +02:00
|
|
|
def get_object_class()
|
2015-05-17 13:40:02 +02:00
|
|
|
return internal_object_get(CLASS_INDEX)
|
2015-05-16 11:53:10 +02:00
|
|
|
end
|
2015-05-11 17:55:49 +02:00
|
|
|
end
|
2015-04-08 19:24:50 +02:00
|
|
|
end
|