debugging missing layout
This commit is contained in:
parent
deaa062062
commit
aaa206fbca
@ -15,6 +15,10 @@
|
||||
module Parfait
|
||||
class List < Object
|
||||
|
||||
def initialize( )
|
||||
super()
|
||||
end
|
||||
|
||||
def get_length
|
||||
internal_object_length - 1
|
||||
end
|
||||
|
@ -43,6 +43,10 @@ module Parfait
|
||||
method
|
||||
end
|
||||
|
||||
def remove_instance_method method
|
||||
@instance_methods.delete method
|
||||
end
|
||||
|
||||
def create_instance_method name , arg_names
|
||||
clazz = Space.object_space.get_class_by_name(self.name)
|
||||
raise "??? #{self.name}" unless clazz
|
||||
|
@ -43,17 +43,20 @@ module Parfait
|
||||
|
||||
# private
|
||||
def set_layout(layout)
|
||||
if( internal_object_get(LAYOUT_INDEX) )
|
||||
#if( was = internal_object_get(LAYOUT_INDEX) )
|
||||
#TODO find out wat these objects are
|
||||
# puts "Layout was set for #{self.class}"
|
||||
return
|
||||
end
|
||||
#puts "Layout was set for #{self.class}"
|
||||
#puts "#{self}" if self.class == Parfait::Word
|
||||
# Space.object_space.check was
|
||||
# return
|
||||
#end
|
||||
raise "Nil layout" unless layout
|
||||
internal_object_set(LAYOUT_INDEX , layout)
|
||||
end
|
||||
|
||||
def get_layout()
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -50,6 +50,25 @@ module Parfait
|
||||
@next_frame = @frames.first
|
||||
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
|
||||
# Make the object space globally available
|
||||
def self.object_space
|
||||
|
@ -6,6 +6,7 @@ module Builtin
|
||||
# so it is responsible for initial setup (and relocation)
|
||||
def __init__ context
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
|
||||
# puts "INIT LAYOUT #{function.get_layout.get_layout}"
|
||||
function.info.return_type = Virtual::Integer
|
||||
main = Virtual::Machine.instance.space.get_main
|
||||
me = Virtual::Self.new(Virtual::Reference)
|
||||
|
@ -8,6 +8,7 @@ require "virtual/slots/slot"
|
||||
require "virtual/type"
|
||||
# the passes _are_ order dependant
|
||||
require "virtual/passes/minimizer"
|
||||
require "virtual/passes/collector"
|
||||
require "virtual/passes/send_implementation"
|
||||
require "virtual/passes/get_implementation"
|
||||
require "virtual/passes/enter_implementation"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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|
|
||||
|
@ -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
|
||||
|
33
lib/virtual/passes/collector.rb
Normal file
33
lib/virtual/passes/collector.rb
Normal 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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user