In 5.1 we saw how to transform simple Scheme programs into
descriptions of register machines. We will now perform this transformation on
a more complex program, the metacircular evaluator of
4.1.1–4.1.4, which shows how the behavior of a Scheme interpreter
can be described in terms of the procedures eval and apply. The
在 5.1 中,我们了解了如何将简单的 Scheme 程序转换为寄存器机器的描述。现在我们将对一个更为复杂的程序——4.1.1 至 4.1.4 中的元循环求值器——执行这一转换,该求值器展示了 Scheme 解释器的行为如何用过程 eval 和 apply 来描述。
explicit-control evaluator that we develop in this section shows how
the underlying procedure-calling and argument-passing mechanisms used in the
evaluation process can be described in terms of operations on registers and
stacks. In addition, the explicit-control evaluator can serve as an
implementation of a Scheme interpreter, written in a language that is very
similar to the native machine language of conventional computers. The
evaluator can be executed by the register-machine simulator of
5.2. Alternatively, it can be used as a starting point for building a
machine-language implementation of a Scheme evaluator, or even a
special-purpose machine for evaluating Scheme expressions. Figure 5.16
shows such a hardware implementation: a silicon chip that acts as an evaluator
for Scheme. The chip designers started with the data-path and controller
specifications for a register machine similar to the evaluator described in
this section and used design automation programs to construct the
integrated-circuit layout.
Figure 5.16: A silicon-chip implementation of an evaluator for Scheme.
Subheading: Registers and operations
我们在本节中开发的显式控制求值器 (explicit-control evaluator) 展示了求值过程中使用的底层过程调用和参数传递机制如何用寄存器和栈上的操作来描述。此外,显式控制求值器还可以作为 Scheme 解释器的一种实现,用一种与传统计算机原生机器语言非常相似的语言编写。该求值器可以由 5.2 的寄存器机器模拟器执行;也可以作为构建 Scheme 求值器机器语言实现的起点,乃至构建专门用于求值 Scheme 表达式的专用机器的起点。图 5.16 展示了这样一种硬件实现:一块充当 Scheme 求值器的硅芯片。芯片设计者从类似于本节所述求值器的寄存器机器数据通路和控制器规格出发,使用设计自动化程序构造出集成电路版图。图 5.16:Scheme 求值器的硅芯片实现。子标题:寄存器和操作
In designing the explicit-control evaluator, we must specify the operations to
be used in our register machine. We described the metacircular evaluator in
terms of abstract syntax, using procedures such as quoted? and
make-procedure. In implementing the register machine, we could expand
these procedures into sequences of elementary list-structure memory operations,
and implement these operations on our register machine. However, this would
make our evaluator very long, obscuring the basic structure with details. To
clarify the presentation, we will include as primitive operations of the
register machine the syntax procedures given in 4.1.2 and the
procedures for representing environments and other run-time data given in
sections 4.1.3 and 4.1.4. In order to completely specify an
evaluator that could be programmed in a low-level machine language or
implemented in hardware, we would replace these operations by more elementary
operations, using the list-structure implementation we described in
5.3.
在设计显式控制求值器时,我们必须指定寄存器机器中将要使用的操作。我们曾用抽象语法来描述元循环求值器,使用了诸如 quoted? 和 make-procedure 之类的过程。在实现寄存器机器时,可以将这些过程展开为一系列基本表结构内存操作,并在寄存器机器上实现这些操作;然而,这样做会使求值器变得非常冗长,用细节掩盖基本结构。为了使表述清晰,我们将把 4.1.2 中给出的语法过程以及 4.1.3 和 4.1.4 节中表示环境和其他运行时数据的过程,作为寄存器机器的基本操作包含进来。若要完整地规格一个可以用底层机器语言编程或用硬件实现的求值器,则需用更基本的操作来替换这些操作,利用我们在 5.3 中描述的表结构实现。
Our Scheme evaluator register machine includes a stack and seven registers:
exp, env, val, continue, proc, argl,
and unev. Exp is used to hold the expression to be evaluated,
and env contains the environment in which the evaluation is to be
performed. At the end of an evaluation, val contains the value obtained
by evaluating the expression in the designated environment. The
continue register is used to implement recursion, as explained in
5.1.4. (The evaluator needs to call itself recursively, since
evaluating an expression requires evaluating its subexpressions.) The
registers proc, argl, and unev are used in evaluating
combinations.
我们的 Scheme 求值器寄存器机器包含一个栈和七个寄存器:exp、env、val、continue、proc、argl 和 unev。exp 用于保存待求值的表达式,env 包含执行求值所在的环境。求值结束时,val 保存在指定环境中对表达式求值所得的值。continue 寄存器用于实现递归,如 5.1.4 中所述(求值器需要递归地调用自身,因为对一个表达式求值需要对其子表达式求值)。寄存器 proc、argl 和 unev 用于对组合式求值。
We will not provide a data-path diagram to show how the registers and
operations of the evaluator are connected, nor will we give the complete list
of machine operations. These are implicit in the evaluator’s controller, which
will be presented in detail.
我们不打算提供数据通路图来展示求值器的寄存器和操作是如何连接的,也不会给出完整的机器操作列表。这些内容隐含在求值器的控制器中,后者将被详细呈现。