[svn:parrot] r41039 - in trunk: include/parrot lib/Parrot/Pmc2c src src/call src/ops src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Sep 6 05:32:51 UTC 2009


Author: bacek
Date: Sun Sep  6 05:32:49 2009
New Revision: 41039
URL: https://trac.parrot.org/parrot/changeset/41039

Log:
Merge kill_parrot_cont branch into trunk.

Modified:
   trunk/include/parrot/sub.h
   trunk/lib/Parrot/Pmc2c/PCCMETHOD.pm
   trunk/src/call/ops.c
   trunk/src/call/pcc.c
   trunk/src/debug.c
   trunk/src/exceptions.c
   trunk/src/ops/core.ops
   trunk/src/ops/pic.ops
   trunk/src/pmc/continuation.pmc
   trunk/src/pmc/coroutine.pmc
   trunk/src/pmc/exception.pmc
   trunk/src/pmc/exceptionhandler.pmc
   trunk/src/pmc/parrotinterpreter.pmc
   trunk/src/pmc/retcontinuation.pmc
   trunk/src/pmc/sub.pmc
   trunk/src/sub.c

Modified: trunk/include/parrot/sub.h
==============================================================================
--- trunk/include/parrot/sub.h	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/include/parrot/sub.h	Sun Sep  6 05:32:49 2009	(r41039)
@@ -152,21 +152,9 @@
 
 typedef struct Parrot_Sub_attributes Parrot_sub;
 typedef struct Parrot_Coroutine_attributes Parrot_coro;
+typedef struct Parrot_Continuation_attributes Parrot_cont;
 
-typedef struct Parrot_cont {
-    /* continuation destination */
-    PackFile_ByteCode   *seg;               /* bytecode segment */
-    opcode_t            *address;           /* start of bytecode, addr to continue */
-    PMC                 *to_ctx;            /* pointer to dest context */
-    /* a Continuation keeps the from_ctx alive */
-    PMC                 *from_ctx;          /* sub, this cont is returning from */
-    opcode_t            *current_results;   /* ptr into code with get_results opcode
-                                        full continuation only */
-    int runloop_id;                  /* id of the creating runloop. */
-    int invoked;                     /* flag when a handler has been invoked. */
-} Parrot_cont;
-
-#define PMC_cont(pmc) (PARROT_CONTINUATION(pmc)->cont)
+#define PMC_cont(pmc) PARROT_CONTINUATION(pmc)
 
 typedef struct Parrot_Context_info {
     STRING   *subname;
@@ -229,33 +217,26 @@
         FUNC_MODIFIES(*cont);
 
 void mark_context_start(void);
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-Parrot_cont * new_continuation(PARROT_INTERP,
-    ARGIN_NULLOK(const Parrot_cont *to))
-        __attribute__nonnull__(1);
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-Parrot_cont * new_ret_continuation(PARROT_INTERP)
-        __attribute__nonnull__(1);
-
 void Parrot_capture_lex(PARROT_INTERP, ARGMOD(PMC *sub_pmc))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*sub_pmc);
 
-void Parrot_continuation_check(PARROT_INTERP,
-    ARGIN(const PMC *pmc),
-    ARGIN(const Parrot_cont *cc))
+void Parrot_continuation_check(PARROT_INTERP, ARGIN(const PMC *pmc))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
+        __attribute__nonnull__(2);
 
-void Parrot_continuation_rewind_environment(PARROT_INTERP,
-    SHIM(PMC *pmc),
-    ARGIN(Parrot_cont *cc))
+void Parrot_continuation_rewind_environment(PARROT_INTERP, ARGIN(PMC *pmc))
         __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+PARROT_CAN_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PMC* Parrot_find_dynamic_pad(PARROT_INTERP,
+    ARGIN(STRING *lex_name),
+    ARGIN(PMC *ctx))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
         __attribute__nonnull__(3);
 
 PARROT_CAN_RETURN_NULL
@@ -298,21 +279,16 @@
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(cont)
 #define ASSERT_ARGS_mark_context_start __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
-#define ASSERT_ARGS_new_continuation __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_new_ret_continuation __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)
 #define ASSERT_ARGS_Parrot_continuation_check __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(pmc) \
-    || PARROT_ASSERT_ARG(cc)
+    || PARROT_ASSERT_ARG(pmc)
 #define ASSERT_ARGS_Parrot_continuation_rewind_environment \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(cc)
+    || PARROT_ASSERT_ARG(pmc)
 #define ASSERT_ARGS_Parrot_find_dynamic_pad __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(lex_name) \

Modified: trunk/lib/Parrot/Pmc2c/PCCMETHOD.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/PCCMETHOD.pm	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/lib/Parrot/Pmc2c/PCCMETHOD.pm	Sun Sep  6 05:32:49 2009	(r41039)
@@ -412,7 +412,7 @@
     }
 
     Parrot_pcc_set_continuation(interp, _ctx, _ret_cont);
-    PMC_cont(_ret_cont)->from_ctx       = _ctx;
+    PARROT_CONTINUATION(_ret_cont)->from_ctx       = _ctx;
 
     _current_args                       = interp->current_args;
     interp->current_args                = NULL;

Modified: trunk/src/call/ops.c
==============================================================================
--- trunk/src/call/ops.c	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/call/ops.c	Sun Sep  6 05:32:49 2009	(r41039)
@@ -251,7 +251,7 @@
 
     if (*sig_p && (dest[0]     == PARROT_OP_get_params_pc
     || (sub->vtable->base_type == enum_class_ExceptionHandler
-    &&  PMC_cont(sub)->current_results))) {
+    &&  PARROT_CONTINUATION(sub)->current_results))) {
         dest = parrot_pass_args_fromc(interp, sig_p, dest, old_ctx, ap);
     }
 

Modified: trunk/src/call/pcc.c
==============================================================================
--- trunk/src/call/pcc.c	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/call/pcc.c	Sun Sep  6 05:32:49 2009	(r41039)
@@ -511,7 +511,7 @@
     /* if this NCI call was a taicall, return results to caller's get_results
      * this also means that we pass the caller's register base pointer */
     if (SUB_FLAG_TAILCALL_ISSET(current_cont))
-        ctx = PMC_cont(current_cont)->to_ctx;
+        ctx = PARROT_CONTINUATION(current_cont)->to_ctx;
 
     /* TODO simplify all */
     Parrot_init_arg_sig(interp, CURRENT_CONTEXT(interp), sig, NULL, &st->src);

Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/debug.c	Sun Sep  6 05:32:49 2009	(r41039)
@@ -3554,13 +3554,13 @@
 
     /* backtrace: follow the continuation chain */
     while (1) {
-        Parrot_cont *sub_cont;
+        Parrot_Continuation_attributes *sub_cont;
         sub = Parrot_pcc_get_continuation(interp, ctx);
 
         if (PMC_IS_NULL(sub))
             break;
 
-        sub_cont = PMC_cont(sub);
+        sub_cont = PARROT_CONTINUATION(sub);
 
         if (!sub_cont)
             break;
@@ -3607,7 +3607,7 @@
         }
 
         /* get the next Continuation */
-        ctx = PMC_cont(sub)->to_ctx;
+        ctx = PARROT_CONTINUATION(sub)->to_ctx;
         old = sub;
 
         if (!ctx)

Modified: trunk/src/exceptions.c
==============================================================================
--- trunk/src/exceptions.c	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/exceptions.c	Sun Sep  6 05:32:49 2009	(r41039)
@@ -251,7 +251,7 @@
            passed properly. */
     }
     /* Set up the continuation context of the handler in the interpreter. */
-    else if (PMC_cont(handler)->current_results)
+    else if (PARROT_CONTINUATION(handler)->current_results)
         address = pass_exception_args(interp, "P", address,
                 CURRENT_CONTEXT(interp), exception);
 
@@ -401,7 +401,7 @@
 
     /* Run the handler. */
     address = VTABLE_invoke(interp, handler, NULL);
-    if (PMC_cont(handler)->current_results)
+    if (PARROT_CONTINUATION(handler)->current_results)
         address = pass_exception_args(interp, "P", address,
                 CURRENT_CONTEXT(interp), exception);
     PARROT_ASSERT(return_point->handler_start == NULL);

Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/ops/core.ops	Sun Sep  6 05:32:49 2009	(r41039)
@@ -577,7 +577,7 @@
     caller_ctx              = Parrot_pcc_get_caller_ctx(interp, ctx);
     ccont                   = Parrot_pcc_get_continuation(interp, ctx);
 
-    if (PMC_cont(ccont)->address) {
+    if (PARROT_CONTINUATION(ccont)->address) {
         /* Call is from runops_fromc */
         caller_ctx = PMC_cont(ccont)->to_ctx;
         if (PMC_IS_NULL(caller_ctx)) {
@@ -616,12 +616,12 @@
     /* Get context of callee from return continuation. */
     PMC * const cc = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp));
     PMC *sig = NULL;
-    if (cc && PMC_cont(cc)->to_ctx) {
+    if (cc && PARROT_CONTINUATION(cc)->to_ctx) {
         /* caller context has results */
         opcode_t * const results = Parrot_pcc_get_results(interp, PMC_cont(cc)->to_ctx);
         if (results) {
             /* get results PMC index and get PMC. */
-            sig = PF_CONST(PMC_cont(cc)->seg, results[1])->u.key;
+            sig = PF_CONST(PARROT_CONTINUATION(cc)->seg, results[1])->u.key;
         }
     }
 

Modified: trunk/src/ops/pic.ops
==============================================================================
--- trunk/src/ops/pic.ops	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/ops/pic.ops	Sun Sep  6 05:32:49 2009	(r41039)
@@ -184,7 +184,7 @@
     opcode_t *dest_pc;
     void **dest_pred;
     PMC *caller_ctx, *ctx;
-    Parrot_cont *cc;
+    Parrot_Continuation_attributes *cc;
     int n;
 
     ctx     = CURRENT_CONTEXT(interp);

Modified: trunk/src/pmc/continuation.pmc
==============================================================================
--- trunk/src/pmc/continuation.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/continuation.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -46,8 +46,16 @@
  */
 
 pmclass Continuation auto_attrs {
-    ATTR struct Parrot_cont *cont; /* the continuation struct */
-
+    /* continuation destination */
+    ATTR PackFile_ByteCode *seg;          /* bytecode segment */
+    ATTR opcode_t *address;               /* start of bytecode, addr to continue */
+    ATTR PMC *to_ctx;   /* pointer to dest context */
+    /* a Continuation keeps the from_ctx alive */
+    ATTR PMC *from_ctx; /* sub, this cont is returning from */
+    ATTR opcode_t *current_results;       /* ptr into code with get_results opcode
+                                        full continuation only */
+    ATTR int runloop_id;                  /* id of the creating runloop. */
+    ATTR int invoked;                     /* flag when a handler has been invoked. */
 /*
 
 =item C<void init()>
@@ -59,11 +67,18 @@
 */
 
     VTABLE void init() {
-        Parrot_Continuation_attributes *attrs =
-            (Parrot_Continuation_attributes *) PMC_data(SELF);
+        Parrot_Continuation_attributes *attrs = PARROT_CONTINUATION(SELF);
+
+        attrs->to_ctx     = CURRENT_CONTEXT(interp);
+        attrs->from_ctx   = CURRENT_CONTEXT(interp);
+        attrs->runloop_id = 0;
+        attrs->seg        = interp->code;
+        attrs->address    = NULL;
+        attrs->current_results = Parrot_pcc_get_results(interp, attrs->to_ctx);
 
-        PMC_cont(SELF) = new_continuation(INTERP, NULL);
+        PObj_active_destroy_SET(SELF);
         PObj_custom_mark_destroy_SETALL(SELF);
+
         /* PANIC("don't do that"); */
         /*
          * Whenever we create a continuation, all return continuations
@@ -74,6 +89,32 @@
         invalidate_retc_context(INTERP, SELF);
     }
 
+    /*if they pass in a PMC to initialize with*/
+    VTABLE void init_pmc(PMC *values) {
+        Parrot_Continuation_attributes *attrs = PARROT_CONTINUATION(SELF);
+
+        attrs->to_ctx     = PARROT_CONTINUATION(values)->to_ctx;
+        attrs->from_ctx   = CURRENT_CONTEXT(interp);
+        attrs->runloop_id = 0;
+        attrs->seg        = PARROT_CONTINUATION(values)->seg;
+        attrs->address    = PARROT_CONTINUATION(values)->address;
+        attrs->current_results = Parrot_pcc_get_results(interp, attrs->to_ctx);
+
+        PObj_active_destroy_SET(SELF);
+        PObj_custom_mark_destroy_SETALL(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);
+    }
+
+
+
 /*
 
 =item C<void mark()>
@@ -85,7 +126,10 @@
 */
 
     VTABLE void mark() {
-        Parrot_cont *cc = PMC_cont(SELF);
+        Parrot_Continuation_attributes *cc = PARROT_CONTINUATION(SELF);
+
+        if (cc->seg)
+            Parrot_gc_mark_PObj_alive(interp, (PObj *)cc->seg);
 
         if (cc->to_ctx)
             Parrot_gc_mark_PObj_alive(INTERP, (PObj *) cc->to_ctx);
@@ -104,9 +148,6 @@
 */
 
     VTABLE void destroy() {
-        Parrot_cont * const cc = PMC_cont(SELF);
-        if (cc)
-            mem_sys_free(cc);
     }
 /*
 
@@ -119,20 +160,7 @@
 */
 
     VTABLE PMC *clone() {
-        Parrot_cont * const cc_self  = PMC_cont(SELF);
-        Parrot_cont * const cc       = new_continuation(INTERP, cc_self);
-        PMC         * const ret      = pmc_new(INTERP, enum_class_Continuation);
-        Parrot_cont * const ret_cont = PMC_cont(ret);
-
-        PObj_custom_mark_destroy_SETALL(ret);
-
-        /* free ret's PMC_cont */
-        /* XXX Looks very suspicious... Why? */
-        mem_sys_free(ret_cont);
-
-        cc->runloop_id = cc_self->runloop_id;
-        PMC_cont(ret)  = cc;
-
+        PMC         * ret      = pmc_new_init(interp, enum_class_Continuation, SELF);
         return ret;
     }
 
@@ -146,8 +174,8 @@
 
 */
     VTABLE void set_pmc(PMC *src) {
-        Parrot_cont * const cc_self = PMC_cont(SELF);
-        Parrot_cont * const cc_src  = PMC_cont(src);
+        Parrot_Continuation_attributes * const cc_self = PARROT_CONTINUATION(SELF);
+        Parrot_Continuation_attributes * const cc_src  = PARROT_CONTINUATION(src);
 
         STRUCT_COPY(cc_self, cc_src);
     }
@@ -164,7 +192,7 @@
 
     VTABLE void set_pointer(void *value) {
         opcode_t    * const pos = (opcode_t *)value;
-        Parrot_cont * const cc  = PMC_cont(SELF);
+        Parrot_Continuation_attributes * const cc  = PARROT_CONTINUATION(SELF);
 
         cc->address       = (opcode_t *)value;
         cc->runloop_id    = INTERP->current_runloop_id;
@@ -186,7 +214,7 @@
 */
 
     VTABLE void *get_pointer() {
-        return PMC_cont(SELF)->address;
+        return PARROT_CONTINUATION(SELF)->address;
     }
 /*
 
@@ -201,11 +229,11 @@
 */
 
     VTABLE INTVAL defined() {
-        return PMC_cont(SELF)->address != NULL;
+        return PARROT_CONTINUATION(SELF)->address != NULL;
     }
 
     VTABLE INTVAL get_bool() {
-        return PMC_cont(SELF)->address != NULL;
+        return PARROT_CONTINUATION(SELF)->address != NULL;
     }
 
 /*
@@ -226,8 +254,8 @@
         opcode_t    *pc           = cc->address;
         UNUSED(next)
 
-        Parrot_continuation_check(interp, SELF, cc);
-        Parrot_continuation_rewind_environment(interp, SELF, cc);
+        Parrot_continuation_check(interp, SELF);
+        Parrot_continuation_rewind_environment(interp, SELF);
 
         /* pass args to where caller wants result */
         if (cc->current_results)
@@ -254,8 +282,8 @@
         /* switch segment */
         INTERP->current_args = NULL;
 
-        if (INTERP->code != cc->seg)
-            Parrot_switch_to_cs(INTERP, cc->seg, 1);
+        if (INTERP->code != PARROT_CONTINUATION(SELF)->seg)
+            Parrot_switch_to_cs(INTERP, PARROT_CONTINUATION(SELF)->seg, 1);
 
         return pc;
     }
@@ -271,7 +299,7 @@
 */
 
     VTABLE STRING *get_string() {
-        return Parrot_Context_infostr(INTERP, PMC_cont(SELF)->to_ctx);
+        return Parrot_Context_infostr(INTERP, PARROT_CONTINUATION(SELF)->to_ctx);
     }
 
 /*
@@ -285,7 +313,7 @@
 */
 
     METHOD caller() {
-        Parrot_cont *cc     = PMC_cont(SELF);
+        Parrot_Continuation_attributes *cc     = PARROT_CONTINUATION(SELF);
         PMC         *caller = Parrot_pcc_get_sub(interp, cc->to_ctx);
         Parrot_Sub_attributes  *sub;
 
@@ -311,7 +339,7 @@
 */
 
     METHOD continuation() {
-        Parrot_cont *cc   = PMC_cont(SELF);
+        Parrot_Continuation_attributes *cc   = PARROT_CONTINUATION(SELF);
         PMC         *cont = Parrot_pcc_get_continuation(interp, cc->to_ctx);
 
         if (cont)

Modified: trunk/src/pmc/coroutine.pmc
==============================================================================
--- trunk/src/pmc/coroutine.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/coroutine.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -149,7 +149,7 @@
             co->ctx                   = ctx;
 
             Parrot_pcc_set_caller_ctx(INTERP, ctx, caller_ctx);
-            PMC_cont(ccont)->from_ctx                       = ctx;
+            PARROT_CONTINUATION(ccont)->from_ctx = ctx;
             Parrot_pcc_set_sub(INTERP, ctx, SELF);
             Parrot_pcc_set_HLL(interp, ctx, co->HLL_id);
             Parrot_pcc_set_namespace(INTERP, ctx, co->namespace_stash);
@@ -201,7 +201,7 @@
 
             wanted_seg            = co->caller_seg;
             ccont                 = Parrot_pcc_get_continuation(INTERP, co->ctx);
-            ctx                   = PMC_cont(ccont)->to_ctx;
+            ctx                   = PARROT_CONTINUATION(ccont)->to_ctx;
 
             if (! ctx) {
                 /* This still isn't quite right, but it beats segfaulting.  See

Modified: trunk/src/pmc/exception.pmc
==============================================================================
--- trunk/src/pmc/exception.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/exception.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -645,9 +645,8 @@
              * XXX TT#596 - when we have Context PMCs, just take and set that. */
             if (!PMC_IS_NULL(value) && VTABLE_isa(interp, value, CONST_STRING(interp, "Continuation"))) {
                 PMC *ctx = PMC_cont(value)->from_ctx;
-                if (!PMC_IS_NULL(ctx)) {
+                if (!PMC_IS_NULL(ctx))
                     SET_ATTR_thrower(interp, SELF, ctx);
-                }
             }
         }
         else {
@@ -710,7 +709,7 @@
         /* Get resume continuation, to find location we failed at. */
         GET_ATTR_resume(interp, SELF, resume);
         if (!PMC_IS_NULL(resume)) {
-            Parrot_cont *cont = PMC_cont(resume);
+            Parrot_Continuation_attributes *cont = PARROT_CONTINUATION(resume);
             if (cont->seg != NULL && cont->seg->annotations != NULL)
                 result = PackFile_Annotations_lookup(interp, cont->seg->annotations,
                         cont->address - cont->seg->base.data, name);
@@ -744,14 +743,14 @@
         PMC *result = pmc_new(interp, enum_class_ResizablePMCArray);
         PMC *resume;
         PMC *cur_ctx;
-        Parrot_cont    *cont;
+        Parrot_Continuation_attributes    *cont;
 
         /* Get starting context, then loop over them. */
         GET_ATTR_resume(interp, SELF, resume);
         if (!PMC_IS_NULL(resume)) {
             /* We have a resume continuation, so we can get the address from
              * that. */
-            cont    = PMC_cont(resume);
+            cont    = PARROT_CONTINUATION(resume);
             cur_ctx = cont->to_ctx;
         }
         else {

Modified: trunk/src/pmc/exceptionhandler.pmc
==============================================================================
--- trunk/src/pmc/exceptionhandler.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/exceptionhandler.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -40,23 +40,20 @@
 */
 
     VTABLE void init() {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
             (Parrot_ExceptionHandler_attributes *)PMC_data(SELF);
-        Parrot_cont * const cc     = new_continuation(INTERP, NULL);
-
-        cc->invoked                = 0;
-        PMC_cont(SELF)             = cc;
-        core_struct->min_severity  = 0;
-        core_struct->max_severity  = 0;
-        core_struct->handled_types = PMCNULL;
-        core_struct->handled_types_except = PMCNULL;
+        SUPER();
+        attrs->invoked      = 0;
+        attrs->min_severity  = 0;
+        attrs->max_severity  = 0;
+        attrs->handled_types = PMCNULL;
+        attrs->handled_types_except = PMCNULL;
 
         /* an exception handler has no separate context; it's only a snapshot
          * of an "earlier" context, which is contained in the interpreter's
          * context - the stacks can only be deeper in the interpreter - so no
          * mark of context is needed */
-        PObj_custom_mark_SET(SELF);
-        PObj_custom_destroy_SET(SELF);
+        PObj_custom_mark_destroy_SETALL(SELF);
     }
 /*
 
@@ -69,12 +66,25 @@
 */
 
     VTABLE void mark() {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
             PARROT_EXCEPTIONHANDLER(SELF);
-        if (core_struct->handled_types)
-            Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->handled_types);
-        if (core_struct->handled_types_except)
-            Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->handled_types_except);
+        if (attrs->handled_types)
+            Parrot_gc_mark_PObj_alive(interp, (PObj *)attrs->handled_types);
+        if (attrs->handled_types_except)
+            Parrot_gc_mark_PObj_alive(interp, (PObj *)attrs->handled_types_except);
+        SUPER();
+    }
+
+    VTABLE void destroy(){
+
+        Parrot_ExceptionHandler_attributes *attrs = PARROT_EXCEPTIONHANDLER(SELF);
+
+        if (attrs->handled_types){
+            PObj_on_free_list_SET((PObj *) attrs->handled_types);
+        }
+        if (attrs->handled_types_except){
+            PObj_on_free_list_SET((PObj *) attrs->handled_types_except);
+        }
         SUPER();
     }
 
@@ -95,8 +105,7 @@
 */
 
     VTABLE void set_integer_native(INTVAL value) {
-        Parrot_cont * const cc = (Parrot_cont *)PMC_cont(SELF);
-        cc->invoked = value;
+        PARROT_CONTINUATION(SELF)->invoked = value;
     }
 
 /*
@@ -110,8 +119,7 @@
 */
 
     VTABLE INTVAL get_integer() {
-        const Parrot_cont * const cc = (Parrot_cont *)PMC_cont(SELF);
-        return cc->invoked;
+        return PARROT_CONTINUATION(SELF)->invoked;
     }
 
 /*
@@ -125,15 +133,14 @@
 */
 
     VTABLE opcode_t *invoke(void *next) {
-        Parrot_cont * const cc = (Parrot_cont *)PMC_cont(SELF);
-        opcode_t    * const pc = cc->address;
+        opcode_t    * const pc = PARROT_CONTINUATION(SELF)->address;
 
-        Parrot_continuation_check(interp, SELF, cc);
-        Parrot_continuation_rewind_environment(interp, SELF, cc);
+        Parrot_continuation_check(interp, SELF);
+        Parrot_continuation_rewind_environment(interp, SELF);
 
         /* switch code segment if needed */
-        if (INTERP->code != cc->seg)
-            Parrot_switch_to_cs(INTERP, cc->seg, 1);
+        if (INTERP->code != PARROT_CONTINUATION(SELF)->seg)
+            Parrot_switch_to_cs(INTERP, PARROT_CONTINUATION(SELF)->seg, 1);
 
         return pc;
     }
@@ -232,13 +239,13 @@
 */
 
     METHOD min_severity(INTVAL severity :optional, INTVAL have_severity :opt_flag) {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
                     PARROT_EXCEPTIONHANDLER(SELF);
 
         if (have_severity)
-            core_struct->min_severity = severity;
+            attrs->min_severity = severity;
         else
-            severity = core_struct->min_severity;
+            severity = attrs->min_severity;
 
         RETURN(INTVAL severity);
     }
@@ -254,13 +261,13 @@
 */
 
     METHOD max_severity(INTVAL severity :optional, INTVAL have_severity :opt_flag) {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
                     PARROT_EXCEPTIONHANDLER(SELF);
 
         if (have_severity)
-            core_struct->max_severity = severity;
+            attrs->max_severity = severity;
         else
-            severity = core_struct->max_severity;
+            severity = attrs->max_severity;
 
         RETURN(INTVAL severity);
     }
@@ -276,9 +283,9 @@
 */
 
     METHOD handle_types(PMC *types :slurpy) {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
                     PARROT_EXCEPTIONHANDLER(SELF);
-        core_struct->handled_types =
+        attrs->handled_types =
             VTABLE_elements(interp, types) > 0
                 ? types
                 : PMCNULL;
@@ -295,9 +302,9 @@
 */
 
     METHOD handle_types_except(PMC *types :slurpy) {
-        Parrot_ExceptionHandler_attributes * const core_struct =
+        Parrot_ExceptionHandler_attributes * const attrs =
                     PARROT_EXCEPTIONHANDLER(SELF);
-        core_struct->handled_types_except =
+        attrs->handled_types_except =
             VTABLE_elements(interp, types) > 0
                 ? types
                 : PMCNULL;

Modified: trunk/src/pmc/parrotinterpreter.pmc
==============================================================================
--- trunk/src/pmc/parrotinterpreter.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/parrotinterpreter.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -492,11 +492,11 @@
             for (; level; --level) {
                 cont = Parrot_pcc_get_continuation(interp, ctx);
 
-                if (PMC_IS_NULL(cont) || !PMC_cont(cont)->seg)
+                if (PMC_IS_NULL(cont) || !PARROT_CONTINUATION(cont)->seg)
                     Parrot_ex_throw_from_c_args(interp, NULL,
                         CONTROL_ERROR, "No such caller depth");
 
-                ctx = PMC_cont(cont)->to_ctx;
+                ctx = PARROT_CONTINUATION(cont)->to_ctx;
 
                 if (PMC_IS_NULL(Parrot_pcc_get_sub(interp, ctx)))
                     Parrot_ex_throw_from_c_args(interp, NULL,

Modified: trunk/src/pmc/retcontinuation.pmc
==============================================================================
--- trunk/src/pmc/retcontinuation.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/retcontinuation.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -36,24 +36,18 @@
 */
 
     VTABLE void init() {
-        Parrot_RetContinuation_attributes * const attrs =
-            (Parrot_RetContinuation_attributes *) PMC_data(SELF);
-        PMC_cont(SELF) = new_ret_continuation(INTERP);
+        Parrot_RetContinuation_attributes * const attrs = PARROT_RETCONTINUATION(SELF);
 
-        PObj_custom_mark_destroy_SETALL(SELF);
-    }
+        attrs->to_ctx          = CURRENT_CONTEXT(interp);
+        attrs->from_ctx        = CURRENT_CONTEXT(interp);    /* filled in during a call */
+        attrs->runloop_id      = 0;
+        attrs->seg             = interp->code;
+        attrs->current_results = NULL;
+        attrs->address         = NULL;
 
-    /*
-     * XXX when reusing SUPER.destroy() RetContinuations
-     *     have to set ref_count initially to 1
-     */
+    }
 
-    VTABLE void destroy() {
-        Parrot_cont * const cc = PMC_cont(SELF);
 
-        if (cc)
-            mem_sys_free(cc);
-    }
 /*
 
 =item C<PMC *clone>
@@ -81,14 +75,13 @@
 */
 
     VTABLE opcode_t *invoke(void *in_next) {
-        Parrot_cont       *cc         = PMC_cont(SELF);
-        PMC               *from_ctx   = cc->from_ctx;
-        PackFile_ByteCode * const seg = cc->seg;
-        opcode_t          *next       = cc->address;
+        PMC               *from_ctx   = PARROT_CONTINUATION(SELF)->from_ctx;
+        PackFile_ByteCode * const seg = PARROT_CONTINUATION(SELF)->seg;
+        opcode_t          *next       = PARROT_CONTINUATION(SELF)->address;
         UNUSED(in_next)
 
-        Parrot_continuation_check(interp, SELF, cc);
-        Parrot_continuation_rewind_environment(interp, SELF, cc);
+        Parrot_continuation_check(interp, SELF);
+        Parrot_continuation_rewind_environment(interp, SELF);
 
         /* the continuation is dead - delete and destroy it */
         /* This line causes a failure in t/pmc/packfiledirectory.t. No idea

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/pmc/sub.pmc	Sun Sep  6 05:32:49 2009	(r41039)
@@ -288,7 +288,7 @@
                     "maximum recursion depth exceeded");
 
         /* and copy set context variables */
-        PMC_cont(ccont)->from_ctx = context;
+        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

Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c	Sun Sep  6 04:54:17 2009	(r41038)
+++ trunk/src/sub.c	Sun Sep  6 05:32:49 2009	(r41039)
@@ -49,74 +49,9 @@
 
 /*
 
-=item C<Parrot_cont * new_continuation(PARROT_INTERP, const Parrot_cont *to)>
-
-Returns a new C<Parrot_cont> to the context of C<to> with its own copy of the
-current interpreter context.  If C<to> is C<NULL>, then the C<to_ctx> is set
-to the current context.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-Parrot_cont *
-new_continuation(PARROT_INTERP, ARGIN_NULLOK(const Parrot_cont *to))
-{
-    ASSERT_ARGS(new_continuation)
-    Parrot_cont    * const cc     = mem_allocate_typed(Parrot_cont);
-    PMC            * const to_ctx = to ? to->to_ctx : CURRENT_CONTEXT(interp);
-
-    cc->to_ctx        = to_ctx;
-    cc->from_ctx      = CURRENT_CONTEXT(interp);
-    cc->runloop_id    = 0;
-    if (to) {
-        cc->seg       = to->seg;
-        cc->address   = to->address;
-    }
-    else {
-        cc->seg       = interp->code;
-        cc->address   = NULL;
-    }
-
-    cc->current_results = Parrot_pcc_get_results(interp, to_ctx);
-    return cc;
-}
-
-/*
-
-=item C<Parrot_cont * new_ret_continuation(PARROT_INTERP)>
-
-Returns a new C<Parrot_cont> pointing to the current context.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-Parrot_cont *
-new_ret_continuation(PARROT_INTERP)
-{
-    ASSERT_ARGS(new_ret_continuation)
-    Parrot_cont * const cc = mem_allocate_typed(Parrot_cont);
-
-    cc->to_ctx          = CURRENT_CONTEXT(interp);
-    cc->from_ctx        = CURRENT_CONTEXT(interp);    /* filled in during a call */
-    cc->runloop_id      = 0;
-    cc->seg             = interp->code;
-    cc->current_results = NULL;
-    cc->address         = NULL;
-    return cc;
-}
-
-/*
-
 =item C<PMC * new_ret_continuation_pmc(PARROT_INTERP, opcode_t *address)>
 
-Returns a new C<RetContinuation> PMC. Uses one from the cache,
-if possible; otherwise, creates a new one.
+Returns a new C<RetContinuation> PMC, and sets address field to C<address>
 
 =cut
 
@@ -148,7 +83,8 @@
 invalidate_retc_context(PARROT_INTERP, ARGMOD(PMC *cont))
 {
     ASSERT_ARGS(invalidate_retc_context)
-    PMC *ctx = PMC_cont(cont)->from_ctx;
+
+    PMC *ctx = PARROT_CONTINUATION(cont)->from_ctx;
     cont = Parrot_pcc_get_continuation(interp, ctx);
 
     while (1) {
@@ -522,8 +458,7 @@
 
 /*
 
-=item C<void Parrot_continuation_check(PARROT_INTERP, const PMC *pmc, const
-Parrot_cont *cc)>
+=item C<void Parrot_continuation_check(PARROT_INTERP, const PMC *pmc)>
 
 Verifies that the provided continuation is sane.
 
@@ -532,11 +467,11 @@
 */
 
 void
-Parrot_continuation_check(PARROT_INTERP, ARGIN(const PMC *pmc),
-    ARGIN(const Parrot_cont *cc))
+Parrot_continuation_check(PARROT_INTERP, ARGIN(const PMC *pmc))
 {
     ASSERT_ARGS(Parrot_continuation_check)
-    PMC *to_ctx       = cc->to_ctx;
+
+    PMC *to_ctx       = PARROT_CONTINUATION(pmc)->to_ctx;
     PMC *from_ctx     = CURRENT_CONTEXT(interp);
 
     if (PMC_IS_NULL(to_ctx))
@@ -547,8 +482,7 @@
 
 /*
 
-=item C<void Parrot_continuation_rewind_environment(PARROT_INTERP, PMC *pmc,
-Parrot_cont *cc)>
+=item C<void Parrot_continuation_rewind_environment(PARROT_INTERP, PMC *pmc)>
 
 Restores the appropriate context for the continuation.
 
@@ -557,11 +491,11 @@
 */
 
 void
-Parrot_continuation_rewind_environment(PARROT_INTERP, SHIM(PMC *pmc),
-        ARGIN(Parrot_cont *cc))
+Parrot_continuation_rewind_environment(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_continuation_rewind_environment)
-    PMC * const to_ctx = cc->to_ctx;
+
+    PMC * const to_ctx = PARROT_CONTINUATION(pmc)->to_ctx;
 
     /* debug print before context is switched */
     if (Interp_trace_TEST(interp, PARROT_TRACE_SUB_CALL_FLAG)) {


More information about the parrot-commits mailing list