rename layout to type
this one goes to caleb for pointing it out. Much better word
This commit is contained in:
@ -20,11 +20,11 @@ module Register
|
||||
# That graph can be programatically built and written (with this to boot that process :-))
|
||||
|
||||
# There are some helpers below, but the roadmap is something like:
|
||||
# - create all the layouts, with thier layouts, but no classes
|
||||
# - create all the types, with thier types, but no classes
|
||||
# - create a space by "hand" , using allocate, not new
|
||||
# - create the class objects and assign them to the layouts
|
||||
# - create the class objects and assign them to the types
|
||||
def boot_parfait!
|
||||
boot_layouts
|
||||
boot_types
|
||||
boot_space
|
||||
boot_classes
|
||||
|
||||
@ -34,43 +34,43 @@ module Register
|
||||
boot_functions!
|
||||
end
|
||||
|
||||
# layouts is where the snake bites its tail. Every chain end at a layout and then it
|
||||
# types is where the snake bites its tail. Every chain end at a type and then it
|
||||
# goes around (circular references). We create them from the list below and keep them
|
||||
# in an instance variable (that is a smell, because after booting it is not needed)
|
||||
def boot_layouts
|
||||
@layouts = {}
|
||||
layout_names.each do |name , ivars |
|
||||
@layouts[name] = layout_for( name , ivars)
|
||||
def boot_types
|
||||
@types = {}
|
||||
type_names.each do |name , ivars |
|
||||
@types[name] = type_for( name , ivars)
|
||||
end
|
||||
layout_layout = @layouts[:Layout]
|
||||
@layouts.each do |name , layout |
|
||||
layout.set_layout(layout_layout)
|
||||
type_type = @types[:Type]
|
||||
@types.each do |name , type |
|
||||
type.set_type(type_type)
|
||||
end
|
||||
end
|
||||
|
||||
# once we have the layouts we can create the space by creating the instance variables
|
||||
# once we have the types we can create the space by creating the instance variables
|
||||
# by hand (can't call new yet as that uses the space)
|
||||
def boot_space
|
||||
space_dict = object_with_layout Parfait::Dictionary
|
||||
space_dict.keys = object_with_layout Parfait::List
|
||||
space_dict.values = object_with_layout Parfait::List
|
||||
space_dict = object_with_type Parfait::Dictionary
|
||||
space_dict.keys = object_with_type Parfait::List
|
||||
space_dict.values = object_with_type Parfait::List
|
||||
|
||||
@space = object_with_layout Parfait::Space
|
||||
@space = object_with_type Parfait::Space
|
||||
@space.classes = space_dict
|
||||
Parfait::Space.set_object_space @space
|
||||
end
|
||||
|
||||
# when running code instantiates a class, a layout is created automatically
|
||||
# but even to get our space up, we have already instantiated all layouts
|
||||
# when running code instantiates a class, a type is created automatically
|
||||
# but even to get our space up, we have already instantiated all types
|
||||
# so we have to continue and allocate classes and fill the data by hand
|
||||
# and off cource we can't use space.create_class , but still they need to go there
|
||||
def boot_classes
|
||||
classes = space.classes
|
||||
layout_names.each do |name , vars|
|
||||
cl = object_with_layout Parfait::Class
|
||||
cl.object_layout = @layouts[name]
|
||||
@layouts[name].object_class = cl
|
||||
cl.instance_methods = object_with_layout Parfait::List
|
||||
type_names.each do |name , vars|
|
||||
cl = object_with_type Parfait::Class
|
||||
cl.object_type = @types[name]
|
||||
@types[name].object_class = cl
|
||||
cl.instance_methods = object_with_type Parfait::List
|
||||
# puts "instance_methods is #{cl.instance_methods.class}"
|
||||
cl.name = name
|
||||
classes[name] = cl
|
||||
@ -78,7 +78,7 @@ module Register
|
||||
# superclasses other than default object
|
||||
supers = { :Object => :Kernel , :Kernel => :Value,
|
||||
:Integer => :Value , :BinaryCode => :Word }
|
||||
layout_names.each do |classname , ivar|
|
||||
type_names.each do |classname , ivar|
|
||||
next if classname == :Value # has no superclass
|
||||
clazz = classes[classname]
|
||||
super_name = supers[classname] || :Object
|
||||
@ -86,28 +86,28 @@ module Register
|
||||
end
|
||||
end
|
||||
|
||||
# helper to create a Layout, name is the parfait name, ie :Layout
|
||||
def layout_for( name , ivars )
|
||||
l = Parfait::Layout.allocate.fake_init
|
||||
l.add_instance_variable :layout , :Layout
|
||||
# helper to create a Layout, name is the parfait name, ie :Type
|
||||
def type_for( name , ivars )
|
||||
l = Parfait::Type.allocate.fake_init
|
||||
l.add_instance_variable :type , :Type
|
||||
ivars.each {|n,t| l.add_instance_variable( n , t) }
|
||||
l
|
||||
end
|
||||
|
||||
# create an object with layout (ie allocate it and assign layout)
|
||||
# meaning the lauouts have to be booted, @layouts filled
|
||||
# create an object with type (ie allocate it and assign type)
|
||||
# meaning the lauouts have to be booted, @types filled
|
||||
# here we pass the actual (ruby) class
|
||||
def object_with_layout(cl)
|
||||
def object_with_type(cl)
|
||||
o = cl.allocate.fake_init
|
||||
name = cl.name.split("::").last.to_sym
|
||||
o.set_layout @layouts[name]
|
||||
o.set_type @types[name]
|
||||
o
|
||||
end
|
||||
|
||||
# the function really just returns a constant (just avoiding the constant)
|
||||
# unfortuantely that constant condenses every detail about the system, class names
|
||||
# and all instance variable names. Really have to find a better way
|
||||
def layout_names
|
||||
def type_names
|
||||
{ :Word => {:char_length => :Integer} ,
|
||||
:List => {:indexed_length => :Integer} ,
|
||||
:Message => { :next_message => :Message, :receiver => :Object, :frame => :Frame ,
|
||||
@ -120,8 +120,8 @@ module Register
|
||||
:BinaryCode => {:char_length => :Integer} ,
|
||||
:Space => {:classes => :Dictionary , :first_message => :Message},
|
||||
:Frame => {:next_frame => :Frame, :indexed_length => :Integer},
|
||||
:Layout => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} ,
|
||||
:Class => {:instance_methods => :List, :object_layout => :Layout, :name => :Word,
|
||||
:Type => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} ,
|
||||
:Class => {:instance_methods => :List, :object_type => :Type, :name => :Word,
|
||||
:super_class_name => :Word},
|
||||
:Dictionary => {:keys => :List , :values => :List } ,
|
||||
:Method => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object,
|
||||
|
Reference in New Issue
Block a user