2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2015-05-31 10:07:49 +02:00
|
|
|
|
2015-05-31 12:02:29 +02:00
|
|
|
# collect anything that is in the space but and reachable from init
|
2015-10-18 18:27:02 +02:00
|
|
|
module Collector
|
2016-12-31 18:54:18 +01:00
|
|
|
def self.collect_space
|
2016-12-31 17:46:17 +01:00
|
|
|
@objects = {}
|
2016-12-30 13:10:49 +01:00
|
|
|
keep Parfait.object_space , 0
|
2017-01-19 08:02:29 +01:00
|
|
|
Risc.machine.constants.each {|obj| keep(obj,0)}
|
2016-12-31 17:46:17 +01:00
|
|
|
@objects
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
|
2016-12-31 18:54:18 +01:00
|
|
|
def self.keep( object , depth )
|
2015-05-31 12:02:29 +02:00
|
|
|
return if object.nil?
|
2016-12-31 13:54:15 +01:00
|
|
|
return unless add_object( object , depth )
|
2016-02-25 20:50:10 +01:00
|
|
|
return unless object.respond_to? :has_type?
|
|
|
|
type = object.get_type
|
|
|
|
keep(type , depth + 1)
|
2015-10-26 11:23:52 +01:00
|
|
|
return if object.is_a? Symbol
|
2016-12-29 17:45:32 +01:00
|
|
|
type.names.each do |name|
|
2016-12-31 13:54:15 +01:00
|
|
|
keep(name , depth + 1)
|
2015-07-21 18:41:30 +02:00
|
|
|
inst = object.get_instance_variable name
|
2015-07-30 18:18:41 +02:00
|
|
|
keep(inst , depth + 1)
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
2016-12-30 20:00:18 +01:00
|
|
|
if object.is_a? Parfait::List
|
2015-05-31 10:07:49 +02:00
|
|
|
object.each do |item|
|
2015-07-30 18:18:41 +02:00
|
|
|
keep(item , depth + 1)
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-31 13:54:15 +01:00
|
|
|
|
|
|
|
# Objects are data and get assembled after functions
|
2016-12-31 18:54:18 +01:00
|
|
|
def self.add_object( objekt , depth)
|
2016-12-31 13:54:15 +01:00
|
|
|
return false if @objects[objekt.object_id]
|
|
|
|
return true if objekt.is_a? Fixnum
|
2018-03-27 18:06:16 +02:00
|
|
|
return true if objekt.is_a?( Risc::Label)
|
2016-12-31 13:54:15 +01:00
|
|
|
#puts message(objekt , depth)
|
|
|
|
#puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
|
2018-03-27 18:06:16 +02:00
|
|
|
unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol)
|
2018-03-22 16:38:13 +01:00
|
|
|
raise "adding non parfait #{objekt.class}:#{objekt}"
|
2016-12-31 13:54:15 +01:00
|
|
|
end
|
|
|
|
#raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
|
|
|
|
@objects[objekt.object_id] = objekt
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-12-31 18:54:18 +01:00
|
|
|
def self.message(object , depth)
|
2016-12-31 13:54:15 +01:00
|
|
|
msg = "adding #{depth}#{' ' * depth}:"
|
|
|
|
if( object.respond_to?(:sof_reference_name))
|
|
|
|
msg + object.sof_reference_name.to_s
|
|
|
|
else
|
|
|
|
msg + object.class.name
|
|
|
|
end
|
|
|
|
end
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
end
|