Warren’s Abstract Machine A Tutorial Reconstruction states the following for Variable Register Allocation rules:
- Variable registers are allocated according to least available index.
- Register X1 is always allocated to the outermost term.
- A same register is allocated to all the occurrences of a given variable.
Further in the tutorial, while building program queries, the following example is given:
p(f(X), h(Y, f(a)), Y).
X1 = p(X2, X3, X4)
X2 = f(X5)
X3 = h(X4, X6)
X4 = Y
X5 = X
X6 = f(X7)
X7 = a
My doubt is when considering the two occurrences of the f clause, both are f/1 structures, but with a different body and therefore needed to be instantiated differently. But what exactly is considered a variable in the WAM context, a prolog variable, or every term? How would the clause p(f(a), f(a))
be constructed:
X1 = p(X2, X2)
X2 = f(X3)
X3 = a
or
X1 = p(X2, X3)
X2 = f(X4)
X3 = f(X4)
X4 = a