[Python-Dev] Extended Function syntax

holger krekel pyth@devel.trillke.net
Mon, 3 Feb 2003 09:59:08 +0100


Tim Peters wrote:
> [Guido]
> > ...
> > I think that for synchronized-like cases, even if it is known at
> > compile time that it is to be part of the surrounding scope, the code
> > generated will still need to use nested-scope-cells, since it will be
> > invoked on a different stack frame: the "thunk processor" pushes its
> > own frame on the stack, and I think you can't have something that
> > executes in a frame that's not the topmost frame.  (Or can you?  I
> > don't know exactly what generators can get away with.)
> 
> "resumable function" captures almost all salient aspects of the Python
> generator implementation.  Generator resumption acts like a method call to
> the resumer (generator_iterator.next(), whether explicit or implicit), and
> yielding acts *almost* like a function return to the generator (the
> generator's stack frame is popped just as for a function return; the primary
> difference is just that the frame's refcount isn't decremented).

What do you mean with "generator's stack frame is popped"? 

I interpreted this code  in ceval.c

    if (why != WHY_YIELD) {
            /* Pop remaining stack entries -- but when yielding */
            while (!EMPTY()) {
                v = POP();
                Py_XDECREF(v);
            }
    }

to mean the frame is suspended with a preserved stack. 
f_stacktop/last_i later are used to resume. 

    holger