Author: jisom
Date: Sat Jan 14 04:12:55 2006
New Revision: 11174

Modified:
   trunk/src/classes/resizablestringarray.pmc
   trunk/t/pmc/resizablestringarray.t
Log:
Add a shift_pmc to ResizableStringArray
Returns a new String pmc


Modified: trunk/src/classes/resizablestringarray.pmc
==============================================================================
--- trunk/src/classes/resizablestringarray.pmc  (original)
+++ trunk/src/classes/resizablestringarray.pmc  Sat Jan 14 04:12:55 2006
@@ -205,6 +205,33 @@ Removes and returns an item from the sta
 
 /*
 
+=item C<PMC* shift_pmc()>
+        
+Removes and returns a String PMC from the start of the array.
+
+=cut    
+                
+*/  
+
+    PMC* shift_pmc () {
+        INTVAL size;
+        PMC *ret;
+        STRING* value;
+
+        size = PMC_int_val(SELF);
+        if (size == 0)
+            internal_exception(OUT_OF_BOUNDS,
+                    "ResizableStringArray: Can't shift from an empty array!");
+
+        value = DYNSELF.get_string_keyed_int(0);
+        ret = pmc_new(INTERP, enum_class_String);
+        VTABLE_set_string_native(INTERP, ret, value);
+        DYNSELF.delete_keyed_int(0);
+        return ret;
+    } 
+
+/*
+
 =item C<void unshift_string(STRING *value)>
 
 Extends the array by adding an element of value C<*value> to the start
@@ -273,6 +300,7 @@ Removes the element at C<*key>.
 }
 
 
+
 /*
 
 =back

Modified: trunk/t/pmc/resizablestringarray.t
==============================================================================
--- trunk/t/pmc/resizablestringarray.t  (original)
+++ trunk/t/pmc/resizablestringarray.t  Sat Jan 14 04:12:55 2006
@@ -6,7 +6,7 @@ use strict;
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 27;
+use Parrot::Test tests => 28;
 
 =head1 NAME
 
@@ -545,6 +545,47 @@ d[63]
 [63]
 OUTPUT
 
+pir_output_is(<< 'CODE', << 'OUTPUT', "shift pmc");
+.sub test :main
+       .local string s, s_elem
+       .local pmc pmc_arr, p_elem
+       .local int elements
+
+       pmc_arr= new .ResizableStringArray
+          push pmc_arr, 'a'
+          push pmc_arr, 'b'
+
+       print_num_elements( pmc_arr )
+
+          p_elem = shift pmc_arr
+          print p_elem
+       print_num_elements( pmc_arr )
+
+       p_elem = shift pmc_arr
+       print p_elem
+       print_num_elements( pmc_arr )
+
+       print_num_elements( pmc_arr )
+
+.end
+
+.sub print_num_elements
+       .param pmc pmc_arr
+       .local int elements
+       elements = pmc_arr
+       print '['
+       print elements
+       print "]\n"
+       .return()
+.end
+
+CODE
+[2]
+a[1]
+b[0]
+[0]
+OUTPUT
+
 
 pir_output_like(<< 'CODE', << 'OUTPUT', "shift bounds checking");
 .sub 'test' :main

Reply via email to