From 94f49bf5c2b49d93fb2cba9a491a26e7a31d2b7e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 22 May 2015 22:51:36 +0300 Subject: [PATCH] much work on boot process fiddly egg and chicken, though a bit clearer with parfait objects now --- lib/parfait/class.rb | 4 ++++ lib/parfait/layout.rb | 2 +- lib/parfait/module.rb | 3 +++ lib/parfait/object.rb | 15 +++++------- lib/virtual/boot.rb | 55 ++++++++++++++++++++++++++----------------- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 61e54d56..3ad9ab32 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -22,6 +22,10 @@ module Parfait @object_layout = Layout.new_object(self) end + def object_layout + @object_layout + end + def allocate_object #space, and ruby allocate end diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index c7db071f..440a3953 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -34,7 +34,7 @@ module Parfait # # TODO , later we would need to COPY the layout to keep the old constant # but now we are concerned with booting, ie getting a working structure - def add_instance_name name + def add_instance_variable name self.push(name) self.get_length end diff --git a/lib/parfait/module.rb b/lib/parfait/module.rb index 279a55f7..cb5189e7 100644 --- a/lib/parfait/module.rb +++ b/lib/parfait/module.rb @@ -25,6 +25,9 @@ module Parfait @name end + def instance_methods + @instance_methods + end def add_instance_method method raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method raise "syserr #{method.name.class}" unless method.name.is_a? Word diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 582ae01e..9a43d23c 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -37,23 +37,20 @@ module Parfait # data that every object carries. def get_class() l = get_layout() - puts "Layout #{l.class} in #{self.class}" + puts "Layout #{l.class} in #{self.class} , #{self}" l.get_object_class() end + # private + def set_layout(layout) + internal_object_set(LAYOUT_INDEX , layout) + end + def get_layout() #puts "ME #{self.class}" return internal_object_get(LAYOUT_INDEX) end - # class stores the "latest" layout for instances, ie the layout a new object will - # be created with. - # inside parfait (and for now everywhere) these are constant. - @@EMPTY = { :names => [] , :types => []} - def self.class_layout() - @@EMPTY - end - def get_instance_variables get_layout().get_instance_variables end diff --git a/lib/virtual/boot.rb b/lib/virtual/boot.rb index c277efd4..4db658f9 100644 --- a/lib/virtual/boot.rb +++ b/lib/virtual/boot.rb @@ -16,29 +16,42 @@ module Virtual # (not use the normal initialize way) def boot_parfait! @space = Parfait::Space.new_object - boot_classes! - #space_layout = -# Parfait::Layout.new_object space_class -# puts "Space #{space.get_layout}" - end - - def boot_classes! - values = [ "Integer" , "Object" , "Value" , "Kernel"] - rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"] - (values + rest).each { |cl| @space.create_class(Virtual.new_word(cl)) } - value_class = @space.get_class_by_name Virtual.new_word("Value") - @space.get_class_by_name(Virtual.new_word("Integer")).set_super_class( value_class ) - object_class = @space.get_class_by_name(Virtual.new_word("Object")) - object_class.set_super_class( value_class ) - rest.each do |name| - cl = @space.get_class_by_name( Virtual.new_word( name )) - cl.set_super_class(object_class) + 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]) end - boot_layouts! - end - def boot_layouts! - + # next create layouts by adding instance variable names to the layouts + rest_classes.each do |cl| + name = cl.name + variables = rest_layouts[name] + variables.each do |var_name| + cl.object_layout.add_instance_variable Virtual.new_word(var_name) + end + end + # 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}" + end + # and go through the space instance variables which get created before the object list end # boot the classes, ie create a minimal set of classes with a minimal set of functions