skip to main content

Macros for domain-specific languages

Published:13 November 2020Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

oopsla20main-p625-p-video.mp4

mp4

161.7 MB

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Lennart Augustsson. 1985. Compiling pattern matching. In Proc. Functional Programming Languages and Computer Architecture. 368-381.Google ScholarGoogle ScholarCross RefCross Ref
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Ryan Culpepper. 2012. Fortifying macros. Journal of Functional Programming 22, 4-5 ( Sept. 2012 ), 439-476. https: //doi.org/10.1017/S0956796812000275 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarCross RefCross Ref
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. Daniel P. Friedman, William E. Byrd, Oleg Kiselyov, and Jason Hemann. 2018. The Reasoned Schemer (second ed.). The MIT Press, Cambridge, MA.Google ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. Robert Grimm. 2004. Practical Packrat Parsing. Technical Report TR2004-854. New York University.Google ScholarGoogle Scholar
  24. 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 ScholarGoogle ScholarCross RefCross Ref
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. Erik Hilsdale and Daniel P. Friedman. 2000. Writing macros in continuation-passing style. In Proc. Workshop on Scheme and Functional Programming. 53.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. Donald Ervin Knuth. 1979. TEX and METAFONT: New directions in typesetting. American Mathematical Society.Google ScholarGoogle Scholar
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. Shriram Krishnamurthi. 2001. Linguistic Reuse. Ph.D. Dissertation. Rice University.Google ScholarGoogle Scholar
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. Jay McCarthy. 2010. The two-state solution. In Proc. Object-Oriented Programming Systems, Languages & Applications (OOPSLA '10). 567-582.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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 ScholarGoogle Scholar
  38. Philippe Meunier and Daniel Silva. 2003. From Python to PLT Scheme. In Proc. Workshop on Scheme and Functional Programming. 24-29.Google ScholarGoogle Scholar
  39. 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 ScholarGoogle ScholarCross RefCross Ref
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarCross RefCross Ref
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. Sam Tobin-Hochstadt. 2011. Extensible pattern matching in an extensible language. ( 2011 ). arXiv: 1106.2578v1Google ScholarGoogle Scholar
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. 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 ScholarGoogle ScholarCross RefCross Ref
  52. 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 ScholarGoogle ScholarCross RefCross Ref
  53. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Macros for domain-specific languages

      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