Language Embedding and Optimization in Mython
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.
languages design extensible languages open compilers compile-time metaprogramming