Compiling embedded languages

Functional languages are particularly well-suited to the interpretive implementations of Domain-Specific Embedded Languages (DSELs). We describe an implemented technique for producing optimizing compilers for DSELs, based on Kamin's idea of DSELs for program generation. The technique uses a data type of syntax for basic types, a set of smart constructors that perform rewriting over those types, some code motion transformations, and a back-end code generator. Domain-specific optimization results from chains of domain-independent rewrites on basic types. New DSELs are defined directly in terms of the basic syntactic types, plus host language functions and tuples. This definition style makes compilers easy to write and, in fact, almost identical to the simplest embedded interpreters. We illustrate this technique with a language Pan for the computationally intensive domain of image synthesis and manipulation.

[1]  Alberto Pettorossi Methodologies for transformations and memoing in applicative languages , 1984 .

[2]  Conal Elliott,et al.  Functional Implementations of Continuos Modeled Animation , 1998, PLILP/ALP.

[3]  Conal Elliott,et al.  An Embedded Modeling Language Approach to Interactive 3D and Multimedia Animation , 1999, IEEE Trans. Software Eng..

[4]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[5]  Wei-Ngan Chin Towards an automated tupling strategy , 1993, PEPM '93.

[6]  Andrew Berlin A Compilation Strategy for Numerical Programs Based on Partial Evaluation , 1989 .

[7]  Samuel N. Kamin,et al.  A Special-Purpose Language for Picture-Drawing , 1997, DSL.

[8]  Todd L. Veldhuizen,et al.  Expression templates , 1996 .

[9]  Oege de Moor,et al.  Generic Program Transformation , 1998, Advanced Functional Programming.

[10]  Simon L. Peyton Jones,et al.  Lazy functional state threads , 1994, PLDI '94.

[11]  Paul Hudak The Haskell School of Expression: Learning Functional Programming through Multimedia , 1999 .

[12]  Dov Harel,et al.  A linear algorithm for finding dominators in flow graphs and related problems , 1985, STOC '85.

[13]  Richard S. Bird Using circular programs to eliminate multiple traversals of data , 2004, Acta Informatica.

[14]  Conal Elliott,et al.  Functional Image Synthesis , 2001 .

[15]  Andrew W. Appel,et al.  Modern Compiler Implementation in ML , 1997 .

[16]  Olivier Danvy Online Type-Directed Partial Evaluation , 1998, Fuji International Symposium on Functional and Logic Programming.

[17]  Matteo Frigo,et al.  A fast Fourier transform compiler , 1999, SIGP.

[18]  Todd L. Veldhuizen C++ Templates as Partial Evaluation , 1999, PEPM.

[19]  Paul Hudak,et al.  Modular domain specific languages and tools , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[20]  P. J. Landin,et al.  The next 700 programming languages , 1966, CACM.

[21]  Nancy A. Day,et al.  Symbolic Simulation of Microprocessor Models using Type Classes in Haskell , 1999, CHARME.

[22]  Eerke A. Boiten,et al.  Improving Recursive Functions by Inverting the Order of Evaluation , 1992, Sci. Comput. Program..

[23]  Andrew A. Berlin,et al.  Compiling scientific code using partial evaluation , 1990, Computer.

[24]  Erik Ruf,et al.  Automatic Online Partial Evaluation , 1991, FPCA.

[25]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[26]  Robert E. Tarjan,et al.  Fast Algorithms for Finding Nearest Common Ancestors , 1984, SIAM J. Comput..

[27]  Daan Leijen,et al.  Domain specific embedded compilers , 1999, DSL '99.

[28]  Torben Æ. Mogensen,et al.  Partial Evaluation. Practice and Theory: DIKU 1998 International Summer School, Copenhagen, Denmark, June 29 - July 10, 1998 , 1998 .

[29]  Mikkel Thorup,et al.  Dominators in Linear Time , 1999, SIAM J. Comput..

[30]  Samuel N. Kamin Standard ML as a Meta-Programming Language , 1996 .

[31]  Thomas Johnsson,et al.  Attribute grammars as a functional programming paradigm , 1987, FPCA.

[32]  Koen Claessen,et al.  Observable Sharing for Functional Circuit Description , 1999, ASIAN.