changing factory size per factory

Before it was one class variable, but ints and messages are not created in equal amounts.
This commit is contained in:
Torsten Rüger 2019-08-24 09:46:33 +03:00
parent 86b27ab319
commit 02261ad79d
10 changed files with 43 additions and 45 deletions

View File

@ -12,18 +12,15 @@
# 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 , :reserve , :attribute_name
@page_size = 1024
@reserve_size = 10
cattr :page_size , :reserve_size
attr :type , :for_type , :next_object , :reserve , :attribute_name , :page_size
# initialize for a given type (for_type). The attribute that is used to create the
# list is the first that starts with next_ . "next" itself would have been nice and general
# but is a keyword, so no go.
def initialize(type)
def initialize(type , page)
self.for_type = type
self.attribute_name = type.names.find {|name| name.to_s.start_with?("next")}
self.page_size = page
raise "No next found for #{type.class_name}" unless attribute_name
end
@ -52,7 +49,8 @@
def get_more
self.reserve = get_chain
last_link = self.reserve
count = Factory.reserve_size
count = self.page_size / 100
count = 15 if count < 15
while(count > 0)
last_link = get_next_for(last_link)
count -= 1
@ -66,9 +64,9 @@
# it creates objects from the mem and link them into a chain
def get_chain
raise "type is nil" unless self.for_type
first = sys_mem( for_type , Factory.page_size)
first = sys_mem( for_type , self.page_size)
chain = first
counter = Factory.page_size
counter = self.page_size
while( counter > 0)
nekst = get_next_raw( chain )
set_next_for(chain, nekst)

View File

@ -33,7 +33,7 @@ module Parfait
attr :type, :classes , :types , :factories
attr :true_object , :false_object , :nil_object
def initialize( classes )
def initialize( classes , pages)
self.classes = classes
self.types = Dictionary.new
classes.each do |name , cl|
@ -41,7 +41,11 @@ module Parfait
end
self.factories = Dictionary.new
[:Integer , :ReturnAddress , :Message].each do |fact_name|
factories[ fact_name ] = Factory.new( classes[fact_name].instance_type).get_more
for_type = classes[fact_name].instance_type
page_size = pages[fact_name] || 1024
factory = Factory.new( for_type , page_size )
factory.get_more
factories[ fact_name ] = factory
end
init_message_chain( factories[ :Message ].reserve )
init_message_chain( factories[ :Message ].next_object )

View File

@ -55,9 +55,7 @@ module Parfait
boot_boot_space( types )
classes = boot_classes( types )
fix_types( types , classes )
page = options[:factory] || 1024
Factory.page_size = page
space = Space.new( classes )
space = Space.new( classes , options )
Parfait.set_object_space( space )
end
@ -154,8 +152,8 @@ module Parfait
Data32: {},
Dictionary: {i_keys: :List , i_values: :List } ,
FalseClass: {},
Factory: { for_type: :Type , next_object: :Object ,
reserve: :Object , attribute_name: :Word },
Factory: { for_type: :Type , next_object: :Object , reserve: :Object ,
attribute_name: :Word , page_size: :Integer },
Integer: {next_integer: :Integer},
List: {indexed_length: :Integer , next_list: :List} ,
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,

View File

@ -5,7 +5,8 @@ module Parfait
def setup
super
@factory = Factory.new Parfait.object_space.get_type_by_class_name(:Integer)
type = Parfait.object_space.get_type_by_class_name(:Integer)
@factory = Factory.new(type , 40)
end
def test_ok
assert @factory
@ -24,14 +25,7 @@ module Parfait
assert_equal Parfait::Integer , @factory.get_next_object.class
end
def test_default_test_page
assert_equal 20 , Factory.page_size
end
def test_default_reserve
assert_equal 10 , Factory.reserve_size
end
def test_set_page
assert_equal 10 , Factory.page_size = 10
Factory.page_size = 1024
assert_equal 40 , @factory.page_size
end
def test_first_is_reserve
@factory.get_next_object
@ -45,12 +39,13 @@ module Parfait
start = start.next_integer
count += 1
end
assert_equal 11 , count
assert_equal 16 , count
end
class BigFactoryTest < BigParfaitTest
def setup
super
@factory = Factory.new Parfait.object_space.get_type_by_class_name(:Integer)
type = Parfait.object_space.get_type_by_class_name(:Integer)
@factory = Factory.new(type , 300)
end
def test_chain_length
count = 0
@ -59,10 +54,10 @@ module Parfait
start = start.next_integer
count += 1
end
assert_equal 1024 - 10 , count
assert_equal 300-15 , count
end
def test_default_page
assert_equal 1024 , Factory.page_size
def test_page
assert_equal 300 , @factory.page_size
end
end
end

View File

@ -191,7 +191,7 @@ module Parfait
count += 1
addr = addr.next_integer
end
assert_equal 1014, count
assert_equal 1009, count
end
def test_message_count
mess = @space.get_next_for(:Message)
@ -201,7 +201,7 @@ module Parfait
assert mess.locals_used
mess = mess.next_message
end
assert_equal 1014, count
assert_equal 285, count
end
end

View File

@ -37,7 +37,7 @@ module Risc
ret = main_ticks(46)
assert_equal FunctionReturn , ret.class
assert_equal :r3 , ret.register.symbol
assert_equal 26012 , @interpreter.get_register(ret.register)
assert_equal 40348 , @interpreter.get_register(ret.register)
end
end
end

View File

@ -11,7 +11,7 @@ module Risc
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 601 , objects.length , objects.length.to_s
assert_equal 1564 , objects.length , objects.length.to_s
end
def test_collect_all_types
@ -55,7 +55,7 @@ module Risc
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 2419, objects.length , objects.length.to_s
assert_equal 1564, objects.length , objects.length.to_s
end
def test_integer_positions

View File

@ -55,7 +55,12 @@ module Risc
end
def test_pc1
@interpreter.tick
assert_equal 25912 , @interpreter.pc
assert_equal 40296 , @interpreter.pc
end
def test_pc2
@interpreter.tick
@interpreter.tick
assert_equal 40300 , @interpreter.pc
end
def test_tick2
@interpreter.tick
@ -66,11 +71,6 @@ module Risc
@interpreter.tick
assert_equal 3 , @interpreter.clock
end
def test_pc2
@interpreter.tick
@interpreter.tick
assert_equal 25916 , @interpreter.pc
end
def ttest_tick_14_jump
30.times { @interpreter.tick ;puts @interpreter.instruction.class}
assert_equal Branch , @interpreter.instruction.class

View File

@ -25,7 +25,7 @@ module Risc
assert_equal 0 , Position.get(@linker.cpu_init).at
end
def test_cpu_at
assert_equal "0x5dbc" , Position.get(@linker.cpu_init.first).to_s
assert_equal "0x9e5c" , Position.get(@linker.cpu_init.first).to_s
end
def test_cpu_label
assert_equal Position , Position.get(@linker.cpu_init.first).class

View File

@ -1,17 +1,20 @@
module Parfait
def self.default_test_options
{
factory: 20,
Message: 30,
Integer: 30,
}
end
def self.interpreter_test_options
{
factory: 50,
Message: 50,
Integer: 50,
}
end
def self.full_test_options
{
factory: 1024,
Message: 300,
Integer: 300,
}
end
end