Abstract
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 just-in-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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Augustsson, L., Mansell, H., Sittampalam, G.: Paradise: a two-stage DSL embedded in Haskell. In: Proceeding of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP 2008), pp. 225–228. ACM Press, New York (2008)
Broman, D., Fritzson, P.: Higher-order acausal models. In: Fritzson, P., Cellier, F., Broman, D. (eds.) Proceedings of the 2nd International Workshop on Equation-Based Object-Oriented Languages and Tools, Paphos, Cyprus. Linköping Electronic Conference Proceedings, vol. 29, pp. 59–69. Linköping University Electronic Press (2008)
Cellier, F.E.: Object-oriented modelling: Means for dealing with system complexity. In: Proceedings of the 15th Benelux Meeting on Systems and Control, pp. 53–64 (1996)
Elliott, C., Finne, S., de Moor, O.: Compiling embedded languages. In: Taha, W. (ed.) SAIG 2000. LNCS, vol. 1924, pp. 9–27. Springer, Heidelberg (2000)
Elliott, C., Hudak, P.: Functional reactive animation. In: Proceedings of International Conference on Functional Programming, pp. 163–173 (June 1997)
Giorgidze, G., Nilsson, H.: Embedding a functional hybrid modelling language in Haskell. In: Proceedings of the 20th International Symposium on the Implementation and Application of Functional Languages. University of Hertfordshire, Hatfield (September 2008)
Giorgidze, G., Nilsson, H.: Higher-order non-causal modelling and simulation of structurally dynamic systems. In: Proceedings of the 7th International Modelica Conference, Como, Italy. Linköping Electronic Conference Proceedings, Linköping University Electronic Press (September 2009)
Guillemette, L.-J., Monnier, S.: A type-preserving compiler in Haskell. In: ICFP 2008: Proceeding of the 13th ACM SIGPLAN International Conference on Functional Programming, pp. 75–86. ACM, New York (2008)
Hanus, M., Kuchen, H., Moreno-Navarro, J.J.: Curry: A truly functional logic language. In: Proceedings Workshop on Visions for the Future of Logic Programming, Portland, Oregon, USA, pp. 95–107 (December 1995)
Hindmarsh, A.C., Brown, P.N., Grant, K.E., Lee, S.L., Serban, R., Shumaker, D.E., Woodward, C.S.: Sundials: Suite of nonlinear and differential/algebraic equation solvers. ACM Trans. Math. Softw. 31(3), 363–396 (2005)
Hudak, P.: Modular domain specific languages and tools. In: Proceedings of Fifth International Conference on Software Reuse, pp. 134–142 (June 1998)
Lattner, C.: LLVM: An infrastructure for multi-stage optimization. Master’s thesis, Computer Science Dept., University of Illinois at Urbana-Champaign, Urbana, IL (December 2002), http://llvm.org
Lee, S., Chakravarty, M., Grover, V., Keller, G.: GPU kernels as data-parallel array computations in Haskell. In: Workshop on Exploiting Parallelism using GPUs and other Hardware-Assisted Methods (2009)
Mainland, G.: Why it’s nice to be quoted: quasiquoting for Haskell. In: Proceedings of the ACM SIGPLAN Workshop on Haskell Workshop, pp. 73–82. ACM, New York (2007)
Mainland, G., Morrisett, G., Welsh, M.: Flask: Staged functional programming for sensor networks. In: Proceedings of the Thirteenth ACM SIGPLAN International Conference on Functional Programming, Victoria, British Columbia, Canada. ACM Press, New York (September 2008)
The Modelica Association. Modelica – A Unified Object-Oriented Language for Physical Systems Modeling: Tutorial version 1.4 (December 2000)
The Modelica Association: Modelica – A Unified Object-Oriented Language for Physical Systems Modeling: Language Specification version 3.0 (September 2007), http://www.modelica.org/documents/ModelicaSpec30.pdf
Nilsson, H., Courtney, A., Peterson, J.: Functional reactive programming, continued. In: Proceedings of the 2002 ACM SIGPLAN Haskell Workshop, Pittsburgh, Pennsylvania, USA, pp. 51–64. ACM Press, New York (October 2002)
Nilsson, H., Giorgidze, G.: Exploiting structural dynamism in Functional Hybrid Modelling for simulation of ideal diodes. In: Proceedings of the 7th EUROSIM Congress on Modelling and Simulation, Prague, Czech Republic. Czech Technical University Publishing House (September 2010)
Nilsson, H., Peterson, J., Hudak, P.: Functional hybrid modeling. In: Dahl, V. (ed.) PADL 2003. LNCS, vol. 2562, pp. 376–390. Springer, Heidelberg (2002)
Nilsson, H., Peterson, J., Hudak, P.: Functional hybrid modeling from an object-oriented perspective. In: Fritzson, P., Cellier, F., Nytsch-Geusen, C. (eds.) Proceedings of the 1st International Workshop on Equation-Based Object-Oriented Languages and Tools (EOOLT), Berlin, Germany. Linköping Electronic Conference Proceedings, vol. 24, pp. 71–87. Linköping University Electronic Press (2007)
Nytsch-Geusen, C., Ernst, T., Nordwig, A., Schwarz, P., Schneider, P., Vetter, M., Wittwer, C., Nouidui, T., Holm, A., Leopold, J., Schmidt, G., Mattes, A., Doll, U.: MOSILAB: Development of a Modelica based generic simulation tool supporting model structural dynamics. In: Proceedings of the 4th International Modelica Conference, Hamburg, Germany, pp. 527–535 (2005)
Rhiger, M.: A foundation for embedded languages. ACM Trans. Program. Lang. Syst. 25(3), 291–315 (2003)
Taha, W.: A gentle introduction to multi-stage programming. In: Lengauer, C., Batory, D., Blum, A., Vetta, A. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 30–50. Springer, Heidelberg (2004)
Zimmer, D.: Introducing Sol: A general methodology for equation-based modeling of variable-structure systems. In: Proceedings of the 6th International Modelica Conference, Bielefeld, Germany, pp. 47–56 (2008)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2011 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Giorgidze, G., Nilsson, H. (2011). Mixed-Level Embedding and JIT Compilation for an Iteratively Staged DSL. In: Mariño, J. (eds) Functional and Constraint Logic Programming. WFLP 2010. Lecture Notes in Computer Science, vol 6559. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-20775-4_3
Download citation
DOI: https://doi.org/10.1007/978-3-642-20775-4_3
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-20774-7
Online ISBN: 978-3-642-20775-4
eBook Packages: Computer ScienceComputer Science (R0)