Mixed-Level Embedding and JIT Compilation for an Iteratively Staged DSL

This paper explores how to implement an iteratively staged domain-specific language (DSL) by embedding into a functional language. The domain is modelling and simulation of physical systems where models are expressed in terms of non-causal differential-algebraic equations; i.e., sets of constraints solved through numerical simulation. What distinguishes our language is that the equational constraints are first class entities allowing for an evolving model structure characterised by repeated generation of updated constraints. Hence iteratively staged. Our DSL can thus be seen as a combined functional and constraint programming language, albeit a two-level one, with the functional language chiefly serving as a meta language. However, the two levels do interact throughout the simulation. The embedding strategy we pursue is a mixture of deep and shallow, with the deep embedding enabling justin-time (JIT) compilation of the constraints as they are generated for efficiency, while the shallow embedding is used for the remainder for maximum leverage of the host language. The paper is organised around a specific DSL, but our implementation strategy should be applicable for iteratively staged languages in general. Our DSL itself is further a novel variation of a declarative constraint programming language.

[1]  Geoffrey Mainland Why it's nice to be quoted: quasiquoting for haskell , 2007, Haskell '07.

[2]  Xiang Li Intelligent object-oriented modelling , 1996 .

[3]  Carol S. Woodward,et al.  Enabling New Flexibility in the SUNDIALS Suite of Nonlinear and Differential/Algebraic Equation Solvers , 2020, ACM Trans. Math. Softw..

[4]  M. Otter,et al.  Modelica - A Unified Object-Oriented Language for Physical Systems Modeling - Language Specification , 2000 .

[5]  Henrik Nilsson,et al.  Embedding a Functional Hybrid Modelling Language in Haskell , 2008, IFL.

[6]  H. Nilsson,et al.  EXPLOITING STRUCTURAL DYNAMISM IN FUNCTIONAL HYBRID MODELLING FOR SIMULATION OF IDEAL DIODES , 2010 .

[7]  David Broman,et al.  Higher-Order Acausal Models , 2009, EOOLT.

[8]  Oege de Moor,et al.  Compiling embedded languages , 2000, Journal of Functional Programming.

[9]  Dirk Zimmer Introducing Sol: A General Methodology for Equation-Based Modeling of Variable-Structure Systems , 2008 .

[10]  Henrik Nilsson,et al.  Higher-Order Non-Causal Modelling and Simulation of Structurally Dynamic Systems , 2009 .

[11]  Hilding Elmqvist,et al.  Modelica — A unified object-oriented language for physical systems modeling , 1997 .

[12]  Matt Welsh,et al.  Flask: staged functional programming for sensor networks , 2008, ICFP.

[13]  Paul Hudak,et al.  Functional Hybrid Modeling from an Object-Oriented Perspective , 2007, EOOLT.

[14]  Henrik Nilsson,et al.  Functional reactive programming, continued , 2002, Haskell '02.

[15]  Walid Taha Semantics, Applications, and Implementation of Program Generation , 2003, J. Funct. Program..

[16]  Paul Hudak,et al.  Functional Hybrid Modeling , 2003, PADL.

[17]  Stefan Monnier,et al.  A type-preserving compiler in Haskell , 2008, ICFP.

[18]  Walid Taha,et al.  Semantics, Applications, and Implementation of Program Generation , 2001, Lecture Notes in Computer Science.

[19]  Walid Taha,et al.  A Gentle Introduction to Multi-stage Programming , 2003, Domain-Specific Program Generation.

[20]  Fraunhofer Iis,et al.  MOSILAB: Development of a Modelica based generic simulation tool supporting model structural dynamics , 2005 .

[21]  Morten Rhiger,et al.  A foundation for embedded languages , 2002, TOPL.

[22]  David Broman,et al.  Equation-Based Object-Oriented Languages and Tools , 2008, ECOOP Workshops.

[23]  M. Hanus,et al.  Curry: A Truly Functional Logic Language , 1995 .

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

[25]  Ganesh Sittampalam,et al.  Paradise: a two-stage DSL embedded in Haskell , 2008, ICFP.

[26]  G. Keller,et al.  GPU Kernels as Data-Parallel Array Computations in Haskell , 2009 .

[27]  Chris Lattner,et al.  LLVM: AN INFRASTRUCTURE FOR MULTI-STAGE OPTIMIZATION , 2000 .

[28]  COIS E. CELLIER Object{oriented Modeling: Means for Dealing with System Complexity , 1996 .

[29]  Martin Odersky,et al.  Domain-Specific Program Generation , 2004, Lecture Notes in Computer Science.

[30]  Paul Hudak,et al.  Functional reactive animation , 1997, ICFP '97.