A psi-term is a generalization of a Prolog term. A psi-term has a sort (corresponding to the main functor) which lives in a hierarchy (a lattice). Unification of sorts is a glb operation on the lattice. A psi-term may have any number of named fields ("features"), and features may be added at run-time. Therefore psi-terms do not have an arity. A psi-term may have cycles and sharing between subterms.
Terminology for the algorithm: Each occurrence of a subterm (even a coreferenced one) is considered as a separate psi-term. A coreference class is a set of occurrences that are linked by equality constraints. The first member of a coreference class that is encountered in a depth-first traversal of a term is called the representative member. Coreferences are handled by the judicious placement of unify instructions (see Fig. 3).
Unification compilation is done in 60 lines and peephole optimization in 80 lines. Together with 110 lines of utility routines, this results in 250 lines of Life code. This includes a naive register allocator which maps each subterm occurrence to a different register.
| init_test | ---------------- | Read stream | ---------------- | jump(L) | ---------------- | Write stream | ---------------- | label(L) |
Insert the following instructions into the read and write code streams: Read stream Write stream ----------------------------------------------------------------------------- | | For the rootsort of T: intersect_sort(Rt,s) set_sort(Rt,s) | | ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- For all features f of T: | | test_feature(Rt,f,Rf,L,l) --> label(L) | push_cell(Rf) | set_feature(Rt,f,Rf) | | ----------------------------------------- | Compile psi-term T.f at level l+1 | ----------------------------------------- | | label(L') <------------------ write_test(l,L') | | ----------------------------------------- | Handle possible coreference of T.f | ----------------------------------------- | | -----------------------------------------------------------------------------
----------------------------------------------------------------------------- | | If T.f is in a coreference unify(Rf,Rc) unify(Rf,Rc) class, but is *not* the | | representative member: | | | | -----------------------------------------------------------------------------