At 01:50 AM 6/7/2002 -0400, Dan Sugalski wrote: >So, we're adding an invoke vtable method, and we'll have four sub PMC >types: ParrotSub, ParrotClosure, ParrotCoroutine, and >ParrotContinuation. We ought to be able to create them with limited >trouble, and it's OK if they've got evil knowledge of Parrot's >internals.
Ok, good. I have ParrotSub working as a co-routine, I'll just trim it down and make ParrotSub/Coroutine out of it. I have a few questions but these will wait until tomorrow. For now here is the co-routine hack as it stands, to create a co-routine on the fly. I already sent this to you, but this is for the list. These are currently using an op only, not a vtable method. If I understand co-routines, they are resumeable until they do a return (not a yield). On a return, we can set the entry address back to the "start" of the co-routine for another call. -Melvin # Sample co-routines in Parrot # # Create 2 coroutines new P0, .ParrotSub, PRINT save P0 new P0, .ParrotSub, PRINT set P0, I0 # Calling convention says P0 will contain the sub so.. print "1st routine\n" call call restore P0 print "2nd routine\n" call call end # A coroutine PRINT: print "Mark 1\n" yield print "Mark 2\n" yield print "Mark 3\n" ret Outputs: 1st routine Mark 1 Mark 2 2nd routine Mark 1 Mark 2