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

@ -15,6 +15,10 @@
module Parfait module Parfait
class List < Object class List < Object
def initialize( )
super()
end
def get_length def get_length
internal_object_length - 1 internal_object_length - 1
end end

View File

@ -43,6 +43,10 @@ module Parfait
method method
end end
def remove_instance_method method
@instance_methods.delete method
end
def create_instance_method name , arg_names def create_instance_method name , arg_names
clazz = Space.object_space.get_class_by_name(self.name) clazz = Space.object_space.get_class_by_name(self.name)
raise "??? #{self.name}" unless clazz raise "??? #{self.name}" unless clazz

View File

@ -43,17 +43,20 @@ module Parfait
# private # private
def set_layout(layout) def set_layout(layout)
if( internal_object_get(LAYOUT_INDEX) ) #if( was = internal_object_get(LAYOUT_INDEX) )
#TODO find out wat these objects are #TODO find out wat these objects are
# puts "Layout was set for #{self.class}" #puts "Layout was set for #{self.class}"
return #puts "#{self}" if self.class == Parfait::Word
end # Space.object_space.check was
# return
#end
raise "Nil layout" unless layout
internal_object_set(LAYOUT_INDEX , layout) internal_object_set(LAYOUT_INDEX , layout)
end end
def get_layout() def get_layout()
l = internal_object_get(LAYOUT_INDEX) l = internal_object_get(LAYOUT_INDEX)
raise "No layout #{self.class}" unless l raise "No layout #{self.class}:#{self.to_s} #{self.object_id}" unless l
return l return l
end end

View File

@ -50,6 +50,25 @@ module Parfait
@next_frame = @frames.first @next_frame = @frames.first
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
# private
def check object , recurse = true
raise "No good #{self.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
@@object_space = nil @@object_space = nil
# Make the object space globally available # Make the object space globally available
def self.object_space def self.object_space

View File

@ -6,6 +6,7 @@ module Builtin
# so it is responsible for initial setup (and relocation) # so it is responsible for initial setup (and relocation)
def __init__ context def __init__ context
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , []) function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
# puts "INIT LAYOUT #{function.get_layout.get_layout}"
function.info.return_type = Virtual::Integer function.info.return_type = Virtual::Integer
main = Virtual::Machine.instance.space.get_main main = Virtual::Machine.instance.space.get_main
me = Virtual::Self.new(Virtual::Reference) me = Virtual::Self.new(Virtual::Reference)

View File

@ -8,6 +8,7 @@ require "virtual/slots/slot"
require "virtual/type" require "virtual/type"
# the passes _are_ order dependant # the passes _are_ order dependant
require "virtual/passes/minimizer" require "virtual/passes/minimizer"
require "virtual/passes/collector"
require "virtual/passes/send_implementation" require "virtual/passes/send_implementation"
require "virtual/passes/get_implementation" require "virtual/passes/get_implementation"
require "virtual/passes/enter_implementation" require "virtual/passes/enter_implementation"

View File

@ -44,6 +44,10 @@ module Virtual
class_mappings.each do |name , clazz| # and the rest class_mappings.each do |name , clazz| # and the rest
clazz.set_super_class(value_classes[3]) # superclasses are object clazz.set_super_class(value_classes[3]) # superclasses are object
end 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 # next create layouts by adding instance variable names to the layouts
class_mappings.each do |name , clazz| class_mappings.each do |name , clazz|
variables = layouts[name] variables = layouts[name]
@ -65,14 +69,15 @@ module Virtual
[@space,@space.classes,@space.classes.keys, @space.classes.values,@space.objects].each do |o| [@space,@space.classes,@space.classes.keys, @space.classes.values,@space.objects].each do |o|
@space.add_object o @space.add_object o
end end
@space.late_init @space.late_init
values.each {|v| v.init_layout }
# now update the layout on all objects created so far, # now update the layout on all objects created so far,
# go through objects in space # go through objects in space
@space.objects.each do | o | @space.objects.each do | o |
o.init_layout o.init_layout
end end
@space.double_check
boot_functions! boot_functions!
end end

View File

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

View File

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