[Python-Dev] Anonymous blocks: Thunks or iterators?

Brian Sabbey sabbey at u.washington.edu
Fri Apr 29 20:10:42 CEST 2005


Jim Jewett wrote:

> The only members that need special attention are (f_code, f_lasti)
> and possibly (f_blockstack, f_iblock).

You don't even need to take care of f_code.  The thunk and its surrounding 
function can share the same code.  The thunk gets compiled into the 
function the same way the body of a for loop would.

> (f_code, f_lasti) would need to be replaced with a stack of pairs.
> Finishing a code string would mean popping this stack, rather
> than popping the whole frame.

There doesn't need to be a stack; each thunk can store its own f_lasti.

One also needs to store f_back, and, to avoid exception weirdness, 
f_exc_XXX.

In this way, calling the thunk is much like resuming a generator.

-Brian


More information about the Python-Dev mailing list