cvsuser 05/03/10 03:03:34
Modified: classes resizablepmcarray.pmc
src objects.c
t/pmc resizablepmcarray.t
Log:
ResizablePMCArray.unshift_pmc
Revision Changes Path
1.20 +26 -1 parrot/classes/resizablepmcarray.pmc
Index: resizablepmcarray.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/resizablepmcarray.pmc,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- resizablepmcarray.pmc 18 Feb 2005 13:41:26 -0000 1.19
+++ resizablepmcarray.pmc 10 Mar 2005 11:03:32 -0000 1.20
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: resizablepmcarray.pmc,v 1.19 2005/02/18 13:41:26 leo Exp $
+$Id: resizablepmcarray.pmc,v 1.20 2005/03/10 11:03:32 leo Exp $
=head1 NAME
@@ -242,6 +242,31 @@
}
/*
+=item C<void unshift_pmc (PMC* value)>
+
+Extends the array by adding an element of value C<*value> to the begin of
+the array.
+
+=cut
+
+*/
+
+ void unshift_pmc(PMC* value) {
+ INTVAL size = PMC_int_val(SELF);
+ PMC **data;
+ INTVAL i;
+
+ /* let set_integer_native() worry about memory allocation */
+ DYNSELF.set_integer_native(size + 1);
+ /* make room */
+ data = (PMC**)PMC_data(SELF);
+ for (i = size; i; --i) {
+ data[i] = data[i-1];
+ }
+ data[0] = value;
+ }
+/*
+
=item C<PMC *clone()>
Creates and returns a copy of the array.
1.135 +1 -3 parrot/src/objects.c
Index: objects.c
===================================================================
RCS file: /cvs/public/parrot/src/objects.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- objects.c 10 Mar 2005 09:57:12 -0000 1.134
+++ objects.c 10 Mar 2005 11:03:33 -0000 1.135
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: objects.c,v 1.134 2005/03/10 09:57:12 leo Exp $
+$Id: objects.c,v 1.135 2005/03/10 11:03:33 leo Exp $
=head1 NAME
@@ -320,8 +320,6 @@
child_class_name = Parrot_sprintf_c(interpreter, "%c%canon_%d",
0, 0, ++anon_count);
- //child_class_name = string_make(interpreter,
- // "\0\0anonymous", 11, "iso-8859-1", 0);
VTABLE_set_string_native(interpreter, classname_pmc,
child_class_name );
}
1.13 +36 -4 parrot/t/pmc/resizablepmcarray.t
Index: resizablepmcarray.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/resizablepmcarray.t,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- resizablepmcarray.t 4 Mar 2005 22:18:43 -0000 1.12
+++ resizablepmcarray.t 10 Mar 2005 11:03:34 -0000 1.13
@@ -1,7 +1,7 @@
#! perl -w
# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
-# $Id: resizablepmcarray.t,v 1.12 2005/03/04 22:18:43 nicholas Exp $
+# $Id: resizablepmcarray.t,v 1.13 2005/03/10 11:03:34 leo Exp $
=head1 NAME
@@ -18,7 +18,7 @@
=cut
-use Parrot::Test tests => 18;
+use Parrot::Test tests => 19;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -175,7 +175,7 @@
new P1, .Integer
set P1, 1234
set P0[-1], P1
- new P2, .Integer
+ new P2, .Integer
set P2, P0[9]
print P2
print "\n"
@@ -190,7 +190,7 @@
new P1, .Integer
set P1, 4321
set P0[99], P1
- new P2, .Integer
+ new P2, .Integer
set P2, P0[-1]
print P2
print "\n"
@@ -506,3 +506,35 @@
10001
123asdf
OUTPUT
+
+output_is(<< 'CODE', << 'OUTPUT', "unshift pmc");
+ new P0, .ResizablePMCArray
+ new P1, .Integer
+ set P1, 1
+ new P2, .Integer
+ set P2, 2
+ new P3, .Integer
+ set P3, 3
+ unshift P0, P1
+ unshift P0, P2
+ unshift P0, P3
+ elements I0, P0
+ print I0
+ print "\n"
+ set P3, P0[0]
+ print P3
+ print "\n"
+ set P3, P0[1]
+ print P3
+ print "\n"
+ set P3, P0[2]
+ print P3
+ print "\n"
+ end
+CODE
+3
+3
+2
+1
+OUTPUT
+