Reasoning About Code-Generation in Two-Level Languages

We show that two-level languages are not only a good tool for describing code-generation algorithms, but a good tool for reasoning about them as well. Indeed, some general properties of two-level languages capture common proof obligations of code-generation algorithms in the form of two-level programs. - To prove that the generated code behaves as desired, we use an erasure property, which equationally relates the generated code to an erasure of the original two-level program in the object language, thereby reducing the two-level proof obligation to a simpler one-level obligation. - To prove that the generated code satisfies certain syntactic constraints, e.g., that it is in some normal form, we use a type-preservation property for a refined type system that enforces these constraints. In addition, to justify concrete implementations of code-generation algorithms in one-level languages, we use a native embedding of a two-level language into a one-level language. We present two-level languages with these properties both for a call-by-name object language and for a call-by-value object language with computational effects. Indeed, it is these properties that guide our language design in the call-by-value case. We consider two classes of non-trivial applications: one-pass transformations into continuation-passing style and type-directed partial evaluation for call-by-name and for call-by-value. Keywords. Two-level languages, erasure, type preservation, native implementation, partial evaluation.

[1]  Julia L. Lawall,et al.  Proceedings of the 2000 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM '00), Boston, Massachusetts, USA, January 22-23, 2000 , 2000, PEPM.

[2]  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.

[3]  Bernd Grobauer,et al.  The second Futamura projection for type-directed partial evaluation , 1999 .

[4]  Ulrich Berger,et al.  An inverse of the evaluation functional for typed lambda -calculus , 1991, [1991] Proceedings Sixth Annual IEEE Symposium on Logic in Computer Science.

[5]  Andrzej Filinski,et al.  Normalization by Evaluation for the Computational Lambda-Calculus , 2001, TLCA.

[6]  Claus Brabrand,et al.  The bigwig Project , 2000 .

[7]  Mitchell Wand,et al.  Deriving Target Code as a Representation of Continuation Semantics , 1982, TOPL.

[8]  Flemming Nielson,et al.  Two-level functional languages , 1992, Cambridge tracts in theoretical computer science.

[9]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[10]  Mitchell Wand,et al.  Macro-by-example: Deriving syntactic transformations from their specifications , 1987, POPL '87.

[11]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[12]  Olivier Danvy,et al.  CPS-transformation after strictness analysis , 1992, LOPL.

[13]  Matthias Felleisen,et al.  Hygienic macro expansion , 1986, LFP '86.

[14]  Nils Klarlund,et al.  The DSD Schema Language and its Applications , 2000 .

[15]  Eugenio Moggi,et al.  Functor Categories and Two-Level Languages , 1998, FoSSaCS.

[16]  Olivier Danvy,et al.  A Simple Take on Typed Abstract Syntax in Haskell-like Languages , 2000 .

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

[18]  Alan Bawden,et al.  Quasiquotation in Lisp , 1999, PEPM.

[19]  G. Winskel The formal semantics of programming languages , 1993 .

[20]  Peter Lee,et al.  Run-time code generation and modal-ML , 1998, PLDI.

[21]  Walid Taha,et al.  An Idealized MetaML: Simpler, and More Expressive , 1999, ESOP.

[22]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[23]  G. Plotkin,et al.  Situation Theory and its Applications , 1995 .

[24]  Rowan Davies,et al.  A temporal-logic approach to binding-time analysis , 1995, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[25]  Gordon D. Plotkin,et al.  Abstract syntax and variable binding , 1999, Proceedings. 14th Symposium on Logic in Computer Science (Cat. No. PR00158).

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

[27]  John C. Mitchell,et al.  Foundations for programming languages , 1996, Foundation of computing series.

[28]  Naoki Kobayashi,et al.  A Hybrid Approach to Online and Offline Partial Evaluation , 2001, High. Order Symb. Comput..

[29]  Olivier Danvy Type-Directed Partial Evaluation , 1998, Partial Evaluation.

[30]  Carsten K. Gomard A self-applicable partial evaluator for the lambda calculus: correctness and pragmatics , 1992, TOPL.

[31]  John McCarthy,et al.  LISP 1.5 Programmer's Manual , 1962 .

[32]  Albert R. Meyer,et al.  Continuation Semantics in Typed Lambda-Calculi (Summary) , 1985, Logic of Programs.

[33]  Yoshihiko Futamura,et al.  Partial Evaluation of Computation Process--An Approach to a Compiler-Compiler , 1999, High. Order Symb. Comput..

[34]  Olivier Danvy,et al.  A generic account of continuation-passing styles , 1994, POPL '94.

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

[36]  Olivier Danvy,et al.  A computational formalization for partial evaluation , 1996, Mathematical Structures in Computer Science.

[37]  Mitchell Wand,et al.  Specifying the correctness of binding-time analysis , 1993, POPL '93.

[38]  Walid Taha,et al.  Closed Types as a Simple Approach to Safe Imperative Multi-stage Programming , 2000, ICALP.

[39]  Peter Lee Realistic compiler generation , 1989, Foundations of Computing Series.

[40]  Andrzej Filinski,et al.  A Semantic Account of Type-Directed Partial Evaluation , 1999, PPDP.

[41]  Lockwood Morris The next 700 formal language descriptions , 1993, LISP Symb. Comput..

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

[43]  G.D. Plotkin,et al.  LCF Considered as a Programming Language , 1977, Theor. Comput. Sci..

[44]  Carl A. Gunter Semantics of programming languages: structures and techniques , 1993, Choice Reviews Online.

[45]  Robert Hieb,et al.  Revised 5 Report on the Algorithmic Language , 1999 .

[46]  Mitchell Wand Specifying the Correctness of Binding-Time Analysis , 1993, J. Funct. Program..

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

[48]  Jens Palsberg,et al.  Correctness of binding-time analysis , 1993, Journal of Functional Programming.

[49]  Frank Pfenning,et al.  A modal analysis of staged computation , 1996, POPL '96.

[50]  Ivan Damgård,et al.  A Generalisation, a Simplification and Some Applications of Paillier's Probabilistic Public-Key System , 2001, Public Key Cryptography.

[51]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[52]  Flemming Nielson,et al.  Prescriptive Frameworks for Multi-Level Lambda-Calculi , 1997 .

[53]  Flemming Nielson,et al.  Multi-Level Lambda-Calculi: An Algebraic Description , 1996, Dagstuhl Seminar on Partial Evaluation.

[54]  Walid Taha,et al.  A Sound Reduction Semantics for Untyped CBN Multi-stage Computation. Or, the Theory of MetaML is Non-trivial (Extended Abstract) , 1999, PEPM.