| OCR Text |
Show 34 head of a list. Since this argument is instantiated to a list already. this instruction succeeds and puts the machine into READ mode. Unification will be attempted with the existing structure, referenced by the register X3. The unify_ value instruction places a reference to the head of the list in X4 and the unify_ cdr instruction places a reference to the tail of the list in X3. The execute instruction causes control to branch to the switch_on_term instruction again. Note that much of the unification is handled through specific instructions which are tailored to the specific type of term. This "indexing" eliminates many calls to a generic unification procedure. Note also that the instructions load the argument registers for the next procedure while unifying the incoming arguments. Furthermore, no permanent variables were created, saving the memocy and overhead of creating and accessing an environment on the stack. These and other optimizations make the W AM vecy efficient for sequential logic programs. 2.4.3 Backtracking and Stack Recovery Because the WAM is stack-based, recovecy of space is vecy efficient, usually consisting simply of resetting a stack pointer to some location earlier in the stack. There is one exception, involving the (local) stack. Space on the stack can be recovered only if doing so does not cause a variable value to be lost. This situation can occur when there is a possibility of a permanent variable (whose value cell is on the stack) is bound to an unbound permanent variable. The binding of first variable can be saved in a register, but if the stack is recovered to a point before the second variable's value cell, the register will contain an invalid reference. Permanent variables for which this situation could occur are called unsafe vwiables. When the stack is to be recovered, a test is made and if the unsafe variable is bound to an item on the stack, that item is copied to the heap. Stack-based execution enables two other memocy optimizations: tail-recursion optimization (more appropriately termed last-caU optimization and environment trimming. Last-call optimization allows the stack space for the current environment to be recovered just before the call to the final goal of a clause; recursive clauses can |