2015-04-06 10:38:11 +02:00
|
|
|
|
2015-04-08 19:24:50 +02: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-12 14:36:44 +02:00
|
|
|
require "register/builtin/object"
|
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
module Parfait
|
2015-05-12 14:36:44 +02: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
|
|
|
|
|
|
|
|
# The main entry is a function called (of all things) "main", This _must be supplied by the compling
|
2015-05-12 18:10:45 +02:00
|
|
|
# There is a start and exit block that call main, which receives an List of strings
|
2015-05-12 14:36:44 +02: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 17:55:49 +02:00
|
|
|
class Space < Object
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-12 14:36:44 +02:00
|
|
|
def initialize
|
|
|
|
super()
|
2015-05-12 18:10:45 +02:00
|
|
|
@classes = Parfait::Dictionary.new_object
|
2015-05-12 14:36:44 +02:00
|
|
|
#global objects (data)
|
|
|
|
@objects = []
|
|
|
|
@symbols = []
|
|
|
|
@frames = 100.times.collect{ ::Parfait::Frame.new([],[])}
|
|
|
|
@messages = 100.times.collect{ ::Parfait::Message.new }
|
|
|
|
@next_message = @messages.first
|
|
|
|
@next_frame = @frames.first
|
|
|
|
end
|
2015-05-16 11:53:10 +02:00
|
|
|
attr_reader :classes , :objects , :symbols,:messages, :next_message , :next_frame
|
2015-05-12 14:36:44 +02:00
|
|
|
|
|
|
|
@@SPACE = { :names => [:classes,:objects,:symbols,:messages, :next_message , :next_frame] ,
|
|
|
|
:types => [Virtual::Reference,Virtual::Reference,Virtual::Reference,Virtual::Reference,Virtual::Reference]}
|
2015-05-17 13:41:18 +02:00
|
|
|
def old_layout
|
2015-05-12 14:36:44 +02:00
|
|
|
@@SPACE
|
|
|
|
end
|
|
|
|
|
|
|
|
# Objects are data and get assembled after functions
|
|
|
|
def add_object o
|
|
|
|
return if @objects.include?(o)
|
|
|
|
@objects << o
|
|
|
|
if o.is_a? Symbol
|
|
|
|
@symbols << o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-16 11:53:10 +02:00
|
|
|
# this is the way to instantiate classes (not Parfait::Class.new)
|
2015-05-12 14:36:44 +02:00
|
|
|
# so we get and keep exactly one per name
|
2015-05-16 11:54:11 +02:00
|
|
|
def get_class_by_name name
|
2015-05-16 19:16:49 +02:00
|
|
|
raise "uups #{name}.#{name.class}" unless name.is_a? String or name.is_a? Word
|
2015-05-12 14:36:44 +02:00
|
|
|
c = @classes[name]
|
|
|
|
c
|
|
|
|
end
|
2015-05-16 13:01:48 +02:00
|
|
|
|
|
|
|
def create_class name , variable_names
|
|
|
|
c = Class.new_object(name)
|
|
|
|
c.set_instance_names Parfait.new_list(variable_names)
|
|
|
|
@classes[name] = c
|
|
|
|
end
|
|
|
|
|
2015-05-12 14:36:44 +02:00
|
|
|
def mem_length
|
|
|
|
padded_words( 5 )
|
|
|
|
end
|
2015-05-11 17:55:49 +02:00
|
|
|
end
|
2015-05-12 14:36:44 +02:00
|
|
|
# ObjectSpace
|
|
|
|
# :each_object, :garbage_collect, :define_finalizer, :undefine_finalizer, :_id2ref, :count_objects
|
2015-04-06 10:38:11 +02:00
|
|
|
end
|