rename layout to type
this one goes to caleb for pointing it out. Much better word
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# Class is mainly a list of methods with a name (for now)
|
||||
# The memory layout of object is seperated into Layout
|
||||
# The memory type of object is seperated into Layout
|
||||
|
||||
# A class describes the capabilities of a group of objects, ie what data it has
|
||||
# and functions it responds to.
|
||||
@ -17,16 +17,16 @@
|
||||
module Parfait
|
||||
class Class < Object
|
||||
include Behaviour
|
||||
attributes [:object_layout , :name , :super_class_name]
|
||||
attributes [:object_type , :name , :super_class_name]
|
||||
|
||||
def initialize name , superclass
|
||||
super()
|
||||
self.name = name
|
||||
self.super_class_name = superclass
|
||||
# the layout for this class (class = object of type Class) carries the class
|
||||
# the type for this class (class = object of type Class) carries the class
|
||||
# as an instance. The relation is from an object through the Layout to it's class
|
||||
# TODO the object layout should copy the stuff from superclass
|
||||
self.object_layout = Layout.new(self)
|
||||
# TODO the object type should copy the stuff from superclass
|
||||
self.object_type = Type.new(self)
|
||||
end
|
||||
|
||||
def allocate_object
|
||||
@ -34,7 +34,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def add_instance_name name
|
||||
self.object_layout.push name
|
||||
self.object_type.push name
|
||||
end
|
||||
|
||||
def sof_reference_name
|
||||
@ -48,7 +48,7 @@ module Parfait
|
||||
|
||||
def create_instance_method method_name , arguments
|
||||
raise "create_instance_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
|
||||
clazz = object_layout().object_class()
|
||||
clazz = object_type().object_class()
|
||||
raise "??? #{method_name}" unless clazz
|
||||
#puts "Self: #{self.class} clazz: #{clazz.name}"
|
||||
add_instance_method Method.new( clazz , method_name , arguments )
|
||||
|
@ -12,7 +12,7 @@
|
||||
# to the next message.
|
||||
# The better way to say above is that a message is *used* by the caller, and a frame by the callee.
|
||||
|
||||
# Also at runtime Messages and Frames remain completely "normal" objects. Ie have layouts and so on.
|
||||
# Also at runtime Messages and Frames remain completely "normal" objects. Ie have types and so on.
|
||||
# Which resolves the dichotomy of objects on the stack or heap. Sama sama.
|
||||
|
||||
module Parfait
|
||||
@ -20,7 +20,7 @@ module Parfait
|
||||
attribute :next_frame
|
||||
|
||||
include Indexed
|
||||
self.offset(2) # 1 == the next_frame attributes above + layout. (indexed_length gets added)
|
||||
self.offset(2) # 1 == the next_frame attributes above + type. (indexed_length gets added)
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
# various classes would derive from array in ruby, ie have indexed variables
|
||||
#
|
||||
# But for our memory layout we need the variable part of an object to be after
|
||||
# But for our memory type we need the variable part of an object to be after
|
||||
# the fixed, ie the instance variables
|
||||
#
|
||||
# Just using ruby derivation will not allow us to offset the index, so instead the
|
||||
@ -95,12 +95,12 @@ module Parfait
|
||||
end
|
||||
|
||||
# word length (padded) is the amount of space taken by the object
|
||||
# For your basic object this means the number of instance variables as determined by layout
|
||||
# For your basic object this means the number of instance variables as determined by type
|
||||
# This is off course 0 for a list, unless someone squeezed an instance variable in
|
||||
# but additionally, the amount of data comes on top.
|
||||
# unfortuntely we can't just use super because of the Padding
|
||||
def padded_length
|
||||
padded_words( get_layout().instance_length + get_length() )
|
||||
padded_words( get_type().instance_length + get_length() )
|
||||
end
|
||||
|
||||
def each
|
||||
@ -154,7 +154,7 @@ module Parfait
|
||||
end
|
||||
|
||||
define_method :get_length do
|
||||
r = get_internal_word( offset ) #one for layout
|
||||
r = get_internal_word( offset ) #one for type
|
||||
r.nil? ? 0 : r
|
||||
end
|
||||
|
||||
@ -187,7 +187,7 @@ module Parfait
|
||||
return if old_length >= len
|
||||
# raise "bounds error at #{len}" if( len + offset > 16 )
|
||||
# be nice to use the indexed_length , but that relies on booted space
|
||||
set_internal_word( offset , len) #one for layout
|
||||
set_internal_word( offset , len) #one for type
|
||||
end
|
||||
|
||||
define_method :shrink_to do | len|
|
||||
|
@ -13,7 +13,7 @@ module Parfait
|
||||
attributes [:return_value, :caller , :name ]
|
||||
|
||||
include Indexed
|
||||
self.offset(8) # 8 == the seven attributes above + layout. (indexed_length gets added)
|
||||
self.offset(8) # 8 == the seven attributes above + type. (indexed_length gets added)
|
||||
|
||||
def initialize next_m
|
||||
self.next_message = next_m
|
||||
@ -28,7 +28,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def get_type_for(name)
|
||||
index = @layout.get_index(name)
|
||||
index = @type.get_index(name)
|
||||
get_at(index)
|
||||
end
|
||||
end
|
||||
|
@ -8,11 +8,11 @@ module Parfait
|
||||
# .... the class object but gives us the ability to use the
|
||||
# syntax as if it were a class
|
||||
|
||||
# While the "real" metaclass is the layout, we need to honor the constancy of the layout
|
||||
# So the layout needs to be copied and replaced anytime it is edited.
|
||||
# While the "real" metaclass is the type, we need to honor the constancy of the type
|
||||
# So the type needs to be copied and replaced anytime it is edited.
|
||||
# And then changed in the original object, and thus we need this level of indirection
|
||||
|
||||
# Basically we implement the Behaviour protocol, by forwarding to the layout
|
||||
# Basically we implement the Behaviour protocol, by forwarding to the type
|
||||
|
||||
class MetaClass < Object
|
||||
include Logging
|
||||
@ -25,35 +25,35 @@ module Parfait
|
||||
end
|
||||
|
||||
def name
|
||||
self.object.get_layout.name
|
||||
self.object.get_type.name
|
||||
end
|
||||
# first part of the protocol is read, just forward to self.object.layout
|
||||
# first part of the protocol is read, just forward to self.object.type
|
||||
def methods
|
||||
self.object.get_layout.methods
|
||||
self.object.get_type.methods
|
||||
end
|
||||
def method_names
|
||||
self.object.get_layout.method_names
|
||||
self.object.get_type.method_names
|
||||
end
|
||||
def get_instance_method fname
|
||||
self.object.get_layout.get_instance_method fname
|
||||
self.object.get_type.get_instance_method fname
|
||||
end
|
||||
def resolve_method m_name
|
||||
self.object.get_layout.resolve_method m_name
|
||||
self.object.get_type.resolve_method m_name
|
||||
end
|
||||
|
||||
# the modifying part creates a new layout
|
||||
# forwards the action and replaces the layout
|
||||
# the modifying part creates a new type
|
||||
# forwards the action and replaces the type
|
||||
def add_instance_method method
|
||||
layout = self.object.get_layout.dup
|
||||
ret = layout.add_instance_method(method)
|
||||
self.object.set_layout layout
|
||||
type = self.object.get_type.dup
|
||||
ret = type.add_instance_method(method)
|
||||
self.object.set_type type
|
||||
ret
|
||||
end
|
||||
|
||||
def remove_instance_method method_name
|
||||
layout = self.object.get_layout.dup
|
||||
ret = layout.remove_instance_method(method_name)
|
||||
self.object.set_layout layout
|
||||
type = self.object.get_type.dup
|
||||
ret = type.remove_instance_method(method_name)
|
||||
self.object.set_type type
|
||||
ret
|
||||
end
|
||||
|
||||
|
@ -21,8 +21,8 @@ module Parfait
|
||||
object.fake_init if object.respond_to?(:fake_init) # at compile, not run-time
|
||||
# have to grab the class, because we are in the ruby class not the parfait one
|
||||
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym)
|
||||
# and have to set the layout before we let the object do anything. otherwise boom
|
||||
object.set_layout cl.object_layout
|
||||
# and have to set the type before we let the object do anything. otherwise boom
|
||||
object.set_type cl.object_type
|
||||
|
||||
object.send :initialize , *args
|
||||
object
|
||||
@ -71,27 +71,27 @@ module Parfait
|
||||
# In Salama we store the class in the Layout, and so the Layout is the only fixed
|
||||
# data that every object carries.
|
||||
def get_class()
|
||||
l = get_layout()
|
||||
#puts "Layout #{l.class} in #{self.class} , #{self}"
|
||||
l = get_type()
|
||||
#puts "Type #{l.class} in #{self.class} , #{self}"
|
||||
l.object_class()
|
||||
end
|
||||
|
||||
# private
|
||||
def set_layout(layout)
|
||||
# puts "Layout was set for #{self.class}"
|
||||
raise "Nil layout" unless layout
|
||||
set_internal_word(LAYOUT_INDEX , layout)
|
||||
def set_type(type)
|
||||
# puts "Type was set for #{self.class}"
|
||||
raise "Nil type" unless type
|
||||
set_internal_word(LAYOUT_INDEX , type)
|
||||
end
|
||||
|
||||
# so we can keep the raise in get_layout
|
||||
def has_layout?
|
||||
# so we can keep the raise in get_type
|
||||
def has_type?
|
||||
! get_internal_word(LAYOUT_INDEX).nil?
|
||||
end
|
||||
|
||||
def get_layout()
|
||||
def get_type()
|
||||
l = get_internal_word(LAYOUT_INDEX)
|
||||
#puts "get layout for #{self.class} returns #{l.class}"
|
||||
raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
|
||||
#puts "get type for #{self.class} returns #{l.class}"
|
||||
raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless l
|
||||
return l
|
||||
end
|
||||
|
||||
@ -101,7 +101,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def get_instance_variables
|
||||
get_layout().instance_names
|
||||
get_type().instance_names
|
||||
end
|
||||
|
||||
def get_instance_variable name
|
||||
@ -118,11 +118,11 @@ module Parfait
|
||||
end
|
||||
|
||||
def instance_variable_defined name
|
||||
get_layout().variable_index(name)
|
||||
get_type().variable_index(name)
|
||||
end
|
||||
|
||||
def padded_length
|
||||
padded_words( get_layout().instance_length )
|
||||
padded_words( get_type().instance_length )
|
||||
end
|
||||
|
||||
# parfait versions are deliberately called different, so we "relay"
|
||||
|
@ -64,7 +64,7 @@ module Parfait
|
||||
raise "get_class_by_name #{name}.#{name.class}" unless name.is_a?(Symbol)
|
||||
c = self.classes[name]
|
||||
#puts "MISS, no class #{name} #{name.class}" unless c # " #{self.classes}"
|
||||
#puts "CLAZZ, #{name} #{c.get_layout.get_length}" if c
|
||||
#puts "CLAZZ, #{name} #{c.get_type.get_length}" if c
|
||||
c
|
||||
end
|
||||
|
||||
|
@ -3,11 +3,11 @@ class Symbol
|
||||
include Positioned
|
||||
include Padding
|
||||
|
||||
def has_layout?
|
||||
def has_type?
|
||||
true
|
||||
end
|
||||
def get_layout
|
||||
l = Register.machine.space.classes[:Word].object_layout
|
||||
def get_type
|
||||
l = Register.machine.space.classes[:Word].object_type
|
||||
#puts "LL #{l.class}"
|
||||
l
|
||||
end
|
||||
|
@ -5,17 +5,17 @@
|
||||
# Instead we store only the values, and access them by index.
|
||||
# The Layout allows the mapping of names to index.
|
||||
|
||||
# The Layout of an object describes the memory layout of the object
|
||||
# The Layout of an object describes the memory type of the object
|
||||
# The Layout is a simple list of the names of instance variables.
|
||||
#
|
||||
# As every object has a Layout to describe it, the name "layout" is the
|
||||
# As every object has a Layout to describe it, the name "type" is the
|
||||
# first name in the list for every Layout.
|
||||
|
||||
# But as we want every Object to have a class, the Layout carries that class.
|
||||
# So the layout of layout has an entry "object_class"
|
||||
# So the type of type has an entry "object_class"
|
||||
|
||||
# But Objects must also be able to carry methods themselves (ruby calls singleton_methods)
|
||||
# and those too are stored in the Layout (both layout and class include behaviour)
|
||||
# and those too are stored in the Layout (both type and class include behaviour)
|
||||
|
||||
# In other words, the Layout is a list of names that describe
|
||||
# the values stored in an actual object.
|
||||
@ -24,7 +24,7 @@
|
||||
# Together they turn the object into a hash like structure
|
||||
|
||||
module Parfait
|
||||
class Layout < Object
|
||||
class Type < Object
|
||||
attribute :object_class
|
||||
include Behaviour
|
||||
|
||||
@ -33,7 +33,7 @@ module Parfait
|
||||
|
||||
def initialize( object_class )
|
||||
super()
|
||||
add_instance_variable :layout ,:Layout
|
||||
add_instance_variable :type ,:Type
|
||||
self.object_class = object_class
|
||||
end
|
||||
|
||||
@ -45,7 +45,7 @@ module Parfait
|
||||
# The index will be returned and can subsequently be searched with index_of
|
||||
# The index of the name is the index of the data in the object
|
||||
#
|
||||
# TODO , later we would need to COPY the layout to keep the old constant
|
||||
# TODO , later we would need to COPY the type to keep the old constant
|
||||
# but now we are concerned with booting, ie getting a working structure
|
||||
def add_instance_variable name , type
|
||||
raise "Name shouldn't be nil" unless name
|
||||
@ -75,7 +75,7 @@ module Parfait
|
||||
end
|
||||
|
||||
# index of the variable when using get_internal_word
|
||||
# (get_internal_word is 1 based and 1 is always the layout)
|
||||
# (get_internal_word is 1 based and 1 is always the type)
|
||||
def variable_index name
|
||||
has = super_index(name)
|
||||
return nil unless has
|
||||
@ -89,11 +89,11 @@ module Parfait
|
||||
end
|
||||
|
||||
def inspect
|
||||
"Layout[#{super}]"
|
||||
"Type[#{super}]"
|
||||
end
|
||||
|
||||
def sof_reference_name
|
||||
"#{self.object_class.name}_Layout"
|
||||
"#{self.object_class.name}_Type"
|
||||
end
|
||||
alias :name :sof_reference_name
|
||||
|
@ -10,14 +10,14 @@ module Parfait
|
||||
|
||||
# Words are objects, that means they carry Layout as index 0
|
||||
# So all indexes are offset by one in the implementation
|
||||
# Object length is measured in non-layout cells though
|
||||
# Object length is measured in non-type cells though
|
||||
|
||||
class Word < Object
|
||||
attribute :char_length
|
||||
|
||||
#semi "indexed" methods for interpreter
|
||||
def self.get_length_index
|
||||
2 # 2 is the amount of attributes, layout and char_length. the offset after which chars start
|
||||
2 # 2 is the amount of attributes, type and char_length. the offset after which chars start
|
||||
end
|
||||
def self.get_indexed i
|
||||
i + get_length_index * 4
|
||||
@ -31,7 +31,7 @@ module Parfait
|
||||
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
|
||||
raise "Must init with positive, not #{len}" if len < 0
|
||||
set_length( len , 32 ) unless len == 0 #32 beeing ascii space
|
||||
#puts "layout #{self.get_layout} #{self.object_id.to_s(16)}"
|
||||
#puts "type #{self.get_type} #{self.object_id.to_s(16)}"
|
||||
end
|
||||
|
||||
# return a copy of self
|
||||
@ -182,7 +182,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def padded_length
|
||||
padded( 4 * get_layout().instance_length + self.char_length )
|
||||
padded( 4 * get_type().instance_length + self.char_length )
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user