A partial evaluator for the untyped lambda-calculus

Abstract This article describes theoretical and practical aspects of an implemented self-applicable partial evaluator for the untyped lambda-calculus with constants and a fixed point operator. To the best of our knowledge, it is the first partial evaluator that is simultaneously higher-order, non-trivial, and self-applicable. Partial evaluation produces a residual program from a source program and some of its input data. When given the remaining input data the residual program yields the same result that the source program would when given all its input data. Our partial evaluator produces a residual lambda-expression given a source lambda-expression and the values of some of its free variables. By self-application, the partial evaluator can be used to compile and to generate stand-alone compilers from a denotational or interpretive specification of a programming language. An essential component in our self-applicable partial evaluator is the use of explicitbinding time information. We use this to annotate the source program, marking asresidual the parts for which residual code is to be generated and marking aseliminable the parts that can be evaluated using only the data that is known during partial evaluation. We give a simple criterion,well-annotatedness, that can be used to check that the partial evaluator can handle the annotated higher-order programs without committing errors. Our partial evaluator is simple, is implemented in a side-effect free subset of Scheme, and has been used to compile and to generate compilers and a compiler generator. In this article we examine two machine-generated compilers and find that their structures are surprisingly natural.

[1]  Anders Bondorf,et al.  Automatic Autoprojection of Recursive Equations with Global Variables and Abstract Data Types , 1991, Sci. Comput. Program..

[2]  Neil D. Jones,et al.  Compiler Generation by Partial Evaluation: A Case Study , 1991, Struct. Program..

[3]  Anders Bondorf,et al.  Automatic Autoprojection of Higher Order Recursive Equations , 1990, Sci. Comput. Program..

[4]  Carsten K. Gomard Partial type inference for untyped functional programs , 1990, LISP and Functional Programming.

[5]  Anders Bondorf,et al.  A self-applicable partial evaluator for the lambda calculus , 1990, Proceedings. 1990 International Conference on Computer Languages.

[6]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[7]  Tsung-Min Kuo,et al.  Strictness analysis: a new perspective based on type inference , 1989, FPCA.

[8]  Peter Sestoft,et al.  Replacing function parameters by global variables , 1989, FPCA.

[9]  Torben Æ. Mogensen Binding Time Analysis for Polymorphically Typed Higher Order Languages , 1989, TAPSOFT, Vol.2.

[10]  Anders Bondorf,et al.  A Self-Applicable Partial Evaluator for Term Rewriting Systems , 1989, TAPSOFT, Vol.2.

[11]  Neil D. Jones,et al.  Mix: A self-applicable partial evaluator for experiments in compiler generation , 1989, LISP Symb. Comput..

[12]  Olivier Danvy,et al.  Partial Evaluation of Pattern Matching in Strings , 1989, Inf. Process. Lett..

[13]  Flemming Nielson,et al.  Automatic Binding Time Analysis for a Typed lambda-Calculus , 1988, Sci. Comput. Program..

[14]  Charles Consel,et al.  New Insights into Partial Evaluation: the SCHISM Experiment , 1988, ESOP.

[15]  Flemming Nielson,et al.  Automatic binding time analysis for a typed λ-calculus , 1988, POPL '88.

[16]  S. A. Romanenko,et al.  A compiler generator produced by a self-applicable specializer can have a surprisingly natural and u , 1988 .

[17]  Pierre Weis,et al.  Le systeme sam : metacompilation tres efficace a l'aide d'operateurs semantiques , 1987 .

[18]  Peter Sestoft,et al.  Automatic call unfolding in a partial evaluator , 1987 .

[19]  Mitchell Wand Finding the source of type errors , 1986, POPL '86.

[20]  Peter Sestoft,et al.  An experiment in partial evaluation: the generation of a compiler generator , 1985, SIGP.

[21]  David A. Schmidt Detecting global variables in denotational specifications , 1985, TOPL.

[22]  Andrew W. Appel Semantics-directed code generation , 1985, POPL '85.

[23]  R. Schooler,et al.  PARTIAL EVALUATION AS A MEANS OF LANGUAGE EXTENSIBILITY , 1984 .

[24]  Uwe F. Pleban Compiler prototyping using formal semantics , 1984, SIGPLAN '84.

[25]  Mitchell Wand A semantic prototyping system , 1984, SIGPLAN '84.

[26]  Mitchell Wand Semantics-directed machine architecture , 1982, POPL '82.

[27]  Lawrence C. Paulson A semantics-directed compiler generator , 1982, POPL '82.

[28]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[29]  Joseph E. Stoy,et al.  Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory , 1981 .

[30]  Valentin F. Turchin,et al.  The Use of Metasystem Transition in Theorem Proving and Program Optimization , 1980, ICALP.

[31]  Neil D. Jones,et al.  TEMPO: A Unified Treatment of Binding Time and Parameter Passing Concepts in Programming Languages , 1978, Lecture Notes in Computer Science.

[32]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[33]  Andrei P. Ershov,et al.  Correctness of Mixed Computation in Algol-Like Programs , 1977, MFCS.

[34]  Joseph A. Goguen,et al.  Initial Algebra Semantics and Continuous Algebras , 1977, J. ACM.

[35]  Andrei P. Ershov,et al.  On the Essence of Compilation , 1977, Formal Description of Programming Concepts.

[36]  Erik Sandewall,et al.  A Partial Evaluator, and its Use as a Programming Tool , 1976, Artif. Intell..

[37]  Gordon D. Plotkin,et al.  Call-by-Name, Call-by-Value and the lambda-Calculus , 1975, Theor. Comput. Sci..

[38]  F. Lockwood Morris,et al.  Advice on structuring compilers and proving them correct , 1973, POPL.