Duplication and Partial Evaluation
- For a Better Understanding of Reflective Languages -
This paper presents a general implementation framework for
reflective languages.
It allows us to systematically build reflective languages
which have the following favorable properties:
(1) user programs are allowed to access and change (parts of)
metalevel interpreters,
(2) reflective facilities are available at every level, (hence there
exists conceptually an infinite tower of interpreters), and
(3) the interpreter runs as efficiently as the conventional (directly
implemented) metacircular interpreter when reflection is not used.
Our scheme is divided into three stages.
First, we define interpreters which give the operational semantics
of each level, and conceptually construct the infinite tower of these
interpreters.
They are then duplicated to obtain directly executed
interpreters, while introducing double
interpretation to maintain redefinability of interpreters.
Finally, partial evaluation is employed to collapse the double interpretation
into single interpretation.
We illustrate our scheme by implementing a particular reflective
language called Black in Scheme,
but it is general enough to be applied to other reflective languages.
The paper gives the complete Scheme implementation of Black and
demonstrates some examples.
We also show how a system with the delta abstraction introduced by Blond
can be constructed in our framework.