[svn:parrot] r46162 - branches/codestring/src/pmc
coke at svn.parrot.org
coke at svn.parrot.org
Fri Apr 30 00:58:57 UTC 2010
Author: coke
Date: Fri Apr 30 00:58:56 2010
New Revision: 46162
URL: https://trac.parrot.org/parrot/changeset/46162
Log:
Make String more forgiving about child PMCs that don't use the String ATTR.
This seems too verbose, and perhaps is a good candidate for PMC2C to do for us.
Modified:
branches/codestring/src/pmc/string.pmc
Modified: branches/codestring/src/pmc/string.pmc
==============================================================================
--- branches/codestring/src/pmc/string.pmc Fri Apr 30 00:52:21 2010 (r46161)
+++ branches/codestring/src/pmc/string.pmc Fri Apr 30 00:58:56 2010 (r46162)
@@ -92,7 +92,11 @@
VTABLE INTVAL get_integer() {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_to_int(INTERP, str_val);
}
@@ -108,7 +112,11 @@
VTABLE FLOATVAL get_number() {
STRING *str_val;
- GET_ATTR_str_val(interp, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_to_num(INTERP, str_val);
}
@@ -124,7 +132,11 @@
VTABLE STRING *get_string() {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return str_val;
}
@@ -140,7 +152,11 @@
VTABLE INTVAL get_bool() {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_boolean(INTERP, str_val);
}
@@ -202,7 +218,10 @@
Parrot_str_free_cstring(copy);
}
- SET_ATTR_str_val(INTERP, SELF, value);
+ if (SELF->vtable->base_type == enum_class_String)
+ SET_ATTR_str_val(INTERP, SELF, value);
+ else
+ SELF.set_string_native(value);
}
/*
@@ -216,7 +235,10 @@
*/
VTABLE void assign_string_native(STRING *value) {
- SET_ATTR_str_val(INTERP, SELF, value);
+ if (SELF->vtable->base_type == enum_class_String)
+ SET_ATTR_str_val(INTERP, SELF, value);
+ else
+ SELF.set_string_native(value);
}
/*
@@ -246,7 +268,11 @@
VTABLE INTVAL is_equal(PMC *value) {
STRING *str_val;
STRING * const v = VTABLE_get_string(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return (INTVAL)(Parrot_str_equal(INTERP, str_val, v));
}
@@ -270,7 +296,11 @@
FLOATVAL sf;
const FLOATVAL vf = VTABLE_get_number(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
sf = Parrot_str_to_num(INTERP, str_val);
return (INTVAL)(sf == vf);
@@ -289,7 +319,12 @@
VTABLE INTVAL is_equal_string(PMC *value) {
STRING *str_val;
STRING * const v = VTABLE_get_string(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_equal(INTERP, str_val, v);
}
@@ -307,7 +342,12 @@
VTABLE INTVAL cmp(PMC *value) {
STRING *str_val;
STRING * const v = VTABLE_get_string(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_compare(INTERP, str_val, v);
}
@@ -326,7 +366,12 @@
STRING *str_val;
FLOATVAL sf;
const FLOATVAL vf = VTABLE_get_number(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
sf = Parrot_str_to_num(INTERP, str_val);
if (sf < vf)
@@ -352,7 +397,12 @@
VTABLE INTVAL cmp_string(PMC *value) {
STRING *str_val;
STRING * const v = VTABLE_get_string(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_compare(INTERP, str_val, v);
}
@@ -368,7 +418,12 @@
*/
VTABLE void substr(INTVAL offset, INTVAL length, PMC *dest) {
STRING *str_val, *s2;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
s2 = Parrot_str_substr(INTERP, str_val, offset, length);
VTABLE_set_string_native(INTERP, dest, s2);
}
@@ -385,7 +440,12 @@
*/
VTABLE STRING *substr_str(INTVAL offset, INTVAL length) {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_substr(INTERP, str_val, offset, length);
}
@@ -405,7 +465,11 @@
INTVAL n;
const INTVAL k = VTABLE_get_integer(INTERP, key);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
n = Parrot_str_byte_length(INTERP, str_val);
return (INTVAL)((k >= 0 && k <= n) || (k < 0 && -k <= n));
@@ -440,7 +504,12 @@
VTABLE STRING *get_string_keyed_int(INTVAL pos) {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_substr(INTERP, str_val, pos, 1);
}
@@ -450,7 +519,12 @@
VTABLE INTVAL get_integer_keyed_int(INTVAL pos) {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return string_ord(INTERP, str_val, pos);
}
@@ -471,9 +545,18 @@
VTABLE void set_string_keyed_int(INTVAL pos, STRING * const value) {
STRING *str_val;
const INTVAL len = Parrot_str_byte_length(INTERP, value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
str_val = Parrot_str_replace(INTERP, str_val, pos, len, value);
- SET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ SET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ SELF.set_string_native(str_val);
}
VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
@@ -483,9 +566,18 @@
VTABLE void set_integer_keyed_int(INTVAL pos, INTVAL value) {
STRING *str_val;
STRING * const c = string_chr(INTERP, (UINTVAL) value);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
str_val = Parrot_str_replace(INTERP, str_val, pos, 1, c);
- SET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ SET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ SELF.set_string_native(str_val);
}
VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
@@ -606,7 +698,12 @@
VTABLE INTVAL elements() {
STRING *str_val;
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
return Parrot_str_byte_length(INTERP, str_val);
}
@@ -632,7 +729,12 @@
VTABLE void freeze(PMC *info) {
STRING *str_val;
SUPER(info);
- GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ str_val = SELF.get_string();
+
VTABLE_push_string(INTERP, info, str_val);
}
@@ -646,8 +748,16 @@
*/
VTABLE void thaw(PMC *info) {
+ STRING *str_val;
+
SUPER(info);
- SET_ATTR_str_val(INTERP, SELF, VTABLE_shift_string(INTERP, info));
+
+ str_val = VTABLE_shift_string(INTERP, info);
+
+ if (SELF->vtable->base_type == enum_class_String)
+ SET_ATTR_str_val(INTERP, SELF, str_val);
+ else
+ SELF.set_string_native(str_val);
}
/*
More information about the parrot-commits
mailing list