Python-like generator functions

Python-like generator functions, implemented as a library:

Generator functions implemented as a library

Generator functions implemented as a library

This is possible through two simple tricks:

  1. The language represents stack frames as objects on the heap.
  2. There’s a native function for grabbing the current stack frame.

Turns out replacing the calling stack frame is really the only thing you need in order to implement coroutines and generics.

The implementation is only 23 lines long. On my screen, including the screenshot, this weblog article is already longer up until here.

Comments