Semantics-directed compilation of nonlinear patterns

https://doi.org/10.1016/0020-0190(91)90148-BGet rights and content

Abstract

This paper describes the automatic derivation of compiled patterns and of a pattern compiler by partial evaluation. Compiling a pattern is achieved by specializing a pattern matching program with respect to the pattern. Generating a pattern compiler is achieved by specializing the specializer with respect to the pattern matching program, i.e., by self-application of the specializer. The compiled patterns and the compiler are semantics-based because they are obtained using meaning-preserving transformations upon the definitional pattern matching program and the partial evaluator.

The results are unexpectedly good: not only all are the operations depending on the pattern (syntax analysis, resolution of cross-references due to the nonlinearity) performed at compile time, but whereas the general pattern matcher builds the substitution environment incrementally and for nothing in case of failure, compiled patterns perform all the structural and equality tests first, and build the result only if the match succeeds. This nontrivial runtime staging has been obtained automatically, which is remarkable because staging in general is known to be an art.

This example stresses continuation-passing style as a convenient style for writing general programs. This style makes it possible to circumvent the approximations of binding time analysis (which is an essential requirement for efficient self-application), and in addition, to stage residual programs automatically. These observations have been confirmed by later experiments.

References (15)

  • C. Consel et al.

    Partial evaluation of pattern matching in strings

    Inform. Process. Lett.

    (1989)
  • A. Bondorf

    Automatic autoprojection of higher order recursive equations

  • A. Bondorf et al.

    Automatic autoprojection of recursive equations with global variables and abstract data types

  • C. Consel

    Analyse de programme, evaluation partielle, et génération de compilateurs

  • C. Consel et al.

    Static and Dynamic Semantics Processing

    Proc. Eighteenth Ann. SIGACT-SIGPLAN Symp. on Principles of Programming Languages

    (1991)
  • P. Emanuelson

    Performance enhancement in a well-structured pattern matcher through partial evaluation

There are more references available in the full text version of this article.

Cited by (10)

  • Program Specialization

    2013, Program Specialization
  • Secure information flow via linear continuations

    2002, Higher-Order and Symbolic Computation
View all citing articles on Scopus

This work has been carried out while the author was visiting the Computer Science Department of Stanford University (thanks to Carolyn L. Talcott) and the Computer Science Department of Indiana University (thanks to Daniel P. Friedman), during the summer and fall of 1989. The paper was completed at Kansas State University. An extended version of this paper was published as Tech. Rept. 303, Computer Science Dept., Indiana University (1990).

View full text