diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 85d17680..0f80d4ca 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -1,13 +1,12 @@ -# A Space is a collection of pages. It stores objects, the data for the objects, -# not references. See Page for more detail. - -# Pages are stored by the object size they represent in a hash. - -# Space and Page work together in making *new* objects available. -# "New" is slightly misleading in that normal operation only ever -# recycles objects. - +# The Space is the root object we work off, the only singleton in the parfait world +# +# Space stores the types, classes, factories and singleton objects (true/false/nil) +# +# The Space is booted at compile time, a process outside the scope of Parfait(in parfait_boot) +# Then it is used during compilation and later serialized into the resulting binary +# +# module Parfait # Make the object space globally available def self.object_space @@ -32,8 +31,7 @@ module Parfait class Space < Object attr :type, :classes , :types , :factories - attr :next_message , :next_address - attr :messages, :addresses + attr :next_message , :messages attr :true_object , :false_object , :nil_object def initialize( classes ) @@ -43,8 +41,8 @@ module Parfait add_type(cl.instance_type) end self.factories = Dictionary.new - factories[ :Integer ] = Factory.new( classes[:Integer].instance_type) - 400.times { self.addresses = ReturnAddress.new(0,self.addresses) } + 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 ) @@ -52,7 +50,6 @@ module Parfait message = self.messages end self.next_message = self.messages - self.next_address = self.addresses self.true_object = Parfait::TrueClass.new self.false_object = Parfait::FalseClass.new self.nil_object = Parfait::NilClass.new @@ -77,13 +74,6 @@ module Parfait factories[name].get_next_object end - # hand out a return address for use as constant the address is added - def get_address - addr = next_address - self.next_address = next_address.next_integer - addr - end - # yield each type in the space def each_type types.values.each do |type| diff --git a/lib/risc/instructions/label.rb b/lib/risc/instructions/label.rb index 389cbe9c..fb17f63e 100644 --- a/lib/risc/instructions/label.rb +++ b/lib/risc/instructions/label.rb @@ -65,7 +65,7 @@ module Risc # An integer is plucked from object_space abd added to the machine constant pool # if none was given def self.label( source , name , position = nil , nekst = nil) - position = Parfait.object_space.get_address unless position + position = Parfait.object_space.get_next_for(:ReturnAddress) unless position Label.new( source , name , position, nekst ) end end diff --git a/lib/risc/parfait_boot.rb b/lib/risc/parfait_boot.rb index 07a681f8..3e69208c 100644 --- a/lib/risc/parfait_boot.rb +++ b/lib/risc/parfait_boot.rb @@ -160,12 +160,11 @@ module Parfait NamedList: {}, NilClass: {}, Object: {}, - Factory: { for_type: :Type , next_object: :Object , last_object: :Object , + Factory: { for_type: :Type , next_object: :Object , reserve: :Object , attribute_name: :Word }, ReturnAddress: {next_integer: :ReturnAddress}, Space: {classes: :Dictionary , types: :Dictionary , factories: :Dictionary, next_message: :Message , messages: :Message , - next_address: :ReturnAddress ,addresses: :ReturnAddress , true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass}, TrueClass: {}, Type: {names: :List , types: :List , diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 89bb0bb4..323bcd04 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -11,7 +11,7 @@ module Parfait end def test_space_length - assert_equal 11 , @space.get_type.instance_length , @space.get_type.inspect + assert_equal 9 , @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 1 , @space.factories.length + assert_equal 2 , @space.factories.length end def test_has_integer_factory ints = @space.get_factory_for(:Integer) @@ -110,20 +110,21 @@ module Parfait assert_equal Parfait::Integer , nekst.class end def test_has_addresses - assert_equal Parfait::ReturnAddress , @space.next_address.class - assert_equal 0 , @space.next_address.value + ret = @space.get_next_for(:ReturnAddress) + assert_equal Parfait::ReturnAddress , ret.class + assert_nil ret.value end def test_has_next_address - assert_equal Parfait::ReturnAddress , @space.next_address.next_integer.class + assert_equal Parfait::ReturnAddress , @space.get_next_for(:ReturnAddress).class end def test_address_count - addr = @space.addresses + addr = @space.get_next_for(:ReturnAddress) count = 0 while(addr) count += 1 addr = addr.next_integer end - assert_equal 400, count + assert_equal 1014, count end def test_messages mess = @space.messages diff --git a/test/parfait/type/test_type_api.rb b/test/parfait/type/test_type_api.rb index 7bc8c575..72a441e5 100644 --- a/test/parfait/type/test_type_api.rb +++ b/test/parfait/type/test_type_api.rb @@ -27,7 +27,7 @@ module Parfait assert_equal Parfait::Space , space.class type = space.get_type assert_equal Parfait::Type , type.class - assert_equal 11 , type.names.get_length + assert_equal 9 , type.names.get_length assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.name , :Space end diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 266b3778..dd6178bb 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -54,7 +54,7 @@ module Risc end def test_pc1 @interpreter.tick - assert_equal 41592 , @interpreter.pc + assert_equal 49992 , @interpreter.pc end def test_tick2 @interpreter.tick @@ -68,7 +68,7 @@ module Risc def test_pc2 @interpreter.tick @interpreter.tick - assert_equal 41596 , @interpreter.pc + assert_equal 49996 , @interpreter.pc end def test_tick_14_jump 14.times {@interpreter.tick} diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index 8bbc7e70..22eb93b1 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 "0xb12c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0xd1fc" , Position.get(@linker.cpu_init.first).to_s end def test_cpu_label assert_equal Position , Position.get(@linker.cpu_init.first).class