Abstract
Embedded domain-specific languages (DSLs) are the subject of wide-spread interest, and a variety of implementation techniques exist. Some of them have been invented, and some of them discovered. Many are based on a form of generative or multi-stage programming, where the host language program builds up DSL terms during its evaluation. In this paper, we examine the execution model of LMS (Lightweight Modular Staging), a framework for embedded DSLs in Scala, and link it to evaluation in a two-stage lambda calculus. This clarifies the semantics of certain ad-hoc implementation choices, and provides guidance for implementing similar multi-stage evaluation facilities in other languages.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Ager, M.S., Danvy, O., Rohde, H.K.: Fast partial evaluation of pattern matching in strings. ACM Trans. Program. Lang. Syst. 28(4), 696–714 (2006)
Amarasinghe, S.P.: Petabricks: a language and compiler based on autotuning. In: Katevenis, M., Martonosi, M., Kozyrakis, C., Temam, O. (eds.) Proceedings of the 6th International Conference on High Performance Embedded Architectures and Compilers, HiPEAC 2011, Heraklion, Crete, Greece, 24–26 January 2011, p. 3. ACM (2011)
Axelsson, E., Claessen, K., Sheeran, M., Svenningsson, J., Engdal, D., Persson, A.: The design and implementation of feldspar: an embedded language for digital signal processing. In: Hage, J., Morazán, M.T. (eds.) IFL. LNCS, vol. 6647, pp. 121–136. Springer, Heidelberg (2011)
Beckmann, O., Houghton, A., Mellor, M.R., Kelly, P.H.J.: Runtime code generation in C++ as a foundation for domain-specific optimisation. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 291–306. Springer, Heidelberg (2004)
Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013. ACM (2013)
Bondorf, A.: Self-applicable partial evaluation. Ph.D. thesis, DIKU, Department of Computer Science, University of Copenhagen (1990)
Brown, K.J., Sujeeth, A.K., Lee, H., Rompf, T., Chafi, H., Odersky, M., Olukotun, K.: A heterogeneous parallel framework for domain-specific languages. In: PACT (2011)
Bulyonkov, M.A.: Polyvariant mixed computation for analyzer programs. Acta Inf. 21, 473–484 (1984)
Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using ASTs, gensym, and reflection. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003)
Carette, J., Kiselyov, O., Shan, C.C.: Finally tagless, partially evaluated: tagless staged interpreters forsimpler typed languages. J. Funct. Program. 19(5), 509–543 (2009)
Catanzaro, B., Garland, M., Keutzer, K.: Copperhead: compiling an embedded data parallel language. In: Proceedings of the 16th ACM Symposium on Principles and Practice of Parallel Programming, PPoPP, pp. 47–56. ACM, New York (2011)
Chafi, H., DeVito, Z., Moors, A., Rompf, T., Sujeeth, A.K., Hanrahan, P., Odersky, M., Olukotun, K.: Language virtualization for heterogeneous parallel computing. In: Onward! (2010)
Cheney, J., Lindley, S., Wadler, P.: A practical theory of language-integrated query. In: Morrisett, G., Uustalu, T. (eds.) ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, Boston, MA, USA, 25–27 September 2013, pp. 403–416. ACM (2013)
Click, C., Cooper, K.D.: Combining analyses, combining optimizations. ACM Trans. Program. Lang. Syst. 17, 181–196 (1995)
Consel, C., Danvy, O.: Partial evaluation of pattern matching in strings. Inf. Process. Lett. 30(2), 79–86 (1989)
Consel, C., Khoo, S.-C.: Parameterized partial evaluation. ACM Trans. Program. Lang. Syst. 15(3), 463–493 (1993)
Danvy, O.: Type-directed partial evaluation. In: Hatcliff, J., Mogensen, T.Æ., Thiemann, P. (eds.) DIKU 1998. LNCS, vol. 1706, pp. 367–411. Springer, Heidelberg (1999)
DeVito, Z., Hegarty, J., Aiken, A., Hanrahan, P., Vitek, J.: Terra: a multi-stage language for high-performance computing. In: Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013, pp. 105–116. ACM (2013)
DeVito, Z., Ritchie, D., Fisher, M., Aiken, A., Hanrahan, P.: First-class runtime generation of high-performance types using exotypes. In: O’Boyle, M.F.P., Pingali, K. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2014, Edinburgh, United Kingdom, 09–11 June 2014, p. 11. ACM (2014)
Elliott, C., Finne, S., de Moor, O.: Compiling embedded languages. J. Funct. Program. 13(3), 455–481 (2003)
Filinski, A.: Representing monads. In: Boehm, H., Lang, B., Yellin, D.M. (eds.) 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Conference Record of POPL 1994, Portland, Oregon, USA, 17–21 January 1994, pp. 446–457. ACM Press (1994)
Filinski, A.: Normalization by evaluation for the computational Lambda-Calculus. In: Abramsky, S. (ed.) TLCA 2001. LNCS, vol. 2044, pp. 151–165. Springer, Heidelberg (2001)
Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Cartwright, R. (ed.) Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation (PLDI), Albuquerque, New Mexico, USA, 23–25 June 1993, pp. 237–247. ACM (1993)
Frigo, M.: A fast fourier transform compiler. In: PLDI, pp. 169–180 (1999)
Gill, A.: Domain-specific languages and code synthesis using haskell. Queue 12(4), 30:30–30:43 (2014)
Grant, B., Mock, M., Philipose, M., Chambers, C., Eggers, S.J.: Dyc: an expressive annotation-directed dynamic compiler for c. Theoret. Comput. Sci. 248(1–2), 147–199 (2000)
Hanger, M., Johansen, T.A., Mykland, G.K., Skullestad, A.: Dynamic model predictive control allocation using CVXGEN. In: 9th IEEE International Conference on Control and Automation, ICCA 2011, Santiago, Chile, 19–21 December 2011, pp. 417–422. IEEE (2011)
Hatcliff, J., Danvy, O.: A computational formalization for partial evaluation. Math. Struct. Comput. Sci. 7(5), 507–541 (1997)
Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: Smaragdakis, Y., Siek, J.G. (eds.) GPCE, pp. 137–148. ACM (2008)
Hudak, P.: Building domain-specific embedded languages. ACM Comput. Surv. 28, 196 (1996)
Hudak, P.: Modular domain specific languages and tools. In: Proceedings of Fifth International Conference on Software Reuse, pp. 134–142, June 1998
Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall Inc., Upper Saddle River (1993)
Kiselyov, O., Swadi, K.N., Taha, W.: A methodology for generating verified combinatorial circuits. In: Buttazzo, G.C. (ed.) EMSOFT, pp. 249–258. ACM (2004)
Klimov, A.V.: A Java supercompiler and its application to verification of cache-coherence protocols. In: Pnueli, A., Virbitskaite, I., Voronkov, A. (eds.) PSI 2009. LNCS, vol. 5947, pp. 185–192. Springer, Heidelberg (2010)
Krishnamurthi, S.: Linguistic reuse. Ph.D. thesis, Computer Science, Rice University, Houston (2001)
Landin, P.J.: The next 700 programming languages. Commun. ACM 9(3), 157–166 (1966)
Lawall, J.L., Thiemann, P.: Sound specialization in the presence of computational effects. In: Abadi, M., Ito, T. (eds.) TACS 1997. LNCS, vol. 1281, pp. 165–190. Springer, Heidelberg (1997)
Lee, H., Brown, K.J., Sujeeth, A.K., Chafi, H., Rompf, T., Odersky, M., Olukotun, K.: Implementing domain-specific languages for heterogeneous parallel computing. IEEE Micro 31(5), 42–53 (2011)
Leijen, D., Meijer, E.: Domain specific embedded compilers. In: DSL, pp. 109–122 (1999)
Lindley, S.: Normalisation by evaluation in the compilation of typed functional programming languages (2005)
Mainland, G., Morrisett, G.: Nikola: embedding compiled GPU functions in Haskell. In: Proceedings of the Third ACM Haskell Symposium on Haskell, Haskell 2010, pp. 67–78. ACM, New York (2010)
McDonell, T.L., Chakravarty, M.M., Keller, G., Lippmeier, B.: Optimising purely functional GPU programs. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, pp. 49–60. ACM, New York (2013)
Mogensen, T.A.: Partially static structures in a self-applicable partial evaluator (1988)
Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991)
Najd, S., Lindley, S., Svenningsson, J., Wadler, P.: Everything old is new again: quoted domain specific languages. Technical report, University of Edinburgh (2015)
Nielson, F., Nielson, H.R.: Code generation from two-level denotational meta-languages. In: Ganzinger, H., Jones, N.D. (eds.) Programs as Data Objects. LNCS, vol. 217, pp. 192–205. Springer, Heidelberg (1986)
Nielson, F., Nielson, H.R.: Multi-level Lambda-Calculi: an algebraic description. In: Danvy, O., Glück, R., Thiemann, P. (eds.) Partial Evaluation. LNCS, vol. 1110, pp. 338–354. Springer, Heidelberg (1996)
Nystrom, N., White, D., Das, K.: Firepile: run-time compilation for GPUs in scala. In: Proceedings of the 10th ACM International Conference on Generative Programming and Component Engineering, GPCE, pp. 107–116. ACM, NewYork (2011)
Püschel, M., Moura, J.M.F., Singer, B., Xiong, J., Johnson, J., Padua, D.A., Veloso, M.M., Johnson, R.W.: Spiral: a generator for platform-adapted libraries of signal processing alogorithms. IJHPCA 18(1), 21–45 (2004)
Ragan-Kelley, J., Adams, A., Paris, S., Levoy, M., Amarasinghe, S.P., Durand, F.: Decoupling algorithms from schedules for easy optimization of image processing pipelines. ACM Trans. Graph. 31(4), 32 (2012)
Ragan-Kelley, J., Barnes, C., Adams, A., Paris, S., Durand, F., Amarasinghe, S.P.: Halide: a language and compiler for optimizing parallelism, locality, and recomputation in image processing pipelines. In: Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013, pp. 519–530. ACM (2013)
Reynolds, J.: User-defined types and procedural data structures as complementary approaches to data abstraction (1975)
Rompf, T.: Lightweight Modular Staging and Embedded Compilers: Abstraction Without Regret for High-Level High-Performance Programming. Ph.D. thesis, EPFL (2012)
Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. Commun. ACM 55(6), 121–130 (2012)
Rompf, T., Sujeeth, A.K., Amin, N., Brown, K., Jovanovic, V., Lee, H., Jonnalagedda, M., Olukotun, K., Odersky, M.: Optimizing data structures in high-level programs. In: POPL (2013)
Rompf, T., Sujeeth, A.K., Lee, H., Brown, K.J., Chafi, H., Odersky, M., Olukotun, K.: Building-blocks for performance oriented DSLs. In: DSL (2011)
Schultz, U.P., Lawall, J.L., Consel, C.: Automatic program specialization for java. ACM Trans. Program. Lang. Syst. 25(4), 452–499 (2003)
Shali, A., Cook, W.R.: Hybrid partial evaluation. In: OOPSLA, pp. 375–390 (2011)
Sørensen, M.H., Glück, R., Jones, N.D.: A positive supercompiler. J. Funct. Program. 6(6), 811–838 (1996)
Sperber, M., Thiemann, P.: Realistic compilation by partial evaluation. In: PLDI, pp. 206–214 (1996)
Sperber, M., Thiemann, P.: Generation of LR parsers by partial evaluation. ACM Trans. Program. Lang. Syst. 22(2), 224–264 (2000)
Steele, G.: Growing a language. High.-Order Symbolic Comput. 12(3), 221–236 (1999)
Sujeeth, A.K., Rompf, T., Brown, K.J., Lee, H., Chafi, H., Popic, V., Wu, M., Prokopec, A., Jovanovic, V., Odersky, M., Olukotun, K.: Composition and reuse with compiled domain-specific languages. In: Castagna, G. (ed.) ECOOP 2013. LNCS, vol. 7920, pp. 52–78. Springer, Heidelberg (2013)
Svensson, B.J., Sheeran, M., Newton, R.: Design exploration through code-generating DSLs. Queue 12(4), 40:40–40:52 (2014)
Taha, W., Sheard, T.: MetaML and multi-stage programming with explicit annotations. Theoret. Comput. Sci. 248(1–2), 211–242 (2000)
Thiemann, P.: Partially static operations. In: Albert, E., Mu, S.-C. (eds.) PEPM, pp. 75–76. ACM (2013)
Thiemann, P., Dussart, D.: Partial evaluation for higher-order languages with state. Technical report (1999)
Tobin-Hochstadt, S., St-Amour, V., Culpepper, R., Flatt, M., Felleisen, M.: Languages as libraries. In: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2011, pp. 132–141. ACM, New York (2011)
Turchin, V.F.: The concept of a supercompiler. ACM Trans. Program. Lang. Syst. 8(3), 292–325 (1986)
Whaley, R.C., Petitet, A., Dongarra, J.: Automated empirical optimizations of software and the ATLAS project. Parallel Comput. 27(1–2), 3–35 (2001)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Rompf, T. (2016). The Essence of Multi-stage Evaluation in LMS. In: Lindley, S., McBride, C., Trinder, P., Sannella, D. (eds) A List of Successes That Can Change the World. Lecture Notes in Computer Science(), vol 9600. Springer, Cham. https://doi.org/10.1007/978-3-319-30936-1_17
Download citation
DOI: https://doi.org/10.1007/978-3-319-30936-1_17
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-30935-4
Online ISBN: 978-3-319-30936-1
eBook Packages: Computer ScienceComputer Science (R0)