adding an instance for the length of lists
This commit is contained in:
parent
c1ee67038c
commit
df62b75c6f
@ -14,6 +14,7 @@ module Parfait
|
|||||||
module Indexed # marker module
|
module Indexed # marker module
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend(Methods)
|
base.extend(Methods)
|
||||||
|
base.attribute :indexed_length
|
||||||
end
|
end
|
||||||
|
|
||||||
# include? means non nil index
|
# include? means non nil index
|
||||||
@ -143,11 +144,11 @@ module Parfait
|
|||||||
offset
|
offset
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method :get_length do
|
define_method :get_length do
|
||||||
internal_object_length - 1 - offset
|
r = internal_object_get( offset + 1) #one for layout
|
||||||
|
r.nil? ? 0 : r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# set the value at index.
|
# set the value at index.
|
||||||
# Lists start from index 1
|
# Lists start from index 1
|
||||||
define_method :set do | index , value|
|
define_method :set do | index , value|
|
||||||
@ -174,14 +175,16 @@ module Parfait
|
|||||||
raise "Only positive lenths, #{len}" if len < 0
|
raise "Only positive lenths, #{len}" if len < 0
|
||||||
old_length = self.get_length
|
old_length = self.get_length
|
||||||
return if old_length >= len
|
return if old_length >= len
|
||||||
internal_object_grow(len + 1 + offset)
|
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
|
end
|
||||||
|
|
||||||
define_method :shrink_to do | len|
|
define_method :shrink_to do | len|
|
||||||
raise "Only positive lenths, #{len}" if len < 0
|
raise "Only positive lenths, #{len}" if len < 0
|
||||||
old_length = self.get_length
|
old_length = self.get_length
|
||||||
return if old_length <= len
|
return if old_length <= len
|
||||||
internal_object_shrink(len + 1 + offset)
|
internal_object_set( offset + 1 , len) #one for layout
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -114,7 +114,7 @@ module Register
|
|||||||
# and all instance variable names. Really have to find a better way
|
# and all instance variable names. Really have to find a better way
|
||||||
def layout_names
|
def layout_names
|
||||||
{ :Word => [] ,
|
{ :Word => [] ,
|
||||||
:List => [] ,
|
:List => [:indexed_length] ,
|
||||||
# Assumtion is that name is the last of message
|
# Assumtion is that name is the last of message
|
||||||
:Message => [:next_message , :receiver , :frame , :return_address , :return_value,
|
:Message => [:next_message , :receiver , :frame , :return_address , :return_value,
|
||||||
:caller , :name ],
|
:caller , :name ],
|
||||||
@ -125,7 +125,7 @@ module Register
|
|||||||
:BinaryCode => [],
|
:BinaryCode => [],
|
||||||
:Space => [:classes , :first_message ],
|
:Space => [:classes , :first_message ],
|
||||||
:Frame => [:next_frame ],
|
:Frame => [:next_frame ],
|
||||||
:Layout => [:object_class] ,
|
:Layout => [:object_class,:indexed_length] ,
|
||||||
# TODO fix layouts for inherited classes. Currently only :Class and the
|
# TODO fix layouts for inherited classes. Currently only :Class and the
|
||||||
# instances are copied (shame on you)
|
# instances are copied (shame on you)
|
||||||
:Class => [:object_layout , :name , :instance_methods , :super_class_name , :meta_class],
|
:Class => [:object_layout , :name , :instance_methods , :super_class_name , :meta_class],
|
||||||
|
@ -15,7 +15,6 @@ class TestList < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_old_layout_push
|
def test_old_layout_push
|
||||||
list = Register.machine.space.classes.keys
|
list = Register.machine.space.classes.keys
|
||||||
list.push(1)
|
|
||||||
assert_equal Parfait::Layout , list.get_layout.class
|
assert_equal Parfait::Layout , list.get_layout.class
|
||||||
end
|
end
|
||||||
def test_new_layout
|
def test_new_layout
|
||||||
@ -54,7 +53,8 @@ class TestList < MiniTest::Test
|
|||||||
assert_equal nil , @list.get(3)
|
assert_equal nil , @list.get(3)
|
||||||
end
|
end
|
||||||
def test_one_set1
|
def test_one_set1
|
||||||
assert_equal 1 , @list.set(1,1)
|
assert_equal 2 , @list.set(1,2)
|
||||||
|
assert_equal 1 , @list.internal_object_get(1)
|
||||||
end
|
end
|
||||||
def test_set1_len
|
def test_set1_len
|
||||||
@list.set(1,1)
|
@list.set(1,1)
|
||||||
@ -73,7 +73,7 @@ class TestList < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_one_get1
|
def test_one_get1
|
||||||
test_one_set1
|
test_one_set1
|
||||||
assert_equal 1 , @list.get(1)
|
assert_equal 2 , @list.get(1)
|
||||||
end
|
end
|
||||||
def test_one_get2
|
def test_one_get2
|
||||||
test_one_set2
|
test_one_set2
|
||||||
|
Loading…
Reference in New Issue
Block a user