rubyx/lib/virtual/passes/collector.rb

32 lines
867 B
Ruby
Raw Normal View History

2015-05-31 10:07:49 +02:00
module Virtual
# collect anything that is in the space but and reachable from init
2015-05-31 10:07:49 +02:00
class Collector
def run
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
keep Parfait::Space.object_space
2015-05-31 10:07:49 +02:00
end
def keep object
return if object.nil?
return unless Machine.instance.add_object object
# puts "adding #{object.class}"
unless object.has_layout?
object.init_layout
2015-05-31 10:07:49 +02:00
end
layout = object.get_layout
puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
keep layout
2015-05-31 10:07:49 +02:00
layout.each do |name|
inst = object.instance_variable_get "@#{name}".to_sym
keep inst
end
if object.is_a? Parfait::List
object.each do |item|
keep item
end
end
end
end
end