let spce keep the messages in a factory #14

Like Integers and addresses before, messages are now in a factory
Factories keep allocated (uninitialised) objects, had to make init public to call it
This commit is contained in:
Torsten Ruger 2018-09-01 11:24:16 +03:00
parent 0a390cc5a9
commit d964e9ea9d
10 changed files with 39 additions and 35 deletions

View File

@ -27,12 +27,12 @@ module Parfait
16 16
end end
def initialize( next_m ) def initialize( )
super() super()
self.next_message = next_m
self.frame = NamedList.new() self.frame = NamedList.new()
self.arguments = NamedList.new() self.arguments = NamedList.new()
end end
public :initialize
def set_receiver(rec) def set_receiver(rec)
self.receiver = rec self.receiver = rec

View File

@ -31,7 +31,6 @@ module Parfait
class Space < Object class Space < Object
attr :type, :classes , :types , :factories attr :type, :classes , :types , :factories
attr :next_message , :messages
attr :true_object , :false_object , :nil_object attr :true_object , :false_object , :nil_object
def initialize( classes ) def initialize( classes )
@ -41,15 +40,11 @@ module Parfait
add_type(cl.instance_type) add_type(cl.instance_type)
end end
self.factories = Dictionary.new self.factories = Dictionary.new
factories[ :Integer ] = Factory.new( classes[:Integer].instance_type).get_more [:Integer , :ReturnAddress , :Message].each do |fact_name|
factories[ :ReturnAddress ] = Factory.new( classes[:ReturnAddress].instance_type).get_more factories[ fact_name ] = Factory.new( classes[fact_name].instance_type).get_more
message = Message.new(nil)
50.times do
self.messages = Message.new( message )
message.set_caller( self.messages )
message = self.messages
end end
self.next_message = self.messages init_message_chain( factories[ :Message ].reserve )
init_message_chain( factories[ :Message ].next_object )
self.true_object = Parfait::TrueClass.new self.true_object = Parfait::TrueClass.new
self.false_object = Parfait::FalseClass.new self.false_object = Parfait::FalseClass.new
self.nil_object = Parfait::NilClass.new self.nil_object = Parfait::NilClass.new
@ -62,6 +57,12 @@ module Parfait
16 16
end end
def init_message_chain( message )
while(message)
message.initialize
message = message.next_message
end
end
# return the factory for the given type # return the factory for the given type
# or more exactly the type that has a class_name "name" # or more exactly the type that has a class_name "name"
def get_factory_for(name) def get_factory_for(name)

View File

@ -164,7 +164,6 @@ module Parfait
reserve: :Object , attribute_name: :Word }, reserve: :Object , attribute_name: :Word },
ReturnAddress: {next_integer: :ReturnAddress}, ReturnAddress: {next_integer: :ReturnAddress},
Space: {classes: :Dictionary , types: :Dictionary , factories: :Dictionary, Space: {classes: :Dictionary , types: :Dictionary , factories: :Dictionary,
next_message: :Message , messages: :Message ,
true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass}, true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass},
TrueClass: {}, TrueClass: {},
Type: {names: :List , types: :List , Type: {names: :List , types: :List ,

View File

@ -5,7 +5,7 @@ module Parfait
def setup def setup
super super
@mess = @space.next_message @mess = @space.get_next_for(:Message)
@type = @mess.get_type @type = @mess.get_type
end end

View File

@ -5,7 +5,7 @@ module Parfait
def setup def setup
super super
@mess = @space.next_message @mess = @space.get_next_for(:Message)
end end
def test_length def test_length
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect

View File

@ -5,7 +5,7 @@ module Parfait
def setup def setup
super super
@named_list = @space.next_message.frame @named_list = @space.get_next_for(:Message).frame
@type = @named_list.get_type @type = @named_list.get_type
end end

View File

@ -11,7 +11,7 @@ module Parfait
end end
def test_space_length def test_space_length
assert_equal 9 , @space.get_type.instance_length , @space.get_type.inspect assert_equal 7 , @space.get_type.instance_length , @space.get_type.inspect
end end
def test_singletons def test_singletons
assert @space.true_object , "No truth" assert @space.true_object , "No truth"
@ -92,7 +92,7 @@ module Parfait
assert_equal Dictionary , @space.factories.class assert_equal Dictionary , @space.factories.class
end end
def test_factory_length def test_factory_length
assert_equal 2 , @space.factories.length assert_equal 3 , @space.factories.length
end end
def test_has_integer_factory def test_has_integer_factory
ints = @space.get_factory_for(:Integer) ints = @space.get_factory_for(:Integer)
@ -126,23 +126,27 @@ module Parfait
end end
assert_equal 1014, count assert_equal 1014, count
end end
def test_messages def test_has_message_factory
mess = @space.messages ints = @space.get_factory_for(:Message)
all = [] assert_equal Factory , ints.class
while mess assert_equal :Message , ints.for_type.class_name
all << mess end
def test_has_messages
nekst = @space.get_next_for(:Message)
assert_equal Parfait::Message , nekst.class
end
def test_has_next_message
assert_equal Parfait::Message , @space.get_next_for(:Message).class
end
def test_message_count
mess = @space.get_next_for(:Message)
count = 0
while(mess)
count += 1
assert mess.frame assert mess.frame
mess = mess.next_message mess = mess.next_message
end end
assert_equal all.length , all.uniq.length assert_equal 1014, count
# there is a 5.times in space, but one Message gets created before
assert_equal 50 + 1 , all.length
end
def test_message_vars
mess = @space.next_message
all = mess.get_instance_variables
assert all
assert all.include?(:next_message)
end end
def test_create_class def test_create_class
assert @space.create_class( :NewClass ) assert @space.create_class( :NewClass )

View File

@ -5,7 +5,7 @@ module Parfait
def setup def setup
super super
@mess = @space.next_message @mess = @space.get_next_for(:Message)
assert @mess assert @mess
@type = @mess.get_type() @type = @mess.get_type()
end end

View File

@ -5,7 +5,7 @@ module Parfait
def setup def setup
super super
@mess = @space.next_message @mess = @space.get_next_for(:Message)
end end
def test_message_type def test_message_type

View File

@ -27,7 +27,7 @@ module Parfait
assert_equal Parfait::Space , space.class assert_equal Parfait::Space , space.class
type = space.get_type type = space.get_type
assert_equal Parfait::Type , type.class assert_equal Parfait::Type , type.class
assert_equal 9 , type.names.get_length assert_equal 7 , type.names.get_length
assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.class , Parfait::Class
assert_equal type.object_class.name , :Space assert_equal type.object_class.name , :Space
end end