This commit is contained in:
Vítor Santos Costa
2014-09-22 18:13:35 +01:00
parent f29e017c63
commit 3e255ec4a1
18 changed files with 476 additions and 196 deletions

View File

@@ -76,7 +76,7 @@
3. `executable` implies `['.so', ',dylib', '.dll']` depending on the Operating system,
4. `qlf` implies `['.qlf', '']`,
4. `qly` implies `['.qly', '']`,
5. `directory` implies `['']`,
@@ -209,7 +209,7 @@ absolute_file_name(File0,File) :-
'$check_fn_type'(prolog,_) :- !.
'$check_fn_type'(source,_) :- !.
'$check_fn_type'(executable,_) :- !.
'$check_fn_type'(qlf,_) :- !.
'$check_fn_type'(qly,_) :- !.
'$check_fn_type'(directory,_) :- !.
'$check_fn_type'(T,G) :- atom(T), !,
'$do_error'(domain_error(file_type,T),G).
@@ -563,6 +563,8 @@ remove_from_path(New) :- '$check_path'(New,Path),
prolog_file_type(yap, prolog).
prolog_file_type(pl, prolog).
prolog_file_type(prolog, prolog).
prolog_file_type(qly, prolog).
prolog_file_type(qly, qly).
prolog_file_type(A, prolog) :-
current_prolog_flag(associate, A),
A \== prolog,
@@ -586,8 +588,8 @@ user:prolog_file_type(A, prolog) :-
A \== prolog,
A \==pl,
A \== yap.
%user:prolog_file_type(qlf, prolog).
%user:prolog_file_type(qlf, qlf).
user:prolog_file_type(qly, prolog).
user:prolog_file_type(qly, qly).
user:prolog_file_type(A, executable) :-
current_prolog_flag(shared_object_extension, A).

View File

@@ -30,7 +30,8 @@
source_file/1,
source_file/2,
source_file_property/2,
use_module/3], ['$add_multifile'/3,
use_module/3],
['$add_multifile'/3,
'$csult'/2,
'$do_startup_reconsult'/1,
'$elif'/2,
@@ -92,62 +93,79 @@ files and to set-up the Prolog environment. We discuss
General implementation of the consult/1 family. Execution is controlled by the
following flags:
+ consult(+ _Mode_)
This extension controls the type of file to load. If _Mode_ is:
`consult`, clauses are added to the data-base, unless from the same file;
`reconsult`, clauses are recompiled,
`db`, these are facts that need to be added to the data-base,
`exo`, these are facts with atoms and integers that can be stored in a compact representation (see load_exo/1).
+ consult(+ _Mode_)
+ silent(+ _Bool_)
If true, load the file without printing a message. The specified value is the default for all files loaded as a result of loading the specified files.
This extension controls the type of file to load. If _Mode_ is:
`consult`, clauses are added to the data-base, unless from the same file;
`reconsult`, clauses are recompiled,
`db`, these are facts that need to be added to the data-base,
`exo`, these are facts with atoms and integers that can be stored in a compact representation (see load_exo/1).
+ stream(+ _Input_)
This SWI-Prolog extension compiles the data from the stream _Input_. If this option is used, _Files_ must be a single atom which is used to identify the source-location of the loaded
clauses as well as remove all clauses if the data is re-consulted.
+ silent(+ _Bool_)
This option is added to allow compiling from non-file locations such as databases, the web, the user (see consult/1) or other servers.
If true, load the file without printing a message. The specified
value is the default for all files loaded as a result of loading
the specified files.
+ compilation_mode(+ _Mode_)
This extension controls how procedures are compiled. If _Mode_
is `compact` clauses are compiled and no source code is stored;
if it is `source` clauses are compiled and source code is stored;
if it is `assert_all` clauses are asserted into the data-base.
+ stream(+ _Input_)
+ encoding(+ _Encoding_)
Character encoding used in consulting files. Please (see [Encoding](@ref Encoding)) for
supported encodings.
This SWI-Prolog extension compiles the data from the stream
_Input_. If this option is used, _Files_ must be a single atom
which is used to identify the source-location of the loaded
clauses as well as remove all clauses if the data is re-consulted.
+ expand(+ _Bool_)
If `true`, run the
filenames through expand_file_name/2 and load the returned
files. Default is false, except for consult/1 which is
intended for interactive use.
This option is added to allow compiling from non-file locations
such as databases, the web, the user (see consult/1) or other
servers.
+ if(+ _Condition_)
Load the file only if the specified _Condition_ is
satisfied. The value `true` the file unconditionally,
`changed` loads the file if it was not loaded before, or has
been modified since it was loaded the last time, `not_loaded`
loads the file if it was not loaded before.
+ compilation_mode(+ _Mode_)
+ imports(+ _ListOrAll_)
If `all` and the file is a module file, import all public
predicates. Otherwise import only the named predicates. Each
predicate is referred to as `\<name\>/\<arity\>`. This option has
no effect if the file is not a module file.
This extension controls how procedures are compiled. If _Mode_ is
`compact` clauses are compiled and no source code is stored; if it
is `source` clauses are compiled and source code is stored; if it
is `assert_all` clauses are asserted into the data-base.
+ must_be_module(+ _Bool_)
If true, raise an error if the file is not a module file. Used by
` use_module/1 and use_module/2.
+ encoding(+ _Encoding_)
+ autoload(+ _Autoload_)
SWI-compatible option where if _Autoload_ is `true` undefined predicates
are loaded on first call.
Character encoding used in consulting files. Please (see
[Encoding](@ref Encoding)) for supported encodings.
+ expand(+ _Bool_)
If `true`, run the filenames through expand_file_name/2 and load
the returned files. Default is false, except for consult/1 which
is intended for interactive use.
+ if(+ _Condition_)
Load the file only if the specified _Condition_ is satisfied. The
value `true` the file unconditionally, `changed` loads the file if
it was not loaded before, or has been modified since it was loaded
the last time, `not_loaded` loads the file if it was not loaded
before.
+ imports(+ _ListOrAll_)
If `all` and the file is a module file, import all public
predicates. Otherwise import only the named predicates. Each
predicate is referred to as `\<name\>/\<arity\>`. This option has
no effect if the file is not a module file.
+ must_be_module(+ _Bool_)
If true, raise an error if the file is not a module file. Used by
` use_module/1 and use_module/2.
+ autoload(+ _Autoload_)
SWI-compatible option where if _Autoload_ is `true` undefined
predicates are loaded on first call.
+ derived_from(+ _File_)
SWI-compatible option to control make/0. Currently not supported.
+ derived_from(+ _File_)
SWI-compatible option to control make/0. Currently
not supported.
*/
%
% SWI options
@@ -368,13 +386,18 @@ load_files(Files,Opts) :-
'$lf'([F|Fs], Mod, Call, TOpts) :- !,
% clean up after each consult
( '$lf'(F,Mod,Call, TOpts), fail ;
'$lf'(Fs, Mod, Call, TOpts) ).
'$lf'(Fs, Mod, Call, TOpts), fail;
true
).
'$lf'(user, Mod, _, TOpts) :- !,
b_setval('$source_file', user_input),
'$do_lf'(Mod, user_input, user_input, TOpts).
'$lf'(user_input, Mod, _, TOpts) :- !,
b_setval('$source_file', user_input),
'$do_lf'(Mod, user_input, user_input, TOpts).
'$lf'(File, Mod, Call, TOpts) :-
'$lf_opt'(stream, TOpts, Stream),
b_setval('$source_file', File),
( var(Stream) ->
/* need_to_open_file */
'$full_filename'(File, Y, Call),
@@ -664,16 +687,16 @@ db_files(Fs) :-
'$bind_module'(Mod, use_module(Mod)).
'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts) :-
\+ recorded('$module','$module'(File, _Module, _ModExports, _),_),
\+ recorded('$module','$module'(File, _Module, _, _ModExports, _),_),
% enable loading C-predicates from a different file
recorded( '$load_foreign_done', [File, M0], _),
'$import_foreign'(File, M0, ContextModule ),
fail.
'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts) :-
recorded('$module','$module'(File, Module, ModExports, _),_),
recorded('$module','$module'(File, Module, _Source, ModExports, _),_),
Module \= ContextModule, !,
'$lf_opt'('$call', TOpts, Call),
% '$lf_opt'('$call', TOpts, Call),
'$convert_for_export'(Imports, ModExports, Module, ContextModule, TranslationTab, RemainingImports, Goal),
'$add_to_imports'(TranslationTab, Module, ContextModule).
'$import_to_current_module'(_, _, _, _, _).
@@ -888,9 +911,9 @@ prolog_load_context(source, F0) :-
prolog_load_context(stream, Stream) :-
'$nb_getval'('$consulting_file', _, fail),
'$current_loop_stream'(Stream).
% return this term for SWI compatibility.
prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :-
source_location(_, Line).
prolog_load_context(term_position, Position) :-
'$current_loop_stream'(Stream),
stream_property(Stream, position(Position) ).
% if the file exports a module, then we can
@@ -902,7 +925,7 @@ prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :-
'$import_to_current_module'(F1, M, Imports, _, TOpts).
'$ensure_file_loaded'(F, M, F1) :-
recorded('$module','$module'(F1,_NM,_P,_),_),
recorded('$module','$module'(F1,_NM,_Source,_P,_),_),
recorded('$lf_loaded','$lf_loaded'(F1, _, _),_),
same_file(F1,F), !.
'$ensure_file_loaded'(F, M, F1) :-
@@ -920,7 +943,7 @@ prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :-
'$import_to_current_module'(F1, M, Imports, _, TOpts).
'$ensure_file_unchanged'(F, M, F1) :-
recorded('$module','$module'(F1,_NM,_P,_),_),
recorded('$module','$module'(F1,_NM,_,_P,_),_),
recorded('$lf_loaded','$lf_loaded'(F1,Age,_),R),
same_file(F1,F), !,
'$file_is_unchanged'(F, R, Age).
@@ -1046,7 +1069,7 @@ source_file_property( File0, Prop) :-
'$source_file_property'( F, modified(Age)) :-
recorded('$lf_loaded','$lf_loaded'( F, Age, _), _).
'$source_file_property'( F, module(M)) :-
recorded('$module','$module'(F,M,_,_),_).
recorded('$module','$module'(F,M,_,_,_),_).
/**
@@ -1094,13 +1117,13 @@ use_module(M,F,Is) :- '$use_module'(M,F,Is).
( var(M) -> true
;
absolute_file_name( F0, F1, [expand(true),file_type(prolog)] ),
recorded('$module','$module'(F1,M,_,_),_)
recorded('$module','$module'(F1,M,_,_,_),_)
).
'$use_module'(M,F,Is) :-
nonvar(M), !,
strip_module(F, M0, F0),
(
recorded('$module','$module'(F1,M,_,_),_)
recorded('$module','$module'(F1,M,_,_,_),_)
->
'$load_files'(M0:F1, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
),
@@ -1178,9 +1201,11 @@ may result in incorrect execution.
This section presents a set of built-ins predicates designed to set the
environment for the compiler.
prolog_to_os_filename(+ _PrologPath_,- _OsPath_) @anchor prolog_to_os_filename
*/
/** @pred prolog_to_os_filename(+ _PrologPath_,- _OsPath_)
This is an SWI-Prolog built-in. Converts between the internal Prolog
pathname conventions and the operating-system pathname conventions. The
@@ -1223,8 +1248,6 @@ last one, onto underscores.
fail.
'$remove_multifile_clauses'(_).
/** @pred initialization(+ _G_) is iso
The compiler will execute goals _G_ after consulting the current
file.

View File

@@ -97,7 +97,12 @@
'$exec_directives'(G1, Mode, M, VL, Pos),
'$exec_directives'(G2, Mode, M, VL, Pos).
'$exec_directives'(G, Mode, M, VL, Pos) :-
'$exec_directive'(G, Mode, M, VL, Pos).
'$save_directive'(G, Mode, M, VL, Pos),
'$exec_directive'(G, Mode, M, VL, Pos).
'$save_directive'(G, Mode, M, VL, Pos) :-
prolog_load_context(file, FileName), !,
recorda('$directive', directive(File,M:G, Mode, VL, Pos),_).
'$exec_directive'(multifile(D), _, M, _, _) :-
'$system_catch'('$multifile'(D, M), M,

View File

@@ -58,13 +58,19 @@ load_foreign_files(_Objs,_Libs,_Entry) :-
recorded( '$load_foreign_done', [F, M0], _), !,
'$import_foreign'(F, M0, M).
load_foreign_files(Objs,Libs,Entry) :-
'$check_objs_for_load_foreign_files'(Objs,NewObjs,load_foreign_files(Objs,Libs,Entry)),
'$check_libs_for_load_foreign_files'(Libs,NewLibs,load_foreign_files(Objs,Libs,Entry)),
'$check_entry_for_load_foreign_files'(Entry,load_foreign_files(Objs,Libs,Entry)),
'$load_foreign_files'(NewObjs,NewLibs,Entry),
'$check_objs_for_load_foreign_files'(Objs,NewObjs,load_foreign_files(Objs,Libs,Entry)),
'$check_libs_for_load_foreign_files'(Libs,NewLibs,load_foreign_files(Objs,Libs,Entry)),
'$check_entry_for_load_foreign_files'(Entry,load_foreign_files(Objs,Libs,Entry)),
'$load_foreign_files'(NewObjs,NewLibs,Entry),
ignore( recordzifnot( '$foreign', M:'$foreign'(Objs,Libs,Entry), _) ),
(
prolog_load_context(file, F),
prolog_load_context(module, M),
ignore( recordzifnot( '$load_foreign_done', [F, M], _) ), !.
prolog_load_context(module, M)
->
ignore( recordzifnot( '$load_foreign_done', [F, M], _) )
;
true
), !.
'$check_objs_for_load_foreign_files'(V,_,G) :- var(V), !,
'$do_error'(instantiation_error,G).
@@ -147,7 +153,7 @@ dlerror().
*/
open_shared_object(File, Handle) :-
'$open_shared_object'(File, 0, Handle).
open_shared_object(File, [], Handle).
/** @pred open_shared_object(+ _File_, - _Handle_, + _Options_)
@@ -165,7 +171,9 @@ flags are silently ignored.
*/
open_shared_object(File, Opts, Handle) :-
'$open_shared_opts'(Opts, open_shared_object(File, Opts, Handle), OptsI),
'$open_shared_object'(File, OptsI, Handle).
'$open_shared_object'(File, OptsI, Handle),
prolog_load_context(module, M),
ignore( recordzifnot( '$foreign', M:'$swi_foreign'(File,Opts, Handle), _) ).
'$open_shared_opts'(Opts, G, OptsI) :-
var(Opts), !,
@@ -184,17 +192,18 @@ open_shared_object(File, Opts, Handle) :-
'$open_shared_opt'(Opt, Goal, _) :-
'$do_error'(domain_error(open_shared_object_option,Opt),Goal).
/** @pred call_shared_object_function(+ _Handle_, + _Function_)
Call the named function in the loaded shared library. The function
is called without arguments and the return-value is
ignored. In SWI-Prolog, normally this function installs foreign
language predicates using calls to `PL_register_foreign()`.
/** @pred call_shared_object_function(+ _Handle_, + _Function_)
Call the named function in the loaded shared library. The function is
called without arguments and the return-value is ignored. YAP supports
installing foreign language predicates using calls to 'UserCCall()`,
`PL_register_foreign()`, and friends.
*/
call_shared_object_function( Handle, Function) :-
'$call_shared_object_function'( Handle, Function),
prolog_load_context(module, M),
ignore( recordzifnot( '$foreign', M:'$swi_foreign'( Handle, Function ), _) ).
%%! @}

View File

@@ -389,7 +389,8 @@ name with the `:/2` operator.
**/
'$module_dec'(N, Ps) :-
source_location(F, _),
'$add_module_on_file'(N, F, Ps),
b_getval( '$source_file', F0 ),
'$add_module_on_file'(N, F, F0, Ps),
'$current_module'(_,N).
'$module'(_,N,P) :-
@@ -399,7 +400,7 @@ name with the `:/2` operator.
\pred module(+ M:atom,+ L:list ) is directive
the current file defines module _M_ with exports _L_. The list may include
+ predicatae indicators
+ predicate indicators
+ operator definitions that look like calls to op/3.
@@ -479,21 +480,21 @@ of predicates.
'$prepare_restore_hidden'(Old,New) :-
recorda('$system_initialisation', source_mode(New,Old), _).
'$add_module_on_file'(DonorMod, DonorF, Exports) :-
recorded('$module','$module'(DonorF, DonorMod, _, _),R),
'$add_module_on_file'(DonorMod, DonorF, SourceF, Exports) :-
recorded('$module','$module'(DonorF, DonorMod, _, _, _),R),
% the module has been found, are we reconsulting?
(
DonorF \= OtherF
->
'$do_error'(permission_error(module,redefined,DonorMod, OtherFile, DonorF),module(Mod,Exports))
;
recorded('$module','$module'(DonorF,DonorM, _, _), R),
recorded('$module','$module'(DonorF,DonorMod, SourceF, _, _), R),
erase( R ),
fail
).
'$add_module_on_file'(DonorM, DonorF, Exports) :-
'$add_module_on_file'(DonorM, DonorF, SourceF, Exports) :-
'$current_module'( HostM ),
( recorded('$module','$module'( HostF, HostM, _, _),_) -> true ; HostF = user_input ),
( recorded('$module','$module'( HostF, HostM, _, _, _),_) -> true ; HostF = user_input ),
% first build the initial export tablee
'$convert_for_export'(all, Exports, DonorM, HostM, TranslationTab, AllExports0, load_files),
sort( AllExports0, AllExports ),
@@ -501,17 +502,17 @@ of predicates.
'$add_to_imports'(TranslationTab, DonorM, DonorM), % insert ops, at least for now
% last, export everything to the host: if the loading crashed you didn't actually do
% no evil.
recorda('$module','$module'(DonorF,DonorM,AllExports, Line),_).
recorda('$module','$module'(DonorF,DonorM,SourceF, AllExports, Line),_).
'$extend_exports'(HostF, Exports, DonorF ) :-
( recorded('$module','$module'( DonorF, DonorM, _, DonorExports),_) -> true ; DonorF = user_input ),
( recorded('$module','$module'( HostF, HostM, _, _),_) -> true ; HostF = user_input ),
recorded('$module','$module'(HostF,HostM,AllExports, _Line), R), erase(R),
( recorded('$module','$module'( DonorF, DonorM, SourceF, _, DonorExports),_) -> true ; DonorF = user_input ),
( recorded('$module','$module'( HostF, HostM, _, _, _),_) -> true ; HostF = user_input ),
recorded('$module','$module'(HostF, HostM, _, AllExports, _Line), R), erase(R),
'$convert_for_export'(Exports, DonorExports, DonorM, HostM, TranslationTab, AllReExports, reexport(DonorF, Exports)),
lists:append( AllReExports, AllExports, Everything0 ),
sort( Everything0, Everything ),
( source_location(_, Line) -> true ; Line = 0 ),
recorda('$module','$module'(HostF,HostM,Everything, Line),_).
recorda('$module','$module'(HostF,HostM,SourceF, Everything, Line),_).
'$module_produced by'(M, M0, N, K) :-
recorded('$import','$import'(M,M0,_,_,N,K),_), !.
@@ -552,7 +553,7 @@ Succeeds if _M_ are current modules associated to the file _F_.
*/
current_module(Mod,TFN) :-
'$all_current_modules'(Mod),
( recorded('$module','$module'(TFN,Mod,_Publics, _),_) -> true ; TFN = user ).
( recorded('$module','$module'(TFN,Mod,_,_Publics, _),_) -> true ; TFN = user ).
/** \pred source_module( - Mod:atom ) is nondet
: _Mod_ is the current read-in or source module.
@@ -1153,7 +1154,7 @@ be associated to a new file.
get rid of a module and of all predicates included in the module.
*/
abolish_module(Mod) :-
recorded('$module','$module'(_,Mod,_,_),R), erase(R),
recorded('$module','$module'(_,Mod,_,_,_),R), erase(R),
fail.
abolish_module(Mod) :-
recorded('$import','$import'(Mod,_,_,_,_,_),R), erase(R),
@@ -1180,23 +1181,23 @@ export_resource(Resource) :-
export_resource(P) :-
P = F/N, atom(F), number(N), N >= 0, !,
'$current_module'(Mod),
( recorded('$module','$module'(File,Mod,ExportedPreds,Line),R) ->
( recorded('$module','$module'(File,Mod,SourceF,ExportedPreds,Line),R) ->
erase(R),
recorda('$module','$module'(File,Mod,[P|ExportedPreds],Line),_)
; prolog_load_context(file, File) ->
recorda('$module','$module'(File,Mod,[P],Line),_)
; recorda('$module','$module'(user_input,Mod,[P],1),_)
recorda('$module','$module'(File,Mod,SourceF,[P],Line),_)
; recorda('$module','$module'(user_input,Mod,user_input,[P],1),_)
).
export_resource(P0) :-
P0 = F//N, atom(F), number(N), N >= 0, !,
N1 is N+2, P = F/N1,
'$current_module'(Mod),
( recorded('$module','$module'(File,Mod,ExportedPreds,Line),R) ->
( recorded('$module','$module'(File,Mod,SourceF,ExportedPreds,Line),R) ->
erase(R),
recorda('$module','$module'(File,Mod,[P|ExportedPreds],Line ),_)
recorda('$module','$module'(File,Mod,SourceF,[P|ExportedPreds],Line ),_)
; prolog_load_context(file, File) ->
recorda('$module','$module'(File,Mod,[P],Line),_)
; recorda('$module','$module'(user_input,Mod,[P],1),_)
recorda('$module','$module'(File,Mod,SourceF,[P],Line),_)
; recorda('$module','$module'(user_input,Mod,user_input,[P],1),_)
).
export_resource(op(Prio,Assoc,Name)) :- !,
op(Prio,Assoc,prolog:Name).
@@ -1204,7 +1205,7 @@ export_resource(Resource) :-
'$do_error'(type_error(predicate_indicator,Resource),export(Resource)).
export_list(Module, List) :-
recorded('$module','$module'(_,Module,List,_),_).
recorded('$module','$module'(_,Module,_,List,_),_).
'$convert_for_export'(all, Exports, _Module, _ContextModule, Tab, MyExports, _) :-
'$simple_conversion'(Exports, Tab, MyExports).
@@ -1334,7 +1335,7 @@ export_list(Module, List) :-
op(Prio,Assoc,ContextMod:Name).
'$do_import'(N0/K0-N0/K0, Mod, Mod) :- !.
'$do_import'(_N/K-N1/K, _Mod, ContextMod) :-
recorded('$module','$module'(_F, ContextMod, MyExports,_),_),
recorded('$module','$module'(_F, ContextMod, _SourceF, MyExports,_),_),
once(lists:member(N1/K, MyExports)),
functor(S, N1, K),
% reexport predicates if they are undefined in the current module.
@@ -1380,10 +1381,10 @@ export_list(Module, List) :-
( C == e -> halt(1) ;
C == y ).
'$redefine_action'(true, M1, _, _, _, _) :- !,
recorded('$module','$module'(F, M1, _MyExports,_Line),_),
recorded('$module','$module'(F, M1, _, _MyExports,_Line),_),
unload_file(F).
'$redefine_action'(false, M1, M2, M, ContextM, N/K) :-
recorded('$module','$module'(F, ContextM, _MyExports,_Line),_),
recorded('$module','$module'(F, ContextM, _, _MyExports,_Line),_),
'$current_module'(_, M2),
'$do_error'(permission_error(import,M1:N/K,redefined,M2),F).
@@ -1503,11 +1504,11 @@ delete_import_module(Mod, ImportModule) :-
module_property(Mod, class(L)) :-
'$module_class'(Mod, L).
module_property(Mod, line_count(L)) :-
recorded('$module','$module'(_F,Mod,_,L),_).
recorded('$module','$module'(_F,Mod,_,_,L),_).
module_property(Mod, file(F)) :-
recorded('$module','$module'(F,Mod,_,_),_).
recorded('$module','$module'(F,Mod,_,_,_),_).
module_property(Mod, exports(Es)) :-
recorded('$module','$module'(_,Mod,Es,_),_).
recorded('$module','$module'(_,Mod,_,Es,_),_).
'$module_class'(Mod, system) :- '$system_module'( Mod ).
'$module_class'(Mod, library) :- '$library_module'( Mod ).
@@ -1517,7 +1518,7 @@ module_property(Mod, exports(Es)) :-
'$module_class'(_, development) :- fail.
'$library_module'(M1) :-
recorded('$module','$module'(F, M1, _MyExports,_Line),_),
recorded('$module','$module'(F, M1, _, _MyExports,_Line),_),
user:library_directory(D),
sub_atom(F, 0, _, _, D).

View File

@@ -1097,7 +1097,7 @@ predicate_property(Pred,Prop) :-
'$is_thread_local'(P,M).
'$predicate_property'(P,M,M,exported) :-
functor(P,N,A),
once(recorded('$module','$module'(_TFN,M,Publics,_L),_)),
once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)),
lists:memberchk(N/A,Publics).
'$predicate_property'(P,Mod,_,number_of_clauses(NCl)) :-
'$number_of_clauses'(P,Mod,NCl).

View File

@@ -390,38 +390,87 @@ save_program(File, _Goal) :-
/** @pred qsave_file(+ _File_, +_State_)
Saves an image of all the information compiled by the systemm from file _F_ to _State_.
Saves an image of all the information compiled by the system from file _F_ to _State_.
This includes modules and predicatees eventually including multi-predicates.
**/
qsave_file(F0, State) :-
absolute_file_name( F0, File, [expand(true),file_type(qly)]),
'$qsave_file_'(File, State).
qsave_file(File, State) :-
recorded('$module', '$module'(File,Mod,Exps,Line), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
'$fetch_multi_files_module'(Mod, MFs),
'$fetch_meta_predicates_module'(Mod, Metas),
'$fetch_module_transparents_module'(Mod, ModTransps),
asserta(Mod:'@mod_info'(F, Exps, Line, Parents, Imps, Metas, ModTransps)),
atom_concat(Mod,'.qly',OF),
'$qsave_file_'(File, _State) :-
'$recorded'('$directive','$d'( File, M:G, Mode, VL, Pos ), _),
assert(prolog:'$file_property'( directive( M:G, Mode, VL, Pos ) ) ),
'$set_owner_file'(prolog:'$file_property'( _ ), File ),
fail.
'$qsave_file_'(File, _State) :-
recorded('$module', '$module'(F,Mod,Source,Exps,L), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
assert(prolog:'$file_property'( module( Mod, Exps, L, Parents, Imps ) ) ),
'$set_owner_file'(prolog:'$file_property'( _ ), File ),
fail.
'$qsave_file_'(File, _State) :-
'$fetch_multi_files_file'(File, MultiFiles),
assert(prolog:'$file_property'( multifile(MultiFiles ) ) ),
'$set_owner_file'(prolog:'$file_property'( _ ), File ),
fail.
'$qsave_file_'( File, State ) :-
(
is_stream( State )
->
stream_property(Stream, file_name(File)),
S = Stream,
'$qsave_file_preds'(S, File)
;
absolute_file_name( F0, File, [expand(true),file_type(qly)]),
open(State, write, S, [type(binary)]),
'$qsave_module_preds'(S, Mod),
close(S),
abolish(Mod:'@mod_info'/7),
fail.
qsave_file(_).
'$qsave_file_preds'(S, File),
close(S)
), abolish(prolog:'$file_property'/2).
'$fetch_multi_files_file'(File, Multi_Files) :-
setof(Info, '$fetch_multi_file_module'(File, Info), Multi_Files).
'$fetch_multi_file_file'(FileName, (M:G :- Body)) :-
recorded('$multifile_defs','$defined'(FileName,Name,Arity,Mod), _),
functor(G, Name, Arity ),
clause(M:G, Body, ClauseRef),
clause_property(ClauseRef, file(FileName) ).
/** @pred qsave_module(+ _Module_, +_State_)
Saves an image of all the information compiled by the systemm on module _F_ to _State_.
**/
qsave_module(Mod, OF) :-
recorded('$module', '$module'(F,Mod,Exps,L), _),
qsave_module(Mod, OF) :-
recorded('$module', '$module'(F,Mod,_S,Exps,L), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
'$fetch_multi_files_module'(Mod, MFs),
'$fetch_meta_predicates_module'(Mod, Metas),
'$fetch_module_transparents_module'(Mod, ModTransps),
asserta(Mod:'@mod_info'(F, Exps, L, Parents, Imps, Metas,
ModTransps)), open(OF, write, S, [type(binary)]),
'$qsave_module_preds'(S, Mod), close(S),
abolish(Mod:'@mod_info'/7), fail.
qsave_module(_, _).
/** @pred qsave_module(+ _Module_)
Saves an image of all the information compiled by the systemm on
module _F_ to a file _State.qly_ in the current directory.
**/
qsave_module(Mod) :-
recorded('$module', '$module'(F,Mod,_S,Exps,L), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
'$fetch_multi_files_module'(Mod, MFs),
'$fetch_meta_predicates_module'(Mod, Metas),
'$fetch_module_transparents_module'(Mod, ModTransps),
asserta(Mod:'@mod_info'(F, Exps, L, Parents, Imps, Metas, ModTransps)),
'$fetch_foreigns_module'(Mod, Foreigns),
asserta(Mod:'@mod_info'(F, Exps, L, Parents, Imps, Metas, ModTransps, Foreigns)),
atom_concat(Mod,'.qly',OF),
open(OF, write, S, [type(binary)]),
'$qsave_module_preds'(S, Mod),
@@ -441,98 +490,192 @@ restore(File) :-
close(S).
/**
@pred qload_module(+ _F_)
Restores a previously saved state of YAP with from file _F_.
@pred qload_module(+ _M_)
Restores a previously save image of module _M_. This built-in searches
for a file M.qly or M according to the rules for qly files.
The q_load_module/1 built-in tries to reload any modules it imports
from and any foreign files that had been loaded with the original
module. It tries first reloading from qly images, but if they are not
available it tries reconsulting the source file.
*/
qload_module(Mod) :-
atom_concat(Mod,'.qly',IF),
open(IF, read, S, [type(binary)]),
absolute_file_name( Mod, File, [expand(true),file_type(qly)]),
'$qload_module'(Mod, File).
'$qload_module'(Mod, File) :-
open(File, read, S, [type(binary)]),
'$qload_module_preds'(S),
close(S),
fail.
qload_module(Mod) :-
'$qload_module'(Mod, _File) :-
'$complete_read'(Mod).
'$complete_read'(Mod) :-
retract(Mod:'@mod_info'(F, Exps, Line,Parents, Imps, Metas, ModTransps)),
'$current_module'(CurrentModule),
retract(Mod:'@mod_info'(F, Exps, Line,Parents, Imps, Metas, ModTransps, Foreigns)),
abolish(Mod:'$mod_info'/7),
recorda('$module', '$module'(F,Mod,Exps,Line), _),
'$install_parents_module'(Mod, Parents),
'$install_imports_module'(Mod, Imps),
'$install_imports_module'(Mod, Imps, []),
'$install_multi_files_module'(Mod, MFs),
'$install_meta_predicates_module'(Mod, Metas),
'$install_module_transparents_module'(Mod, ModTransps).
'$install_foreigns_module'(Mod, Foreigns),
'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts).
'$fetch_imports_module'(Mod, Imports) :-
findall(Info, '$fetch_import_module'(Mod, Info), Imports).
% detect an importerator that is local to the module.
'$fetch_import_module'(Mod, '$import'(Mod0,Mod,G0,G,N,K)) :-
recorded('$import', '$import'(Mod0,Mod,G0,G,N,K), _).
% detect an import that is local to the module.
'$fetch_import_module'(Mod, '$import'(Mod0,Mod,G0,G,N,K) - S) :-
recorded('$import', '$import'(Mod0,Mod,G0,G,N,K), _),
( recorded('$module','$module'(_, Mod0, S, _, _), R) -> true ; S = user_input ).
'$fetch_parents_module'(Mod, Parents) :-
findall(Parent, prolog:'$parent_module'(Mod,Parent), Parents).
'$fetch_module_transparents_module'(Mod, Module_Transparents) :-
findall(Info, '$fetch_module_transparent_module'(Mod, Info), Module_Transparents).
setof(Info, '$fetch_module_transparent_module'(Mod, Info), Module_Transparents).
% detect an module_transparenterator that is local to the module.
'$fetch_module_transparent_module'(Mod, '$module_transparent'(F,Mod,N,P)) :-
prolog:'$module_transparent'(F,Mod0,N,P), Mod0 == Mod.
'$fetch_meta_predicates_module'(Mod, Meta_Predicates) :-
findall(Info, '$fetch_meta_predicate_module'(Mod, Info), Meta_Predicates).
setof(Info, '$fetch_meta_predicate_module'(Mod, Info), Meta_Predicates).
% detect an meta_predicateerator that is local to the module.
% detect a meta_predicate that is local to the module.
'$fetch_meta_predicate_module'(Mod, '$meta_predicate'(F,Mod,N,P)) :-
prolog:'$meta_predicate'(F,Mod0,N,P), Mod0 == Mod.
'$fetch_multi_files_module'(Mod, Multi_Files) :-
findall(Info, '$fetch_multi_file_module'(Mod, Info), Multi_Files).
setof(Info, '$fetch_multi_file_module'(Mod, Info), Multi_Files).
% detect an multi_fileerator that is local to the module.
% detect an multi_file that is local to the module.
'$fetch_multi_file_module'(Mod, '$defined'(FileName,Name,Arity,Mod)) :-
recorded('$multifile_defs','$defined'(FileName,Name,Arity,Mod), _).
'$fetch_term_expansions_module'(Mod, Term_Expansions) :-
findall(Info, '$fetch_term_expansion_module'(Mod, Info), Term_Expansions).
setof(Info, '$fetch_term_expansion_module'(Mod, Info), Term_Expansions).
% detect an term_expansionerator that is local to the module.
'$fetch_term_expansion_module'(Mod,'$defined'(FileName,Name,Arity,Mod)) :-
recorded('$multifile_defs','$defined'(FileName,Name,Arity,Mod), _).
'$fetch_foreigns_module'(Mod, Foreigns) :-
setof(Info, '$fetch_foreign_module'(Mod, Info), Foreigns).
% detect an term_expansionerator that is local to the module.
'$fetch_foreign_module'(Mod,Foreign) :-
recorded( '$foreign', Mod:Foreign, _).
'$install_ops_module'(_, []).
'$install_ops_module'(Mod, op(X,Y,Op).Ops) :-
'$install_ops_module'(Mod, [op(X,Y,Op)|Ops]) :-
op(X, Y, Mod:Op),
'$install_ops_module'(Mod, Ops).
'$install_imports_module'(_, []).
'$install_imports_module'(Mod, Import.Imports) :-
'$install_imports_module'(_, [], Fs0) :-
sort(Fs0, Fs),
'$restore_load_files'(Fs).
'$install_imports_module'(Mod, [Import-F|Imports], Fs0) :-
recordz('$import', Import, _),
'$install_imports_module'(Mod, Imports).
arg(1, Import, M),
'$install_imports_module'(Mod, Imports, [M-F|Fs0]).
'$restore_load_files'([]).
'$restore_load_files'([M-F0|Fs]) :-
(
absolute_file_name( M, File, [expand(true),file_type(qly),access(read),file_errors(fail)])
->
qload_module(M)
;
use_module(M, F0, _)
),
'$restore_load_files'(Fs).
'$install_parents_module'(_, []).
'$install_parents_module'(Mod, Parent.Parents) :-
'$install_parents_module'(Mod, [Parent|Parents]) :-
assert(prolog:Parent),
'$install_parents_module'(Mod, Parents).
'$install_module_transparents_module'(_, []).
'$install_module_transparents_module'(Mod, Module_Transparent.Module_Transparents) :-
'$install_module_transparents_module'(Mod, [Module_Transparent|Module_Transparents]) :-
assert(prolog:Module_Transparent),
'$install_module_transparents_module'(Mod, Module_Transparents).
'$install_meta_predicates_module'(_, []).
'$install_meta_predicates_module'(Mod, Meta_Predicate.Meta_Predicates) :-
'$install_meta_predicates_module'(Mod, [Meta_Predicate|Meta_Predicates]) :-
assert(prolog:Meta_Predicate),
'$install_meta_predicates_module'(Mod, Meta_Predicates).
'$install_multi_files_module'(_, []).
'$install_multi_files_module'(Mod, Multi_File.Multi_Files) :-
recordz('$multifile_defs',Multi_File, _).
'$install_multi_files_module'(Mod, [Multi_File|Multi_Files]) :-
recordz('$multifile_defs',Multi_File, _),
'$install_multi_files_module'(Mod, Multi_Files).
'$install_foreigns_module'(_, []).
'$install_foreigns_module'(Mod, [Foreign|Foreigns]) :-
'$do_foreign'(Foreign, Foreigns),
'$install_foreigns_module'(Mod, Foreigns).
'$do_foreign'('$foreign'(Objs,Libs,Entry), _) :-
load_foreign_files(Objs,Libs,Entry).
'$do_foreign'('$swi_foreign'(File, Opts, Handle), More) :-
open_shared_object(File, Opts, Handle, NewHandle),
'$init_foreigns'(More, NewHandle).
'$do_foreign'('$swi_foreign'(_,_), More).
'$init_foreigns'([], Handle, NewHandle).
'$init_foreigns'(['$swi_foreign'( Handle, Function )|More], Handle, NewHandle) :-
!,
call_shared_object_function( NewHandle, Function),
'$init_foreigns'(More, Handle, NewHandle).
'$init_foreigns'([_|More], Handle, NewHandle) :-
'$init_foreigns'(More, Handle, NewHandle).
/**
@pred qload_file(+ _F_)
Restores a previously saved state of YAP contaianing a qly file _F_.
*/
qload_file(F0) :-
H0 is heapused, '$cputime'(T0,_),
( is_strean( F0 )
->
stream_property(F0, file_name(File) ),
S = F0
;
absolute_file_name( F0, File, [expand(true),file_type(qly)]),
open(File, read, S, [type(binary)])
),
'$qload_file_preds'(S, File),
close(S),
fail
;
'$complete_read_file'(File).
'$complete_read_file'(File) :-
file_directory_name(File, DirName),
working_directory(OldD, Dir),
'$process_directives'( File ),
working_directory( _, OldD),
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
'$current_module'(Mod, SourceModule),
fail.
'$process_directives' :-
prolog:'$file_property'( multifile( List ) ),
lists:member( Clause, List ),
assert( Clause ),
fail.
'$process_directives' :-
prolog:'$file_property'( directive( M:G, Mode, VL, Pos ) ),
'$exec_directive'(G, Mode, M, VL, Pos),
fail.
'$process_directives' :-
abolish(prolog:'$file_property'/1).