Generating a Pattern Matching Compiler by Partial Evaluation

  • Jesper Jørgensen
Part of the Workshops in Computing book series (WORKSHOPS COMP.)

Abstract

Partial evaluation can be used for automatic generation of compilers and was first implemented by Jones et. al. [9]. Since partial evaluation was extended to higher order functional languages, Jones et. al. [8] and Bondorf [2], 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.

Keywords

Sugar Val1 Dine Prefix Cond 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [1]
    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
  2. [2]
    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
  3. [3]
    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
  4. [4]
    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
  5. [5]
    Charles Consel and Olivier Danvy. Partial evaluation of pattern matching in strings. Information Processing Letters, 30 (2): 79–86, 1989.CrossRefGoogle Scholar
  6. [6]
    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
  7. [7]
    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
  8. [8]
    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
  9. [9]
    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
  10. [10]
    Donald E. Knuth, James H. Morris, and Vaughan R. Pratt. Fast pattern matching in strings. Siam Journal on Computing, 6 (2): 323–350, 1977.MathSciNetMATHCrossRefGoogle Scholar
  11. [11]
    Paul Hudak and Philip Wadler, editors. Report on the programming language Haskell. Technical Report, Yale University and Glasgow University, April 1990.Google Scholar
  12. [12]
    Jonathan Rees and William Clinger. Revised reporta on the algorithmic language scheme. Sigplan Notices, 21 (12): 37–79, December 1986.CrossRefGoogle Scholar
  13. [13]
    David A. Schmidt. De notational Semantics, a Methodology for Language Development. Allyn and Bacon, Boston, 1986.Google Scholar
  14. [14]
    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
  15. [15]
    Valentin F. Turchin. The concept of a supercompiler. Transactions on Programming Languages and Systems, 8 (3): 292–325, 1986.MATHCrossRefGoogle Scholar
  16. [16]
    David Turner. An overview of Miranda. Sigplan Notices, 21 (12): 158–166, December 1986.CrossRefGoogle Scholar
  17. [17]
    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

Copyright information

© Springer-Verlag Berlin Heidelberg 1991

Authors and Affiliations

  • Jesper Jørgensen
    • 1
  1. 1.DIKU, Department of Computer ScienceUniversity of CopenhagenCopenhagen ØDenmark

Personalised recommendations