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 *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2001-05-28 20:54:53 +01:00
|
|
|
ensure_loaded(V) :-
|
|
|
|
'$ensure_loaded'(V).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ensure_loaded'(V) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,ensure_loaded(V)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ensure_loaded'([]) :- !.
|
|
|
|
'$ensure_loaded'([F|Fs]) :- !,
|
|
|
|
'$ensure_loaded'(F),
|
|
|
|
'$ensure_loaded'(Fs).
|
2001-11-23 13:04:17 +00:00
|
|
|
'$ensure_loaded'(M:X) :- atom(M), !,
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M0),
|
|
|
|
'$change_module'(M),
|
|
|
|
'$ensure_loaded'(X),
|
|
|
|
'$change_module'(M0).
|
2002-02-08 22:19:24 +00:00
|
|
|
'$ensure_loaded'(X) :-
|
|
|
|
'$find_in_path'(X,Y,ensure_loaded(X)),
|
2002-02-12 18:24:21 +00:00
|
|
|
'$open'(Y, '$csult', Stream, 0), !,
|
2002-05-24 04:57:20 +01:00
|
|
|
( '$loaded'(Stream,TFN) ->
|
|
|
|
( '$recorded'('$module','$module'(TFN,M,P),_) ->
|
2002-02-12 18:24:21 +00:00
|
|
|
'$current_module'(T), '$import'(P,M,T)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2002-02-12 18:24:21 +00:00
|
|
|
true
|
|
|
|
)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2002-02-12 18:24:21 +00:00
|
|
|
'$reconsult'(X,Stream)
|
|
|
|
),
|
|
|
|
'$close'(Stream).
|
|
|
|
'$ensure_loaded'(X) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(input,stream,X),ensure_loaded(X)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
compile(P) :-
|
|
|
|
'$has_yap_or',
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(context_error(compile(P),clause),query).
|
2001-04-09 20:54:03 +01:00
|
|
|
compile(P) :-
|
|
|
|
'$compile'(P).
|
|
|
|
|
|
|
|
% leave compile mode to 1 for native code.
|
|
|
|
'$compile'(A) :-
|
|
|
|
'$compile_mode'(Old,0),
|
|
|
|
'$reconsult'(A),
|
|
|
|
'$compile_mode'(_,Old).
|
|
|
|
|
|
|
|
consult(Fs) :-
|
|
|
|
'$has_yap_or',
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(context_error(consult(Fs),clause),query).
|
2001-04-09 20:54:03 +01:00
|
|
|
consult(Fs) :-
|
|
|
|
'$consult'(Fs).
|
|
|
|
|
|
|
|
reconsult(Fs) :-
|
2001-10-30 22:13:18 +00:00
|
|
|
'$has_yap_or', fail,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(context_error(reconsult(Fs),clause),query).
|
2001-04-09 20:54:03 +01:00
|
|
|
reconsult(Fs) :-
|
|
|
|
'$reconsult'(Fs).
|
|
|
|
|
|
|
|
'$reconsult'(V) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,reconsult(V)).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$reconsult'([]) :- !.
|
2001-11-23 13:04:17 +00:00
|
|
|
'$reconsult'(M:X) :- atom(M), !,
|
|
|
|
'$current_module'(M0),
|
|
|
|
'$change_module'(M),
|
|
|
|
'$reconsult'(X),
|
|
|
|
'$change_module'(M0).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$reconsult'([F|Fs]) :- !,
|
|
|
|
'$reconsult'(F),
|
|
|
|
'$reconsult'(Fs).
|
2002-02-08 22:19:24 +00:00
|
|
|
'$reconsult'(X) :-
|
|
|
|
'$find_in_path'(X,Y,reconsult(X)),
|
2002-02-12 18:24:21 +00:00
|
|
|
'$open'(Y,'$csult',Stream,0), !,
|
|
|
|
'$reconsult'(X,Stream),
|
|
|
|
'$close'(Stream).
|
|
|
|
'$reconsult'(X) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(input,stream,X),reconsult(X)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-05-24 04:57:20 +01:00
|
|
|
'$reconsult'(F,Stream) :-
|
|
|
|
'$record_loaded'(Stream),
|
|
|
|
fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$reconsult'(F,Stream) :-
|
|
|
|
'$getcwd'(OldD),
|
|
|
|
'$get_value'('$consulting_file',OldF),
|
|
|
|
'$set_consulting_file'(Stream),
|
2002-01-22 17:11:36 +00:00
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2001-04-09 20:54:03 +01:00
|
|
|
current_stream(File,_,Stream),
|
|
|
|
'$get_value'('$consulting',Old),
|
|
|
|
'$set_value'('$consulting',false),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$current_module'(OldModule),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$start_reconsulting'(F),
|
|
|
|
'$start_consult'(reconsult,File,LC),
|
|
|
|
'$recorda'('$initialisation','$',_),
|
2002-01-22 19:29:28 +00:00
|
|
|
'$print_message'(informational, loading(reconsulting, File)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$loop'(Stream,reconsult),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$current_module'(Mod,OldModule),
|
|
|
|
'$end_consult',
|
2001-04-09 20:54:03 +01:00
|
|
|
'$clear_reconsulting',
|
|
|
|
( LC == 0 -> prompt(_,' |: ') ; true),
|
2002-01-22 17:11:36 +00:00
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
2002-01-22 19:29:28 +00:00
|
|
|
'$print_message'(informational, loaded(reconsulted, File, Mod, T, H)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$set_value'('$consulting',Old),
|
|
|
|
'$set_value'('$consulting_file',OldF),
|
|
|
|
'$cd'(OldD),
|
2002-10-23 18:10:33 +01:00
|
|
|
'$exec_initialisation_goals',
|
2001-04-09 20:54:03 +01:00
|
|
|
!.
|
|
|
|
|
|
|
|
'$start_reconsulting'(F) :-
|
|
|
|
'$recorda'('$reconsulted','$',_),
|
|
|
|
'$recorda'('$reconsulting',F,_).
|
|
|
|
|
|
|
|
'EMACS_FILE'(F,File0) :-
|
2002-01-07 06:28:04 +00:00
|
|
|
'$format'('''EMACS_RECONSULT''(~w).~n',[File0]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$getcwd'(OldD),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$open'(F,'$csult',Stream,0),
|
2002-02-08 22:19:24 +00:00
|
|
|
'$find_in_path'(File0,File,emacs(F)),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$open'(File,'$csult',Stream0,0),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$get_value'('$consulting_file',OldF),
|
|
|
|
'$set_consulting_file'(Stream0),
|
2002-01-22 17:11:36 +00:00
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$get_value'('$consulting',Old),
|
|
|
|
'$set_value'('$consulting',false),
|
|
|
|
'$start_reconsulting'(File),
|
|
|
|
'$start_consult'(reconsult,File,LC),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$current_module'(OldModule),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$recorda'('$initialisation','$',_),
|
2002-01-22 19:29:28 +00:00
|
|
|
'$print_message'(informational, loading(reconsulting, File)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$loop'(Stream,reconsult),
|
2002-01-22 17:11:36 +00:00
|
|
|
'$current_module'(Mod,OldModule),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$end_consult',
|
|
|
|
'$clear_reconsulting',
|
|
|
|
( LC == 0 -> prompt(_,' |: ') ; true),
|
2002-01-22 17:11:36 +00:00
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
2002-01-22 19:29:28 +00:00
|
|
|
'$print_message'(informational, loaded(reconsulted, File, Mod, T, H)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$set_value'('$consulting',Old),
|
|
|
|
'$set_value'('$consulting_file',OldF),
|
|
|
|
'$cd'(OldD),
|
2002-10-23 18:10:33 +01:00
|
|
|
'$exec_initialisation_goals',
|
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) :-
|
|
|
|
'$recorda'('$initialisation',G,_),
|
|
|
|
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) :-
|
|
|
|
'$find_in_path'(X,Y,include(X)),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$values'('$included_file',OY,Y),
|
2002-01-07 06:28:04 +00:00
|
|
|
( '$open'(Y,'$csult',Stream,0), !,
|
|
|
|
'$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
|
|
|
),
|
2001-11-19 03:36:51 +00:00
|
|
|
'$set_value'('$included_file',OY).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$do_startup_reconsult'(X) :-
|
|
|
|
( '$access_yap_flags'(15, 0) ->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
'$set_value'('$verbose',off)
|
|
|
|
),
|
2002-02-14 19:36:12 +00:00
|
|
|
( '$find_in_path'(X,Y,reconsult(X)),
|
|
|
|
'$open'(Y,'$csult',Stream,0) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
( '$access_yap_flags'(15, 0) -> true ; '$skip_unix_comments'(Stream) ),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$reconsult'(X,Stream), '$close'(Stream)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
'$output_error_message'(permission_error(input,stream,X),reconsult(X))
|
|
|
|
),
|
|
|
|
( '$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(_, _) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$get_value'('$consulting_file',[]), !, fail.
|
|
|
|
prolog_load_context(directory, DirName) :-
|
|
|
|
'$get_value'('$consulting_file',FileName),
|
|
|
|
(FileName = user_input ->
|
|
|
|
'$getcwd'(S),
|
|
|
|
atom_codes(DirName,S)
|
|
|
|
;
|
|
|
|
atom_codes(FileName,S),
|
|
|
|
'$strip_file_for_scd'(S,Dir,Unsure,Unsure),
|
|
|
|
atom_codes(DirName,Dir)
|
|
|
|
).
|
|
|
|
prolog_load_context(file, FileName) :-
|
|
|
|
'$get_value'('$included_file',IncFileName),
|
|
|
|
( IncFileName = [] ->
|
|
|
|
'$get_value'('$consulting_file',FileName)
|
|
|
|
;
|
|
|
|
FileName = IncFileName
|
|
|
|
).
|
|
|
|
prolog_load_context(module, X) :-
|
|
|
|
'$current_module'(X).
|
|
|
|
prolog_load_context(source, FileName) :-
|
|
|
|
'$get_value'('$consulting_file',FileName).
|
|
|
|
prolog_load_context(stream, Stream) :-
|
|
|
|
'$fetch_stream_alias'('$loop_stream', Stream).
|
|
|
|
prolog_load_context(term_position, Position) :-
|
|
|
|
'$fetch_stream_alias'('$loop_stream', Stream),
|
|
|
|
stream_position(Stream, Position).
|
|
|
|
|
|
|
|
|
2002-05-24 04:57:20 +01:00
|
|
|
'$loaded'(Stream,F1) :-
|
2001-11-23 13:04:17 +00:00
|
|
|
'$file_name'(Stream,F), %
|
2002-05-24 04:57:20 +01:00
|
|
|
'$recorded'('$loaded','$loaded'(F1,Age),R),
|
|
|
|
'$same_file'(F1,F), !,
|
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
|
|
|
|
|
|
|
|
|
|
|
|