[svn:parrot] r41244 - in trunk: src/ops src/pmc t/pmc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Sun Sep 13 01:05:36 UTC 2009


Author: NotFound
Date: Sun Sep 13 01:05:35 2009
New Revision: 41244
URL: https://trac.parrot.org/parrot/changeset/41244

Log:
[core] signal when invoke is used for a yield operation, TT #1003

Modified:
   trunk/src/ops/core.ops
   trunk/src/pmc/coroutine.pmc
   trunk/t/pmc/coroutine.t

Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops	Sat Sep 12 21:22:37 2009	(r41243)
+++ trunk/src/ops/core.ops	Sun Sep 13 01:05:35 2009	(r41244)
@@ -448,6 +448,7 @@
 inline op yield() :flow {
     opcode_t *dest = expr NEXT();
     PMC * const p = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
+    p->vtable->increment(interp, p);
     dest = (opcode_t *)p->vtable->invoke(interp, p, dest);
     goto ADDRESS(dest);
 }

Modified: trunk/src/pmc/coroutine.pmc
==============================================================================
--- trunk/src/pmc/coroutine.pmc	Sat Sep 12 21:22:37 2009	(r41243)
+++ trunk/src/pmc/coroutine.pmc	Sun Sep 13 01:05:35 2009	(r41244)
@@ -57,8 +57,9 @@
 }
 
 pmclass Coroutine extends Sub auto_attrs {
-    ATTR PackFile_ByteCode *caller_seg;  /* bytecode segment */
-    ATTR opcode_t *address;           /* next address to run - toggled each time */
+    ATTR PackFile_ByteCode *caller_seg; /* bytecode segment */
+    ATTR opcode_t *address;             /* next address to run - toggled each time */
+    ATTR INTVAL yield;                  /* yield in process */
 
 /*
 
@@ -110,6 +111,20 @@
 
 /*
 
+=item C<void increment()>
+
+Signals the start of a yield.
+
+=cut
+
+*/
+
+    VTABLE void increment () {
+        SET_ATTR_yield(INTERP, SELF, 1);
+    }
+
+/*
+
 =item C<opcode_t *invoke(void *next)>
 
 Swaps the "context".
@@ -186,6 +201,12 @@
         else {
             PMC * const ccont = Parrot_pcc_get_continuation(INTERP, co->ctx);
             PMC * const ctx   = PARROT_CONTINUATION(ccont)->to_ctx;
+            INTVAL yield;
+            GET_ATTR_yield(INTERP, SELF, yield);
+            if (! yield)
+                Parrot_ex_throw_from_c_args(INTERP, NULL, CONTROL_ERROR,
+                               "Cannot resume dead coroutine.");
+            SET_ATTR_yield(INTERP, SELF, 0);
 
             PObj_get_FLAGS(SELF) &= ~SUB_FLAG_CORO_FF;
             /* switch back to last remembered code seg and context */
@@ -197,7 +218,8 @@
                    the "Call an exited coroutine" case in t/pmc/coroutine.t; the
                    problem is that the defunct coroutine yields up one more
                    result before we get here.  -- rgr, 7-Oct-06.
-                */
+                 * This may be unneeded after the yield fix, see TT #1003
+                 */
                 Parrot_ex_throw_from_c_args(INTERP, NULL, CONTROL_ERROR,
                                "Cannot resume dead coroutine.");
             }

Modified: trunk/t/pmc/coroutine.t
==============================================================================
--- trunk/t/pmc/coroutine.t	Sat Sep 12 21:22:37 2009	(r41243)
+++ trunk/t/pmc/coroutine.t	Sun Sep 13 01:05:35 2009	(r41244)
@@ -308,7 +308,7 @@
 CODE
 
 pir_output_like(
-    <<'CODE', <<'OUTPUT', "Call an exited coroutine", todo => 'goes one iteration too far.' );
+    <<'CODE', <<'OUTPUT', "Call an exited coroutine", todo => 'goes one iteration too far TT #1003' );
 .sub main :main
     .local pmc c
     c = get_global "coro"


More information about the parrot-commits mailing list