This commit is contained in:
Torsten Ruger 2015-07-30 19:18:41 +03:00
parent 7216300452
commit 8ab9a417aa
7 changed files with 18 additions and 16 deletions

View File

@ -26,5 +26,7 @@
module Parfait module Parfait
class Frame < Object class Frame < Object
attribute :next_frame
end end
end end

View File

@ -56,7 +56,7 @@ module Parfait
raise "uups #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol) raise "uups #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
clazz = object_layout().object_class() clazz = object_layout().object_class()
raise "??? #{method_name}" unless clazz raise "??? #{method_name}" unless clazz
puts "Self: #{self.class} clazz: #{clazz.name}" #puts "Self: #{self.class} clazz: #{clazz.name}"
Method.new( clazz , method_name , arg_names ) Method.new( clazz , method_name , arg_names )
end end

View File

@ -46,6 +46,7 @@ module Virtual
# returns if this is a block that ends in a call (and thus needs local variable handling) # returns if this is a block that ends in a call (and thus needs local variable handling)
def call_block? def call_block?
raise "called"
return false unless codes.last.is_a?(CallInstruction) return false unless codes.last.is_a?(CallInstruction)
return false unless codes.last.opcode == :call return false unless codes.last.opcode == :call
codes.dup.reverse.find{ |c| c.is_a? StackInstruction } codes.dup.reverse.find{ |c| c.is_a? StackInstruction }

View File

@ -7,7 +7,7 @@ module Virtual
def self.compile_class expression , method def self.compile_class expression , method
clazz = Parfait::Space.object_space.get_class_by_name! expression.name clazz = Parfait::Space.object_space.get_class_by_name! expression.name
puts "Compiling class #{clazz.name.inspect}" #puts "Compiling class #{clazz.name.inspect}"
expression_value = nil expression_value = nil
expression.expressions.each do |expr| expression.expressions.each do |expr|
# check if it's a function definition and add # check if it's a function definition and add

View File

@ -4,30 +4,31 @@ module Virtual
class Collector class Collector
def run def run
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__" # init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
keep Parfait::Space.object_space Virtual.machine.objects.clear
keep Parfait::Space.object_space , 0
end end
def keep object def keep object , depth
return if object.nil? return if object.nil?
#puts "adding #{' ' * depth}:#{object.class}"
#puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array
return unless Virtual.machine.add_object object return unless Virtual.machine.add_object object
#puts "adding #{object.class}"
return unless object.respond_to? :has_layout? return unless object.respond_to? :has_layout?
if( object.is_a? Parfait::Method) if( object.is_a? Parfait::Method)
object.source.constants.each{|c| object.source.constants.each{|c|
puts "keeping constant #{c.class}" #puts "keeping constant #{c.class}:#{c.object_id}"
keep(c) keep(c , depth + 1)
} }
end end
layout = object.get_layout layout = object.get_layout
keep layout keep(layout , depth + 1)
#puts "Layout #{layout.object_class.name} #{Machine.instance.objects.has_key?(layout.object_id)}"
layout.object_instance_names.each do |name| layout.object_instance_names.each do |name|
inst = object.get_instance_variable name inst = object.get_instance_variable name
keep inst keep(inst , depth + 1)
end end
if object.is_a? Parfait::List if object.is_a? Parfait::List
object.each do |item| object.each do |item|
keep item keep(item , depth + 1)
end end
end end
end end

View File

@ -11,8 +11,7 @@ module Virtual
@gonners << f @gonners << f
end end
end end
init = Parfait::Space.object_space.get_class_by_name(:Kernel).get_instance_method :__init__ remove Virtual.machine.space.get_init
remove init
dump_remaining dump_remaining
end end

View File

@ -3,8 +3,7 @@ require_relative "../helper"
class TestSpace < MiniTest::Test class TestSpace < MiniTest::Test
def setup def setup
@machine = Virtual.machine @machine = Virtual.machine.boot
@machine.boot
end end
def classes def classes
[:Kernel,:Word,:List,:Message,:Frame,:Layout,:Class,:Dictionary,:Method] [:Kernel,:Word,:List,:Message,:Frame,:Layout,:Class,:Dictionary,:Method]
@ -46,7 +45,7 @@ class TestSpace < MiniTest::Test
classes.each do |name| classes.each do |name|
cl = @machine.space.classes[name] cl = @machine.space.classes[name]
cl.method_names.each do |mname| cl.method_names.each do |mname|
puts "Mehtod #{mname}" #puts "Mehtod #{mname}"
method = cl.get_instance_method(mname) method = cl.get_instance_method(mname)
assert_equal mname , method.name assert_equal mname , method.name
assert_equal name , method.for_class.name assert_equal name , method.for_class.name