A deep dive into implementing generators (semicoroutines) in the lone lisp language. The author explains why delimited continuations were unsuitable as a foundation for generators due to the cost of memcpy-ing entire stacks, then walks through the conceptual journey from delimited continuations to full coroutines to semicoroutines. The post includes C struct definitions and machine step code showing how generator stacks are swapped in/out, how yield saves and restores stacks, and how the generator primitive and yield primitive are implemented at the machine level.
Table of contents
From delimited continuations to coroutinesFrom coroutines to semicoroutinesGenerators in the lone lisp machineThe primitivesSort: