Abstract
Multi-stage programming (MSP) is a paradigm for developing generic software that does not pay a runtime penalty for this generality. This is achieved through concise, carefully-designed language extensions that support runtime code generation and program execution. Additionally, type systems for MSP languages are designed to statically ensure that dynamically generated programs are type-safe, and therefore require no type checking after they are generated.
This hands-on tutorial is aimed at the reader interested in learning the basics of MSP practice. The tutorial uses a freely available MSP extension of OCaml called MetaOCaml, and presents a detailed analysis of the issues that arise in staging an interpreter for a small programming language. The tutorial concludes with pointers to various resources that can be used to probe further into related topics.
Supported by NSF ITR-0113569 and NSF CCR-0205542.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Bawden, A.: Quasiquotation in LISP. In: Danvy, O. (ed.) Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Manipulation, San Antonio, pp. 88–99. University of Aarhus, Dept. of Computer Science (1999) (invited talk)
Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using asts, gensym, and reflection. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003)
Consel, C., Danvy, O.: Tutorial notes on partial evaluation. In: ACM Symposium on Principles of Programming Languages, pp. 493–501 (1993)
Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W.: DSL Implementation in MetaOCaml, Template Haskell, and C++. In: Lengauer, C., Batory, D., Consel, C., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 51–72. Springer, Heidelberg (2004)
Danvy, O.: Semantics-directed compilation of non-linear patterns. Technical Report 303, Indiana University, Bloomington, Indiana, USA (1990)
Jones, N.D.: What not to do when writing an interpreter for specialisation. In: Danvy, O., Thiemann, P., Glück, R. (eds.) Dagstuhl Seminar 1996. LNCS, vol. 1110, pp. 216–237. Springer, Heidelberg (1996)
Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)
Lawall, J.L., Danvy, O.: Continuation-based partial evaluation. In: 1994 ACM Conference on Lisp and Functional Programming, Orlando, Florida, June 1994, pp. 227–238. ACM, New York (1994)
Leroy, X.: Objective Caml (2000), Available from: http://caml.inria.fr/ocaml/
Complete source code for lint (2003), Available online from: http://www.metaocaml.org/examples/lint.ml
MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from: http://www.metaocaml.org/
The MetaML Home Page (2000), Provides source code and documentation online at: http://www.cse.ogi.edu/PacSoft/projects/metaml/index.html
Oregon Graduate Institute Technical Reports. P.O. Box 91000, Portland, OR 97291-1000,USA, Available online from: ftp://cse.ogi.edu/pub/tech-reports/README.html
Pašalić, E., Taha, W., Sheard, T.: Tagless staged interpreters for typed languages. In: The International Conference on Functional Programming (ICFP 2002), Pittsburgh, USA, October 2002. ACM, New York (2002)
Sheard, T.: Accomplishments and research challenges in meta-programming. In: Batory, D., Consel, C., Taha, W. (eds.) GPCE 2002. LNCS, vol. 2487, pp. 2–44. Springer, Heidelberg (2002)
Sheard, T., Benaissa, Z.E.-A., Pašalić, E.: DSL implementation using staging and monads. In: Second Conference on Domain-Specific Languages (DSL 1999), Austin, Texas, USENIX (1999)
Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999); Available from [13]
Taha, W.: A sound reduction semantics for untyped CBN multi-stage computation. Or, the theory of MetaML is non-trivial. In: Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Maniplation (PEPM), Boston. ACM Press, New York (2000)
Taha, W., Makholm, H.: Tag elimination – or – type specialisation is a type-indexed effect. In: Subtyping and Dependent Types in Programming, APPSEM Workshop. INRIA technical report (2000)
Taha, W., Makholm, H., Hughes, J.: Tag elimination and jones-optimality. In: Danvy, O., Filinski, A. (eds.) PADO 2001. LNCS, vol. 2053, pp. 257–275. Springer, Heidelberg (2001)
Taha, W., Nielsen, M.F.: Environment classifiers. In: The Symposium on Principles of Programming Languages (POPL 2003), New Orleans (2003)
Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: Proceedings of the Symposium on Partial Evaluation and Semantic-Based Program Manipulation (PEPM), Amsterdam, pp. 203–217. ACM Press, New York (1997)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Taha, W. (2004). A Gentle Introduction to Multi-stage Programming. In: Lengauer, C., Batory, D., Consel, C., Odersky, M. (eds) Domain-Specific Program Generation. Lecture Notes in Computer Science, vol 3016. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-25935-0_3
Download citation
DOI: https://doi.org/10.1007/978-3-540-25935-0_3
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-22119-7
Online ISBN: 978-3-540-25935-0
eBook Packages: Springer Book Archive