Semantics-Based Compiling: A Case Study in Type-Directed Partial Evaluation
DOI:
https://doi.org/10.7146/brics.v3i13.19976Resumé
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.
Downloads
Publiceret
Citation/Eksport
Nummer
Sektion
Licens
Authors who publish with this journal agree to the following terms:- Authors retain copyright and grant the journal right of first publication with the work simultaneously licensed under a Creative Commons Attribution License that allows others to share the work with an acknowledgement of the work's authorship and initial publication in this journal.
- Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the journal's published version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgement of its initial publication in this journal.
- Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (See The Effect of Open Access).