remove collecting from the machine
use as stand alone module
This commit is contained in:
parent
671512b96c
commit
dccd097fef
@ -2,14 +2,14 @@ module Register
|
|||||||
|
|
||||||
# collect anything that is in the space but and reachable from init
|
# collect anything that is in the space but and reachable from init
|
||||||
module Collector
|
module Collector
|
||||||
def collect_space
|
def self.collect_space
|
||||||
@objects = {}
|
@objects = {}
|
||||||
keep Parfait.object_space , 0
|
keep Parfait.object_space , 0
|
||||||
constants.each {|obj| keep(obj,0)}
|
Register.machine.constants.each {|obj| keep(obj,0)}
|
||||||
@objects
|
@objects
|
||||||
end
|
end
|
||||||
|
|
||||||
def keep( object , depth )
|
def self.keep( object , depth )
|
||||||
return if object.nil?
|
return if object.nil?
|
||||||
return unless add_object( object , depth )
|
return unless add_object( object , depth )
|
||||||
# probably should make labels or even instructions derive from Parfait::Object, but . .
|
# probably should make labels or even instructions derive from Parfait::Object, but . .
|
||||||
@ -22,20 +22,18 @@ module Register
|
|||||||
return if object.is_a? Symbol
|
return if object.is_a? Symbol
|
||||||
type.names.each do |name|
|
type.names.each do |name|
|
||||||
keep(name , depth + 1)
|
keep(name , depth + 1)
|
||||||
#puts "Keep #{name} for #{object.class}"
|
|
||||||
inst = object.get_instance_variable name
|
inst = object.get_instance_variable name
|
||||||
keep(inst , depth + 1)
|
keep(inst , depth + 1)
|
||||||
end
|
end
|
||||||
if object.is_a? Parfait::List
|
if object.is_a? Parfait::List
|
||||||
object.each do |item|
|
object.each do |item|
|
||||||
#puts "Keep item "
|
|
||||||
keep(item , depth + 1)
|
keep(item , depth + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Objects are data and get assembled after functions
|
# Objects are data and get assembled after functions
|
||||||
def add_object( objekt , depth)
|
def self.add_object( objekt , depth)
|
||||||
return false if @objects[objekt.object_id]
|
return false if @objects[objekt.object_id]
|
||||||
return true if objekt.is_a? Fixnum
|
return true if objekt.is_a? Fixnum
|
||||||
#puts message(objekt , depth)
|
#puts message(objekt , depth)
|
||||||
@ -48,7 +46,7 @@ module Register
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def message(object , depth)
|
def self.message(object , depth)
|
||||||
msg = "adding #{depth}#{' ' * depth}:"
|
msg = "adding #{depth}#{' ' * depth}:"
|
||||||
if( object.respond_to?(:sof_reference_name))
|
if( object.respond_to?(:sof_reference_name))
|
||||||
msg + object.sof_reference_name.to_s
|
msg + object.sof_reference_name.to_s
|
||||||
|
@ -10,8 +10,8 @@ module Positioned
|
|||||||
pos = Positioned.positions[self]
|
pos = Positioned.positions[self]
|
||||||
if pos == nil
|
if pos == nil
|
||||||
str = "position accessed but not set, "
|
str = "position accessed but not set, "
|
||||||
str += "#{Register.machine.objects.has_key?(self.object_id)}, at #{self.object_id.to_s(16)}\n"
|
str += "#{self.object_id.to_s(16)}\n"
|
||||||
raise str + "for #{self.class} byte_length #{byte_length} for #{self.inspect[0...100]}"
|
raise str + "for #{self.class} byte_length #{self.byte_length if self.respond_to?(:byte_length)} for #{self.inspect[0...100]}"
|
||||||
end
|
end
|
||||||
pos
|
pos
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ class HelloTest < MiniTest::Test
|
|||||||
def check
|
def check
|
||||||
machine = Register.machine.boot
|
machine = Register.machine.boot
|
||||||
Typed.compile( @input )
|
Typed.compile( @input )
|
||||||
objects = machine.collect_space
|
objects = Register::Collector.collect_space
|
||||||
machine.translate_arm
|
machine.translate_arm
|
||||||
writer = Elf::ObjectWriter.new(machine , objects )
|
writer = Elf::ObjectWriter.new(machine , objects )
|
||||||
writer.save "test/hello.o"
|
writer.save "test/hello.o"
|
||||||
|
@ -10,7 +10,7 @@ class TestZeroCode < MiniTest::Test
|
|||||||
type.remove_method(method) unless keeper(method)
|
type.remove_method(method) unless keeper(method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@objects = @machine.collect_space
|
@objects = Register::Collector.collect_space
|
||||||
end
|
end
|
||||||
def keeper name
|
def keeper name
|
||||||
name == :main or name == :__init__
|
name == :main or name == :__init__
|
||||||
|
@ -5,10 +5,10 @@ module Ticker
|
|||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
machine = Register.machine.boot
|
Register.machine.boot
|
||||||
do_clean_compile
|
do_clean_compile
|
||||||
Typed.compile( @input )
|
Typed.compile( @input )
|
||||||
machine.collect_space
|
Register::Collector.collect_space
|
||||||
@interpreter = Register::Interpreter.new
|
@interpreter = Register::Interpreter.new
|
||||||
@interpreter.start Register.machine.init
|
@interpreter.start Register.machine.init
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_collect_all_types
|
def test_collect_all_types
|
||||||
objects = @machine.collect_space
|
objects = Register::Collector.collect_space
|
||||||
objects.each do |id, objekt|
|
objects.each do |id, objekt|
|
||||||
next unless objekt.is_a?( Parfait::Type )
|
next unless objekt.is_a?( Parfait::Type )
|
||||||
assert Parfait.object_space.get_type_for( objekt.hash ) , objekt.hash
|
assert Parfait.object_space.get_type_for( objekt.hash ) , objekt.hash
|
||||||
|
Loading…
Reference in New Issue
Block a user