Abstract
Given a tower of interpreters, i.e., a sequence of multiple interpreters interpreting one another as input programs, we aim to collapse this tower into a compiler that removes all interpretive overhead and runs in a single pass. In the real world, a use case might be Python code executed by an x86 runtime, on a CPU emulated in a JavaScript VM, running on an ARM CPU. Collapsing such a tower can not only exponentially improve runtime performance, but also enable the use of base-language tools for interpreted programs, e.g., for analysis and verification. In this paper, we lay the foundations in an idealized but realistic setting.
We present a multi-level lambda calculus that features staging constructs and stage polymorphism: based on runtime parameters, an evaluator either executes source code (thereby acting as an interpreter) or generates code (thereby acting as 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 evaluator on top of this calculus, and demonstrate that we can collapse arbitrarily many levels of self-interpretation, including levels with semantic modifications. 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 realizes a conceptually infinite tower, where every aspect of the semantics can change dynamically. Addressing an open challenge, we show how user programs can be compiled and recompiled under user-modified semantics.
Supplemental Material
- Stefan Ackermann, Vojin Jovanovic, Tiark Rompf, and Martin Odersky. 2012. Jet: An Embedded DSL for High Performance Big Data Processing (BigData).Google Scholar
- Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. 2003. A functional correspondence between evaluators and abstract machines. In PPDP. Google Scholar
Digital Library
- Jason Ansel, Cy Chan, Yee Lok Wong, Marek Olszewski, Qin Zhao, Alan Edelman, and Saman Amarasinghe. 2009. PetaBricks: A Language and Compiler for Algorithmic Choice. In PLDI. Google Scholar
Digital Library
- Kenichi Asai. 2014. Compiling a Reflective Language Using MetaOCaml. In GPCE. code from personal correspondence. Google Scholar
Digital Library
- Kenichi Asai, Satoshi Matsuoka, and Akinori Yonezawa. 1996. Duplication and Partial Evaluation: For a Better Understanding of Reflective Languages. Lisp and Symbolic Computation - Special issue on computational reflection, 203–241. code at github.com/readevalprintlove/black .Google Scholar
- Alan Bawden. 1999. Quasiquotation in Lisp. In PEPM.Google Scholar
- Olav Beckmann, Alastair Houghton, Michael R. Mellor, and Paul H. J. Kelly. 2003. Runtime Code Generation in C++ as a Foundation for Domain-Specific Optimisation. In Domain-Specific Program Generation.Google Scholar
- Fabrice Bellard. 2011–2017. JSLinux. bellard.org/jslinux .Google Scholar
- Martin Berger, Laurence Tratt, and Christian Urban. 2017. Modelling Homogeneous Generative Meta-Programming. In ECOOP.Google Scholar
- Ulrich Berger, Matthias Eberl, and Helmut Schwichtenberg. 1998. Normalization by Evaluation. In Prospects for Hardware Foundations: ESPRIT Working Group 8533 NADA — New Hardware Design Methods Survey Chapters, Bernhard Möller and John V. Tucker (Eds.). 117–137. Google Scholar
Cross Ref
- Lars Birkedal and Morten Welinder. 1994. Hand-writing program generator generators. In PLILP. Google Scholar
Cross Ref
- Anders Bondorf. 1990. Self-applicable partial evaluation. Ph.D. Dissertation. DIKU, Department of Computer Science, University of Copenhagen.Google Scholar
- Anders Bondorf and Olivier Danvy. 1991. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming 16, 2, 151–195. Google Scholar
Digital Library
- Matt Brown and Jens Palsberg. 2016. Breaking through the normalization barrier: a self-interpreter for f-omega. In POPL. Google Scholar
Digital Library
- Matt Brown and Jens Palsberg. 2017. Typed self-evaluation via intensional type functions. In POPL. Google Scholar
Digital Library
- William E. Byrd, Michael Ballantyne, Gregory Rosenblatt, and Matthew Might. 2017. A Unified Approach to Solving Seven Programming Problems (Functional Pearl). In ICFP.Google Scholar
- Cristiano Calcagno, Walid Taha, Liwen Huang, and Xavier Leroy. 2003. Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection. In GPCE.Google Scholar
- Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. JFP 19, 5, 509–543. Google Scholar
Digital Library
- Cliff Click and Keith D. Cooper. 1995. Combining analyses, combining optimizations. TOPLAS 17, 181–196. Issue 2.Google Scholar
Digital Library
- Charles Consel and Siau-Cheng Khoo. 1993. Parameterized Partial Evaluation. TOPLAS 15, 3, 463–493. Google Scholar
Digital Library
- Olivier Danvy. 1996a. Pragmatics of type-directed partial evaluation. In Partial Evaluation: Dagstuhl, Selected Papers, Olivier Danvy, Robert Glück, and Peter Thiemann (Eds.). Google Scholar
Cross Ref
- Olivier Danvy. 1996b. Type-directed Partial Evaluation. In POPL. Google Scholar
Digital Library
- Olivier Danvy. 1998a. Online Type-Directed Partial Evaluation. In Fuji International Symposium on Functional and Logic Programming.Google Scholar
- Olivier Danvy. 1998b. Type-Directed Partial Evaluation. In DIKU 1998 International Summer School, John Hatcliff, Torben Æ. Mogensen, and Peter Thiemann (Eds.).Google Scholar
- Olivier Danvy. 2003. A New One-pass Transformation into Monadic Normal Form. In Compiler Construction. Google Scholar
Cross Ref
- Olivier Danvy. 2006. An Analytical Approach to Programs as Data Objects. DSc thesis. Department of Computer Science, Aarhus University, Aarhus, Denmark. ebooks.au.dk/index.php/aul/catalog/book/214 .Google Scholar
- Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts. Technical Report. DIKU, University of Copenhagen.Google Scholar
- Olivier Danvy and Andrzej Filinski. 1990. Abstracting control. In Lisp and Functional Programming. Google Scholar
Digital Library
- Olivier Danvy and Mayer Goldberg. 2005. There and Back Again. Fundam. Inform. 66, 4, 397–413. Google Scholar
Digital Library
- Olivier Danvy and Jacob Johannsen. 2010. Inter-deriving semantic artifacts for object-oriented programming. J. Comput. Syst. Sci. 76, 5, 302–323. Google Scholar
Digital Library
- Olivier Danvy and Karoline Malmkjær. 1988. Intensions and Extensions in a Reflective Tower. In Lisp and Functional Programming. Google Scholar
Digital Library
- Olivier Danvy, Kevin Millikin, Johan Munk, and Ian Zerny. 2012. On inter-deriving small-step and big-step semantics: A case study for storeless call-by-need evaluation. Theor. Comput. Sci. 435, 21–42. Google Scholar
Digital Library
- Olivier Danvy and Lasse R. Nielsen. 2004. Refocusing in Reduction Semantics. Research Report BRICS RS-04-26. Department of Computer Science, Aarhus University, Aarhus, Denmark. A preliminary version appeared in the informal proceedings of the Second International Workshop on Rule-Based Programming (RULE 2001), Electronic Notes in Theoretical Computer Science, Vol. 59.4. Google Scholar
Cross Ref
- David Darais, Nicholas Labich, Phúc C. Nguyen, and David Van Horn. 2017. Abstracting Definitional Interpreters (Functional Pearl). In ICFP.Google Scholar
- Andrei P. Ershov. 1978. On the essence of compilation. Formal Description of Programming Concepts, 391–420.Google Scholar
- Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics Engineering with PLT Redex. MIT Press.Google Scholar
Digital Library
- Andrzej Filinski. 1994. Representing Monads. In POPL. Google Scholar
Digital Library
- Andrzej Filinski. 1999. A Semantic Account of Type-Directed Partial Evaluation. In PPDP. Google Scholar
Cross Ref
- Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In PLDI. Google Scholar
Digital Library
- Daniel P. Friedman and Mitchell Wand. 1984. Reification: Reflection without Metaphysics. In Lisp and Functional Programming.Google Scholar
- Matteo Frigo. 1999. A Fast Fourier Transform Compiler. In PLDI. Google Scholar
Digital Library
- Yoshihiko Futamura. 1971. Partial Evaluation of Computation Process — An approach to a Compiler-Compiler. Transactions of the Institute of Electronics and Communication Engineers of Japan 54-C, 8, 721–728.Google Scholar
- Yoshihiko Futamura. 1999. Partial Evaluation of Computation Process, Revisited. Higher-Order and Symbolic Computation, 377–380. Google Scholar
Digital Library
- Rui Ge and Ronald Garcia. 2017. Refining Semantics for Multi-stage Programming. In GPCE. Google Scholar
Digital Library
- Robert Glück. 2002. Jones Optimality, Binding-time Improvements, and the Strength of Program Specializers. In PEPM.Google Scholar
- Robert Glück and Jesper Jørgensen. 1995. Efficient Multi-level Generating Extensions for Program Specialization. In PLILP. Google Scholar
Cross Ref
- Robert Glück and Jesper Jørgensen. 1996. Fast binding-time analysis for multi-level specialization. In Ershov Memorial Conference, PSI. Google Scholar
Cross Ref
- Robert Glück and Jesper Jørgensen. 1998. Multi-Level Specialization (Extended Abstract). In Partial Evaluation.Google Scholar
- Robert Glück and Andrei V. Klimov. 1999. Reduction of language hierarchies by metacomputation. In The Evolution of Complexity.Google Scholar
- Brian Grant, Markus Mock, Matthai Philipose, Craig Chambers, and Susan J. Eggers. 2000. DyC: an expressive annotationdirected dynamic compiler for C. Theor. Comput. Sci. 248, 1-2, 147–199. Google Scholar
Digital Library
- Martin Hanger, Tor Arne Johansen, Geir Kare Mykland, and Aage Skullestad. 2011. Dynamic model predictive control allocation using CVXGEN. In ICCA. Google Scholar
Cross Ref
- John Hatcliff and Olivier Danvy. 1997. A Computational Formalization for Partial Evaluation. Mathematical Structures in Computer Science 7, 5, 507–541. Google Scholar
Digital Library
- Fabian Hemmer. 2014–2017. x86 virtualization in JavaScript, running in your browser and NodeJS. copy.sh/v86 .Google Scholar
- Fritz Henglein and Christian Mossin. 1994. Polymorphic Binding-Time Analysis. In ESOP. Google Scholar
Cross Ref
- David Van Horn and Matthew Might. 2011. Abstracting abstract machines: a systematic approach to higher-order program analysis. CACM 54, 9, 101–109. Google Scholar
Digital Library
- Stanley Jefferson and Daniel P. Friedman. 1996. A Simple Reflective Interpreter. Lisp and Symbolic Computation 9, 2-3, 181–202. Google Scholar
Digital Library
- Neil D. Jones. 2004. Transformation by interpreter specialisation. Sci. Comput. Program. 52, 307–339. Google Scholar
Digital Library
- Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial evaluation and automatic program generation. Prentice-Hall, Inc., Upper Saddle River, NJ, USA. www.itu.dk/people/sestoft/pebook .Google Scholar
Digital Library
- Neil D. Jones, Peter Sestoft, and Harald Søndergaard. 1989. MIX: A Self-Applicable Partial Evaluator for Experiments in Compiler Generation. Lisp and Symbolic Computation 2, 1, 9–50. Google Scholar
Cross Ref
- Brian Kernighan and Rob Pike. 2007. A Regular Expression Matcher. In Beautiful Code, Greg Wilson and Andy Oram (Eds.). O’Reilly, Chapter 1. www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html .Google Scholar
- Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml. In FLOPS. Google Scholar
Cross Ref
- Oleg Kiselyov, Kedar N. Swadi, and Walid Taha. 2004. A methodology for generating verified combinatorial circuits. In EMSOFT. Google Scholar
Digital Library
- Andrei V. Klimov. 2009. A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols. In Ershov Memorial Conference, PSI.Google Scholar
- Grzegorz Kossakowski, Nada Amin, Tiark Rompf, and Martin Odersky. 2012. JavaScript as an Embedded DSL. In ECOOP. Google Scholar
Digital Library
- Julia L. Lawall and Peter Thiemann. 1997. Sound Specialization in the Presence of Computational Effects. In TACS. Google Scholar
Cross Ref
- Hidehiko Masuhara, Gregor Kiczales, and Christopher Dutchyn. 2003. A Compilation and Optimization Model for AspectOriented Programs. In Compiler Construction.Google Scholar
- Torben Æ. Mogensen. 1988. Partially static structures in a self-applicable partial evaluator. In Partial Evaluation and Mixed Computation: IFIP TC2 Workshop, Dines Bjørner, Andrei P. Ershov, and Neil D. Jones (Eds.).Google Scholar
- Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput. 93, 1, 55–92. Google Scholar
Digital Library
- Flemming Nielson and Hanne Riis Nielson. 1996. Multi-Level Lambda-Calculi: An Algebraic Description. In Partial Evaluation: Dagstuhl, Selected Papers, Olivier Danvy, Robert Glück, and Peter Thiemann (Eds.).Google Scholar
- Georg Ofenbeck, Tiark Rompf, and Markus Püschel. 2017. Staging for Generic Programming in Space and Time. In GPCE. Google Scholar
Digital Library
- Georg Ofenbeck, Tiark Rompf, Alen Stojanov, Martin Odersky, and Markus Püschel. 2013. Spiral in Scala: Towards the Systematic Construction of Generators for Performance Libraries. In GPCE.Google Scholar
- Markus Püschel, José M. F. Moura, Bryan Singer, Jianxin Xiong, Jeremy Johnson, David A. Padua, Manuela M. Veloso, and Robert W. Johnson. 2004. Spiral: A Generator for Platform-Adapted Libraries of Signal Processing Alogorithms. IJHPCA 18, 1, 21–45. Google Scholar
Digital Library
- Tillmann Rendel, Klaus Ostermann, and Christian Hofer. 2009. Typed self-representation. In PLDI. Google Scholar
Digital Library
- John C. Reynolds. 1972. Definitional Interpreters for Higher-order Programming Languages. In Proceedings of the ACM Annual Conference. Google Scholar
Digital Library
- Tiark Rompf. 2012. Lightweight Modular Staging and Embedded Compilers: Abstraction Without Regret for High-Level High-Performance Programming. Ph.D. Dissertation. EPFL IC, Ecole Polytechnique Fédérale de Lausanne, School of Computer and Communication Sciences.Google Scholar
- Tiark Rompf. 2016. The Essence of Multi-Stage Evaluation in LMS. In A List of Successes That Can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday (WadlerFest), Sam Lindley, Conor McBride, Phil Trinder, and Don Sannella (Eds.). Google Scholar
Cross Ref
- Tiark Rompf and Nada Amin. 2015. Functional Pearl: A SQL to C Compiler in 500 Lines of Code. In ICFP.Google Scholar
- Tiark Rompf and Martin Odersky. 2010. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In GPCE. Google Scholar
Digital Library
- Tiark Rompf and Martin Odersky. 2012. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. CACM 55, 6, 121–130. Google Scholar
Digital Library
- Tiark Rompf, Arvind K. Sujeeth, Nada Amin, Kevin Brown, Vojin Jovanovic, HyoukJoong Lee, Manohar Jonnalagedda, Kunle Olukotun, and Martin Odersky. 2013. Optimizing Data Structures in High-Level Programs. In POPL.Google Scholar
- Tiark Rompf, Arvind K. Sujeeth, HyoukJoong Lee, Kevin J. Brown, Hassan Chafi, Martin Odersky, and Kunle Olukotun. 2011. Building-Blocks for Performance Oriented DSLs, In DSL. Electronic Proceedings in Theoretical Computer Science.Google Scholar
Cross Ref
- Ulrik Pagh Schultz, Julia L. Lawall, and Charles Consel. 2003. Automatic program specialization for Java. TOPLAS 25, 4, 452–499. Google Scholar
Digital Library
- Amin Shali and William R. Cook. 2011. Hybrid partial evaluation. In OOPSLA. Google Scholar
Digital Library
- Brian C. Smith. 1982. Reflection and Semantics in a Procedural Language. Ph.D. Dissertation. MIT EECS, Massachusetts Institute of Technology, Dept. of Electrical Engineering and Computer Science.Google Scholar
- Brian C. Smith. 1984. Reflection and Semantics in Lisp. In POPL. Google Scholar
Digital Library
- Jonathan M Sobel and Daniel P Friedman. 1996. An introduction to reflection-oriented programming. In Proceedings of reflection.Google Scholar
- Michael Sperber and Peter Thiemann. 1996. Realistic Compilation by Partial Evaluation. In PLDI. Google Scholar
Digital Library
- Arvind K. Sujeeth, HyoukJoong. Lee, Kevin J. Brown, Tiark Rompf, Michael Wu, Anand R. Atreya, Martin Odersky, and Kunle Olukotun. 2011. OptiML: an Implicitly Parallel Domain-Specific Language for Machine Learning. In ICML.Google Scholar
- Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theor. Comput. Sci. 248, 1-2, 211–242. Google Scholar
Digital Library
- Peter Thiemann. 1996. Cogen in Six Lines. In ICFP. Google Scholar
Digital Library
- Peter Thiemann. 2013. Partially static operations. In PEPM. Google Scholar
Digital Library
- Peter Thiemann and Dirk Dussart. 1999. Partial evaluation for higher-order languages with state. Technical Report. www.informatik.uni-freiburg.de/ thiemann/papers/mlpe.ps.gz .Google Scholar
- John Vilk and Emery D. Berger. 2014. Doppio: Breaking the Browser Language Barrier. In PLDI.Google Scholar
- Philip Wadler and Stephen Blott. 1989. How to Make ad-hoc Polymorphism Less ad-hoc. In POPL. Google Scholar
Digital Library
- Mitchell Wand and Daniel P. Friedman. 1986. The Mystery of the Tower Revealed: A Non-Reflective Description of the Reflective Tower. In Lisp and Functional Programming. Google Scholar
Digital Library
- R. Clinton Whaley, Antoine Petitet, and Jack Dongarra. 2001. Automated empirical optimizations of software and the ATLAS project. Parallel Comput. 27, 1-2, 3–35.Google Scholar
Cross Ref
- Alon Zakai. 2011. Emscripten: an LLVM-to-JavaScript compiler. In OOPSLA.Google Scholar
Index Terms
Collapsing towers of interpreters
Recommendations
Definitional Interpreters for Higher-Order Programming Languages
Higher-order programming languages (i.e., languages in which procedures or labels can occur as values) are usually defined by interpreters that are themselves written in a programming language based on the lambda calculus (i.e., an applicative language ...
Definitional interpreters for higher-order programming languages
ACM '72: Proceedings of the ACM annual conference - Volume 2Higher-order programming languages (i.e., languages in which procedures or labels can occur as values) are usually defined by interpreters which are themselves written in a programming language based on the lambda calculus (i.e., an applicative language ...
Compiling a reflective language using MetaOCaml
GPCE 2014: Proceedings of the 2014 International Conference on Generative Programming: Concepts and ExperiencesA reflective language makes the language semantics open to user programs and allows them to access, extend, and modify it from within the same language framework. Because of its high flexibility and expressiveness, it can be an ideal platform for ...






Comments