rubyx/lib/parfait/space.rb

93 lines
2.8 KiB
Ruby
Raw Normal View History

2015-04-06 10:38:11 +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.
require "register/builtin/object"
module Parfait
# 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 11:20:39 +02:00
# The main entry is a function called (of all things) "main".
# This _must be supplied by the compled code (similar to c)
# There is a start and exit block that call main, which receives an List of strings
# 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
class Space < Object
def initialize
super()
2015-05-22 21:50:19 +02:00
Parfait::Space.set_object_space self
@classes = Parfait::Dictionary.new_object
@syscall_message = nil # a hack sto store the message during syscall
2015-05-22 21:50:19 +02:00
end
attr_reader :classes , :frames, :messages, :next_message , :next_frame
2015-05-22 21:50:19 +02: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-05-24 18:59:19 +02:00
@frames = List.new_object
@messages = List.new_object
counter = 0
2015-05-25 17:48:35 +02:00
while( counter < 5)
2015-05-24 18:59:19 +02:00
@frames.push Frame.new_object
@messages.push Message.new_object
counter = counter + 1
end
@next_message = @messages.first
@next_frame = @frames.first
2015-06-22 21:48:42 +02:00
init_layout
end
@@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 21:50:19 +02:00
@@object_space = space
end
2015-05-25 17:48:35 +02:00
def get_main
kernel = get_class_by_name :Object
kernel.get_instance_method :main
2015-05-25 17:48:35 +02:00
end
def get_init
kernel = get_class_by_name :Kernel
kernel.get_instance_method :__init__
end
# this is the way to instantiate classes (not Parfait::Class.new)
# so we get and keep exactly one per name
2015-05-16 11:54:11 +02:00
def get_class_by_name name
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
c = @classes[name]
puts "MISS, no class #{name} #{name.class}" unless c # " #{@classes}"
c
end
2015-05-24 12:53:49 +02:00
def create_class name , superclass
raise "uups " if name.is_a? String
2015-05-24 18:59:19 +02:00
c = Class.new_object(name , superclass)
@classes[name] = c
end
2015-06-19 18:50:53 +02:00
def sof_reference_name
"space"
end
end
# ObjectSpace
# :each_object, :garbage_collect, :define_finalizer, :undefine_finalizer, :_id2ref, :count_objects
2015-04-06 10:38:11 +02:00
end