move address list to object_space

where i guess it should have been from the start
This commit is contained in:
Torsten Ruger 2018-07-01 13:43:53 +03:00
parent 35b10c46a3
commit 57fc67ddf6
3 changed files with 40 additions and 17 deletions

View File

@ -36,6 +36,8 @@ module Parfait
@types = Dictionary.new
message = Message.new(nil)
101.times { @next_integer = Integer.new(0,@next_integer) }
10.times { @next_address = ReturnAddress.new(0,@next_address) }
50.times do
@first_message = Message.new message
message.set_caller @first_message
@ -49,7 +51,7 @@ module Parfait
@nil_object = Parfait::NilClass.new
end
attr_reader :classes , :types , :first_message , :next_integer
attr_reader :classes , :types , :first_message , :next_integer , :next_address
attr_reader :true_object , :false_object , :nil_object
# hand out one of the preallocated ints for use as constant
@ -62,6 +64,16 @@ module Parfait
int
end
# hand out a return address for use as constant the address is added
def get_address
10.times do # 10 for whole pages
@next_address = ReturnAddress.new(0,@next_address)
end unless @next_address
addr = @next_address
@next_address = @next_address.next_integer
addr
end
def each_type
@types.values.each do |type|
yield(type)

View File

@ -115,7 +115,8 @@ module Parfait
# superclasses other than default object
def self.super_class_names
{ Data4: :DataObject , Data8: :DataObject ,Data16: :DataObject ,Data32: :DataObject ,
{ Data4: :DataObject , Data8: :DataObject ,Data16: :DataObject ,
Data32: :DataObject ,
BinaryCode: :Data16 , Integer: :Data4 , Word: :Data8 ,
Object: :BasicObject, List: :Data16 , ReturnAddress: :Integer}
end
@ -130,7 +131,7 @@ module Parfait
return_address: :Integer, return_value: :Object,
caller: :Message , name: :Word , arguments: :NamedList },
Integer: {next_integer: :Integer},
ReturnAddress: {next_integer: :Integer},
ReturnAddress: {next_integer: :ReturnAddress},
DataObject: {},
Data4: {},
Data8: {},
@ -141,7 +142,7 @@ module Parfait
BinaryCode: {next: :BinaryCode} ,
Space: {classes: :Dictionary , types: :Dictionary ,
first_message: :Message , next_integer: :Integer ,
true_object: :TrueClass,
true_object: :TrueClass, next_address: :ReturnAddress ,
false_object: :FalseClass , nil_object: :NilClass},
NamedList: {},
Type: {names: :List , types: :List ,

View File

@ -4,11 +4,13 @@ module Parfait
class TestSpace < ParfaitTest
def classes
[:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
[:Word,:List,:Message,:Integer,:ReturnAddress,:DataObject,:Data4,:Data8,
:TrueClass,:FalseClass,:NilClass,:Object,:BinaryCode,:Space,:NamedList,
:Type,:Class,:Dictionary,:CacheEntry,:TypedMethod,:VoolMethod]
end
def test_space_length
assert_equal 8 , @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"
@ -19,7 +21,6 @@ module Parfait
assert_equal Parfait::Space , Parfait.object_space.class
end
def test_get_integer_instance
int = @space.get_integer
assert_equal Integer , int.class
@ -30,33 +31,31 @@ module Parfait
assert_equal Parfait::Class , @space.classes[name].class
end
end
def test_all_classes
assert_equal classes.length , @space.classes.length , @space.classes.keys.inspect
end
def test_types
assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary
end
def test_types_attr
assert @space.types.is_a? Parfait::Dictionary
end
def test_types_each
@space.each_type do |type|
assert type.is_a?(Parfait::Type)
end
end
def test_types_hashes
types = @space.instance_variable_ged("@types")
types.each do |has , type|
assert has.is_a?(Fixnum) , has.inspect
end
end
def test_classes_types_in_space_types
@space.classes do |name , clazz|
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
end
end
def test_word_class
word = @space.classes[:Word]
assert word.instance_type
@ -64,19 +63,16 @@ module Parfait
assert_equal word.instance_type.hash , t_word.hash
assert_equal word.instance_type.object_id , t_word.object_id
end
def test_classes_type
classes.each do |name|
assert_equal Parfait::Type , @space.classes[name].get_type.class
end
end
def test_classes_name
classes.each do |name|
assert_equal name , @space.classes[name].name
end
end
def test_method_name
classes.each do |name|
cl = @space.classes[name]
@ -87,6 +83,21 @@ module Parfait
end
end
end
def test_has_integers
assert_equal Parfait::Integer , @space.next_integer.class
assert_equal 0 , @space.next_integer.value
end
def test_has_next_integer
assert_equal Parfait::Integer , @space.next_integer.next_integer.class
end
def test_has_addresses
assert_equal Parfait::ReturnAddress , @space.next_address.class
assert_equal 0 , @space.next_address.value
end
def test_has_next_address
assert_equal Parfait::ReturnAddress , @space.next_address.next_integer.class
end
def test_messages
mess = @space.first_message
all = []
@ -105,7 +116,6 @@ module Parfait
assert all
assert all.include?(:next_message)
end
def test_create_class
assert @space.create_class( :NewClass )
end