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
|
|
|
|
% encoding(Enconding)
|
|
|
|
% expand({true,false)
|
|
|
|
% if(changed,true,not_loaded)
|
|
|
|
% imports(all,List)
|
|
|
|
% qcompile(true,false)
|
|
|
|
% silent(true,false) => implemented
|
|
|
|
% stream(Stream) => implemented
|
|
|
|
% consult(consult,reconsult)
|
|
|
|
%
|
|
|
|
load_files(Files,Opts) :-
|
|
|
|
'$load_files'(Files,Opts,load_files(Files,Opts)).
|
|
|
|
|
|
|
|
'$load_files'(Files,Opts,Call) :-
|
|
|
|
'$process_lf_opts'(Opts,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,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),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$lf'(Files,M0,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,UseModule),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$close_lf'(Silent).
|
|
|
|
|
|
|
|
'$process_lf_opts'(V,_,_,_,_,_,_,_,_,_,_,Call) :-
|
|
|
|
var(V), !,
|
|
|
|
'$do_error'(instantiation_error,Call).
|
|
|
|
'$process_lf_opts'([],_,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opts'([Opt|Opts],Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,Files,Call) :-
|
|
|
|
'$process_lf_opt'(Opt,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,Files,Call), !,
|
|
|
|
'$process_lf_opts'(Opts,Silent,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,Files,Call).
|
|
|
|
'$process_lf_opts'([Opt|Opts],_,_,_,_,_,_,_,_,_,_,Call) :-
|
|
|
|
'$do_error'(domain_error(unimplemented_option,Opt),Call).
|
|
|
|
|
|
|
|
'$process_lf_opt'(autoload(true),_,InfLevel,_,_,_,_,_,_,_,_,_) :-
|
|
|
|
get_value('$verbose_auto_load',VAL),
|
|
|
|
(VAL = true ->
|
|
|
|
InfLevel = informational
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2005-10-18 18:04:43 +01:00
|
|
|
InfLevel = silent
|
|
|
|
).
|
|
|
|
'$process_lf_opt'(autoload(false),_,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(derived_from(File),_,_,_,_,_,_,_,_,_,Files,Call) :-
|
|
|
|
( 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).
|
|
|
|
'$process_lf_opt'(encoding(Encoding),_,_,_,_,_,_,_,_,_,_,Call) :-
|
|
|
|
'$do_error'(domain_error(unimplemented_option,encoding),Call).
|
|
|
|
'$process_lf_opt'(expand(true),_,_,true,_,_,_,_,_,_,_,Call) :-
|
|
|
|
'$do_error'(domain_error(unimplemented_option,expand),Call).
|
|
|
|
'$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) :-
|
|
|
|
'$do_error'(domain_error(unimplemented_option,qcompile),Call).
|
|
|
|
'$process_lf_opt'(qcompile(false),_,_,_,_,false,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(silent(true),Silent,silent,_,_,_,_,_,_,_,_,_) :-
|
|
|
|
( get_value('$lf_verbose',Silent) -> true ; Silent = informational),
|
|
|
|
set_value('$lf_verbose',silent).
|
|
|
|
'$process_lf_opt'(silent(false),_,_,_,_,_,_,_,_,_,_,_).
|
|
|
|
'$process_lf_opt'(consult(reconsult),_,_,_,_,_,_,_,_,reconsult,_,_).
|
|
|
|
'$process_lf_opt'(consult(consult),_,_,_,_,_,_,_,_,consult,_,_).
|
2005-10-19 11:12:50 +01:00
|
|
|
'$process_lf_opt'(stream(Stream),_,_,_,_,_,_,Stream,_,_,Files,_) :-
|
|
|
|
/* ( '$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) :- !.
|
|
|
|
|
|
|
|
'$lf'(V,_,Call,_,_,_,_,_,_,_,_) :- var(V), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$do_error'(instantiation_error,Call).
|
2005-10-28 18:38:50 +01:00
|
|
|
'$lf'([],_,_,_,_,_,_,_,_,_,_,_) :- !.
|
|
|
|
'$lf'(M:X, _, Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,UseModule) :- !,
|
2005-10-18 18:04:43 +01:00
|
|
|
(
|
|
|
|
atom(M)
|
|
|
|
->
|
2005-10-28 18:38:50 +01:00
|
|
|
'$lf'(X, M, Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,UseModule)
|
2005-10-18 18:04:43 +01:00
|
|
|
;
|
|
|
|
'$do_error'(type_error(atom,M),Call)
|
|
|
|
).
|
2005-10-28 18:38:50 +01:00
|
|
|
'$lf'([F|Fs], Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,UseModule) :- !,
|
2005-12-18 17:12:33 +00:00
|
|
|
'$lf'(F,Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,_),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$lf'(Fs, Mod,Call,InfLevel,Expand,Changed,CompilationMode,Imports,Stream,Encoding,Reconsult,UseModule).
|
|
|
|
'$lf'(X, Mod, Call,InfLevel,_,Changed,CompilationMode,Imports,Stream,_,Reconsult,UseModule) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
nonvar(Stream), !,
|
2005-10-28 18:38:50 +01:00
|
|
|
'$do_lf'(X, Mod, Stream, InfLevel,CompilationMode,Imports,Reconsult,UseModule).
|
|
|
|
'$lf'(user, Mod, Call,InfLevel,_,Changed,CompilationMode,Imports,_,_,Reconsult,UseModule) :- !,
|
|
|
|
'$do_lf'(user_input, Mod, user_input, InfLevel, CompilationMode,Imports,Reconsult,UseModule).
|
|
|
|
'$lf'(user_input, Mod, Call,InfLevel,_,Changed,CompilationMode,Imports,_,_,UseModule) :- !,
|
|
|
|
'$do_lf'(user_input, Mod, user_input, InfLevel, CompilationMode,Imports,UseModule).
|
|
|
|
'$lf'(X, Mod, Call, InfLevel,_,Changed,CompilationMode,Imports,_,_,Reconsult,UseModule) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$find_in_path'(X, Y, Call),
|
|
|
|
'$open'(Y, '$csult', Stream, 0), !,
|
2005-10-28 18:38:50 +01:00
|
|
|
'$set_changed_lfmode'(Changed),
|
|
|
|
'$start_lf'(X, Mod, Stream, InfLevel, CompilationMode, Imports, Changed,Reconsult,UseModule),
|
2002-02-12 18:24:21 +00:00
|
|
|
'$close'(Stream).
|
2005-10-28 18:38:50 +01: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
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$start_lf'(_, Mod, Stream,_ ,_, Imports, not_loaded, _,_) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_loaded'(Stream, Mod, Imports), !.
|
2005-10-28 18:38:50 +01:00
|
|
|
'$start_lf'(_, Mod, Stream, _, _, Imports, changed, _,_) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
'$file_unchanged'(Stream, Mod, Imports), !.
|
2005-10-28 18:38:50 +01:00
|
|
|
'$start_lf'(X, Mod, Stream, InfLevel, CompilationMode, Imports, _, Reconsult, UseModule) :-
|
|
|
|
'$do_lf'(X, Mod, Stream, InfLevel, CompilationMode, Imports, Reconsult, UseModule).
|
2005-10-18 18:04:43 +01:00
|
|
|
|
|
|
|
'$close_lf'(Silent) :-
|
2005-10-19 02:47:43 +01:00
|
|
|
nonvar(Silent), !,
|
2005-10-18 18:04:43 +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
|
|
|
|
|
|
|
consult(Fs) :-
|
|
|
|
'$has_yap_or',
|
2002-09-09 18:40:12 +01:00
|
|
|
'$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
|
|
|
|
!,
|
|
|
|
'$load_files'(Module:Fs,[],Fs).
|
|
|
|
'$consult'(Fs, Module) :- var(V), !,
|
2005-10-19 02:47:43 +01:00
|
|
|
'$load_files'(Module:Fs,[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
|
|
|
|
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) :-
|
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).
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$do_lf'(F, ContextModule, Stream, InfLevel, _, Imports, Reconsult, UseModule) :-
|
2003-11-29 23:41:28 +00:00
|
|
|
'$record_loaded'(Stream, M),
|
2004-02-10 01:07:46 +00:00
|
|
|
'$current_module'(OldModule,ContextModule),
|
2005-11-23 13:24:00 +00:00
|
|
|
getcwd(OldD),
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$consulting_file',OldF),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$set_consulting_file'(Stream),
|
2002-01-22 17:11:36 +00:00
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$current_stream'(File,_,Stream),
|
2005-10-28 18:38:50 +01:00
|
|
|
'$fetch_stream_alias'(OldStream,'$loop_stream'),
|
|
|
|
'$change_alias_to_stream'('$loop_stream',Stream),
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$consulting',Old),
|
|
|
|
set_value('$consulting',false),
|
2005-10-18 18:04:43 +01:00
|
|
|
'$consult_infolevel'(InfLevel),
|
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
|
|
|
|
),
|
|
|
|
'$print_message'(InfLevel, loading(StartMsg, File)),
|
2005-02-08 04:05:39 +00:00
|
|
|
( recorded('$trace', on, TraceR) -> erase(TraceR) ; true),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$loop'(Stream,Reconsult),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$end_consult',
|
2005-02-08 04:05:39 +00:00
|
|
|
( nonvar(TraceR) -> recorda('$trace', on, _) ; true),
|
2005-10-19 02:47:43 +01:00
|
|
|
(
|
|
|
|
Reconsult = reconsult ->
|
|
|
|
'$clear_reconsulting'
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2003-08-27 14:37:10 +01:00
|
|
|
set_value('$consulting',Old),
|
|
|
|
set_value('$consulting_file',OldF),
|
2005-10-19 02:47:43 +01:00
|
|
|
cd(OldD),
|
2002-11-19 14:43:17 +00:00
|
|
|
'$current_module'(Mod,OldModule),
|
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),
|
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$print_message'(InfLevel, loaded(EndMsg, File, Mod, T, H)),
|
2004-02-05 16:57:02 +00:00
|
|
|
'$exec_initialisation_goals',
|
2005-10-28 18:38:50 +01:00
|
|
|
'$change_alias_to_stream'('$loop_stream',OldStream),
|
2001-04-09 20:54:03 +01:00
|
|
|
!.
|
|
|
|
|
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) :-
|
2005-10-28 18:38:50 +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) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$initialisation',G,_),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
'$initialization'(_).
|
|
|
|
|
|
|
|
|
|
|
|
'$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) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
get_value('$lf_verbose',Verbosity),
|
2002-02-08 22:19:24 +00:00
|
|
|
'$find_in_path'(X,Y,include(X)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$values'('$included_file',OY,Y),
|
2004-09-30 20:51:54 +01:00
|
|
|
'$current_module'(Mod),
|
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2002-01-07 06:28:04 +00:00
|
|
|
( '$open'(Y,'$csult',Stream,0), !,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$print_message'(Verbosity, loading(including, Y)),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$loop'(Stream,Status), '$close'(Stream)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2002-09-09 18:40:12 +01: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,
|
2005-10-18 18:04:43 +01:00
|
|
|
'$print_message'(Verbosity, loaded(included, Y, Mod, T, H)),
|
2003-08-27 14:37:10 +01:00
|
|
|
set_value('$included_file',OY).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$do_startup_reconsult'(X) :-
|
|
|
|
( '$access_yap_flags'(15, 0) ->
|
2005-10-19 11:12:50 +01:00
|
|
|
Opts=[]
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2005-10-19 11:12:50 +01:00
|
|
|
Opts=[silent(true)]
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2006-02-17 15:56:36 +00:00
|
|
|
load_files(X, Opts),
|
2001-04-09 20:54:03 +01:00
|
|
|
( '$access_yap_flags'(15, 0) -> true ; halt).
|
|
|
|
|
|
|
|
'$skip_unix_comments'(Stream) :-
|
2002-02-06 17:35:26 +00:00
|
|
|
'$peek'(Stream, 0'#), !, % 35 is ASCII for #
|
2001-04-09 20:54:03 +01:00
|
|
|
'$get0_line_codes'(Stream, _),
|
|
|
|
'$skip_unix_comments'(Stream).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$skip_unix_comments'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
prolog_load_context(_, _) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$consulting_file',[]), !, 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) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$included_file',IncFileName),
|
2001-04-09 20:54:03 +01:00
|
|
|
( IncFileName = [] ->
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$consulting_file',FileName)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
FileName = IncFileName
|
|
|
|
).
|
|
|
|
prolog_load_context(module, X) :-
|
|
|
|
'$current_module'(X).
|
|
|
|
prolog_load_context(source, FileName) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$consulting_file',FileName).
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_load_context(stream, Stream) :-
|
2005-10-28 18:38:50 +01:00
|
|
|
'$fetch_stream_alias'(Stream,'$loop_stream').
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_load_context(term_position, Position) :-
|
2005-10-28 18:38:50 +01:00
|
|
|
'$fetch_stream_alias'(Stream,'$loop_stream').
|
2001-04-09 20:54:03 +01:00
|
|
|
stream_position(Stream, Position).
|
|
|
|
|
|
|
|
|
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),_),
|
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,_,Age),R),
|
|
|
|
'$same_file'(F1,F), !,
|
|
|
|
'$use_preds'(Imports,P, NM, M).
|
|
|
|
'$ensure_file_loaded'(F, M, _) :-
|
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,M,Age),R),
|
|
|
|
'$same_file'(F1,F).
|
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),_),
|
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,_,Age),R),
|
2003-11-29 23:41:28 +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, _) :-
|
|
|
|
recorded('$lf_loaded','$lf_loaded'(F1,M,Age),R),
|
2002-05-24 04:57:20 +01: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) :-
|
2001-07-05 21:23:21 +01:00
|
|
|
'$file_age'(F,CurrentAge),
|
|
|
|
((CurrentAge = Age ; 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) :-
|
|
|
|
get_value('$consulting_file',File),
|
|
|
|
'$add_multifile'(File,Name,Arity,Module).
|
|
|
|
|
|
|
|
'$add_multifile'(File,Name,Arity,Module) :-
|
2005-04-20 21:06:26 +01:00
|
|
|
recorded('$multifile_defs','$defined'(File,Name,Arity,Module), _), !,
|
|
|
|
'$print_message'(warning,declaration((multifile Module:Name/Arity),ignored)).
|
|
|
|
'$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) :- !,
|
|
|
|
set_value('$consulting_file',user_input).
|
|
|
|
'$set_consulting_file'(user_input) :- !,
|
|
|
|
set_value('$consulting_file',user_input).
|
|
|
|
'$set_consulting_file'(Stream) :-
|
|
|
|
'$file_name'(Stream,F),
|
|
|
|
set_value('$consulting_file',F),
|
|
|
|
'$set_consulting_dir'(F).
|
|
|
|
|
|
|
|
%
|
|
|
|
% Use directory where file exists
|
|
|
|
%
|
|
|
|
'$set_consulting_dir'(F) :-
|
|
|
|
file_directory_name(F, Dir),
|
|
|
|
cd(Dir).
|
|
|
|
|
2005-10-19 11:12:50 +01:00
|
|
|
'$record_loaded'(Stream, M) :-
|
|
|
|
Stream \= user,
|
|
|
|
Stream \= user_input,
|
|
|
|
'$file_name'(Stream,F),
|
|
|
|
( recorded('$lf_loaded','$lf_loaded'(F,M,_),R), erase(R), fail ; true ),
|
|
|
|
|
|
|
|
'$file_age'(F,Age),
|
|
|
|
recorda('$lf_loaded','$lf_loaded'(F,M,Age),_),
|
|
|
|
fail.
|
|
|
|
'$record_loaded'(_, _).
|
2005-10-19 02:47:43 +01:00
|
|
|
|