The compiler is invoked directly at the interpreter level (or in a program) through the Prolog predicates compile/[1,2].
?- compile(Files).
is just a notational shorthand for the query:
?- compile(Files, []).
The standard predicates consult/[1,2] call compile/1 (if necessary). Error conditions for compile/[1,2] are similar to those for consult/[1,2].
The list of compiler options OptionList, if specified, should be a proper Prolog list, i.e. a term of the form:
The source file name corresponding to a given module is obtained by concatenating a directory prefix and the extension .P (or other filenames, see Section 3.3) to the module name. The directory prefix must be in the dynamic loader path (see Section 3.6). Note that these directories are searched in a predetermined order (see Section 3.6), so if a module with the same name appears in more than one of the directories searched, the compiler will compile the first one it encounters. In such a case, the user can override the search order by providing an absolute path name.
If File contains no extension, an attempt is made to compile the file File.P (or other extensions) before trying compiling the file with name File.
We recommend use of the extension .P for Prolog source file to avoid ambiguity. Optionally, users can also provide a header file for a module (denoted by the module name suffixed by .H). In such a case, the XSB compiler will first read the header file (if it exists), and then the source file. Currently the compiler makes no special treatment of header files. They are simply included in the beginning of the corresponding source files, and code can, in principle, be placed in either.
The result of the compilation (an SLG-WAM object code file) is stored
in a (
filename
.xwam), but compile/[1,2] does not load the object file it creates. (The standard predicates consult/[1,2] and reconsult/[1,2] both recompile the source
file, if needed, and load the object file into the system.) The
object file created is always written into the directory where the
source file resides (the user must therefore have write permission
in that directory).
If desired, when compiling a module (file), clauses and directives can be transformed as they are read. This is indeed the case for definite clause grammar rules (see Chapter 10), but it can also be done for clauses of any form by providing a definition for predicate term_expansion/2 (see Section 10.3).
Predicates compile/[1,2] can also be used to compile foreign language modules. In this case, the names of the source files should have the extension .c and a .P file must not exist. A header file (with extension .H) must be present for a foreign language module (see the chapter Foreign Language Interface in Volume 2).