“Bootstrapping a Compiler for an Equation-Based Object-Oriented Language”

Authors: Martin Sjölund, Peter Fritzson and Adrian Pop,
Affiliation: Linköping University
Reference: 2014, Vol 35, No 1, pp. 1-19.

Keywords: compilation,equation-based,object-oriented,meta-programming,modeling

Abstract: What does it mean to bootstrap a compiler, and why do it? This paper reports on the first bootstrapping of a full-scale EOO (Equation-based Object-Oriented) modeling language such as Modelica. Bootstrapping means that the compiler of a language can compile itself. However, the usual application area for the Modelica is modeling and simulation of complex physical systems. Fortunately it turns out that with some minor extensions, the Modelica language is well suited for the modeling of language semantics. We use the name MetaModelica for this slightly extended Modelica. This is a prerequisite for bootstrapping which requires that the language can be used to model and/or implement itself. The OpenModelica Compiler (OMC) has been written in this MetaModelica language. It originally supported only the standard Modelica language but has been gradually extended to also cover the MetaModelica language extensions. After substantial work, OMC is able to quickly compile itself and produces an executable with good performance. The benefits include a more extensible and maintainable compiler by introducing improved language constructs and a more powerful runtime that makes it easy to add functionality such as parser generators, debuggers, and profiling tools. Future work includes extracting and restructuring parts of OMC, making the compiler smaller and more modular and extensible. This will also make it easier to interface with OMC, making it possible to create more powerful and user-friendly OpenModelica-based tools. The compiler and its bootstrapping is a major effort -- it is currently about 330 000 lines of code, and the MetaModelica extensions are used routinely by approximately ten developers on a daily basis.

PDF PDF (448 Kb)        DOI: 10.4173/mic.2014.1.1

DOI forward links to this article:
[1] Adrian Pop, Martin Sjölund, Adeel Ashgar, Peter Fritzson and Francesco Casella (2014), doi:10.4173/mic.2014.2.3
[2] Åke Kinnander, Martin Sjölund and Adrian Pop (2016), doi:10.4173/mic.2016.4.3
[3] John Tinnerholm, Martin Sjölund and Adrian Pop (2019), doi:10.1145/3365984.3365990
[4] Peter Fritzson, Adrian Pop, Karim Abdelhak, Adeel Ashgar, Bernhard Bachmann, Willi Braun, Daniel Bouskela, Robert Braun, Lena Buffoni, Francesco Casella, Rodrigo Castro, Rudiger Franke, Dag Fritzson, (2020), doi:10.4173/mic.2020.4.1
[5] Lena Buffoni, Lennart Ochel, Adrian Pop, Peter Fritzson, Niklas Fors, Gorel Hedin, Walid Taha and Martin Sjolund (2021), doi:10.3390/electronics10080902
References:
[1] Amdahl, G.M. (1967). Validity of the single processor approach to achieving large scale computing capabilities, In Proceedings of the April 18-20, 1967, Spring Joint Computer Conference, AFIPS '67 (Spring). ACM, New York, NY, USA, pages 483--485, 1967. doi:10.1145/1465482.1465560
[2] Appel, A.W., Mattson, J.S., and Tarditi, D.R. (1994). A lexical analyzer generator for Standard ML, 1994. http://www.smlnj.org/doc/ML-Lex/manual.html.
[3] Bachmann, B., editor. (2008). Proceedings of the 6th International Modelica Conference, Modelica Association.
[4] Barton, P.I. and Pantelides, C.C. (1994). Modeling of combined discrete/continuous processes, AIChE Journal. 40:966--979. doi:10.1002/aic.690400608
[5] Blume, M. (2001). CMB - The SML/NJ Bootstrap Compiler - User Manual, 2001. http://www.smlnj.org/doc/CM/btcomp/.
[6] Boehm, H.-J., Demers, A.J., and Shenker, S. (1991). Mostly parallel garbage collection, SIGPLAN Not.. 26(6):157--164. doi:10.1145/113446.113459
[7] Boehm, H.-J. and Weiser, M. (1988). Garbage collection in an uncooperative environment, Software: Practice and Experience. 18(9):807--820. doi:10.1002/spe.4380180902
[8] Brück, D., Elmqvist, H., Olsson, H., and Mattsson, S.E. (2002). Dymola for multi-engineering modeling and simulation, In modelica2002.
[9] Broman, D. (2010). Meta-Languages and Semantics for Equation-Based Modeling and Simulation, Doctoral thesis No 1333, Department of Computer and Information Science, Linköping University, Sweden. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-58743.
[10] Brus, S. (2009). Bootstrapping the OpenModelica Compiler: Implementing Functions as Arguments, Bachelor's thesis draft, Linköping University. Not published.
[11] Casella, F., editor. (2009). Proceedings of the 7th International Modelica Conference, Linköping University Electronic Press.
[12] Chailloux, E., Manoury, P., and Pagano, B. (2000). Developing applications with Objective Caml, O'Reilly and Associates. http://caml.inria.fr/pub/docs/oreilly-book/ocaml-ora-book.pdf.
[13] Clauß, C., editor. (2011). Proceedings of the 8th International Modelica Conference, Linköping University Electronic Press.
[14] Elmqvist, H. (1978). A Structured Model Language for Large Continuous Systems, Ph.D. thesis, Department of Automatic Control, Lund University, Sweden.
[15] Elmqvist, H., Mattsson, S.E., and Otter, M. (1999). Modelica - a language for physical system modeling, visualization and interaction, In Proceedings of the 1999 IEEE International Symposium on Computer-Aided Control System Design. pages 630 --639. doi:10.1109/CACSD.1999.808720
[16] Equa AB. (2002). IDA Simulation Environment, 2002. http://www.equa.se/eng.se.html.
[17] Fritzson, P. (2004). Principles of Object-Oriented Modeling and Simulation with Modelica 2, 1. Wiley-IEEE Press.
[18] Fritzson, P. (2005). Language modeling and symbolic transformations with Meta-Modelica, 2005. http://openmodelica.org, Later versions openmodelica.org:fritzson:meta:2007:citerelated,openmodelica.org:fritzson:meta1.0:citerelated.
[19] Fritzson, P. (2007). Language modeling and symbolic transformations with Meta-Modelica, 2007. http://openmodelica.org, Slightly updated version of openmodelica.org:fritzson:meta:2005:citerelated; later update openmodelica.org:fritzson:meta1.0:citerelated.
[20] Fritzson, P. (2011). Introduction to Modeling and Simulation of Technical and Physical Systems with Modelica, Wiley-IEEE Press.
[21] Fritzson, P. (2014). Principles of Object-Oriented Modeling and Simulation with Modelica 3, 3: A Cyber-Physical Approach. Wiley-IEEE Press.
[22] Fritzson, P., Aronsson, P., Lundvall, H., Nyström, K., Pop, A., Saldamli, L., and Broman, D. (2005). The OpenModelica Modeling, Simulation, and Software Development Environment, Simulation News Europe, 2005. 44(45).
[23] Fritzson, P. and Bunus, P. (2002). Modelica - a general object-oriented language for continuous and discrete-event system modeling and simulation, In Proceedings 35th Annual Simulation Symposium. pages 365--380. doi:10.1109/SIMSYM.2002.1000174
[24] Fritzson, P. and Engelson, V. (1998). Modelica - a unified object-oriented language for systems modeling, In E.Jul, editor, ECOOP’98 - Object-Oriented Programming, volume 1445 of Lecture Notes in Computer Science, pages 67--90. Springer Berlin / Heidelberg. doi:10.1007/BFb0054087
[25] Fritzson, P., Gunnarsson, J., and Jirstrand, M. (2002). Mathmodelica -- an extensible modeling and simulation environment with integrated graphics and literate programming, In modelica2002, pages 41--54.
[26] Fritzson, P. and Pop, A. (2011). Meta-programming and language modeling with MetaModelica 1, 0. Technical Report9, Linköping University, PELAB - Programming Environment Laboratory, 2011. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-66440, Almost identical to openmodelica.org:fritzson:meta:2007:citerelated, but tech. report.
[27] Fritzson, P. and Pop, A. (2011). Meta-programming and language modeling with MetaModelica 1, 0. Technical Report9, Linköping University, PELAB - Programming Environment Laboratory, 2011. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-66440.
[28] Fritzson, P., Pop, A., and Aronsson, P. (2005). Comprehensive meta-modeling and meta-programming capabilities in Modelica, In G.Schmitz, editor, Proceedings of the 4th International Modelica Conference. 2005.
[29] Fritzson, P., Pop, A., Broman, D., and Aronsson, P. (2009). Formal semantics based translator generation and tool development in practice, In C.Fidge, editor, Proceedings of the 2009 Australian Software Engineering Conference. IEEE Computer Society, Washington, DC, USA, pages 256--266, 2009. doi:10.1109/ASWEC.2009.46
[30] Fritzson, P., Pop, A., and Sjolund, M. (2011). Towards Modelica 4 meta-programming and language modeling with MetaModelica 2, 0. Technical Report 2011:10, Linköping University, PELAB - Programming Environment Laboratory. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-68361.
[31] Fritzson, P., Privitzer, P., Sjölund, M., and Pop, A. (2009). Towards a text generation template language for Modelica, In modelica2009, pages 193--207, 2009. doi:10.3384/ecp09430124
[32] Hindley, J.R. (1969). The principal type-scheme of an object in combinatory logic, Transactions of the American Mathematical Society. 146:29--60. http://www.jstor.org/stable/1995158.
[33] ITI GmbH. (2012). SimulationX, 2012. http://www.itisim.com/simulationx.html.
[34] Åkesson, J., Årzén, K.-E., Gäfvert, M., Bergdahl, T., and Tummescheit, H. (2010). Modeling and optimization with Optimica and JModelica, org - languages and tools for solving large-scale dynamic optimization problems. Computers & Chemical Engineering. 34(11):1737 -- 1749. doi:10.1016/j.compchemeng.2009.11.011
[35] Kloas, M., Friesen, V., and Simons, M. (1995). Smile - a simulation environment for energy systems, In Proceedings of the 5th International IMACS - Symposium on Systems Analysis and Simulation (SAS’95. Gordon and Breach Publishers, pages 503--506.
[36] Kofrakek, J., Matejak, M., and Privitzer, P. (2011). HumMod -- large scale physiological models in Modelica, In modelica2011, pages 713--724. doi:10.3384/ecp11063713
[37] Levine, J. (2009). flex & bison, O'Reilly Media.
[38] Lopez-Rojas, E.A. (2011). OMCCp: A MetaModelica Based Parser Generator Applied to Modelica, Master's thesis, Linköping University, Department of Computer and Information Science. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-68863.
[39] Maplesoft. (2012). MapleSim, 2012. http://www.maplesoft.com/.
[40] Milner, R. (1978). A theory of type polymorphism in programming, Journal of Computer and System Sciences. 17:348--375.
[41] Milner, R., Tofte, M., Harper, R., and MacQueen, D. (1997). The Definition of Standard ML, MIT Press, Cambridge, MA, USA.
[42] MLton. (2011). Installation instructions (bootstrapping), 2011. http://mlton.org/PortingMLton.
[43] Modelica Association. (2010). Minutes of the Modelica Design Meeting 67, 2010. http://modelica.org.
[44] Modelica Association. (2012). Modelica: A unified object-oriented language for physical systems modeling, language specification version 3, 3. 2012. http://www.modelica.org/.
[45] Modelica Association. (2013). Modelica Standard Library version 3, 2.1. 2013. https://modelica.org/libraries.
[46] Nilsson, H., Peterson, J., and Hudak, P. (2007). Functional hybrid modeling from an object-oriented perspective, In P.Fritzson, F.Cellier, and C.Nytsch-Geusen, editors, Proceedings of the 1st International Workshop on Equation-Based Object-Oriented Modeling Languages and Tools. Linköping University Electronic Press. http://www.ep.liu.se/ecp/024/.
[47] Nilsson, U. and Maluszynski, J. (1995). Logic, Programming and Prolog (2ed), John Wiley & Sons Ltd. http://www.ida.liu.se/ulfni/lpp/.
[48] Odersky, M., Spoon, L., and Venners, B. (2008). Programming in Scala: A Comprehensive Step-by-step Guide, Artima Incorporation, USA, 1st edition.
[49] Otter, M., editor. (2002). Proceedings of the 2nd International Modelica Conference, Modelica Association.
[50] Otter, M. and Zimmer, D., editors. (2012). Proceedings of the 9th International Modelica Conference, Linköping University Electronic Press.
[51] Palanisamy, A., Pop, A., Sjölund, M., and Fritzson, P. (2014). Modelica based parser generator with good error handling, In H.Tummescheit and K.-E. Årzén, editors, Proceedings of the 10th International Modelica Conference. Modelica Association and Linköping University Electronic Press. doi:10.3384/ecp14096567
[52] Parr, T. (2010). ANTLR parser generator 3, 3. 2010. http://www.antlr.org/.
[53] Pettersson, M. (1995). Compiling Natural Semantics, Doctoral thesis No 413, Department of Computer and Information Science, Linköping University, Sweden, 1995. Also published in openmodelica.org:pettersson:lncs:1999.
[54] Pettersson, M. (1995). Compiling Natural Semantics, Doctoral thesis No 413, Department of Computer and Information Science, Linköping University, Sweden, 1995.
[55] Pettersson, M. (1999). Compiling Natural Semantics, volume 1549 of Lecture Notes in Computer Science, Springer. doi:10.1007/b71652
[56] Peyton Jones, S. etal. (2003). The Haskell 98 language and libraries: The revised report, Journal of Functional Programming. 13(1). doi:10.1017/S0956796803000315
[57] Pop, A. (2008). Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages, Doctoral thesis No 1183, Department of Computer and Information Science, Linköping University, Sweden.
[58] Pop, A. and Fritzson, P. (2006). Metamodelica: A unified equation-based semantical and mathematical modeling language, In D.Lightfoot and C.Szyperski, editors, Modular Programming Languages, volume 4228 of Lecture Notes in Computer Science, pages 211--229. Springer Berlin / Heidelberg. doi:10.1007/11860990_14
[59] Pop, A., Fritzson, P., Remar, A., Jagudin, E., and Akhvlediani, D. (2006). OpenModelica development environment with Eclipse integration for browsing, modeling, and debugging, In C.Kral and A.Haumer, editors, Proceedings of the 5th International Modelica Conference. 2006.
[60] Pop, A., Sjölund, M., Asghar, A., Fritzson, P., and Casella, F. (2012). Static and dynamic debugging of Modelica models, In modelica2012. doi:10.3384/ecp12076443
[61] Pop, A., Stavåker, K., and Fritzson, P. (2008). Exception handling for Modelica, In modelica2008, pages 409--418.
[62] Sahlin, P. and Sowell, E.F. (1989). A neutral format for building simulation models, In Proceedings of the Conference on Building Simulation. pages 147--154.
[63] Sjölund, M. (2009). Bidirectional External Function Interface Between Modelica/MetaModelica and Java, Master's thesis, Linköping University, Department of Computer and Information Science. http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-20386.
[64] Sjölund, M., Fritzson, P., and Pop, A. (2011). Bootstrapping a Modelica compiler aiming at Modelica 4, In modelica2011. doi:10.3384/ecp11063510
[65] Stavåker, K., Pop, A., and Fritzson, P. (2008). Compiling and using pattern matching in Modelica, In modelica2008, pages 637--646.
[66] Steele, G.L., Jr. and Gabriel, R.P. (1993). The evolution of lisp, In The second ACM SIGPLAN conference on History of programming languages, HOPL-II. ACM, New York, NY, USA, pages 231--270. doi:10.1145/154766.155373
[67] Tarditi, D.R. and Appel, A.W. (2000). ML-Yacc User's Manual, 2000. http://www.smlnj.org/doc/ML-Yacc/.
[68] Tiller, M. (2001). Introduction to Physical Modeling with Modelica, Springer.
[69] Viklund, L., Herber, J., and Fritzson, P. (1992). The implementation of ObjectMath - a high-level programming environment for scientific computing, In U.Kastens and P.Pfahler, editors, Compiler Construction, volume 641 of Lecture Notes in Computer Science, pages 312--318. Springer Berlin / Heidelberg. doi:10.1007/3-540-55984-1_28
[70] Wilson, P.R. (1992). Uniprocessor garbage collection techniques, In Proceedings of the International Workshop on Memory Management, IWMM '92. Springer-Verlag, London, UK, pages 1--42.
[71] Wirth, N. (1971). The programming language Pascal, Acta Informatica. 1:35--63. doi:10.1007/BF00264291
[72] Wolfram Mathcore. (2012). System Modeler, 2012. http://mathcore.com/.
[73] Zimmer, D. (2010). Equation-based modeling of variable-structure systems, Ph.D. thesis, Eidgenössische Technische Hochschule ETH Zürich, Switzerland. doi:10.3929/ethz-a-006053740


BibTeX:
@article{MIC-2014-1-1,
  title={{Bootstrapping a Compiler for an Equation-Based Object-Oriented Language}},
  author={Sjölund, Martin and Fritzson, Peter and Pop, Adrian},
  journal={Modeling, Identification and Control},
  volume={35},
  number={1},
  pages={1--19},
  year={2014},
  doi={10.4173/mic.2014.1.1},
  publisher={Norwegian Society of Automatic Control}
};