SICP 第 5 章:dispatch-on-type 如何在显式控制评估器中更有效?

SICP Ch 5: How would dispatch-on-type be more efficient in the explicit control evaluator?

我正在学习 SICP,正在学习第 5 章——实施显式控制评估器。

他们开始为 eval-dispatch

编写机器语言
eval-dispatch
  (test (op self-evaluating?) (reg exp))
  (branch (label ev-self-eval))
  (test (op variable?) (reg exp))
  (branch (label ev-variable))
  (test (op quoted?) (reg exp))
  (branch (label ev-quoted))
  (test (op assignment?) (reg exp))
  (branch (label ev-assignment))
  (test (op definition?) (reg exp))
  (branch (label ev-definition))
  (test (op if?) (reg exp))
  (branch (label ev-if))
  (test (op lambda?) (reg exp))
  (branch (label ev-lambda))
  (test (op begin?) (reg exp))
  (branch (label ev-begin))
  (test (op application?) (reg exp))
  (branch (label ev-application))
  (goto (label unknown-expression-type))

但是,they note here这也可以以数据导向的方式进行:

In our controller, the dispatch is written as a sequence of test and branch instructions. Alternatively, it could have been written in a data-directed style (and in a real system it probably would have been) to avoid the need to perform sequential tests and to facilitate the definition of new expression types. A machine designed to run Lisp would probably include a dispatch-on-type instruction that would efficiently execute such data-directed dispatches.

我不太确定我理解他们在这里的意思:

  1. 这里的instruction是什么意思?我是否正确理解为 op

类似于:

(assign type (op dispatch-on-type) (reg exp))
(goto type)

我不太清楚为什么这样写 dispatch-on-type 必然会使添加新表达式类型变得更容易

  1. 他们注意到 lisp 机器将dispatch-on-type有效地实现

我不太确定我明白了。有什么方法可以使它比 eval-dispatch 已经在做的事情更有效率吗?我猜 dispatch-on-type 必须 运行 测试才能确定它是什么类型

好的,我注意到一个效率差异:

在这个版本中,branch指令仍然由机器检查。 如果我们使用 data-directed 方法

,我们 可以 避免这些检查