A Gentle Introduction to Multi-stage Programming

  • Walid Taha
Part of the Lecture Notes in Computer Science book series (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.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 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. 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)CrossRefGoogle Scholar
  3. 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. 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)CrossRefGoogle Scholar
  5. 5.
    Danvy, O.: Semantics-directed compilation of non-linear patterns. Technical Report 303, Indiana University, Bloomington, Indiana, USA (1990)Google Scholar
  6. 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. 7.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)MATHGoogle Scholar
  8. 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)CrossRefGoogle Scholar
  9. 9.
    Leroy, X.: Objective Caml (2000), Available from: http://caml.inria.fr/ocaml/
  10. 10.
    Complete source code for lint (2003), Available online from: http://www.metaocaml.org/examples/lint.ml
  11. 11.
    MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from: http://www.metaocaml.org/
  12. 12.
    The MetaML Home Page (2000), Provides source code and documentation online at: http://www.cse.ogi.edu/PacSoft/projects/metaml/index.html
  13. 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. 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. 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. 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. 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. 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. 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. 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)CrossRefGoogle Scholar
  21. 21.
    Taha, W., Nielsen, M.F.: Environment classifiers. In: The Symposium on Principles of Programming Languages (POPL 2003), New Orleans (2003)Google Scholar
  22. 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)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2004

Authors and Affiliations

  • Walid Taha
    • 1
  1. 1.Department of Computer ScienceRice UniversityHoustonUSA

Personalised recommendations