ABSTRACT
Multi-stage programming (MSP) provides a disciplined approach to run-time code generation. In the purely functional setting, it has been shown how MSP can be used to reduce the overhead of abstractions, allowing clean, maintainable code without paying performance penalties. Unfortunately, MSP is difficult to combine with imperative features, which are prevalent in mainstream languages. The central difficulty is scope extrusion, wherein free variables can inadvertently be moved outside the scopes of their binders. This paper proposes a new approach to combining MSP with imperative features that occupies a "sweet spot" in the design space in terms of how well useful MSP applications can be expressed and how easy it is for programmers to understand. The key insight is that escapes (or "anti-quotes") must be weakly separable from the rest of the code, i.e. the computational effects occurring inside an escape that are visible outside the escape are guaranteed to not contain code. To demonstrate the feasibility of this approach, we formalize a type system based on Lightweight Java which we prove sound, and we also provide an implementation, called Mint, to validate both the expressivity of the type system and the effect of staging on the performance of Java programs.
- Baris Aktemur. Type Checking Program Generators Using the Record Calculus, 2009. http://loome.cs.uiuc.edu/pubs/transformationForTyping.pdf.Google Scholar
- Davide Ancona and Eugenio Moggi. A fresh calculus for name management. In GPCE '04: Proceedings of the 3rd International Conference on Generative Programming and Component Engineering, volume 3286, pages 206--224, 2004.Google ScholarCross Ref
- Cristiano Calcagno, Eugenio Moggi, and Walid Taha. Closed Types as a Simple Approach to Safe Imperative Multi-stage Programming. In ICALP '00: Proceedings of the 27th International Colloquium on Automata, Languages and Programming, pages 25--36, 2000. Google ScholarDigital Library
- Cristiano Calcagno, Eugenio Moggi, and Walid Taha. ML-like inference for classifiers. In ESOP '04: Proceedings of the 13th European Symposium on Programming, pages 79--93, 2004.Google ScholarCross Ref
- Cristiano Calcagno, Walid Taha, Liwen Huang, and Xavier Leroy. Implementing multi-stage languages using asts, gensym, and reflection. In GPCE '03: Proceedings of the 2nd International Conference on Generative Programming and Component Engineering, pages 57--76, New York, NY, USA, 2003. Springer-Verlag New York, Inc. Google ScholarDigital Library
- Tim Davis and Yifan Hu. The University of Florida Sparse Matrix Collection. http://www.cise.ufl.edu/research/sparse/matrices/Pajek/Tina DisCal.html.Google Scholar
- Manuel Fähndrich, Michael Carbin, and James R. Larus. Reflective program generation with patterns. In GPCE '06: Proceedings of the 5th International Conference on Generative Programming and Component Engineering, pages 275--284, 2006. Google ScholarDigital Library
- Habanero Multicore Software Research Project. http://habanero.rice.edu.Google Scholar
- Shan Shan Huang and Yannis Smaragdakis. Expressive and safe static reflection with MorphJ. In PLDI '08: Proceedings of the 2008 ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 79--89, 2008. Google ScholarDigital Library
- Shan Shan Huang, David Zook, and Yannis Smaragdakis. Statically safe program generation with safegen. In GPCE '04: Proceedings of the 3rd International Conference on Generative Programming and Component Engineering, pages 309--326, 2005. Google ScholarDigital Library
- Yukiyoshi Kameyama, Oleg Kiselyov, and Chung chieh Shan. Closing the stage: from staged code to typed closures. In PEPM '08: Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, pages 147--157, 2008. Google ScholarDigital Library
- Yukiyoshi Kameyama, Oleg Kiselyov, and Chung chieh Shan. Shifting the stage: Staging with delimited control. In PEPM '09: Proceedings of the 2009 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, pages 111--120, 2009. Google ScholarDigital Library
- Sam Kamin, Lars Clausen, and Ava Jarvis. Jumbo: Run-time code generation for Java and its applications. In CGO '03: Proceedings of the International Symposium on Code Generation and Optimization, pages 48--56, 2003. Google ScholarDigital Library
- Ik-Soon Kim, Kwangkeun Yi, and Cristiano Calcagno. A polymorphic modal type system for lisp-like multi-staged languages. In POPL '06: Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 257--268, New York, NY, USA, 2006. ACM. Google ScholarDigital Library
- Gregory Neverov and Paul Roe. Metaphor: A Multi-stage, Object-Oriented Programming Language. In GPCE '04: Proceedings of the 3rd International Conference on Generative Programming and Component Engineering, pages 168--185, 2004.Google Scholar
- Yutaka Oiwa, Hidehiko Masuhara, and Akinori Yonezawa. DynJava: Type safe dynamic code generation in Java. In PPL '01: Proceedings of the 3rd JSSST Workshop on Programming and Programming Languages, March 2001.Google Scholar
- OpenJDK Project. http://openjdk.java.net.Google Scholar
- Rice PLT. Mint Multi-stage Java Compiler. Available at http://www.javamint.org.Google Scholar
- Massimiliano Poletto, Wilson C. Hsieh, Dawson R. Engler, and M. Frans Kaashoek. C and tcc: a language and compiler for dynamic code generation. ACM Transactions on Programming Languages and Systems, 21(2):324--369, 1999. Google ScholarDigital Library
- U.P. Schultz and J.L. Lawall C. Consel. Automatic Program Specialization for Java. ACM Transactions on Programming Languages and Systems, 25(4):452--499, 2003. Google ScholarDigital Library
- Peter Sestoft. Runtime code generation with JVM and CLR. Available at http://www.dina.dk/sestoft/publications.html, 2002.Google Scholar
- Jun Shirako, Hironori Kasahara, and Vivek Sarkar. Language extensions in support of compiler parallelization. In Languages and Compilers for Parallel Computing: 20th International Workshop, LCPC 2007, Urbana, IL, USA, October 11-13, 2007, Revised Selected Papers, pages 78--94, Berlin, Heidelberg, 2008. Springer-Verlag. Google ScholarDigital Library
- Frederick Smith, Dan Grossman, J. Gregory Morrisett, Luke Hornof, and Trevor Jim. Compiling for template-based run-time code generation. Journal of Functional Programming, 13(3):677--708, 2003. Google ScholarDigital Library
- SoyLatte Project. http://landonf.bikemonkey.org/static/soylatte/.Google Scholar
- Rok Strniaa, Peter Sewell, and Matthew Parkinson. The Java module system: Core design and semantic definition. In OOPSLA '07: Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object Oriented Programming Systems and Applications, pages 499--514, 2007. Google ScholarDigital Library
- Walid Taha. A gentle introduction to multi-stage programming. In DSPG '03: Proceedings of the International Seminar on Domain-Specific Program Generation, 2003.Google Scholar
- Walid Taha, Zine el-abidine Benaissa, and Tim Sheard. Multi-Stage Programming: Axiomatization and Type Safety (Extended Abstract). In ICALP'98: 25th International Colloquium on Automata, Languages, and Programming, pages 918--929, 1998. Google ScholarDigital Library
- Walid Taha and Michael Florentin Nielsen. Environment classifiers. In POPL '03: Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 26--37, New York, NY, USA, 2003. ACM. Google ScholarDigital Library
- Edwin Westbrook, Mathias Ricken, Jun Inoue, Yilong Yao, Tamer Abdelatif, and Walid Taha. Multi-stage Programming for Mainstream Languages. Technical Report TR09-02, Rice University, 2009.Google Scholar
- David Zook, Shan Shan Huang, and Yannis Smaragdakis. Generating AspectJ Programs with Meta-AspectJ. In GPCE '04: Proceedings of the 3rd International Conference on Generative Programming and Component Engineering, pages 1--18, 2004.Google Scholar
Index Terms
- Mint: Java multi-stage programming using weak separability
Recommendations
Mint: Java multi-stage programming using weak separability
PLDI '10Multi-stage programming (MSP) provides a disciplined approach to run-time code generation. In the purely functional setting, it has been shown how MSP can be used to reduce the overhead of abstractions, allowing clean, maintainable code without paying ...
A polymorphic modal type system for lisp-like multi-staged languages
Proceedings of the 2006 POPL ConferenceThis article presents a polymorphic modal type system and its principal type inference algorithm that conservatively extend ML by all of Lisp's staging constructs (the quasi-quotation system). The combination is meaningful because ML is a practical ...
A polymorphic modal type system for lisp-like multi-staged languages
POPL '06: Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languagesThis article presents a polymorphic modal type system and its principal type inference algorithm that conservatively extend ML by all of Lisp's staging constructs (the quasi-quotation system). The combination is meaningful because ML is a practical ...
Comments