[svn:parrot] r36500 - trunk/languages/lua/src/pmc
fperrad at svn.parrot.org
fperrad at svn.parrot.org
Mon Feb 9 18:29:36 UTC 2009
Author: fperrad
Date: Mon Feb 9 18:29:36 2009
New Revision: 36500
URL: https://trac.parrot.org/parrot/changeset/36500
Log:
[Lua] refactor LuaThread PMC with ATTR
Modified:
trunk/languages/lua/src/pmc/luathread.pmc
Modified: trunk/languages/lua/src/pmc/luathread.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/luathread.pmc Mon Feb 9 18:11:52 2009 (r36499)
+++ trunk/languages/lua/src/pmc/luathread.pmc Mon Feb 9 18:29:36 2009 (r36500)
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2005-2008, The Perl Foundation.
+Copyright (C) 2005-2009, The Perl Foundation.
$Id$
=head1 NAME
@@ -22,15 +22,17 @@
#include "lua_private.h"
+#define t_val(pmc) (PARROT_LUATHREAD(pmc))->val
+#define t_env(pmc) (PARROT_LUATHREAD(pmc))->env
+
static PMC* curr_func(PARROT_INTERP) {
- Parrot_Context *ctx = CONTEXT(interp);
- PMC *sub = ctx->current_sub;
- return sub;
+ Parrot_Context * const ctx = CONTEXT(interp);
+ return ctx->current_sub;
}
static PMC* getcurrenv(PARROT_INTERP) {
PMC *env = NULL;
- PMC *sub = curr_func(interp);
+ PMC * const sub = curr_func(interp);
if (sub) {
env = PMC_metadata(sub);
}
@@ -45,6 +47,9 @@
group lua_group
hll lua {
+ ATTR PMC *val;
+ ATTR PMC *env;
+
/*
=item C<void init()>
@@ -69,18 +74,20 @@
VTABLE void init_pmc(PMC *sub) {
PMC * const classobj = Parrot_oo_get_class_str(INTERP,
Parrot_str_new_constant(INTERP, "Parrot::Coroutine"));
+ Parrot_LuaThread_attributes * const t = mem_allocate_zeroed_typed(Parrot_LuaThread_attributes);
PMC *init_args;
if (PMC_IS_NULL(classobj))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_GLOBAL_NOT_FOUND,
"Parrot::Coroutine not found");
+ PMC_data(SELF) = t;
init_args = pmc_new(INTERP, enum_class_Hash);
VTABLE_set_pmc_keyed_str(INTERP, init_args,
Parrot_str_new_constant(INTERP, "initial_sub"), sub);
- PMC_pmc_val(SELF) = VTABLE_instantiate(INTERP, classobj, init_args);
- PMC_metadata(SELF) = getcurrenv(INTERP);
- PObj_custom_mark_SET(SELF);
+ t_val(SELF) = VTABLE_instantiate(INTERP, classobj, init_args);
+ t_env(SELF) = getcurrenv(INTERP);
+ PObj_custom_mark_destroy_SETALL(SELF);
}
/*
@@ -93,10 +100,27 @@
*/
VTABLE void mark() {
- if (PMC_pmc_val(SELF))
- pobject_lives(INTERP, (PObj *)PMC_pmc_val(SELF));
- if (PMC_metadata(SELF))
- pobject_lives(INTERP, (PObj *)PMC_metadata(SELF));
+ if (t_val(SELF))
+ pobject_lives(INTERP, (PObj *)t_val(SELF));
+ if (t_env(SELF))
+ pobject_lives(INTERP, (PObj *)t_env(SELF));
+ }
+
+/*
+
+=item C<void destroy()>
+
+Call finalizer and free the thread.
+
+=cut
+
+*/
+ VTABLE void destroy() {
+ Parrot_LuaThread_attributes *u = PARROT_LUATHREAD(SELF);
+ if (u) {
+ mem_sys_free(u);
+ PMC_data(SELF) = NULL;
+ }
}
/*
@@ -131,7 +155,7 @@
*/
VTABLE PMC* get_attr_str(STRING *key) {
- return PMC_pmc_val(SELF);
+ return t_val(SELF);
}
/*
@@ -153,7 +177,8 @@
*/
VTABLE void set_pmc(PMC *value) {
- PMC_pmc_val(SELF) = PMC_pmc_val(value);
+ t_val(SELF) = t_val(value);
+ t_env(SELF) = t_env(value);
}
/*
@@ -191,7 +216,7 @@
*/
METHOD PMC* getfenv() {
- PMC *retval = PMC_metadata(SELF);
+ PMC *retval = t_env(SELF);
if (!retval)
retval = pmc_new(INTERP, dynpmc_LuaNil);
@@ -222,7 +247,7 @@
*/
METHOD void setfenv(PMC *env) {
- PMC_metadata(SELF) = env;
+ t_env(SELF) = env;
}
}
More information about the parrot-commits
mailing list