Author: pmichaud
Date: Mon Mar 31 11:50:43 2008
New Revision: 26670
Modified:
trunk/src/pmc/resizablepmcarray.pmc
trunk/t/pmc/resizablepmcarray.t
Log:
* Add shift, unshift, push, pop, and elems methods to ResizablePMCArray.
Modified: trunk/src/pmc/resizablepmcarray.pmc
==============================================================================
--- trunk/src/pmc/resizablepmcarray.pmc (original)
+++ trunk/src/pmc/resizablepmcarray.pmc Mon Mar 31 11:50:43 2008
@@ -724,6 +724,65 @@
VTABLE_set_pmc_keyed_int(INTERP, SELF, i + offset,
VTABLE_get_pmc_keyed_int(INTERP, value, i));
}
+
+/*
+
+=item METHOD PMC* shift()
+
+=item METHOD PMC* pop()
+
+Method forms to remove and return a PMC from the beginning or
+end of the array.
+
+=cut
+
+*/
+
+ METHOD PMC* shift() {
+ PMC* value = VTABLE_shift_pmc(INTERP, SELF);
+ RETURN(PMC *value);
+ }
+
+ METHOD PMC* pop() {
+ PMC* value = VTABLE_pop_pmc(INTERP, SELF);
+ RETURN(PMC *value);
+ }
+
+/*
+
+=item METHOD unshift(PMC* value)
+
+=item METHOD push(PMC* value)
+
+Method forms to add a PMC to the beginning or end of the array.
+
+=cut
+
+*/
+
+ METHOD unshift(PMC* value) {
+ VTABLE_unshift_pmc(INTERP, SELF, value);
+ }
+
+ METHOD push(PMC* value) {
+ VTABLE_push_pmc(INTERP, SELF, value);
+ }
+
+/*
+
+=item METHOD elems()
+
+Method form to return the number of elements in an array.
+
+=cut
+
+*/
+
+ METHOD elems() {
+ INTVAL n = VTABLE_elements(INTERP, SELF);
+ RETURN(INTVAL n);
+ }
+
}
/*
Modified: trunk/t/pmc/resizablepmcarray.t
==============================================================================
--- trunk/t/pmc/resizablepmcarray.t (original)
+++ trunk/t/pmc/resizablepmcarray.t Mon Mar 31 11:50:43 2008
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 38;
+use Parrot::Test tests => 39;
=head1 NAME
@@ -1220,6 +1220,25 @@
15
OUTPUT
+pir_output_is( <<'CODE', <<'OUTPUT', 'method forms of
unshift/push/shift/pop/elems' );
+.sub main :main
+ $P0 = new 'ResizablePMCArray'
+ $P0.'unshift'(1)
+ $P0.'push'('two')
+ $I0 = $P0.'elems'()
+ say $I0
+ $P1 = $P0.'shift'()
+ say $P1
+ $P1 = $P0.'pop'()
+ say $P1
+.end
+CODE
+2
+1
+two
+OUTPUT
+
+
# don't forget to change the number of tests
# Local Variables: