Permalink
Browse files

this patch adds some relevant 'push' ops to the resizable PMCs, descr…

…ibed in

pdd_17.
There are also a couple of POD improvements and tests in t/pmc/resizable*.t.

Courtesy of Bernhard Schmalhofer <Bernhard.Schmalhofer@biomax.de>


git-svn-id: https://svn.parrot.org/parrot/trunk@6856 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 70bb9f4 commit 1e8a4ab7d9972098f88038c81d8765c3085db103 Dan Sugalski committed Oct 19, 2004
View
2 classes/fixedbooleanarray.pmc
@@ -441,7 +441,7 @@ C<value>.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
View
2 classes/fixedfloatarray.pmc
@@ -440,7 +440,7 @@ C<value>.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
View
2 classes/fixedintegerarray.pmc
@@ -441,7 +441,7 @@ C<value>.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
View
7 classes/fixedpmcarray.pmc
@@ -10,7 +10,6 @@ classes/fixedpmcarray.pmc - fixed size array for PMCs only
This class, FixedPMCArray, implements an array of fixed size, which stores PMCs,
it puts things into Integer, Float, or String PMCs as appropriate
-TODO currently this uses Perl types.
=head2 Functions
@@ -734,9 +733,13 @@ Return a new iterator for SELF.
=back
+=head1 TODO
+
+currently this uses Perl types.
+
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
View
2 classes/fixedstringarray.pmc
@@ -471,7 +471,7 @@ C<value>.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
View
29 classes/resizablebooleanarray.pmc
@@ -4,12 +4,12 @@ $Id$
=head1 NAME
-classes/resizablebooleanarray.pmc - resizable size array for booleans only
+classes/resizablebooleanarray.pmc - resizable array for booleans only
=head1 DESCRIPTION
-This class, ResizableBooleanArray, implements an array of resizable size, which stores booleans,
-it uses Boolean PMCs for all of the conversions
+This class, ResizableBooleanArray, implements an array of resizable size, which stores booleans.
+It uses Boolean PMCs for all of the conversions,
=head2 Functions
@@ -75,6 +75,22 @@ Sets the integer value of the element at index C<key> to C<value>.
/*
+=item C<void push_integer (STRING* value)>
+
+Extends the array by adding an element of value C<*value> to the end of
+the array.
+
+=cut
+
+*/
+
+ void push_integer (INTVAL value) {
+ INTVAL nextix = DYNSELF.elements();
+ DYNSELF.set_integer_keyed_int(nextix, value);
+ }
+
+/*
+
=item C<void set_integer_native(INTVAL size)>
Resizes the array to C<size> elements.
@@ -138,12 +154,13 @@ Creates and returns a copy of the array.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
-Initial version 2004.06.11 by Matt Fowles
-Changed allocator to double size - MF 2004.06.15
+Initial version - Matt Fowles 2004-06-11
+Changed allocator to double size - Matt Fowles 2004-06-15
+Added push_integer - Bernhard Schmalhofer 2004-10-17
=cut
View
8 classes/resizablefloatarray.pmc
@@ -4,7 +4,7 @@ $Id$
=head1 NAME
-classes/resizablefloatarray.pmc - resizable size array for floating point
+classes/resizablefloatarray.pmc - resizable array for floating point
numbers only
=head1 DESCRIPTION
@@ -199,12 +199,12 @@ Removes and returns the last element in the array.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
-Initial version 2004.06.11 by Matt Fowles
-Changed allocator to double size - MF 2004.06.15
+Initial version - Matt Fowles 2004-06-11
+Changed allocator to double size - Matt Fowles 2004-06-15
=cut
View
29 classes/resizableintegerarray.pmc
@@ -4,12 +4,12 @@ $Id$
=head1 NAME
-classes/resizableintegerarray.pmc - resizable size array for integers only
+classes/resizableintegerarray.pmc - resizable array for integers only
=head1 DESCRIPTION
-This class, ResizableIntegerArray, implements an array of resizable size, which stored INTVALs,
-it uses Integer PMCs for all of the conversions
+This class, ResizableIntegerArray, implements an array of resizable size, which stores INTVALs.
+It uses Integer PMCs for all of the conversions.
=head2 Functions
@@ -107,6 +107,22 @@ Resizes the array to C<size> elements.
/*
+=item C<void push_integer (STRING* value)>
+
+Extends the array by adding an element of value C<*value> to the end of
+the array.
+
+=cut
+
+*/
+
+ void push_integer (INTVAL value) {
+ INTVAL nextix = DYNSELF.elements();
+ DYNSELF.set_integer_keyed_int(nextix, value);
+ }
+
+/*
+
=item C<PMC *clone()>
Creates and returns a copy of the array.
@@ -138,12 +154,13 @@ Creates and returns a copy of the array.
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
-Initial version 2004.06.11 by Matt Fowles
-Changed allocator to double size - MF 2004.06.15
+Initial version - Matt Fowles 2004-06-11
+Changed allocator to double size - Matt Fowles 2004-06-15
+Added push_integer - Bernhard Schmalhofer 2004-10-17
=cut
View
40 classes/resizablepmcarray.pmc
@@ -4,15 +4,13 @@ $Id$
=head1 NAME
-classes/resizablepmcarray.pmc - resizable size array for PMCs only
+classes/resizablepmcarray.pmc - resizable array for PMCs only
=head1 DESCRIPTION
-This class, ResizablePMCArray, implements an array of resizable size,
-which stores PMCs, it puts things into Integer, Float, or String PMCs
-as appropriate
-
-TODO currently this uses PerlString instead of String PMCs.
+This class, ResizablePMCArray, implements an resizable array,
+which stores PMCs. It puts things into Integer, Float, or String PMCs
+as appropriate.
=head2 Functions
@@ -176,14 +174,24 @@ If key is a slice, do a splice as set that item.
"ResizablePMCArray: unimplemented delete!\n");
}
+/*
+
+=item C<void push_pmc (PMC* value)>
+
+Extends the array by adding an element of value C<*value> to the end of
+the array.
+
+=cut
+
+*/
+
void push_pmc(PMC* value) {
- INTVAL cap = PMC_int_val2(SELF);
INTVAL size = PMC_int_val(SELF);
- if (size + 1 >= cap)
- DYNSELF.set_integer_native(size + 1);
- else
- PMC_int_val(SELF) = size + 1;
+ /* let set_integer_native() worry about memory allocation */
+ DYNSELF.set_integer_native(size + 1);
((PMC**)PMC_data(SELF))[size] = value;
+
+ return;
}
METHOD void append(PMC* value) {
@@ -308,14 +316,18 @@ list.elements == 1.
=back
+=head1 TODO
+
+Currently this uses PerlString instead of String PMCs.
+
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
-Initial version 2004.06.11 by Matt Fowles
-Changed allocator to double size - MF 2004.06.15
+Initial version - Matt Fowles 2004-06-11
+Changed allocator to double size - Matt Fowles 2004-06-15
=cut
View
33 classes/resizablestringarray.pmc
@@ -4,12 +4,12 @@ $Id$
=head1 NAME
-classes/resizablestringarray.pmc - resizable size array for strings only
+classes/resizablestringarray.pmc - resizable array for strings only
=head1 DESCRIPTION
-This class, ResizableStringArray, implements an array of resizable size, which stored STRING*
-TODO: it uses PerlString's internally to perform conversion, but it should use String PMCs
+This class, ResizableStringArray, implements a resizeable array, which stores STRING*
+values only.
=head2 Functions
@@ -75,6 +75,22 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
/*
+=item C<void push_string (STRING* value)>
+
+Extends the array by adding an element of value C<*value> to the end of
+the array.
+
+=cut
+
+*/
+
+ void push_string (STRING* value) {
+ INTVAL nextix = DYNSELF.elements();
+ DYNSELF.set_string_keyed_int(nextix, value);
+ }
+
+/*
+
=item C<void set_integer_native(INTVAL size)>
Resizes the array to C<size> elements.
@@ -168,14 +184,19 @@ Marks the array as live.
=back
+=head1 TODO
+
+This PMC uses PerlString's internally to perform conversion, but it should use String PMCs.
+
=head1 SEE ALSO
-F<docs/pdds/pdd03_calling_conventions.pod>.
+F<docs/pdds/pdd17_basic_types.pod>.
=head1 HISTORY
-Initial version 2004.06.11 by Matt Fowles
-Changed allocator to double size - MF 2004.06.15
+Initial version - Matt Fowles 2004-06-11
+Changed allocator to double size - Matt Fowles 2004-06-15
+Added push_string - Bernhard Schmalhofer 2004-10-17
=cut
View
24 t/pmc/resizablebooleanarray.t
@@ -17,7 +17,7 @@ out-of-bounds test. Checks INT and PMC keys.
=cut
-use Parrot::Test tests => 8;
+use Parrot::Test tests => 9;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -308,4 +308,24 @@ CODE
0
OUTPUT
-1;
+output_is(<< 'CODE', << 'OUTPUT', "push integer");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new ResizableBooleanArray
+ pmc1[9999] = 0
+ push pmc1, 10001
+ .local int elements
+ elements = pmc1
+ print elements
+ print "\n"
+ .local string last
+ last = pmc1[10000]
+ print last
+ print "\n"
+ end
+.end
+CODE
+10001
+1
+OUTPUT
View
24 t/pmc/resizablefloatarray.t
@@ -17,7 +17,7 @@ out-of-bounds test. Checks INT and PMC keys.
=cut
-use Parrot::Test tests => 16;
+use Parrot::Test tests => 17;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -432,4 +432,24 @@ CODE
0
OUTPUT
-1;
+output_is(<< 'CODE', << 'OUTPUT', "push float");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new ResizableFloatArray
+ pmc1[9999] = 10000.10000
+ push pmc1, 123.123
+ .local int elements
+ elements = pmc1
+ print elements
+ print "\n"
+ .local string last
+ last = pmc1[10000]
+ print last
+ print "\n"
+ end
+.end
+CODE
+10001
+123.123
+OUTPUT
View
24 t/pmc/resizableintegerarray.t
@@ -17,7 +17,7 @@ out-of-bounds test. Checks INT and PMC keys.
=cut
-use Parrot::Test tests => 8;
+use Parrot::Test tests => 9;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -292,4 +292,24 @@ CODE
0
OUTPUT
-1;
+output_is(<< 'CODE', << 'OUTPUT', "push integer");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new ResizableIntegerArray
+ pmc1[9999] = 0
+ push pmc1, 10001
+ .local int elements
+ elements = pmc1
+ print elements
+ print "\n"
+ .local string last
+ last = pmc1[10000]
+ print last
+ print "\n"
+ end
+.end
+CODE
+10001
+10001
+OUTPUT
View
28 t/pmc/resizablepmcarray.t
@@ -17,7 +17,7 @@ out-of-bounds test. Checks INT and PMC keys.
=cut
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 11;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -356,4 +356,28 @@ CODE
1 2 5 9 10 x
OUTPUT
-1;
+output_is(<< 'CODE', << 'OUTPUT', "push pmc");
+##PIR##
+.sub _main
+ .local pmc pmc_arr, pmc_9999, pmc_10000
+ pmc_arr = new ResizablePMCArray
+ pmc_9999 = new Float
+ pmc_9999 = 10000.10000
+ pmc_10000 = new Float
+ pmc_10000 = 123.123
+ pmc_arr[9999] = pmc_9999
+ push pmc_arr, pmc_10000
+ .local int elements
+ elements = pmc_arr
+ print elements
+ print "\n"
+ .local pmc last
+ last = pmc_arr[10000]
+ print last
+ print "\n"
+ end
+.end
+CODE
+10001
+123.123
+OUTPUT
View
24 t/pmc/resizablestringarray.t
@@ -17,7 +17,7 @@ out-of-bounds test. Checks INT and PMC keys.
=cut
-use Parrot::Test tests => 8;
+use Parrot::Test tests => 9;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -293,4 +293,24 @@ CODE
0
OUTPUT
-1;
+output_is(<< 'CODE', << 'OUTPUT', "push string");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new ResizableStringArray
+ pmc1[2009] = "two zero zero nine"
+ push pmc1, "two zero one zero"
+ .local int elements
+ elements = pmc1
+ print elements
+ print "\n"
+ .local string last
+ last = pmc1[2010]
+ print last
+ print "\n"
+ end
+.end
+CODE
+2011
+two zero one zero
+OUTPUT

0 comments on commit 1e8a4ab

Please sign in to comment.