fixed layouts

also moved objects to machine, from space
space has a list of objects, but implicit,
not as an explicit array
This commit is contained in:
Torsten Ruger
2015-05-31 13:02:29 +03:00
parent aaa206fbca
commit 03bdc16810
8 changed files with 69 additions and 75 deletions

View File

@ -1,24 +1,22 @@
module Virtual
# garbage collect anything that is in the space but not reachable from init
# collect anything that is in the space but and reachable from init
class Collector
def run
@keepers = []
init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
keep init
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
keep Parfait::Space.object_space
end
def keep object
return if @keepers.include? object
layout = object.get_layout
begin
puts "Object #{object.class} #{Parfait::Space.object_space.objects.include?(object)}"
puts "Object #{layout.object_id} #{Parfait::Space.object_space.objects.include?(layout)}"
keep layout
rescue => e
puts "for #{object.name}"
raise e
return if object.nil?
return unless Machine.instance.add_object object
# puts "adding #{object.class}"
unless object.has_layout?
object.init_layout
end
layout = object.get_layout
puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
keep layout
layout.each do |name|
inst = object.instance_variable_get "@#{name}".to_sym
keep inst