沃伦的抽象机程序指令何时执行?
When Warren's Abstract Machine program instructions are executed?
我正在阅读Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction"。
在第2章中,L0程序的编译是在L0查询的编译之后介绍的。程序编译部分(2.3)开头为:
Compiling a program term p is just a bit trickier, although not by
much. Observe that it assumes that a query ?-
q will have built a term
on the heap and set register X1 to contain its address. Thus,
unifying q to p can proceed by following the term structure already
present in X1 as long as it matches functor for functor the structure of p.
所以一个程序的编译是在执行查询编译得到的指令之后?这有意义吗?我很困惑...
对我来说有意义的是:从程序的注释语法树生成的 WAM 代码由解释器存储。对于每个过程(在程序中定义),都会存储一个 WAM 代码块。进行查询时,将生成并执行其指令。如果查询正在调用定义的过程,则执行其代码块。是这样的吗?
请注意,您引用的是本文介绍的一系列日益复杂的虚拟机的开头:
We consider here ℒ0, a very simple language indeed. In this language, one can specify only two sorts of entities: a program term and a query term. Both program and query are first-order terms but not variables. The semantics of ℒ0 is simply
tantamount to computing the most general unifier of the program and the query.
这种简单的语言按照您的描述进行解释。
在本书的后面部分,更复杂的机器的设计和执行成比例地变得更复杂,几页之后我们已经找到例如:
In ℳ1, compiled code is stored in a code area (CODE
), an addressable array of data words, each containing a possibly labeled instruction over one or more memory words consisting of an opcode
followed by operands.
这已经是您在 post 末尾描述的设计,这当然是实际 Prolog 代码在实践中的编译方式。
So the compilation of a program is made after instructions obtained from query compilation are executed? Does that even make sense? I'm confused...
一开始就澄清了(2,最后一段):
The idea is quite simple: having defined a program term p, one can submit any query ?-
q and execution either fails if p and q do not unify, or succeeds with a binding of the variables in q obtained by unifying it with p.
正如@mat 已经指出的那样:这是一个循序渐进的方法。从非常简单的程序开始。只是 一个 基本事实和一个查询。
我正在阅读Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction"。
在第2章中,L0程序的编译是在L0查询的编译之后介绍的。程序编译部分(2.3)开头为:
Compiling a program term p is just a bit trickier, although not by much. Observe that it assumes that a query
?-
q will have built a term on the heap and set register X1 to contain its address. Thus, unifying q to p can proceed by following the term structure already present in X1 as long as it matches functor for functor the structure of p.
所以一个程序的编译是在执行查询编译得到的指令之后?这有意义吗?我很困惑...
对我来说有意义的是:从程序的注释语法树生成的 WAM 代码由解释器存储。对于每个过程(在程序中定义),都会存储一个 WAM 代码块。进行查询时,将生成并执行其指令。如果查询正在调用定义的过程,则执行其代码块。是这样的吗?
请注意,您引用的是本文介绍的一系列日益复杂的虚拟机的开头:
We consider here ℒ0, a very simple language indeed. In this language, one can specify only two sorts of entities: a program term and a query term. Both program and query are first-order terms but not variables. The semantics of ℒ0 is simply tantamount to computing the most general unifier of the program and the query.
这种简单的语言按照您的描述进行解释。
在本书的后面部分,更复杂的机器的设计和执行成比例地变得更复杂,几页之后我们已经找到例如:
In ℳ1, compiled code is stored in a code area (
CODE
), an addressable array of data words, each containing a possibly labeled instruction over one or more memory words consisting of an opcode followed by operands.
这已经是您在 post 末尾描述的设计,这当然是实际 Prolog 代码在实践中的编译方式。
So the compilation of a program is made after instructions obtained from query compilation are executed? Does that even make sense? I'm confused...
一开始就澄清了(2,最后一段):
The idea is quite simple: having defined a program term p, one can submit any query
?-
q and execution either fails if p and q do not unify, or succeeds with a binding of the variables in q obtained by unifying it with p.
正如@mat 已经指出的那样:这是一个循序渐进的方法。从非常简单的程序开始。只是 一个 基本事实和一个查询。