When Warren's Abstract Machine program instructions are executed?

184 Views Asked by At

I'm reading Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction".

In Chapter 2, the compilation of L0 programs is presented after the compilation of L0 queries. The program compilation section (2.3) starts with:

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.

So the compilation of a program is made after instructions obtained from query compilation are executed? Does that even make sense? I'm confused...

What makes sense to me: WAM code generated from a program's annotated syntax tree is stored by the interpreter. For each procedure (defined in the program) a block of WAM code is stored. When a query is made, its instructions are generated and executed. If the query is calling a defined procedure, execute its block of code. Is it something like that?

2

There are 2 best solutions below

0
On BEST ANSWER

Please note that what you quote is from the very beginning of a series of increasingly complex virtual machines that are introduced in this text:

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.

This simple language is interpreted as you describe.

In later sections of the book, the design and execution of more complex machines becomes proportionally more sophisticated, and already a few pages later we find for example:

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.

This is already the design you describe at the end of your post, which is of course how actual Prolog code is compiled in practice.

0
On

So the compilation of a program is made after instructions obtained from query compilation are executed? Does that even make sense? I'm confused...

In the beginning, this is clarified (2, last paragraph):

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.

As @mat already states: This is a step-by-step approach. Starting from very simple programs. Just one ground fact and a query.