wam.compiler

assoc-variables

(assoc-variables ctx register-allocation)

compile-structure

(compile-structure instruction-builder structure register-allocation seen?)

compile-term

(compile-term builder term)
Emits a sequence of instructions that equates to provided term according
to the rules of the builder. Returns a function which is capable of
executing the instructions given a context.

emit-instructions

(emit-instructions builder term register-allocation)
Constructs a sequence of instructions (missing the context argument)
suitable for threading with a context. The builder determines how
the structures in the term are walked (generally pre-order for
programs, and post-order for queries), and emits the most
appropriate instructions for each structure, which is reliant on
which arguments have been previously processed.

program

(program ctx expression)

program-builder

query

(query ctx expression)

query-builder

register-allocation

(register-allocation term)
Variable registers are allocated to a term on a least available index basis
such that (1) register X1 is always allocated to the otutermost term, and
(2) the same register is allocated to all occurrences of a given variable.
For example, registers are allocated to the variables of the term
p(Z, h(Z,W), f(W)) as follows:

  X1 = p(X2, X3, X4)
  X2 = Z
  X3 = h(X2, X5)
  X4 = f(X5)
  X5 = W

This amounts to saying that a term is seen as a flattened conjunctive set
of equations of the form Xi = X or Xi = f(Xi1, ..., Xin), n>=0 where
the Xi's are all distinct new variable names.

A hashmap is returned with key as the term, and the value as allocated
register,

register-names

(register-names prefix)
Generates an infinite incrementing sequence of register symbols,
e.g. X1, X2, X3, X4 ...

single-step

(single-step ctx [instr & args])
Execute an instruction with respect to the supplied context, if
the fail flag has not been set. If the context has failed, then
just return the context unchanged (i.e. don't execute the instruction).
This causes the remaining instructions to also fall through.