Abstract
The paper addresses theoretical and practical aspects of implementing multi-stage languages using abstract syntax trees (ASTs), gensym, and reflection. We present an operational account of the correctness of this approach, and report on our experience with a bytecode compiler called MetaOCaml that is based on this strategy. Current performance measurements reveal interesting characteristics of the underlying OCaml compiler, and illustrate why this strategy can be particularly useful for implementing domain-specific languages in a typed, functional setting.
Funded by NSF ITR-0113569.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
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)
Benaissa, Z.E.-A., Moggi, E., Taha, W., Sheard, T.: Logical modalities and multi-stage programming. In: Federated Logic Conference (FLoC) Satellite Workshop on Intuitionistic Modal Logics and Applications (IMLA) (1999)
Calcagno, C., Moggi, E.: Adequacy and correctness for two-level languages (1998) (unpublished manuscript)
Calcagno, C., Moggi, E.: Multi-stage imperative languages: A conservative extension result. In: [41], pp. 92–107 (2000)
Calcagno, C., Moggi, E., Sheard, T.: Closed types for a safe imperative MetaML. Journal of Functional Programming (2003) (to appear)
Calcagno, C., Moggi, E., Taha, W.: Closed types as a simple approach to safe imperative multi-stage programming. In: Welzl, E., Montanari, U., Rolim, J.D.P. (eds.) ICALP 2000. LNCS, vol. 1853, pp. 25–36. Springer, Heidelberg (2000)
Clinger, W., Rees, J.: Macros that work. In: Proceedings of the ACM Symposium on Principles of Programming Languages (POPL), Orlando, pp. 155–162. ACM Press, New York (1991)
Consel, C., Noël, F.: A general approach for run-time specialization and its application to C. In. In: Proceedings of the ACM Symposium on Principles of Programming Languages (POPL), St. Petersburg Beach, pp. 145–156 (1996)
Consel, C., Pu, C., Walpole, J.: Incremental specialization: The key to high performance, modularity, and portability in operating systems. In: Proceedings of the Symposium on Partial Evaluation and Semantics-Based Program Manipulation, New York, pp. 44–46. ACM Press, New York (1993)
Danvy, O., Malmkjær, K.: Intensions and extensions in a reflective tower. In: Proceedings of the 1988 ACM Conference on LISP and Functional Programming, pp. 327–341. ACM Press, New York (1988)
Davies, R.: A temporal-logic approach to binding-time analysis. In: The Symposium on Logic in Computer Science (LICS 1996), New Brunswick, pp. 184–195. IEEE Computer Society Press, Los Alamitos (1996)
Davies, R., Pfenning, F.: A modal analysis of staged computation. In: The Symposium on Principles of Programming Languages (POPL 1996), St. Petersburg Beach, pp. 258–270 (1996)
Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in Scheme. Lisp and Symbolic Computation 5(4), 295–326 (1992)
Filinski, A.: A semantic account of type-directed partial evaluation. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 378–395. Springer, Heidelberg (1999)
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)
Ganz, S., Sabry, A., Taha, W.: Macros as multi-stage computations: Typesafe, generative, binding macros in MacroML. In: The International Conference on Functional Programming (ICFP 2001), Florence, Italy. ACM, New York (2001)
Glück, R., Jørgensen, J.: Efficient multi-level generating extensions for program specialization. In: Swierstra, S.D., Hermenegildo, M. (eds.) PLILP 1995. LNCS, vol. 982, pp. 259–278. Springer, Heidelberg (1995)
Glück, R., Jørgensen, J.: Fast binding-time analysis for multi-level specialization. In: Bjorner, D., Broy, M., Pottosin, I.V. (eds.) PSI 1996. LNCS, vol. 1181, pp. 261–272. Springer, Heidelberg (1996)
Glück, R., Nakashige, R., Zöchling, R.: Binding-time analysis applied to mathematical algorithms. In: Doležal, J., Fidler, J. (eds.) System Modelling and Optimization, pp. 137–146. Chapman & Hall, Boca Raton (1995)
Gomard, C.K., Jones, N.D.: A partial evaluator for untyped lambda calculus. Journal of Functional Programming 1(1), 21–69 (1991)
Hornof, L., Jim, T.: Certifying compilation and run-time code generation. Higher-Order and Symbolic Computation 12(4), 337–375 (1999)
Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)
Jones, N.D., Sestoft, P., Sondergraard, H.: An experiment in partial evaluation: The generation of a compiler generator. In: Jouannaud, J.-P. (ed.) RTA 1985. LNCS, vol. 202, pp. 124–140. Springer, Heidelberg (1985)
Keppel, D., Eggers, S.J., Henry, R.R.: A case for runtime code generation. Tech. Rep. 91-11-04, University of Washington (1991)
Kolhlbecker, E.E.: Syntactic Extensions in the Programming Language Lisp. PhD thesis, Indiana University, Bloomington, Indiana (1986)
Leroy, X.: Objective Caml (2000), Available from http://caml.inria.fr/ocaml/
Malmkjær, K.: On some semantic issues in the reflective tower. In: Schmidt, D.A., Main, M.G., Melton, A.C., Mislove, M.W. (eds.) MFPS 1989. LNCS, vol. 442, pp. 229–246. Springer, Heidelberg (1990)
Masuhara, H., Yonezawa, A.: Run-time bytecode specialization. In: Danvy, O., Filinski, A. (eds.) PADO 2001. LNCS, vol. 2053, p. 138. Springer, Heidelberg (2001)
MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from http://www.cs.rice.edu/~taha/MetaOCaml/
Moggi, E.: A categorical account of two-level languages. In: Mathematics Foundations of Program Semantics, Elsevier Science, Amsterdam (1997)
Moggi, E.: Functor categories and two-level languages. In: Nivat, M. (ed.) FOSSACS 1998. LNCS, vol. 1378, p. 211. Springer, Heidelberg (1998)
Moggi, E., Taha, W., Benaissa, Z.E.-A., Sheard, T.: An idealized MetaML: Simpler, and more expressive. In: Swierstra, S.D. (ed.) ESOP 1999. LNCS, vol. 1576, pp. 193–207. Springer, Heidelberg (1999)
Multi-stage programming (2003), http://www.cs.rice.edu/~taha/teaching/02F/511
Noël, F., Hornof, L., Consel, C., Lawall, J.L.: Automatic, templatebased run-time specialization: Implementation and experimental study. In: Proceedings of the 1998 International Conference on Computer Languages, pp. 132–142. IEEE Computer Society Press, Los Alamitos (1998)
Oregon Graduate Institute Technical Reports. P.O. Box 91000, Portland, OR 97291-1000,USA, Last viewed (August 1999), Available online, from ftp://cse.ogi.edu/pub/tech-reports/README.html
Pu, C., Walpole, J.: A study of dynamic optimization techniques: Lessons and directions in kernel design. Tech. Rep. CSE-93-007, Oregon Graduate Institute (1993), Available from [35]
Smith, B.C.: Reflection and Semantics in a Procedural Language. PhD thesis, Massachusetts Institute of Technology (1982)
Smith, B.C.: Reflection and semantics in LISP. In: ACM Symposium on Principles of Programming Languages, pp. 23–35 (1984)
Smith, F., Grossman, D., Morrisett, G., Hornof, L., Jim, T.: Compiling for template-based run-time code generation. Journal of Functional Programming (2002) ( to appear)
Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999); Available from [35]
Taha, W. (ed.): Semantics, Applications, and Implementation of Program Generation. LNCS, vol. 1924. Springer, Heidelberg (2000)
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., Benaissa, Z.-E.-A., Sheard, T.: Multi-stage programming: Axiomatization and type-safety. In: Larsen, K.G., Skyum, S., Winskel, G. (eds.) ICALP 1998. LNCS, vol. 1443, pp. 918–929. Springer, Heidelberg (1998)
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)
Taha, W., Sheard, T.: MetaML and multi-stage programming with explicit annotations. Tech. Rep. CSE-99-007, Department of Computer Science, Oregon Graduate Institute (1999); Extended version of [46], Available from [35]
Taha, W., Sheard, T.: MetaML: Multi-stage programming with explicit annotations. Theoretical Computer Science 248, 1–2 (2000); Revision of [47]
Thibault, S., Consel, C., Lawall, J.L., Marlet, R., Muller, G.: Static and dynamic program compilation by interpreter specialization. Higher-Order and Symbolic Computation 13(3), 161–178 (2000)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2003 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Calcagno, C., Taha, W., Huang, L., Leroy, X. (2003). Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection. In: Pfenning, F., Smaragdakis, Y. (eds) Generative Programming and Component Engineering. GPCE 2003. Lecture Notes in Computer Science, vol 2830. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-39815-8_4
Download citation
DOI: https://doi.org/10.1007/978-3-540-39815-8_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-20102-1
Online ISBN: 978-3-540-39815-8
eBook Packages: Springer Book Archive