[Python-Dev] Anonymous blocks: Thunks or iterators?
jimjjewett at gmail.com
Fri Apr 29 19:17:13 CEST 2005
> It is possible to implement thunks without them creating their own
> frame. They can reuse the frame of the surrounding function ...
> The implementation just needs to take care
> to save and restore members of the frame that get clobbered when the
> thunk is running.
> Woo. That's cute.
It *sounds* horrendous, but is actually pretty reasonable.
Conceptually, a thunk replaces a suite in the caller.
Most frame members are intended to be shared, and changes
should be visible -- so they don't have to (and shouldn't) be restored.
The only members that need special attention are (f_code, f_lasti)
and possibly (f_blockstack, f_iblock).
(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.
Since a completed suite leaves the blockstack where it started,
(f_blockstack, f_iblock) *can* be ignored, though debugging and
CO_MAXBLOCKS both *suggest* replacing the pair with a stack of
More information about the Python-Dev