NAME ^

classes/coroutine.pmc - Co-Routine PMC

DESCRIPTION ^

Coroutine extends Continuation to provide a subroutine that can stop in the middle, and start back up later at the point at which it stopped. See the Glossary for more information.

Flags ^

private0 call flip flop

private3 called first time, used for python

Methods ^

void init()

Initializes the co-routine.

void *invoke(void *next)

Swaps the "context".

PMC *shift_pmc)

Run the coroutine until it yields a value. The call to the coroutine is actually done via the call_hook below, a piece of code at the end of a coroutine:

set P0, P5 # get the real coroutine invokecc # run that code end # terminate the runloop

INTVAL elements ()

Return much, we don't know.

*/

    INTVAL elements () {
        return (2^31) - 1;
    }

    PMC* get_iter () {
        if (PObj_get_FLAGS(SELF) & PObj_private3_FLAG) {
            struct Parrot_coro * sub = PMC_coro(SELF);
            PMC *ret = pmc_new(INTERP, enum_class_Coroutine);
            struct Parrot_coro * coro = PMC_coro(ret);
            coro->end = sub->end;
            coro->address = sub->address;

            PObj_get_FLAGS(ret) |= PObj_private1_FLAG; /* fixup done */
            PObj_get_FLAGS(ret) &= ~PObj_private3_FLAG;
            PObj_flag_CLEAR(custom_mark, SELF);
            return ret;
        }
        return SELF;
    }

    INTVAL get_bool () {
        return 1;
    }
/*

void mark()

Marks the coroutine as live.

HISTORY ^

Initial version by Melvin on 2002/06/6.


parrot