Hey all,

When you invoke a Coroutine, it calls swap_context()
from src/sub.c ... There's an else clause in there
that either swaps or restores theinterpreter  stack,
but as far as I can tell, swap_context() is ONLY
called when entering a coroutine - not when we're
suspending it. That means all sorts of nasty things
happen when the either coroutine or the calling
context gets modified.

For example, the code below counts up from 1 to
forever. But if you uncomment the zero=0 line,
it never gets higher than 1 because "zero"
in __main__ and "x" in "_iterator" get assigned
to the same register, and the context isn't
properly restored.

It seems to me that invoke() is doing the right
thing by swapping the context, but that there
needs to be a yield() method (and opcode?) to
balance it out. It definitely needs more than
a savetop or an "invoke" of ther return
continuation, because neither of these things
would let you fire a method on the coroutine
instance. That's why I'm thinking we need a
yield op.

Am I on the right track here? Either way,
what can I do to get this working?

Sincerely,

Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
--------------------------------------

#!/bin/env parrot
# uncomment the second zero=0 line to see the magic bug :)

.sub __main__
    .local Coroutine itr
    .local object return
    .local object counter
    newsub itr, .Coroutine, _iterator

    .local object zero
    zero = new PerlInt
    zero = 0

    newsub return, .Coroutine, return_here
    loop:
        .pcc_begin non_prototyped
            .pcc_call itr, return
             return_here:
            .result counter
        .pcc_end

        print counter
        print " "

        ### zero = 0
        print zero
        print "\n"
    goto loop
    end
.end


.pcc_sub _iterator non_prototyped
    .local object x
    x = new PerlInt
    x = 0
    iloop:
        .pcc_begin_yield
        .return x
        .pcc_end_yield
        x = x + 1
    goto iloop
.end


Reply via email to