Skip to content

Commit

Permalink
Detach RetContinuation from current CallContext in tailcall. Closes T…
Browse files Browse the repository at this point in the history
…T#1393.

git-svn-id: https://svn.parrot.org/parrot/trunk@43414 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bacek committed Jan 9, 2010
1 parent a7d1174 commit 5850932
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ops/core.ops
Expand Up @@ -464,8 +464,17 @@ inline op tailcall(invar PMC) :flow {
PMC * const this_call_sig = Parrot_pcc_get_signature(interp, ctx);
PMC * const parent_call_sig = Parrot_pcc_get_signature(interp, parent_ctx);
interp->current_cont = Parrot_pcc_get_continuation(interp, ctx);

Parrot_pcc_merge_signature_for_tailcall(interp, parent_call_sig, this_call_sig);

/* Detach continuation from current CallContext to avoid marking dead object. */
/* RetContinuation will kill itself after invoke */
if (interp->current_cont->vtable->base_type == enum_class_RetContinuation
&& Parrot_pcc_do_run_ops(interp, p)) {
PMC_cont(interp->current_cont)->from_ctx = parent_ctx;
Parrot_pcc_set_continuation(interp, ctx, PMCNULL);
}

SUB_FLAG_TAILCALL_SET(interp->current_cont);
dest = VTABLE_invoke(interp, p, dest);
goto ADDRESS(dest);
Expand Down
19 changes: 19 additions & 0 deletions src/ops/object.ops
Expand Up @@ -138,6 +138,15 @@ op tailcallmethod(invar PMC, in STR) :object_base :flow {
else {
interp->current_cont = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp));
PObj_get_FLAGS(interp->current_cont) |= SUB_FLAG_TAILCALL;
/* Detach continuation from current CallContext to avoid marking dead object. */
/* RetContinuation will kill itself after invoke */
if (interp->current_cont->vtable->base_type == enum_class_RetContinuation
&& Parrot_pcc_do_run_ops(interp, method_pmc)) {
PMC * const ctx = CURRENT_CONTEXT(interp);
PMC * const parent_ctx = Parrot_pcc_get_caller_ctx(interp, ctx);
PMC_cont(interp->current_cont)->from_ctx = parent_ctx;
Parrot_pcc_set_continuation(interp, ctx, PMCNULL);
}
interp->current_object = object;
dest = (opcode_t *)VTABLE_invoke(interp, method_pmc, next);
}
Expand All @@ -153,6 +162,16 @@ op tailcallmethod(invar PMC, invar PMC) :object_base :flow {

interp->current_cont = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp));
PObj_get_FLAGS(interp->current_cont) |= SUB_FLAG_TAILCALL;
/* Detach continuation from current CallContext to avoid marking dead object. */
/* RetContinuation will kill itself after invoke */
if (interp->current_cont->vtable->base_type == enum_class_RetContinuation
&& Parrot_pcc_do_run_ops(interp, method_pmc)) {
PMC * const ctx = CURRENT_CONTEXT(interp);
PMC * const parent_ctx = Parrot_pcc_get_caller_ctx(interp, ctx);
PMC_cont(interp->current_cont)->from_ctx = parent_ctx;
Parrot_pcc_set_continuation(interp, ctx, PMCNULL);
}

interp->current_object = object;
dest = (opcode_t *)VTABLE_invoke(interp, method_pmc, next);
goto ADDRESS(dest);
Expand Down

0 comments on commit 5850932

Please sign in to comment.