2015-05-31 10:07:49 +02:00
|
|
|
module Virtual
|
|
|
|
|
2015-05-31 12:02:29 +02:00
|
|
|
# collect anything that is in the space but and reachable from init
|
2015-05-31 10:07:49 +02:00
|
|
|
class Collector
|
|
|
|
def run
|
2015-05-31 12:02:29 +02:00
|
|
|
# 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
|
2015-05-31 12:02:29 +02:00
|
|
|
return if object.nil?
|
2015-06-01 07:40:17 +02:00
|
|
|
return unless Virtual.machine.add_object object
|
2015-05-31 13:44:26 +02:00
|
|
|
#puts "adding #{object.class}"
|
2015-05-31 12:02:29 +02:00
|
|
|
unless object.has_layout?
|
|
|
|
object.init_layout
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
2015-06-01 07:33:23 +02:00
|
|
|
if( object.is_a? Parfait::Method)
|
2015-07-03 19:13:03 +02:00
|
|
|
object.source.constants.each{|c| keep(c) }
|
2015-06-01 07:33:23 +02:00
|
|
|
end
|
2015-05-31 12:02:29 +02:00
|
|
|
layout = object.get_layout
|
|
|
|
keep layout
|
2015-06-01 07:33:23 +02:00
|
|
|
#puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(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
|