Move the space instance to the parfait module
A better fit, maybe even a pattern for singletons
This commit is contained in:
@ -21,7 +21,7 @@ module Elf
|
||||
set_text assembler.write_as_string
|
||||
|
||||
# for debug add labels for labels
|
||||
Parfait::Space.object_space.types.values.each do |type|
|
||||
Parfait.object_space.types.values.each do |type|
|
||||
type.methods.each do |f|
|
||||
f.instructions.each_label do |label|
|
||||
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position
|
||||
|
@ -21,7 +21,7 @@ module Melon
|
||||
|
||||
def on_class statement
|
||||
name , sup , body = *statement
|
||||
clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) )
|
||||
clazz = Parfait.object_space.create_class(get_name(name) , get_name(sup) )
|
||||
ivar_hash = TypeCollector.new.collect(body)
|
||||
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
||||
|
||||
|
@ -21,7 +21,7 @@ module Melon
|
||||
private
|
||||
|
||||
def make_type( statement )
|
||||
type = Parfait::Space.object_space.get_class_by_name(:Message ).instance_type
|
||||
type = Parfait.object_space.get_class_by_name(:Message ).instance_type
|
||||
statement.children.each do |arg|
|
||||
type = type.add_instance_variable( arg.children[0] , :Object )
|
||||
end
|
||||
@ -30,7 +30,7 @@ module Melon
|
||||
|
||||
def make_locals(body)
|
||||
locals = LocalsCollector.new.collect(body)
|
||||
type = Parfait::Space.object_space.get_class_by_name(:NamedList ).instance_type
|
||||
type = Parfait.object_space.get_class_by_name(:NamedList ).instance_type
|
||||
locals.each do |name , local_type |
|
||||
type = type.add_instance_variable( name , local_type )
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ module Register
|
||||
fix_types( types , classes )
|
||||
|
||||
space = Parfait::Space.new( classes )
|
||||
Parfait::Space.set_object_space( space )
|
||||
Parfait.set_object_space( space )
|
||||
|
||||
#puts Sof.write(@space)
|
||||
boot_functions!( space )
|
||||
@ -91,7 +91,7 @@ module Register
|
||||
clazz = BootClass.new(type)
|
||||
boot_space.classes[name] = clazz
|
||||
end
|
||||
Parfait::Space.set_object_space boot_space
|
||||
Parfait.set_object_space boot_space
|
||||
end
|
||||
|
||||
# superclasses other than default object
|
||||
|
@ -11,7 +11,7 @@ module Register
|
||||
compiler.method.set_instructions( new_start)
|
||||
compiler.set_current new_start
|
||||
|
||||
space = Parfait::Space.object_space
|
||||
space = Parfait.object_space
|
||||
space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init
|
||||
compiler.add_load_constant("__init__ load Space", space , space_reg)
|
||||
message_ind = Register.resolve_to_index( :space , :first_message )
|
||||
@ -21,7 +21,7 @@ module Register
|
||||
ret_tmp = compiler.use_reg(:Label)
|
||||
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||
compiler.add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address)
|
||||
compiler.add_code Register.function_call( "__init__ issue call" , Parfait::Space.object_space.get_main )
|
||||
compiler.add_code Register.function_call( "__init__ issue call" , Parfait.object_space.get_main )
|
||||
compiler.add_code exit_label
|
||||
emit_syscall( compiler , :exit )
|
||||
return compiler.method
|
||||
|
@ -4,7 +4,7 @@ module Register
|
||||
module Collector
|
||||
def collect
|
||||
self.objects.clear
|
||||
keep Parfait::Space.object_space , 0
|
||||
keep Parfait.object_space , 0
|
||||
constants.each {|o| keep(o,0)}
|
||||
end
|
||||
|
||||
|
@ -26,7 +26,7 @@ module Register
|
||||
# idea being that later method missing could catch translate_xxx and translate to target xxx
|
||||
# now we just instantiate ArmTranslater and pass instructions
|
||||
def translate_arm
|
||||
methods = Parfait::Space.object_space.collect_methods
|
||||
methods = Parfait.object_space.collect_methods
|
||||
translate_methods( methods )
|
||||
label = @init.next
|
||||
@init = Arm::Translator.new.translate( @init )
|
||||
@ -64,7 +64,7 @@ module Register
|
||||
def boot
|
||||
initialize
|
||||
boot_parfait!
|
||||
@init = Branch.new( "__initial_branch__" , Parfait::Space.object_space.get_init.instructions )
|
||||
@init = Branch.new( "__initial_branch__" , Parfait.object_space.get_init.instructions )
|
||||
@booted = true
|
||||
self
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ module Register
|
||||
def self.resolve_to_index( clazz_name , instance_name )
|
||||
return instance_name unless instance_name.is_a? Symbol
|
||||
real_name = clazz_name.to_s.split('_').last.capitalize.to_sym
|
||||
clazz = Parfait::Space.object_space.get_class_by_name(real_name)
|
||||
clazz = Parfait.object_space.get_class_by_name(real_name)
|
||||
raise "Class name not given #{real_name}" unless clazz
|
||||
index = clazz.instance_type.variable_index( instance_name )
|
||||
raise "Instance name=#{instance_name} not found on #{real_name}:#{clazz.instance_type}" unless index.is_a?(Numeric)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user