From 853a5315786777e8474bc8bfd1b321255d7064b6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 31 Dec 2016 14:54:15 +0200 Subject: [PATCH] Move add_object to collector more changes to come --- lib/register/collector.rb | 32 +++++++++++++++++++++++++++----- lib/register/machine.rb | 14 +------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/register/collector.rb b/lib/register/collector.rb index 1334f348..8b6ab581 100644 --- a/lib/register/collector.rb +++ b/lib/register/collector.rb @@ -8,20 +8,19 @@ module Register constants.each {|obj| keep(obj,0)} end - def keep object , depth + def keep( object , depth ) return if object.nil? - #puts "adding #{' ' * depth}:#{object.class}" - #puts "ADD #{object.inspect}, #{object.hash}" if object.is_a? Parfait::Type - return unless add_object( object ) + return unless add_object( object , depth ) # probably should make labels or even instructions derive from Parfait::Object, but . . if object.is_a? Register::Label - object.each_label { |l| self.add_object(l)} + object.each_label { |l| self.add_object(l ,depth)} end return unless object.respond_to? :has_type? type = object.get_type keep(type , depth + 1) return if object.is_a? Symbol type.names.each do |name| + keep(name , depth + 1) #puts "Keep #{name} for #{object.class}" inst = object.get_instance_variable name keep(inst , depth + 1) @@ -33,5 +32,28 @@ module Register end end end + + # Objects are data and get assembled after functions + def add_object( objekt , depth) + return false if @objects[objekt.object_id] + return true if objekt.is_a? Fixnum + #puts message(objekt , depth) + #puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::TypedMethod + unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol) or objekt.is_a?( Register::Label) + raise "adding non parfait #{objekt.class}" + end + #raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod + @objects[objekt.object_id] = objekt + true + end + + def message(object , depth) + 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 end end diff --git a/lib/register/machine.rb b/lib/register/machine.rb index 1410fb2f..33453235 100644 --- a/lib/register/machine.rb +++ b/lib/register/machine.rb @@ -36,7 +36,7 @@ module Register def translate_methods(methods) translator = Arm::Translator.new methods.each do |method| - log.debug "Method #{method.name}" + log.debug "Translate method #{method.name}" instruction = method.instructions while instruction.next nekst = instruction.next @@ -50,18 +50,6 @@ module Register end end - # Objects are data and get assembled after functions - def add_object( objekt ) - return false if @objects[objekt.object_id] - return true if objekt.is_a? Fixnum - unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol) or objekt.is_a?( Register::Label) - raise "adding non parfait #{objekt.class}" - end - #raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod - @objects[objekt.object_id] = objekt - true - end - def boot initialize boot_parfait!