I am working through Hassan Ait-Kaci's book Warren's Abstract Machine - A Tutorial Reconstruction. Currently I am stuck on section 2.4, "Argument Registers".
To be precise, what I don't understand is how to get from these register assignments (p.22) (for query p(Z,h(Z,W),f(W))
):
A1 = Z
A2 = h(A1,X4)
A3 = f(X4)
X4 = W
to these instructions (p.24):
put_variable X4,A1
put_structure h/2,A2
set_value X4
set_variable X5
put_structure f/1,A3
set_value X5
call p/3
Like, where does X5 come from all of a sudden? In the register assignments, X4 refers to variable W, and there's no X5. But in the instructions, X5 refers to (what is/was essentially) W, and X4 now refers to Z. I am not seeing an explanation in the book. What am I missing?
I tried to understand this but to no avail. Nothing in the errata. Here are some notes:
Instruction review
put_structure f/n,Xi
: push a newSTR
(and adjoining functor) cell onto the heap and copy that cell into the allocated register address;set_variable Xi
: push a newREF
cell onto the heap containing its own address, and copy it into the given register;set_value Xi
: push a new cell onto the heap and copy into the register's value.put_variable Xn,Ai
: the first occurrence of a variable in i-th argument position pushes a new unboundREF
cell onto the heap and copies it into that variable's register as well as argument registerAi
; andput_value Xn,Ai
(used for query): a later occurrence copies its value into argument registerAi
.get_variable Xn,Ai
: the first occurrence of a variable in i-th argument position sets it to the value of argument registerAi
; andget_value Xn,Ai
: a later occurrence unifies with the value ofAi
.So, about that query
It seems to be coded differently on pages 17 and 19
Edit: It seems the code on the left allows variables appearing in non-root-positions to be in "argument registers" which is disallowed on the right, hence indirection.
The code
The
Ai
are the argument registers, theXi
are some value registers.At position (1), so far, so good.
X4
andX5
seem to implicitly be the first and second arguments of theh/2
in A2 (is that right?)At (2)
At (3)
At (4)