fold last of the virtual into register
This commit is contained in:
38
lib/register/collector.rb
Normal file
38
lib/register/collector.rb
Normal file
@ -0,0 +1,38 @@
|
||||
module Register
|
||||
|
||||
# collect anything that is in the space but and reachable from init
|
||||
module Collector
|
||||
def collect
|
||||
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
|
||||
self.objects.clear
|
||||
keep Parfait::Space.object_space , 0
|
||||
end
|
||||
|
||||
def keep object , depth
|
||||
return if object.nil?
|
||||
#puts "adding #{' ' * depth}:#{object.class}"
|
||||
#puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array
|
||||
return unless self.add_object object
|
||||
return unless object.respond_to? :has_layout?
|
||||
if( object.is_a? Parfait::Method)
|
||||
object.source.constants.each{|c|
|
||||
#puts "keeping constant #{c.class}:#{c.object_id}"
|
||||
keep(c , depth + 1)
|
||||
}
|
||||
end
|
||||
layout = object.get_layout
|
||||
keep(layout , depth + 1)
|
||||
layout.object_instance_names.each do |name|
|
||||
#puts "Keep #{name}"
|
||||
inst = object.get_instance_variable name
|
||||
keep(inst , depth + 1)
|
||||
end
|
||||
if object.is_a? Parfait::List
|
||||
object.each do |item|
|
||||
#puts "Keep item "
|
||||
keep(item , depth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user