[pypy-dev] Stacklets
Antonio Cuni
anto.cuni at gmail.com
Fri Aug 12 14:22:28 CEST 2011
Hi Armin,
On 11/08/11 18:46, Armin Rigo wrote:
> Moreover, we can give it an interface very similar to generators. A
> genlet object has a primitive method send(x), a wrapper next() that
> just calls send(None), and is an iterator. Example:
>
> @genlet
> def f(gen, a, b):
> for i in range(a, b):
> gen.send(i)
>
> for x in f(10, 20):
> print x
>
I'm not sure to fully understand how it would work. Let's rewrite it this way:
def f_inner(gen, a, b):
...
f = genlen(f_inner)
...
When I call f(10, 20), it returns a genlet object, which is an iterator with a
next() method.
When the for loop calls gen.next(), the execution of f_inner is resumed until
it calls gen.send(i), and then "i" is used as a return value for next(). Is it
correct so far?
What I don't get is how all these calls interact with the C stack. I suppose
that when I call "gen.send(i)" the C stack for f_inner is saved inside and
moved away (and "gen" has a reference to it), and then it resumed later when I
call gen.next().
But, what happens to the C stack of the code which executes "for x in f(10,
20)"? Is it saved as soon as I switch to the genlet? Are the caller/callee
genlets symmetrical? Is there a concept of "main genlet" or something like that?
thanks,
Anto
More information about the pypy-dev
mailing list