Multi-Stage Programming with Generative and Analytical Macros

by Nicolas Stucki, Jonathan Immanuel Brachthäuser, and Martin Odersky

In Proceedings of the 20th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, pages 110–122. Association for Computing Machinery, 2021.

Abstract

In metaprogramming, code generation and code analysis are complementary. Traditionally, principled metaprogramming extensions for programming languages, like MetaML and BER MetaOCaml, offer strong foundations for code generation but lack equivalent support for code analysis. Similarly, existing macro systems are biased towards the code generation aspect. In this work, we present a calculus for macros featuring both code generation and code analysis. The calculus directly models separate compilation of macros, internalizing a commonly neglected aspect of macros. The system ensures that the generated code is well-typed and hygienic. We implement our system in Scala 3, provide a formalization, and prove its soundness.

Talk

Video recording of the talk available on YouTube.

News

Best Paper Award – GPCE 2021

Our paper Multi-Stage Programming with Generative and Analytical Macros, by Nicolas Stucki, Jonathan Brachthäuser
Head of the SE research group
Jonathan Immanuel Brachthäuser
, and Martin Odersky was honored with the Best Paper Award at the International Conference on Generative Programming: Concepts & Experiences (GPCE 2021)

Read more ...