Node:Load Intro, Next:, Previous:Module Intro, Up:Top



Loading Programs

Programs can be loaded in three different ways: consulted or compiled from source file, or loaded from object files. The latter is the fastest way of loading programs, but of course requires that the programs have been compiled to object files first. Object files may be handy when developing large applications consisting of many source files, but are not strictly necessary since it is possible to save and restore entire execution states (see Misc Pred).

Consulted, or interpreted, predicates are equivalent to, but slower than, compiled ones. Although they use different representations, the two types of predicates can call each other freely.

The SICStus Prolog compiler produces compact and efficient code, running about 8 times faster than consulted code, and requiring much less runtime storage. Compiled Prolog programs are comparable in efficiency with LISP programs for the same task. However, against this, compilation itself takes about twice as long as consulting, and tracing of goals that compile in-line are not available in compiled code.

The compiler operates in four different modes, controlled by the "Compilation mode" flag (see prolog_flag/3). The possible states of the flag are:

compactcode
Compilation produces byte-coded abstract instructions. This is the default unless SICStus Prolog has been installed with support for fastcode compilation.
fastcode
Compilation produces native machine instructions. Currently only available for Sparc platforms. Fastcode runs about 3 times faster than compactcode. This is the default if SICStus Prolog has been installed with support for fastcode compilation.
profiledcode
Compilation produces byte-coded abstract instructions instrumented to produce execution profiling data. See Profiling. Profiling is not available in runtime systems.
debugcode
Compilation produces interpreted code, i.e. compiling is replaced by consulting.

The compilation mode can be changed by issuing the query:

     | ?- prolog_flag(compiling, OldValue, NewValue).
     

A Prolog program consists of a sequence of sentences (see Sentence). Directives encountered among the sentences are executed immediately as they are encountered, unless they can be interpreted as declarations (see Declarations), which affect the treatment of forthcoming clauses, or as initializations, which build up a set of goals to be executed after the program has been loaded. Clauses are loaded as they are encountered.

A Prolog program may also contain a list of sentences (including the empty list). This is treated as equivalent to those sentences occurring in place of the list. This feature makes it possible to have user:term_expansion/[2,4] (see Definite) "return" a list of sentences, instead of a single sentence.