From 78ab76295a291415fdef7dc084bf886a14efd888 Mon Sep 17 00:00:00 2001 From: Vasily Chekalkin Date: Wed, 21 Apr 2010 21:11:17 +0000 Subject: [PATCH] Remove RetContinuation PMC. Closes TT#1427. Coke++ for all hard work. git-svn-id: https://svn.parrot.org/parrot/trunk@45867 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- MANIFEST | 2 - PBC_COMPAT | 1 + include/parrot/sub.h | 17 ----- src/call/pcc.c | 2 +- src/interp/inter_misc.c | 3 - src/ops/core.ops | 16 +++-- src/pmc/continuation.pmc | 18 ------ src/pmc/coroutine.pmc | 6 +- src/pmc/retcontinuation.pmc | 118 ----------------------------------- src/pmc/sub.pmc | 11 ++-- src/sub.c | 54 ---------------- t/native_pbc/annotations.pbc | Bin 1136 -> 1136 bytes t/native_pbc/integer_1.pbc | Bin 800 -> 800 bytes t/native_pbc/number_1.pbc | Bin 2304 -> 2304 bytes t/native_pbc/string_1.pbc | Bin 1120 -> 1120 bytes t/op/gc.t | 1 - t/pmc/retcontinuation.t | 32 ---------- 17 files changed, 23 insertions(+), 258 deletions(-) delete mode 100644 src/pmc/retcontinuation.pmc delete mode 100644 t/pmc/retcontinuation.t diff --git a/MANIFEST b/MANIFEST index 147462e1fe..98fbdddc0a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1465,7 +1465,6 @@ src/pmc/resizablefloatarray.pmc [] src/pmc/resizableintegerarray.pmc [] src/pmc/resizablepmcarray.pmc [] src/pmc/resizablestringarray.pmc [] -src/pmc/retcontinuation.pmc [] src/pmc/role.pmc [] src/pmc/scalar.pmc [] src/pmc/scheduler.pmc [] @@ -1949,7 +1948,6 @@ t/pmc/resizablefloatarray.t [test] t/pmc/resizableintegerarray.t [test] t/pmc/resizablepmcarray.t [test] t/pmc/resizablestringarray.t [test] -t/pmc/retcontinuation.t [test] t/pmc/ro.t [test] t/pmc/role.t [test] t/pmc/scalar.t [test] diff --git a/PBC_COMPAT b/PBC_COMPAT index 19db2f9394..595c1e6290 100644 --- a/PBC_COMPAT +++ b/PBC_COMPAT @@ -27,6 +27,7 @@ # please insert tab separated entries at the top of the list +6.7 2010.04.17 coke remove RetContinuation PMC 6.6 2010.04.17 bacek add replace op 6.5 2010.03.09 cotto remove cpu_ret op 6.4 2010.03.02 cotto remove prederef__ and reserved diff --git a/include/parrot/sub.h b/include/parrot/sub.h index c2d4146008..e096257a51 100644 --- a/include/parrot/sub.h +++ b/include/parrot/sub.h @@ -171,13 +171,6 @@ typedef struct Parrot_Context_info { /* HEADERIZER BEGIN: src/sub.c */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ -PARROT_EXPORT -PARROT_MALLOC -PARROT_CANNOT_RETURN_NULL -PMC * new_ret_continuation_pmc(PARROT_INTERP, - ARGIN_NULLOK(opcode_t *address)) - __attribute__nonnull__(1); - PARROT_EXPORT void Parrot_capture_lex(PARROT_INTERP, ARGMOD(PMC *sub_pmc)) __attribute__nonnull__(1) @@ -219,11 +212,6 @@ PMC* parrot_new_closure(PARROT_INTERP, ARGIN(PMC *sub_pmc)) __attribute__nonnull__(1) __attribute__nonnull__(2); -void invalidate_retc_context(PARROT_INTERP, ARGMOD(PMC *cont)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - FUNC_MODIFIES(*cont); - void mark_context_start(void); void Parrot_continuation_check(PARROT_INTERP, ARGIN(const PMC *pmc)) __attribute__nonnull__(1) @@ -262,8 +250,6 @@ INTVAL Parrot_Sub_get_line_from_pc(PARROT_INTERP, ARGIN_NULLOK(opcode_t *pc)) __attribute__nonnull__(1); -#define ASSERT_ARGS_new_ret_continuation_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp)) #define ASSERT_ARGS_Parrot_capture_lex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(sub_pmc)) @@ -283,9 +269,6 @@ INTVAL Parrot_Sub_get_line_from_pc(PARROT_INTERP, #define ASSERT_ARGS_parrot_new_closure __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(sub_pmc)) -#define ASSERT_ARGS_invalidate_retc_context __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(cont)) #define ASSERT_ARGS_mark_context_start __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_continuation_check __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ diff --git a/src/call/pcc.c b/src/call/pcc.c index 17047801b2..c16253e895 100644 --- a/src/call/pcc.c +++ b/src/call/pcc.c @@ -340,7 +340,7 @@ Parrot_pcc_invoke_from_sig_object(PARROT_INTERP, ARGIN(PMC *sub_obj), opcode_t *dest; UINTVAL n_regs_used[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; PMC *ctx = Parrot_push_context(interp, n_regs_used); - PMC * const ret_cont = new_ret_continuation_pmc(interp, NULL); + PMC * const ret_cont = pmc_new(interp, enum_class_Continuation); Parrot_pcc_set_signature(interp, ctx, call_object); Parrot_pcc_set_continuation(interp, ctx, ret_cont); diff --git a/src/interp/inter_misc.c b/src/interp/inter_misc.c index b7715600d3..f7748dd481 100644 --- a/src/interp/inter_misc.c +++ b/src/interp/inter_misc.c @@ -283,9 +283,6 @@ interpinfo_p(PARROT_INTERP, INTVAL what) case CURRENT_CONT: { PMC * const cont = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp)); - if (!PMC_IS_NULL(cont) && cont->vtable->base_type == - enum_class_RetContinuation) - return VTABLE_clone(interp, cont); return cont; } case CURRENT_OBJECT: diff --git a/src/ops/core.ops b/src/ops/core.ops index bd6b77b0eb..69e3438ef2 100644 --- a/src/ops/core.ops +++ b/src/ops/core.ops @@ -746,7 +746,9 @@ inline op throw(invar PMC) :flow { PMC * except = $1; opcode_t *dest; opcode_t * const ret = expr NEXT(); - PMC * const resume = new_ret_continuation_pmc(interp, ret); + PMC * const resume = pmc_new(interp, enum_class_Continuation); + + VTABLE_set_pointer(interp, resume, ret); if (PMC_IS_NULL(except) || except->vtable->base_type != enum_class_Exception) except = Parrot_ex_build_exception(interp, EXCEPT_fatal, @@ -792,10 +794,12 @@ inline op count_eh(out INT) { inline op die(in STR) :flow { opcode_t *dest; opcode_t * const ret = expr NEXT(); - PMC * const resume = new_ret_continuation_pmc(interp, ret); + PMC * const resume = pmc_new(interp, enum_class_Continuation); PMC * const exception = Parrot_ex_build_exception(interp, EXCEPT_error, CONTROL_ERROR, $1); + VTABLE_set_pointer(interp, resume, ret); + VTABLE_set_attr_str(interp, exception, Parrot_str_new_constant(interp, "resume"), resume); dest = Parrot_ex_throw_from_op(interp, exception, ret); @@ -805,11 +809,13 @@ inline op die(in STR) :flow { inline op die(in PMC) :flow { opcode_t *dest; opcode_t * const ret = expr NEXT(); - PMC * const resume = new_ret_continuation_pmc(interp, ret); + PMC * const resume = pmc_new(interp, enum_class_Continuation); STRING * const msg = PMC_IS_NULL($1) ? NULL : VTABLE_get_string(interp, $1); PMC * const exception = Parrot_ex_build_exception(interp, EXCEPT_error, CONTROL_ERROR, msg); + VTABLE_set_pointer(interp, resume, ret); + VTABLE_set_attr_str(interp, exception, Parrot_str_new_constant(interp, "resume"), resume); dest = Parrot_ex_throw_from_op(interp, exception, ret); @@ -831,9 +837,11 @@ inline op die(in INT, in INT) :flow { inline op exit(in INT) :flow { opcode_t *dest; opcode_t * const ret = expr NEXT(); - PMC * const resume = new_ret_continuation_pmc(interp, ret); + PMC * const resume = pmc_new(interp, enum_class_Continuation); PMC * const exception = Parrot_ex_build_exception(interp, EXCEPT_exit, $1, NULL); + VTABLE_set_pointer(interp, resume, ret); + VTABLE_set_attr_str(interp, exception, Parrot_str_new_constant(interp, "resume"), resume); VTABLE_set_integer_keyed_str(interp, exception, diff --git a/src/pmc/continuation.pmc b/src/pmc/continuation.pmc index 6e2ba503ad..31d54419d9 100644 --- a/src/pmc/continuation.pmc +++ b/src/pmc/continuation.pmc @@ -78,15 +78,6 @@ Initializes the continuation. SET_ATTR_address(INTERP, SELF, NULL); PObj_custom_mark_SET(SELF); - - /* PANIC("don't do that"); */ - /* - * Whenever we create a continuation, all return continuations - * up the call chain may be reused due to invoking the - * continuation. To avoid that all return continuations are - * converted to true continuations. - */ - invalidate_retc_context(INTERP, SELF); } /*if they pass in a PMC to initialize with*/ @@ -109,15 +100,6 @@ Initializes the continuation. SET_ATTR_address(INTERP, SELF, address); PObj_custom_mark_SET(SELF); - - /* PANIC("don't do that"); */ - /* - * Whenever we create a continuation, all return continuations - * up the call chain may be reused due to invoking the - * continuation. To avoid that all return continuations are - * converted to true continuations. - */ - invalidate_retc_context(INTERP, SELF); } diff --git a/src/pmc/coroutine.pmc b/src/pmc/coroutine.pmc index 513ece3c67..b59fe1a374 100644 --- a/src/pmc/coroutine.pmc +++ b/src/pmc/coroutine.pmc @@ -169,8 +169,10 @@ Swaps the "context". PMC *ctx = Parrot_pcc_get_signature(INTERP, caller_ctx); PMC *ccont = INTERP->current_cont; - if (ccont == NEED_CONTINUATION) - ccont = (PMC *)new_ret_continuation_pmc(INTERP, next_op); + if (ccont == NEED_CONTINUATION) { + ccont = pmc_new(interp, enum_class_Continuation); + VTABLE_set_pointer(interp, ccont, next_op); + } if (PObj_get_FLAGS(ccont) & SUB_FLAG_TAILCALL) Parrot_ex_throw_from_c_args(INTERP, NULL, CONTROL_ERROR, diff --git a/src/pmc/retcontinuation.pmc b/src/pmc/retcontinuation.pmc deleted file mode 100644 index 3ef565b999..0000000000 --- a/src/pmc/retcontinuation.pmc +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright (C) 2001-2008, Parrot Foundation. -$Id$ - -=head1 NAME - -src/pmc/retcontinuation.pmc - Return Continuation - -=head1 DESCRIPTION - -C extends C. - -A return continuation is a one shot Continuation. It gets recycled immediately -after invocation. - -=head2 Methods - -=over 4 - -=cut - -*/ - -#include "parrot/oplib/ops.h" - -/* HEADERIZER HFILE: none */ -/* HEADERIZER BEGIN: static */ -/* HEADERIZER END: static */ - -pmclass RetContinuation extends Continuation auto_attrs { - -/* - -=item C - -Initializes the continuation. - -=cut - -*/ - - VTABLE void init() { - Parrot_RetContinuation_attributes * const attrs = PARROT_RETCONTINUATION(SELF); - - attrs->to_ctx = CURRENT_CONTEXT(interp); - attrs->from_ctx = PMCNULL; /* filled in during a call */ - attrs->runloop_id = 0; - attrs->seg = interp->code; - attrs->address = NULL; - } - - -/* - -=item C - -Return a new Continuation PMC with the context of SELF. Note: the returned -object is not a RetContinuation and creating a real Continuation invalidates -all RetContinuation all the way up the call chain. That is, these can't be -recycled; they persist until the GC gets at them. - -=cut - -*/ - VTABLE PMC *clone() { - invalidate_retc_context(INTERP, SELF); - return SUPER(); - } -/* - -=item C - -Transfers control to the calling context and frees the current context. - -=cut - -*/ - - VTABLE opcode_t *invoke(void *in_next) { - Parrot_Continuation_attributes *data = PARROT_CONTINUATION(SELF); - PMC *from_ctx = data->from_ctx; - PackFile_ByteCode * const seg = data->seg; - opcode_t *next = data->address; - UNUSED(in_next) - - Parrot_continuation_check(interp, SELF); - Parrot_continuation_rewind_environment(interp, SELF); - - /* recycle this PMC and make sure it doesn't get marked */ - if (!PMC_IS_NULL(from_ctx)) - Parrot_pcc_set_continuation(interp, from_ctx, NULL); - - if (INTERP->code != seg) - Parrot_switch_to_cs(INTERP, seg, 1); - - return next; - } -} - - -/* - -=back - -=head1 HISTORY - -Initial revision by sean 2002/08/04. - -=cut - -*/ - -/* - * Local variables: - * c-file-style: "parrot" - * End: - * vim: expandtab shiftwidth=4: - */ diff --git a/src/pmc/sub.pmc b/src/pmc/sub.pmc index bbf8a52696..d872bf8e06 100644 --- a/src/pmc/sub.pmc +++ b/src/pmc/sub.pmc @@ -392,8 +392,10 @@ Invokes the subroutine. pc = sub->seg->base.data + sub->start_offs; INTERP->current_cont = NULL; - if (ccont == NEED_CONTINUATION) - ccont = new_ret_continuation_pmc(interp, (opcode_t *)next); + if (ccont == NEED_CONTINUATION) { + ccont = pmc_new(interp, enum_class_Continuation); + VTABLE_set_pointer(interp, ccont, next); + } PARROT_ASSERT(!PMC_IS_NULL(ccont)); @@ -421,12 +423,9 @@ Invokes the subroutine. PARROT_CONTINUATION(ccont)->from_ctx = context; /* if this is an outer sub, then we need to set sub->ctx - * to the new context (refcounted) and convert the - * retcontinuation to a normal continuation. */ + * to the new context (refcounted) */ if (PObj_get_FLAGS(SELF) & SUB_FLAG_IS_OUTER) { sub->ctx = context; - /* convert retcontinuation to a continuation */ - ccont->vtable = interp->vtables[enum_class_Continuation]; } /* create pad if needed diff --git a/src/sub.c b/src/sub.c index 9c94bf912e..6afb4ae410 100644 --- a/src/sub.c +++ b/src/sub.c @@ -47,60 +47,6 @@ mark_context_start(void) } -/* - -=item C - -Returns a new C PMC, and sets address field to C
- -=cut - -*/ - -PARROT_EXPORT -PARROT_MALLOC -PARROT_CANNOT_RETURN_NULL -PMC * -new_ret_continuation_pmc(PARROT_INTERP, ARGIN_NULLOK(opcode_t *address)) -{ - ASSERT_ARGS(new_ret_continuation_pmc) - PMC* const continuation = Parrot_pmc_new(interp, enum_class_RetContinuation); - VTABLE_set_pointer(interp, continuation, address); - return continuation; -} - -/* - -=item C - -Make true Continuations from all RetContinuations up the call chain. - -=cut - -*/ - -void -invalidate_retc_context(PARROT_INTERP, ARGMOD(PMC *cont)) -{ - ASSERT_ARGS(invalidate_retc_context) - - PMC *ctx = PARROT_CONTINUATION(cont)->from_ctx; - cont = Parrot_pcc_get_continuation(interp, ctx); - - while (1) { - /* - * We stop if we encounter a true continuation, because - * if one were created, everything up the chain would have been - * invalidated earlier. - */ - if (!cont || cont->vtable != interp->vtables[enum_class_RetContinuation]) - break; - cont->vtable = interp->vtables[enum_class_Continuation]; - ctx = Parrot_pcc_get_caller_ctx(interp, ctx); - cont = Parrot_pcc_get_continuation(interp, ctx); - } -} - /* =item C diff --git a/t/native_pbc/annotations.pbc b/t/native_pbc/annotations.pbc index 008f02948cd64438a5b0a051f6e00781d4995d14..ce53dc96b0136f3ee1913fb02d09945b08164553 100644 GIT binary patch delta 134 zcmeys@qt6&Ux1S{FP9V-3j+faGXop@Mge<9M)t`8j555+3=9m6K+FTg@{=nW)ddZK zETBTLs0fhup1hG!oY8RdNk(Z#5L=iNq+S7t P`7BcyguU5<*@6)OhKUv8 delta 134 zcmeys@qt6&Ux1S{FP9V-3j+faGXopjMge<9Mz+ZTj553`3=9m6K+FTg3X>}t)dh`! zETBTLs0fhunY@uvoY83VNk(Z#5L=iNq+S7pCo?h$vw8tp43pxl)dh`! zETBTLs0fhunLLqEoY83VN=9i$5L=iNq+S7pCqHBqX7vKH7$)y!lAbKWq|C&|FwszW IvJcZ001e#|ng9R* diff --git a/t/native_pbc/number_1.pbc b/t/native_pbc/number_1.pbc index 455333e14d3af69612853b8d5341d6947d47c0cb..d12516ff5469bf4dadf9ba30e40721ccfdd7b6ff 100644 GIT binary patch delta 111 zcmZn=Y7i3m7vSW~%O%Cd!oa}9%)rLJQ6Qg%k$rLliwv(a0|Nsi5c2@B{N$A^>Vk$q z7EmErR0K$SPkzWE&S*IKCyO*Ah%L+sQm+8S@{Vif< z7EmErR0K%-On%5B&S*6GCyO*Ah%L+sQm+8QlMPvg8ND{UvaVueWZV3KO@Iji!&eeh diff --git a/t/native_pbc/string_1.pbc b/t/native_pbc/string_1.pbc index ee4065d1f6f1ed9719f2023483a083d60b73dc2e..bb2a9dec9c495f4ea959ee7d6c9c136e2e282fc3 100644 GIT binary patch delta 119 zcmaFB@qk0%Ux1S{FP9V-3j+faGXop@MuGQ?jO>$`WO$Vs7#J9VmjIlQ%L6vw8wq43qCNOHY2nR17jyWO5Gk F7XVZw6e0is delta 119 zcmaFB@qk0%Ux1S{FP9V-3j+faGXopjMuGQ?jBJybWO!8=7#J9Vmc6H!=ycdI4DslkYN1PkzEw3^G(?at`ws E096PSCjbBd diff --git a/t/op/gc.t b/t/op/gc.t index a25dcb26d5..606022a7eb 100755 --- a/t/op/gc.t +++ b/t/op/gc.t @@ -508,7 +508,6 @@ lp: # coro context and invalid return continuations # this is a stripped down version of imcc/t/syn/pcc_16 -# s. also src/pmc/retcontinuation.pmc .sub coro_context_ret_continuation .const 'Sub' $P0 = "co1" diff --git a/t/pmc/retcontinuation.t b/t/pmc/retcontinuation.t deleted file mode 100644 index 1cda48fe68..0000000000 --- a/t/pmc/retcontinuation.t +++ /dev/null @@ -1,32 +0,0 @@ -#! parrot -# Copyright (C) 2006-2008, Parrot Foundation. -# $Id$ - -=head1 NAME - -t/pmc/retcontinuation.t - test the RetContinuation PMC - -=head1 SYNOPSIS - - % prove t/pmc/retcontinuation.t - -=head1 DESCRIPTION - -Tests the RetContinuation PMC. - -=cut - -.sub main :main - .include 'test_more.pir' - - plan(1) - - new $P0, ['RetContinuation'] - ok(1, 'Instantiated a RetContinuation PMC') -.end - -# Local Variables: -# mode: pir -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4 ft=pir: