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?