[svn:parrot] r37637 - in trunk: src/pmc t/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Sun Mar 22 05:04:18 UTC 2009
Author: cotto
Date: Sun Mar 22 05:04:17 2009
New Revision: 37637
URL: https://trac.parrot.org/parrot/changeset/37637
Log:
[PMC] add get_iter VTABLE function and tests to *IntegerArray
Modified:
trunk/src/pmc/fixedintegerarray.pmc
trunk/t/pmc/fixedintegerarray.t
trunk/t/pmc/resizableintegerarray.t
Modified: trunk/src/pmc/fixedintegerarray.pmc
==============================================================================
--- trunk/src/pmc/fixedintegerarray.pmc Sun Mar 22 04:20:05 2009 (r37636)
+++ trunk/src/pmc/fixedintegerarray.pmc Sun Mar 22 05:04:17 2009 (r37637)
@@ -563,6 +563,33 @@
/*
+=item C<PMC *get_iter()>
+
+Return a new 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<void visit(visit_info *info)>
This is used by freeze/thaw to visit the contents of the array.
Modified: trunk/t/pmc/fixedintegerarray.t
==============================================================================
--- trunk/t/pmc/fixedintegerarray.t Sun Mar 22 04:20:05 2009 (r37636)
+++ trunk/t/pmc/fixedintegerarray.t Sun Mar 22 05:04:17 2009 (r37637)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 11;
+use Parrot::Test tests => 12;
=head1 NAME
@@ -269,6 +269,28 @@
0
OUTPUT
+pir_output_is( <<'CODE', <<'OUTPUT', "get_iter" );
+.sub 'main' :main
+ new $P0, ['FixedIntegerArray']
+ set $P0, 3
+ $P0[0] = 42
+ $P0[1] = 43
+ $P0[2] = 44
+ $P1 = iter $P0
+loop:
+ unless $P1 goto loop_end
+ $S2 = shift $P1
+ say $S2
+ goto loop
+loop_end:
+.end
+CODE
+42
+43
+44
+OUTPUT
+
+
1;
# Local Variables:
Modified: trunk/t/pmc/resizableintegerarray.t
==============================================================================
--- trunk/t/pmc/resizableintegerarray.t Sun Mar 22 04:20:05 2009 (r37636)
+++ trunk/t/pmc/resizableintegerarray.t Sun Mar 22 05:04:17 2009 (r37637)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 17;
+use Parrot::Test tests => 18;
=head1 NAME
@@ -424,6 +424,29 @@
2 20 10
OUTPUT
+pir_output_is( <<'CODE', <<'OUTPUT', "get_iter" );
+.sub 'main' :main
+ $P0 = new ['ResizableIntegerArray']
+ $P0[0] = 42
+ $P0[1] = 43
+ $P0[2] = 44
+ push $P0, 999
+ $P1 = iter $P0
+loop:
+ unless $P1 goto loop_end
+ $S2 = shift $P1
+ say $S2
+ goto loop
+loop_end:
+.end
+CODE
+42
+43
+44
+999
+OUTPUT
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list