much work on boot process
fiddly egg and chicken, though a bit clearer with parfait objects now
This commit is contained in:
parent
174afb33fb
commit
94f49bf5c2
@ -22,6 +22,10 @@ module Parfait
|
|||||||
@object_layout = Layout.new_object(self)
|
@object_layout = Layout.new_object(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def object_layout
|
||||||
|
@object_layout
|
||||||
|
end
|
||||||
|
|
||||||
def allocate_object
|
def allocate_object
|
||||||
#space, and ruby allocate
|
#space, and ruby allocate
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ module Parfait
|
|||||||
#
|
#
|
||||||
# TODO , later we would need to COPY the layout to keep the old constant
|
# 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
|
# 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.push(name)
|
||||||
self.get_length
|
self.get_length
|
||||||
end
|
end
|
||||||
|
@ -25,6 +25,9 @@ module Parfait
|
|||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def instance_methods
|
||||||
|
@instance_methods
|
||||||
|
end
|
||||||
def add_instance_method method
|
def add_instance_method method
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? 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
|
raise "syserr #{method.name.class}" unless method.name.is_a? Word
|
||||||
|
@ -37,23 +37,20 @@ module Parfait
|
|||||||
# data that every object carries.
|
# data that every object carries.
|
||||||
def get_class()
|
def get_class()
|
||||||
l = get_layout()
|
l = get_layout()
|
||||||
puts "Layout #{l.class} in #{self.class}"
|
puts "Layout #{l.class} in #{self.class} , #{self}"
|
||||||
l.get_object_class()
|
l.get_object_class()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# private
|
||||||
|
def set_layout(layout)
|
||||||
|
internal_object_set(LAYOUT_INDEX , layout)
|
||||||
|
end
|
||||||
|
|
||||||
def get_layout()
|
def get_layout()
|
||||||
#puts "ME #{self.class}"
|
#puts "ME #{self.class}"
|
||||||
return internal_object_get(LAYOUT_INDEX)
|
return internal_object_get(LAYOUT_INDEX)
|
||||||
end
|
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
|
def get_instance_variables
|
||||||
get_layout().get_instance_variables
|
get_layout().get_instance_variables
|
||||||
end
|
end
|
||||||
|
@ -16,29 +16,42 @@ module Virtual
|
|||||||
# (not use the normal initialize way)
|
# (not use the normal initialize way)
|
||||||
def boot_parfait!
|
def boot_parfait!
|
||||||
@space = Parfait::Space.new_object
|
@space = Parfait::Space.new_object
|
||||||
boot_classes!
|
|
||||||
#space_layout =
|
|
||||||
# Parfait::Layout.new_object space_class
|
|
||||||
|
|
||||||
# puts "Space #{space.get_layout}"
|
values = [ "Value" , "Integer" , "Kernel" , "Object"].collect {|cl| Virtual.new_word(cl) }
|
||||||
end
|
value_classes = values.collect { |cl| @space.create_class(cl) }
|
||||||
|
rest = [ "Word", "Space", "Layout", "Module" ,
|
||||||
def boot_classes!
|
"Class" , "Dictionary", "List"]
|
||||||
values = [ "Integer" , "Object" , "Value" , "Kernel"]
|
rest_layouts = { Virtual.new_word("Word") => [] ,
|
||||||
rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"]
|
Virtual.new_word("Space") => ["classes","objects"],
|
||||||
(values + rest).each { |cl| @space.create_class(Virtual.new_word(cl)) }
|
Virtual.new_word("Layout") => ["object_class"] ,
|
||||||
value_class = @space.get_class_by_name Virtual.new_word("Value")
|
Virtual.new_word("Module") => ["name","instance_methods", "super_class", "meta_class"],
|
||||||
@space.get_class_by_name(Virtual.new_word("Integer")).set_super_class( value_class )
|
Virtual.new_word("Class") => ["object_layout"],
|
||||||
object_class = @space.get_class_by_name(Virtual.new_word("Object"))
|
Virtual.new_word("Dictionary") => ["keys" , "values"],
|
||||||
object_class.set_super_class( value_class )
|
Virtual.new_word("List") => [] }
|
||||||
rest.each do |name|
|
rest_classes = rest_layouts.collect { |cl , lay| @space.create_class(cl) }
|
||||||
cl = @space.get_class_by_name( Virtual.new_word( name ))
|
rest_classes[1].set_super_class( value_classes[0] ) # #set superclass for object
|
||||||
cl.set_super_class(object_class)
|
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
|
end
|
||||||
boot_layouts!
|
# next create layouts by adding instance variable names to the layouts
|
||||||
end
|
rest_classes.each do |cl|
|
||||||
def boot_layouts!
|
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
|
end
|
||||||
|
|
||||||
# boot the classes, ie create a minimal set of classes with a minimal set of functions
|
# boot the classes, ie create a minimal set of classes with a minimal set of functions
|
||||||
|
Loading…
Reference in New Issue
Block a user