2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: consult.yap *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Consulting Files in YAP *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
%
|
|
|
|
% SWI options
|
|
|
|
% autoload(true,false)
|
|
|
|
% derived_from(File) -> make
|
2007-11-06 17:02:13 +00:00
|
|
|
% encoding(Encoding) => implemented
|
2005-10-18 18:04:43 +01:00
|
|
|
% expand({true,false)
|
2007-11-06 17:02:13 +00:00
|
|
|
% if(changed,true,not_loaded) => implemented
|
|
|
|
% imports(all,List) => implemented
|
2005-10-18 18:04:43 +01:00
|
|
|
% qcompile(true,false)
|
|
|
|
% silent(true,false) => implemented
|
|
|
|
% stream(Stream) => implemented
|
2013-01-15 11:18:09 +00:00
|
|
|
% consult(consult,reconsult,exo,db) => implemented
|
2008-07-11 18:02:10 +01:00
|
|
|
% compilation_mode(compact,source,assert_all) => implemented
|
2005-10-18 18:04:43 +01:00
|
|
|
%
|
|
|
|
load_files(Files,Opts) :-
|
|
|
|
'$load_files'(Files,Opts,load_files(Files,Opts)).
|
|
|
|
|
2010-03-02 23:13:39 +00:00
|
|
|
'$load_files'(Files,Opts,Call) :-
|
|
|
|
'$check_files'(Files,load_files(Files,Opts)),
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opts'(Opts,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,Files,Call),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$check_use_module'(Call,UseModule),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M0),
|
2013-09-09 22:11:12 +01:00
|
|
|
% make sure we can run consult
|
|
|
|
'$init_system',
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'(Files,M0,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$close_lf'(Silent).
|
|
|
|
|
2010-03-02 23:13:39 +00:00
|
|
|
'$check_files'(Files,Call) :-
|
|
|
|
var(Files), !,
|
|
|
|
'$do_error'(instantiation_error,Call).
|
2010-03-09 22:00:46 +00:00
|
|
|
'$check_files'(M:Files,Call) :- !,
|
2010-03-02 23:13:39 +00:00
|
|
|
(var(M)
|
|
|
|
->
|
|
|
|
'$do_error'(instantiation_error,Call)
|
|
|
|
;
|
|
|
|
atom(M)
|
|
|
|
->
|
|
|
|
'$check_files'(Files,Call)
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(atom,M),Call)
|
|
|
|
).
|
|
|
|
'$check_files'(Files,Call) :-
|
|
|
|
(ground(Files)
|
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
'$do_error'(instantiation_error,Call)
|
|
|
|
).
|
|
|
|
|
|
|
|
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opts'(V,_,_,_,_,_,_,_,_,_,_,_,_,Call) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
var(V), !,
|
|
|
|
'$do_error'(instantiation_error,Call).
|
2011-02-15 07:39:27 +00:00
|
|
|
'$process_lf_opts'([],_,InfLevel,_,_,_,_,_,_,_,_,_,_,_).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opts'([Opt|Opts],Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,Files,Call) :-
|
|
|
|
'$process_lf_opt'(Opt,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,Files,Call), !,
|
|
|
|
'$process_lf_opts'(Opts,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,Files,Call).
|
|
|
|
'$process_lf_opts'([Opt|_],_,_,_,_,_,_,_,_,_,_,_,_,Call) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(domain_error(unimplemented_option,Opt),Call).
|
|
|
|
|
2010-06-14 08:47:15 +01:00
|
|
|
'$process_lf_opt'(autoload(true),Silent,InfLevel,_,_,_,_,_,_,_,_,_,_,_) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
get_value('$verbose_auto_load',VAL),
|
|
|
|
(VAL = true ->
|
2010-06-14 08:47:15 +01:00
|
|
|
InfLevel = informational,
|
|
|
|
(get_value('$lf_verbose',informational) -> true ; Silent = silent),
|
|
|
|
set_value('$lf_verbose',informational)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2010-06-14 08:47:15 +01:00
|
|
|
InfLevel = silent,
|
|
|
|
(get_value('$lf_verbose',silent) -> true ; Silent = informational),
|
|
|
|
set_value('$lf_verbose',silent)
|
2005-10-18 18:04:43 +01:00
|
|
|
).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(autoload(false),_,_,_,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(derived_from(File),_,_,_,_,_,_,_,_,_,_,_,Files,Call) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
( atom(File) -> true ; '$do_error'(type_error(atom,File),Call) ),
|
|
|
|
( atom(Files) -> true ; '$do_error'(type_error(atom,Files),Call) ),
|
|
|
|
/* call make */
|
|
|
|
'$do_error'(domain_error(unimplemented_option,derived_from),Call).
|
2011-09-02 21:03:41 +01:00
|
|
|
'$process_lf_opt'(encoding(Encoding),_,_,_,_,_,_,_,_,Encoding,_,_,_,Call) :-
|
|
|
|
atom(Encoding).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(expand(true),_,_,true,_,_,_,_,_,_,_,_,_,Call) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(domain_error(unimplemented_option,expand),Call).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(expand(false),_,_,false,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(if(changed),_,_,_,changed,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(if(true),_,_,_,true,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(if(not_loaded),_,_,_,not_loaded,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(imports(all),_,_,_,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(imports(Imports),_,_,_,_,_,Imports,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(qcompile(true),_,_,_,_,true,_,_,_,_,_,_,_,Call) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(domain_error(unimplemented_option,qcompile),Call).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(qcompile(false),_,_,_,_,false,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(silent(true),Silent,silent,_,_,_,_,_,_,_,_,_,_,_) :-
|
2010-06-14 08:47:15 +01:00
|
|
|
( get_value('$lf_verbose',silent) -> true ; Silent = informational),
|
|
|
|
set_value('$lf_verbose',silent).
|
|
|
|
'$process_lf_opt'(silent(false),Silent,informational,_,_,_,_,_,_,_,_,_,_,_) :-
|
|
|
|
( get_value('$lf_verbose',informational) -> true ; Silent = silent),
|
|
|
|
set_value('$lf_verbose',informational).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(skip_unix_comments,_,_,_,_,_,_,_,_,skip_unix_comments,_,_,_,_).
|
|
|
|
'$process_lf_opt'(compilation_mode(source),_,_,_,_,_,_,_,_,_,source,_,_,_).
|
2008-07-11 18:02:10 +01:00
|
|
|
'$process_lf_opt'(compilation_mode(compact),_,_,_,_,_,_,_,_,_,compact,_,_,_).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(compilation_mode(assert_all),_,_,_,_,_,_,_,_,_,assert_all,_,_,_).
|
|
|
|
'$process_lf_opt'(consult(reconsult),_,_,_,_,_,_,_,_,_,_,reconsult,_,_).
|
2013-01-15 11:18:09 +00:00
|
|
|
'$process_lf_opt'(consult(exo),_,_,_,_,_,_,_,_,_,_,exo,_,_).
|
|
|
|
'$process_lf_opt'(consult(db),_,_,_,_,_,_,_,_,_,_,db,_,_).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$process_lf_opt'(consult(consult),_,_,_,_,_,_,_,_,_,_,consult,_,_).
|
|
|
|
'$process_lf_opt'(stream(Stream),_,_,_,_,_,_,Stream,_,_,_,_,Files,Call) :-
|
2011-02-14 22:19:30 +00:00
|
|
|
/* ( is_stream(Stream) -> true ; '$do_error'(domain_error(stream,Stream),Call) ), */
|
2005-10-18 18:04:43 +01:00
|
|
|
( atom(Files) -> true ; '$do_error'(type_error(atom,Files),Call) ).
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$check_use_module'(use_module(_),use_module(_)) :- !.
|
|
|
|
'$check_use_module'(use_module(_,_),use_module(_)) :- !.
|
|
|
|
'$check_use_module'(use_module(M,_,_),use_module(M)) :- !.
|
|
|
|
'$check_use_module'(_,load_files) :- !.
|
|
|
|
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'(V,_,Call,_,_,_,_,_,_,_,_,_,_) :- var(V), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(instantiation_error,Call).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'([],_,_,_,_,_,_,_,_,_,_,_,_,_) :- !.
|
|
|
|
'$lf'(M:X, _, Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule) :- !,
|
2005-10-18 18:04:43 +01:00
|
|
|
(
|
|
|
|
atom(M)
|
|
|
|
->
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'(X, M, Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule)
|
2005-10-18 18:04:43 +01:00
|
|
|
;
|
|
|
|
'$do_error'(type_error(atom,M),Call)
|
|
|
|
).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'([F|Fs], Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule) :- !,
|
|
|
|
'$lf'(F,Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,_),
|
|
|
|
'$lf'(Fs, Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule).
|
|
|
|
'$lf'(_, Mod, _,InfLevel,_,_,CompilationMode,Imports,Stream,_,Reconsult,SkipUnixComments,CompMode,UseModule) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
nonvar(Stream), !,
|
2007-11-08 11:22:05 +00:00
|
|
|
'$do_lf'(Mod, Stream, InfLevel,CompilationMode,Imports,SkipUnixComments,CompMode,Reconsult,UseModule).
|
|
|
|
'$lf'(user, Mod, _,InfLevel,_,_,CompilationMode,Imports,_,_,SkipUnixComments,CompMode,Reconsult,UseModule) :- !,
|
|
|
|
'$do_lf'(Mod, user_input, InfLevel, CompilationMode,Imports,SkipUnixComments,CompMode,Reconsult,UseModule).
|
|
|
|
'$lf'(user_input, Mod, _,InfLevel,_,_,CompilationMode,Imports,_,_,SkipUnixComments,CompMode,Reconsult,UseModule) :- !,
|
|
|
|
'$do_lf'(Mod, user_input, InfLevel, CompilationMode,Imports,SkipUnixComments,CompMode,Reconsult,UseModule).
|
2011-09-02 21:03:41 +01:00
|
|
|
'$lf'(X, Mod, Call, InfLevel,_,Changed,CompilationMode,Imports,_,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule) :-
|
2011-06-21 22:36:09 +01:00
|
|
|
'$full_filename'(X, Y, Call),
|
2011-02-15 07:39:27 +00:00
|
|
|
(
|
|
|
|
var(Encoding)
|
|
|
|
->
|
|
|
|
Opts = []
|
|
|
|
;
|
|
|
|
Opts = [encoding(Encoding)]
|
|
|
|
),
|
|
|
|
open(Y, read, Stream, Opts), !,
|
2005-10-28 18:38:50 +01:00
|
|
|
'$set_changed_lfmode'(Changed),
|
2007-11-08 11:22:05 +00:00
|
|
|
'$start_lf'(X, Mod, Stream, InfLevel, CompilationMode, Imports, Changed,SkipUnixComments,CompMode,Reconsult,UseModule),
|
2011-02-14 22:55:59 +00:00
|
|
|
close(Stream).
|
2007-11-08 11:22:05 +00:00
|
|
|
'$lf'(X, _, Call, _, _, _, _, _, _, _, _, _, _, _) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(permission_error(input,stream,X),Call).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$set_changed_lfmode'(true) :- !.
|
|
|
|
'$set_changed_lfmode'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2007-11-08 11:22:05 +00:00
|
|
|
'$start_lf'(_, Mod, Stream,_ ,_, Imports, not_loaded, _, _, _, _) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_loaded'(Stream, Mod, Imports), !.
|
2007-11-08 11:22:05 +00:00
|
|
|
'$start_lf'(_, Mod, Stream, _, _, Imports, changed, _, _, _, _) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_unchanged'(Stream, Mod, Imports), !.
|
2007-11-08 11:22:05 +00:00
|
|
|
'$start_lf'(_, Mod, Stream, InfLevel, CompilationMode, Imports, _, SkipUnixComments, CompMode, Reconsult, UseModule) :-
|
|
|
|
'$do_lf'(Mod, Stream, InfLevel, CompilationMode, Imports, SkipUnixComments, CompMode, Reconsult, UseModule).
|
2005-10-18 18:04:43 +01:00
|
|
|
|
|
|
|
'$close_lf'(Silent) :-
|
2005-10-19 02:47:43 +01:00
|
|
|
nonvar(Silent), !,
|
2010-06-14 08:47:15 +01:00
|
|
|
set_value('$lf_verbose',Silent).
|
2005-10-19 02:47:43 +01:00
|
|
|
'$close_lf'(_).
|
2005-10-28 18:38:50 +01:00
|
|
|
|
2005-10-20 00:16:49 +01:00
|
|
|
ensure_loaded(Fs) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$load_files'(Fs, [if(changed)],ensure_loaded(Fs)).
|
|
|
|
|
|
|
|
compile(Fs) :-
|
|
|
|
'$load_files'(Fs, [], compile(Fs)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2010-07-31 00:32:54 +01:00
|
|
|
% consult(Fs) :-
|
|
|
|
% '$has_yap_or',
|
|
|
|
% '$do_error'(context_error(consult(Fs),clause),query).
|
2004-02-12 18:23:29 +00:00
|
|
|
consult(V) :-
|
|
|
|
var(V), !,
|
|
|
|
'$do_error'(instantiation_error,consult(V)).
|
|
|
|
consult(M0:Fs) :- !,
|
|
|
|
'$consult'(Fs, M0).
|
2001-04-09 20:54:03 +01:00
|
|
|
consult(Fs) :-
|
2004-02-12 18:23:29 +00:00
|
|
|
'$current_module'(M0),
|
|
|
|
'$consult'(Fs, M0).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
'$consult'(Fs,Module) :-
|
|
|
|
'$access_yap_flags'(8, 2), % SICStus Prolog compatibility
|
|
|
|
!,
|
2010-03-03 19:08:59 +00:00
|
|
|
'$load_files'(Module:Fs,[],consult(Fs)).
|
2007-01-24 14:20:04 +00:00
|
|
|
'$consult'(Fs, Module) :-
|
2010-03-03 19:08:59 +00:00
|
|
|
'$load_files'(Module:Fs,[consult(consult)],consult(Fs)).
|
2005-10-18 18:04:43 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
reconsult(Fs) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$load_files'(Fs, [], reconsult(Fs)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2013-01-15 11:18:09 +00:00
|
|
|
exo_files(Fs) :-
|
|
|
|
'$load_files'(Fs, [consult(exo), if(not_loaded)], exo_files(Fs)).
|
|
|
|
|
|
|
|
db_files(Fs) :-
|
|
|
|
'$load_files'(Fs, [consult(db), if(not_loaded)], exo_files(Fs)).
|
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
use_module(F) :-
|
2005-10-28 18:38:50 +01:00
|
|
|
'$load_files'(F, [if(not_loaded)], use_module(F)).
|
2005-10-18 18:04:43 +01:00
|
|
|
|
|
|
|
use_module(F,Is) :-
|
2005-10-28 18:38:50 +01:00
|
|
|
'$load_files'(F, [if(not_loaded),imports(Is)], use_module(F,Is)).
|
2005-10-18 18:04:43 +01:00
|
|
|
|
|
|
|
use_module(M,F,Is) :-
|
2006-11-18 01:40:42 +00:00
|
|
|
'$use_module'(M,F,Is).
|
|
|
|
|
2007-01-24 14:20:04 +00:00
|
|
|
'$use_module'(U,_F,Is) :- nonvar(U), U = user, !,
|
2006-12-13 16:10:26 +00:00
|
|
|
'$import_to_current_module'(user_input, user, Is).
|
2006-11-18 01:40:42 +00:00
|
|
|
'$use_module'(M,F,Is) :- nonvar(M), !,
|
|
|
|
recorded('$module','$module'(F1,M,_),_),
|
|
|
|
'$load_files'(F1, [if(not_loaded),imports(Is)], use_module(M,F,Is)),
|
|
|
|
F1 = F.
|
|
|
|
'$use_module'(M,F,Is) :- nonvar(F),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$load_files'(F, [if(not_loaded),imports(Is)], use_module(M,F,Is)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-19 02:47:43 +01:00
|
|
|
'$csult'(V, _) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,consult(V)).
|
|
|
|
'$csult'([], _).
|
|
|
|
'$csult'([-F|L], M) :- !, '$load_files'(M:F, [],[-M:F]), '$csult'(L, M).
|
|
|
|
'$csult'([F|L], M) :- '$consult'(F, M), '$csult'(L, M).
|
|
|
|
|
2007-11-08 11:22:05 +00:00
|
|
|
'$do_lf'(ContextModule, Stream, InfLevel, _, Imports, SkipUnixComments, CompMode, Reconsult, UseModule) :-
|
2012-02-27 16:37:31 +00:00
|
|
|
'$reset_if'(OldIfLevel),
|
2012-04-15 00:01:26 +01:00
|
|
|
'$into_system_mode'(OldMode),
|
2009-10-16 08:31:23 +01:00
|
|
|
'$record_loaded'(Stream, ContextModule, Reconsult),
|
2004-02-10 01:07:46 +00:00
|
|
|
'$current_module'(OldModule,ContextModule),
|
2011-05-12 22:26:10 +01:00
|
|
|
working_directory(OldD,OldD),
|
2012-04-15 00:01:26 +01:00
|
|
|
'$ensure_consulting_file'(OldF, Stream),
|
2002-01-22 17:11:36 +00:00
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2010-02-26 13:41:40 +00:00
|
|
|
'$file_name'(Stream,File),
|
2011-07-11 15:40:58 +01:00
|
|
|
'$set_current_loop_stream'(OldStream, Stream),
|
2012-04-15 00:01:26 +01:00
|
|
|
'$ensure_consulting'(Old, false),
|
2007-02-26 10:41:40 +00:00
|
|
|
'$access_yap_flags'(18,GenerateDebug),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$consult_infolevel'(InfLevel),
|
2007-11-08 11:22:05 +00:00
|
|
|
'$comp_mode'(OldCompMode, CompMode),
|
2010-12-13 19:13:33 +00:00
|
|
|
( get_value('$syntaxcheckflag',on) -> '$init_style_check'(File) ; true ),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$initialisation','$',_),
|
2005-10-18 18:04:43 +01:00
|
|
|
( Reconsult = reconsult ->
|
2006-02-17 15:56:36 +00:00
|
|
|
'$start_reconsulting'(File),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$start_consult'(Reconsult,File,LC),
|
|
|
|
'$remove_multifile_clauses'(File),
|
|
|
|
StartMsg = reconsulting,
|
|
|
|
EndMsg = reconsulted
|
|
|
|
;
|
|
|
|
'$start_consult'(Reconsult,File,LC),
|
|
|
|
StartMsg = consulting,
|
|
|
|
EndMsg = consulted
|
|
|
|
),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(InfLevel, loading(StartMsg, File)),
|
2006-03-03 23:11:30 +00:00
|
|
|
( SkipUnixComments == skip_unix_comments ->
|
|
|
|
'$skip_unix_comments'(Stream)
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$loop'(Stream,Reconsult),
|
2008-02-22 15:08:37 +00:00
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
|
|
|
'$current_module'(Mod,OldModule),
|
|
|
|
print_message(InfLevel, loaded(EndMsg, File, Mod, T, H)),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$end_consult',
|
2005-10-19 02:47:43 +01:00
|
|
|
(
|
|
|
|
Reconsult = reconsult ->
|
|
|
|
'$clear_reconsulting'
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2011-07-11 15:40:58 +01:00
|
|
|
'$set_current_loop_stream'(_, OldStream),
|
2007-02-26 10:41:40 +00:00
|
|
|
'$set_yap_flags'(18,GenerateDebug),
|
2008-07-11 18:02:10 +01:00
|
|
|
'$comp_mode'(CompMode, OldCompMode),
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$consulting',Old),
|
|
|
|
nb_setval('$consulting_file',OldF),
|
2011-05-12 22:26:10 +01:00
|
|
|
working_directory(_,OldD),
|
2007-10-21 09:48:06 +01:00
|
|
|
% surely, we were in run mode or we would not have included the file!
|
|
|
|
nb_setval('$if_skip_mode',run),
|
|
|
|
% back to include mode!
|
2012-02-27 16:37:31 +00:00
|
|
|
nb_setval('$if_level',OldIfLevel),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$bind_module'(Mod, UseModule),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$import_to_current_module'(File, ContextModule, Imports),
|
2002-11-19 14:43:17 +00:00
|
|
|
( LC == 0 -> prompt(_,' |: ') ; true),
|
2006-12-13 16:10:26 +00:00
|
|
|
( OldMode == off -> '$exit_system_mode' ; true ),
|
2004-02-05 16:57:02 +00:00
|
|
|
'$exec_initialisation_goals',
|
2001-04-09 20:54:03 +01:00
|
|
|
!.
|
|
|
|
|
2012-02-27 16:37:31 +00:00
|
|
|
'$reset_if'(OldIfLevel) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$if_level', OldIfLevel, fail), !,
|
2012-02-27 16:37:31 +00:00
|
|
|
nb_setval('$if_level',0).
|
|
|
|
'$reset_if'(0) :-
|
|
|
|
nb_setval('$if_level',0).
|
|
|
|
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(Level0) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$if_level', Level, fail), !,
|
2012-03-04 10:22:40 +00:00
|
|
|
Level0 = Level.
|
|
|
|
'$get_if'(0).
|
|
|
|
|
2012-04-15 00:01:26 +01:00
|
|
|
'$into_system_mode'(OldMode) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$nb_getval'('$system_mode', OldMode, fail) -> true ; OldMode = off),
|
2012-04-15 00:01:26 +01:00
|
|
|
( OldMode == off -> '$enter_system_mode' ; true ).
|
|
|
|
|
|
|
|
'$ensure_consulting_file'(OldF, Stream) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$nb_getval'('$consulting_file',OldF, fail) -> true ; OldF = []),
|
2012-04-15 00:01:26 +01:00
|
|
|
'$set_consulting_file'(Stream).
|
|
|
|
|
|
|
|
'$ensure_consulting'(Old, New) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$nb_getval'('$consulting',Old, fail) -> true ; Old = false ),
|
2012-04-15 00:01:26 +01:00
|
|
|
nb_setval('$consulting', New).
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$bind_module'(_, load_files).
|
|
|
|
'$bind_module'(Mod, use_module(Mod)).
|
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
'$import_to_current_module'(File, M, Imports) :-
|
|
|
|
recorded('$module','$module'(File,NM,Ps),_), M \= NM, !,
|
|
|
|
'$use_preds'(Imports, Ps, NM, M).
|
|
|
|
'$import_to_current_module'(_, _, _).
|
|
|
|
|
|
|
|
'$consult_infolevel'(InfoLevel) :- nonvar(InfoLevel), !.
|
|
|
|
'$consult_infolevel'(InfoLevel) :-
|
2010-06-14 08:47:15 +01:00
|
|
|
get_value('$lf_verbose',InfoLevel), InfoLevel \= [], !.
|
2005-10-18 18:04:43 +01:00
|
|
|
'$consult_infolevel'(informational).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$start_reconsulting'(F) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$reconsulted','$',_),
|
|
|
|
recorda('$reconsulting',F,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$initialization'(V) :-
|
|
|
|
var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,initialization(V)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$initialization'(C) :- number(C), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,C),initialization(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$initialization'(C) :- db_reference(C), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,C),initialization(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$initialization'(G) :-
|
2006-02-24 14:26:37 +00:00
|
|
|
'$show_consult_level'(Level1),
|
|
|
|
% it will be done after we leave the current consult level.
|
|
|
|
Level is Level1-1,
|
2010-05-28 16:07:20 +01:00
|
|
|
recordz('$initialisation',do(Level,G),_),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
'$initialization'(_).
|
|
|
|
|
2010-06-17 00:24:19 +01:00
|
|
|
initialization(G,OPT) :-
|
|
|
|
'$initialization'(G,OPT).
|
|
|
|
|
2010-01-15 16:21:29 +00:00
|
|
|
'$initialization'(G,OPT) :-
|
|
|
|
(
|
|
|
|
var(G)
|
|
|
|
->
|
|
|
|
'$do_error'(instantiation_error,initialization(G,OPT))
|
|
|
|
;
|
|
|
|
number(G)
|
|
|
|
->
|
|
|
|
'$do_error'(type_error(callable,G),initialization(G,OPT))
|
|
|
|
;
|
|
|
|
db_reference(G)
|
|
|
|
->
|
|
|
|
'$do_error'(type_error(callable,G),initialization(G,OPT))
|
|
|
|
;
|
|
|
|
var(OPT)
|
|
|
|
->
|
|
|
|
'$do_error'(instantiation_error,initialization(G,OPT))
|
|
|
|
;
|
|
|
|
atom(OPT)
|
|
|
|
->
|
|
|
|
(
|
|
|
|
OPT == now
|
|
|
|
->
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
OPT == after_load
|
|
|
|
->
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
OPT == restore
|
|
|
|
->
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
'$do_error'(domain_error(initialization,OPT),initialization(OPT))
|
|
|
|
)
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(OPT),initialization(G,OPT))
|
|
|
|
).
|
|
|
|
'$initialization'(G,now) :-
|
2013-02-15 02:40:11 +00:00
|
|
|
( call(G) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ).
|
2010-01-15 16:21:29 +00:00
|
|
|
'$initialization'(G,after_load) :-
|
|
|
|
'$initialization'(G).
|
|
|
|
% ignore for now.
|
|
|
|
'$initialization'(G,restore).
|
|
|
|
|
2009-04-21 21:19:26 +01:00
|
|
|
'$exec_initialisation_goals' :-
|
|
|
|
nb_setval('$initialization_goals',on),
|
|
|
|
fail.
|
2006-03-03 23:11:30 +00:00
|
|
|
'$exec_initialisation_goals' :-
|
|
|
|
recorded('$blocking_code',_,R),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
% system goals must be performed first
|
|
|
|
'$exec_initialisation_goals' :-
|
|
|
|
recorded('$system_initialisation',G,R),
|
|
|
|
erase(R),
|
|
|
|
G \= '$',
|
2013-02-15 02:40:11 +00:00
|
|
|
once( call(G) ),
|
2006-03-03 23:11:30 +00:00
|
|
|
fail.
|
|
|
|
'$exec_initialisation_goals' :-
|
2010-04-12 18:30:39 +01:00
|
|
|
'$show_consult_level'(Level),
|
2006-03-03 23:11:30 +00:00
|
|
|
'$current_module'(M),
|
2012-12-07 08:08:32 +00:00
|
|
|
recorded('$initialisation',do(Level,_),_),
|
|
|
|
findall(G,
|
|
|
|
'$fetch_init_goal'(Level, G),
|
2010-05-28 16:07:20 +01:00
|
|
|
LGs),
|
|
|
|
lists:member(G,LGs),
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$system_mode', OldMode, fail),
|
2006-12-13 16:10:26 +00:00
|
|
|
( OldMode == on -> '$exit_system_mode' ; true ),
|
|
|
|
% run initialization under user control (so allow debugging this stuff).
|
|
|
|
(
|
2013-02-08 16:36:45 +00:00
|
|
|
'$system_catch'(once(M:G), M, Error, user:'$LoopError'(Error, top)),
|
2006-12-13 16:10:26 +00:00
|
|
|
fail
|
|
|
|
;
|
|
|
|
OldMode = on,
|
|
|
|
'$enter_system_mode',
|
|
|
|
fail
|
|
|
|
).
|
2009-04-21 21:19:26 +01:00
|
|
|
'$exec_initialisation_goals' :-
|
|
|
|
nb_setval('$initialization_goals',off).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2012-12-07 08:08:32 +00:00
|
|
|
|
|
|
|
'$fetch_init_goal'(Level, G) :-
|
|
|
|
recorded('$initialisation',do(Level,G),R),
|
|
|
|
erase(R),
|
|
|
|
G\='$'.
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$include'(V, _) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,include(V)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$include'([], _) :- !.
|
|
|
|
'$include'([F|Fs], Status) :- !,
|
|
|
|
'$include'(F, Status),
|
|
|
|
'$include'(Fs, Status).
|
2002-02-08 22:19:24 +00:00
|
|
|
'$include'(X, Status) :-
|
2010-06-14 08:47:15 +01:00
|
|
|
get_value('$lf_verbose',Verbosity),
|
2011-06-21 22:36:09 +01:00
|
|
|
'$full_filename'(X,Y,include(X)),
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$nb_getval'('$included_file', OY, fail ) -> true ; OY = [] ),
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$included_file', Y),
|
2004-09-30 20:51:54 +01:00
|
|
|
'$current_module'(Mod),
|
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2011-02-15 07:39:27 +00:00
|
|
|
( open(Y, read, Stream), !,
|
|
|
|
print_message(Verbosity, loading(including, Y)),
|
|
|
|
'$loop'(Stream,Status), close(Stream)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2011-02-15 07:39:27 +00:00
|
|
|
'$do_error'(permission_error(input,stream,Y),include(X))
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2004-09-30 20:51:54 +01:00
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(Verbosity, loaded(included, Y, Mod, T, H)),
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$included_file',OY).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$do_startup_reconsult'(X) :-
|
|
|
|
( '$access_yap_flags'(15, 0) ->
|
2011-09-07 21:28:13 +01:00
|
|
|
'$system_catch'(load_files(X, [silent(true)]),Module, Error, '$Error'(Error))
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2006-03-03 23:11:30 +00:00
|
|
|
set_value('$verbose',off),
|
2006-12-13 16:10:26 +00:00
|
|
|
'$system_catch'(load_files(X, [silent(true),skip_unix_comments]),Module,_,fail)
|
|
|
|
;
|
|
|
|
true
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2006-12-13 16:10:26 +00:00
|
|
|
!,
|
2001-04-09 20:54:03 +01:00
|
|
|
( '$access_yap_flags'(15, 0) -> true ; halt).
|
2011-09-07 21:28:13 +01:00
|
|
|
'$do_startup_reconsult'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$skip_unix_comments'(Stream) :-
|
2011-05-12 22:34:44 +01:00
|
|
|
peek_code(Stream, 0'#), !, % 35 is ASCII for '#
|
2011-02-15 14:43:28 +00:00
|
|
|
skip(Stream, 10),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$skip_unix_comments'(Stream).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$skip_unix_comments'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2010-02-28 22:24:51 +00:00
|
|
|
source_file(FileName) :-
|
|
|
|
recorded('$lf_loaded','$lf_loaded'(FileName,Mod,_,_),_), Mod \= prolog.
|
|
|
|
|
|
|
|
source_file(Mod:Pred, FileName) :-
|
|
|
|
current_module(Mod),
|
|
|
|
Mod \= prolog,
|
|
|
|
'$current_predicate_no_modules'(Mod,_,Pred),
|
|
|
|
'$owned_by'(Pred, Mod, FileName).
|
|
|
|
|
|
|
|
'$owned_by'(T, Mod, FileName) :-
|
|
|
|
'$is_multifile'(T, Mod),
|
|
|
|
functor(T, Name, Arity),
|
|
|
|
setof(FileName, Ref^recorded('$multifile_defs','$defined'(FileName,Name,Arity,Mod), Ref), L),
|
|
|
|
lists:member(FileName, L).
|
|
|
|
'$owned_by'(T, Mod, FileName) :-
|
|
|
|
'$owner_file'(T, Mod, FileName).
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
prolog_load_context(_, _) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$consulting_file', [], fail), !, fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_load_context(directory, DirName) :-
|
2005-11-23 13:24:00 +00:00
|
|
|
getcwd(DirName).
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_load_context(file, FileName) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$nb_getval'('$included_file', IncFileName, fail ) -> true ; IncFileName = [] ),
|
2001-04-09 20:54:03 +01:00
|
|
|
( IncFileName = [] ->
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$consulting_file', FileName, fail),
|
2008-06-12 11:55:52 +01:00
|
|
|
FileName \= []
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2008-02-12 17:03:59 +00:00
|
|
|
FileName = IncFileName
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
|
|
|
prolog_load_context(module, X) :-
|
|
|
|
'$current_module'(X).
|
|
|
|
prolog_load_context(source, FileName) :-
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_getval('$consulting_file',FileName).
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_load_context(stream, Stream) :-
|
2011-07-11 15:40:58 +01:00
|
|
|
'$current_loop_stream'(Stream).
|
2011-04-30 10:57:00 +01:00
|
|
|
% return this term for SWI compatibility.
|
|
|
|
prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :-
|
2011-07-11 15:40:58 +01:00
|
|
|
'$current_loop_stream'(Stream),
|
2011-04-30 10:57:00 +01:00
|
|
|
stream_property(Stream, position(Position)),
|
|
|
|
stream_position_data(line_count, Position, Line).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
% if the file exports a module, then we can
|
|
|
|
% be imported from any module.
|
|
|
|
'$file_loaded'(Stream, M, Imports) :-
|
|
|
|
'$file_name'(Stream, F),
|
|
|
|
'$ensure_file_loaded'(F, M, Imports).
|
|
|
|
|
|
|
|
'$ensure_file_loaded'(F, M, Imports) :-
|
|
|
|
recorded('$module','$module'(F1,NM,P),_),
|
2009-10-16 08:31:23 +01:00
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,_,_,_),_),
|
2011-02-14 22:55:59 +00:00
|
|
|
same_file(F1,F), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$use_preds'(Imports,P, NM, M).
|
|
|
|
'$ensure_file_loaded'(F, M, _) :-
|
2009-10-16 08:31:23 +01:00
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,M,_,_),_),
|
2011-02-14 22:55:59 +00:00
|
|
|
same_file(F1,F), !.
|
2006-11-27 17:42:03 +00:00
|
|
|
|
2003-11-29 23:41:28 +00:00
|
|
|
|
|
|
|
% if the file exports a module, then we can
|
|
|
|
% be imported from any module.
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_unchanged'(Stream, M, Imports) :-
|
|
|
|
'$file_name'(Stream, F),
|
|
|
|
'$ensure_file_unchanged'(F, M, Imports).
|
|
|
|
|
|
|
|
'$ensure_file_unchanged'(F, M, Imports) :-
|
|
|
|
recorded('$module','$module'(F1,NM,P),_),
|
2009-10-16 08:31:23 +01:00
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,_,Age,_),R),
|
2011-02-14 22:55:59 +00:00
|
|
|
same_file(F1,F), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_is_unchanged'(F, R, Age),
|
|
|
|
'$use_preds'(Imports, P, NM, M).
|
|
|
|
'$ensure_file_unchanged'(F, M, _) :-
|
2009-10-16 08:31:23 +01:00
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,M,Age,_),R),
|
2011-02-14 22:55:59 +00:00
|
|
|
same_file(F1,F), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_is_unchanged'(F, R, Age).
|
2003-11-29 23:41:28 +00:00
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_is_unchanged'(F, R, Age) :-
|
2013-06-07 18:00:27 +01:00
|
|
|
time_file64(F,CurrentAge),
|
|
|
|
( (Age == CurrentAge ; Age = -1) -> true; erase(R), fail).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-07 12:05:39 +00:00
|
|
|
path(Path) :- findall(X,'$in_path'(X),Path).
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
'$in_path'(X) :- recorded('$path',Path,_),
|
2003-02-07 12:05:39 +00:00
|
|
|
atom_codes(Path,S),
|
|
|
|
( S = "" -> X = '.' ;
|
|
|
|
atom_codes(X,S) ).
|
|
|
|
|
|
|
|
add_to_path(New) :- add_to_path(New,last).
|
|
|
|
|
|
|
|
add_to_path(New,Pos) :-
|
|
|
|
atom(New), !,
|
|
|
|
'$check_path'(New,Str),
|
|
|
|
atom_codes(Path,Str),
|
|
|
|
'$add_to_path'(Path,Pos).
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
'$add_to_path'(New,_) :- recorded('$path',New,R), erase(R), fail.
|
2003-09-26 15:58:29 +01:00
|
|
|
'$add_to_path'(New,last) :- !, recordz('$path',New,_).
|
2003-08-27 14:37:10 +01:00
|
|
|
'$add_to_path'(New,first) :- recorda('$path',New,_).
|
2003-02-07 12:05:39 +00:00
|
|
|
|
|
|
|
remove_from_path(New) :- '$check_path'(New,Path),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$path',Path,R), erase(R).
|
2003-02-07 12:05:39 +00:00
|
|
|
|
|
|
|
'$check_path'(At,SAt) :- atom(At), !, atom_codes(At,S), '$check_path'(S,SAt).
|
|
|
|
'$check_path'([],[]).
|
|
|
|
'$check_path'([Ch],[Ch]) :- '$dir_separator'(Ch), !.
|
|
|
|
'$check_path'([Ch],[Ch,A]) :- !, integer(Ch), '$dir_separator'(A).
|
|
|
|
'$check_path'([N|S],[N|SN]) :- integer(N), '$check_path'(S,SN).
|
|
|
|
|
2004-10-06 17:55:48 +01:00
|
|
|
% add_multifile_predicate when we start consult
|
2003-11-26 18:36:35 +00:00
|
|
|
'$add_multifile'(Name,Arity,Module) :-
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_getval('$consulting_file',File),
|
2003-11-26 18:36:35 +00:00
|
|
|
'$add_multifile'(File,Name,Arity,Module).
|
|
|
|
|
|
|
|
'$add_multifile'(File,Name,Arity,Module) :-
|
2009-05-29 16:48:40 +01:00
|
|
|
recorded('$multifile_defs','$defined'(File,Name,Arity,Module), _), !.
|
|
|
|
% print_message(warning,declaration((multifile Module:Name/Arity),ignored)).
|
2005-04-20 21:06:26 +01:00
|
|
|
'$add_multifile'(File,Name,Arity,Module) :-
|
|
|
|
recordz('$multifile_defs','$defined'(File,Name,Arity,Module),_), !,
|
2003-11-26 18:36:35 +00:00
|
|
|
fail.
|
|
|
|
'$add_multifile'(File,Name,Arity,Module) :-
|
|
|
|
recorded('$mf','$mf_clause'(File,Name,Arity,Module,Ref),R),
|
|
|
|
erase(R),
|
2005-04-20 21:06:26 +01:00
|
|
|
'$erase_clause'(Ref,Module),
|
2003-11-26 18:36:35 +00:00
|
|
|
fail.
|
|
|
|
'$add_multifile'(_,_,_,_).
|
|
|
|
|
|
|
|
% retract old multifile clauses for current file.
|
|
|
|
'$remove_multifile_clauses'(FileName) :-
|
|
|
|
recorded('$multifile_defs','$defined'(FileName,_,_,_),R1),
|
|
|
|
erase(R1),
|
|
|
|
fail.
|
|
|
|
'$remove_multifile_clauses'(FileName) :-
|
|
|
|
recorded('$mf','$mf_clause'(FileName,_,_,Module,Ref),R),
|
|
|
|
'$erase_clause'(Ref, Module),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
'$remove_multifile_clauses'(_).
|
|
|
|
|
2005-10-19 02:47:43 +01:00
|
|
|
'$set_consulting_file'(user) :- !,
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$consulting_file',user_input).
|
2005-10-19 02:47:43 +01:00
|
|
|
'$set_consulting_file'(user_input) :- !,
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$consulting_file',user_input).
|
2005-10-19 02:47:43 +01:00
|
|
|
'$set_consulting_file'(Stream) :-
|
|
|
|
'$file_name'(Stream,F),
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$consulting_file',F),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$set_consulting_dir'(F).
|
|
|
|
|
|
|
|
%
|
|
|
|
% Use directory where file exists
|
|
|
|
%
|
|
|
|
'$set_consulting_dir'(F) :-
|
|
|
|
file_directory_name(F, Dir),
|
2011-05-12 22:26:10 +01:00
|
|
|
working_directory(_, Dir).
|
2005-10-19 02:47:43 +01:00
|
|
|
|
2009-10-16 08:31:23 +01:00
|
|
|
'$record_loaded'(Stream, M, Reconsult) :-
|
2005-10-19 11:12:50 +01:00
|
|
|
Stream \= user,
|
|
|
|
Stream \= user_input,
|
|
|
|
'$file_name'(Stream,F),
|
2009-10-16 08:31:23 +01:00
|
|
|
( recorded('$lf_loaded','$lf_loaded'(F,M,_,_),R), erase(R), fail ; true ),
|
2013-06-07 18:00:27 +01:00
|
|
|
time_file64(F,Age),
|
2009-10-16 08:31:23 +01:00
|
|
|
recorda('$lf_loaded','$lf_loaded'(F,M,Age,Reconsult),_),
|
2005-10-19 11:12:50 +01:00
|
|
|
fail.
|
2009-10-16 08:31:23 +01:00
|
|
|
'$record_loaded'(_, _, _).
|
2005-10-19 02:47:43 +01:00
|
|
|
|
2011-09-02 21:03:41 +01:00
|
|
|
'$set_encoding'(Encoding) :-
|
2011-07-11 15:40:58 +01:00
|
|
|
'$current_loop_stream'(Stream),
|
2011-09-02 21:03:41 +01:00
|
|
|
( Encoding == default -> true ; set_stream(Stream, encoding(Encoding)) ).
|
2007-09-28 00:02:00 +01:00
|
|
|
|
2007-09-27 16:25:34 +01:00
|
|
|
absolute_file_name(V,Out) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, absolute_file_name(V, Out)).
|
|
|
|
absolute_file_name(user,user) :- !.
|
|
|
|
absolute_file_name(File0,File) :-
|
2007-09-28 23:59:11 +01:00
|
|
|
'$absolute_file_name'(File0,[access(none),file_type(txt),file_errors(fail),solutions(first)],File,absolute_file_name(File0,File)).
|
2006-11-27 17:42:03 +00:00
|
|
|
|
2011-06-21 22:36:09 +01:00
|
|
|
'$full_filename'(F0,F,G) :-
|
|
|
|
'$absolute_file_name'(F0,[access(read),file_type(source),file_errors(fail),solutions(first),expand(true)],F,G).
|
2006-11-27 17:42:03 +00:00
|
|
|
|
2012-11-25 23:35:59 +00:00
|
|
|
% fix wrong argument order, TrueFileName should be last.
|
2007-09-27 16:25:34 +01:00
|
|
|
absolute_file_name(File,TrueFileName,Opts) :-
|
2012-11-25 23:35:59 +00:00
|
|
|
( var(TrueFileName) -> true ; atom(TrueFileName), TrueFileName \= [] ),
|
|
|
|
!,
|
2007-09-27 16:25:34 +01:00
|
|
|
absolute_file_name(File,Opts,TrueFileName).
|
|
|
|
absolute_file_name(File,Opts,TrueFileName) :-
|
|
|
|
'$absolute_file_name'(File,Opts,TrueFileName,absolute_file_name(File,Opts,TrueFileName)).
|
|
|
|
|
|
|
|
'$absolute_file_name'(File,Opts,TrueFileName,G) :- var(File), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$absolute_file_name'(File,Opts,TrueFileName, G) :-
|
|
|
|
'$process_fn_opts'(Opts,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G),
|
2011-06-22 12:29:35 +01:00
|
|
|
/* our own local findall */
|
|
|
|
nb:nb_queue(Ref),
|
2007-09-27 16:25:34 +01:00
|
|
|
(
|
2011-06-22 12:29:35 +01:00
|
|
|
'$find_in_path'(File,opts(Extensions,RelTo,Type,Access,FErrors,Expand,Debug),TrueFileName,G),
|
|
|
|
nb:nb_queue_enqueue(Ref, TrueFileName),
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
nb:nb_queue_close(Ref, FileNames, [])
|
|
|
|
),
|
2011-06-24 03:35:42 +01:00
|
|
|
'$absolute_file_names'(Solutions, FileNames, FErrors, TrueFileName, File, G).
|
2011-06-22 12:29:35 +01:00
|
|
|
|
|
|
|
'$absolute_file_names'(Solutions, [], error, _, File, G) :- !,
|
|
|
|
'$do_error'(existence_error(file,File),G).
|
|
|
|
'$absolute_file_names'(Solutions, FileNames, _, TrueFileName, _, _) :-
|
|
|
|
lists:member(TrueFileName, FileNames),
|
|
|
|
(Solutions == first -> ! ; true).
|
2007-09-27 16:25:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
'$process_fn_opts'(V,_,_,_,_,_,_,_,_,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
2011-06-22 12:29:35 +01:00
|
|
|
'$process_fn_opts'([],[],_,txt,none,error,first,false,false,_) :- !.
|
2007-09-27 16:25:34 +01:00
|
|
|
'$process_fn_opts'([Opt|Opts],Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
|
|
|
'$process_fn_opt'(Opt,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions0,RelTo0,Type0,Access0,FErrors0,Solutions0,Expand0,Debug0,G),
|
|
|
|
'$process_fn_opts'(Opts,Extensions0,RelTo0,Type0,Access0,FErrors0,Solutions0,Expand0,Debug0,G).
|
|
|
|
'$process_fn_opts'(Opts,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
2012-02-13 09:36:44 +00:00
|
|
|
'$do_error'(type_error(list,Opts),G).
|
2007-09-27 16:25:34 +01:00
|
|
|
|
|
|
|
'$process_fn_opt'(Opt,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- var(Opt), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$process_fn_opt'(extensions(Extensions),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,_,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
2009-03-13 19:40:27 +00:00
|
|
|
'$check_fn_extensions'(Extensions,G).
|
2007-09-27 16:25:34 +01:00
|
|
|
'$process_fn_opt'(relative_to(RelTo),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,_,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
|
|
|
'$check_atom'(RelTo,G).
|
|
|
|
'$process_fn_opt'(access(Access),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,_,FErrors,Solutions,Expand,Debug,G) :- !,
|
|
|
|
'$check_atom'(Access,G).
|
|
|
|
'$process_fn_opt'(file_type(Type),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,_,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
|
|
|
'$check_fn_type'(Type,G).
|
|
|
|
'$process_fn_opt'(file_errors(FErrors),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,_,Solutions,Expand,Debug,G) :- !,
|
|
|
|
'$check_fn_errors'(FErrors,G).
|
|
|
|
'$process_fn_opt'(solutions(Solutions),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,_,Expand,Debug,G) :- !,
|
|
|
|
'$check_fn_solutions'(Solutions,G).
|
|
|
|
'$process_fn_opt'(expand(Expand),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,_,Debug,G) :- !,
|
|
|
|
'$check_true_false'(Expand,G).
|
|
|
|
'$process_fn_opt'(verbose_file_search(Debug),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,_,G) :- !,
|
|
|
|
'$check_true_false'(Debug,G).
|
|
|
|
'$process_fn_opt'(Opt,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !,
|
2011-06-22 12:29:35 +01:00
|
|
|
'$do_error'(domain_error(file_name_option,Opt),G).
|
2007-09-27 16:25:34 +01:00
|
|
|
|
|
|
|
'$check_fn_extensions'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_fn_extensions'([],_) :- !.
|
|
|
|
'$check_fn_extensions'([A|L],G) :- !,
|
|
|
|
'$check_atom'(A,G),
|
|
|
|
'$check_fn_extensions'(L,G).
|
|
|
|
'$check_fn_extensions'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(list,T),G).
|
|
|
|
|
|
|
|
'$check_atom'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_atom'(A,G) :- atom(A), !.
|
|
|
|
'$check_atom'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(atom,T),G).
|
|
|
|
|
|
|
|
'$check_fn_type'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_fn_type'(txt,_) :- !.
|
|
|
|
'$check_fn_type'(prolog,_) :- !.
|
|
|
|
'$check_fn_type'(source,_) :- !.
|
|
|
|
'$check_fn_type'(executable,_) :- !.
|
|
|
|
'$check_fn_type'(qlf,_) :- !.
|
|
|
|
'$check_fn_type'(directory,_) :- !.
|
|
|
|
'$check_fn_type'(T,G) :- atom(T), !,
|
|
|
|
'$do_error'(domain_error(file_type,T),G).
|
|
|
|
'$check_fn_type'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(atom,T),G).
|
|
|
|
|
|
|
|
'$check_fn_errors'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_fn_errors'(fail,_) :- !.
|
|
|
|
'$check_fn_errors'(error,_) :- !.
|
|
|
|
'$check_fn_errors'(T,G) :- atom(T), !,
|
|
|
|
'$do_error'(domain_error(file_errors,T),G).
|
|
|
|
'$check_fn_errors'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(atom,T),G).
|
|
|
|
|
|
|
|
'$check_fn_solutions'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_fn_solutions'(first,_) :- !.
|
|
|
|
'$check_fn_solutions'(all,_) :- !.
|
|
|
|
'$check_fn_solutions'(T,G) :- atom(T), !,
|
|
|
|
'$do_error'(domain_error(solutions,T),G).
|
|
|
|
'$check_fn_solutions'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(atom,T),G).
|
|
|
|
|
|
|
|
'$check_true_false'(V,G) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error, G).
|
|
|
|
'$check_true_false'(true,_) :- !.
|
|
|
|
'$check_true_false'(false,_) :- !.
|
|
|
|
'$check_true_false'(T,G) :- atom(T), !,
|
|
|
|
'$do_error'(domain_error(boolean,T),G).
|
|
|
|
'$check_true_false'(T,G) :- !,
|
|
|
|
'$do_error'(type_error(atom,T),G).
|
|
|
|
|
|
|
|
% This sequence must be followed:
|
|
|
|
% user and user_input are special;
|
|
|
|
% library(F) must check library_directories
|
|
|
|
% T(F) must check file_search_path
|
|
|
|
% all must try search in path
|
|
|
|
'$find_in_path'(user,_,user_input, _) :- !.
|
|
|
|
'$find_in_path'(user_input,_,user_input, _) :- !.
|
2009-02-16 12:25:03 +00:00
|
|
|
'$find_in_path'(commons(F0),_,_, _) :-
|
|
|
|
% make sure library_directory is open.
|
|
|
|
\+ clause(user:commons_directory(_),_),
|
|
|
|
'$system_commons_directories'(D),
|
|
|
|
assert(user:commons_directory(D)),
|
|
|
|
fail.
|
2007-09-27 16:25:34 +01:00
|
|
|
'$find_in_path'(S, Opts, NewFile, Call) :-
|
2011-02-15 15:50:33 +00:00
|
|
|
S =.. [Name,File0],
|
|
|
|
'$cat_file_name'(File0,File), !,
|
2007-09-27 16:25:34 +01:00
|
|
|
'$dir_separator'(D),
|
|
|
|
atom_codes(A,[D]),
|
|
|
|
'$extend_path_directory'(Name, A, File, Opts, NewFile, Call).
|
2008-08-30 04:34:27 +01:00
|
|
|
'$find_in_path'(File0,Opts,NewFile,_) :-
|
|
|
|
'$cat_file_name'(File0,File), !,
|
2007-09-27 16:25:34 +01:00
|
|
|
'$add_path'(File,PFile),
|
|
|
|
'$get_abs_file'(PFile,Opts,AbsFile),
|
|
|
|
'$search_in_path'(AbsFile,Opts,NewFile).
|
|
|
|
'$find_in_path'(File,_,_,Call) :-
|
|
|
|
'$do_error'(domain_error(source_sink,File),Call).
|
|
|
|
|
2008-08-30 04:34:27 +01:00
|
|
|
% allow paths in File Name
|
|
|
|
'$cat_file_name'(File0,File) :-
|
|
|
|
atom(File0), !,
|
|
|
|
File = File0.
|
2011-02-15 15:50:33 +00:00
|
|
|
'$cat_file_name'(Atoms, File) :-
|
|
|
|
'$to_list_of_atoms'(Atoms, List, []),
|
|
|
|
atom_concat(List, File).
|
|
|
|
|
|
|
|
'$to_list_of_atoms'(V, _, _) :- var(V), !, fail.
|
|
|
|
'$to_list_of_atoms'(Atom, [Atom|L], L) :- atom(Atom), !.
|
|
|
|
'$to_list_of_atoms'(Atoms, L1, LF) :-
|
|
|
|
Atoms =.. [A,As,Bs],
|
|
|
|
atom_codes(A,[D]),
|
|
|
|
'$dir_separator'(D),
|
|
|
|
'$to_list_of_atoms'(As, L1, [A|L2]),
|
|
|
|
'$to_list_of_atoms'(Bs, L2, LF).
|
2008-08-30 04:34:27 +01:00
|
|
|
|
2011-06-21 22:36:09 +01:00
|
|
|
'$get_abs_file'(File,opts(_,RelTo,_,_,_,Expand,_),AbsFile) :-
|
|
|
|
(
|
|
|
|
nonvar(Relto)
|
|
|
|
->
|
|
|
|
'$dir_separator'(D),
|
|
|
|
atom_concat([RelTo, D, File], ActualFile)
|
|
|
|
;
|
|
|
|
ActualFile = File
|
|
|
|
),
|
|
|
|
'$swi_current_prolog_flag'(file_name_variables, OldF),
|
|
|
|
'$swi_set_prolog_flag'(file_name_variables, Expand),
|
|
|
|
(
|
|
|
|
'$absolute_file_name'(ActualFile,AbsFile)
|
|
|
|
->
|
|
|
|
'$swi_set_prolog_flag'(file_name_variables, OldF)
|
|
|
|
;
|
|
|
|
'$swi_set_prolog_flag'(file_name_variables, OldF),
|
|
|
|
fail
|
|
|
|
).
|
|
|
|
|
2007-09-27 16:25:34 +01:00
|
|
|
|
2010-09-24 12:14:37 +01:00
|
|
|
'$search_in_path'(File,opts(Extensions,_,Type,Access,_,_,_),F) :-
|
|
|
|
'$add_extensions'(Extensions, File, F0),
|
|
|
|
'$check_file'(F0, Type, Access, F).
|
2007-09-27 16:25:34 +01:00
|
|
|
'$search_in_path'(File,opts(_,_,Type,Access,_,_,_),F) :-
|
2010-09-24 12:14:37 +01:00
|
|
|
'$add_type_extensions'(Type, File, F0),
|
|
|
|
'$check_file'(F0, Type, Access, F).
|
|
|
|
|
|
|
|
'$check_file'(F, Type, none, F) :- !.
|
|
|
|
'$check_file'(F0, Type, Access, F0) :-
|
|
|
|
access_file(F0, Access),
|
|
|
|
(Type == directory
|
|
|
|
->
|
|
|
|
exists_directory(F0)
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
2007-09-27 16:25:34 +01:00
|
|
|
|
|
|
|
'$add_extensions'([Ext|_],File,F) :-
|
|
|
|
'$mk_sure_true_ext'(Ext,NExt),
|
|
|
|
atom_concat([File,NExt],F).
|
|
|
|
'$add_extensions'([_|Extensions],File,F) :-
|
|
|
|
'$add_extensions'(Extensions,File,F).
|
|
|
|
|
|
|
|
'$mk_sure_true_ext'(Ext,NExt) :-
|
|
|
|
atom_codes(Ext,[C|L]),
|
|
|
|
C \= 0'.,
|
|
|
|
!,
|
|
|
|
atom_codes(NExt,[0'.,C|L]).
|
|
|
|
'$mk_sure_true_ext'(Ext,Ext).
|
|
|
|
|
|
|
|
'$add_type_extensions'(Type,File,F) :-
|
2011-06-22 12:29:35 +01:00
|
|
|
( Type == source -> NType = prolog ; NType = Type ),
|
|
|
|
user:prolog_file_type(Ext, NType),
|
2011-06-14 09:04:03 +01:00
|
|
|
atom_concat([File,'.',Ext],F).
|
2011-06-22 12:29:35 +01:00
|
|
|
'$add_type_extensions'(_,File,File).
|
2007-09-27 16:25:34 +01:00
|
|
|
|
|
|
|
'$add_path'(File,File).
|
|
|
|
'$add_path'(File,PFile) :-
|
|
|
|
recorded('$path',Path,_),
|
|
|
|
atom_concat([Path,File],PFile).
|
|
|
|
|
2008-02-22 15:08:37 +00:00
|
|
|
'$system_library_directories'(Dir) :-
|
|
|
|
getenv('YAPSHAREDIR', Dir).
|
2009-02-16 12:25:03 +00:00
|
|
|
'$system_library_directories'(Dir) :-
|
|
|
|
getenv('YAPCOMMONSDIR', Dir).
|
2010-03-05 08:33:40 +00:00
|
|
|
'$system_library_directories'(Dir) :-
|
|
|
|
get_value(system_library_directory,Dir).
|
2009-02-16 12:25:03 +00:00
|
|
|
'$system_library_directories'(Dir) :-
|
|
|
|
get_value(prolog_commons_directory,Dir).
|
|
|
|
|
2008-02-22 15:08:37 +00:00
|
|
|
|
2007-09-27 16:25:34 +01:00
|
|
|
'$extend_path_directory'(Name, D, File, Opts, NewFile, Call) :-
|
2013-02-08 16:36:45 +00:00
|
|
|
user:file_search_path(Name, Dir),
|
2007-09-27 16:25:34 +01:00
|
|
|
'$extend_pathd'(Dir, D, File, Opts, NewFile, Call).
|
|
|
|
|
2007-10-10 10:44:28 +01:00
|
|
|
'$extend_pathd'(Dir, A, File, Opts, NewFile, Call) :-
|
2007-09-27 16:25:34 +01:00
|
|
|
atom(Dir), !,
|
2011-02-15 15:50:33 +00:00
|
|
|
'$add_file_to_dir'(Dir,A,File,NFile),
|
2007-10-10 10:44:28 +01:00
|
|
|
'$find_in_path'(NFile, Opts, NewFile, Goal), !.
|
2007-09-27 16:25:34 +01:00
|
|
|
'$extend_pathd'(Name, A, File, Opts, OFile, Goal) :-
|
|
|
|
nonvar(Name),
|
|
|
|
Name =.. [N,P0],
|
2011-02-15 15:50:33 +00:00
|
|
|
'$add_file_to_dir'(P0,A,File,NFile),
|
2007-09-27 16:25:34 +01:00
|
|
|
NewName =.. [N,NFile],
|
|
|
|
'$find_in_path'(NewName, Opts, OFile, Goal).
|
2006-11-27 17:42:03 +00:00
|
|
|
|
2011-02-15 15:50:33 +00:00
|
|
|
'$add_file_to_dir'(P0,A,Atoms,NFile) :-
|
|
|
|
atom_concat([P0,A,Atoms],NFile).
|
|
|
|
|
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
%
|
|
|
|
% This is complicated because of embedded ifs.
|
|
|
|
%
|
|
|
|
'$if'(_,top) :- !, fail.
|
|
|
|
'$if'(Goal,_) :-
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(Level0),
|
2007-10-21 09:48:06 +01:00
|
|
|
Level is Level0 + 1,
|
|
|
|
nb_setval('$if_level',Level),
|
2013-10-30 09:41:45 +00:00
|
|
|
( '$nb_getval'('$endif', OldEndif, fail) -> true ; OldEndif=top),
|
|
|
|
( '$nb_getval'('$if_skip_mode', Mode, fail) -> true ; Mode = run ),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$endif',elif(Level,OldEndif,Mode)),
|
|
|
|
fail.
|
|
|
|
% we are in skip mode, ignore....
|
|
|
|
'$if'(Goal,_) :-
|
2013-10-29 12:43:31 +00:00
|
|
|
'$nb_getval'('$endif',elif(Level, OldEndif, skip), fail), !,
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$endif',endif(Level, OldEndif, skip)).
|
|
|
|
% we are in non skip mode, check....
|
|
|
|
'$if'(Goal,_) :-
|
|
|
|
('$if_call'(Goal)
|
|
|
|
->
|
|
|
|
% we will execute this branch, and later enter skip
|
2013-10-29 12:43:31 +00:00
|
|
|
'$nb_getval'('$endif', elif(Level,OldEndif,Mode), fail),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$endif',endif(Level,OldEndif,Mode))
|
2013-10-30 09:41:45 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
;
|
|
|
|
% we are now in skip, but can start an elif.
|
|
|
|
nb_setval('$if_skip_mode',skip)
|
|
|
|
).
|
|
|
|
|
|
|
|
'$else'(top) :- !, fail.
|
|
|
|
'$else'(_) :-
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(0), !,
|
2007-10-21 09:48:06 +01:00
|
|
|
'$do_error'(context_error(no_if),(:- else)).
|
|
|
|
% we have done an if, so just skip
|
|
|
|
'$else'(_) :-
|
2013-10-30 09:41:45 +00:00
|
|
|
nb_getval('$endif',endif(_Level,_,_)), !,
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$if_skip_mode',skip).
|
|
|
|
% we can try the elif
|
|
|
|
'$else'(_) :-
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(Level),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_getval('$endif',elif(Level,OldEndif,Mode)),
|
|
|
|
nb_setval('$endif',endif(Level,OldEndif,Mode)),
|
|
|
|
nb_setval('$if_skip_mode',run).
|
|
|
|
|
|
|
|
'$elif'(_,top) :- !, fail.
|
|
|
|
'$elif'(Goal,_) :-
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(0),
|
2007-10-21 09:48:06 +01:00
|
|
|
'$do_error'(context_error(no_if),(:- elif(Goal))).
|
|
|
|
% we have done an if, so just skip
|
|
|
|
'$elif'(_,_) :-
|
|
|
|
nb_getval('$endif',endif(_,_,_)), !,
|
|
|
|
nb_setval('$if_skip_mode',skip).
|
|
|
|
% we can try the elif
|
|
|
|
'$elif'(Goal,_) :-
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(Level),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_getval('$endif',elif(Level,OldEndif,Mode)),
|
|
|
|
('$if_call'(Goal)
|
|
|
|
->
|
|
|
|
% we will not skip, and we will not run any more branches.
|
|
|
|
nb_setval('$endif',endif(Level,OldEndif,Mode)),
|
|
|
|
nb_setval('$if_skip_mode',run)
|
|
|
|
;
|
|
|
|
% we will (keep) on skipping
|
|
|
|
nb_setval('$if_skip_mode',skip)
|
|
|
|
).
|
|
|
|
'$elif'(_,_).
|
|
|
|
|
|
|
|
'$endif'(top) :- !, fail.
|
|
|
|
'$endif'(_) :-
|
|
|
|
% unmmatched endif.
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(0),
|
2007-10-21 09:48:06 +01:00
|
|
|
'$do_error'(context_error(no_if),(:- endif)).
|
|
|
|
'$endif'(_) :-
|
|
|
|
% back to where you belong.
|
2012-03-04 10:22:40 +00:00
|
|
|
'$get_if'(Level),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_getval('$endif',Endif),
|
|
|
|
Level0 is Level-1,
|
|
|
|
nb_setval('$if_level',Level0),
|
|
|
|
arg(2,Endif,OldEndif),
|
|
|
|
arg(3,Endif,OldMode),
|
|
|
|
nb_setval('$endif',OldEndif),
|
|
|
|
nb_setval('$if_skip_mode',OldMode).
|
|
|
|
|
|
|
|
|
|
|
|
'$if_call'(G) :-
|
|
|
|
catch('$eval_if'(G), E, (print_message(error, E), fail)).
|
|
|
|
|
|
|
|
'$eval_if'(Goal) :-
|
|
|
|
expand_term(Goal,TrueGoal),
|
|
|
|
once(TrueGoal).
|
|
|
|
|
|
|
|
'$if_directive'((:- if(_))).
|
|
|
|
'$if_directive'((:- else)).
|
|
|
|
'$if_directive'((:- elif(_))).
|
|
|
|
'$if_directive'((:- endif)).
|
|
|
|
|
2007-11-08 11:22:05 +00:00
|
|
|
|
2008-07-11 18:02:10 +01:00
|
|
|
'$comp_mode'(_OldCompMode, CompMode) :-
|
|
|
|
var(CompMode), !. % just do nothing.
|
|
|
|
'$comp_mode'(OldCompMode, assert_all) :-
|
|
|
|
'$fetch_comp_status'(OldCompMode),
|
|
|
|
nb_setval('$assert_all',on).
|
|
|
|
'$comp_mode'(OldCompMode, source) :-
|
|
|
|
'$fetch_comp_status'(OldCompMode),
|
|
|
|
'$set_yap_flags'(11,1).
|
|
|
|
'$comp_mode'(OldCompMode, compact) :-
|
|
|
|
'$fetch_comp_status'(OldCompMode),
|
|
|
|
'$set_yap_flags'(11,0).
|
|
|
|
|
|
|
|
'$fetch_comp_status'(assert_all) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$assert_all',on, fail), !.
|
2008-07-11 18:02:10 +01:00
|
|
|
'$fetch_comp_status'(source) :-
|
2008-12-12 22:46:32 +00:00
|
|
|
'$access_yap_flags'(11,1).
|
2008-07-11 18:02:10 +01:00
|
|
|
'$fetch_comp_status'(compact).
|
2007-11-08 11:22:05 +00:00
|
|
|
|
2009-10-15 12:56:16 +01:00
|
|
|
make :-
|
2009-10-16 08:31:23 +01:00
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,M,_,reconsult),_),
|
2009-10-15 12:56:16 +01:00
|
|
|
'$load_files'(F1, [if(changed)],make),
|
|
|
|
fail.
|
|
|
|
make.
|
|
|
|
|
2011-07-22 15:49:40 +01:00
|
|
|
make_library_index(_Directory).
|
|
|
|
|
2011-02-12 14:14:12 +00:00
|
|
|
'$file_name'(Stream,F) :-
|
|
|
|
stream_property(Stream, file_name(F)), !.
|
|
|
|
'$file_name'(user_input,user_output).
|
|
|
|
'$file_name'(user_output,user_ouput).
|
|
|
|
'$file_name'(user_error,user_error).
|
|
|
|
|
|
|
|
|
2011-02-14 14:59:15 +00:00
|
|
|
'$fetch_stream_alias'(OldStream,Alias) :-
|
|
|
|
stream_property(OldStream, alias(Alias)), !.
|
|
|
|
|
2011-06-14 09:04:03 +01:00
|
|
|
'$require'(_Ps, _M).
|
|
|
|
|
|
|
|
'$store_clause'('$source_location'(File, Line):Clause, File) :-
|
|
|
|
assert_static(Clause).
|
|
|
|
|
|
|
|
|
2011-07-11 15:40:58 +01:00
|
|
|
'$set_current_loop_stream'(OldStream, Stream) :-
|
|
|
|
'$current_loop_stream'(OldStream), !,
|
|
|
|
'$new_loop_stream'(Stream).
|
|
|
|
'$set_current_loop_stream'(OldStream, Stream) :-
|
|
|
|
'$new_loop_stream'(Stream).
|
|
|
|
|
|
|
|
'$new_loop_stream'(Stream) :-
|
|
|
|
(var(Stream) ->
|
|
|
|
nb_delete('$loop_stream')
|
|
|
|
;
|
|
|
|
nb_setval('$loop_stream',Stream)
|
|
|
|
).
|
|
|
|
|
|
|
|
'$current_loop_stream'(Stream) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$loop_stream',Stream, fail).
|
2011-07-11 15:40:58 +01:00
|
|
|
|
2012-02-13 09:36:44 +00:00
|
|
|
exists_source(File) :-
|
|
|
|
'$full_filename'(File, AbsFile, exists_source(File)).
|
|
|
|
|