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: boot.yap *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: boot file for Prolog *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2003-01-08 16:45:35 +00:00
|
|
|
|
2011-06-14 09:01:10 +01:00
|
|
|
%
|
|
|
|
%
|
|
|
|
%
|
2002-03-08 06:33:16 +00:00
|
|
|
true :- true.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2009-10-23 16:50:43 +01:00
|
|
|
'$live' :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$init_system',
|
2002-01-16 22:11:55 +00:00
|
|
|
'$do_live'.
|
|
|
|
|
2012-09-21 11:49:59 +01:00
|
|
|
'$init_prolog' :-
|
|
|
|
'$init_system'.
|
|
|
|
|
2002-01-16 22:11:55 +00:00
|
|
|
'$do_live' :-
|
2012-09-21 11:49:59 +01:00
|
|
|
repeat,
|
|
|
|
'$current_module'(Module),
|
|
|
|
( Module==user ->
|
|
|
|
'$compile_mode'(_,0)
|
|
|
|
;
|
|
|
|
format(user_error,'[~w]~n', [Module])
|
|
|
|
),
|
|
|
|
'$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$init_system' :-
|
2013-10-30 14:12:54 +00:00
|
|
|
get_value('$yap_inited', true), !.
|
2012-09-21 11:49:59 +01:00
|
|
|
'$init_system' :-
|
2013-10-30 14:12:54 +00:00
|
|
|
set_value('$yap_inited', true),
|
2012-09-21 11:49:59 +01:00
|
|
|
% do catch as early as possible
|
|
|
|
(
|
|
|
|
'$access_yap_flags'(15, 0),
|
|
|
|
'$access_yap_flags'(22, 0),
|
|
|
|
\+ '$uncaught_throw'
|
|
|
|
->
|
|
|
|
'$version'
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'$access_yap_flags'(22, 0) ->
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_set_prolog_flag'(verbose, normal)
|
2012-09-21 11:49:59 +01:00
|
|
|
;
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_set_prolog_flag'(verbose, silent)
|
2012-09-21 11:49:59 +01:00
|
|
|
),
|
2012-06-12 14:50:36 +01:00
|
|
|
% '$init_preds', % needs to be done before library_directory
|
|
|
|
% (
|
|
|
|
% retractall(user:library_directory(_)),
|
|
|
|
% '$system_library_directories'(D),
|
|
|
|
% assertz(user:library_directory(D)),
|
|
|
|
% fail
|
|
|
|
% ;
|
|
|
|
% true
|
|
|
|
% ),
|
2012-09-21 11:49:59 +01:00
|
|
|
'$init_globals',
|
|
|
|
'$swi_set_prolog_flag'(fileerrors, true),
|
|
|
|
set_value('$gc',on),
|
|
|
|
('$exit_undefp' -> true ; true),
|
|
|
|
prompt1(' ?- '),
|
2013-11-04 13:05:40 +00:00
|
|
|
'$swi_set_prolog_flag'(debug, false),
|
2006-12-13 16:10:26 +00:00
|
|
|
% simple trick to find out if this is we are booting from Prolog.
|
2011-09-09 21:39:15 +01:00
|
|
|
% boot from a saved state
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2011-09-09 21:39:15 +01:00
|
|
|
'$undefined'('$init_preds',prolog)
|
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
'$init_state'
|
|
|
|
),
|
2006-12-13 16:10:26 +00:00
|
|
|
'$db_clean_queues'(0),
|
2010-12-07 15:06:53 +00:00
|
|
|
% this must be executed from C-code.
|
|
|
|
% '$startup_saved_state',
|
2011-02-14 19:43:54 +00:00
|
|
|
set_input(user_input),
|
|
|
|
set_output(user_output),
|
2010-01-14 15:58:19 +00:00
|
|
|
'$init_or_threads',
|
2009-04-25 18:54:21 +01:00
|
|
|
'$run_at_thread_start'.
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2010-02-28 09:08:06 +00:00
|
|
|
'$init_globals' :-
|
|
|
|
'$init_consult',
|
2013-11-15 15:45:55 +00:00
|
|
|
% '$swi_set_prolog_flag'(break_level, 0),
|
2013-10-29 12:43:31 +00:00
|
|
|
% '$set_read_error_handler'(error), let the user do that
|
|
|
|
nb_setval('$chr_toplevel_show_store',false).
|
2010-02-28 09:08:06 +00:00
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
'$init_consult' :-
|
2013-10-29 12:43:31 +00:00
|
|
|
set_value('$open_expands_filename',true),
|
|
|
|
nb_setval('$assert_all',off),
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_setval('$if_level',0),
|
|
|
|
nb_setval('$endif',off),
|
2013-11-04 01:14:48 +00:00
|
|
|
nb_setval('$initialization_goals',off),
|
2012-07-07 00:49:02 +01:00
|
|
|
nb_setval('$included_file',[]),
|
2012-08-23 21:02:15 +01:00
|
|
|
\+ '$undefined'('$init_preds',prolog),
|
|
|
|
'$init_preds',
|
2012-07-07 00:49:02 +01:00
|
|
|
fail.
|
|
|
|
'$init_consult' :-
|
|
|
|
retractall(user:library_directory(_)),
|
|
|
|
% make sure library_directory is open.
|
|
|
|
\+ clause(user:library_directory(_),_),
|
|
|
|
'$system_library_directories'(D),
|
|
|
|
assert(user:library_directory(D)),
|
|
|
|
fail.
|
|
|
|
'$init_consult'.
|
|
|
|
|
2010-01-14 15:58:19 +00:00
|
|
|
'$init_or_threads' :-
|
2011-06-21 15:19:07 +01:00
|
|
|
'$c_yapor_workers'(W), !,
|
2010-01-14 15:58:19 +00:00
|
|
|
'$start_orp_threads'(W).
|
|
|
|
'$init_or_threads'.
|
|
|
|
|
|
|
|
'$start_orp_threads'(1) :- !.
|
|
|
|
'$start_orp_threads'(W) :-
|
2010-04-20 03:59:48 +01:00
|
|
|
thread_create('$c_worker',_,[detached(true)]),
|
2010-01-14 15:58:19 +00:00
|
|
|
W1 is W-1,
|
|
|
|
'$start_orp_threads'(W1).
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
% Start file for yap
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
/* I/O predicates */
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
/* meaning of flags for '$write' is
|
2006-01-02 02:16:19 +00:00
|
|
|
1 quote illegal atoms
|
|
|
|
2 ignore operator declarations
|
|
|
|
4 output '$VAR'(N) terms as A, B, C, ...
|
|
|
|
8 use portray(_)
|
2007-10-21 09:48:06 +01:00
|
|
|
*/
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
/* main execution loop */
|
2011-07-26 23:32:50 +01:00
|
|
|
'$read_toplevel'(Goal, Bindings) :-
|
2012-12-14 23:30:48 +00:00
|
|
|
'$pred_exists'(read_history(_,_,_,_,_,_), user),
|
2011-07-26 23:32:50 +01:00
|
|
|
'$swi_current_prolog_flag'(readline, true), !,
|
2011-02-23 17:46:50 +00:00
|
|
|
read_history(h, '!h',
|
|
|
|
[trace, end_of_file],
|
2011-05-01 22:43:54 +01:00
|
|
|
Prompt, Goal, Bindings), !,
|
2011-02-23 17:46:50 +00:00
|
|
|
(nonvar(Err) ->
|
|
|
|
print_message(error,Err), fail
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
2011-07-26 23:32:50 +01:00
|
|
|
'$read_toplevel'(Goal, Bindings) :-
|
2011-09-01 05:10:49 +01:00
|
|
|
prompt1('?- '),
|
|
|
|
prompt(_,'|: '),
|
2011-07-26 23:32:50 +01:00
|
|
|
'$system_catch'('$raw_read'(user_input, Line), prolog, E,
|
2012-09-21 11:49:59 +01:00
|
|
|
(print_message(error, E),
|
2013-02-26 15:32:39 +00:00
|
|
|
'$handle_toplevel_error'(Line, E))),
|
2012-09-21 11:49:59 +01:00
|
|
|
(
|
|
|
|
current_predicate(_, user:rl_add_history(_))
|
|
|
|
->
|
|
|
|
format(atom(CompleteLine), '~W~W',
|
2011-07-26 23:32:50 +01:00
|
|
|
[ Line, [partial(true)],
|
|
|
|
'.', [partial(true)]
|
|
|
|
]),
|
|
|
|
call(user:rl_add_history(CompleteLine))
|
2012-09-21 11:49:59 +01:00
|
|
|
;
|
|
|
|
true
|
2011-07-26 23:32:50 +01:00
|
|
|
),
|
2012-09-21 11:49:59 +01:00
|
|
|
'$system_catch'(
|
|
|
|
atom_to_term(Line, Goal, Bindings), prolog, E,
|
|
|
|
( print_message(error, E),
|
|
|
|
fail
|
|
|
|
)
|
|
|
|
), !.
|
2011-07-26 23:32:50 +01:00
|
|
|
|
2013-02-26 15:32:39 +00:00
|
|
|
'$handle_toplevel_error'(_, syntax_error(_)) :- !, fail.
|
|
|
|
'$handle_toplevel_error'(end_of_file, error(io_error(read,user_input),_)) :- !.
|
|
|
|
'$handle_toplevel_error'(_, E) :-
|
|
|
|
throw(E).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
% reset alarms when entering top-level.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
'$alarm'(0, 0, _, _),
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
'$clean_up_dead_clauses',
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
2013-11-15 15:45:55 +00:00
|
|
|
'$swi_current_prolog_flag'(break_level, BreakLevel),
|
2013-10-31 13:16:27 +00:00
|
|
|
'$swi_current_prolog_flag'(debug, DBON),
|
2007-10-21 09:48:06 +01:00
|
|
|
(
|
2010-03-01 22:32:40 +00:00
|
|
|
'$nb_getval'('$trace', on, fail)
|
2007-10-21 09:48:06 +01:00
|
|
|
->
|
|
|
|
TraceDebug = trace
|
|
|
|
;
|
2008-09-02 03:48:02 +01:00
|
|
|
DBON == true
|
2007-10-21 09:48:06 +01:00
|
|
|
->
|
|
|
|
TraceDebug = debug
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(informational,prompt(BreakLevel,TraceDebug)),
|
2007-10-21 09:48:06 +01:00
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
get_value('$top_level_goal',GA), GA \= [], !,
|
|
|
|
set_value('$top_level_goal',[]),
|
|
|
|
'$run_atom_goal'(GA),
|
2013-11-15 15:45:55 +00:00
|
|
|
'$swi_current_prolog_flag'(break_level, BreakLevel),
|
|
|
|
( Breaklevel \= 0 -> true ; '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
|
2007-10-21 09:48:06 +01:00
|
|
|
'$enter_top_level' :-
|
|
|
|
'$run_toplevel_hooks',
|
2011-07-27 16:49:43 +01:00
|
|
|
prompt1(' ?- '),
|
2011-07-26 23:32:50 +01:00
|
|
|
'$read_toplevel'(Command,Varnames),
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$spy_gn',1),
|
2011-07-27 16:49:43 +01:00
|
|
|
% stop at spy-points if debugging is on.
|
2007-10-21 09:48:06 +01:00
|
|
|
nb_setval('$debug_run',off),
|
2010-04-08 01:44:08 +01:00
|
|
|
nb_setval('$debug_jump',off),
|
2011-07-26 23:32:50 +01:00
|
|
|
'$command'(Command,Varnames,_Pos,top),
|
2013-11-15 15:45:55 +00:00
|
|
|
'$swi_current_prolog_flag'(break_level, BreakLevel),
|
2013-07-22 16:52:49 +01:00
|
|
|
( BreakLevel \= 0 -> true ; '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2006-02-08 17:29:55 +00:00
|
|
|
|
2006-01-02 02:16:19 +00:00
|
|
|
'$erase_sets' :-
|
|
|
|
eraseall('$'),
|
|
|
|
eraseall('$$set'),
|
|
|
|
eraseall('$$one'),
|
|
|
|
eraseall('$reconsulted'), fail.
|
|
|
|
'$erase_sets' :- \+ recorded('$path',_,_), recorda('$path',"",_).
|
|
|
|
'$erase_sets'.
|
|
|
|
|
|
|
|
'$version' :-
|
|
|
|
get_value('$version_name',VersionName),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(help, version(VersionName)),
|
2006-05-22 17:12:01 +01:00
|
|
|
get_value('$myddas_version_name',MYDDASVersionName),
|
|
|
|
MYDDASVersionName \== [],
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(help, myddas_version(MYDDASVersionName)),
|
2006-01-02 02:16:19 +00:00
|
|
|
fail.
|
2009-05-24 21:16:40 +01:00
|
|
|
'$version' :-
|
|
|
|
recorded('$version',VersionName,_),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(help, VersionName),
|
2006-01-02 02:16:19 +00:00
|
|
|
fail.
|
|
|
|
'$version'.
|
|
|
|
|
|
|
|
repeat :- '$repeat'.
|
|
|
|
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat' :- '$repeat'.
|
|
|
|
|
2007-10-21 09:48:06 +01:00
|
|
|
'$start_corouts' :-
|
|
|
|
recorded('$corout','$corout'(Name,_,_),R),
|
|
|
|
Name \= main,
|
|
|
|
finish_corout(R),
|
|
|
|
fail.
|
|
|
|
'$start_corouts' :-
|
|
|
|
eraseall('$corout'),
|
|
|
|
eraseall('$result'),
|
|
|
|
eraseall('$actual'),
|
|
|
|
fail.
|
|
|
|
'$start_corouts' :- recorda('$actual',main,_),
|
|
|
|
recordz('$corout','$corout'(main,main,'$corout'([],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[])),_Ref),
|
|
|
|
recorda('$result',going,_).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2008-10-23 22:17:45 +01:00
|
|
|
'$command'(C,VL,Pos,Con) :-
|
2007-10-21 09:48:06 +01:00
|
|
|
'$access_yap_flags'(9,1), !,
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(C,VL,Pos,Con,C).
|
|
|
|
'$command'(C,VL,Pos,Con) :-
|
2007-10-21 09:48:06 +01:00
|
|
|
( (Con = top ; var(C) ; C = [_|_]) ->
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(C,VL,Pos,Con,C), ! ;
|
2008-08-06 11:15:48 +01:00
|
|
|
% do term expansion
|
2007-10-21 09:48:06 +01:00
|
|
|
expand_term(C, EC),
|
2008-08-06 11:15:48 +01:00
|
|
|
% execute a list of commands
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_commands'(EC,VL,Pos,Con,C),
|
2008-08-06 11:15:48 +01:00
|
|
|
% succeed only if the *original* was at end of file.
|
|
|
|
C == end_of_file
|
2007-10-21 09:48:06 +01:00
|
|
|
).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% Hack in case expand_term has created a list of commands.
|
|
|
|
%
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_commands'(V,_,_,_,Source) :- var(V), !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$do_error'(instantiation_error,meta_call(Source)).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_commands'([],_,_,_,_) :- !.
|
|
|
|
'$execute_commands'([C|Cs],VL,Pos,Con,Source) :- !,
|
2006-01-02 02:16:19 +00:00
|
|
|
(
|
2011-11-10 12:27:36 +00:00
|
|
|
'$system_catch'('$execute_command'(C,VL,Pos,Con,C),prolog,Error,user:'$LoopError'(Error, Con)),
|
2008-07-11 18:02:10 +01:00
|
|
|
fail
|
2006-01-02 02:16:19 +00:00
|
|
|
;
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_commands'(Cs,VL,Pos,Con,Source)
|
2008-08-06 01:56:11 +01:00
|
|
|
).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_commands'(C,VL,Pos,Con,Source) :-
|
|
|
|
'$execute_command'(C,VL,Pos,Con,Source).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2008-08-12 02:27:23 +01:00
|
|
|
%
|
2006-01-02 02:16:19 +00:00
|
|
|
%
|
|
|
|
%
|
|
|
|
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(C,_,_,top,Source) :- var(C), !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$do_error'(instantiation_error,meta_call(Source)).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(C,_,_,top,Source) :- number(C), !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$do_error'(type_error(callable,C),meta_call(Source)).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(R,_,_,top,Source) :- db_reference(R), !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$do_error'(type_error(callable,R),meta_call(Source)).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$execute_command'(end_of_file,_,_,_,_) :- !.
|
|
|
|
'$execute_command'(Command,_,_,_,_) :-
|
2010-03-01 22:32:40 +00:00
|
|
|
'$nb_getval'('$if_skip_mode', skip, fail),
|
2007-10-21 09:48:06 +01:00
|
|
|
\+ '$if_directive'(Command),
|
2008-08-06 11:15:48 +01:00
|
|
|
!.
|
2011-03-11 19:49:32 +00:00
|
|
|
'$execute_command'((:-G),VL,Pos,Option,_) :-
|
|
|
|
% !,
|
2010-05-25 16:15:09 +01:00
|
|
|
Option \= top, !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$current_module'(M),
|
2007-10-10 10:44:28 +01:00
|
|
|
% allow user expansion
|
2007-10-17 00:17:04 +01:00
|
|
|
expand_term((:- G), O),
|
2011-03-11 19:49:32 +00:00
|
|
|
(
|
|
|
|
O = (:- G1)
|
|
|
|
->
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(G1, Option, M, VL, Pos)
|
2011-03-11 19:49:32 +00:00
|
|
|
;
|
|
|
|
'$execute_commands'(O,VL,Pos,Option,O)
|
|
|
|
).
|
2010-05-25 16:15:09 +01:00
|
|
|
'$execute_command'((?-G), V, Pos, Option, Source) :-
|
|
|
|
Option \= top, !,
|
|
|
|
'$execute_command'(G, V, Pos, top, Source).
|
|
|
|
'$execute_command'(G, V, Pos, Option, Source) :-
|
|
|
|
'$continue_with_command'(Option, V, Pos, G, Source).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% This command is very different depending on the language mode we are in.
|
|
|
|
%
|
|
|
|
% ISO only wants directives in files
|
|
|
|
% SICStus accepts everything in files
|
|
|
|
% YAP accepts everything everywhere
|
|
|
|
%
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(G, top, M, VL, Pos) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
'$access_yap_flags'(8, 0), !, % YAP mode, go in and do it,
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(G, consult, M, VL, Pos).
|
|
|
|
'$process_directive'(G, top, _, _, _) :- !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$do_error'(context_error((:- G),clause),query).
|
|
|
|
%
|
|
|
|
% allow modules
|
|
|
|
%
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(M:G, Mode, _, VL, Pos) :- !,
|
|
|
|
'$process_directive'(G, Mode, M, VL, Pos).
|
2006-01-02 02:16:19 +00:00
|
|
|
%
|
|
|
|
% default case
|
|
|
|
%
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(Gs, Mode, M, VL, Pos) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
'$all_directives'(Gs), !,
|
2012-02-13 09:39:29 +00:00
|
|
|
'$exec_directives'(Gs, Mode, M, VL, Pos).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% ISO does not allow goals (use initialization).
|
|
|
|
%
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(D, _, M, VL, Pos) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
'$access_yap_flags'(8, 1), !, % ISO Prolog mode, go in and do it,
|
|
|
|
'$do_error'(context_error((:- M:D),query),directive).
|
|
|
|
%
|
|
|
|
% but YAP and SICStus does.
|
|
|
|
%
|
2012-02-13 09:39:29 +00:00
|
|
|
'$process_directive'(G, _, M, VL, Pos) :-
|
2013-02-08 16:36:45 +00:00
|
|
|
( '$execute'(M:G) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2010-03-14 09:30:24 +00:00
|
|
|
'$continue_with_command'(Where,V,'$stream_position'(C,_P,A1,A2,A3),'$source_location'(_F,L):G,Source) :- !,
|
|
|
|
'$continue_with_command'(Where,V,'$stream_position'(C,L,A1,A2,A3),G,Source).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$continue_with_command'(reconsult,V,Pos,G,Source) :-
|
|
|
|
'$go_compile_clause'(G,V,Pos,5,Source),
|
2006-01-02 02:16:19 +00:00
|
|
|
fail.
|
2008-10-23 22:17:45 +01:00
|
|
|
'$continue_with_command'(consult,V,Pos,G,Source) :-
|
|
|
|
'$go_compile_clause'(G,V,Pos,13,Source),
|
2006-01-02 02:16:19 +00:00
|
|
|
fail.
|
2008-10-23 22:17:45 +01:00
|
|
|
'$continue_with_command'(top,V,_,G,_) :-
|
2006-12-13 16:10:26 +00:00
|
|
|
'$query'(G,V).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% not 100% compatible with SICStus Prolog, as SICStus Prolog would put
|
|
|
|
% module prefixes all over the place, although unnecessarily so.
|
|
|
|
%
|
2008-10-23 22:17:45 +01:00
|
|
|
'$go_compile_clause'(G,V,Pos,N,Source) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
'$current_module'(Mod),
|
2008-10-23 22:17:45 +01:00
|
|
|
'$go_compile_clause'(G,V,Pos,N,Mod,Mod,Source).
|
2008-07-23 00:34:50 +01:00
|
|
|
|
2009-11-20 00:32:14 +00:00
|
|
|
'$go_compile_clause'(G,_,_,_,_,_,Source) :-
|
|
|
|
var(G), !,
|
|
|
|
'$do_error'(instantiation_error,assert(Source)).
|
|
|
|
'$go_compile_clause'((G:-_),_,_,_,_,_,Source) :-
|
|
|
|
var(G), !,
|
|
|
|
'$do_error'(instantiation_error,assert(Source)).
|
2008-10-23 22:17:45 +01:00
|
|
|
'$go_compile_clause'(M:G,V,Pos,N,_,_,Source) :- !,
|
|
|
|
'$go_compile_clause'(G,V,Pos,N,M,M,Source).
|
|
|
|
'$go_compile_clause'((M:H :- B),V,Pos,N,_,BodyMod,Source) :- !,
|
|
|
|
'$go_compile_clause'((H :- B),V,Pos,N,M,BodyMod,Source).
|
|
|
|
'$go_compile_clause'(G,V,Pos,N,HeadMod,BodyMod,Source) :- !,
|
|
|
|
'$prepare_term'(G, V, Pos, G0, G1, BodyMod, HeadMod, Source),
|
2008-07-23 00:34:50 +01:00
|
|
|
'$$compile'(G1, G0, N, HeadMod).
|
|
|
|
|
2008-10-23 22:17:45 +01:00
|
|
|
'$prepare_term'(G, V, Pos, G0, G1, BodyMod, SourceMod, Source) :-
|
2010-12-12 19:19:49 +00:00
|
|
|
(
|
|
|
|
get_value('$syntaxcheckflag',on)
|
|
|
|
->
|
2013-01-18 14:32:13 +00:00
|
|
|
'$check_term'(Source, G, V, Pos, BodyMod)
|
2010-12-12 19:19:49 +00:00
|
|
|
;
|
|
|
|
true
|
2010-12-13 19:13:33 +00:00
|
|
|
),
|
|
|
|
'$precompile_term'(G, G0, G1, BodyMod, SourceMod).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
% process an input clause
|
|
|
|
'$$compile'(G, G0, L, Mod) :-
|
2008-05-15 14:41:48 +01:00
|
|
|
'$head_and_body'(G,H,_),
|
2006-01-02 02:16:19 +00:00
|
|
|
'$flags'(H, Mod, Fl, Fl),
|
|
|
|
is(NFl, /\, Fl, 0x00002000),
|
2007-11-08 11:22:05 +00:00
|
|
|
(
|
|
|
|
NFl \= 0
|
|
|
|
->
|
|
|
|
'$assertz_dynamic'(L,G,G0,Mod)
|
|
|
|
;
|
2012-12-07 08:08:32 +00:00
|
|
|
'$nb_getval'('$assert_all',on,fail)
|
2007-11-08 11:22:05 +00:00
|
|
|
->
|
2008-04-01 21:47:57 +01:00
|
|
|
functor(H,N,A),
|
2007-11-08 11:22:05 +00:00
|
|
|
'$dynamic'(N/A,Mod),
|
|
|
|
'$assertz_dynamic'(L,G,G0,Mod)
|
|
|
|
;
|
2008-05-15 14:41:48 +01:00
|
|
|
'$not_imported'(H, Mod),
|
2007-11-08 11:22:05 +00:00
|
|
|
'$compile'(G, L, G0, Mod)
|
|
|
|
).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2012-03-28 14:35:09 +01:00
|
|
|
%
|
|
|
|
% check if current module redefines an imported predicate.
|
|
|
|
% and remove import.
|
|
|
|
%
|
2008-05-15 14:41:48 +01:00
|
|
|
'$not_imported'(H, Mod) :-
|
2012-03-28 14:35:09 +01:00
|
|
|
recorded('$import','$import'(NM,Mod,NH,H,_,_),R),
|
|
|
|
NM \= Mod,
|
2008-05-15 14:41:48 +01:00
|
|
|
functor(NH,N,Ar),
|
2012-03-28 14:35:09 +01:00
|
|
|
print_message(warning,redefine_imported(Mod,NM,N/Ar)),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
2008-05-15 14:41:48 +01:00
|
|
|
'$not_imported'(_, _).
|
|
|
|
|
2009-09-20 16:03:10 +01:00
|
|
|
|
|
|
|
'$check_if_reconsulted'(N,A) :-
|
|
|
|
once(recorded('$reconsulted',N/A,_)),
|
|
|
|
recorded('$reconsulted',X,_),
|
|
|
|
( X = N/A , !;
|
|
|
|
X = '$', !, fail;
|
|
|
|
fail
|
|
|
|
).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2008-05-15 14:41:48 +01:00
|
|
|
'$inform_as_reconsulted'(N,A) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
recorda('$reconsulted',N/A,_).
|
|
|
|
|
2008-05-15 14:41:48 +01:00
|
|
|
'$clear_reconsulting' :-
|
|
|
|
recorded('$reconsulted',X,Ref),
|
|
|
|
erase(Ref),
|
|
|
|
X == '$', !,
|
|
|
|
( recorded('$reconsulting',_,R) -> erase(R) ).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2010-12-31 05:20:49 +00:00
|
|
|
'$prompt_alternatives_on'(determinism).
|
2010-02-28 00:05:38 +00:00
|
|
|
|
|
|
|
/* Executing a query */
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2008-05-15 14:41:48 +01:00
|
|
|
'$query'(end_of_file,_).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2010-03-27 11:34:10 +00:00
|
|
|
'$query'(G,[]) :-
|
2011-01-06 17:20:29 +00:00
|
|
|
'$prompt_alternatives_on'(OPT),
|
|
|
|
( OPT = groundness ; OPT = determinism), !,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$yes_no'(G,(?-)).
|
2010-03-27 11:34:10 +00:00
|
|
|
'$query'(G,V) :-
|
2006-01-02 02:16:19 +00:00
|
|
|
(
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(CP),
|
2013-02-08 16:36:45 +00:00
|
|
|
'$current_module'(M),
|
2013-12-13 08:42:57 +00:00
|
|
|
'$user_call'(G, M),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(NCP),
|
2012-06-08 13:26:11 +01:00
|
|
|
'$delayed_goals'(G, V, NV, LGs, DCP),
|
2010-03-27 11:34:10 +00:00
|
|
|
'$write_answer'(NV, LGs, Written),
|
2010-02-28 00:05:38 +00:00
|
|
|
'$write_query_answer_true'(Written),
|
|
|
|
(
|
2013-02-15 16:31:49 +00:00
|
|
|
'$prompt_alternatives_on'(determinism), CP == NCP, DCP = 0
|
2013-02-12 18:47:30 +00:00
|
|
|
->
|
|
|
|
format(user_error, '.~n', []),
|
2010-02-28 00:05:38 +00:00
|
|
|
!
|
|
|
|
;
|
2006-12-13 16:10:26 +00:00
|
|
|
'$another',
|
2010-02-28 00:05:38 +00:00
|
|
|
!
|
|
|
|
),
|
|
|
|
fail
|
2006-12-13 16:10:26 +00:00
|
|
|
;
|
2010-02-28 00:05:38 +00:00
|
|
|
'$out_neg_answer'
|
2006-01-02 02:16:19 +00:00
|
|
|
).
|
|
|
|
|
|
|
|
'$yes_no'(G,C) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$do_yes_no'(G,M),
|
2012-06-08 13:26:11 +01:00
|
|
|
'$delayed_goals'(G, [], NV, LGs, _),
|
2010-03-27 11:34:10 +00:00
|
|
|
'$write_answer'(NV, LGs, Written),
|
2006-01-02 02:16:19 +00:00
|
|
|
( Written = [] ->
|
2013-02-12 18:47:30 +00:00
|
|
|
!,'$present_answer'(C, true)
|
2013-02-08 16:36:45 +00:00
|
|
|
;
|
2013-02-12 18:47:30 +00:00
|
|
|
'$another', !
|
2006-01-02 02:16:19 +00:00
|
|
|
),
|
|
|
|
fail.
|
|
|
|
'$yes_no'(_,_) :-
|
2008-05-15 19:31:02 +01:00
|
|
|
'$out_neg_answer'.
|
2006-12-13 16:10:26 +00:00
|
|
|
|
|
|
|
'$add_env_and_fail' :- fail.
|
|
|
|
|
2012-06-21 15:41:35 +01:00
|
|
|
%
|
|
|
|
% *-> at this point would require compiler support, which does not exist.
|
|
|
|
%
|
2012-06-08 13:26:11 +01:00
|
|
|
'$delayed_goals'(G, V, NV, LGs, NCP) :-
|
2012-08-08 00:32:45 +01:00
|
|
|
(
|
|
|
|
CP is '$last_choice_pt',
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(NCP1),
|
2012-06-08 13:26:11 +01:00
|
|
|
'$attributes':delayed_goals(G, V, NV, LGs),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(NCP2),
|
2012-12-02 13:18:29 +00:00
|
|
|
'$clean_ifcp'(CP),
|
2012-08-08 00:32:45 +01:00
|
|
|
NCP is NCP2-NCP1
|
|
|
|
;
|
|
|
|
copy_term_nat(V, NV),
|
|
|
|
LGs = [],
|
|
|
|
NCP = 0
|
2012-06-04 16:29:56 +01:00
|
|
|
).
|
2010-03-27 11:34:10 +00:00
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
'$out_neg_answer' :-
|
2008-02-22 15:08:37 +00:00
|
|
|
( '$undefined'(print_message(_,_),prolog) ->
|
2013-02-12 18:47:30 +00:00
|
|
|
'$present_answer'(user_error,'false.~n', [])
|
2006-01-02 02:16:19 +00:00
|
|
|
;
|
2013-02-12 18:47:30 +00:00
|
|
|
print_message(help,false)
|
2006-01-02 02:16:19 +00:00
|
|
|
),
|
|
|
|
fail.
|
|
|
|
|
2013-02-08 16:36:45 +00:00
|
|
|
'$do_yes_no'([X|L], M) :-
|
|
|
|
!,
|
|
|
|
'$csult'([X|L], M).
|
2009-05-05 00:10:07 +01:00
|
|
|
'$do_yes_no'(G, M) :-
|
2013-12-13 08:42:57 +00:00
|
|
|
'$user_call'(G, M).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2009-05-05 00:10:07 +01:00
|
|
|
'$write_query_answer_true'([]) :- !,
|
2013-02-12 18:47:30 +00:00
|
|
|
format(user_error,'true',[]).
|
2009-05-05 00:10:07 +01:00
|
|
|
'$write_query_answer_true'(_).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%
|
|
|
|
% present_answer has three components. First it flushes the streams,
|
|
|
|
% then it presents the goals, and last it shows any goals frozen on
|
|
|
|
% the arguments.
|
|
|
|
%
|
|
|
|
'$present_answer'(_,_):-
|
2011-02-14 19:28:44 +00:00
|
|
|
flush_output,
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
'$present_answer'((?-), Answ) :-
|
2013-11-15 15:45:55 +00:00
|
|
|
'$swi_current_prolog_flag'(break_level, BL ),
|
2004-07-22 22:32:23 +01:00
|
|
|
( BL \= 0 -> format(user_error, '[~p] ',[BL]) ;
|
2001-04-09 20:54:03 +01:00
|
|
|
true ),
|
2003-08-27 14:37:10 +01:00
|
|
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
write_term(user_error,Answ,Opts) ;
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'~w',[Answ])
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2013-02-12 18:47:30 +00:00
|
|
|
format(user_error,'.~n', []).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$another' :-
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,' ? ',[]),
|
2008-03-12 15:37:34 +00:00
|
|
|
get0(user_input,C),
|
2010-02-11 18:06:27 +00:00
|
|
|
'$do_another'(C).
|
|
|
|
|
|
|
|
'$do_another'(C) :-
|
2011-02-14 20:47:34 +00:00
|
|
|
( C== 0'; -> skip(user_input,10), %'
|
2013-02-12 18:47:30 +00:00
|
|
|
% '$add_nl_outside_console',
|
2003-02-24 11:01:01 +00:00
|
|
|
fail
|
2002-05-24 06:14:46 +01:00
|
|
|
;
|
2003-02-24 11:01:01 +00:00
|
|
|
C== 10 -> '$add_nl_outside_console',
|
2008-02-22 15:08:37 +00:00
|
|
|
( '$undefined'(print_message(_,_),prolog) ->
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'yes~n', [])
|
2003-12-01 17:27:42 +00:00
|
|
|
;
|
|
|
|
print_message(help,yes)
|
|
|
|
)
|
2010-02-11 18:06:27 +00:00
|
|
|
;
|
|
|
|
C== 13 ->
|
|
|
|
get0(user_input,NC),
|
|
|
|
'$do_another'(NC)
|
2002-05-24 06:14:46 +01:00
|
|
|
;
|
|
|
|
C== -1 -> halt
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2011-02-14 20:47:34 +00:00
|
|
|
skip(user_input,10), '$ask_again_for_another'
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
|
|
|
|
2011-02-14 19:28:44 +00:00
|
|
|
%'$add_nl_outside_console' :-
|
|
|
|
% '$is_same_tty'(user_input, user_error), !.
|
2003-02-24 11:01:01 +00:00
|
|
|
'$add_nl_outside_console' :-
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'~n',[]).
|
2003-02-24 11:01:01 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ask_again_for_another' :-
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'Action (\";\" for more choices, <return> for exit)', []),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$another'.
|
|
|
|
|
|
|
|
'$write_answer'(_,_,_) :-
|
2011-02-14 19:28:44 +00:00
|
|
|
flush_output,
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
2005-10-28 18:38:50 +01:00
|
|
|
'$write_answer'(Vs, LBlk, FLAnsw) :-
|
2003-02-24 11:01:01 +00:00
|
|
|
'$purge_dontcares'(Vs,IVs),
|
|
|
|
'$sort'(IVs, NVs),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$prep_answer_var_by_var'(NVs, LAnsw, LBlk),
|
|
|
|
'$name_vars_in_goals'(LAnsw, Vs, NLAnsw),
|
2006-05-24 03:35:39 +01:00
|
|
|
'$write_vars_and_goals'(NLAnsw, first, FLAnsw).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$purge_dontcares'([],[]).
|
2012-10-09 16:31:43 +01:00
|
|
|
'$purge_dontcares'([Name=_|Vs],NVs) :-
|
|
|
|
atom_codes(Name, [C|_]), C is "_", !,
|
2001-04-09 20:54:03 +01:00
|
|
|
'$purge_dontcares'(Vs,NVs).
|
|
|
|
'$purge_dontcares'([V|Vs],[V|NVs]) :-
|
|
|
|
'$purge_dontcares'(Vs,NVs).
|
|
|
|
|
|
|
|
|
|
|
|
'$prep_answer_var_by_var'([], L, L).
|
2012-10-09 16:31:43 +01:00
|
|
|
'$prep_answer_var_by_var'([Name=Value|L], LF, L0) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$delete_identical_answers'(L, Value, NL, Names),
|
|
|
|
'$prep_answer_var'([Name|Names], Value, LF, LI),
|
|
|
|
'$prep_answer_var_by_var'(NL, LI, L0).
|
|
|
|
|
|
|
|
% fetch all cases that have the same solution.
|
|
|
|
'$delete_identical_answers'([], _, [], []).
|
2012-10-09 16:31:43 +01:00
|
|
|
'$delete_identical_answers'([(Name=Value)|L], Value0, FL, [Name|Names]) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
Value == Value0, !,
|
|
|
|
'$delete_identical_answers'(L, Value0, FL, Names).
|
|
|
|
'$delete_identical_answers'([VV|L], Value0, [VV|FL], Names) :-
|
|
|
|
'$delete_identical_answers'(L, Value0, FL, Names).
|
|
|
|
|
|
|
|
% now create a list of pairs that will look like goals.
|
|
|
|
'$prep_answer_var'(Names, Value, LF, L0) :- var(Value), !,
|
|
|
|
'$prep_answer_unbound_var'(Names, LF, L0).
|
|
|
|
'$prep_answer_var'(Names, Value, [nonvar(Names,Value)|L0], L0).
|
|
|
|
|
|
|
|
% ignore unbound variables
|
|
|
|
'$prep_answer_unbound_var'([_], L, L) :- !.
|
|
|
|
'$prep_answer_unbound_var'(Names, [var(Names)|L0], L0).
|
|
|
|
|
|
|
|
'$gen_name_string'(I,L,[C|L]) :- I < 26, !, C is I+65.
|
|
|
|
'$gen_name_string'(I,L0,LF) :-
|
|
|
|
I1 is I mod 26,
|
|
|
|
I2 is I // 26,
|
|
|
|
C is I1+65,
|
|
|
|
'$gen_name_string'(I2,[C|L0],LF).
|
|
|
|
|
2006-05-24 03:35:39 +01:00
|
|
|
'$write_vars_and_goals'([], _, []).
|
|
|
|
'$write_vars_and_goals'([nl,G1|LG], First, NG) :- !,
|
2005-10-18 18:04:43 +01:00
|
|
|
nl(user_error),
|
2006-05-24 03:35:39 +01:00
|
|
|
'$write_goal_output'(G1, First, NG, Next, IG),
|
|
|
|
'$write_vars_and_goals'(LG, Next, IG).
|
|
|
|
'$write_vars_and_goals'([G1|LG], First, NG) :-
|
|
|
|
'$write_goal_output'(G1, First, NG, Next, IG),
|
|
|
|
'$write_vars_and_goals'(LG, Next, IG).
|
|
|
|
|
2011-02-12 18:42:44 +00:00
|
|
|
'$goal_to_string'(Format, G, String) :-
|
|
|
|
format(codes(String),Format,G).
|
2006-05-24 03:35:39 +01:00
|
|
|
|
2009-09-10 00:00:35 +01:00
|
|
|
'$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :- !,
|
2006-05-24 03:35:39 +01:00
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
2012-10-09 16:31:43 +01:00
|
|
|
format(user_error,'~a',[V]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$write_output_vars'(VL).
|
2009-09-10 00:00:35 +01:00
|
|
|
'$write_goal_output'(nonvar([V|VL],B), First, [nonvar([V|VL],B)|L], next, L) :- !,
|
2006-05-24 03:35:39 +01:00
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
2012-10-09 16:31:43 +01:00
|
|
|
format(user_error,'~a',[V]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$write_output_vars'(VL),
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,' = ', []),
|
2003-08-27 14:37:10 +01:00
|
|
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
2009-05-22 19:24:27 +01:00
|
|
|
write_term(user_error,B,[priority(699)|Opts]) ;
|
|
|
|
write_term(user_error,B,[priority(699)])
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2008-03-13 17:16:47 +00:00
|
|
|
'$write_goal_output'(nl, First, NG, First, NG) :- !,
|
|
|
|
format(user_error,'~n',[]).
|
2009-09-10 00:00:35 +01:00
|
|
|
'$write_goal_output'(Format-G, First, NG, Next, IG) :- !,
|
2005-10-18 18:04:43 +01:00
|
|
|
G = [_|_], !,
|
2006-05-24 03:35:39 +01:00
|
|
|
% dump on string first so that we can check whether we actually
|
|
|
|
% had any output from the solver.
|
|
|
|
'$goal_to_string'(Format, G, String),
|
|
|
|
( String == [] ->
|
|
|
|
% we didn't
|
|
|
|
IG = NG, First = Next
|
|
|
|
;
|
|
|
|
% we did
|
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
|
|
|
format(user_error, '~s', [String]),
|
|
|
|
NG = [G|IG]
|
|
|
|
).
|
2009-09-10 00:00:35 +01:00
|
|
|
'$write_goal_output'(_-G, First, [G|NG], next, NG) :- !,
|
2006-05-24 03:35:39 +01:00
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
2003-08-27 14:37:10 +01:00
|
|
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
write_term(user_error,G,Opts) ;
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'~w',[G])
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2009-09-10 00:00:35 +01:00
|
|
|
'$write_goal_output'(_M:G, First, [G|NG], next, NG) :- !,
|
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
|
|
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
|
|
|
write_term(user_error,G,Opts) ;
|
|
|
|
format(user_error,'~w',[G])
|
|
|
|
).
|
|
|
|
'$write_goal_output'(G, First, [M:G|NG], next, NG) :-
|
|
|
|
'$current_module'(M),
|
2009-04-25 18:54:21 +01:00
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
|
|
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
|
|
|
write_term(user_error,G,Opts) ;
|
|
|
|
format(user_error,'~w',[G])
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2010-03-27 11:34:10 +00:00
|
|
|
'$name_vars_in_goals'(G, VL0, G) :-
|
|
|
|
'$name_well_known_vars'(VL0),
|
|
|
|
'$variables_in_term'(G, [], GVL),
|
|
|
|
'$name_vars_in_goals1'(GVL, 0, _).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$name_well_known_vars'([]).
|
2012-12-02 13:18:29 +00:00
|
|
|
'$name_well_known_vars'([Name=V|NVL0]) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
var(V), !,
|
|
|
|
V = '$VAR'(Name),
|
|
|
|
'$name_well_known_vars'(NVL0).
|
|
|
|
'$name_well_known_vars'([_|NVL0]) :-
|
|
|
|
'$name_well_known_vars'(NVL0).
|
|
|
|
|
|
|
|
'$name_vars_in_goals1'([], I, I).
|
2011-03-18 19:34:19 +00:00
|
|
|
'$name_vars_in_goals1'(['$VAR'(Name)|NGVL], I0, IF) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
I is I0+1,
|
2011-03-18 19:34:19 +00:00
|
|
|
'$gen_name_string'(I0,[],SName), !,
|
|
|
|
atom_codes(Name, [95|SName]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$name_vars_in_goals1'(NGVL, I, IF).
|
|
|
|
'$name_vars_in_goals1'([NV|NGVL], I0, IF) :-
|
|
|
|
nonvar(NV),
|
2002-01-02 16:55:24 +00:00
|
|
|
'$name_vars_in_goals1'(NGVL, I0, IF).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$write_output_vars'([]).
|
|
|
|
'$write_output_vars'([V|VL]) :-
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,' = ~s',[V]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$write_output_vars'(VL).
|
|
|
|
|
|
|
|
call(G) :- '$execute'(G).
|
|
|
|
|
|
|
|
incore(G) :- '$execute'(G).
|
|
|
|
|
|
|
|
%
|
|
|
|
% standard meta-call, called if $execute could not do everything.
|
|
|
|
%
|
2001-11-15 00:01:43 +00:00
|
|
|
'$meta_call'(G, M) :-
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(CP),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(G, CP, G, M).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2013-12-13 08:42:57 +00:00
|
|
|
'$user_call'(G, M) :-
|
|
|
|
( '$$save_by'(CP1),
|
|
|
|
'$enable_debugging',
|
|
|
|
'$call'(G, CP, M:G, M),
|
|
|
|
'$$save_by'(CP2),
|
|
|
|
(CP1 == CP2 -> ! ; ( true ; '$enable_debugging', fail ) ),
|
|
|
|
'$disable_debugging'
|
|
|
|
;
|
|
|
|
'$disable_debugging',
|
|
|
|
fail
|
|
|
|
).
|
|
|
|
|
|
|
|
'$enable_debugging' :-
|
|
|
|
'$swi_current_prolog_flag'(debug, false), !.
|
|
|
|
'$enable_debugging' :-
|
|
|
|
'$nb_getval'('$trace', on, fail), !,
|
|
|
|
'$creep'.
|
|
|
|
'$enable_debugging'.
|
|
|
|
|
|
|
|
'$disable_debugging' :-
|
|
|
|
'$stop_creeping'.
|
|
|
|
|
2004-11-22 16:22:14 +00:00
|
|
|
|
|
|
|
','(X,Y) :-
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks:env_choice_point(CP),
|
2004-11-22 16:22:14 +00:00
|
|
|
'$current_module'(M),
|
2004-11-22 16:31:33 +00:00
|
|
|
'$call'(X,CP,(X,Y),M),
|
|
|
|
'$call'(Y,CP,(X,Y),M).
|
2008-02-12 17:03:59 +00:00
|
|
|
';'((X->A),Y) :- !,
|
|
|
|
yap_hacks:env_choice_point(CP),
|
|
|
|
'$current_module'(M),
|
|
|
|
( '$execute'(X)
|
|
|
|
->
|
|
|
|
'$call'(A,CP,(X->A;Y),M)
|
|
|
|
;
|
|
|
|
'$call'(Y,CP,(X->A;Y),M)
|
|
|
|
).
|
|
|
|
';'((X*->A),Y) :- !,
|
|
|
|
yap_hacks:env_choice_point(CP),
|
|
|
|
'$current_module'(M),
|
|
|
|
(
|
2013-02-15 19:40:05 +00:00
|
|
|
yap_hacks:current_choice_point(DCP),
|
2008-02-12 17:03:59 +00:00
|
|
|
'$execute'(X),
|
|
|
|
yap_hacks:cut_at(DCP),
|
|
|
|
'$call'(A,CP,((X*->A),Y),M)
|
|
|
|
;
|
|
|
|
'$call'(Y,CP,((X*->A),Y),M)
|
|
|
|
).
|
2004-11-22 16:22:14 +00:00
|
|
|
';'(X,Y) :-
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks:env_choice_point(CP),
|
2004-11-22 16:22:14 +00:00
|
|
|
'$current_module'(M),
|
2004-11-22 16:31:33 +00:00
|
|
|
( '$call'(X,CP,(X;Y),M) ; '$call'(Y,CP,(X;Y),M) ).
|
2004-11-22 16:22:14 +00:00
|
|
|
'|'(X,Y) :-
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks:env_choice_point(CP),
|
2004-11-22 16:22:14 +00:00
|
|
|
'$current_module'(M),
|
2004-11-22 16:31:33 +00:00
|
|
|
( '$call'(X,CP,(X|Y),M) ; '$call'(Y,CP,(X|Y),M) ).
|
|
|
|
'->'(X,Y) :-
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks:env_choice_point(CP),
|
2004-11-22 16:22:14 +00:00
|
|
|
'$current_module'(M),
|
2006-03-24 16:26:31 +00:00
|
|
|
( '$call'(X,CP,(X->Y),M) -> '$call'(Y,CP,(X->Y),M) ).
|
2008-02-12 17:03:59 +00:00
|
|
|
'*->'(X,Y) :-
|
|
|
|
yap_hacks:env_choice_point(CP),
|
|
|
|
'$current_module'(M),
|
|
|
|
( '$call'(X,CP,(X*->Y),M), '$call'(Y,CP,(X*->Y),M) ).
|
2004-11-22 16:22:14 +00:00
|
|
|
\+(G) :- \+ '$execute'(G).
|
|
|
|
not(G) :- \+ '$execute'(G).
|
|
|
|
|
2006-12-30 03:25:47 +00:00
|
|
|
'$cut_by'(CP) :- '$$cut_by'(CP).
|
2004-11-22 16:22:14 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
%
|
|
|
|
% do it in ISO mode.
|
|
|
|
%
|
2001-11-15 00:01:43 +00:00
|
|
|
'$meta_call'(G,_ISO,M) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$iso_check_goal'(G,G),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$current_choice_point'(CP),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(G, CP, G, M).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$meta_call'(G, CP, G0, M) :-
|
|
|
|
'$call'(G, CP, G0, M).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(G, CP, G0, _, M) :- /* iso version */
|
2001-04-09 20:54:03 +01:00
|
|
|
'$iso_check_goal'(G,G0),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(G, CP, G0, M).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(M:_,_,G0,_) :- var(M), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,call(G0)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(M:G,CP,G0,_) :- !,
|
|
|
|
'$call'(G,CP,G0,M).
|
|
|
|
'$call'((X,Y),CP,G0,M) :- !,
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(X,CP,G0,M),
|
|
|
|
'$call'(Y,CP,G0,M).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'((X->Y),CP,G0,M) :- !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2008-02-12 17:03:59 +00:00
|
|
|
'$call'(Y,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2008-02-12 17:03:59 +00:00
|
|
|
'$call'((X*->Y),CP,G0,M) :- !,
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M),
|
2008-02-12 17:03:59 +00:00
|
|
|
'$call'(Y,CP,G0,M).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'((X->Y; Z),CP,G0,M) :- !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(Y,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(Z,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2008-02-12 17:03:59 +00:00
|
|
|
'$call'((X*->Y; Z),CP,G0,M) :- !,
|
|
|
|
(
|
2013-02-15 19:40:05 +00:00
|
|
|
'$current_choice_point'(DCP),
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M),
|
2008-02-12 17:03:59 +00:00
|
|
|
yap_hacks:cut_at(DCP),
|
|
|
|
'$call'(Y,CP,G0,M)
|
|
|
|
;
|
|
|
|
'$call'(Z,CP,G0,M)
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'((A;B),CP,G0,M) :- !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(A,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(B,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2003-01-29 14:47:17 +00:00
|
|
|
'$call'((X->Y| Z),CP,G0,M) :- !,
|
|
|
|
(
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
->
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(Y,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
;
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(Z,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
).
|
2008-02-12 17:03:59 +00:00
|
|
|
'$call'((X*->Y| Z),CP,G0,M) :- !,
|
|
|
|
(
|
2013-02-15 19:40:05 +00:00
|
|
|
'$current_choice_point'(DCP),
|
2008-08-06 01:56:11 +01:00
|
|
|
'$call'(X,CP,G0,M),
|
2008-02-12 17:03:59 +00:00
|
|
|
yap_hacks:cut_at(DCP),
|
|
|
|
'$call'(Y,CP,G0,M)
|
|
|
|
;
|
|
|
|
'$call'(Z,CP,G0,M)
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'((A|B),CP, G0,M) :- !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(A,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(B,CP,G0,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2006-11-27 17:42:03 +00:00
|
|
|
'$call'(\+ X, _CP, _G0, M) :- !,
|
2013-02-15 19:40:05 +00:00
|
|
|
'$current_choice_point'(CP),
|
2008-08-06 01:56:11 +01:00
|
|
|
\+ '$call'(X,CP,G0,M).
|
2007-01-24 14:20:04 +00:00
|
|
|
'$call'(not(X), _CP, _G0, M) :- !,
|
2008-08-06 01:56:11 +01:00
|
|
|
\+ '$call'(X,CP,G0,M).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'(!, CP, _,_) :- !,
|
2006-12-30 03:25:47 +00:00
|
|
|
'$$cut_by'(CP).
|
2001-12-11 04:35:31 +00:00
|
|
|
'$call'([A|B], _, _, M) :- !,
|
|
|
|
'$csult'([A|B], M).
|
2004-12-05 05:01:45 +00:00
|
|
|
'$call'(G, CP, G0, CurMod) :-
|
|
|
|
( '$is_expand_goal_or_meta_predicate'(G,CurMod) ->
|
|
|
|
(
|
2012-12-07 08:08:32 +00:00
|
|
|
'$do_goal_expansion'(G, CurMod, NG) ->
|
|
|
|
'$call'(NG, CP, G0,CurMod)
|
2004-12-05 05:01:45 +00:00
|
|
|
;
|
|
|
|
% repeat other code.
|
|
|
|
'$is_metapredicate'(G,CurMod) ->
|
|
|
|
(
|
2008-07-23 00:34:50 +01:00
|
|
|
'$meta_expansion'(G,CurMod,CurMod,CurMod,NG,[]) ->
|
2004-12-05 05:01:45 +00:00
|
|
|
'$execute0'(NG, CurMod)
|
|
|
|
;
|
|
|
|
'$execute0'(G, CurMod)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
'$execute0'(G, CurMod)
|
|
|
|
)
|
2002-11-26 23:00:32 +00:00
|
|
|
;
|
2004-12-05 05:01:45 +00:00
|
|
|
'$execute0'(G, CurMod)
|
2002-11-26 23:00:32 +00:00
|
|
|
).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_callable'(V,G) :- var(V), !,
|
2006-05-25 17:28:28 +01:00
|
|
|
'$do_error'(instantiation_error,G).
|
2007-01-24 14:20:04 +00:00
|
|
|
'$check_callable'(M:_G1,G) :- var(M), !,
|
2006-05-25 17:28:28 +01:00
|
|
|
'$do_error'(instantiation_error,G).
|
|
|
|
'$check_callable'(_:G1,G) :- !,
|
|
|
|
'$check_callable'(G1,G).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_callable'(A,G) :- number(A), !,
|
2006-05-25 17:28:28 +01:00
|
|
|
'$do_error'(type_error(callable,A),G).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_callable'(R,G) :- db_reference(R), !,
|
2006-05-25 17:28:28 +01:00
|
|
|
'$do_error'(type_error(callable,R),G).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_callable'(_,_).
|
|
|
|
|
|
|
|
% Called by the abstract machine, if no clauses exist for a predicate
|
|
|
|
'$undefp'([M|G]) :-
|
2010-12-03 12:40:30 +00:00
|
|
|
'$find_goal_definition'(M, G, NM, NG),
|
|
|
|
'$execute0'(NG, NM).
|
|
|
|
|
|
|
|
'$find_goal_definition'(M, G, NM, NG) :-
|
2004-12-08 04:45:04 +00:00
|
|
|
% make sure we do not loop on undefined predicates
|
|
|
|
% for undefined_predicates.
|
2009-12-03 16:33:44 +00:00
|
|
|
'$enter_undefp',
|
2008-02-07 22:34:45 +00:00
|
|
|
(
|
2009-12-04 11:00:13 +00:00
|
|
|
'$get_undefined_pred'(G, M, Goal, NM)
|
2008-02-12 17:03:59 +00:00
|
|
|
->
|
2013-11-13 10:38:20 +00:00
|
|
|
'$exit_undefp',
|
|
|
|
Goal \= fail,
|
|
|
|
'$complete_goal'(M, Goal, NM, G, NG)
|
2008-02-07 22:34:45 +00:00
|
|
|
;
|
2013-11-13 10:38:20 +00:00
|
|
|
'$find_undefp_handler'(G, M),
|
|
|
|
NG = G, NM = M
|
|
|
|
).
|
2008-07-23 00:34:50 +01:00
|
|
|
|
2010-12-03 12:40:30 +00:00
|
|
|
'$complete_goal'(M, G, CurMod, G0, NG) :-
|
2008-07-23 00:34:50 +01:00
|
|
|
(
|
|
|
|
'$is_metapredicate'(G,CurMod)
|
|
|
|
->
|
2010-12-03 12:40:30 +00:00
|
|
|
'$meta_expansion'(G, CurMod, M, M, NG,[])
|
2008-07-23 00:34:50 +01:00
|
|
|
;
|
2010-12-03 12:40:30 +00:00
|
|
|
NG = G
|
2008-07-23 00:34:50 +01:00
|
|
|
).
|
2004-12-07 04:35:22 +00:00
|
|
|
|
2010-03-01 23:02:24 +00:00
|
|
|
'$find_undefp_handler'(G,M,NG,user) :-
|
|
|
|
functor(G, Na, Ar),
|
|
|
|
user:exception(undefined_predicate,M:Na/Ar,Action), !,
|
|
|
|
'$exit_undefp',
|
2013-11-13 10:38:20 +00:00
|
|
|
(
|
|
|
|
Action == fail
|
|
|
|
->
|
|
|
|
NG = fail
|
|
|
|
;
|
|
|
|
Action == retry
|
|
|
|
->
|
|
|
|
NG = G
|
|
|
|
;
|
|
|
|
Action == error
|
|
|
|
->
|
|
|
|
'$unknown_error'(M:G)
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(atom, Action),M:G)
|
|
|
|
).
|
|
|
|
|
|
|
|
'$find_undefp_handler'(G,M) :-
|
|
|
|
'$exit_undefp',
|
|
|
|
'$swi_current_prolog_flag'(M:unknown, Action),
|
2010-03-01 23:02:24 +00:00
|
|
|
(
|
|
|
|
Action == fail
|
|
|
|
->
|
2013-11-13 10:38:20 +00:00
|
|
|
fail
|
2010-03-01 23:02:24 +00:00
|
|
|
;
|
2013-11-13 10:38:20 +00:00
|
|
|
Action == warning
|
2010-03-01 23:02:24 +00:00
|
|
|
->
|
2013-11-13 10:38:20 +00:00
|
|
|
'$unknown_warning'(M:G),
|
|
|
|
fail
|
2010-03-01 23:02:24 +00:00
|
|
|
;
|
|
|
|
'$unknown_error'(M:G)
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$silent_bootstrap'(F) :-
|
2010-02-28 09:08:06 +00:00
|
|
|
'$init_globals',
|
2007-10-29 22:48:54 +00:00
|
|
|
nb_setval('$if_level',0),
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_current_prolog_flag'(verbose_load, OldSilent),
|
|
|
|
'$swi_set_prolog_flag'(verbose_load, silent),
|
2005-10-28 18:38:50 +01:00
|
|
|
bootstrap(F),
|
2011-03-02 09:20:18 +00:00
|
|
|
% -p option must be processed after initializing the system
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_set_prolog_flag'(verbose_load, OldSilent).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-19 02:47:43 +01:00
|
|
|
bootstrap(F) :-
|
2011-02-12 14:14:12 +00:00
|
|
|
% '$open'(F, '$csult', Stream, 0, 0, F),
|
|
|
|
% '$file_name'(Stream,File),
|
|
|
|
open(F, read, Stream),
|
|
|
|
stream_property(Stream, file_name(File)),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$start_consult'(consult, File, LC),
|
|
|
|
file_directory_name(File, Dir),
|
2011-05-12 22:26:10 +01:00
|
|
|
working_directory(OldD, Dir),
|
2005-10-28 18:38:50 +01:00
|
|
|
(
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_current_prolog_flag'(verbose_load, silent)
|
2005-10-28 18:38:50 +01:00
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
H0 is heapused, '$cputime'(T0,_),
|
|
|
|
format(user_error, '~*|% consulting ~w...~n', [LC,F])
|
|
|
|
),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$loop'(Stream,consult),
|
2011-05-12 22:26:10 +01:00
|
|
|
working_directory(_, OldD),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$end_consult',
|
2005-10-28 18:38:50 +01:00
|
|
|
(
|
2013-11-04 01:14:48 +00:00
|
|
|
'$swi_current_prolog_flag'(verbose_load, silent)
|
2005-10-28 18:38:50 +01:00
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
|
|
|
format(user_error, '~*|% ~w consulted ~w bytes in ~d msecs~n', [LC,F,H,T])
|
|
|
|
),
|
2007-02-18 00:26:36 +00:00
|
|
|
!,
|
2011-02-14 22:55:59 +00:00
|
|
|
close(Stream).
|
2007-02-18 00:26:36 +00:00
|
|
|
|
2013-01-15 11:18:09 +00:00
|
|
|
'$loop'(Stream,exo) :-
|
2013-01-22 22:21:44 +00:00
|
|
|
prolog_flag(agc_margin,Old,0),
|
2013-01-15 11:18:09 +00:00
|
|
|
prompt1('| '), prompt(_,'| '),
|
|
|
|
'$current_module'(OldModule),
|
|
|
|
repeat,
|
|
|
|
'$system_catch'(dbload_from_stream(Stream, OldModule, exo), '$db_load', Error,
|
|
|
|
user:'$LoopError'(Error, Status)),
|
2013-01-22 22:21:44 +00:00
|
|
|
prolog_flag(agc_margin,_,Old),
|
2013-01-15 11:18:09 +00:00
|
|
|
!.
|
|
|
|
'$loop'(Stream,db) :-
|
2013-01-22 22:21:44 +00:00
|
|
|
prolog_flag(agc_margin,Old,0),
|
2013-01-15 11:18:09 +00:00
|
|
|
prompt1('| '), prompt(_,'| '),
|
|
|
|
'$current_module'(OldModule),
|
|
|
|
repeat,
|
|
|
|
'$system_catch'(dbload_from_stream(Stream, OldModule, db), '$db_load', Error,
|
|
|
|
user:'$LoopError'(Error, Status)),
|
2013-01-22 22:21:44 +00:00
|
|
|
prolog_flag(agc_margin,_,Old),
|
2013-01-15 11:18:09 +00:00
|
|
|
!.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$loop'(Stream,Status) :-
|
|
|
|
repeat,
|
2011-02-14 15:19:37 +00:00
|
|
|
prompt1('| '), prompt(_,'| '),
|
2002-04-09 16:12:14 +01:00
|
|
|
'$current_module'(OldModule),
|
2013-11-20 22:30:49 +00:00
|
|
|
'$system_catch'('$enter_command'(Stream,OldModule,Status), OldModule, Error,
|
2003-12-01 17:27:42 +00:00
|
|
|
user:'$LoopError'(Error, Status)),
|
2002-01-22 17:11:36 +00:00
|
|
|
!.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2013-11-20 22:30:49 +00:00
|
|
|
'$enter_command'(Stream,Mod,Status) :-
|
2014-01-06 22:17:42 +00:00
|
|
|
read_term(Stream, Command, [module(Mod), variable_names(Vars), term_position(Pos), syntax_errors(dec10), process_comment(true), singletons( Singletons ) ]),
|
|
|
|
( Singletons == []
|
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
get_value('$syntaxchecksinglevar',on)
|
|
|
|
->
|
|
|
|
'$sv_warning'(Singletons, Command )
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2011-06-14 09:01:10 +01:00
|
|
|
'$command'(Command,Vars,Pos,Status).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$abort_loop'(Stream) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(input,closed_stream,Stream), loop).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* General purpose predicates */
|
|
|
|
|
|
|
|
'$head_and_body'((H:-B),H,B) :- !.
|
|
|
|
'$head_and_body'(H,H,true).
|
|
|
|
|
|
|
|
%
|
|
|
|
% split head and body, generate an error if body is unbound.
|
|
|
|
%
|
|
|
|
'$check_head_and_body'((H:-B),H,B,P) :- !,
|
|
|
|
'$check_head'(H,P).
|
|
|
|
'$check_head_and_body'(H,H,true,P) :-
|
|
|
|
'$check_head'(H,P).
|
|
|
|
|
|
|
|
'$check_head'(H,P) :- var(H), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head'(H,P) :- number(H), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,H),P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head'(H,P) :- db_reference(H), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,H),P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head'(_,_).
|
|
|
|
|
|
|
|
% term expansion
|
|
|
|
%
|
|
|
|
% return two arguments: Expanded0 is the term after "USER" expansion.
|
|
|
|
% Expanded is the final expanded term.
|
|
|
|
%
|
2008-07-23 00:34:50 +01:00
|
|
|
'$precompile_term'(Term, Expanded0, Expanded, BodyMod, SourceMod) :-
|
|
|
|
'$module_expansion'(Term, Expanded0, ExpandedI, BodyMod, SourceMod), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2008-07-23 00:34:50 +01:00
|
|
|
'$access_yap_flags'(9,1) /* strict_iso on */
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2008-07-23 00:34:50 +01:00
|
|
|
Expanded = ExpandedI,
|
|
|
|
'$check_iso_strict_clause'(Expanded0)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2008-07-23 00:34:50 +01:00
|
|
|
'$expand_array_accesses_in_term'(ExpandedI,Expanded)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2008-07-23 00:34:50 +01:00
|
|
|
'$precompile_term'(Term, Term, Term, _, _).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
expand_term(Term,Expanded) :-
|
2012-12-07 08:08:32 +00:00
|
|
|
( '$do_term_expansion'(Term,Expanded)
|
|
|
|
->
|
|
|
|
true
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
'$expand_term_grammar'(Term,Expanded)
|
2012-12-07 08:08:32 +00:00
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%
|
|
|
|
% Grammar Rules expansion
|
|
|
|
%
|
|
|
|
'$expand_term_grammar'((A-->B), C) :-
|
|
|
|
'$translate_rule'((A-->B),C), !.
|
|
|
|
'$expand_term_grammar'(A, A).
|
|
|
|
|
|
|
|
%
|
|
|
|
% Arithmetic expansion
|
|
|
|
%
|
|
|
|
'$expand_array_accesses_in_term'(Expanded0,ExpandedF) :-
|
|
|
|
'$array_refs_compiled',
|
|
|
|
'$c_arrays'(Expanded0,ExpandedF), !.
|
|
|
|
'$expand_array_accesses_in_term'(Expanded,Expanded).
|
|
|
|
|
2001-12-17 18:31:11 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
% catch/throw implementation
|
|
|
|
|
2001-12-17 18:31:11 +00:00
|
|
|
% at each catch point I need to know:
|
|
|
|
% what is ball;
|
|
|
|
% where was the previous catch
|
2002-01-07 06:28:04 +00:00
|
|
|
catch(G, C, A) :-
|
2002-01-28 04:30:40 +00:00
|
|
|
'$catch'(C,A,_),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$$save_by'(CP0),
|
2008-09-24 00:13:02 +01:00
|
|
|
'$execute'(G),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$$save_by'(CP1),
|
2009-05-05 00:10:07 +01:00
|
|
|
(CP0 == CP1 -> !; true ).
|
2008-09-24 00:13:02 +01:00
|
|
|
|
|
|
|
% makes sure we have an environment.
|
|
|
|
'$true'.
|
2001-12-17 18:31:11 +00:00
|
|
|
|
2004-07-15 16:47:08 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
% system_catch is like catch, but it avoids the overhead of a full
|
2001-11-15 00:01:43 +00:00
|
|
|
% meta-call by calling '$execute0' instead of $execute.
|
2001-04-09 20:54:03 +01:00
|
|
|
% This way it
|
|
|
|
% also avoids module preprocessing and goal_expansion
|
|
|
|
%
|
2002-01-07 06:28:04 +00:00
|
|
|
'$system_catch'(G, M, C, A) :-
|
|
|
|
% check current trail
|
2002-01-28 04:30:40 +00:00
|
|
|
'$catch'(C,A,_),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$$save_by'(CP0),
|
2008-09-24 00:13:02 +01:00
|
|
|
'$execute_nonstop'(G, M),
|
2013-02-13 15:06:06 +00:00
|
|
|
'$$save_by'(CP1),
|
2009-05-05 00:10:07 +01:00
|
|
|
(CP0 == CP1 -> !; true ).
|
2002-01-24 23:55:34 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% throw has to be *exactly* after system catch!
|
|
|
|
%
|
2009-11-27 11:21:24 +00:00
|
|
|
throw(_Ball) :-
|
|
|
|
% use existing ball
|
2009-12-02 21:59:41 +00:00
|
|
|
'$get_exception'(Ball),
|
2009-11-27 11:21:24 +00:00
|
|
|
!,
|
|
|
|
'$jump_env_and_store_ball'(Ball).
|
2002-01-24 23:55:34 +00:00
|
|
|
throw(Ball) :-
|
2013-01-17 14:00:12 +00:00
|
|
|
( var(Ball) ->
|
|
|
|
'$do_error'(instantiation_error,throw(Ball))
|
|
|
|
;
|
2002-01-24 23:55:34 +00:00
|
|
|
% get current jump point
|
2013-01-17 14:00:12 +00:00
|
|
|
'$jump_env_and_store_ball'(Ball)
|
|
|
|
).
|
2001-06-11 16:12:07 +01:00
|
|
|
|
2002-01-14 22:26:53 +00:00
|
|
|
|
2002-01-24 23:55:34 +00:00
|
|
|
% just create a choice-point
|
2002-01-28 04:30:40 +00:00
|
|
|
'$catch'(_,_,_).
|
|
|
|
'$catch'(_,_,_) :- fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-01-24 23:55:34 +00:00
|
|
|
'$handle_throw'(_, _, _).
|
2009-11-27 11:21:24 +00:00
|
|
|
'$handle_throw'(C, A, _Ball) :-
|
2009-12-02 21:59:41 +00:00
|
|
|
'$reset_exception'(Ball),
|
2009-04-22 17:32:07 +01:00
|
|
|
% reset info
|
2011-07-09 12:56:11 +01:00
|
|
|
(catch_ball(Ball, C) ->
|
2002-01-07 06:28:04 +00:00
|
|
|
'$execute'(A)
|
|
|
|
;
|
|
|
|
throw(Ball)
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-07-09 12:56:11 +01:00
|
|
|
catch_ball(Abort, _) :- Abort == '$abort', !, fail.
|
2009-04-22 17:32:07 +01:00
|
|
|
% system defined throws should be ignored by used, unless the
|
|
|
|
% user is hacking away.
|
2011-07-09 12:56:11 +01:00
|
|
|
catch_ball(Ball, V) :-
|
2009-04-22 17:32:07 +01:00
|
|
|
var(V),
|
|
|
|
nonvar(Ball),
|
2009-04-22 22:13:08 +01:00
|
|
|
Ball = error(Type,_), % internal error ??
|
|
|
|
functor(Type, Name, _),
|
2009-04-22 17:32:07 +01:00
|
|
|
atom_codes(Name, [0'$|_]), %'0
|
|
|
|
!, fail.
|
2011-07-09 12:56:11 +01:00
|
|
|
catch_ball(C, C).
|
2009-04-22 17:32:07 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$run_toplevel_hooks' :-
|
2013-11-15 15:45:55 +00:00
|
|
|
'$swi_current_prolog_flag'(break_level, 0 ),
|
2012-12-07 08:08:32 +00:00
|
|
|
recorded('$toplevel_hooks',H,_),
|
|
|
|
H \= fail, !,
|
2013-02-15 02:40:11 +00:00
|
|
|
( call(user:H1) -> true ; true).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$run_toplevel_hooks'.
|
|
|
|
|
2009-04-25 18:54:21 +01:00
|
|
|
'$run_at_thread_start' :-
|
|
|
|
recorded('$thread_initialization',M:D,_),
|
2013-12-13 08:42:57 +00:00
|
|
|
'$meta_call'(D, M),
|
2009-04-25 18:54:21 +01:00
|
|
|
fail.
|
|
|
|
'$run_at_thread_start'.
|
|
|
|
|
|
|
|
|
2011-03-09 23:28:30 +00:00
|
|
|
|
|
|
|
|