|Did you know ...||Search Documentation:|
|Creating a saved state|
The predicates in this section support creating a saved state. Note that states are commonly created from the commandline using the -c, for example:
swipl -o mystate --foreign=save -c load.pl
--) options are translated into options for
This transformation uses the same conventions as used by argv_options/3,
except that the transformation is guided by the option type. This
implies that integer and callable options need to have valid syntax and
boolean options may be abbreviated to simply
--no-autoload as shorthands for
stand_aloneoption, the resource is headed by the emulator, a Unix shell script or nothing. Options is a list of additional options:
prologstarts the Prolog toplevel and
defaultruns halt/0 if there are initialization goals and the prolog/0 toplevel otherwise.
main, the default toplevel is to enter the Prolog interactive shell unless a goal has been specified using
runtime(default), read resources from the state and disconnect the code loaded into the state from the original source. If
development, save the predicates in their current state and keep reading resources from their source (if present). See also open_resource/3.
true(default), run autoload/0 first. If the class is
true, the state is supposed to be self contained and autoloading is disabled in the restored state.
save(default) to save the current operator table or
standardto use the initial table of the emulator.
true, the emulator is the first part of the state. If the emulator is started it tests whether a saved state is attached to itself and load this state. Provided the application has all libraries loaded, the resulting executable is completely independent from the runtime environment or location where it was built. See also section 22.214.171.124.
save, include shared objects (DLLs) for the current architecture into the saved state. See current_foreign_library/2, and current_prolog_flag(arch, Arch). If the program strip is available, this is first used to reduce the size of the shared object. If a state is started, use_foreign_library/1 first tries to locate the foreign resource in the resource database. When found it copies the content of the resource to a temporary file and loads it. If possible (Unix), the temporary object is deleted immediately after opening.223This option is experimental and currently disabled by default. It will become the default if it proves robust.224Creating a temporary file is the most portable way to load a shared object from a zip file but requires write access to the file system. Future versions may provide shortcuts for specific platforms that bypass the file system.
If Action is of the form
then the shared objects for the specified architectures are stored in
the saved state. On the command line, the list of architectures can be
In order to obtain the shared object file for the specified
calls a user defined hook:
qsave:arch_shlib(+Arch, +FileSpec, -SoPath). This hook
needs to unify
SoPath with the absolute path to the shared
object for the specified architecture.
FileSpec is of the
At runtime, SWI-Prolog will try to load the shared library which is
compatible with the current architecture, obtained by calling
current_prolog_flag(arch, Arch). An architecture is
compatible if one of the two following conditions is true (tried in
qsave:compat_arch(Arch1, Arch2)hook succeeds.
This last one is useful when one wants to produce one shared object file that works for multiple architectures, usually compiling for the lowest common denominator of a certain CPU type. For example, it is common to compile for armv7 if even if the code will be running on newer arm CPUs. It is also useful to provide highly-optimized shared objects for particular architectures.
error. In the latter case creating the state is aborted with a message that indicates the undefines predicates and from where they are called.
false), replace predicate names with generated symbols to make the code harder to assess for reverse engineering. See section 13.6.1.
false), report progress and status, notably regarding auto loading.
This predicate is used by qsave_program/[1,2] to ensure the saved state does not depend on availability of the libraries. The predicate autoload_all/0 examines all clauses of the loaded program (obtained with clause/2) and analyzes the body for referenced goals. Such an analysis cannot be complete in Prolog, which allows for the creation of arbitrary terms at runtime and the use of them as a goal. The current analysis is limited to the following:
The analysis of meta-predicate arguments is limited to cases where the argument appears literally in the clause or is assigned using =/2 before the meta-call. That is, the following fragment is processed correctly:
..., Goal = prove(Theory), forall(current_theory(Theory), Goal)),
But, the calls to prove_simple/1 and prove_complex/1 in the example below are not discovered by the analysis and therefore the modules that define these predicates must be loaded explicitly using use_module/[1,2].
..., member(Goal, [ prove_simple(Theory), prove_complex(Theory) ]), forall(current_theory(Theory), Goal)),
It is good practice to use gxref/0 to make sure that the program has sufficient declarations such that the analysis tools can verify that all required predicates can be resolved and that all code is called. See meta_predicate/1, dynamic/1, public/1 and prolog:called_by/2.