next up previous contents index
Next: The multifile directive Up: 3. System Description Previous: 3.8 Memory Management   Contents   Index


3.9 Compiling, Consulting, and Loading

Like other Prologs, XSB provides for both statically compiled code and dynamically asserted code. Unlike some Prologs, however, there is no difference between compiled and consulted code. Abstractly, ``Compiling'' in XSB means creation of a file containing SLG-WAM byte-code; ``Consulting'' means loading such a byte-code file, (and perhaps creating the file itself, via compilation). Compiled code may be more optimized than asserted code, but certain types of indexing, such as trie and star indexing are (currently) available only for dynamically asserted predicates (see index/2).

The standard predicate consult/[1,2] is the most convenient method for entering static source code rules into XSB's database 3.7. consult/1 has the form:

consult(+Files)
in which Files is either a file designator (see Section 3.3) or a list of file designators. consult/1 compiles any files specified in Files that have been touched later than their byte-code files, and loads them into XSB. In addition the form
[Files].
Is an alternative syntax for consult(Files).

consult/2 has the form.

consult(+Files, +CompilerOptionList)
Files is as in consult/1 and CompilerOptionList is a list of options that are to be passed to the compiler if it is invoked (alternatively, these compiler options can be declared in the files themselves, as in Section 3.10. consult/2 is more general than consult/1, and consult(Files) is defined as consult(FileName, []).

Consulting a file (module) conceptually consists of the following five steps which are described in detail in the following paragraphs.

Name Resolution:
determine the file to be consulted, including directory and drive location and extension.
Compilation:
if the source file has changed later than the object file, compile the module using predicate compile/2 with the options specified.
Loading:
load the object code of the file into memory.
Importing:
if the file is a module, import any the exported predicates of that module to usermod.
Query Execution:
execute any queries that the file may contain.

There are two steps to name resolution: determining the proper directory prefix and determining the proper file extension. When FileName is absolute (i.e. it contains a path from the file to the root of the file system) determining the proper directory prefix is straightforward. If FileName is relative, i.e. it contains a '/' in Unix or '/' in Windows, FileName is expanded to a directory prefix in an OS-dependent way, resolving symbols like '.', '..' and '~' when applicable. However, the user may also enter a name without any directory prefix. In this case, the directory prefix is a directory in the dynamic loader path (see Section 3.6) where the source file exists. Once the directory prefix is determined, the file name is checked for an extension. If there is no extension the loader first checks for a file in the directory with the .P extension, (or .c for foreign modules) before searching for a file without the extension, and finally for a file with a .pl extension. Note that since directories in the dynamic loader path are searched in a predetermined order (see Section 3.6), if the same file name appears in more than one of these directories, the compiler will consult the first one it encounters.

Compilation is performed if the update date of a source file (*.P/.pl or *.H) is later than that of the the object file (*.xwam). Currently (Version 3.0), a foreign language module is compiled when at least one of files *.c or *.H has been changed from the time the corresponding object files have been created.

Once the file is compiled into byte-code, the byte-code for the file is loaded into XSB's database. After loading the file all exported predicates of that module are imported into the current environment (the current working module usermod) if the file is a module. For non-modules, all predicates are imported into the current working module. As the last part of loading, any queries -- that is, any terms with principal functor '?-'/1, or with the principal functor ':-'/1 and that are not directives like the ones described in Section 3.10 are executed in the order that they are encountered.

Error conditions for consult(+File) are as follows:



Subsections
next up previous contents index
Next: The multifile directive Up: 3. System Description Previous: 3.8 Memory Management   Contents   Index
Terrance Swift 2007-10-05