Permalink
Browse files

[PMC] add get_iter + tests to *FloatArray

git-svn-id: https://svn.parrot.org/parrot/trunk@37640 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 42f7a8e commit c2b50bfbcbc7ddd2b495a941f2e162e6ad0b588c @cotto cotto committed Mar 22, 2009
Showing with 67 additions and 2 deletions.
  1. +26 −0 src/pmc/fixedfloatarray.pmc
  2. +20 −1 t/pmc/fixedfloatarray.t
  3. +21 −1 t/pmc/resizablefloatarray.t
@@ -100,6 +100,32 @@ Creates and returns a copy of the array.
/*
+=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
View
@@ -20,7 +20,7 @@ out-of-bounds test. Checks INT and PMC keys.
.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 @@ out-of-bounds test. Checks INT and PMC keys.
clone_tests()
what_is_truth()
interface_check()
+ get_iter_test()
.end
.sub array_size_tests
@@ -221,6 +222,24 @@ end:
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
@@ -6,7 +6,7 @@ use strict;
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 @@ CODE
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

0 comments on commit c2b50bf

Please sign in to comment.