skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

Collapsing towers of interpreters

Published:27 December 2017Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

collapsingtowersofinterpreters.webm

References

  1. Stefan Ackermann, Vojin Jovanovic, Tiark Rompf, and Martin Odersky. 2012. Jet: An Embedded DSL for High Performance Big Data Processing (BigData).Google ScholarGoogle Scholar
  2. Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. 2003. A functional correspondence between evaluators and abstract machines. In PPDP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. Kenichi Asai. 2014. Compiling a Reflective Language Using MetaOCaml. In GPCE. code from personal correspondence. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. Alan Bawden. 1999. Quasiquotation in Lisp. In PEPM.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. Fabrice Bellard. 2011–2017. JSLinux. bellard.org/jslinux .Google ScholarGoogle Scholar
  9. Martin Berger, Laurence Tratt, and Christian Urban. 2017. Modelling Homogeneous Generative Meta-Programming. In ECOOP.Google ScholarGoogle Scholar
  10. 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 ScholarGoogle ScholarCross RefCross Ref
  11. Lars Birkedal and Morten Welinder. 1994. Hand-writing program generator generators. In PLILP. Google ScholarGoogle ScholarCross RefCross Ref
  12. Anders Bondorf. 1990. Self-applicable partial evaluation. Ph.D. Dissertation. DIKU, Department of Computer Science, University of Copenhagen.Google ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. Matt Brown and Jens Palsberg. 2016. Breaking through the normalization barrier: a self-interpreter for f-omega. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Matt Brown and Jens Palsberg. 2017. Typed self-evaluation via intensional type functions. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. William E. Byrd, Michael Ballantyne, Gregory Rosenblatt, and Matthew Might. 2017. A Unified Approach to Solving Seven Programming Problems (Functional Pearl). In ICFP.Google ScholarGoogle Scholar
  17. Cristiano Calcagno, Walid Taha, Liwen Huang, and Xavier Leroy. 2003. Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection. In GPCE.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Cliff Click and Keith D. Cooper. 1995. Combining analyses, combining optimizations. TOPLAS 17, 181–196. Issue 2.Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Charles Consel and Siau-Cheng Khoo. 1993. Parameterized Partial Evaluation. TOPLAS 15, 3, 463–493. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarCross RefCross Ref
  22. Olivier Danvy. 1996b. Type-directed Partial Evaluation. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Olivier Danvy. 1998a. Online Type-Directed Partial Evaluation. In Fuji International Symposium on Functional and Logic Programming.Google ScholarGoogle Scholar
  24. Olivier Danvy. 1998b. Type-Directed Partial Evaluation. In DIKU 1998 International Summer School, John Hatcliff, Torben Æ. Mogensen, and Peter Thiemann (Eds.).Google ScholarGoogle Scholar
  25. Olivier Danvy. 2003. A New One-pass Transformation into Monadic Normal Form. In Compiler Construction. Google ScholarGoogle ScholarCross RefCross Ref
  26. 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 ScholarGoogle Scholar
  27. Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts. Technical Report. DIKU, University of Copenhagen.Google ScholarGoogle Scholar
  28. Olivier Danvy and Andrzej Filinski. 1990. Abstracting control. In Lisp and Functional Programming. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Olivier Danvy and Mayer Goldberg. 2005. There and Back Again. Fundam. Inform. 66, 4, 397–413. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Olivier Danvy and Jacob Johannsen. 2010. Inter-deriving semantic artifacts for object-oriented programming. J. Comput. Syst. Sci. 76, 5, 302–323. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Olivier Danvy and Karoline Malmkjær. 1988. Intensions and Extensions in a Reflective Tower. In Lisp and Functional Programming. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle ScholarCross RefCross Ref
  34. David Darais, Nicholas Labich, Phúc C. Nguyen, and David Van Horn. 2017. Abstracting Definitional Interpreters (Functional Pearl). In ICFP.Google ScholarGoogle Scholar
  35. Andrei P. Ershov. 1978. On the essence of compilation. Formal Description of Programming Concepts, 391–420.Google ScholarGoogle Scholar
  36. Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics Engineering with PLT Redex. MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Andrzej Filinski. 1994. Representing Monads. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Andrzej Filinski. 1999. A Semantic Account of Type-Directed Partial Evaluation. In PPDP. Google ScholarGoogle ScholarCross RefCross Ref
  39. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Daniel P. Friedman and Mitchell Wand. 1984. Reification: Reflection without Metaphysics. In Lisp and Functional Programming.Google ScholarGoogle Scholar
  41. Matteo Frigo. 1999. A Fast Fourier Transform Compiler. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle Scholar
  43. Yoshihiko Futamura. 1999. Partial Evaluation of Computation Process, Revisited. Higher-Order and Symbolic Computation, 377–380. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Rui Ge and Ronald Garcia. 2017. Refining Semantics for Multi-stage Programming. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Robert Glück. 2002. Jones Optimality, Binding-time Improvements, and the Strength of Program Specializers. In PEPM.Google ScholarGoogle Scholar
  46. Robert Glück and Jesper Jørgensen. 1995. Efficient Multi-level Generating Extensions for Program Specialization. In PLILP. Google ScholarGoogle ScholarCross RefCross Ref
  47. Robert Glück and Jesper Jørgensen. 1996. Fast binding-time analysis for multi-level specialization. In Ershov Memorial Conference, PSI. Google ScholarGoogle ScholarCross RefCross Ref
  48. Robert Glück and Jesper Jørgensen. 1998. Multi-Level Specialization (Extended Abstract). In Partial Evaluation.Google ScholarGoogle Scholar
  49. Robert Glück and Andrei V. Klimov. 1999. Reduction of language hierarchies by metacomputation. In The Evolution of Complexity.Google ScholarGoogle Scholar
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. Martin Hanger, Tor Arne Johansen, Geir Kare Mykland, and Aage Skullestad. 2011. Dynamic model predictive control allocation using CVXGEN. In ICCA. Google ScholarGoogle ScholarCross RefCross Ref
  52. John Hatcliff and Olivier Danvy. 1997. A Computational Formalization for Partial Evaluation. Mathematical Structures in Computer Science 7, 5, 507–541. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Fabian Hemmer. 2014–2017. x86 virtualization in JavaScript, running in your browser and NodeJS. copy.sh/v86 .Google ScholarGoogle Scholar
  54. Fritz Henglein and Christian Mossin. 1994. Polymorphic Binding-Time Analysis. In ESOP. Google ScholarGoogle ScholarCross RefCross Ref
  55. David Van Horn and Matthew Might. 2011. Abstracting abstract machines: a systematic approach to higher-order program analysis. CACM 54, 9, 101–109. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Stanley Jefferson and Daniel P. Friedman. 1996. A Simple Reflective Interpreter. Lisp and Symbolic Computation 9, 2-3, 181–202. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Neil D. Jones. 2004. Transformation by interpreter specialisation. Sci. Comput. Program. 52, 307–339. Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  59. 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 ScholarGoogle ScholarCross RefCross Ref
  60. 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 ScholarGoogle Scholar
  61. Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml. In FLOPS. Google ScholarGoogle ScholarCross RefCross Ref
  62. Oleg Kiselyov, Kedar N. Swadi, and Walid Taha. 2004. A methodology for generating verified combinatorial circuits. In EMSOFT. Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. Andrei V. Klimov. 2009. A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols. In Ershov Memorial Conference, PSI.Google ScholarGoogle Scholar
  64. Grzegorz Kossakowski, Nada Amin, Tiark Rompf, and Martin Odersky. 2012. JavaScript as an Embedded DSL. In ECOOP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. Julia L. Lawall and Peter Thiemann. 1997. Sound Specialization in the Presence of Computational Effects. In TACS. Google ScholarGoogle ScholarCross RefCross Ref
  66. Hidehiko Masuhara, Gregor Kiczales, and Christopher Dutchyn. 2003. A Compilation and Optimization Model for AspectOriented Programs. In Compiler Construction.Google ScholarGoogle Scholar
  67. 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 ScholarGoogle Scholar
  68. Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput. 93, 1, 55–92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  69. 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 ScholarGoogle Scholar
  70. Georg Ofenbeck, Tiark Rompf, and Markus Püschel. 2017. Staging for Generic Programming in Space and Time. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. 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 ScholarGoogle Scholar
  72. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  73. Tillmann Rendel, Klaus Ostermann, and Christian Hofer. 2009. Typed self-representation. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  74. John C. Reynolds. 1972. Definitional Interpreters for Higher-order Programming Languages. In Proceedings of the ACM Annual Conference. Google ScholarGoogle ScholarDigital LibraryDigital Library
  75. 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 ScholarGoogle Scholar
  76. 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 ScholarGoogle ScholarCross RefCross Ref
  77. Tiark Rompf and Nada Amin. 2015. Functional Pearl: A SQL to C Compiler in 500 Lines of Code. In ICFP.Google ScholarGoogle Scholar
  78. Tiark Rompf and Martin Odersky. 2010. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  79. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  80. 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 ScholarGoogle Scholar
  81. 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 ScholarGoogle ScholarCross RefCross Ref
  82. Ulrik Pagh Schultz, Julia L. Lawall, and Charles Consel. 2003. Automatic program specialization for Java. TOPLAS 25, 4, 452–499. Google ScholarGoogle ScholarDigital LibraryDigital Library
  83. Amin Shali and William R. Cook. 2011. Hybrid partial evaluation. In OOPSLA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  84. 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 ScholarGoogle Scholar
  85. Brian C. Smith. 1984. Reflection and Semantics in Lisp. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  86. Jonathan M Sobel and Daniel P Friedman. 1996. An introduction to reflection-oriented programming. In Proceedings of reflection.Google ScholarGoogle Scholar
  87. Michael Sperber and Peter Thiemann. 1996. Realistic Compilation by Partial Evaluation. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  88. 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 ScholarGoogle Scholar
  89. Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theor. Comput. Sci. 248, 1-2, 211–242. Google ScholarGoogle ScholarDigital LibraryDigital Library
  90. Peter Thiemann. 1996. Cogen in Six Lines. In ICFP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  91. Peter Thiemann. 2013. Partially static operations. In PEPM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  92. 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 ScholarGoogle Scholar
  93. John Vilk and Emery D. Berger. 2014. Doppio: Breaking the Browser Language Barrier. In PLDI.Google ScholarGoogle Scholar
  94. Philip Wadler and Stephen Blott. 1989. How to Make ad-hoc Polymorphism Less ad-hoc. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  95. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  96. 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 ScholarGoogle ScholarCross RefCross Ref
  97. Alon Zakai. 2011. Emscripten: an LLVM-to-JavaScript compiler. In OOPSLA.Google ScholarGoogle Scholar

Index Terms

  1. Collapsing towers of interpreters

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!