[svn:parrot] r37638 - in trunk: src/pmc t/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Sun Mar 22 05:19:02 UTC 2009


Author: cotto
Date: Sun Mar 22 05:19:02 2009
New Revision: 37638
URL: https://trac.parrot.org/parrot/changeset/37638

Log:
[PMC] add get_iter + tests to *BooleanArray

Modified:
   trunk/src/pmc/fixedbooleanarray.pmc
   trunk/t/pmc/fixedbooleanarray.t
   trunk/t/pmc/resizablebooleanarray.t

Modified: trunk/src/pmc/fixedbooleanarray.pmc
==============================================================================
--- trunk/src/pmc/fixedbooleanarray.pmc	Sun Mar 22 05:04:17 2009	(r37637)
+++ trunk/src/pmc/fixedbooleanarray.pmc	Sun Mar 22 05:19:02 2009	(r37638)
@@ -497,6 +497,34 @@
 
 /*
 
+=item C<PMC *get_iter()>
+
+Return a new iterator for SELF.
+
+=cut
+
+*/
+
+    VTABLE PMC *get_iter() {
+        STRING     *name     = CONST_STRING(interp, "set_key");
+        PMC * const iter     = pmc_new_init(INTERP, enum_class_Iterator, SELF);
+        PMC * const key      = pmc_new(INTERP, enum_class_Key);
+
+        Parrot_PCCINVOKE(interp, iter, name, "P->", key);
+        PObj_get_FLAGS(key) |= KEY_integer_FLAG;
+
+        if (SELF.get_integer() == 0)
+            VTABLE_set_integer_native(INTERP, key, -1);
+        else
+            VTABLE_set_integer_native(INTERP, key, 0);
+
+        return iter;
+    }
+
+
+
+/*
+
 =back
 
 =head2 Freeze/thaw Interface

Modified: trunk/t/pmc/fixedbooleanarray.t
==============================================================================
--- trunk/t/pmc/fixedbooleanarray.t	Sun Mar 22 05:04:17 2009	(r37637)
+++ trunk/t/pmc/fixedbooleanarray.t	Sun Mar 22 05:19:02 2009	(r37638)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 13;
+use Parrot::Test tests => 14;
 
 =head1 NAME
 
@@ -337,6 +337,28 @@
 01001000100010010
 OUTPUT
 
+pir_output_is( <<'CODE', <<'OUTPUT', "get_iter" );
+.sub 'main' :main
+    $P0 = new ['FixedBooleanArray']
+    $P0 = 3
+    $P0[0] = 1
+    $P0[1] = 0
+    $P0[2] = 1
+    $P1 = iter $P0
+loop:
+    unless $P1 goto loop_end
+    $S2 = shift $P1
+    say $S2
+    goto loop
+loop_end:
+.end
+CODE
+1
+0
+1
+OUTPUT
+
+
 1;
 
 

Modified: trunk/t/pmc/resizablebooleanarray.t
==============================================================================
--- trunk/t/pmc/resizablebooleanarray.t	Sun Mar 22 05:04:17 2009	(r37637)
+++ trunk/t/pmc/resizablebooleanarray.t	Sun Mar 22 05:19:02 2009	(r37638)
@@ -24,7 +24,7 @@
 
     .include 'test_more.pir'
 
-    plan(64)
+    plan(65)
 
     setting_array_size()
     setting_first_element()
@@ -48,6 +48,7 @@
     pop_into_sparse()
     clone_tests()
     alternate_clone_tests()
+    get_iter_test()
 
 .end
 
@@ -831,6 +832,24 @@
     is(failed, 0, "all alternate clone tests passed")
 .end
 
+.sub get_iter_test
+    $P0 = new ['ResizableBooleanArray']
+    $P0 = 3
+    $P0[0] = 1
+    $P0[1] = 0
+    $P0[2] = 1
+    $P1 = iter $P0
+loop:
+    unless $P1 goto loop_end
+    $S2 = shift $P1
+    $S0 = concat $S0, $S2
+    goto loop
+  loop_end:
+    is($S0, "101", "get_iter works")
+.end
+
+
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list