Move the space instance to the parfait module

A better fit, maybe even a pattern for singletons
This commit is contained in:
Torsten Ruger
2016-12-30 14:10:49 +02:00
parent a00f6be3ba
commit f0350601a7
43 changed files with 85 additions and 85 deletions

View File

@ -71,7 +71,7 @@ module Typed
@method = method
@type = method.for_type
else
@type = Parfait::Space.object_space.get_type()
@type = Parfait.object_space.get_type()
@method = @type.get_method( :main )
@method = @type.create_method( :main ,{}) unless @method
end
@ -108,7 +108,7 @@ module Typed
# class_name and method_name are pretty clear, args are given as a ruby array
def create_method( class_name , method_name , args = {})
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
clazz = Parfait::Space.object_space.get_class_by_name! class_name
clazz = Parfait.object_space.get_class_by_name! class_name
create_method_for( clazz.instance_type , method_name , args)
end

View File

@ -46,7 +46,7 @@ module Typed
when Parfait::Type
type = me.type
when Symbol
type = Parfait::Space.object_space.get_class_by_name(me.type).instance_type
type = Parfait.object_space.get_class_by_name(me.type).instance_type
else
raise me.inspect
end

View File

@ -7,7 +7,7 @@ module Typed
type = receiver.type
if(type.is_a?(Symbol))
type = Parfait::Space.object_space.get_class_by_name(type).instance_type
type = Parfait.object_space.get_class_by_name(type).instance_type
end
field_name = statement.field.name

View File

@ -45,7 +45,7 @@ module Typed
end
def load_special_space(statement)
space = Parfait::Space.object_space
space = Parfait.object_space
reg = use_reg :Space , space
add_load_constant( "#{statement} load space", space , reg )
return reg

View File

@ -45,7 +45,7 @@ module Parfait
def super_class
raise "No super_class for class #{@name}" unless @super_class_name
s = Parfait::Space.object_space.get_class_by_name(@super_class_name)
s = Parfait.object_space.get_class_by_name(@super_class_name)
raise "superclass not found for class #{@name} (#{@super_class_name})" unless s
s
end

View File

@ -23,7 +23,7 @@ module Parfait
object = self.allocate
# have to grab the class, because we are in the ruby class not the parfait one
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym)
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

View File

@ -9,6 +9,16 @@
# recycles objects.
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
@ -42,16 +52,6 @@ module Parfait
attr_reader :types , :classes , :first_message
# Make the object space globally available
def self.object_space
@@object_space
end
# TODO Must get rid of the setter
def self.set_object_space space
@@object_space = space
end
def each_type
@types.values.each do |type|
yield(type)

View File

@ -7,7 +7,7 @@ class Symbol
true
end
def get_type
l = Parfait::Space.object_space.classes[:Word].instance_type
l = Parfait.object_space.classes[:Word].instance_type
#puts "LL #{l.class}"
l
end

View File

@ -42,7 +42,7 @@ module Parfait
def self.for_hash( object_class , hash)
new_type = Type.new( object_class , hash)
code = hash_code_for_hash( hash )
Space.object_space.types[code] = new_type
Parfait.object_space.types[code] = new_type
new_type
end
@ -154,7 +154,7 @@ module Parfait
hash = to_hash
hash[name] = type
code = Type.hash_code_for_hash( hash )
existing = Space.object_space.types[code]
existing = Parfait.object_space.types[code]
if existing
return existing
else

View File

@ -40,7 +40,7 @@ module Parfait
@name = name
@binary = BinaryCode.new 0
@arguments = arguments
@locals = Type.new Space.object_space.get_class_by_name( :Object )
@locals = Type.new Parfait.object_space.get_class_by_name( :Object )
end
def set_instructions(inst)