[svn:parrot] r40132 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Fri Jul 17 10:09:13 UTC 2009
Author: bacek
Date: Fri Jul 17 10:09:10 2009
New Revision: 40132
URL: https://trac.parrot.org/parrot/changeset/40132
Log:
[pmc] Add StringIterator.shift_pmc and pop_pmc. fperrad++ for reporting
Modified:
trunk/src/pmc/stringiterator.pmc
trunk/t/pmc/stringiterator.t
Modified: trunk/src/pmc/stringiterator.pmc
==============================================================================
--- trunk/src/pmc/stringiterator.pmc Fri Jul 17 06:07:09 2009 (r40131)
+++ trunk/src/pmc/stringiterator.pmc Fri Jul 17 10:09:10 2009 (r40132)
@@ -188,6 +188,30 @@
/*
+=item C<STRING *shift_pmc()>
+
+Shift next character from C<string> as PMC.
+
+=cut
+
+*/
+ VTABLE PMC *shift_pmc() {
+ Parrot_StringIterator_attributes *attrs =
+ PARROT_STRINGITERATOR(SELF);
+ PMC *ret;
+
+ if (attrs->pos >= attrs->length)
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
+ "StopIteration");
+
+ ret = pmc_new(INTERP, enum_class_String);
+ VTABLE_set_string_native(INTERP, ret,
+ VTABLE_get_string_keyed_int(INTERP, attrs->string, attrs->pos++));
+ return ret;
+ }
+
+/*
+
=item C<STRING *shift_string()>
Shift next character from C<string>.
@@ -228,6 +252,30 @@
/*
+=item C<STRING *pop_pmc()>
+
+Shift "next" character from C<string> for reverse iterator as PMC.
+
+=cut
+
+*/
+ VTABLE PMC *pop_pmc() {
+ Parrot_StringIterator_attributes *attrs =
+ PARROT_STRINGITERATOR(SELF);
+ PMC *ret;
+
+ if (!STATICSELF.get_bool())
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
+ "StopIteration");
+
+ ret = pmc_new(INTERP, enum_class_String);
+ VTABLE_set_string_native(INTERP, ret,
+ VTABLE_get_string_keyed_int(INTERP, attrs->string, --attrs->pos));
+ return ret;
+ }
+
+/*
+
=item C<STRING *pop_string()>
Shift "next" character from C<string> for reverse iterator.
Modified: trunk/t/pmc/stringiterator.t
==============================================================================
--- trunk/t/pmc/stringiterator.t Fri Jul 17 06:07:09 2009 (r40131)
+++ trunk/t/pmc/stringiterator.t Fri Jul 17 10:09:10 2009 (r40132)
@@ -51,9 +51,9 @@
ok(it, "Can shift 2nd character")
is($S0, 'a', "With correct value")
- $S0 = shift it
+ $P0 = shift it
nok(it, "Iterator is finished after 3rd shift")
- is($S0, 'r', "3rd character has correct value")
+ is($P0, 'r', "3rd character has correct value as PMC")
$I0 = 1
push_eh fail
@@ -83,13 +83,13 @@
ok(it, "Can shift 2nd character")
is($S0, 'A', "With expected value")
- $S0 = pop it
+ $P0 = pop it
nok(it, "Iterator is finished after third shift")
- is($S0, 'B', "3rd element has correct value")
+ is($P0, 'B', "3rd element has correct value as PMC")
$I0 = 1
push_eh fail
- $P0 = shift it
+ $P0 = pop it
$I0 = 0
fail:
pop_eh
More information about the parrot-commits
mailing list