Check types: issue a message if n's type is not compatible with its expected type.
Check types: issue a message if n's type is not compatible with its expected type. The unknown type is compatible with any other type.
Default environment.
Default environment. Contains entities for the pre-defined predicates for lists: cons and nil.
The program entity referred to by a predicate or atom.
The program entity referred to by a predicate or atom. We just look in the environment. If it's not there, then use the unknown entity. If we have implemented the environments correctly, nothing can be unknown since the first appearance is the defining ocurrence.
The entity for a given predicate or atom that is implied by the context.
The entity for a given predicate or atom that is implied by the context. This differs from entity because it doesn't account for information implied by the node itself. Used for type checking since we don't want to use information from this node to check this node (a circularity).
The environment containing all bindings visible "after" a particular node in the tree.
The environment containing all bindings visible "after" a particular node in the tree. The only nodes that add bindings are the first occurrence of any particular predicate. Other nodes just pass the environment through: a node with children gets the env coming out of its last child; a node with no children just passes its own envin.
For type checking we record the types of predicate arguments. If this is the defining occurrence of a predicate, we obtain the types of the actual arguments and use those. Otherwise, we use only those argument types for which we don't know anything already.
The environment containing all bindings visible at a particular node in the tree, not including any that are defined at that node.
The environment containing all bindings visible at a particular node in the tree, not including any that are defined at that node. If we are at the top of the tree, initialise the environment to be empty. Otherwise, if we are in a sequence, ask the previous node for its environment, including any definitions there. If we are the first in a sequence or not in a sequence, ask the parent.
The semantic error messages for a given tree.
The expected type of a term, given by the context.
The expected type of a term, given by the context. The only place that terms can be used is as predicate arguments, so we look up the predicate to find out what its argument constraints are and select the one that corresponds to this argument. The index property gives us the position of the variable in the argument list.
The type of a term given by the previous uses.
The variable entity for a particular variable name, given by the context before this occurrence.
The environment containing visible variables *after* this node.
The environment containing visible variables *after* this node. Only updates at variable nodes. If the variable has not been seen before, we insert a binding to a new variable with a type give by the expected type for the context. Otherwise, if the variable has been seen before, if it has an unknown type, then we update that type to the expected type for the context. Otherwise, the variable has been seen before and already has a type constraint, so we don't change anything.
The environment of variables that are visible at this node.
The environment of variables that are visible at this node. This env gets reset for each clause since the variables of one clause are not related to those in the next clause.