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