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

cotto at svn.parrot.org cotto at svn.parrot.org
Sun Mar 22 05:36:09 UTC 2009


Author: cotto
Date: Sun Mar 22 05:36:08 2009
New Revision: 37640
URL: https://trac.parrot.org/parrot/changeset/37640

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

Modified:
   trunk/src/pmc/fixedfloatarray.pmc
   trunk/t/pmc/fixedfloatarray.t
   trunk/t/pmc/resizablefloatarray.t

Modified: trunk/src/pmc/fixedfloatarray.pmc
==============================================================================
--- trunk/src/pmc/fixedfloatarray.pmc	Sun Mar 22 05:19:30 2009	(r37639)
+++ trunk/src/pmc/fixedfloatarray.pmc	Sun Mar 22 05:36:08 2009	(r37640)
@@ -100,6 +100,32 @@
 
 /*
 
+=item C<PMC *get_iter()>
+
+Return an Iterator for this PMC.
+
+=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;
+    }
+
+/*
+
 =item C<INTVAL get_bool()>
 
 Returns whether the array has any elements (meaning been initialized, for a

Modified: trunk/t/pmc/fixedfloatarray.t
==============================================================================
--- trunk/t/pmc/fixedfloatarray.t	Sun Mar 22 05:19:30 2009	(r37639)
+++ trunk/t/pmc/fixedfloatarray.t	Sun Mar 22 05:36:08 2009	(r37640)
@@ -20,7 +20,7 @@
 .sub main :main
     .include 'fp_equality.pasm'
     .include 'test_more.pir'
-    plan(24)
+    plan(25)
 
     array_size_tests()
     element_set_tests()
@@ -29,6 +29,7 @@
     clone_tests()
     what_is_truth()
     interface_check()
+    get_iter_test()
 .end
 
 .sub array_size_tests
@@ -221,6 +222,24 @@
     is(b, 0, "FFA does not do no_interface")
 .end
 
+.sub get_iter_test
+    $P0 = new ['FixedFloatArray']
+    $P0 = 3
+    $P0[0] = 1.1
+    $P0[1] = 99.99
+    $P0[2] = -345.001
+    $P1 = iter $P0
+loop:
+    unless $P1 goto loop_end
+    $S2 = shift $P1
+    $S0 = concat $S0, $S2
+    $S0 = concat $S0, ","
+    goto loop
+  loop_end:
+    is($S0, "1.1,99.99,-345.001,", "get_iter works")
+.end
+
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/t/pmc/resizablefloatarray.t
==============================================================================
--- trunk/t/pmc/resizablefloatarray.t	Sun Mar 22 05:19:30 2009	(r37639)
+++ trunk/t/pmc/resizablefloatarray.t	Sun Mar 22 05:36:08 2009	(r37640)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 21;
+use Parrot::Test tests => 22;
 
 =head1 NAME
 
@@ -489,6 +489,26 @@
 2 20.2 10.1
 OUTPUT
 
+pir_output_is( << 'CODE', << 'OUTPUT', "get_iter" );
+.sub main :main
+    $P0 = new ['ResizableFloatArray']
+    $P0[0] = 1.1
+    $P0[1] = 99.99
+    $P0[2] = -345.001
+    $P1 = iter $P0
+loop:
+    unless $P1 goto loop_end
+    $S2 = shift $P1
+    say $S2
+    goto loop
+  loop_end:
+.end
+CODE
+1.1
+99.99
+-345.001
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4


More information about the parrot-commits mailing list