A practical unification of multi-stage programming and macros
- 7 April 2020
- journal article
- research article
- Published by Association for Computing Machinery (ACM) in ACM SIGPLAN Notices
- Vol. 53 (9), 14-27
- https://doi.org/10.1145/3393934.3278139
Abstract
Program generation is indispensable. We propose a novel unification of two existing metaprogramming techniques: multi-stage programming and hygienic generative macros. The former supports runtime code generation and execution in a type-safe manner while the latter offers compile-time code generation. In this work we draw upon a long line of research on metaprogramming, starting with Lisp, MetaML and MetaOCaml. We provide direct support for quotes, splices and top-level splices, all regulated uniformly by a level-counting Phase Consistency Principle. Our design enables the construction and combination of code values for both expressions and types. Moreover, code generation can happen either at runtime à la MetaML or at compile time, in a macro fashion, à la MacroML. We provide an implementation of our design in Scala and we present two case studies. The first implements the Hidden Markov Model, Shonan Challenge for HPC. The second implements the staged streaming library Strymonas.Keywords
Funding Information
- Schweizerischer Nationalfonds zur Förderung der Wissenschaftlichen Forschung (200021_166154)
This publication has 20 references indexed in Scilit:
- Reflections on LMS: exploring front-end alternativesPublished by Association for Computing Machinery (ACM) ,2016
- Scala macros: let our powers combine!Published by Association for Computing Machinery (ACM) ,2013
- Shonan challenge for generative programmingPublished by Association for Computing Machinery (ACM) ,2013
- ACM Transactions on Programming Languages and Systems, 2008
- FUNCTIONAL PEARL Pickler combinatorsJournal of Functional Programming, 2004
- Inlining as staged computationJournal of Functional Programming, 2003
- Template meta-programming for HaskellPublished by Association for Computing Machinery (ACM) ,2002
- Macros as multi-stage computationsPublished by Association for Computing Machinery (ACM) ,2001
- A modal analysis of staged computationJournal of the ACM, 2001
- Multi-stage programming with explicit annotationsPublished by Association for Computing Machinery (ACM) ,1997