Abstract
Macros provide a powerful means of extending languages. They have proven useful in both general-purpose and domain-specific programming contexts. This paper presents an architecture for implementing macro-extensible DSLs on top of macro-extensible host languages. The macro expanders of these DSLs inherit the syntax system, hygienic expansion, and more from the host. They transform the extensible DSL syntax into a DSL core language. This arrangement has several important consequences. It becomes straightforward to integrate the syntax of various DSLs and the host language when their expanders share these inherited components. Also, a DSL compiler may be designed around a fixed core language, even for an extensible DSL. Finally, macros empower programmers to safely grow DSLs on their own and tailor them to their needs.
Supplemental Material
- Leif Andersen, Stephen Chang, and Matthias Felleisen. 2017. Super 8 languages for making movies (functional pearl). Proc. ACM Program. Lang. 1, ICFP, Article 30 ( Aug. 2017 ), 29 pages. https://doi.org/10.1145/3110274 Google ScholarDigital Library
- Lennart Augustsson. 1985. Compiling pattern matching. In Proc. Functional Programming Languages and Computer Architecture. 368-381.Google ScholarCross Ref
- William E. Byrd, Michael Ballantyne, Gregory Rosenblatt, and Matthew Might. 2017. A unified approach to solving seven programming problems (functional pearl). Proc. ACM Program. Lang. 1, ICFP, Article 8 ( Aug. 2017 ), 26 pages. https://doi.org/10.1145/3110252 Google ScholarDigital Library
- Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming 19, 5 (Sept. 2009 ), 509-543. https://doi.org/10.1017/ S0956796809007205 Google ScholarDigital Library
- Stephen Chang, Michael Ballantyne, Milo Turner, and William J. Bowman. 2019. Dependent type systems as macros. Proc. ACM Program. Lang. 4, POPL, Article 3 ( Dec. 2019 ), 29 pages. https://doi.org/10.1145/3371071 Google ScholarDigital Library
- Stephen Chang, Alex Knauth, and Ben Greenman. 2017. Type systems as macros. In Proc. Principles of Programming Languages (POPL 2017 ). 694-705. https://doi.org/10.1145/3009837.3009886 Google ScholarDigital Library
- Thomas E. Cheatham. 1969. Motivation for extensible languages. ACM SIGPLAN Notices 4, 8 (Aug. 1969 ), 45-49. https: //doi.org/10.1145/1115858.1115869 Google ScholarDigital Library
- William Clinger and Jonathan Rees. 1991. Macros that work. In Proc. Principles of Programming Languages (POPL '91). 155-162. https://doi.org/10.1145/99583.99607 Google ScholarDigital Library
- Ryan Culpepper. 2012. Fortifying macros. Journal of Functional Programming 22, 4-5 ( Sept. 2012 ), 439-476. https: //doi.org/10.1017/S0956796812000275 Google ScholarDigital Library
- R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. 1993. Syntactic abstraction in Scheme. Lisp and Symbolic Computation 5, 4 (Dec. 1993 ), 295-326. https://doi.org/10.1007/BF01806308 Google ScholarDigital Library
- Sebastian Erdweg, Tillmann Rendel, Christian Kästner, and Klaus Ostermann. 2011. SugarJ: Library-based syntactic language extensibility. In Proc. Object-Oriented Programming Systems, Languages & Applications (OOPSLA '11). 391-406. https://doi.org/10.1145/2048066.2048099 Google ScholarDigital Library
- Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, Shriram Krishnamurthi, Eli Barzilay, Jay McCarthy, and Sam Tobin-Hochstadt. 2018. A programmable programming language. Commun. ACM 61, 3 (Feb. 2018 ), 62-71. https: //doi.org/10.1145/3127323 Google ScholarDigital Library
- Robert Bruce Findler, John Clements, Cormac Flanagan, Matthew Flatt, Shriram Krishnamurthi, Paul Steckler, and Matthias Felleisen. 2002. DrScheme: A programming environment for Scheme. Journal of Functional Programming 12, 2 ( 2002 ), 159-182. https://doi.org/10.1017/S0956796801004208 Google ScholarDigital Library
- Jack Firth. 2015. Generic syntax expanders and extensible macros. Video. In Fifth RacketCon. Retrieved September 14, 2020 from https://www.youtube.com/watch?v=PoHGvY4RZ9UGoogle Scholar
- David Fisher and Olin Shivers. 2008. Building language towers with Ziggurat. Journal of Functional Programming 18, 5 /6 (Sept. 2008 ), 707-780. https://doi.org/10.1017/S0956796808006928 Google ScholarCross Ref
- Matthew Flatt. 2002. Composable and compilable macros: You want it when?. In Proc. International Conference on Functional Programming (ICFP '02). 72-83. https://doi.org/10.1145/581478.581486 Google ScholarDigital Library
- Matthew Flatt. 2016. Binding as sets of scopes. In Proc. Principles of Programming Languages (POPL '16). 705-717. https: //doi.org/10.1145/2837614.2837620 Google ScholarDigital Library
- Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler. 2012. Macros that work together: Compile-time bindings, partial expansion, and definition contexts. Journal of Functional Programming 22, 2 (March 2012 ), 181-216. https://doi.org/10.1017/S0956796812000093 Google ScholarDigital Library
- Bryan Ford. 2004. Parsing expression grammars: A recognition-based syntactic foundation. In Proc. Principles of Programming Languages (POPL '04). 111-122. https://doi.org/10.1145/964001.964011 Google ScholarDigital Library
- Daniel P. Friedman, William E. Byrd, Oleg Kiselyov, and Jason Hemann. 2018. The Reasoned Schemer (second ed.). The MIT Press, Cambridge, MA.Google Scholar
- Jeremy Gibbons and Nicolas Wu. 2014. Folding domain-specific languages: Deep and shallow embeddings. In Proc. International Conference on Functional Programming (ICFP '14). 339-347. https://doi.org/10.1145/2628136.2628138 Google ScholarDigital Library
- Andy Gill. 2009. Type-safe observable sharing in Haskell. In Proc. Symposium on Haskell (Haskell '09). 117-128. https: //doi.org/10.1145/1596638.1596653 Google ScholarDigital Library
- Robert Grimm. 2004. Practical Packrat Parsing. Technical Report TR2004-854. New York University.Google Scholar
- SystemVerilog Language Working Group. 2005. IEEE standard for SystemVerilog: Unified hardware design, specification and verification language. IEEE Std 1800-2005 (Nov. 2005 ), 1-648. https://doi.org/10.1109/IEEESTD. 2005.97972 Google ScholarCross Ref
- William Gallard Hatch and Matthew Flatt. 2018. Rash: From reckless interactions to reliable programs. In Proc. Generative Programming: Concepts & Experience (GPCE 2018 ). 28-39. https://doi.org/10.1145/3278122.3278129 Google ScholarDigital Library
- Erik Hilsdale and Daniel P. Friedman. 2000. Writing macros in continuation-passing style. In Proc. Workshop on Scheme and Functional Programming. 53.Google Scholar
- Paul Hudak. 1996. Building domain-specific embedded languages. ACM Comput. Surv. 28, 4es (Dec. 1996 ), 196-es. https: //doi.org/10.1145/242224.242477 Google ScholarDigital Library
- Ted Kaminski, Lucas Kramer, Travis Carlson, and Eric Van Wyk. 2017. Reliable and automatic composition of language extensions to C: The ableC extensible language framework. Proc. ACM Program. Lang. 1, OOPSLA, Article 98 (Oct. 2017 ), 29 pages. https://doi.org/10.1145/3138224 Google ScholarDigital Library
- Lennart C. L. Kats and Eelco Visser. 2010. The Spoofax language workbench: Rules for declarative specification of languages and IDEs. In Proc. Object-Oriented Programming Systems, Languages & Applications. 444-463. https://doi.org/10.1145/ 1869459.1869497 Google ScholarDigital Library
- Donald Ervin Knuth. 1979. TEX and METAFONT: New directions in typesetting. American Mathematical Society.Google Scholar
- Eugene E. Kohlbecker, Daniel P. Friedman, Matthias Felleisen, and Bruce F. Duba. 1986. Hygienic macro expansion. In Proc. Lisp and Functional Programming (LFP '86). 151-161. https://doi.org/10.1145/319838.319859 Google ScholarDigital Library
- Shriram Krishnamurthi. 2001. Linguistic Reuse. Ph.D. Dissertation. Rice University.Google Scholar
- Fabrice Le Fessant and Luc Maranget. 2001. Optimizing pattern matching. In Proc. International Conference on Functional Programming (ICFP '01). 26-37. https://doi.org/10.1145/507635.507641 Google ScholarDigital Library
- Geofrey Mainland. 2007. Why it's nice to be quoted: quasiquoting for Haskell. In Proc. Symposium on Haskell (Haskell '07). 73-82. https://doi.org/10.1145/1291201.1291211 Google ScholarDigital Library
- Luc Maranget. 2008. Compiling pattern matching to good decision trees. In Proc. Workshop on ML (ML '08). 35-46. https://doi.org/10.1145/1411304.1411311 Google ScholarDigital Library
- Jay McCarthy. 2010. The two-state solution. In Proc. Object-Oriented Programming Systems, Languages & Applications (OOPSLA '10). 567-582.Google ScholarDigital Library
- John McCarthy, Paul W. Abrahams, Daniel J. Edwards, Timothy P. Hart, and Michael I. Levin. 1965. LISP 1.5 Programmer's Manual. The MIT Press, Cambridge, Massachusetts. Retrieved September 14, 2020 from http://www.softwarepreservation. org/projects/LISP/book/LISP%201.5%20Programmers% 20Manual.pdfGoogle Scholar
- Philippe Meunier and Daniel Silva. 2003. From Python to PLT Scheme. In Proc. Workshop on Scheme and Functional Programming. 24-29.Google Scholar
- Pierre Neron, Andrew Tolmach, Eelco Visser, and Guido Wachsmuth. 2015. A theory of name resolution. In Proc. European Symposium on Programming (ESOP '15). 205-231. https://doi.org/10.1007/978-3-662-46669-8_9 Google ScholarCross Ref
- Joe Gibbs Politz, Alejandro Martinez, Matthew Milano, Sumner Warren, Daniel Patterson, Junsong Li, Anand Chitipothu, and Shriram Krishnamurthi. 2013. Python: The full monty. In Proc. Object-Oriented Programming Systems, Languages & Applications (OOPSLA '13). 217-232. https://doi.org/10.1145/2509136.2509536 Google ScholarDigital Library
- Jon Rafkind and Matthew Flatt. 2012. Honu: Syntactic extension for algebraic notation through enforestation. In Proc. Generative Programming and Component Engineering (GPCE '12). 122-131. https://doi.org/10.1145/2371401.2371420 Google ScholarDigital Library
- Pedro Palma Ramos and António Menezes Leitão. 2014. Implementing Python for DrRacket. In Proc. Symposium on Languages, Applications and Technologies. 127-141. https://doi.org/10.4230/OASIcs.SLATE. 2014.127 Google ScholarCross Ref
- Olin Shivers. 2005. The anatomy of a loop: A story of scope and control. In Proc. International Conference on Functional Programming (ICFP '05). 2-14. https://doi.org/10.1145/1086365.1086368 Google ScholarDigital Library
- Peter Thiemann and Matthias Neubauer. 2008. Macros for context-free grammars. In Proc. Principles and Practice of Declarative Programming (PPDP '08). 120-130. https://doi.org/10.1145/1389449.1389465 Google ScholarDigital Library
- Sam Tobin-Hochstadt. 2011. Extensible pattern matching in an extensible language. ( 2011 ). arXiv: 1106.2578v1Google Scholar
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The design and implementation of Typed Scheme. In Proc. Principles of Programming Languages (POPL '08). 395-406. https://doi.org/10.1145/1328438.1328486 Google ScholarDigital Library
- Sam Tobin-Hochstadt, Vincent St-Amour, Ryan Culpepper, Matthew Flatt, and Matthias Felleisen. 2011. Languages as libraries. In Proc. Programming Language Design and Implementation (PLDI '11). 132-141. https://doi.org/10.1145/1993498.1993514 Google ScholarDigital Library
- Hendrik van Antwerpen, Casper Bach Poulsen, Arjen Rouvoet, and Eelco Visser. 2018. Scopes as types. Proc. ACM Program. Lang. 2, OOPSLA, Article 114 (Oct. 2018 ), 30 pages. https://doi.org/10.1145/3276484 Google ScholarDigital Library
- Hendrik van Antwerpen, Pierre Néron, Andrew Tolmach, Eelco Visser, and Guido Wachsmuth. 2016. A Constraint Language for Static Semantic Analysis Based on Scope Graphs. In Proc. Partial Evaluation and Program Manipulation (PEPM '16). 49-60. https://doi.org/10.1145/2847538.2847543 Google ScholarDigital Library
- Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh Krishnan. 2008. Silver: An extensible attribute grammar system. In Proc. Workshop on Language Descriptions, Tools, and Applications (LDTA '07). 103-116. https://doi.org/10.1016/j.entcs. 2008. 03. 047 Google ScholarDigital Library
- Markus Voelter. 2011. Language and IDE modularization and composition with MPS. In International Summer School on Generative and Transformational Techniques in Software Engineering (GTTSE '11). 383-430. https://doi.org/10.1007/978-3-642-35992-7_11 Google ScholarCross Ref
- Martin P Ward. 1994. Language-oriented programming. Software Concepts and Tools 15, 4 ( 1994 ), 147-161. https: //doi.org/10.1007/978-1-4302-2390-0_12 Google ScholarCross Ref
- Jan Wielemaker, Tom Schrijvers, Markus Triska, and Torbjörn Lager. 2012. SWI-Prolog. Theory and Practice of Logic Programming 12, 1-2 ( 2012 ), 67-96. https://doi.org/10.1017/S1471068411000494 Google ScholarDigital Library
Index Terms
- Macros for domain-specific languages
Recommendations
Composable and hygienic typed syntax macros
SAC '15: Proceedings of the 30th Annual ACM Symposium on Applied ComputingSyntax extension mechanisms are powerful, but reasoning about syntax extensions can be difficult. Recent work on type-specific languages (TSLs) addressed reasoning about composition, hygiene and typing for extensions introducing new literal forms. We ...
Composable and compilable macros:: you want it when?
Many macro systems, especially for Lisp and Scheme, allow macro transformers to perform general computation. Moreover, the language for implementing compile-time macro transformers is usually the same as the language for implementing run-time functions. ...
Composable and compilable macros:: you want it when?
ICFP '02: Proceedings of the seventh ACM SIGPLAN international conference on Functional programmingMany macro systems, especially for Lisp and Scheme, allow macro transformers to perform general computation. Moreover, the language for implementing compile-time macro transformers is usually the same as the language for implementing run-time functions. ...
Comments