Python/C API

Clark C. Evans cce at clarkevans.com
Thu Apr 10 03:01:23 EDT 2003


On Thu, Apr 10, 2003 at 02:34:13AM -0400, Jp Calderone wrote:
| How does one write generators in C, or does one not?

You basically implement your own secondary call stack.  Instead of 
calling a function directly, you call a procedure which puts your
function on the secondary call stack and then executes it.  Then,
when the function returns you don't pop the secondary call stack.
For each generator, you get another call stack, etc.   

Clark

P.S. I'm (in the background cycles) working on a yaml parser
in C, which uses 'generator' technique for parsing.  I only
have a crude call stack impl, if someone has a good one...





More information about the Python-list mailing list