Problems implementing some basic machine instructions for a WAM based Prolog

Since you are creating test cases, just the other day Jan listed a unification case that I have not seen before.

?- X=f(X), Y=f(Y), X=Y.
X=Y, Y=f(Y).

and the explanation in the code.

Would be interesting to see if your WAM can do it.