skip to main content
article

Compiling a reflective language using MetaOCaml

Published:15 September 2014Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Jones, N. D., C. K. Gomard, and P. Sestoft Partial Evaluation and Automatic Program Generation, New York: Prentice-Hall (1993). Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Kiczales, G., J. des Rivières, and D. G. Bobrow The Art of the Metaobject Protocol, Cambridge: MIT Press (1991). Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle Scholar
  12. 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 ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle Scholar
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Compiling a reflective language using MetaOCaml

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!