Almost first-class language embedding: taming staged embedded DSLs

Embedded domain-specific languages (EDSLs), inheriting a general-purpose language's features as well as look-and-feel, have traditionally been second-class or rather non-citizens in terms of host-language design. This makes sense when one regards them to be on the same level as traditional, non-EDSL library interfaces. However, this equivalence only applies to the simplest of EDSLs. In this paper we illustrate why this is detrimental when moving on to EDSLs that employ staging, i.e. program reification, by example of various issues that affect authors and users alike. We believe that if EDSLs are to be considered a reliable, language-like interface abstraction, they require exceptional attention and design scrutiny. Instead of unenforceable conventions, we advocate the acceptance of EDSLs as proper, i.e. almost first-class, citizens while retaining most advantages of pure embeddings. As a small step towards this goal, we present a pragmatic framework prototype for Java. It is based on annotations that explicate and document membership to explicit EDSL entities. In a nutshell, our framework identifies (annotated) method calls and field accesses as EDSL terms and dynamically constructs an abstract-syntax representation, which is eventually passed to a semantics-defining back end implemented by the EDSL author.

[1]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[2]  Gary A. Kildall,et al.  A unified approach to global program optimization , 1973, POPL.

[3]  Michael Eichberg,et al.  Reify your collection queries for modularity and speed! , 2012, AOSD.

[4]  Martin Odersky,et al.  Yin-yang: concealing the deep embedding of DSLs , 2015 .

[5]  Martin Odersky,et al.  Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs , 2010, GPCE '10.

[6]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[7]  Benjamin Chung,et al.  Safely Composable Type-Specific Languages , 2014, ECOOP.

[8]  Krzysztof Czarnecki,et al.  DSL Implementation in MetaOCaml, Template Haskell, and C++ , 2003, Domain-Specific Program Generation.

[9]  Walid Taha,et al.  Mint: Java multi-stage programming using weak separability , 2010, PLDI '10.

[10]  Joshua Bloch Effective Java (2nd Edition) (The Java Series) , 2008 .

[11]  Shigeru Chiba,et al.  Composable user-defined operators that can express user-defined literals , 2014, MODULARITY.

[12]  Steve Freeman,et al.  Evolving an embedded domain-specific language in Java , 2006, OOPSLA '06.

[13]  Magne Haveraaen,et al.  Design of the CodeBoost transformation system for domain-specific optimisation of C++ programs , 2003, Proceedings Third IEEE International Workshop on Source Code Analysis and Manipulation.

[14]  Kunle Olukotun,et al.  Go Meta! A Case for Generative Programming and DSLs in Performance Critical Systems , 2015, SNAPL.

[15]  Shigeru Chiba,et al.  Load-Time Structural Reflection in Java , 2000, ECOOP.

[16]  Graham Hutton,et al.  Programming in Haskell , 2007 .

[17]  Paul Graham On LISP: Advanced Techniques for Common LISP , 1993 .

[18]  Hao Xu EriLex: An Embedded Domain Specific Language Generator , 2010, TOOLS.

[19]  W. Taha,et al.  Plenary talk III Domain-specific languages , 2008, 2008 International Conference on Computer Engineering & Systems.

[20]  Emil Axelsson,et al.  Combining Deep and Shallow Embedding for EDSL , 2012, Trends in Functional Programming.

[21]  Kunle Olukotun,et al.  Building-Blocks for Performance Oriented DSLs , 2011, DSL.

[22]  Shigeru Chiba,et al.  Implicit Staging of EDSL Expressions: A Bridge between Shallow and Deep Embedding , 2014, ECOOP.

[23]  Yannis Smaragdakis,et al.  JTS: tools for implementing domain-specific languages , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[24]  Simon Peyton Jones,et al.  Template meta-programming for Haskell , 2002, ACM SIGPLAN Notices.

[25]  Nicolas Wu,et al.  Folding domain-specific languages , 2014, ICFP.

[26]  David Fine The Cambridge Companion to the Literature of Los Angeles Kevin R. McNamara , 2011 .

[27]  Paul Hudak,et al.  Modular domain specific languages and tools , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[28]  Oege de Moor,et al.  Compiling embedded languages , 2003, J. Funct. Program..

[29]  Laurence Tratt,et al.  Domain specific language implementation via compile-time meta-programming , 2008, TOPL.

[30]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[31]  Martin Fowler,et al.  Domain-Specific Languages , 2010, The Addison-Wesley signature series.

[32]  Martin Odersky,et al.  Higher-order and Symbolic Computation Manuscript No. Scala-virtualized: Linguistic Reuse for Deep Embeddings , 2022 .

[33]  Walid Taha,et al.  Multi-Stage Programming: Its Theory and Applications , 1999 .

[34]  Kunle Olukotun,et al.  Surgical precision JIT compilers , 2014, PLDI.

[35]  Calvin Lin,et al.  Broadway: A Compiler for Exploiting the Domain-Specific Semantics of Software Libraries , 2005, Proceedings of the IEEE.