Message from discussion
yield op?
Newsgroups: perl.perl6.internals
Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stanford.edu!nntp.perl.org
Return-Path: <mic...@sabren.com>
Mailing-List: contact perl6-internals-h...@perl.org; run by ezmlm
Delivered-To: mailing list perl6-intern...@perl.org
Received: (qmail 49767 invoked by uid 76); 9 Jan 2004 08:30:18 -0000
Received: from qma...@one.develooper.com (HELO ran-out.mx.develooper.com) (64.81.84.115) by onion.perl.org (qpsmtpd/0.26) with SMTP; Fri, 09 Jan 2004 00:30:18 -0800
Received: (qmail 11123 invoked by uid 225); 9 Jan 2004 08:30:13 -0000
Delivered-To: perl6-intern...@perl.org
Received: (qmail 11118 invoked by uid 507); 9 Jan 2004 08:30:13 -0000
Received: from hydrogen.sabren.com (HELO hydrogen.sabren.com) (69.20.61.175) by one.develooper.com (qpsmtpd/0.27-dev) with ESMTP; Fri, 09 Jan 2004 00:29:42 -0800
Received: from hydrogen.sabren.com (localhost [127.0.0.1]) by hydrogen.sabren.com (8.12.10/8.12.10) with ESMTP id i098Tohn024555 for <perl6-intern...@perl.org>; Fri, 9 Jan 2004 03:29:50 -0500
Received: from localhost (sei@localhost) by hydrogen.sabren.com (8.12.10/8.12.10/Submit) with ESMTP id i098ToYI024551 for <perl6-intern...@perl.org>; Fri, 9 Jan 2004 03:29:50 -0500
X-Authentication-Warning: hydrogen.sabren.com: sei owned process doing -bs
Date: Fri, 9 Jan 2004 03:29:49 -0500 (EST)
X-X-Sender: s...@hydrogen.sabren.com
To: perl6-intern...@perl.org
Subject: yield op?
Message-ID: <Pine.LNX.4.58.0401090305540.21408@hydrogen.sabren.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Spam-Check-By: one.develooper.com
X-Spam-Status: No, hits=0.3 required=7.0 tests=CARRIAGE_RETURNS,SPAM_PHRASE_00_01,USER_AGENT_PINE,X_AUTH_WARNING version=2.44
X-SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/
Approved: n...@nntp.perl.org
From: mic...@sabren.com (Michal Wallace)
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: mic...@sabren.com
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