[svn:parrot] r36894 - trunk/src/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu Feb 19 22:19:48 UTC 2009
Author: cotto
Date: Thu Feb 19 22:19:48 2009
New Revision: 36894
URL: https://trac.parrot.org/parrot/changeset/36894
Log:
[PMC] convert String PMC to use ATTRs
Modified:
trunk/src/pmc/string.pmc
Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc Thu Feb 19 22:17:25 2009 (r36893)
+++ trunk/src/pmc/string.pmc Thu Feb 19 22:19:48 2009 (r36894)
@@ -23,6 +23,7 @@
#include "parrot/parrot.h"
pmclass String extends scalar provides string provides scalar {
+ ATTR STRING * str_val;
/*
@@ -35,12 +36,39 @@
*/
VTABLE void init() {
- PMC_str_val(SELF) = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0);
- PObj_custom_mark_SET(SELF);
+
+ Parrot_String_attributes *attrs =
+ mem_allocate_zeroed_typed(Parrot_String_attributes);
+
+ attrs->str_val = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0);
+ PMC_data(SELF) = attrs;
+
+ PObj_custom_mark_destroy_SETALL(SELF);
}
/*
+=item C<void destroy()>
+
+Destroys this String PMC.
+
+=cut
+
+*/
+
+ VTABLE void destroy() {
+
+ /* There's a bug that causes this function to be called several times,
+ * even for a simple PIR hello world. The null check/assignment allows
+ * parrot not to explode, but obviously something's goofy. */
+ if (PMC_data(SELF))
+ mem_sys_free(PMC_data(SELF));
+ PMC_data(SELF) = NULL;
+ }
+
+
+/*
+
=item C<PMC instantiate_str(STRING *rep)>
Class method to construct a String from the string representation C<rep>.
@@ -49,15 +77,15 @@
*/
VTABLE PMC *instantiate_str(STRING *rep, INTVAL flags) {
- PMC *res;
- const INTVAL type = SELF->vtable->base_type;
+ PMC *res;
+ const INTVAL type = SELF->vtable->base_type;
if (flags & PObj_constant_FLAG)
res = constant_pmc_new(INTERP, type);
else
res = pmc_new(INTERP, type);
- PMC_str_val(res) = rep;
+ SET_ATTR_str_val(INTERP, res, rep);
return res;
}
@@ -72,8 +100,11 @@
*/
VTABLE void mark() {
- if (PMC_str_val(SELF))
- pobject_lives(INTERP, (PObj *)PMC_str_val(SELF));
+ STRING *str_val;
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+
+ if (str_val)
+ pobject_lives(INTERP, (PObj *)str_val);
}
/*
@@ -87,7 +118,7 @@
*/
VTABLE PMC *clone() {
- PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+ PMC * const dest = pmc_new(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
VTABLE_set_string_native(INTERP, dest, Parrot_str_copy(INTERP, SELF.get_string()));
return dest;
@@ -151,8 +182,9 @@
*/
VTABLE STRING *get_string() {
- STRING * const s = PMC_str_val(SELF);
- return s ? Parrot_str_copy(INTERP, s) : NULL;
+ STRING *str_val;
+ GET_ATTR_str_val(INTERP, SELF, str_val);
+ return str_val ? Parrot_str_copy(INTERP, str_val) : NULL;
}
/*
@@ -221,7 +253,8 @@
const char *copy = Parrot_str_to_cstring(INTERP, value);
value = Parrot_str_new_constant(INTERP, copy);
}
- PMC_str_val(SELF) = value;
+
+ SET_ATTR_str_val(INTERP, SELF, value);
}
/*
@@ -235,7 +268,8 @@
*/
VTABLE void assign_string_native(STRING *value) {
- PMC_str_val(SELF) = Parrot_str_set(INTERP, SELF.get_string(), value);
+ SET_ATTR_str_val(INTERP, SELF,
+ Parrot_str_set(INTERP, SELF.get_string(), value));
}
/*
@@ -250,8 +284,8 @@
*/
VTABLE void set_string_same(PMC *value) {
- PMC_str_val(SELF) =
- Parrot_str_set(INTERP, SELF.get_string(), VTABLE_get_string(INTERP, value));
+ SET_ATTR_str_val(INTERP, SELF,
+ Parrot_str_set(INTERP, SELF.get_string(), VTABLE_get_string(INTERP, value)));
}
/*
@@ -447,7 +481,11 @@
VTABLE INTVAL is_equal(PMC *value) {
STRING * const s = VTABLE_get_string(INTERP, SELF);
STRING * const v = VTABLE_get_string(INTERP, value);
- return (INTVAL)(0 == Parrot_str_not_equal(INTERP, s, v));
+ return (INTVAL)(Parrot_str_equal(INTERP, s, v));
+ }
+
+ MULTI INTVAL is_equal(PMC *value) {
+ return SELF.is_equal(value);
}
/*
@@ -480,7 +518,7 @@
VTABLE INTVAL is_equal_string(PMC *value) {
STRING * const s = VTABLE_get_string(INTERP, SELF);
STRING * const v = VTABLE_get_string(INTERP, value);
- return Parrot_str_not_equal(INTERP, s, v) == 0;
+ return Parrot_str_equal(INTERP, s, v);
}
/*
@@ -941,10 +979,12 @@
}
VTABLE PMC *share_ro() {
- PMC * const ret = SUPER();
+ STRING *str_val;
+ PMC * const ret = SUPER();
+ GET_ATTR_str_val(INTERP, SELF, str_val);
/* prevent wrong garbage collection */
- PObj_is_shared_SET(PMC_str_val(SELF));
+ PObj_is_shared_SET(str_val);
return ret;
}
More information about the parrot-commits
mailing list