The compilation of a single clause is not affected by the standard indexing method and the enhanced indexing methods described in this paper. In case you are not familiar with the WAM, the following small examples will give you an idea of how clauses are compiled.
Consider the following clause:
less(0,N).Here is the WAM assembler code for the procedure:
less/2 get_constant 0, X1 proceedless/2 is the entry label for the procedure. The /2 is needed no distinguish the binary relation less from, say, a unary procedure with the same name.
get_constant is one of the instructions used for unification. In this case, the register X1, which always contains the first argument passed to a procedure, is unified with the constant 0: If X1 is a free variable, X1 is bound to the constant 0; if X1 is bound, this instruction ``fails'' iff X1 is not bound to 0, otherwise no action is taken.
For the (really anonymous) variable in the second argument no instruction is necessary.
The proceed instruction simply marks the end of a procedure. It acts quite similarly to the return instruction in conventional machine languages.
Compiling a rule is almost as simple as compiling a fact; the assembler code sequences for the head and the body are concatenated:
less(s(M), s(N)) :- less(M, N).Here is the WAM assembler code for the rule:
less/2 allocate 0 % allocate a new environment on the stack get_structure s/1, X1 % head: less(s( unify_variable X3 % M), get_structure s/1, X2 % s( unify_variable X4 % N)) :- put_value X3, X1 % body: put_value X4, X2 call less/2, 0 % less(M, N). deallocate % remove the environment frame proceed