skip to main content
10.1145/1640134.1640141acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

Language embedding and optimization in mython

Published:26 October 2009Publication History

ABSTRACT

Mython is an extensible variant of the Python programming language. Mython achieves extensibility by adding a quotation mechanism that accepts an additional parameter as well as the code being quoted. The additional quotation parameter takes the form of a Mython expression. Unlike other user code, Mython evaluates the quotation parameter at compile-time. The result of the compile-time expression is a function that is used to both parse the quoted code, and extend the compile-time environment. By explicitly passing the compilation environment to compile-time quotation functions, Mython's parameterized quotation allows users to inject code into the language compiler. Injected code can extend the language by modifying the compilation phases, which are visible to the compilation environment. The Mython language is realized by the MyFront compiler, a tool for translating Mython into Python byte-code modules. This paper introduces the Mython language, describes the implementation and usage of the MyFront tool, and shows how MyFront can be used to implement domain-specific optimizations using a little rewrite language.

References

  1. Martin Bravenboer and Eelco Visser. Concrete syntax for objects. Domain-specifc language embedding and assimilation without restrictions. In Douglas C. Schmidt, editor, Proceedings of the 19th ACM SIGPLAN Conference on Object-Oriented Programing, Systems, Languages, and Applications (OOPSLA'04), pages 365--383, Vancouver, Canada, October 2004. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Brett Cannon. Python Enhancement Proposal PEP 339 - Design of the CPython Compiler, 2005. Available at http://www.python.org/dev/peps/pep-0339/.Google ScholarGoogle Scholar
  3. William Clinger and Jonathan Rees. Macros that work. In POPL '91: Proceedings of the 18th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 155--162, New York, NY, USA, 1991. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Duncan Coutts, Roman Leshchinskiy, and Don Stewart. Stream fusion: From lists to streams to nothing at all. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming, ICFP 2007, April 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Duncan Coutts, Don Stewart, and Roman Leshchinskiy. Rewriting Haskell Strings. In Practical Aspects of Declarative Languages 8th International Symposium, PADL 2007. Springer-Verlag, January 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R. Kent Dybvig. Writing hygienic macros in Scheme with syntax-case. Technical Report 356, Indiana University, Bloomington, Indiana, USA, June 1992.Google ScholarGoogle Scholar
  7. Matthew Fluet, Nic Ford, Mike Rainey, John Reppy, Adam Shaw, and Yingqi Xiao. Status Report: The Manticore Project. In Proceedings of the 2007 ACM SIGPLAN Workshop on ML, October 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Brian W. Kernignhan and Dennis M. Ritchie. The C Programming Language. Prentice Hall, Englewood Cliffs, NJ, USA, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. John K. Ousterhout. Tcl: An embeddable command language. In Proceedings of the Winter USENIX Conference, pages 133--145, January 1990.Google ScholarGoogle Scholar
  10. Simon Peyton Jones, Andrew Tolmach, and Tony Hoare. Playing by the rules: Rewriting as a practical optimisation technique in GHC. In Ralf Hinze, editor, Preliminary Proceedings of the 2001 ACM SIGPLAN Haskell Workshop (HW '01), pages 203--233, Firenze, Italy, September 2001.Google ScholarGoogle Scholar
  11. Ian Piumarta. Open, extensible dynamic programming systems - or just how deep is the dynamic rabbit hole?, October 2006. Presented at the Dynamic Languages Symposium (DLS) 2006. Slides available at http://www.swa.hpi.uni- potsdam.de/dls06/.Google ScholarGoogle Scholar
  12. Norman Ramsey. Embedding an interpreted language using higher-order functions and types. In IVME '03: Proceedings of the 2003 workshop on Interpreters, virtual machines and emulators, pages 6--14, New York, NY, USA, 2003. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Jonathan Riehl. Assimilating MetaBorg: Embedding language tools in languages. In Proceedings of the Fifth International Conference on Generative Programming and Component Engineering (GPCE'06), October 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Tavis Rudd. Cheetah - The Python-Powered Template Engine, 2007. Available at http://www.cheetahtemplate.org/.Google ScholarGoogle Scholar
  15. Bjarne Stroustrup. The Design and Evolution of C++. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Walid Taha. A gentle introduction to multi-stage programming. In Domain-Specifc Program Generation, pages 30--50, 2003.Google ScholarGoogle Scholar
  17. Guido van Rossum. Python Reference Manual (2.5), September 2006. Available at http://www.python.org/doc/2.5/ref/ref.html.Google ScholarGoogle Scholar
  18. Todd Veldhuizen. Using C++ template metaprograms. C++ Report, 7(4):36--43, May 1995. Reprinted in C++ Gems, ed. Stanley Lippman.Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Todd L. Veldhuizen. C++ templates as partial evaluation. In Proceedings of PEPM'99, The ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, ed. O. Danvy, San Antonio, January 1999., pages 13--18. University of Aarhus, Dept. of Computer Science, January 1999.Google ScholarGoogle Scholar
  20. Eelco Visser, Zine-el-Abidine Benaissa, and Andrew Tolmach. Building program optimizers with rewriting strategies. In Proceedings of the third ACM SIGPLAN International Conference on Functional Programming (ICFP'98), pages 13--26. ACM Press, September 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Philip Wadler. Deforestation: transforming programs to eliminate trees. Theoretical Computer Science, (Special issue of selected papers from 2nd European Symposium on Programming), 73(2):231--248, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Daniel C. Wang, Andrew W. Appel, Jeff L. Korn, and Chris S. Serra. The Zephyr Abstract Syntax Description Language. In Proceedings of the USENIX Conference on Domain-Specifc Languages, pages 213--228, October 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Language embedding and optimization in mython

      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
      • Published in

        cover image ACM Conferences
        DLS '09: Proceedings of the 5th symposium on Dynamic languages
        October 2009
        118 pages
        ISBN:9781605587691
        DOI:10.1145/1640134
        • Program Chair:
        • James Noble
        • cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 44, Issue 12
          DLS '09
          December 2009
          107 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1837513
          Issue’s Table of Contents

        Copyright © 2009 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 26 October 2009

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        DLS '09 Paper Acceptance Rate10of27submissions,37%Overall Acceptance Rate32of77submissions,42%

        Upcoming Conference

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader