Extensibility Didier Verna DSL Overview DSLs from the Perspective of Extensible Taxonomy Extensibility Languages Example Internal External Conclusion Discussion Didier Verna didier@lrde.epita.fr http://www.lrde.epita.fr/˜didier ACCU 2012 – Thursday, April 26th 1/32
Introduction The Challenges in DSL design and implementation Extensibility Orthogonal expertise Didier Verna ◮ Application domain ◮ Language design and implementation DSL Overview Taxonomy DSLs vs GPLs Extensibility Example ◮ � = syntax Internal ◮ � = semantics External Conclusion ◮ DSLs and GPLs need to be completely different. Discussion Really ? 2/32
Table of contents Extensibility Didier Verna DSL Overview 1 DSL Overview Taxonomy of DSLs Taxonomy Extensibility Extensibility at a glance Example Internal External Conclusion A concrete example 2 Discussion Building the DSL Externalizing it Conclusion 3 Discussion 3/32
Taxonomy of DSLs [Fowler, 2005, Tratt, 2008] Extensibility Didier Verna DSL Overview Taxonomy Extensibility Example Internal External Conclusion Discussion 5/32
Extensibility at a glance I [van Deursen et al., 2000, Vasudevan and Tratt, 2011] Extensibility User-defined data types and (infix) operators Didier Verna Algol 68 [Denert et al., 1975, Pagan, 1979] DSL Overview Operator overloading Taxonomy Extensibility C++ [McNamara and Smaragdakis, 2000] Example Compile-Time Meta-Programming Internal External C++ templates [Prud’homme, 2006] Conclusion Template Haskell, Meta OCaml [Czarnecki et al., 2004] Discussion Meta Lua, Converge, Nermerle [Tratt, 2005, Fleutot and Tratt, 2007, Skalski et al., 2004]. . . Functional languages (Haskell, ML) [Kamin, 1998, Elliott, 1999, Hudak, 1998] 6/32
Extensibility at a glance II [van Deursen et al., 2000, Vasudevan and Tratt, 2011] Extensibility Forth: Operator extensibility + CTMP Didier Verna [Ahson and Lamba, 1985] DSL Overview Scala [Rompf et al., 2011] Taxonomy Extensibility Marginally: T EX, m4 Example Internal External Conclusion Discussion 7/32
Example Command-line options highlighting Extensibility Didier Verna DSL Overview Taxonomy Extensibility Example Internal External Conclusion Discussion Properties (bold, underline, foreground color. . . ) Faces (localized property set) Themes (face trees) 9/32
Step 1: the basic thing Extensibility Didier Verna ( setq default − theme ( make − instance ’ face :name ’ t o p l e v e l : background ’ black DSL Overview : subfaces ( l i s t ( make − instance ’ face :name ’ option Taxonomy : foreground ’ white Extensibility : subfaces ( l i s t ( make − instance ’ face :name ’ syntax Example : bold t : foreground ’ cyan ) Internal ( make − instance ’ face :name ’ usage External : foreground ’ yellow ) ) ) ) ) ) Conclusion Discussion Problems with make-instance : 1 Class name exposed 2 Name argument optional 10/32
Step 2: an instantiation wrapper Extensibility Didier Verna ( setq default − theme ( make − face ’ t o p l e v e l : background ’ black DSL Overview : subfaces ( l i s t ( make − face ’ option Taxonomy : foreground ’ white Extensibility : subfaces ( l i s t ( make − face ’ syntax Example : bold t : foreground ’ cyan ) Internal ( make − face ’ usage External : foreground ’ yellow ) ) ) ) ) ) Conclusion Discussion Problems: 1 Explicit toplevel face name 2 Explicit creation of sub-faces list 3 Lots of calls to make-face 4 Lots of quoting 11/32
Step 3: a theme creation wrapper Solution to problem #1 Extensibility Didier Verna ( setq default − theme (make − theme : background ’ black DSL Overview : subfaces ( l i s t ( make − face ’ option Taxonomy : foreground ’ white Extensibility : subfaces ( l i s t ( make − face ’ syntax Example : bold t : foreground ’ cyan ) Internal ( make − face ’ usage External : foreground ’ yellow ) ) ) ) ) ) Conclusion Discussion Problems: 1 Explicit toplevel face name 2 Explicit creation of sub-faces list 3 Lots of calls to make-face 4 Lots of quoting 12/32
Step 4: C LOS and the MOP Solution to problem #2 Extensibility Generic functions, methods Didier Verna ( defmethod func ( ( arg1 class1 ) arg2 . . . ) DSL Overview body ) Taxonomy Extensibility Example ◮ Methods are outside the classes (ordinary function calls) Internal External ◮ Multiple dispatch (multi-methods) Conclusion Discussion The C LOS Meta-Object Protocol ( MOP ) C LOS itself is object-oriented ◮ The C LOS MOP : a de facto implementation standard ◮ The C LOS components (classes etc. ) are (meta-)objects of some (meta-)classes ◮ initialize-instance is a generic function 13/32
Step 4: C LOS and the MOP Solution to problem #2 Extensibility Didier Verna ( setq default − theme (make − theme : background ’ black DSL Overview : face ( make − face ’ option Taxonomy : foreground ’ white Extensibility : face ( make − face ’ syntax : bold t : foreground ’ cyan ) Example : face ( make − face ’ usage : foreground ’ yellow ) ) ) ) Internal External Conclusion Discussion Problems: 1 Explicit toplevel face name 2 Explicit creation of sub-faces list 3 Lots of calls to make-face 4 Lots of quoting 14/32
Step 5: syntax extension Solution to problem #3 Extensibility readtable : currently active syntax extensions table Didier Verna macro character : special syntactic meaning DSL Overview reader macro : implements macro character behavior Taxonomy Extensibility Example Internal External Conclusion Discussion 15/32
Step 5: syntax extension Solution to problem #3 Extensibility Didier Verna ( setq default − theme (make − theme : background ’ black DSL Overview : face { ’ option : foreground ’ white Taxonomy : face { ’ syntax : bold t : foreground ’ cyan } Extensibility : face { ’ usage : foreground ’ yellow } Example } ) ) Internal External Conclusion Discussion Problems: 1 Explicit toplevel face name 2 Explicit creation of sub-faces list 3 Lots of calls to make-face 4 Lots of quoting 16/32
Step 6: macros Solution to problem #4 Extensibility Ordinary Lisp functions Didier Verna Work on chunks of code (as data) DSL Overview Tranform expressions into a new expression Taxonomy Extensibility Compile-time effect Example Internal Control over evaluation External Conclusion Discussion 17/32
Step 6: macros Solution to problem #4 Extensibility Didier Verna ( setq default − theme ( define − theme : background black DSL Overview : face { option : foreground white Taxonomy : face { syntax : bold t : foreground cyan } Extensibility : face { usage : foreground yellow } Example } ) ) Internal External Conclusion Discussion Problems: 1 Explicit toplevel face name 2 Explicit creation of sub-faces list 3 Lots of calls to make-face 4 Lots of quoting 18/32
Final result Extensibility Looks pretty much like a DSL to me. . . Didier Verna ; ; My personal theme with so cool colors DSL Overview Taxonomy : background black Extensibility : face { option : foreground white Example : face { syntax : bold t : foreground cyan } : face { usage : foreground yellow } } Internal External Conclusion Discussion read , eval and possibly compile 19/32
Conclusion Extensibility Impact of GPL on DSL design and implementation Didier Verna Key GPL aspect: extensibility DSL Overview Embedded homogeneous approach Taxonomy Extensibility ◮ A single language Example ◮ DSL infrastructure smaller Internal External ◮ DSL both internal and external Conclusion Common Lisp Discussion ◮ Functional, Imperative, Object-Oriented ◮ MOP ◮ CTMP ◮ Syntax extension ◮ read , eval , compile 21/32
Internal vs External DSLs [Kamin, 1998, Czarnecki et al., 2004] Extensibility Suboptimal syntax ok but. . . Didier Verna Not ok: ◮ [Fowler, 2010]: “external DSLs have their own custom DSL Overview Taxonomy syntax and you write a full parser to process them” Extensibility ◮ [Kamin, 1998, Czarnecki et al., 2004]: “a prerequisite Example Internal for embedding is that the syntax for the new language External be a subset of the syntax for the host language” Conclusion ◮ BTW, same disagreement at the semantic level (MOP) Discussion Poor error reporting ◮ Research: [Tratt, 2008] ◮ Lisp: ? (but Cf. condition system & restarts) 22/32
Controversial aspects of extensibility Extensibility Dynamic typing Didier Verna ◮ pros: end-user friendly ◮ cons: run-time type errors / checking DSL Overview Taxonomy ◮ Research: [Taha and Sheard, 1997] Extensibility ◮ Hybrid languages (Cf. Racket) Example Internal Lazy Evaluation External ◮ pros: infinite data structures, new control primitives etc. Conclusion Discussion ◮ cons: pure functional languages only ◮ Lisp: lazyness through macros (not as straightforward), but side-effects for free, and still functional. 23/32
The root of (Lisp) extensibility Extensibility Reflexion Didier Verna ◮ Introspection ◮ Intercession DSL Overview Taxonomy Implementation Extensibility Example ◮ By API Internal ◮ Inherent: “homoiconicity” [McIlroy, 1960, Kay, 1969] External Conclusion Further distinction [Maes, 1987, Smith, 1984] Discussion ◮ Structural reflexion (program) ◮ Behavioral reflexion (language) 24/32
Recommend
More recommend