fixed layouts
also moved objects to machine, from space space has a list of objects, but implicit, not as an explicit array
This commit is contained in:
@ -27,7 +27,7 @@ module Virtual
|
||||
"List" => [] ,
|
||||
"Message" => [],
|
||||
"BinaryCode" => [],
|
||||
"Space" => ["classes","objects","frames","messages","next_message","next_frame"],
|
||||
"Space" => ["classes","frames","messages","next_message","next_frame"],
|
||||
"Frame" => ["locals" , "tmps" ],
|
||||
"Layout" => ["object_class"] ,
|
||||
"Class" => ["object_layout"],
|
||||
@ -65,19 +65,17 @@ module Virtual
|
||||
class_mappings["Kernel"] = value_classes[2] #need for further booting
|
||||
class_mappings["Object"] = value_classes[3] #need for further booting
|
||||
|
||||
# add space and instances which get created before the objects list
|
||||
[@space,@space.classes,@space.classes.keys, @space.classes.values,@space.objects].each do |o|
|
||||
@space.add_object o
|
||||
end
|
||||
@space.late_init
|
||||
|
||||
# add_object @space
|
||||
|
||||
values.each {|v| v.init_layout }
|
||||
|
||||
|
||||
# now update the layout on all objects created so far,
|
||||
# go through objects in space
|
||||
@space.objects.each do | o |
|
||||
@objects.each do | o |
|
||||
o.init_layout
|
||||
end
|
||||
@space.double_check
|
||||
boot_functions!
|
||||
end
|
||||
|
||||
|
@ -38,8 +38,9 @@ module Virtual
|
||||
def initialize
|
||||
@parser = Parser::Salama.new
|
||||
@passes = [ "Virtual::SendImplementation" ]
|
||||
@objects = []
|
||||
end
|
||||
attr_reader :passes , :space , :class_mappings , :init
|
||||
attr_reader :passes , :space , :class_mappings , :init , :objects
|
||||
|
||||
def run_passes
|
||||
Minimizer.new.run
|
||||
@ -62,6 +63,34 @@ module Virtual
|
||||
end
|
||||
end
|
||||
|
||||
# double check that all objects dependents are really in the space too (debugging)
|
||||
def double_check
|
||||
@objects.each do |o|
|
||||
check o
|
||||
end
|
||||
end
|
||||
# Objects are data and get assembled after functions
|
||||
def add_object o
|
||||
return false if @objects.include?(o)
|
||||
@objects.push o
|
||||
true
|
||||
end
|
||||
|
||||
# private
|
||||
def check object , recurse = true
|
||||
raise "No good #{object.class}" unless @objects.include? object
|
||||
puts "#{object.class}"
|
||||
puts "#{object}" if object.class == Parfait::Word
|
||||
check object.get_layout
|
||||
return unless recurse
|
||||
object.get_layout.each do |name|
|
||||
check name , false
|
||||
inst = object.instance_variable_get "@#{name}".to_sym
|
||||
check inst , false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Passes may be added to by anyone who wants
|
||||
# This is intentionally quite flexible, though one sometimes has to watch the order of them
|
||||
# most ordering is achieved by ordering the requires and using add_pass
|
||||
|
@ -10,12 +10,7 @@ module FakeMem
|
||||
@memory = [0,nil]
|
||||
@position = nil
|
||||
@length = -1
|
||||
if Parfait::Space.object_space and Parfait::Space.object_space.objects
|
||||
Parfait::Space.object_space.add_object self
|
||||
else
|
||||
# Note: the else is handled in boot, by ading the space "by hand", as it slips though
|
||||
# puts "Got away #{self.class}"
|
||||
end
|
||||
# Virtual::Machine.instance.add_object self
|
||||
if Virtual::Machine.instance.class_mappings
|
||||
init_layout
|
||||
else
|
||||
|
@ -1,24 +1,22 @@
|
||||
module Virtual
|
||||
|
||||
# garbage collect anything that is in the space but not reachable from init
|
||||
# collect anything that is in the space but and reachable from init
|
||||
class Collector
|
||||
def run
|
||||
@keepers = []
|
||||
init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
|
||||
keep init
|
||||
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
|
||||
keep Parfait::Space.object_space
|
||||
end
|
||||
|
||||
def keep object
|
||||
return if @keepers.include? object
|
||||
layout = object.get_layout
|
||||
begin
|
||||
puts "Object #{object.class} #{Parfait::Space.object_space.objects.include?(object)}"
|
||||
puts "Object #{layout.object_id} #{Parfait::Space.object_space.objects.include?(layout)}"
|
||||
keep layout
|
||||
rescue => e
|
||||
puts "for #{object.name}"
|
||||
raise e
|
||||
return if object.nil?
|
||||
return unless Machine.instance.add_object object
|
||||
# puts "adding #{object.class}"
|
||||
unless object.has_layout?
|
||||
object.init_layout
|
||||
end
|
||||
layout = object.get_layout
|
||||
puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
|
||||
keep layout
|
||||
layout.each do |name|
|
||||
inst = object.instance_variable_get "@#{name}".to_sym
|
||||
keep inst
|
||||
|
Reference in New Issue
Block a user