debugging missing layout

This commit is contained in:
Torsten Ruger
2015-05-31 11:07:49 +03:00
parent deaa062062
commit aaa206fbca
11 changed files with 92 additions and 14 deletions

View File

@ -44,6 +44,10 @@ module Virtual
class_mappings.each do |name , clazz| # and the rest
clazz.set_super_class(value_classes[3]) # superclasses are object
end
supers = { "BinaryCode" => "Word", "Layout" => "List", "Class" => "Module"}
supers.each do |clazz , superclaszz| # set_super_class has no sideeffects, so setting twice ok
class_mappings[clazz].set_super_class class_mappings[superclaszz]
end
# next create layouts by adding instance variable names to the layouts
class_mappings.each do |name , clazz|
variables = layouts[name]
@ -65,14 +69,15 @@ module Virtual
[@space,@space.classes,@space.classes.keys, @space.classes.values,@space.objects].each do |o|
@space.add_object o
end
@space.late_init
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 |
o.init_layout
end
@space.double_check
boot_functions!
end

View File

@ -39,10 +39,11 @@ module Virtual
@parser = Parser::Salama.new
@passes = [ "Virtual::SendImplementation" ]
end
attr_reader :message , :passes , :space , :class_mappings , :init
attr_reader :passes , :space , :class_mappings , :init
def run_passes
Minimizer.new.run
Collector.new.run
@passes.each do |pass_class|
blocks = [@init]
@space.classes.values.each do |c|

View File

@ -6,21 +6,27 @@
module FakeMem
def initialize
super()
@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}"
# Note: the else is handled in boot, by ading the space "by hand", as it slips though
# puts "Got away #{self.class}"
end
if Virtual::Machine.instance.class_mappings
init_layout
else
#puts "No init for #{self.class}:#{self.object_id}"
end
init_layout if Virtual::Machine.instance.class_mappings
end
def init_layout
vm_name = self.class.name.split("::").last
clazz = Virtual::Machine.instance.class_mappings[vm_name]
raise "Class not found #{vm_name}" unless clazz
raise "Layout not set #{vm_name}" unless clazz.object_layout
self.set_layout clazz.object_layout
end
#TODO, this is copied from module Positioned, maybe avoid duplication ?
@ -163,7 +169,7 @@ module Virtual
# Functions to generate parfait objects
def self.new_word( string )
string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new( string.length )
word = Parfait::Word.new_object( string.length )
string.codepoints.each_with_index do |code , index |
word.set_char(index + 1 , code)
end

View File

@ -0,0 +1,33 @@
module Virtual
# garbage collect anything that is in the space but not reachable from init
class Collector
def run
@keepers = []
init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
keep init
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
end
layout.each do |name|
inst = object.instance_variable_get "@#{name}".to_sym
keep inst
end
if object.is_a? Parfait::List
object.each do |item|
keep item
end
end
end
end
end

View File

@ -37,8 +37,9 @@ module Virtual
end
def dump_remaining
names = @gonners.collect {|f| f.name }
puts "Dump #{names}"
@gonners.each do |method|
method.for_class.remove_instance_method method
end
end
end
end