Skip to main content

A Gentle Introduction to Multi-stage Programming

  • Chapter
Domain-Specific Program Generation

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 3016))

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 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)

    Google Scholar 

  2. 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)

    Chapter  Google Scholar 

  3. Consel, C., Danvy, O.: Tutorial notes on partial evaluation. In: ACM Symposium on Principles of Programming Languages, pp. 493–501 (1993)

    Google Scholar 

  4. 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)

    Chapter  Google Scholar 

  5. Danvy, O.: Semantics-directed compilation of non-linear patterns. Technical Report 303, Indiana University, Bloomington, Indiana, USA (1990)

    Google Scholar 

  6. 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)

    Google Scholar 

  7. Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)

    MATH  Google Scholar 

  8. 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)

    Chapter  Google Scholar 

  9. Leroy, X.: Objective Caml (2000), Available from: http://caml.inria.fr/ocaml/

  10. Complete source code for lint (2003), Available online from: http://www.metaocaml.org/examples/lint.ml

  11. MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from: http://www.metaocaml.org/

  12. The MetaML Home Page (2000), Provides source code and documentation online at: http://www.cse.ogi.edu/PacSoft/projects/metaml/index.html

  13. 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

  14. 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)

    Google Scholar 

  15. 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)

    Google Scholar 

  16. 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)

    Google Scholar 

  17. Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999); Available from [13]

    Google Scholar 

  18. 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)

    Google Scholar 

  19. 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)

    Google Scholar 

  20. 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)

    Chapter  Google Scholar 

  21. Taha, W., Nielsen, M.F.: Environment classifiers. In: The Symposium on Principles of Programming Languages (POPL 2003), New Orleans (2003)

    Google Scholar 

  22. 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)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics