lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/machine/WAMResolvingJavaMachine.java
private boolean unify(int a1, int a2)
    {
        // pdl.push(a1)
        // pdl.push(a2)
        uPush(a1);
        uPush(a2);

        // fail <- false
        boolean fail = false;

        // while !empty(PDL) and not failed
        while (!uEmpty() && !fail)
        {
            // d1 <- deref(pdl.pop())
            // d2 <- deref(pdl.pop())
            // t1, v1 <- STORE[d1]
            // t2, v2 <- STORE[d2]
            int d1 = deref(uPop());
            int t1 = derefTag;
            int v1 = derefVal;

            int d2 = deref(uPop());
            int t2 = derefTag;
            int v2 = derefVal;

            // if (d1 != d2)
            if (d1 != d2)
            {
                // if (t1 = REF or t2 = REF)
                // bind(d1, d2)
                if ((t1 == WAMInstruction.REF))
                {
                    bind(d1, d2);
                }
                else if (t2 == WAMInstruction.REF)
                {
                    bind(d1, d2);
                }
                else if (t2 == WAMInstruction.STR)
                {
                    // f1/n1 <- STORE[v1]
                    // f2/n2 <- STORE[v2]
                    int fn1 = data.get(v1);
                    int fn2 = data.get(v2);
                    byte n1 = (byte) (fn1 >>> 24);

                    // if f1 = f2 and n1 = n2
                    if (fn1 == fn2)
                    {
                        // for i <- 1 to n1
                        for (int i = 1; i <= n1; i++)
                        {
                            // pdl.push(v1 + i)
                            // pdl.push(v2 + i)
                            uPush(v1 + i);
                            uPush(v2 + i);
                        }
                    }
                    else
                    {
                        // fail <- true
                        fail = true;
                    }
                }
                else if (t2 == WAMInstruction.CON)
                {
                    if ((t1 != WAMInstruction.CON) || (v1 != v2))
                    {
                        fail = true;
                    }
                }
                else if (t2 == WAMInstruction.LIS)
                {
                    if (t1 != WAMInstruction.LIS)
                    {
                        fail = true;
                    }
                    else
                    {
                        uPush(v1);
                        uPush(v2);
                        uPush(v1 + 1);
                        uPush(v2 + 1);
                    }
                }
            }
        }

        return !fail;
    }
private boolean unify(int a1, int a2)
    {
        // pdl.push(a1)
        // pdl.push(a2)
        uPush(a1);
        uPush(a2);

        // fail <- false
        boolean fail = false;

        // while !empty(PDL) and not failed
        while (!uEmpty() && !fail)
        {
            // d1 <- deref(pdl.pop())
            // d2 <- deref(pdl.pop())
            // t1, v1 <- STORE[d1]
            // t2, v2 <- STORE[d2]
            int d1 = deref(uPop());
            int t1 = derefTag;
            int v1 = derefVal;

            int d2 = deref(uPop());
            int t2 = derefTag;
            int v2 = derefVal;

            // if (d1 != d2)
            if (d1 != d2)
            {
                // if (t1 = REF or t2 = REF)
                // bind(d1, d2)
                if ((t1 == WAMInstruction.REF))
                {
                    bind(d1, d2);
                }
                else if (t2 == WAMInstruction.REF)
                {
                    bind(d1, d2);
                }
                else if (t2 == WAMInstruction.STR)
                {
                    // f1/n1 <- STORE[v1]
                    // f2/n2 <- STORE[v2]
                    int fn1 = data.get(v1);
                    int fn2 = data.get(v2);
                    byte n1 = (byte) (fn1 >>> 24);

                    // if f1 = f2 and n1 = n2
                    if (fn1 == fn2)
                    {
                        // for i <- 1 to n1
                        for (int i = 1; i <= n1; i++)
                        {
                            // pdl.push(v1 + i)
                            // pdl.push(v2 + i)
                            uPush(v1 + i);
                            uPush(v2 + i);
                        }
                    }
                    else
                    {
                        // fail <- true
                        fail = true;
                    }
                }
                else if (t2 == WAMInstruction.CON)
                {
                    if ((t1 != WAMInstruction.CON) || (v1 != v2))
                    {
                        fail = true;
                    }
                }
                else if (t2 == WAMInstruction.LIS)
                {
                    if (t1 != WAMInstruction.LIS)
                    {
                        fail = true;
                    }
                    else
                    {
                        uPush(v1);
                        uPush(v2);
                        uPush(v1 + 1);
                        uPush(v2 + 1);
                    }
                }
            }
        }

        return !fail;
    }
Attempts to unify structures or references on the heap, given two references to them. Structures are matched
element by element, free references become bound.

@param  a1 The address of the first structure or reference.
@param  a2 The address of the second structure or reference.

@return <tt>true</tt> if the two structures unify, <tt>false</tt> otherwise.