[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
research-article
Open access

Macros for domain-specific languages

Published: 13 November 2020 Publication History

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.

Supplementary Material

Auxiliary Presentation Video (oopsla20main-p625-p-video.mp4)
Macros provide a powerful means of extending languages. They have proven useful in both general-purpose and domain-specific programming contexts. This talk 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.

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
[2]
Lennart Augustsson. 1985. Compiling pattern matching. In Proc. Functional Programming Languages and Computer Architecture. 368-381.
[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
[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
[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
[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
[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
[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
[9]
Ryan Culpepper. 2012. Fortifying macros. Journal of Functional Programming 22, 4-5 ( Sept. 2012 ), 439-476. https: //doi.org/10.1017/S0956796812000275
[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
[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
[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
[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
[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=PoHGvY4RZ9U
[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
[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
[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
[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
[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
[20]
Daniel P. Friedman, William E. Byrd, Oleg Kiselyov, and Jason Hemann. 2018. The Reasoned Schemer (second ed.). The MIT Press, Cambridge, MA.
[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
[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
[23]
Robert Grimm. 2004. Practical Packrat Parsing. Technical Report TR2004-854. New York University.
[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
[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
[26]
Erik Hilsdale and Daniel P. Friedman. 2000. Writing macros in continuation-passing style. In Proc. Workshop on Scheme and Functional Programming. 53.
[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
[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
[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
[30]
Donald Ervin Knuth. 1979. TEX and METAFONT: New directions in typesetting. American Mathematical Society.
[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
[32]
Shriram Krishnamurthi. 2001. Linguistic Reuse. Ph.D. Dissertation. Rice University.
[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
[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
[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
[36]
Jay McCarthy. 2010. The two-state solution. In Proc. Object-Oriented Programming Systems, Languages & Applications (OOPSLA '10). 567-582.
[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.pdf
[38]
Philippe Meunier and Daniel Silva. 2003. From Python to PLT Scheme. In Proc. Workshop on Scheme and Functional Programming. 24-29.
[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
[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
[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
[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
[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
[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
[45]
Sam Tobin-Hochstadt. 2011. Extensible pattern matching in an extensible language. ( 2011 ). arXiv: 1106.2578v1
[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
[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
[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
[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
[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
[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
[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
[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

Cited By

View all
  • (2024)DSLs in Racket: You Want It How, Now?Proceedings of the 17th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3687997.3695645(84-103)Online publication date: 17-Oct-2024
  • (2024)Compiled, Extensible, Multi-language DSLs (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36746278:ICFP(64-87)Online publication date: 15-Aug-2024
  • (2023)A pred-LL(*) Parsable Typed Higher-Order Macro System for Architecture Description LanguagesProceedings of the 22nd ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3624007.3624052(29-41)Online publication date: 22-Oct-2023
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 4, Issue OOPSLA
November 2020
3108 pages
EISSN:2475-1421
DOI:10.1145/3436718
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 13 November 2020
Published in PACMPL Volume 4, Issue OOPSLA

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. extensible domain specific languages
  2. hygiene
  3. macros

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)616
  • Downloads (Last 6 weeks)85
Reflects downloads up to 12 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)DSLs in Racket: You Want It How, Now?Proceedings of the 17th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3687997.3695645(84-103)Online publication date: 17-Oct-2024
  • (2024)Compiled, Extensible, Multi-language DSLs (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36746278:ICFP(64-87)Online publication date: 15-Aug-2024
  • (2023)A pred-LL(*) Parsable Typed Higher-Order Macro System for Architecture Description LanguagesProceedings of the 22nd ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3624007.3624052(29-41)Online publication date: 22-Oct-2023
  • (2023)How Domain Experts Use an Embedded DSLProceedings of the ACM on Programming Languages10.1145/36228517:OOPSLA2(1499-1530)Online publication date: 16-Oct-2023
  • (2023)Rhombus: A New Spin on Macros without All the ParenthesesProceedings of the ACM on Programming Languages10.1145/36228187:OOPSLA2(574-603)Online publication date: 16-Oct-2023
  • (2023)Enterprise Platform and Integration Concepts Research at HPIACM SIGMOD Record10.1145/3582302.358232251:4(68-73)Online publication date: 25-Jan-2023
  • (2023)The World of Graph Databases from An Industry PerspectiveACM SIGMOD Record10.1145/3582302.358232051:4(60-67)Online publication date: 25-Jan-2023
  • (2023)Collaborative Data Science using Scalable HomoiconicityACM SIGMOD Record10.1145/3582302.358231651:4(54-55)Online publication date: 25-Jan-2023
  • (2023)Report on the First International Workshop on Data Systems Education (DataEd '22)ACM SIGMOD Record10.1145/3582302.358231451:4(49-53)Online publication date: 25-Jan-2023
  • (2023)PDQ 2.0ACM SIGMOD Record10.1145/3582302.358230851:4(36-41)Online publication date: 25-Jan-2023
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media