Author: leo
Date: Mon Jan 30 05:39:39 2006
New Revision: 11379

Modified:
   trunk/src/pmc/continuation.pmc
   trunk/src/pmc/exception_handler.pmc
   trunk/t/op/calling.t
Log:
[perl #38348] [PATCH] Accept return values via a Continuation 

   It seems that Continuation needs the same set_address magic as
Exception_Handler in order to return values.  Which means that
Exception_Handler can just inherit the magic.  Having this extra magic
doesn't seem to bother RetContinuation, though I'm not sure that I
understand why it doesn't, but at least RetContinuation is thoroughly
covered by the test suite, so I think it's probably OK.

Courtesy of Bob Rogers <[EMAIL PROTECTED]>


Modified: trunk/src/pmc/continuation.pmc
==============================================================================
--- trunk/src/pmc/continuation.pmc      (original)
+++ trunk/src/pmc/continuation.pmc      Mon Jan 30 05:39:39 2006
@@ -150,22 +150,30 @@ Assign context.
 
 =item C<void set_pointer(void *value)>
 
-Sets the pointer to the actual subroutine.
+Sets the pointer to the return instruction.
 
 =cut
 
 */
 
     void set_pointer (void* value) {
+        opcode_t *pos = value;
+        struct Parrot_cont * cc = PMC_cont(SELF);
+
         PObj_get_FLAGS(SELF) |= PObj_private1_FLAG;
-        PMC_cont(SELF)->address = value;
+        cc->address = value;
+        if (pos && *pos == PARROT_OP_get_results_pc) {
+            cc->current_results = pos;
+        }
+        else
+            cc->current_results = NULL;
     }
 
 /*
 
 =item C<void *get_pointer()>
 
-Returns the pointer to the actual subroutine.
+Returns the pointer to the return instruction.
 
 =cut
 

Modified: trunk/src/pmc/exception_handler.pmc
==============================================================================
--- trunk/src/pmc/exception_handler.pmc (original)
+++ trunk/src/pmc/exception_handler.pmc Mon Jan 30 05:39:39 2006
@@ -82,17 +82,6 @@ Initializes the exception handler.
         return result;
     }
 
-    void set_pointer (void* value) {
-        opcode_t *pos = value;
-        struct Parrot_cont * cc = PMC_cont(SELF);
-        if (*pos == PARROT_OP_get_results_pc) {
-            cc->current_results = pos;
-        }
-        else
-            cc->current_results = NULL;
-        SUPER(value);
-    }
-
     void* invoke (void* ex) {
         struct Parrot_cont * cc = PMC_cont(SELF);
         PMC *exception = ex;

Modified: trunk/t/op/calling.t
==============================================================================
--- trunk/t/op/calling.t        (original)
+++ trunk/t/op/calling.t        Mon Jan 30 05:39:39 2006
@@ -1579,6 +1579,31 @@ ok 1
 ok 2
 OUTPUT
 
+pir_output_is(<<'CODE', <<'OUTPUT', "set_args via explicit continuation");
+.sub main :main
+    .local string result
+    result = "not ok 2\n"
+    .local pmc cont
+    cont = new .Continuation
+    set_addr cont, cont_dest
+    bar(cont, "ok 1\n")
+    print "oops\n"
+cont_dest:
+    .get_results (result)
+    print result
+.end
+
+.sub bar
+    .param pmc cc
+    .param string s
+    print s
+    cc("ok 2\n")
+.end
+CODE
+ok 1
+ok 2
+OUTPUT
+
 pir_output_is(<<'CODE', <<'OUTPUT', "call evaled vtable code");
 .sub main :main
     .local string s
@@ -2154,5 +2179,5 @@ CODE
 /duplicate name/
 OUTPUT
 ## remember to change the number of tests :-)
-BEGIN { plan tests => 85 }
+BEGIN { plan tests => 86 }
 

Reply via email to