From cbfb9225b4931dc422e3832284b375c87699f6a7 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Mon, 23 Feb 2009 15:11:55 +0100 Subject: [PATCH] use ATTR in LuaString PMC --- Configure.pl | 1 + src/pmc/luastring.pmc | 46 ++++++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Configure.pl b/Configure.pl index 8a8965d..6717de1 100644 --- a/Configure.pl +++ b/Configure.pl @@ -1,3 +1,4 @@ +# Copyright (C) 2009, Parrot Foundation. # $Id$ use strict; diff --git a/src/pmc/luastring.pmc b/src/pmc/luastring.pmc index 45eb5c5..034c0b4 100644 --- a/src/pmc/luastring.pmc +++ b/src/pmc/luastring.pmc @@ -37,6 +37,8 @@ pmclass LuaString hll lua maps String { + ATTR STRING * str_val; + /* =item C @@ -47,8 +49,24 @@ Initializes the string. */ VTABLE void init() { - PMC_str_val(SELF) = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0); - PObj_custom_mark_SET(SELF); + Parrot_LuaString_attributes *attrs = + mem_allocate_zeroed_typed(Parrot_LuaString_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 + +Destroys this String PMC. + +=cut + +*/ + VTABLE void destroy() { + mem_sys_free(PMC_data(SELF)); } /* @@ -64,14 +82,13 @@ Allow : */ VTABLE PMC* instantiate_str(STRING *rep, INTVAL flags) { PMC *res; - INTVAL type = PMC_type(SELF); + const INTVAL type = PMC_type(SELF); if (flags & PObj_constant_FLAG) res = constant_pmc_new(INTERP, type); else res = pmc_new(INTERP, type); - VTABLE_set_string_native(INTERP, res, Parrot_str_copy(INTERP, rep)); - PObj_custom_mark_SET(res); + SET_ATTR_str_val(INTERP, res, rep); return res; } @@ -85,8 +102,10 @@ Marks the string as live. */ 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); } /* @@ -99,7 +118,10 @@ Creates a copy of the string. */ VTABLE PMC* clone() { - return VTABLE_instantiate_str(INTERP, SELF, PMC_str_val(SELF), 0); + PMC * const res = pmc_new(INTERP, PMC_type(SELF)); + PObj_custom_mark_destroy_SETALL(res); + VTABLE_set_string_native(INTERP, res, Parrot_str_copy(INTERP, SELF.get_string())); + return res; } /* @@ -112,7 +134,9 @@ Returns the string itself. */ VTABLE STRING* get_string() { - return PMC_str_val(SELF); + STRING *str_val; + GET_ATTR_str_val(INTERP, SELF, str_val); + return Parrot_str_copy(INTERP, str_val); } /* @@ -168,7 +192,7 @@ Sets the value of the string to that of the specified C. value = Parrot_str_new_constant(INTERP, copy); } - PMC_str_val(SELF) = value; + SET_ATTR_str_val(INTERP, SELF, value); } /* @@ -182,7 +206,7 @@ the specified C. */ VTABLE void set_pmc(PMC *value) { - PMC_str_val(SELF) = VTABLE_get_string(INTERP, value); + SET_ATTR_str_val(INTERP, SELF, VTABLE_get_string(INTERP, value)); } /*