[svn:parrot] r40915 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Sep 1 22:27:40 UTC 2009
Author: bacek
Date: Tue Sep 1 22:27:36 2009
New Revision: 40915
URL: https://trac.parrot.org/parrot/changeset/40915
Log:
[cage][t] Add String.get_pmc_keyed and tests for keyed access to string.
Modified:
trunk/src/pmc/string.pmc
trunk/t/pmc/string.t
Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc Tue Sep 1 21:53:57 2009 (r40914)
+++ trunk/src/pmc/string.pmc Tue Sep 1 22:27:36 2009 (r40915)
@@ -645,6 +645,16 @@
return string_ord(INTERP, s, pos);
}
+ VTABLE PMC *get_pmc_keyed(PMC *key) {
+ return SELF.get_pmc_keyed_int(VTABLE_get_integer(INTERP, key));
+ }
+
+ VTABLE PMC *get_pmc_keyed_int(INTVAL pos) {
+ PMC * const dest = pmc_new(INTERP, SELF->vtable->base_type);
+ VTABLE_set_string_native(INTERP, dest, SELF.get_string_keyed_int(pos));
+ return dest;
+ }
+
VTABLE void set_string_keyed(PMC *key, STRING * const value) {
SELF.set_string_keyed_int(VTABLE_get_integer(INTERP, key), value);
}
@@ -666,6 +676,14 @@
Parrot_str_replace(INTERP, s, pos, 1, c, NULL);
VTABLE_set_string_native(INTERP, SELF, s);
}
+
+ VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
+ SELF.set_pmc_keyed_int(VTABLE_get_integer(INTERP, key), value);
+ }
+
+ VTABLE void set_pmc_keyed_int(INTVAL pos, PMC *value) {
+ SELF.set_string_keyed_int(pos, VTABLE_get_string(INTERP, value));
+ }
/*
=item C<void replace(STRING *orig, STRING *_new)>
Modified: trunk/t/pmc/string.t
==============================================================================
--- trunk/t/pmc/string.t Tue Sep 1 21:53:57 2009 (r40914)
+++ trunk/t/pmc/string.t Tue Sep 1 22:27:36 2009 (r40915)
@@ -20,7 +20,7 @@
.sub main :main
.include 'test_more.pir'
- plan(165)
+ plan(171)
set_or_get_strings()
setting_integers()
@@ -71,7 +71,7 @@
exception_to_int_2()
exception_to_int_3()
assign_null_string()
-
+ access_keyed()
# END_OF_TESTS
.end
@@ -1018,6 +1018,39 @@
is( $I0, 0, 'assign null string, TT #729' )
.end
+.sub access_keyed
+ .local pmc s
+ s = new ['String']
+ s = "BAR" # Second character is zero, not 'o'
+
+ # Get
+ $S0 = s[0]
+ is($S0, 'B', 'Get string by index')
+
+ $I0 = s[1]
+ $I1 = ord 'A'
+ is($I0, $I1, 'Get integer by index')
+
+ $P0 = s[2]
+ is($P0, 'R', 'Get PMC by index')
+
+ # Set
+ s = new ['String']
+
+ $S0 = 'f'
+ s[0] = $S0
+ is(s, 'f', 'Set string keyed')
+
+ $I0 = ord 'o'
+ s[1] = $I0
+ is(s, 'fo', 'Set integer keyed')
+
+ $P0 = new ['String']
+ $P0 = 'o'
+ s[2] = $P0
+ is(s, 'foo', 'Set PMC keyed')
+.end
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list