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:
parent
0a390cc5a9
commit
d964e9ea9d
@ -27,12 +27,12 @@ module Parfait
|
||||
16
|
||||
end
|
||||
|
||||
def initialize( next_m )
|
||||
def initialize( )
|
||||
super()
|
||||
self.next_message = next_m
|
||||
self.frame = NamedList.new()
|
||||
self.arguments = NamedList.new()
|
||||
end
|
||||
public :initialize
|
||||
|
||||
def set_receiver(rec)
|
||||
self.receiver = rec
|
||||
|
@ -31,7 +31,6 @@ module Parfait
|
||||
class Space < Object
|
||||
|
||||
attr :type, :classes , :types , :factories
|
||||
attr :next_message , :messages
|
||||
attr :true_object , :false_object , :nil_object
|
||||
|
||||
def initialize( classes )
|
||||
@ -41,15 +40,11 @@ module Parfait
|
||||
add_type(cl.instance_type)
|
||||
end
|
||||
self.factories = Dictionary.new
|
||||
factories[ :Integer ] = Factory.new( classes[:Integer].instance_type).get_more
|
||||
factories[ :ReturnAddress ] = Factory.new( classes[:ReturnAddress].instance_type).get_more
|
||||
message = Message.new(nil)
|
||||
50.times do
|
||||
self.messages = Message.new( message )
|
||||
message.set_caller( self.messages )
|
||||
message = self.messages
|
||||
[:Integer , :ReturnAddress , :Message].each do |fact_name|
|
||||
factories[ fact_name ] = Factory.new( classes[fact_name].instance_type).get_more
|
||||
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.false_object = Parfait::FalseClass.new
|
||||
self.nil_object = Parfait::NilClass.new
|
||||
@ -62,6 +57,12 @@ module Parfait
|
||||
16
|
||||
end
|
||||
|
||||
def init_message_chain( message )
|
||||
while(message)
|
||||
message.initialize
|
||||
message = message.next_message
|
||||
end
|
||||
end
|
||||
# return the factory for the given type
|
||||
# or more exactly the type that has a class_name "name"
|
||||
def get_factory_for(name)
|
||||
|
@ -164,7 +164,6 @@ module Parfait
|
||||
reserve: :Object , attribute_name: :Word },
|
||||
ReturnAddress: {next_integer: :ReturnAddress},
|
||||
Space: {classes: :Dictionary , types: :Dictionary , factories: :Dictionary,
|
||||
next_message: :Message , messages: :Message ,
|
||||
true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass},
|
||||
TrueClass: {},
|
||||
Type: {names: :List , types: :List ,
|
||||
|
@ -5,7 +5,7 @@ module Parfait
|
||||
|
||||
def setup
|
||||
super
|
||||
@mess = @space.next_message
|
||||
@mess = @space.get_next_for(:Message)
|
||||
@type = @mess.get_type
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,7 @@ module Parfait
|
||||
|
||||
def setup
|
||||
super
|
||||
@mess = @space.next_message
|
||||
@mess = @space.get_next_for(:Message)
|
||||
end
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
|
@ -5,7 +5,7 @@ module Parfait
|
||||
|
||||
def setup
|
||||
super
|
||||
@named_list = @space.next_message.frame
|
||||
@named_list = @space.get_next_for(:Message).frame
|
||||
@type = @named_list.get_type
|
||||
end
|
||||
|
||||
|
@ -11,7 +11,7 @@ module Parfait
|
||||
end
|
||||
|
||||
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
|
||||
def test_singletons
|
||||
assert @space.true_object , "No truth"
|
||||
@ -92,7 +92,7 @@ module Parfait
|
||||
assert_equal Dictionary , @space.factories.class
|
||||
end
|
||||
def test_factory_length
|
||||
assert_equal 2 , @space.factories.length
|
||||
assert_equal 3 , @space.factories.length
|
||||
end
|
||||
def test_has_integer_factory
|
||||
ints = @space.get_factory_for(:Integer)
|
||||
@ -126,23 +126,27 @@ module Parfait
|
||||
end
|
||||
assert_equal 1014, count
|
||||
end
|
||||
def test_messages
|
||||
mess = @space.messages
|
||||
all = []
|
||||
while mess
|
||||
all << mess
|
||||
def test_has_message_factory
|
||||
ints = @space.get_factory_for(:Message)
|
||||
assert_equal Factory , ints.class
|
||||
assert_equal :Message , ints.for_type.class_name
|
||||
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
|
||||
mess = mess.next_message
|
||||
end
|
||||
assert_equal all.length , all.uniq.length
|
||||
# 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)
|
||||
assert_equal 1014, count
|
||||
end
|
||||
def test_create_class
|
||||
assert @space.create_class( :NewClass )
|
||||
|
@ -5,7 +5,7 @@ module Parfait
|
||||
|
||||
def setup
|
||||
super
|
||||
@mess = @space.next_message
|
||||
@mess = @space.get_next_for(:Message)
|
||||
assert @mess
|
||||
@type = @mess.get_type()
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Parfait
|
||||
|
||||
def setup
|
||||
super
|
||||
@mess = @space.next_message
|
||||
@mess = @space.get_next_for(:Message)
|
||||
end
|
||||
|
||||
def test_message_type
|
||||
|
@ -27,7 +27,7 @@ module Parfait
|
||||
assert_equal Parfait::Space , space.class
|
||||
type = space.get_type
|
||||
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.name , :Space
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user