[svn:parrot] r40797 - in branches/context_pmc3: compilers/imcc include/parrot src src/gc src/interp src/ops src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Aug 25 22:22:21 UTC 2009
Author: bacek
Date: Tue Aug 25 22:22:20 2009
New Revision: 40797
URL: https://trac.parrot.org/parrot/changeset/40797
Log:
[core] Add current_sub accessor to Context and use it
Modified:
branches/context_pmc3/compilers/imcc/pbc.c
branches/context_pmc3/include/parrot/context.h
branches/context_pmc3/src/context.c
branches/context_pmc3/src/debug.c
branches/context_pmc3/src/embed.c
branches/context_pmc3/src/gc/alloc_register.c
branches/context_pmc3/src/hash.c
branches/context_pmc3/src/interp/inter_create.c
branches/context_pmc3/src/interp/inter_misc.c
branches/context_pmc3/src/ops/core.ops
branches/context_pmc3/src/packfile.c
branches/context_pmc3/src/pmc/continuation.pmc
branches/context_pmc3/src/pmc/coroutine.pmc
branches/context_pmc3/src/pmc/exception.pmc
branches/context_pmc3/src/pmc/parrotinterpreter.pmc
branches/context_pmc3/src/pmc/sub.pmc
branches/context_pmc3/src/sub.c
Modified: branches/context_pmc3/compilers/imcc/pbc.c
==============================================================================
--- branches/context_pmc3/compilers/imcc/pbc.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/compilers/imcc/pbc.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -1280,9 +1280,9 @@
}
/* could be eval too; check if :outer is the current sub */
- current = CURRENT_CONTEXT_FIELD(interp, current_sub);
+ current = Parrot_cx_get_sub(interp, CONTEXT(interp));
- if (!current)
+ if (PMC_IS_NULL(current))
IMCC_fatal(interp, 1, "Undefined :outer sub '%s'.\n",
unit->outer->name);
Modified: branches/context_pmc3/include/parrot/context.h
==============================================================================
--- branches/context_pmc3/include/parrot/context.h Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/include/parrot/context.h Tue Aug 25 22:22:20 2009 (r40797)
@@ -136,6 +136,11 @@
__attribute__nonnull__(2);
PARROT_EXPORT
+PMC* Parrot_cx_get_sub(PARROT_INTERP, ARGIN(PMC *ctx))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
UINTVAL Parrot_cx_inc_recursion_depth(PARROT_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -190,6 +195,13 @@
__attribute__nonnull__(2)
__attribute__nonnull__(3);
+PARROT_EXPORT
+void Parrot_cx_set_sub(PARROT_INTERP,
+ ARGIN(PMC *ctx),
+ ARGIN_NULLOK(PMC *sub))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
#define ASSERT_ARGS_Parrot_cx_constants __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
@@ -228,6 +240,9 @@
#define ASSERT_ARGS_Parrot_cx_get_string_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
+#define ASSERT_ARGS_Parrot_cx_get_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(ctx)
#define ASSERT_ARGS_Parrot_cx_inc_recursion_depth __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
@@ -255,6 +270,9 @@
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(outer_ctx)
+#define ASSERT_ARGS_Parrot_cx_set_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(ctx)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/context.c */
Modified: branches/context_pmc3/src/context.c
==============================================================================
--- branches/context_pmc3/src/context.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/context.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -445,6 +445,45 @@
c->current_object = object;
}
+/*
+
+=item C<PMC* Parrot_cx_get_sub(PARROT_INTERP, PMC *ctx)>
+
+Get Sub executed inside Context.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PMC*
+Parrot_cx_get_sub(PARROT_INTERP, ARGIN(PMC *ctx))
+{
+ ASSERT_ARGS(Parrot_cx_get_sub)
+ Parrot_Context *c = Parrot_cx_get_context(interp, ctx);
+ return c->current_sub;
+}
+
+
+/*
+
+=item C<void Parrot_cx_set_sub(PARROT_INTERP, PMC *ctx, PMC *sub)>
+
+Set Sub executed inside Context.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_cx_set_sub(PARROT_INTERP, ARGIN(PMC *ctx), ARGIN_NULLOK(PMC *sub))
+{
+ ASSERT_ARGS(Parrot_cx_set_sub)
+ Parrot_Context *c = Parrot_cx_get_context(interp, ctx);
+ c->current_sub = sub;
+}
+
/*
Modified: branches/context_pmc3/src/debug.c
==============================================================================
--- branches/context_pmc3/src/debug.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/debug.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -3559,8 +3559,8 @@
if (!PMC_IS_NULL(old) && PMC_cont(old) &&
CONTEXT_FIELD(interp, PMC_cont(old)->to_ctx, current_pc) ==
CONTEXT_FIELD(interp, PMC_cont(sub)->to_ctx, current_pc) &&
- CONTEXT_FIELD(interp, PMC_cont(old)->to_ctx, current_sub) ==
- CONTEXT_FIELD(interp, PMC_cont(sub)->to_ctx, current_sub)) {
+ Parrot_cx_get_sub(interp, PMC_cont(old)->to_ctx) ==
+ Parrot_cx_get_sub(interp, PMC_cont(sub)->to_ctx)) {
++rec_level;
}
else if (rec_level != 0) {
Modified: branches/context_pmc3/src/embed.c
==============================================================================
--- branches/context_pmc3/src/embed.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/embed.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -910,7 +910,7 @@
const size_t offs = sub->start_offs;
if (offs == interp->resume_offset) {
- CURRENT_CONTEXT_FIELD(interp, current_sub) = sub_pmc;
+ Parrot_cx_set_sub(interp, CONTEXT(interp), sub_pmc);
Parrot_cx_set_HLL(interp, CONTEXT(interp), sub->HLL_id);
return sub_pmc;
}
@@ -925,7 +925,7 @@
sub_pmc = pmc_new(interp, enum_class_Sub);
PMC_get_sub(interp, sub_pmc, sub_pmc_sub);
sub_pmc_sub->start_offs = 0;
- CURRENT_CONTEXT_FIELD(interp, current_sub) = sub_pmc;
+ Parrot_cx_set_sub(interp, CONTEXT(interp), sub_pmc);
return sub_pmc;
}
@@ -970,14 +970,14 @@
Parrot_on_exit(interp, print_profile, NULL);
/* Let's kick the tires and light the fires--call interpreter.c:runops. */
- main_sub = CURRENT_CONTEXT_FIELD(interp, current_sub);
+ main_sub = Parrot_cx_get_sub(interp, CONTEXT(interp));
/* if no sub was marked being :main, we create a dummy sub with offset 0 */
if (!main_sub)
main_sub = set_current_sub(interp);
- CURRENT_CONTEXT_FIELD(interp, current_sub) = NULL;
+ Parrot_cx_set_sub(interp, CONTEXT(interp), NULL);
CURRENT_CONTEXT_FIELD(interp, constants) = interp->code->const_table->constants;
Parrot_runops_fromc_args(interp, main_sub, "vP", userargv);
Modified: branches/context_pmc3/src/gc/alloc_register.c
==============================================================================
--- branches/context_pmc3/src/gc/alloc_register.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/gc/alloc_register.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -325,7 +325,7 @@
Parrot_cx_set_caller_ctx(interp, ctx, old);
/* doesn't change */
- CONTEXT_FIELD(interp, ctx, current_sub) = CONTEXT_FIELD(interp, old, current_sub);
+ Parrot_cx_set_sub(interp, ctx, Parrot_cx_get_sub(interp, old));
/* copy more ? */
return ctx;
Modified: branches/context_pmc3/src/hash.c
==============================================================================
--- branches/context_pmc3/src/hash.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/hash.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -1282,6 +1282,8 @@
const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
HashBucket *bucket = hash->bi[hashval & hash->mask];
+ //PARROT_ASSERT((hash->entry_type != enum_type_PMC) || value);
+
/* Very complex assert that we'll not put non-constant stuff into constant hash */
PARROT_ASSERT(
PMC_IS_NULL(hash->container)
Modified: branches/context_pmc3/src/interp/inter_create.c
==============================================================================
--- branches/context_pmc3/src/interp/inter_create.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/interp/inter_create.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -215,7 +215,7 @@
CURRENT_CONTEXT_FIELD(interp, recursion_depth) = (UINTVAL)-1;
/* clear context introspection vars */
- CURRENT_CONTEXT_FIELD(interp, current_sub) = NULL;
+ Parrot_cx_set_sub(interp, CONTEXT(interp), NULL);
Parrot_cx_set_continuation(interp, CONTEXT(interp), NULL); /* TODO Use PMCNULL */
Parrot_cx_set_object(interp, CONTEXT(interp), NULL);
Modified: branches/context_pmc3/src/interp/inter_misc.c
==============================================================================
--- branches/context_pmc3/src/interp/inter_misc.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/interp/inter_misc.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -282,7 +282,7 @@
ASSERT_ARGS(interpinfo_p)
switch (what) {
case CURRENT_SUB:
- return CURRENT_CONTEXT_FIELD(interp, current_sub);
+ return Parrot_cx_get_sub(interp, CONTEXT(interp));
case CURRENT_CONT:
{
PMC * const cont = Parrot_cx_get_continuation(interp, CONTEXT(interp));
Modified: branches/context_pmc3/src/ops/core.ops
==============================================================================
--- branches/context_pmc3/src/ops/core.ops Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/ops/core.ops Tue Aug 25 22:22:20 2009 (r40797)
@@ -447,7 +447,7 @@
inline op yield() :flow {
opcode_t *dest = expr NEXT();
- PMC * const p = CURRENT_CONTEXT_FIELD(interp, current_sub);
+ PMC * const p = Parrot_cx_get_sub(interp, CONTEXT(interp));
dest = (opcode_t *)p->vtable->invoke(interp, p, dest);
goto ADDRESS(dest);
}
Modified: branches/context_pmc3/src/packfile.c
==============================================================================
--- branches/context_pmc3/src/packfile.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/packfile.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -759,7 +759,7 @@
/ sizeof (opcode_t *);
PObj_get_FLAGS(sub_pmc) &= ~SUB_FLAG_PF_MAIN;
- CURRENT_CONTEXT_FIELD(interp, current_sub) = sub_pmc;
+ Parrot_cx_set_sub(interp, CONTEXT(interp), sub_pmc);
}
else {
Parrot_warn(interp, PARROT_WARNINGS_ALL_FLAG,
Modified: branches/context_pmc3/src/pmc/continuation.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/continuation.pmc Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/pmc/continuation.pmc Tue Aug 25 22:22:20 2009 (r40797)
@@ -286,7 +286,7 @@
METHOD caller() {
Parrot_cont *cc = PMC_cont(SELF);
- PMC *caller = CONTEXT_FIELD(interp, cc->to_ctx, current_sub);
+ PMC *caller = Parrot_cx_get_sub(interp, cc->to_ctx);
Parrot_Sub_attributes *sub;
if (!caller)
Modified: branches/context_pmc3/src/pmc/coroutine.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/coroutine.pmc Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/pmc/coroutine.pmc Tue Aug 25 22:22:20 2009 (r40797)
@@ -49,7 +49,7 @@
if (co->ctx && (PObj_get_FLAGS(sub_pmc) & SUB_FLAG_CORO_FF)) {
Parrot_io_eprintf(tracer, " to '%Ss'",
Parrot_full_sub_name(interp,
- CONTEXT_FIELD(interp, Parrot_cx_get_caller_ctx(interp, co->ctx), current_sub)));
+ Parrot_cx_get_sub(interp, Parrot_cx_get_caller_ctx(interp, co->ctx))));
}
Parrot_io_eprintf(tracer, "\n# ");
@@ -151,8 +151,8 @@
CONTEXT_FIELD(INTERP, ctx, caller_ctx) = caller_ctx;
PMC_cont(ccont)->from_ctx = ctx;
- CONTEXT_FIELD(INTERP, ctx, current_sub) = SELF;
- Parrot_cx_set_HLL(interp, CONTEXT(interp), co->HLL_id);
+ Parrot_cx_set_sub(INTERP, ctx, SELF);
+ Parrot_cx_set_HLL(interp, ctx, co->HLL_id);
Parrot_cx_set_namespace(INTERP, ctx, co->namespace_stash);
Parrot_cx_set_continuation(INTERP, ctx, ccont);
Parrot_cx_set_object(interp, ctx, NULL);
Modified: branches/context_pmc3/src/pmc/exception.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/exception.pmc Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/pmc/exception.pmc Tue Aug 25 22:22:20 2009 (r40797)
@@ -767,9 +767,9 @@
Parrot_Sub_attributes *sub;
/* Get sub and put it in the hash. */
- PMC *sub_pmc = CONTEXT_FIELD(interp, cur_ctx, current_sub);
+ PMC *sub_pmc = Parrot_cx_get_sub(interp, cur_ctx);
- if (!sub_pmc)
+ if (sub_pmc)
sub_pmc = PMCNULL;
VTABLE_set_pmc_keyed_str(interp, frame, CONST_STRING(interp, "sub"), sub_pmc);
Modified: branches/context_pmc3/src/pmc/parrotinterpreter.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/parrotinterpreter.pmc Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/pmc/parrotinterpreter.pmc Tue Aug 25 22:22:20 2009 (r40797)
@@ -498,19 +498,19 @@
ctx = PMC_cont(cont)->to_ctx;
- if (PMC_IS_NULL(CONTEXT_FIELD(interp, ctx, current_sub)))
+ if (PMC_IS_NULL(Parrot_cx_get_sub(interp, ctx)))
Parrot_ex_throw_from_c_args(interp, NULL,
CONTROL_ERROR, "No such caller depth");
}
}
if (item == outer)
- return CONTEXT_FIELD(interp, ctx, current_sub);
+ return Parrot_cx_get_sub(interp, ctx);
s = CONST_STRING(interp, "sub");
if (Parrot_str_equal(interp, item, s))
- return CONTEXT_FIELD(interp, ctx, current_sub);
+ return Parrot_cx_get_sub(interp, ctx);
s = CONST_STRING(interp, "lexpad");
@@ -530,7 +530,7 @@
s = CONST_STRING(interp, "annotations");
if (Parrot_str_equal(interp, item, s)) {
- PMC *sub_pmc = CONTEXT_FIELD(interp, ctx, current_sub);
+ PMC *sub_pmc = Parrot_cx_get_sub(interp, ctx);
if (ctx == CONTEXT(interp)) {
/* We can't know the current program counter for the currently
* executing sub, so can't return annotations for that. */
Modified: branches/context_pmc3/src/pmc/sub.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/sub.pmc Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/pmc/sub.pmc Tue Aug 25 22:22:20 2009 (r40797)
@@ -282,7 +282,7 @@
/* plain subroutine call
* create new context, place it in interpreter */
context = Parrot_set_new_context(INTERP, sub->n_regs_used);
- CONTEXT_FIELD(interp, context, current_sub) = SELF;
+ Parrot_cx_set_sub(interp, context, SELF);
CONTEXT_FIELD(interp, context, caller_ctx) = caller_ctx;
CONTEXT_FIELD(interp, context, current_pc) = pc;
Parrot_cx_set_continuation(interp, context, ccont);
@@ -335,7 +335,7 @@
PMC *outer_pmc;
Parrot_Sub_attributes *current_sub, *outer_sub;
- PMC_get_sub(INTERP, CONTEXT_FIELD(interp, c, current_sub), current_sub);
+ PMC_get_sub(INTERP, Parrot_cx_get_sub(interp, c), current_sub);
outer_pmc = current_sub->outer_sub;
if (PMC_IS_NULL(outer_pmc))
@@ -346,7 +346,7 @@
if (!outer_sub->ctx) {
PMC * const dummy = Parrot_alloc_context(INTERP,
outer_sub->n_regs_used, NULL);
- CONTEXT_FIELD(interp, dummy, current_sub) = outer_pmc;
+ Parrot_cx_set_sub(interp, dummy, outer_pmc);
if (!PMC_IS_NULL(outer_sub->lex_info)) {
Parrot_cx_set_lex_pad(interp, dummy, pmc_new_init(INTERP,
@@ -969,10 +969,10 @@
/* (CONTEXT(interp)->caller_ctx->caller_ctx->current_sub */
tmp1 = Parrot_cx_get_caller_ctx(interp, CONTEXT(interp));
tmp2 = Parrot_cx_get_caller_ctx(interp, tmp1);
- if (CONTEXT_FIELD(interp, tmp2, current_sub) == outer)
+ if (Parrot_cx_get_sub(interp, tmp2) == outer)
sub->outer_ctx = tmp2;
/* else if (CONTEXT(interp)->caller_ctx->current_sub == outer) */
- else if (CONTEXT_FIELD(interp, tmp1, current_sub) == outer)
+ else if (Parrot_cx_get_sub(interp, tmp1) == outer)
sub->outer_ctx = tmp1;
}
Modified: branches/context_pmc3/src/sub.c
==============================================================================
--- branches/context_pmc3/src/sub.c Tue Aug 25 22:21:34 2009 (r40796)
+++ branches/context_pmc3/src/sub.c Tue Aug 25 22:22:20 2009 (r40797)
@@ -264,7 +264,7 @@
info->fullname = NULL;
/* is the current sub of the specified context valid? */
- if (PMC_IS_NULL(CONTEXT_FIELD(interp, ctx, current_sub))) {
+ if (PMC_IS_NULL(Parrot_cx_get_sub(interp, ctx))) {
info->subname = Parrot_str_new(interp, "???", 3);
info->nsname = info->subname;
info->fullname = Parrot_str_new(interp, "??? :: ???", 10);
@@ -273,10 +273,10 @@
}
/* fetch Parrot_sub of the current sub in the given context */
- if (!VTABLE_isa(interp, CONTEXT_FIELD(interp, ctx, current_sub), CONST_STRING(interp, "Sub")))
+ if (!VTABLE_isa(interp, Parrot_cx_get_sub(interp, ctx), CONST_STRING(interp, "Sub")))
return 1;
- PMC_get_sub(interp, CONTEXT_FIELD(interp, ctx, current_sub), sub);
+ PMC_get_sub(interp, Parrot_cx_get_sub(interp, ctx), sub);
/* set the sub name */
info->subname = sub->name;
@@ -287,7 +287,7 @@
}
else {
info->nsname = VTABLE_get_string(interp, sub->namespace_name);
- info->fullname = Parrot_full_sub_name(interp, CONTEXT_FIELD(interp, ctx, current_sub));
+ info->fullname = Parrot_full_sub_name(interp, Parrot_cx_get_sub(interp, ctx));
}
/* return here if there is no current pc */
@@ -412,7 +412,7 @@
Parrot_Sub_attributes *current_sub;
Parrot_Sub_attributes *sub;
- PMC_get_sub(interp, CONTEXT_FIELD(interp, ctx, current_sub), current_sub);
+ PMC_get_sub(interp, Parrot_cx_get_sub(interp, ctx), current_sub);
/* MultiSub gets special treatment */
if (VTABLE_isa(interp, sub_pmc, CONST_STRING(interp, "MultiSub"))) {
@@ -532,7 +532,7 @@
/* debug print before context is switched */
if (Interp_trace_TEST(interp, PARROT_TRACE_SUB_CALL_FLAG)) {
- PMC * const sub = CONTEXT_FIELD(interp, to_ctx, current_sub);
+ PMC * const sub = Parrot_cx_get_sub(interp, to_ctx);
Parrot_io_eprintf(interp, "# Back in sub '%Ss', env %p\n",
Parrot_full_sub_name(interp, sub),
More information about the parrot-commits
mailing list