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:
parent
86b27ab319
commit
02261ad79d
@ -12,18 +12,15 @@
|
|||||||
# 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 , :reserve , :attribute_name
|
attr :type , :for_type , :next_object , :reserve , :attribute_name , :page_size
|
||||||
|
|
||||||
@page_size = 1024
|
|
||||||
@reserve_size = 10
|
|
||||||
cattr :page_size , :reserve_size
|
|
||||||
|
|
||||||
# initialize for a given type (for_type). The attribute that is used to create the
|
# 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
|
# list is the first that starts with next_ . "next" itself would have been nice and general
|
||||||
# but is a keyword, so no go.
|
# but is a keyword, so no go.
|
||||||
def initialize(type)
|
def initialize(type , page)
|
||||||
self.for_type = type
|
self.for_type = type
|
||||||
self.attribute_name = type.names.find {|name| name.to_s.start_with?("next")}
|
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
|
raise "No next found for #{type.class_name}" unless attribute_name
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,7 +49,8 @@
|
|||||||
def get_more
|
def get_more
|
||||||
self.reserve = get_chain
|
self.reserve = get_chain
|
||||||
last_link = self.reserve
|
last_link = self.reserve
|
||||||
count = Factory.reserve_size
|
count = self.page_size / 100
|
||||||
|
count = 15 if count < 15
|
||||||
while(count > 0)
|
while(count > 0)
|
||||||
last_link = get_next_for(last_link)
|
last_link = get_next_for(last_link)
|
||||||
count -= 1
|
count -= 1
|
||||||
@ -66,9 +64,9 @@
|
|||||||
# it creates objects from the mem and link them into a chain
|
# it creates objects from the mem and link them into a chain
|
||||||
def get_chain
|
def get_chain
|
||||||
raise "type is nil" unless self.for_type
|
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
|
chain = first
|
||||||
counter = Factory.page_size
|
counter = self.page_size
|
||||||
while( counter > 0)
|
while( counter > 0)
|
||||||
nekst = get_next_raw( chain )
|
nekst = get_next_raw( chain )
|
||||||
set_next_for(chain, nekst)
|
set_next_for(chain, nekst)
|
||||||
|
@ -33,7 +33,7 @@ module Parfait
|
|||||||
attr :type, :classes , :types , :factories
|
attr :type, :classes , :types , :factories
|
||||||
attr :true_object , :false_object , :nil_object
|
attr :true_object , :false_object , :nil_object
|
||||||
|
|
||||||
def initialize( classes )
|
def initialize( classes , pages)
|
||||||
self.classes = classes
|
self.classes = classes
|
||||||
self.types = Dictionary.new
|
self.types = Dictionary.new
|
||||||
classes.each do |name , cl|
|
classes.each do |name , cl|
|
||||||
@ -41,7 +41,11 @@ module Parfait
|
|||||||
end
|
end
|
||||||
self.factories = Dictionary.new
|
self.factories = Dictionary.new
|
||||||
[:Integer , :ReturnAddress , :Message].each do |fact_name|
|
[: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
|
end
|
||||||
init_message_chain( factories[ :Message ].reserve )
|
init_message_chain( factories[ :Message ].reserve )
|
||||||
init_message_chain( factories[ :Message ].next_object )
|
init_message_chain( factories[ :Message ].next_object )
|
||||||
|
@ -55,9 +55,7 @@ module Parfait
|
|||||||
boot_boot_space( types )
|
boot_boot_space( types )
|
||||||
classes = boot_classes( types )
|
classes = boot_classes( types )
|
||||||
fix_types( types , classes )
|
fix_types( types , classes )
|
||||||
page = options[:factory] || 1024
|
space = Space.new( classes , options )
|
||||||
Factory.page_size = page
|
|
||||||
space = Space.new( classes )
|
|
||||||
Parfait.set_object_space( space )
|
Parfait.set_object_space( space )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -154,8 +152,8 @@ module Parfait
|
|||||||
Data32: {},
|
Data32: {},
|
||||||
Dictionary: {i_keys: :List , i_values: :List } ,
|
Dictionary: {i_keys: :List , i_values: :List } ,
|
||||||
FalseClass: {},
|
FalseClass: {},
|
||||||
Factory: { for_type: :Type , next_object: :Object ,
|
Factory: { for_type: :Type , next_object: :Object , reserve: :Object ,
|
||||||
reserve: :Object , attribute_name: :Word },
|
attribute_name: :Word , page_size: :Integer },
|
||||||
Integer: {next_integer: :Integer},
|
Integer: {next_integer: :Integer},
|
||||||
List: {indexed_length: :Integer , next_list: :List} ,
|
List: {indexed_length: :Integer , next_list: :List} ,
|
||||||
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,
|
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,
|
||||||
|
@ -5,7 +5,8 @@ module Parfait
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
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
|
end
|
||||||
def test_ok
|
def test_ok
|
||||||
assert @factory
|
assert @factory
|
||||||
@ -24,14 +25,7 @@ module Parfait
|
|||||||
assert_equal Parfait::Integer , @factory.get_next_object.class
|
assert_equal Parfait::Integer , @factory.get_next_object.class
|
||||||
end
|
end
|
||||||
def test_default_test_page
|
def test_default_test_page
|
||||||
assert_equal 20 , Factory.page_size
|
assert_equal 40 , @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
|
|
||||||
end
|
end
|
||||||
def test_first_is_reserve
|
def test_first_is_reserve
|
||||||
@factory.get_next_object
|
@factory.get_next_object
|
||||||
@ -45,12 +39,13 @@ module Parfait
|
|||||||
start = start.next_integer
|
start = start.next_integer
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
assert_equal 11 , count
|
assert_equal 16 , count
|
||||||
end
|
end
|
||||||
class BigFactoryTest < BigParfaitTest
|
class BigFactoryTest < BigParfaitTest
|
||||||
def setup
|
def setup
|
||||||
super
|
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
|
end
|
||||||
def test_chain_length
|
def test_chain_length
|
||||||
count = 0
|
count = 0
|
||||||
@ -59,10 +54,10 @@ module Parfait
|
|||||||
start = start.next_integer
|
start = start.next_integer
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
assert_equal 1024 - 10 , count
|
assert_equal 300-15 , count
|
||||||
end
|
end
|
||||||
def test_default_page
|
def test_page
|
||||||
assert_equal 1024 , Factory.page_size
|
assert_equal 300 , @factory.page_size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -191,7 +191,7 @@ module Parfait
|
|||||||
count += 1
|
count += 1
|
||||||
addr = addr.next_integer
|
addr = addr.next_integer
|
||||||
end
|
end
|
||||||
assert_equal 1014, count
|
assert_equal 1009, count
|
||||||
end
|
end
|
||||||
def test_message_count
|
def test_message_count
|
||||||
mess = @space.get_next_for(:Message)
|
mess = @space.get_next_for(:Message)
|
||||||
@ -201,7 +201,7 @@ module Parfait
|
|||||||
assert mess.locals_used
|
assert mess.locals_used
|
||||||
mess = mess.next_message
|
mess = mess.next_message
|
||||||
end
|
end
|
||||||
assert_equal 1014, count
|
assert_equal 285, count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ module Risc
|
|||||||
ret = main_ticks(46)
|
ret = main_ticks(46)
|
||||||
assert_equal FunctionReturn , ret.class
|
assert_equal FunctionReturn , ret.class
|
||||||
assert_equal :r3 , ret.register.symbol
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module Risc
|
|||||||
|
|
||||||
def test_simple_collect
|
def test_simple_collect
|
||||||
objects = Collector.collect_space(@linker)
|
objects = Collector.collect_space(@linker)
|
||||||
assert_equal 601 , objects.length , objects.length.to_s
|
assert_equal 1564 , objects.length , objects.length.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collect_all_types
|
def test_collect_all_types
|
||||||
@ -55,7 +55,7 @@ module Risc
|
|||||||
|
|
||||||
def test_simple_collect
|
def test_simple_collect
|
||||||
objects = Collector.collect_space(@linker)
|
objects = Collector.collect_space(@linker)
|
||||||
assert_equal 2419, objects.length , objects.length.to_s
|
assert_equal 1564, objects.length , objects.length.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_integer_positions
|
def test_integer_positions
|
||||||
|
@ -55,7 +55,12 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc1
|
||||||
@interpreter.tick
|
@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
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@ -66,11 +71,6 @@ module Risc
|
|||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 3 , @interpreter.clock
|
assert_equal 3 , @interpreter.clock
|
||||||
end
|
end
|
||||||
def test_pc2
|
|
||||||
@interpreter.tick
|
|
||||||
@interpreter.tick
|
|
||||||
assert_equal 25916 , @interpreter.pc
|
|
||||||
end
|
|
||||||
def ttest_tick_14_jump
|
def ttest_tick_14_jump
|
||||||
30.times { @interpreter.tick ;puts @interpreter.instruction.class}
|
30.times { @interpreter.tick ;puts @interpreter.instruction.class}
|
||||||
assert_equal Branch , @interpreter.instruction.class
|
assert_equal Branch , @interpreter.instruction.class
|
||||||
|
@ -25,7 +25,7 @@ module Risc
|
|||||||
assert_equal 0 , Position.get(@linker.cpu_init).at
|
assert_equal 0 , Position.get(@linker.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
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
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
def self.default_test_options
|
def self.default_test_options
|
||||||
{
|
{
|
||||||
factory: 20,
|
Message: 30,
|
||||||
|
Integer: 30,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def self.interpreter_test_options
|
def self.interpreter_test_options
|
||||||
{
|
{
|
||||||
factory: 50,
|
Message: 50,
|
||||||
|
Integer: 50,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def self.full_test_options
|
def self.full_test_options
|
||||||
{
|
{
|
||||||
factory: 1024,
|
Message: 300,
|
||||||
|
Integer: 300,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user