still fixing index bugs

the indexed_length got written wrong
which is why the layout methods didn’t work
Now all indexes are 1 based, even fake men, where we just ignore 0
This commit is contained in:
Torsten Ruger
2015-10-26 14:33:36 +02:00
parent 9f4952b5ac
commit 885aa765d6
10 changed files with 36 additions and 23 deletions

View File

@ -12,6 +12,11 @@ module Parfait
base.attribute :instance_methods
end
def initialize
super()
self.instance_methods = List.new
end
def method_names
names = List.new
self.instance_methods.each do |method|

View File

@ -22,10 +22,10 @@ module Parfait
def initialize name , superclass
super()
self.name = name
self.instance_methods = List.new
self.super_class_name = superclass
# the layout 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)
end
@ -34,10 +34,9 @@ module Parfait
end
def meta
m = self.meta_class
return m if m
self.meta_class = MetaClass.new(self)
get_layout
end
def add_instance_name name
self.object_layout.push name
end

View File

@ -147,7 +147,7 @@ module Parfait
end
define_method :get_length do
r = internal_object_get( offset + 1) #one for layout
r = internal_object_get( offset ) #one for layout
r.nil? ? 0 : r
end
@ -158,7 +158,7 @@ module Parfait
if index > self.get_length
grow_to(index)
end
# internally 1 is reserved for the layout
# start one higher than offset, which is where the length is
internal_object_set( index + 1 + offset, value)
end
@ -169,6 +169,7 @@ module Parfait
if index > self.get_length
return nil
else
# start one higher than offset, which is where the length is
return internal_object_get(index + offset + 1)
end
end
@ -179,14 +180,14 @@ 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
internal_object_set( offset + 1 , len) #one for layout
internal_object_set( offset , len) #one for layout
end
define_method :shrink_to do | len|
raise "Only positive lenths, #{len}" if len < 0
old_length = self.get_length
return if old_length <= len
internal_object_set( offset + 1 , len) #one for layout
internal_object_set( offset , len)
end
end

View File

@ -14,18 +14,22 @@
# 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"
# 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)
# In other words, the Layout is a list of names that describe
# the values stored in an actual object.
# The object is an List of values of length n and
# the Layout is an List of names of length n
# the Layout is an List of names of length n , plus class reference and methods reference
# Together they turn the object into a hash like structure
module Parfait
class Layout < Object
attribute :object_class
include Behaviour
include Indexed
self.offset(1)
self.offset(3)
def initialize( object_class )
super()

View File

@ -15,7 +15,7 @@ require_relative "indexed"
module Parfait
class List < Object
include Indexed
self.offset(0)
self.offset(1)
def initialize( )
super()

View File

@ -11,10 +11,9 @@
# The Layout is **always** the first entry (index 1) in an object, but the type word is index 0
module Parfait
class Object < Value
LAYOUT_INDEX = 1
LAYOUT_INDEX = 0
CLASS_INDEX = 1 #only used in class, but keep constants together
class Object < Value
def self.new *args
object = self.allocate