Generating a Pattern Matching Compiler by Partial Evaluation
Partial evaluation can be used for automatic generation of compilers and was first implemented by Jones et. al. . Since partial evaluation was extended to higher order functional languages, Jones et. al.  and Bondorf , it has become possible to write denotational semantics definitions of languages and implement these with very few changes in the language treated by partial evaluators.
In this paper we use this technique to generate a compiler for a small strict combinator language with pattern matching. First, a simple denotational specification for the language is written and a compiler is generated. This first compiler turns out not to generate too efficient code.
By changing the denotational specification, new compilers that generate more efficient code are obtained. This process can be described as generating optimizing compilers by changing specifications. The optimization concerns generation of object code for pattern matching and the final compiler does in fact generate very efficient code for this. Specifically, it treats non-uniform function definitions in a satisfactory way. The optimization performed can be viewed as being equivalent to the well-known compiler optimization called common subexpression elimination.
KeywordsSugar Val1 Dine Prefix Cond
Unable to display preview. Download preview PDF.
- Lennart Augustsson. Compiling pattern matching. In J.-P. Jouannaud, editor, Conference on Functional Programming Languages and Computer Architecture, Nancy, France. Lecture Notes in Computer Science 201, pages 368–381, Springer-Verlag, 1985.Google Scholar
- Anders Bondorf. Automatic autoprojection of higher order recursive equations. In Neil D. Jones, editor, ESOP’90, Copenhagen, Denmark. Lecture Notes in Computer Science 432, pages 70–87, Springer-Verlag, May 1990.Google Scholar
- Anders Bondorf. Compiling laziness by partial evaluation. In 1990 Glasgow Workshop on Functional Programming, Ullapool, Computing Science Department, Glasgow University, Glasgow, Scotland, 1990.Google Scholar
- Anders Bondorf and Olivier Danvy. Automatic autoprojection of recursive equations with global variables and abstract data types. Technical Report 90–4, DIKU, University of Copenhagen, Denmark, 1990.Google Scholar
- Pär Emanuelson. From abstract model to efficient compilation of patterns. In M. Dezani-Ciancaglini and U. Montanan, editors, International Symposium on Programming, 5th Colloquium, Turin, Lecture Notes in Computer Science 137, pages 91–104, Springer-Verlag, April 1982.Google Scholar
- Yoshihiko Futamura and Kenroku Nogi. Genreralized partial computation. In Dines Bjorner, Andrei P. Ershov, and Neil D. Jones, editors, Partial Evaluation and Mixed Computation, pages 133–151, North-Holland, 1988.Google Scholar
- Neil D. Jones, Carsten K. Cornard, Anders Bondorf, Olivier Danvy, and Tor-ben Æ. Mogensen. A self-applicable partial evaluator for the lambda calculus. In IEEE Computer Society 1990 International Conference on Computer Languages, IEEE, March 1990.Google Scholar
- Neil D. Jones, Peter Sestoft, and Harald Sondergaard. An experiment in partial evaluation: the generation of a compiler generator. In J.-P. Jouannaud, editor, Rewriting Techniques and Applications, Dijon, France. Lecture Notes in Computer Science 202, pages 124–140, Springer-Verlag, 1985.Google Scholar
- Paul Hudak and Philip Wadler, editors. Report on the programming language Haskell. Technical Report, Yale University and Glasgow University, April 1990.Google Scholar
- David A. Schmidt. De notational Semantics, a Methodology for Language Development. Allyn and Bacon, Boston, 1986.Google Scholar
- Peter Sestoft. The structure of a self-applicable partial evaluator. In Harald Ganzinger and Neil D. Jones, editors, Programs as Data Objects, Copenhagen, Denmark. Lecture Notes in Computer Science 217, pages 236–256, Springer-Verlag, October 1985.Google Scholar
- Philip Wadler. Efficient compilation of pattern-matching. In Simon L. Peyton Jones, editor, The Implementation of Functional Programming Languages, chapter 5, pages 78–103, Prentice-Hall, 1987.Google Scholar