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
|
2018-06-15 20:54:21 +02:00
|
|
|
#
|
|
|
|
# The place we collect in is the position map in Position class
|
2015-10-18 18:27:02 +02:00
|
|
|
module Collector
|
2018-07-01 13:11:29 +02:00
|
|
|
def self.collect_space(linker)
|
2016-12-30 13:10:49 +01:00
|
|
|
keep Parfait.object_space , 0
|
2018-08-29 20:05:54 +02:00
|
|
|
linker.constants.each do |obj|
|
|
|
|
keep(obj,0)
|
|
|
|
end
|
2018-06-15 20:54:21 +02:00
|
|
|
Position.positions
|
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)
|
2018-06-15 20:54:21 +02:00
|
|
|
return false if Position.set?(objekt)
|
2019-02-07 17:24:35 +01:00
|
|
|
return true if objekt.is_a? ::Integer
|
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)
|
2018-07-07 08:11:09 +02:00
|
|
|
#puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::CallableMethod
|
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
|
2018-07-07 08:11:09 +02:00
|
|
|
#raise "Method #{objekt.name}" if objekt.is_a? Parfait::CallableMethod
|
2018-06-15 20:54:21 +02:00
|
|
|
Position.get_or_create(objekt)
|
2016-12-31 13:54:15 +01:00
|
|
|
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}:"
|
2018-05-14 11:38:44 +02:00
|
|
|
if( object.respond_to?(:rxf_reference_name))
|
|
|
|
msg + object.rxf_reference_name.to_s
|
2016-12-31 13:54:15 +01:00
|
|
|
else
|
|
|
|
msg + object.class.name
|
|
|
|
end
|
|
|
|
end
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
end
|