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
This commit is contained in:
Torsten Ruger 2018-08-29 21:05:54 +03:00
parent c983dcf0eb
commit ea7f3c9653
5 changed files with 24 additions and 17 deletions

View File

@ -13,7 +13,7 @@ module Parfait
# factory when the next (not current) is nil. # 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. # This is btw just as easy a check, as the next needs to be gotten to swap the list.
class Factory < Object 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 PAGE_SIZE = 1024
RESERVE = 10 RESERVE = 10
@ -50,8 +50,8 @@ module Parfait
# and rebuilt the reserve (get_next already instantiates the reserve) # and rebuilt the reserve (get_next already instantiates the reserve)
# #
def get_more def get_more
chain = get_chain first_object = get_chain
link = chain link = first_object
count = RESERVE count = RESERVE
while(count > 0) while(count > 0)
link = get_next_for(link) link = get_next_for(link)
@ -59,7 +59,8 @@ module Parfait
end end
self.next_object = get_next_for(link) self.next_object = get_next_for(link)
set_next_for( link , nil ) set_next_for( link , nil )
self.reserve = chain self.reserve = first_object
self
end end
# this initiates the syscall to get more memory. # this initiates the syscall to get more memory.
@ -111,6 +112,7 @@ module Parfait
r_class = eval( "Parfait::#{type.object_class.name}" ) r_class = eval( "Parfait::#{type.object_class.name}" )
obj = r_class.allocate obj = r_class.allocate
obj.set_type(type) obj.set_type(type)
#puts "Factory #{type.object_class.name} at 0x#{obj.object_id.to_s(16)}"
obj obj
end end
end end

View File

@ -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 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 class Integer < Data4
attr :type, :next_integer attr :type, :next_integer
@ -55,6 +53,10 @@ module Parfait
# #
# But the integer (address) needs to be adjusted by load address. # But the integer (address) needs to be adjusted by load address.
class ReturnAddress < Integer class ReturnAddress < Integer
def to_s
"ReturnAddress 0x#{object_id.to_s(16)}:#{value}"
end
end end
# adding other base classes in here for now: # adding other base classes in here for now:

View File

@ -27,10 +27,8 @@ module Parfait
def self.new( *args ) def self.new( *args )
object = self.allocate object = self.allocate
# have to grab the class, because we are in the ruby class not the parfait one # 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) 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 # and have to set the type before we let the object do anything. otherwise boom
object.set_type cl.instance_type object.set_type cl.instance_type
object.send :initialize , *args object.send :initialize , *args

View File

@ -6,7 +6,9 @@ module Risc
module Collector module Collector
def self.collect_space(linker) def self.collect_space(linker)
keep Parfait.object_space , 0 keep Parfait.object_space , 0
linker.constants.each {|obj| keep(obj,0)} linker.constants.each do |obj|
keep(obj,0)
end
Position.positions Position.positions
end end

View File

@ -1,7 +1,7 @@
require_relative "helper" require_relative "helper"
module Parfait module Parfait
class TestPage < ParfaitTest class TestFactory < ParfaitTest
def setup def setup
super super
@ -18,12 +18,15 @@ module Parfait
end end
def test_no_next def test_no_next
assert_nil @factory.next_object assert_nil @factory.next_object
assert_nil @factory.last_object
assert_nil @factory.reserve assert_nil @factory.reserve
end end
def test_get_next_object def test_get_next_object
assert_equal Parfait::Integer , @factory.get_next_object.class assert_equal Parfait::Integer , @factory.get_next_object.class
end end
def test_first_is_reserve
@factory.get_next_object
assert_equal Parfait::Integer , @factory.reserve.class
end
def test_chain_length def test_chain_length
count = 0 count = 0
start = @factory.get_next_object start = @factory.get_next_object