Semantics-Based Compiling: A Case Study in Type-Directed Partial Evaluation - Danvy, Olivier; Vestergaard, René (BRICS Report Series, 1996)
We illustrate a simple and effective solution to semantics-based compiling. Our solution is based on type-directed partial evaluation, where - our compiler generator is expressed in a few lines, and is efficient; - its input is a well-typed, purely functional definitional interpreter in the manner of denotational semantics; - the output of the generated compiler is three-address code, in the fashion and efficiency of the Dragon Book; - the generated compiler processes several hundred lines of source code per second. The source language considered in this case study is imperative, block-structured, higher-order, call-by-value, allows subtyping, and obeys stack discipline. It is bigger than what is usually reported in the literature on semantics-based compiling and partial evaluation. Our compiling technique uses the first Futamura projection, i.e., we compile programs by specializing a definitional interpreter with respect to this program. Our denitional interpreter is completely straightforward, stack-based, and in direct style. In particular, it requires no clever staging technique (currying, continuations, binding-time improvements, etc.), nor does it rely on any other framework (attribute grammars, annotations, etc.) than the typed lambda-calculus. In particular, it uses no other program analysis than traditional type inference. The overall simplicity and effectiveness of the approach has encouraged us to write this paper, to illustrate this genuine solution to denotational semantics-directed compilation, in the spirit of Scott and Strachey.