From ea7f3c9653b363a104fe120d7b0d400971fc8143 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 29 Aug 2018 21:05:54 +0300 Subject: [PATCH] remove the last_object from chain also tried to keep the first around as was done in space partially to not have to add the consrtants seperately didn't work, as chain gets broken also this has to be redone anyway --- lib/parfait/factory.rb | 10 ++++++---- lib/parfait/integer.rb | 18 ++++++++++-------- lib/parfait/object.rb | 2 -- lib/risc/collector.rb | 4 +++- test/parfait/test_factory.rb | 7 +++++-- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/parfait/factory.rb b/lib/parfait/factory.rb index fb38c37c..8ea65d28 100644 --- a/lib/parfait/factory.rb +++ b/lib/parfait/factory.rb @@ -13,7 +13,7 @@ module Parfait # factory when the next (not current) is nil. # This is btw just as easy a check, as the next needs to be gotten to swap the list. class Factory < Object - attr :type , :for_type , :next_object , :last_object , :reserve , :attribute_name + attr :type , :for_type , :next_object , :reserve , :attribute_name PAGE_SIZE = 1024 RESERVE = 10 @@ -50,8 +50,8 @@ module Parfait # and rebuilt the reserve (get_next already instantiates the reserve) # def get_more - chain = get_chain - link = chain + first_object = get_chain + link = first_object count = RESERVE while(count > 0) link = get_next_for(link) @@ -59,7 +59,8 @@ module Parfait end self.next_object = get_next_for(link) set_next_for( link , nil ) - self.reserve = chain + self.reserve = first_object + self end # this initiates the syscall to get more memory. @@ -111,6 +112,7 @@ module Parfait r_class = eval( "Parfait::#{type.object_class.name}" ) obj = r_class.allocate obj.set_type(type) + #puts "Factory #{type.object_class.name} at 0x#{obj.object_id.to_s(16)}" obj end end diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 56b332c3..7c1a9a31 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -1,12 +1,10 @@ - -# Integer class for representing maths on Integers -# Integers are Objects, specifically DataObjects -# - they have fixed value -# - they are immutable -# (both by implementation, not design. -# Ie it would be possible to change the value, we just don't support that) - module Parfait + # Integer class for representing maths on Integers + # Integers are Objects, specifically DataObjects + # - they have fixed value + # - they are immutable + # (both by implementation, not design. + # Ie it would be possible to change the value, we just don't support that) class Integer < Data4 attr :type, :next_integer @@ -55,6 +53,10 @@ module Parfait # # But the integer (address) needs to be adjusted by load address. class ReturnAddress < Integer + + def to_s + "ReturnAddress 0x#{object_id.to_s(16)}:#{value}" + end end # adding other base classes in here for now: diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index c98f8493..b2719a29 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -27,10 +27,8 @@ module Parfait def self.new( *args ) object = self.allocate - # have to grab the class, because we are in the ruby class not the parfait one cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym) - # and have to set the type before we let the object do anything. otherwise boom object.set_type cl.instance_type object.send :initialize , *args diff --git a/lib/risc/collector.rb b/lib/risc/collector.rb index e0cce2a8..64e5db3d 100644 --- a/lib/risc/collector.rb +++ b/lib/risc/collector.rb @@ -6,7 +6,9 @@ module Risc module Collector def self.collect_space(linker) keep Parfait.object_space , 0 - linker.constants.each {|obj| keep(obj,0)} + linker.constants.each do |obj| + keep(obj,0) + end Position.positions end diff --git a/test/parfait/test_factory.rb b/test/parfait/test_factory.rb index 9be959e3..658f4bc0 100644 --- a/test/parfait/test_factory.rb +++ b/test/parfait/test_factory.rb @@ -1,7 +1,7 @@ require_relative "helper" module Parfait - class TestPage < ParfaitTest + class TestFactory < ParfaitTest def setup super @@ -18,12 +18,15 @@ module Parfait end def test_no_next assert_nil @factory.next_object - assert_nil @factory.last_object assert_nil @factory.reserve end def test_get_next_object assert_equal Parfait::Integer , @factory.get_next_object.class end + def test_first_is_reserve + @factory.get_next_object + assert_equal Parfait::Integer , @factory.reserve.class + end def test_chain_length count = 0 start = @factory.get_next_object