Once a program has been read, the system will have available all the information necessary for its execution. This information is called a program state.
The saved-state of a program may be saved on disk for future execution. To save a program into a file File, type the following query. On UNIX platforms, the file becomes executable:
| ?- save_program(File).
You can also specify a goal to be run when a saved program is restored. This is done by:
| ?- save_program(File, start).
start/0 is the predicate to be called.
Once a program has been saved into a file File, the following query will restore the system to the saved-state:
| ?- restore(File).
If a saved-state has been moved or copied to another machine, the path names of foreign resources and other files needed upon restore are typically different at restore time from their save time values. To solve this problem, certain atoms will be relocated during restore as follows:
The purpose of this procedure is to be able to build and deploy an application consisting of a saved-state and other files as a directory tree with the saved-state at the root: as long as the other files maintain their relative position in the deployed copy, they can still be found upon restore.
Please note: Foreign resources, see Calling C from Prolog, are unloaded by
save_program/[1,2]. The names and paths of the resources, typically $SP_PATH/library relative, are however included in the saved-state. After the save, and after restoring a saved-state, this information is used to reload the foreign resources again. The state of the foreign resource in terms of global C variables and allocated memory is thus not preserved. Foreign resources may define init and deinit functions to take special action upon loading and unloading; see Init and Deinit Functions.
As of SICStus Prolog 3.8, partial saved-states corresponding to a
set of source files, modules, and predicates can be created
by the built-in predicates
save_predicates/2 respectively. These
predicates create files in a binary format, by default with the
prefix `.po' (for Prolog object file), which can be loaded by
load_files/[1,2]. For example, to compile a program
split into several source files into a single object file, type:
| ?- compile(Files), save_files(Files, Object).
For each filename given, the first goal will try to locate a source file with the default suffix `.pl' and compile it into memory. The second goal will save the program just compiled into an object file whose default suffix is `.po'. Thus the object file will contain a partial memory image.
Please note: Prolog object files can be created with any suffix, but cannot be loaded unless the suffix is `.po'!