diff --git a/lib/virtual/boot.rb b/lib/virtual/boot.rb index 4db658f9..0ee2905a 100644 --- a/lib/virtual/boot.rb +++ b/lib/virtual/boot.rb @@ -19,37 +19,41 @@ module Virtual values = [ "Value" , "Integer" , "Kernel" , "Object"].collect {|cl| Virtual.new_word(cl) } value_classes = values.collect { |cl| @space.create_class(cl) } - rest = [ "Word", "Space", "Layout", "Module" , - "Class" , "Dictionary", "List"] - rest_layouts = { Virtual.new_word("Word") => [] , - Virtual.new_word("Space") => ["classes","objects"], - Virtual.new_word("Layout") => ["object_class"] , - Virtual.new_word("Module") => ["name","instance_methods", "super_class", "meta_class"], - Virtual.new_word("Class") => ["object_layout"], - Virtual.new_word("Dictionary") => ["keys" , "values"], - Virtual.new_word("List") => [] } - rest_classes = rest_layouts.collect { |cl , lay| @space.create_class(cl) } - rest_classes[1].set_super_class( value_classes[0] ) # #set superclass for object - rest_classes[3].set_super_class( value_classes[0] ) # and integer - rest_classes.each do |cl| # and the rest - cl.set_super_class(value_classes[3]) + layouts = { "Word" => [] , + "Space" => ["classes","objects"], + "Layout" => ["object_class"] , + "Method" => ["name" , "arg_names" , "locals" , "tmps"] , + "Module" => ["name","instance_methods", "super_class", "meta_class"], + "Class" => ["object_layout"], + "Dictionary" => ["keys" , "values"], + "List" => [] } + # map from the vm - class_name to the Parfait class (which carries parfait name) + class_mappings = {} + layouts.each do |name , layout| + class_mappings[name] = @space.create_class(Virtual.new_word(name)) + end + value_classes[1].set_super_class( value_classes[0] ) # #set superclass (value) for object + value_classes[3].set_super_class( value_classes[0] ) # and integer + class_mappings.each do |name , clazz| # and the rest + clazz.set_super_class(value_classes[3]) # superclasses are object end # next create layouts by adding instance variable names to the layouts - rest_classes.each do |cl| - name = cl.name - variables = rest_layouts[name] + class_mappings.each do |name , clazz| + variables = layouts[name] variables.each do |var_name| - cl.object_layout.add_instance_variable Virtual.new_word(var_name) + clazz.object_layout.add_instance_variable Virtual.new_word(var_name) end end + # now store the classes so we can hand them out later during object creation + # this can not be done earlier, as parfait objects are all the time created and would + # lookup half created class info + # but it must be done before going through the objects (next step) + @class_mappings = class_mappings + # now update the layout on all objects created so far, # go through objects in space @space.objects.each do | o | - vm_name = o.class.name.split("::").last - index = rest.index(vm_name) - raise "Class not found #{o.class}" unless index - o.set_layout rest_classes[index].object_layout - puts "index #{index}" + o.init_layout end # and go through the space instance variables which get created before the object list end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 7d4e7af0..56d69db5 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -38,7 +38,7 @@ module Virtual @passes = [ "Virtual::SendImplementation" ] # @message = Message.new(the_end , the_end , "Object" ) end - attr_reader :message , :passes , :space , :init , :main + attr_reader :message , :passes , :space , :init , :main , :class_mappings def run_passes #TODO puts "INIT #{@init}" diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index 6ea96d26..54e49cbd 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -6,23 +6,20 @@ module FakeMem def initialize - if( self.class.name == "Parfait::Space") - puts "YES , I am SPACE" - end @memory = [0,nil] if Parfait::Space.object_space and Parfait::Space.object_space.objects Parfait::Space.object_space.add_object self - puts "got it #{self.class.name}" else - puts "it escaped #{self.class.name}" + #TODO, must go through spce instance variables "by hand" + puts "fixme, no layout for #{self.class.name}" end + init_layout if Virtual::Machine.instance.class_mappings end def init_layout - class_name = self.class.name - puts "CLASS #{class_name}" - puts "Check for #{class_name}" - cl = Parfait::Space.space.get_class(class_name) - puts "found #{cl}" if cl + vm_name = self.class.name.split("::").last + clazz = Virtual::Machine.instance.class_mappings[vm_name] + raise "Class not found #{vm_name}" unless clazz + self.set_layout clazz.object_layout end end diff --git a/lib/virtual/passes/send_implementation.rb b/lib/virtual/passes/send_implementation.rb index 658e0cbb..d9d4d5b6 100644 --- a/lib/virtual/passes/send_implementation.rb +++ b/lib/virtual/passes/send_implementation.rb @@ -23,7 +23,7 @@ module Virtual # get the function from my class. easy peasy puts "Me is #{me.class}" method = me.get_class.get_instance_method(code.name) - raise "Method not implemented #{clazz.name}.#{code.name}" unless method + raise "Method not implemented #{me.class}.#{code.name}" unless method new_codes << MethodCall.new( method ) else # note: this is the current view: call internal send, even the method name says else