Simplify Parfait booting

Since some weeks, Parfait uses instance variables instead of generated attribute getters (that needed type)
This makes it possible to simplify the boot process, getting rid of separate boot Space and class versions.
It is still quite order dependent, but all "normal" ruby code, (less magic) so easier to understand.

Also moved all code that can never run at runtime into the adapter. This included Space and Object new, space as the space will only ever be created at compile time and object, since that is quite different at run-time (which is where i am working towards)
This commit is contained in:
2019-09-22 19:10:47 +03:00
parent a496ea7e4b
commit e61c5d4a55
11 changed files with 105 additions and 174 deletions

View File

@ -30,7 +30,7 @@ module Parfait
super(instance_type)
@name = name
@super_class_name = superclass
@meta_class = MetaClass.new( self )
@meta_class = MetaClass.new( self , self.type || @name)
end
def rxf_reference_name

View File

@ -25,10 +25,9 @@ module Parfait
8
end
def initialize( clazz )
type = Object.object_space.get_type_by_class_name(:Object)
raise "No type for #{clazz.name}" unless type
super( type )
def initialize( clazz , clazz_type)
raise "No type for #{clazz.name}" unless clazz_type
super( clazz_type )
@clazz = clazz
end

View File

@ -30,36 +30,6 @@ module Parfait
8
end
def initialize( classes , pages)
@classes = classes
@types = Dictionary.new
classes.each do |name , cl|
add_type(cl.instance_type)
end
@factories = Dictionary.new
[:Integer , :ReturnAddress , :Message].each do |fact_name|
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
init_message_chain( factories[ :Message ].reserve )
init_message_chain( factories[ :Message ].next_object )
@true_object = Parfait::TrueClass.new
@false_object = Parfait::FalseClass.new
@nil_object = Parfait::NilClass.new
end
def init_message_chain( message )
prev = nil
while(message)
message.initialize
message._set_caller(prev) if prev
prev = message
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)
@ -88,11 +58,6 @@ module Parfait
types[hash] = type
end
# get a type by the type hash (the hash is what uniquely identifies the type)
def get_type_for( hash )
@types[hash]
end
# all methods form all types
def get_all_methods
methods = []

View File

@ -197,7 +197,9 @@ module Parfait
end
def set_object_class(oc)
raise "object class should be a class, not #{oc.class}" unless oc.is_a?(Class)
unless oc.is_a?(Class) #but during boot a symbol is ok
raise "object class should be a class, not #{oc.class}" unless oc.is_a?(Symbol)
end
@object_class = oc
end
@ -267,7 +269,8 @@ module Parfait
def hash
index = 1
hash_code = Type.str_hash( object_class.name )
name = object_class.is_a?(Symbol) ? object_class : object_class.name
hash_code = Type.str_hash(name)
each do |name , type|
item_hash = Type.str_hash(name) + Type.str_hash(type)
hash_code += item_hash + (item_hash / 256 ) * index