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.
- 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 ScholarDigital Library
- Brett Cannon. Python Enhancement Proposal PEP 339 - Design of the CPython Compiler, 2005. Available at http://www.python.org/dev/peps/pep-0339/.Google Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- R. Kent Dybvig. Writing hygienic macros in Scheme with syntax-case. Technical Report 356, Indiana University, Bloomington, Indiana, USA, June 1992.Google Scholar
- 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 ScholarDigital Library
- Brian W. Kernignhan and Dennis M. Ritchie. The C Programming Language. Prentice Hall, Englewood Cliffs, NJ, USA, 1988. Google ScholarDigital Library
- John K. Ousterhout. Tcl: An embeddable command language. In Proceedings of the Winter USENIX Conference, pages 133--145, January 1990.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- Tavis Rudd. Cheetah - The Python-Powered Template Engine, 2007. Available at http://www.cheetahtemplate.org/.Google Scholar
- Bjarne Stroustrup. The Design and Evolution of C++. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1994. Google ScholarDigital Library
- Walid Taha. A gentle introduction to multi-stage programming. In Domain-Specifc Program Generation, pages 30--50, 2003.Google Scholar
- Guido van Rossum. Python Reference Manual (2.5), September 2006. Available at http://www.python.org/doc/2.5/ref/ref.html.Google Scholar
- Todd Veldhuizen. Using C++ template metaprograms. C++ Report, 7(4):36--43, May 1995. Reprinted in C++ Gems, ed. Stanley Lippman.Google ScholarDigital Library
- 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 Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
Index Terms
- Language embedding and optimization in mython
Recommendations
The design and implementation of the wolfram language compiler
CGO 2020: Proceedings of the 18th ACM/IEEE International Symposium on Code Generation and OptimizationThe popularity of data- and scientific-oriented applications, abundance of on-demand compute resources, and scarcity of domain expert programmers have given rise to high-level scripting languages. These high-level scripting languages offer a fast way to ...
Language embedding and optimization in mython
DLS '09Mython 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 ...
Languages as libraries
PLDI '11Programming language design benefits from constructs for extending the syntax and semantics of a host language. While C's string-based macros empower programmers to introduce notational shorthands, the parser-level macros of Lisp encourage ...
Comments