Moving space to object class

away from Parfait module, as that gets collapsed
Leaving shortcut outside parfait for now
This commit is contained in:
2019-09-18 22:36:56 +03:00
parent 41617519d9
commit b0d1948800
14 changed files with 55 additions and 44 deletions

View File

@ -1,25 +1,6 @@
# Parfait is the ruby runtime
module Parfait
TYPE_INDEX = 0
class Object
def self.memory_size
8
end
def self.type_length
1
end
def self.new( *args )
object = self.allocate
# have to grab the class, because we are in the ruby class not the parfait one
cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym)
# and have to set the type before we let the object do anything. otherwise boom
object.set_type cl.instance_type
object.send :initialize , *args
object
end
end
end
require_relative "parfait/object"
@ -41,3 +22,32 @@ require_relative "parfait/type"
require_relative "parfait/cache_entry"
require_relative "parfait/message"
require_relative "parfait/space"
module Parfait
# temporary shorthand getter for the space
# See implementation, space is now moved to inside the Object class
# (not module anymore), but there is a lot of code (about 100, 50/50 li/test)
# still calling this old version and since it is shorter . . .
def self.object_space
Object.object_space
end
class Object
# redefine the runtime version
def self.new( *args )
object = self.allocate
# have to grab the class, because we are in the ruby class not the parfait one
cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym)
# and have to set the type before we let the object do anything. otherwise boom
object.set_type cl.instance_type
object.send :initialize , *args
object
end
# Setter fo the boot process, only at runtime.
# only one space exists and it is generated at compile time, not runtime
def self.set_object_space( space )
@object_space = space
end
end
end

View File

@ -87,7 +87,7 @@ module Parfait
# Nil name means no superclass, and so nil is a valid return value
def super_class
return nil unless @super_class_name
Parfait.object_space.get_class_by_name(@super_class_name)
Object.object_space.get_class_by_name(@super_class_name)
end
# ruby 2.1 list (just for reference, keep at bottom)

View File

@ -25,10 +25,10 @@ module Parfait
32
end
def self.args_start_at
Parfait.object_space.get_type_by_class_name(:Message).variable_index(:arguments_given)
Object.object_space.get_type_by_class_name(:Message).variable_index(:arguments_given)
end
def self.locals_start_at
Parfait.object_space.get_type_by_class_name(:Message).variable_index(:locals_used)
Object.object_space.get_type_by_class_name(:Message).variable_index(:locals_used)
end
def initialize( )

View File

@ -15,13 +15,23 @@
module Parfait
class Object
attr_reader :type
def self.type_length
1
end
def self.memory_size
4
end
# Make the object space globally available
def self.object_space
@object_space
end
def self.new
factory = @object_space.get_factory(:Object)
object = factory.get_next
object.initialize
end
def type=(t)
set_type( t )

View File

@ -8,15 +8,6 @@
#
#
module Parfait
# Make the object space globally available
def self.object_space
@object_space
end
# TODO Must get rid of the setter (move the boot process ?)
def self.set_object_space( space )
@object_space = space
end
# The Space contains all objects for a program. In functional terms it is a program, but in oo
# it is a collection of objects, some of which are data, some classes, some functions

View File

@ -45,12 +45,12 @@ module Parfait
def self.for_hash( hash , object_class = :Object)
name = object_class
if(object_class.is_a?(Symbol))
object_class = Parfait.object_space.get_class_by_name(object_class)
object_class = Object.object_space.get_class_by_name(object_class)
end
raise "No such class #{name}" unless object_class
hash = {type: object_class.name }.merge(hash) unless hash[:type]
new_type = Type.new( object_class , hash)
Parfait.object_space.add_type(new_type)
Object.object_space.add_type(new_type)
end
# should not be called directly. Use Type.for_hash instead, that adds the

View File

@ -50,13 +50,13 @@ module Parfait
# - flesh out the types , create the real space
# - and finally load the methods
def self.boot!(options)
Parfait.set_object_space( nil )
Parfait::Object.set_object_space( nil ) # in case we are rebooting
types = boot_types
boot_boot_space( types )
classes = boot_classes( types )
fix_types( types , classes )
space = Space.new( classes , options )
Parfait.set_object_space( space )
Parfait::Object.set_object_space( space )
end
# types is where the snake bites its tail. Every chain ends at a type and then it
@ -83,7 +83,7 @@ module Parfait
clazz = Boot::Class.new(type)
boot_space.classes[name] = clazz
end
Parfait.set_object_space( boot_space )
Parfait::Object.set_object_space( boot_space )
end
# when running code instantiates a class, a type is created automatically