From 02261ad79d5281aa009b920e6bb10609c5683ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Sat, 24 Aug 2019 09:46:33 +0300 Subject: [PATCH] changing factory size per factory Before it was one class variable, but ints and messages are not created in equal amounts. --- lib/parfait/factory.rb | 16 +++++++------- lib/parfait/space.rb | 8 +++++-- lib/risc/parfait_boot.rb | 8 +++---- test/parfait/test_factory.rb | 23 ++++++++------------- test/parfait/test_space.rb | 4 ++-- test/risc/interpreter/calling/test_minus.rb | 2 +- test/risc/test_collector.rb | 4 ++-- test/risc/test_interpreter.rb | 12 +++++------ test/risc/test_linker.rb | 2 +- test/support/options.rb | 9 +++++--- 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/parfait/factory.rb b/lib/parfait/factory.rb index 43b93548..a38449ad 100644 --- a/lib/parfait/factory.rb +++ b/lib/parfait/factory.rb @@ -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) diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 8c77ae47..c7efedc1 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -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 ) diff --git a/lib/risc/parfait_boot.rb b/lib/risc/parfait_boot.rb index e538062f..e07b8eda 100644 --- a/lib/risc/parfait_boot.rb +++ b/lib/risc/parfait_boot.rb @@ -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 , diff --git a/test/parfait/test_factory.rb b/test/parfait/test_factory.rb index db086cfe..14b728ea 100644 --- a/test/parfait/test_factory.rb +++ b/test/parfait/test_factory.rb @@ -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 diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index d07cb7eb..dfee5f43 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index d1c2c971..fd8b288b 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -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 diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 245298b0..a9c76a0a 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -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 diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index f12dbc93..a03d124c 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -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 diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index 8d6cfa69..96885481 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -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 diff --git a/test/support/options.rb b/test/support/options.rb index e2872432..725ee54a 100644 --- a/test/support/options.rb +++ b/test/support/options.rb @@ -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