Collapsing Towers of Interpreters ⭐️
We present a multi-level lambda calculus that features staging constructs and stage polymorphism: based on runtime parameters, an interpreter can either act as a normal interpreter or generate code, which turns it into a compiler. We identify stage polymorphism, a programming model from the domain of high-performance program generators, as the key mechanism to make such interpreters compose in a collapsible way.
We present Pink, a meta-circular Lisp-like interpreter on top of this calculus, and demonstrate that we can collapse arbitrarily many levels of self-interpretation, including levels with semantic modi cations. We discuss several examples: compiling regular expressions through an interpreter to base code, building program transformers from modi ed interpreters, and others. We develop these ideas further to include reflection and reification, culminating in Purple, a reflective language inspired by Brown, Blond, and Black, which implements a conceptually in nite tower, where every aspect of the semantics can change dynamically. Addressing an open challenge, we demonstrate how user programs can be compiled and recompiled under user-modified semantics.
Joint work with Tiark Rompf.