fixing indexed stuff

layout returns layout as first name (offsets indexes)
object internal length is gone  into layouts functionality
This commit is contained in:
Torsten Ruger 2015-10-26 12:22:32 +02:00
parent bb3d211c04
commit 979ebb7612
8 changed files with 28 additions and 36 deletions

View File

@ -69,7 +69,6 @@ module Parfait
found = get_instance_method( method.name )
if found
self.instance_methods.delete(found)
#raise "existed in #{self.name} #{Sof.write found.source.blocks}"
end
self.instance_methods.push method
#puts "#{self.name} add #{method.name}"

View File

@ -26,6 +26,7 @@ module Parfait
# return nil if no such item
def index_of item
max = self.get_length
#puts "length #{max} #{max.class}"
counter = 1
while( counter <= max )
if( get(counter) == item)
@ -103,7 +104,7 @@ module Parfait
def each
# not sure how to do this with define_method, because of the double block issue.
# probably some clever way around that, but not important
index = 1 + get_offset
index = 1
while index <= self.get_length
item = get(index)
yield item
@ -175,7 +176,7 @@ module Parfait
raise "Only positive lenths, #{len}" if len < 0
old_length = self.get_length
return if old_length >= len
raise "bounds error at #{len}" if( len + offset > 16 )
# 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
end

View File

@ -22,11 +22,11 @@
module Parfait
class Layout < Object
include Indexed
self.offset(0)
attribute :object_class
include Indexed
self.offset(2)
def initialize( object_class )
super()
self.object_class = object_class
@ -43,24 +43,20 @@ 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_variable name
self.push(1) if self.get_length == 0
self.push(name)
self.get_length
end
def object_instance_names
names = List.new
index = 3
while index <= self.get_length
item = get(index)
each do |item|
names.push item
index = index + 1
end
names
end
def object_instance_length
self.get_length - 2
self.get_length
end
alias :list_index :index_of
@ -74,8 +70,8 @@ module Parfait
def variable_index name
has = list_index(name)
return nil unless has
raise "internal error #{name}:#{has}" if has < 2
has - 1
raise "internal error #{name}:#{has}" if has < 1
has
end
def inspect

View File

@ -74,7 +74,7 @@ HERE
was = check
get = was.next(6)
assert_equal GetSlot , get.class
assert_equal 3, get.index , "Get to frame index must be offset, not #{get.index}"
assert_equal 4, get.index , "Get to frame index must be offset, not #{get.index}"
end
def test_assign_arg
@ -90,7 +90,7 @@ HERE
was = check
set = was.next(3)
assert_equal SetSlot , set.class
assert_equal 9, set.index , "Set to args index must be offset, not #{set.index}"
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_assign_int
@ -105,7 +105,7 @@ HERE
was = check
set = was.next(4)
assert_equal SetSlot , set.class
assert_equal 3, set.index , "Set to frame index must be offset, not #{set.index}"
assert_equal 4, set.index , "Set to frame index must be offset, not #{set.index}"
end
def test_arg_get
@ -122,7 +122,7 @@ HERE
was = check
get = was.next(2)
assert_equal GetSlot , get.class
assert_equal 9, get.index , "Get to frame index must be offset, not #{get.index}"
assert_equal 10, get.index , "Get to frame index must be offset, not #{get.index}"
end
end
end

View File

@ -100,7 +100,7 @@ HERE
was = check
set = was.next(8)
assert_equal SetSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
assert_equal 10, set.index , "Set to message must be offset, not #{set.index}"
end
end
end

View File

@ -12,7 +12,7 @@ class TestAttributes < MiniTest::Test
end
def test_message_layout_first
@layout.object_class = :next_message
assert_equal :next_message , @layout.object_instance_names.first
assert_equal :layout , @layout.object_instance_names.first
assert_equal :next_message , @layout.object_class
end
def test_message_name_nil

View File

@ -21,7 +21,7 @@ class TestLayout < MiniTest::Test
end
def test_layout_index
assert_equal @mess.get_layout , @mess.internal_object_get(1) , "mess"
assert_equal @mess.get_layout , @mess.internal_object_get(0) , "mess"
end
def test_forbidden_index_of
@ -36,10 +36,14 @@ class TestLayout < MiniTest::Test
assert_equal 1 , layout.variable_index(:layout)
end
def test_length
assert_equal 8 , @mess.get_layout.object_instance_length , @mess.get_layout.inspect
end
def test_no_index_below_1
layout = @mess.get_layout
names = layout.object_instance_names
assert_equal 7 , names.get_length , names.inspect
assert_equal 8 , names.get_length , names.inspect
names.each do |n|
assert layout.variable_index(n) >= 1
end
@ -50,8 +54,8 @@ class TestLayout < MiniTest::Test
assert_equal Parfait::Class , oc.class
layout = oc.object_layout
assert_equal Parfait::Layout , layout.class
assert_equal layout.object_instance_names.get_length , 0
#assert_equal layout.first , :layout
assert_equal 1 , layout.object_instance_names.get_length
assert_equal layout.first , :layout
end
def test_attribute_set
@ -73,6 +77,6 @@ class TestLayout < MiniTest::Test
def test_remove_me
layout = @mess.get_layout
assert_equal layout , @mess.internal_object_get(1)
assert_equal layout , @mess.internal_object_get(0)
end
end

View File

@ -7,7 +7,7 @@ class TestObject < MiniTest::Test
end
def test_object_create
assert_equal 1 , @object.internal_object_length
assert_equal 1 , @object.get_layout.object_instance_length
end
def test_empty_object_doesnt_return
@ -18,18 +18,10 @@ class TestObject < MiniTest::Test
assert_equal 1 , @object.internal_object_set(1,1)
end
def test_set1_len
@object.internal_object_set(1,1)
assert_equal 1 , @object.internal_object_length
end
def test_one_set2
assert_equal :some , @object.internal_object_set(2,:some)
end
def test_set2_len
@object.internal_object_set(2,:some)
assert_equal 2 , @object.internal_object_length
end
def test_two_sets
assert_equal 1 , @object.internal_object_set(1,1)
assert_equal :some , @object.internal_object_set(1,:some)