2015-04-06 11:38:11 +03:00
|
|
|
|
2015-04-08 20:24:50 +03:00
|
|
|
# A Space is a collection of pages. It stores objects, the data for the objects,
|
|
|
|
# not references. See Page for more detail.
|
|
|
|
|
|
|
|
# Pages are stored by the object size they represent in a hash.
|
|
|
|
|
|
|
|
# Space and Page work together in making *new* objects available.
|
|
|
|
# "New" is slightly misleading in that normal operation only ever
|
|
|
|
# recycles objects.
|
|
|
|
|
2015-05-11 18:55:49 +03:00
|
|
|
module Parfait
|
2015-05-12 15:36:44 +03:00
|
|
|
# The Space contains all objects for a program. In functional terms it is a program, but in oo
|
|
|
|
# it is a collection of objects, some of which are data, some classes, some functions
|
|
|
|
|
2015-05-30 12:20:39 +03:00
|
|
|
# The main entry is a function called (of all things) "main".
|
|
|
|
# This _must be supplied by the compled code (similar to c)
|
2015-05-12 19:10:45 +03:00
|
|
|
# There is a start and exit block that call main, which receives an List of strings
|
2015-05-12 15:36:44 +03:00
|
|
|
|
|
|
|
# While data ususally would live in a .data section, we may also "inline" it into the code
|
|
|
|
# in an oo system all data is represented as objects
|
|
|
|
|
2015-05-11 18:55:49 +03:00
|
|
|
class Space < Object
|
2015-04-08 20:24:50 +03:00
|
|
|
|
2015-05-12 15:36:44 +03:00
|
|
|
def initialize
|
2015-07-21 15:40:25 +03:00
|
|
|
raise "Space can not be instantiated by new, you'd need a space to do so. Chicken and egg"
|
2015-05-22 22:50:19 +03:00
|
|
|
end
|
2015-07-21 15:40:25 +03:00
|
|
|
attributes [:classes , :first_message]
|
2015-05-22 22:50:19 +03:00
|
|
|
|
|
|
|
# need a two phase init for the object space (and generally parfait) because the space
|
|
|
|
# is an interconnected graph, so not everthing is ready
|
|
|
|
def late_init
|
2015-07-01 19:27:18 +03:00
|
|
|
message = Message.new(nil)
|
2015-11-05 12:12:15 +02:00
|
|
|
50.times do
|
2015-07-21 15:40:25 +03:00
|
|
|
self.first_message = Message.new message
|
2015-10-06 00:27:13 +03:00
|
|
|
#puts "INIT caller #{message.object_id} to #{self.first_message.object_id}"
|
2015-07-21 15:40:25 +03:00
|
|
|
message.set_caller self.first_message
|
|
|
|
message = self.first_message
|
2015-05-24 19:59:19 +03:00
|
|
|
end
|
2015-05-12 15:36:44 +03:00
|
|
|
end
|
|
|
|
|
2015-05-19 20:29:33 +03:00
|
|
|
@@object_space = nil
|
|
|
|
# Make the object space globally available
|
|
|
|
def self.object_space
|
|
|
|
@@object_space
|
|
|
|
end
|
|
|
|
# TODO Must get rid of the setter
|
|
|
|
def self.set_object_space space
|
2015-05-22 22:50:19 +03:00
|
|
|
@@object_space = space
|
2015-05-19 20:29:33 +03:00
|
|
|
end
|
|
|
|
|
2015-05-25 18:48:35 +03:00
|
|
|
def get_main
|
2015-05-31 18:34:18 +03:00
|
|
|
kernel = get_class_by_name :Object
|
|
|
|
kernel.get_instance_method :main
|
2015-05-25 18:48:35 +03:00
|
|
|
end
|
|
|
|
|
2015-06-25 16:31:09 +03:00
|
|
|
def get_init
|
|
|
|
kernel = get_class_by_name :Kernel
|
|
|
|
kernel.get_instance_method :__init__
|
|
|
|
end
|
|
|
|
|
2015-07-19 10:36:06 +03:00
|
|
|
# get a class by name (symbol)
|
|
|
|
# return nili if no such class. Use bang version if create should be implicit
|
2015-05-16 12:54:11 +03:00
|
|
|
def get_class_by_name name
|
2015-08-17 02:37:07 +03:00
|
|
|
raise "get_class_by_name #{name}.#{name.class}" unless name.is_a?(Symbol)
|
2015-07-21 15:40:25 +03:00
|
|
|
c = self.classes[name]
|
|
|
|
#puts "MISS, no class #{name} #{name.class}" unless c # " #{self.classes}"
|
2015-07-28 16:19:10 +03:00
|
|
|
#puts "CLAZZ, #{name} #{c.get_layout.get_length}" if c
|
2015-05-12 15:36:44 +03:00
|
|
|
c
|
|
|
|
end
|
2015-05-16 14:01:48 +03:00
|
|
|
|
2015-07-19 10:36:06 +03:00
|
|
|
# get or create the class by the (symbol) name
|
|
|
|
# notice that this method of creating classes implies Object superclass
|
|
|
|
def get_class_by_name! name
|
|
|
|
c = get_class_by_name(name)
|
|
|
|
return c if c
|
|
|
|
create_class name , get_class_by_name(:Object)
|
|
|
|
end
|
|
|
|
|
|
|
|
# this is the way to instantiate classes (not Parfait::Class.new)
|
|
|
|
# so we get and keep exactly one per name
|
2015-05-24 13:53:49 +03:00
|
|
|
def create_class name , superclass
|
2015-08-17 02:37:07 +03:00
|
|
|
raise "create_class #{name.class}" unless name.is_a? Symbol
|
2015-07-20 13:01:15 +03:00
|
|
|
c = Class.new(name , superclass)
|
2015-07-21 15:40:25 +03:00
|
|
|
self.classes[name] = c
|
2015-05-16 14:01:48 +03:00
|
|
|
end
|
2015-06-19 19:50:53 +03:00
|
|
|
|
|
|
|
def sof_reference_name
|
|
|
|
"space"
|
|
|
|
end
|
|
|
|
|
2015-05-11 18:55:49 +03:00
|
|
|
end
|
2015-05-12 15:36:44 +03:00
|
|
|
# ObjectSpace
|
|
|
|
# :each_object, :garbage_collect, :define_finalizer, :undefine_finalizer, :_id2ref, :count_objects
|
2015-04-06 11:38:11 +03:00
|
|
|
end
|