next up previous contents index
Next: Fetching arguments of Prolog Up: Calling C from Prolog Previous: Calling C from Prolog   Contents   Index

Term representation

A term is represented by a word containing a value and a tag. The tag, which takes the two lowest bits, distinguishes the type of the term. It may be 00 denoting a reference, 10 denoting an integer or an atom, 01 denoting a structure, and 11 denoting a list. Floating-point numbers are represented as special structures in the form of $float(I1,I2,I3) where I1, I2 and I3 are integers.

The value of a term is an address except when the term is an integer (in this case, the value represents the integer itself). The address points to a different place depending on the type of the term. The address in a reference points to the referenced term. An unbound variable is represented by a self-referencing pointer. The address in an atom points to the record for the atom symbol in the symbol table. The address in a structure $f(t_1,\ldots,t_n)$ points to a block of $n+1$ consecutive words where the first word points to the record for the functor $f/n$ in the symbol table and the remaining $n$ words store the components of the structure. The address in a list $[H\vert T]$ points to a block of two consecutive words where the first word stores the car $H$ and the second word stores the cdr $T$.


next up previous contents index
Next: Fetching arguments of Prolog Up: Calling C from Prolog Previous: Calling C from Prolog   Contents   Index
Neng-Fa Zhou
1999-11-24