Abstract
A reflective language makes the language semantics open to user programs and allows them to access, extend, and modify it from within the same language framework. Because of its high flexibility and expressiveness, it can be an ideal platform for programming language research as well as practical applications in dynamic environments. However, efficient implementation of a reflective language is extremely difficult. Under the circumstance where the language semantics can change, a partial evaluator is required for compilation. This paper reports on the experience of using MetaOCaml as a compiler for a reflective language. With staging annotations, MetaOCaml achieves the same effect as using a partial evaluator. Unlike the standard partial evaluator, the run mechanism of MetaOCaml enables us to use the specialized (compiled) code in the current runtime environment. On the other hand, the lack of a binding-time analysis in MetaOCaml prohibits us from compiling a user program under modified compiled semantics.
- Asai, K. “Integrating Partial Evaluators into Interpreters," In W. Taha, editor, Semantics, Applications, and Implementation of Program Generation (LNCS 2196), pp. 126–145 (September 2001). Google Scholar
Digital Library
- Asai, K. “Reflection in Direct Style," Proceedings of the Tenth ACM International Conference on Generative Programming and Component Engineering (GPCE ’11), pp. 97–106 (October 2011). Google Scholar
Digital Library
- Asai, K., S. Matsuoka, and A. Yonezawa “Duplication and Partial Evaluation — For a Better Understanding of Reflective Languages —,” Lisp and Symbolic Computation, Vol. 9, Nos. 2/3, pp. 203–241, Kluwer Academic Publishers (May/June 1996). Google Scholar
Digital Library
- Danvy, O., and K. Malmkjær “Intensions and Extensions in a Reflective Tower," Conference Record of the 1988 ACM Symposium on Lisp and Functional Programming, pp. 327–341 (July 1988). Google Scholar
Digital Library
- Danvy, O., K. Malmkjær, and J. Palsberg “The Essence of Eta-Expansion in Partial Evaluation," Lisp and Symbolic Computation, Vol. 8, No. 3, pp. 209–227, Kluwer Academic Publishers (1995). Google Scholar
Digital Library
- Friedman, D. P., and M. Wand “Reification: Reflection without Metaphysics," Conference Record of the 1984 ACM Symposium on Lisp and Functional Programming, pp. 348–355 (August 1984). Google Scholar
Digital Library
- Futamura, Y. “Partial evaluation of computation process – an approach to a compiler-compiler," Systems, Computers, Controls, Vol. 2, No. 5, pp. 45–50, (1971), reprinted in Higher-Order and Symbolic Computation, Vol. 12, No. 4, pp. 381–391, Kluwer Academic Publishers (December 1999). Google Scholar
Digital Library
- Herrmann, C. A., and T. Langhammer “Combining partial evaluation and staged interpretation in the implementation of domain-specific languages," Science of Computer Programming, Vol. 62, pp. 47–65, Elsevier (June 2006). Google Scholar
Digital Library
- Jones, N. D., C. K. Gomard, and P. Sestoft Partial Evaluation and Automatic Program Generation, New York: Prentice-Hall (1993). Google Scholar
Digital Library
- Kiczales, G., J. des Rivières, and D. G. Bobrow The Art of the Metaobject Protocol, Cambridge: MIT Press (1991). Google Scholar
Digital Library
- Kiczales, G., J. Lamping, A. Mendhekar, C. Maeda, C. Videira Lopes, J-M. Loingtier, and J. Irwin “Aspect-Oriented Programming," Proceedings of the European Conference on Object-Oriented Programming (ECOOP’97), pp. 220–242 (1997).Google Scholar
- Linger, N., and T. Sheard “Binding-Time Analysis for MetaML via Type Inference and Constraint Solving," In K. Jensen and A. Podelski, editors, Tools and Algorithms for the Construction and Analysis of Systems (LNCS 2988), pp. 266–279 (March 2004).Google Scholar
- Masuhara, H., G. Kiczales, and C. Dutchyn “A Compilation and Optimization Model for Aspect-Oriented Programs," Proceedings of the 12th International Conference on Compiler Construction (CC2003), LNCS 2622, pp. 46–60 (April 2003). Google Scholar
Digital Library
- Masuhara, H., S. Matsuoka, K. Asai, and A. Yonezawa “Compiling Away the Meta-Level in Object-Oriented Concurrent Reflective Languages Using Partial Evaluation,” Tenth Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA ’95), pp. 300–315, (October 1995). Google Scholar
Digital Library
- Reynolds, J. C. “Definitional Interpreters for Higher-Order Programming Languages," Proceedings of the ACM National Conference, Vol. 2, pp. 717–740, (August 1972), reprinted in Higher-Order and Symbolic Computation, Vol. 11, No. 4, pp. 363–397, Kluwer Academic Publishers (December 1998). Google Scholar
Digital Library
- Rompf, T., and M. Odersky “Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs," Proceedings of the Ninth International Conference on Generative Programming and Component Engineering (GPCE ’10), pp. 127–136 (October 2010). Google Scholar
Digital Library
- Shali, A., and W. R. Cook “Hybrid Partial Evaluation," Proceedings of the ACM International Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA ’11), pp. 375–390, (October 2011). Google Scholar
Digital Library
- Smith, B. C. “Reflection and Semantics in Lisp," Conference Record of the 14th Annual ACM Symposium on Principles of Programming Languages, pp. 23–35 (January 1984). Google Scholar
Digital Library
- Taha, W. “A Gentle Introduction to Multi-stage Programming," In C. Lengauer, D. Batory, C. Consel, and M. Odersky, editors, Domain-Specific Program Generation (LNCS 3016), pp. 30–50 (2004).Google Scholar
- Thiemann, P. J., and D. Dussart “Partial Evaluation for Higher-Order Languages with State," Available at http://www.informatik.uni-freiburg.de/˜thiemann/papers/ mlpe.ps.gz.Google Scholar
- Verwaest, T., C. Bruni, D. Gurtner, A. Lienhard, and O. Niestrasz “PINOCCHIO: Bringing Reflection to Life with First-Class Interpreters," Proceedings of the ACM International Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA ’10), pp. 774–789, (October 2010). Google Scholar
Digital Library
- Wand, M., and D. P. Friedman “The Mystery of the Tower Revealed: A Non-Reflective Description of the Reflective Tower," Conference Record of the 1986 ACM Symposium on Lisp and Functional Programming, pp. 298–307 (August 1986). Google Scholar
Digital Library
Index Terms
Compiling a reflective language using MetaOCaml
Recommendations
Reflection in direct style
GCPE '11A reflective language enables us to access, inspect, and/or modify the language semantics from within the same language framework. Although the degree of semantics exposure differs from one language to another, the most powerful approach, referred to as ...
Compiling a reflective language using MetaOCaml
GPCE 2014: Proceedings of the 2014 International Conference on Generative Programming: Concepts and ExperiencesA reflective language makes the language semantics open to user programs and allows them to access, extend, and modify it from within the same language framework. Because of its high flexibility and expressiveness, it can be an ideal platform for ...
Reflection in direct style
GPCE '11: Proceedings of the 10th ACM international conference on Generative programming and component engineeringA reflective language enables us to access, inspect, and/or modify the language semantics from within the same language framework. Although the degree of semantics exposure differs from one language to another, the most powerful approach, referred to as ...






Comments