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
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
% This one should come first so that disjunctions and long distance
|
|
|
|
% cuts are compiled right with co-routining.
|
|
|
|
%
|
2002-03-08 06:33:16 +00:00
|
|
|
|
|
|
|
true :- true.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$live' :-
|
|
|
|
'$init_system',
|
2002-01-16 22:11:55 +00:00
|
|
|
'$do_live'.
|
|
|
|
|
|
|
|
'$do_live' :-
|
2001-04-09 20:54:03 +01:00
|
|
|
repeat,
|
2006-01-02 02:16:19 +00:00
|
|
|
'$set_input'(user_input),'$set_output'(user),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$current_module'(Module),
|
2005-07-06 16:10:18 +01:00
|
|
|
( Module==user ->
|
2001-04-09 20:54:03 +01:00
|
|
|
'$compile_mode'(_,0)
|
|
|
|
;
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'[~w]~n', [Module])
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$init_system' :-
|
2005-10-31 00:51:53 +00:00
|
|
|
'$change_alias_to_stream'('$loop_stream','$stream'(0)),
|
2002-01-17 16:20:36 +00:00
|
|
|
% do catch as early as possible
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2004-11-19 21:32:53 +00:00
|
|
|
'$access_yap_flags'(15, 0), \+ '$uncaught_throw' ->
|
2001-04-09 20:54:03 +01:00
|
|
|
'$version'
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
2006-08-22 17:12:46 +01:00
|
|
|
'$allocate_default_arena'(1024, 64),
|
2006-12-13 16:10:26 +00:00
|
|
|
'$enter_system_mode',
|
2005-02-08 18:14:30 +00:00
|
|
|
set_value(fileerrors,1),
|
2003-08-27 14:37:10 +01:00
|
|
|
set_value('$gc',on),
|
2005-10-18 18:04:43 +01:00
|
|
|
set_value('$lf_verbose',informational),
|
2004-12-08 04:45:04 +00:00
|
|
|
('$exit_undefp' -> true ; true),
|
2001-04-09 20:54:03 +01:00
|
|
|
prompt(' ?- '),
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_setval('$break',0),
|
|
|
|
% '$set_read_error_handler'(error), let the user do that
|
|
|
|
nb_setval('$debug',off),
|
|
|
|
nb_setval('$trace',off),
|
|
|
|
b_setval('$spy_glist',[]),
|
|
|
|
% simple trick to find out if this is we are booting from Prolog.
|
|
|
|
get_value('$user_module',V),
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2006-12-13 16:10:26 +00:00
|
|
|
V == []
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2006-12-13 16:10:26 +00:00
|
|
|
'$current_module'(_,prolog)
|
|
|
|
;
|
|
|
|
'$current_module'(_,V), '$compile_mode'(_,0),
|
|
|
|
('$access_yap_flags'(16,0) ->
|
|
|
|
( exists('~/.yaprc') -> load_files('~/.yaprc', []) ; true ),
|
|
|
|
( exists('~/.prologrc') -> load_files('~/.prologrc', []) ; true ),
|
|
|
|
( exists('~/prolog.ini') -> load_files('~/prolog.ini', []) ; true )
|
|
|
|
;
|
|
|
|
true
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'$db_clean_queues'(0),
|
|
|
|
'$startup_reconsult',
|
|
|
|
'$startup_goals'.
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
% Start file for yap
|
|
|
|
|
|
|
|
/* I/O predicates */
|
|
|
|
|
|
|
|
/* meaning of flags for '$write' is
|
|
|
|
1 quote illegal atoms
|
|
|
|
2 ignore operator declarations
|
|
|
|
4 output '$VAR'(N) terms as A, B, C, ...
|
|
|
|
8 use portray(_)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* main execution loop */
|
|
|
|
'$read_vars'(Stream,T,Mod,Pos,V) :-
|
|
|
|
'$read'(true,T,Mod,V,Pos,Err,Stream),
|
|
|
|
(nonvar(Err) ->
|
|
|
|
'$print_message'(error,Err), fail
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
|
|
|
|
|
|
|
% reset alarms when entering top-level.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
'$alarm'(0, _),
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
'$clean_up_dead_clauses',
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
recorded('$restore_goal',G,R),
|
|
|
|
erase(R),
|
|
|
|
prompt(_,' | '),
|
|
|
|
'$system_catch'('$do_yes_no'((G->true),user),user,Error,user:'$Error'(Error)),
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_getval('$break',BreakLevel),
|
|
|
|
(
|
|
|
|
nb_getval('$trace',on)
|
|
|
|
->
|
|
|
|
TraceDebug = trace
|
2006-01-02 02:16:19 +00:00
|
|
|
;
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_getval('$debug', on)
|
|
|
|
->
|
|
|
|
TraceDebug = debug
|
2006-01-02 02:16:19 +00:00
|
|
|
;
|
2006-12-13 16:10:26 +00:00
|
|
|
true
|
2006-01-02 02:16:19 +00:00
|
|
|
),
|
|
|
|
'$print_message'(informational,prompt(BreakLevel,TraceDebug)),
|
|
|
|
fail.
|
|
|
|
'$enter_top_level' :-
|
|
|
|
get_value('$top_level_goal',GA), GA \= [], !,
|
|
|
|
set_value('$top_level_goal',[]),
|
|
|
|
'$run_atom_goal'(GA),
|
|
|
|
set_value('$live','$false').
|
|
|
|
'$enter_top_level' :-
|
|
|
|
prompt(_,' ?- '),
|
|
|
|
prompt(' | '),
|
|
|
|
'$run_toplevel_hooks',
|
|
|
|
'$read_vars'(user_input,Command,_,_,Varnames),
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_setval('$spy_gn',1),
|
|
|
|
% stop at spy-points if debugging is on.
|
|
|
|
nb_setval('$debug_run',off),
|
|
|
|
nb_setval('$debug_zip',off),
|
2006-01-02 02:16:19 +00:00
|
|
|
prompt(_,' |: '),
|
|
|
|
'$command'((?-Command),Varnames,top),
|
|
|
|
'$sync_mmapped_arrays',
|
|
|
|
set_value('$live','$false').
|
|
|
|
|
|
|
|
'$startup_goals' :-
|
|
|
|
get_value('$extend_file_search_path',P), P \= [],
|
|
|
|
set_value('$extend_file_search_path',[]),
|
|
|
|
'$extend_file_search_path'(P),
|
|
|
|
fail.
|
|
|
|
'$startup_goals' :-
|
|
|
|
recorded('$startup_goal',G,_),
|
|
|
|
'$current_module'(Module),
|
|
|
|
'$system_catch'('$query'(once(G), []),Module,Error,user:'$Error'(Error)),
|
|
|
|
fail.
|
|
|
|
'$startup_goals' :-
|
|
|
|
get_value('$init_goal',GA), GA \= [],
|
|
|
|
set_value('$init_goal',[]),
|
|
|
|
'$run_atom_goal'(GA),
|
|
|
|
fail.
|
2006-02-08 17:29:55 +00:00
|
|
|
'$startup_goals' :-
|
|
|
|
get_value('$myddas_goal',GA), GA \= [],
|
|
|
|
set_value('$myddas_goal',[]),
|
|
|
|
get_value('$myddas_user',User), User \= [],
|
|
|
|
set_value('$myddas_user',[]),
|
|
|
|
get_value('$myddas_db',Db), Db \= [],
|
|
|
|
set_value('$myddas_db',[]),
|
|
|
|
get_value('$myddas_host',HostT),
|
|
|
|
( HostT \= [] ->
|
|
|
|
Host = HostT,
|
|
|
|
set_value('$myddas_host',[])
|
|
|
|
;
|
|
|
|
Host = localhost
|
|
|
|
),
|
|
|
|
get_value('$myddas_pass',PassT),
|
|
|
|
( PassT \= [] ->
|
|
|
|
Pass = PassT,
|
|
|
|
set_value('$myddas_pass',[])
|
|
|
|
;
|
|
|
|
Pass = ''
|
|
|
|
),
|
|
|
|
use_module(library(myddas)),
|
|
|
|
call(db_open(mysql,myddas,Host/Db,User,Pass)),
|
|
|
|
'$myddas_import_all',
|
|
|
|
fail.
|
2006-01-02 02:16:19 +00:00
|
|
|
'$startup_goals'.
|
|
|
|
|
|
|
|
'$startup_reconsult' :-
|
|
|
|
get_value('$consult_on_boot',X), X \= [], !,
|
|
|
|
set_value('$consult_on_boot',[]),
|
|
|
|
'$do_startup_reconsult'(X).
|
|
|
|
'$startup_reconsult'.
|
|
|
|
|
2006-02-08 17:29:55 +00:00
|
|
|
%
|
|
|
|
% MYDDAS: Import all the tables from one database
|
|
|
|
%
|
|
|
|
|
|
|
|
'$myddas_import_all':-
|
|
|
|
call(db_my_show_tables(myddas,table(Table))),
|
|
|
|
call(db_import(myddas,Table,Table)),
|
|
|
|
fail.
|
|
|
|
'$myddas_import_all'.
|
|
|
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
'$print_message'(help, version(VersionName)),
|
2006-05-22 17:12:01 +01:00
|
|
|
get_value('$myddas_version_name',MYDDASVersionName),
|
|
|
|
MYDDASVersionName \== [],
|
|
|
|
'$print_message'(help, myddas_version(MYDDASVersionName)),
|
2006-01-02 02:16:19 +00:00
|
|
|
fail.
|
|
|
|
'$version' :- recorded('$version',VersionName,_),
|
|
|
|
'$print_message'(help, VersionName),
|
|
|
|
fail.
|
|
|
|
'$version'.
|
|
|
|
|
|
|
|
repeat :- '$repeat'.
|
|
|
|
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat'.
|
|
|
|
'$repeat' :- '$repeat'.
|
|
|
|
|
|
|
|
'$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,_).
|
|
|
|
|
|
|
|
'$command'(C,VL,Con) :-
|
|
|
|
'$access_yap_flags'(9,1), !,
|
|
|
|
'$execute_command'(C,VL,Con,C).
|
|
|
|
'$command'(C,VL,Con) :-
|
|
|
|
( (Con = top ; var(C) ; C = [_|_]) ->
|
|
|
|
'$execute_command'(C,VL,Con,C), ! ;
|
|
|
|
expand_term(C, EC),
|
|
|
|
'$execute_commands'(EC,VL,Con,C)
|
|
|
|
).
|
|
|
|
|
|
|
|
%
|
|
|
|
% Hack in case expand_term has created a list of commands.
|
|
|
|
%
|
|
|
|
'$execute_commands'(V,_,_,Source) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,meta_call(Source)).
|
|
|
|
'$execute_commands'([],_,_,_) :- !, fail.
|
|
|
|
'$execute_commands'([C|Cs],VL,Con,Source) :- !,
|
|
|
|
(
|
|
|
|
'$execute_command'(C,VL,Con,Source)
|
|
|
|
;
|
|
|
|
'$execute_commands'(Cs,VL,Con,Source)
|
|
|
|
),
|
|
|
|
fail.
|
|
|
|
'$execute_commands'(C,VL,Con,Source) :-
|
|
|
|
'$execute_command'(C,VL,Con,Source).
|
|
|
|
|
|
|
|
%
|
|
|
|
%
|
|
|
|
%
|
|
|
|
|
|
|
|
'$execute_command'(C,_,top,Source) :- var(C), !,
|
|
|
|
'$do_error'(instantiation_error,meta_call(Source)).
|
|
|
|
'$execute_command'(C,_,top,Source) :- number(C), !,
|
|
|
|
'$do_error'(type_error(callable,C),meta_call(Source)).
|
|
|
|
'$execute_command'(R,_,top,Source) :- db_reference(R), !,
|
|
|
|
'$do_error'(type_error(callable,R),meta_call(Source)).
|
|
|
|
'$execute_command'(end_of_file,_,_,_) :- !.
|
|
|
|
'$execute_command'((:-G),_,Option,_) :- !,
|
|
|
|
'$current_module'(M),
|
|
|
|
'$process_directive'(G, Option, M),
|
|
|
|
fail.
|
|
|
|
'$execute_command'((?-G),V,_,Source) :- !,
|
|
|
|
'$execute_command'(G,V,top,Source).
|
|
|
|
'$execute_command'(G,V,Option,Source) :-
|
|
|
|
'$continue_with_command'(Option,V,G,Source).
|
|
|
|
|
|
|
|
%
|
|
|
|
% 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
|
|
|
|
%
|
|
|
|
'$process_directive'(G, top, M) :-
|
|
|
|
'$access_yap_flags'(8, 0), !, % YAP mode, go in and do it,
|
|
|
|
'$process_directive'(G, consult, M).
|
|
|
|
'$process_directive'(G, top, _) :- !,
|
|
|
|
'$do_error'(context_error((:- G),clause),query).
|
|
|
|
%
|
|
|
|
% allow modules
|
|
|
|
%
|
|
|
|
'$process_directive'(M:G, Mode, _) :- !,
|
|
|
|
'$process_directive'(G, Mode, M).
|
|
|
|
%
|
|
|
|
% default case
|
|
|
|
%
|
|
|
|
'$process_directive'(Gs, Mode, M) :-
|
|
|
|
'$all_directives'(Gs), !,
|
|
|
|
'$exec_directives'(Gs, Mode, M).
|
|
|
|
|
|
|
|
%
|
|
|
|
% ISO does not allow goals (use initialization).
|
|
|
|
%
|
|
|
|
'$process_directive'(D, _, M) :-
|
|
|
|
'$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.
|
|
|
|
%
|
|
|
|
'$process_directive'(G, _, M) :-
|
2006-12-13 16:10:26 +00:00
|
|
|
( '$do_yes_no'(G,M) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
'$continue_with_command'(reconsult,V,G,Source) :-
|
|
|
|
'$go_compile_clause'(G,V,5,Source),
|
|
|
|
fail.
|
|
|
|
'$continue_with_command'(consult,V,G,Source) :-
|
|
|
|
'$go_compile_clause'(G,V,13,Source),
|
|
|
|
fail.
|
|
|
|
'$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.
|
|
|
|
%
|
|
|
|
'$go_compile_clause'(Mod:G,V,N,Source) :- !,
|
|
|
|
'$go_compile_clause'(G,V,N,Mod,Source).
|
|
|
|
'$go_compile_clause'((M:G :- B),V,N,Source) :- !,
|
|
|
|
'$current_module'(M1),
|
|
|
|
(M1 = M ->
|
|
|
|
NG = (G :- B)
|
|
|
|
;
|
|
|
|
'$preprocess_clause_before_mod_change'((G:-B),M1,M,NG)
|
|
|
|
),
|
|
|
|
'$go_compile_clause'(NG,V,N,M,Source).
|
|
|
|
'$go_compile_clause'(G,V,N,Source) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$go_compile_clause'(G,V,N,Mod,Source).
|
|
|
|
|
|
|
|
'$go_compile_clause'(G, V, N, Mod, Source) :-
|
|
|
|
'$prepare_term'(G, V, G0, G1, Mod, Source),
|
|
|
|
'$$compile'(G1, G0, N, Mod).
|
|
|
|
|
|
|
|
'$prepare_term'(G, V, G0, G1, Mod, Source) :-
|
|
|
|
( get_value('$syntaxcheckflag',on) ->
|
|
|
|
'$check_term'(Source, V, Mod) ; true ),
|
|
|
|
'$precompile_term'(G, G0, G1, Mod).
|
|
|
|
|
|
|
|
% process an input clause
|
|
|
|
'$$compile'(G, G0, L, Mod) :-
|
|
|
|
'$head_and_body'(G,H,_),
|
|
|
|
'$flags'(H, Mod, Fl, Fl),
|
|
|
|
is(NFl, /\, Fl, 0x00002000),
|
|
|
|
( NFl \= 0 -> '$assertz_dynamic'(L,G,G0,Mod) ;
|
|
|
|
'$compile'(G, L, G0, Mod) ).
|
|
|
|
|
|
|
|
'$check_if_reconsulted'(N,A) :-
|
|
|
|
recorded('$reconsulted',X,_),
|
|
|
|
( X = N/A , !;
|
|
|
|
X = '$', !, fail;
|
|
|
|
fail
|
|
|
|
).
|
|
|
|
|
|
|
|
'$inform_as_reconsulted'(N,A) :-
|
|
|
|
recorda('$reconsulted',N/A,_).
|
|
|
|
|
|
|
|
'$clear_reconsulting' :-
|
|
|
|
recorded('$reconsulted',X,Ref),
|
|
|
|
erase(Ref),
|
|
|
|
X == '$', !,
|
|
|
|
( recorded('$reconsulting',_,R) -> erase(R) ).
|
|
|
|
|
|
|
|
/* Executing a query */
|
|
|
|
|
|
|
|
'$query'(end_of_file,_).
|
|
|
|
|
|
|
|
% ***************************
|
|
|
|
% * -------- YAPOR -------- *
|
|
|
|
% ***************************
|
|
|
|
|
|
|
|
'$query'(G,V) :-
|
|
|
|
\+ '$undefined'('$yapor_on', prolog),
|
|
|
|
'$yapor_on',
|
|
|
|
\+ '$undefined'('$start_yapor', prolog),
|
|
|
|
'$parallelizable'(G), !,
|
|
|
|
'$parallel_query'(G,V),
|
|
|
|
fail.
|
|
|
|
|
|
|
|
% end of YAPOR
|
|
|
|
|
|
|
|
'$query'(G,[]) :- !,
|
|
|
|
'$yes_no'(G,(?-)).
|
|
|
|
'$query'(G,V) :-
|
|
|
|
(
|
2006-12-13 16:10:26 +00:00
|
|
|
'$exit_system_mode',
|
|
|
|
'$execute'(G),
|
|
|
|
( '$enter_system_mode' ; '$exit_system_mode', fail),
|
|
|
|
'$output_frozen'(G, V, LGs),
|
|
|
|
'$write_answer'(V, LGs, Written),
|
|
|
|
'$write_query_answer_true'(Written),
|
|
|
|
'$another',
|
|
|
|
!, fail
|
|
|
|
;
|
|
|
|
'$enter_system_mode',
|
|
|
|
'$out_neg_answer'
|
2006-01-02 02:16:19 +00:00
|
|
|
).
|
|
|
|
|
|
|
|
'$yes_no'(G,C) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$do_yes_no'(G,M),
|
|
|
|
'$output_frozen'(G, [], LGs),
|
|
|
|
'$write_answer'([], LGs, Written),
|
|
|
|
( Written = [] ->
|
|
|
|
!,'$present_answer'(C, yes);
|
|
|
|
'$another', !
|
|
|
|
),
|
|
|
|
fail.
|
|
|
|
'$yes_no'(_,_) :-
|
2006-12-13 16:10:26 +00:00
|
|
|
'$out_neg_answer'.
|
|
|
|
|
|
|
|
'$add_env_and_fail' :- fail.
|
|
|
|
|
|
|
|
'$out_neg_answer' :-
|
2006-01-02 02:16:19 +00:00
|
|
|
( '$undefined'('$print_message'(_,_),prolog) ->
|
|
|
|
'$present_answer'(user_error,"no~n", [])
|
|
|
|
;
|
|
|
|
print_message(help,no)
|
|
|
|
),
|
|
|
|
fail.
|
|
|
|
|
|
|
|
'$do_yes_no'([X|L], M) :- !, '$csult'([X|L], M).
|
|
|
|
'$do_yes_no'(G, M) :-
|
2006-12-13 16:10:26 +00:00
|
|
|
'$exit_system_mode',
|
|
|
|
'$execute'(M:G),
|
|
|
|
( '$enter_system_mode' ; '$exit_system_mode', fail ).
|
2006-01-02 02:16:19 +00:00
|
|
|
|
|
|
|
'$write_query_answer_true'([]) :- !,
|
|
|
|
format(user_error,'~ntrue',[]).
|
|
|
|
'$write_query_answer_true'(_).
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
'$output_frozen'(_,V,LGs) :-
|
2005-10-18 18:04:43 +01:00
|
|
|
\+ '$undefined'(bindings_message(_,_,_), swi),
|
|
|
|
swi:bindings_message(V, LGs, []), !.
|
|
|
|
'$output_frozen'(G,V,LGs) :-
|
|
|
|
'$extract_goal_vars_for_dump'(V,LIV),
|
|
|
|
'$show_frozen'(G,LIV,LGs).
|
|
|
|
|
|
|
|
'$extract_goal_vars_for_dump'([],[]).
|
|
|
|
'$extract_goal_vars_for_dump'([[_|V]|VL],[V|LIV]) :-
|
|
|
|
'$extract_goal_vars_for_dump'(VL,LIV).
|
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'(_,_):-
|
2001-04-27 17:02:43 +01:00
|
|
|
'$flush_all_streams',
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
'$present_answer'((?-), Answ) :-
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_getval('$break',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
|
|
|
),
|
2004-07-22 22:32:23 +01: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,' ? ',[]),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$get0'(user_input,C),
|
2006-05-24 03:35:39 +01:00
|
|
|
( C== 0'; -> '$skip'(user_input,10), %'
|
2003-02-24 11:01:01 +00:00
|
|
|
'$add_nl_outside_console',
|
|
|
|
fail
|
2002-05-24 06:14:46 +01:00
|
|
|
;
|
2003-02-24 11:01:01 +00:00
|
|
|
C== 10 -> '$add_nl_outside_console',
|
2003-12-01 17:27:42 +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)
|
|
|
|
)
|
2002-05-24 06:14:46 +01:00
|
|
|
;
|
|
|
|
C== -1 -> halt
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
'$skip'(user_input,10), '$ask_again_for_another'
|
|
|
|
).
|
|
|
|
|
2003-02-24 11:01:01 +00:00
|
|
|
'$add_nl_outside_console' :-
|
|
|
|
'$is_same_tty'(user_input, user_error), !.
|
|
|
|
'$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'(_,_,_) :-
|
2001-04-27 17:02:43 +01:00
|
|
|
'$flush_all_streams',
|
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'([],[]).
|
|
|
|
'$purge_dontcares'([[[95|_]|_]|Vs],NVs) :- !,
|
|
|
|
'$purge_dontcares'(Vs,NVs).
|
|
|
|
'$purge_dontcares'([V|Vs],[V|NVs]) :-
|
|
|
|
'$purge_dontcares'(Vs,NVs).
|
|
|
|
|
|
|
|
|
|
|
|
'$prep_answer_var_by_var'([], L, L).
|
|
|
|
'$prep_answer_var_by_var'([[Name|Value]|L], LF, L0) :-
|
|
|
|
'$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'([], _, [], []).
|
|
|
|
'$delete_identical_answers'([[Name|Value]|L], Value0, FL, [Name|Names]) :-
|
|
|
|
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).
|
|
|
|
|
|
|
|
'$goal_to_string'(Format, G, String) :-
|
|
|
|
charsio:open_mem_write_stream(W),
|
|
|
|
format(W,Format,G),
|
|
|
|
charsio:peek_mem_write_stream(W, [], String),
|
|
|
|
close(W).
|
|
|
|
|
|
|
|
'$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :-
|
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
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).
|
2006-05-24 03:35:39 +01:00
|
|
|
'$write_goal_output'(nonvar([V|VL],B), First, [nonvar([V|VL],B)|L], next, L) :-
|
|
|
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
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),
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,' = ', []),
|
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,B,Opts) ;
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error,'~w',[B])
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2006-05-24 03:35:39 +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]
|
|
|
|
).
|
|
|
|
'$write_goal_output'(_-G, First, [G|NG], next, NG) :-
|
|
|
|
( 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
|
|
|
).
|
|
|
|
|
|
|
|
'$name_vars_in_goals'(G, VL0, NG) :-
|
2005-10-28 18:38:50 +01:00
|
|
|
copy_term_nat(G+VL0, NG+NVL0),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$name_well_known_vars'(NVL0),
|
|
|
|
'$variables_in_term'(NG, [], NGVL),
|
|
|
|
'$name_vars_in_goals1'(NGVL, 0, _).
|
|
|
|
|
|
|
|
'$name_well_known_vars'([]).
|
|
|
|
'$name_well_known_vars'([[Name|V]|NVL0]) :-
|
|
|
|
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).
|
|
|
|
'$name_vars_in_goals1'(['$VAR'([95|Name])|NGVL], I0, IF) :-
|
|
|
|
I is I0+1,
|
|
|
|
'$gen_name_string'(I0,[],Name), !,
|
|
|
|
'$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) :-
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks: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
|
|
|
|
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) ).
|
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) ).
|
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),
|
2006-12-27 01:32:38 +00:00
|
|
|
yap_hacks: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
|
|
|
(
|
2003-05-02 15:37: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
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$call'((X->Y; Z),CP,G0,M) :- !,
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2003-05-02 15:37: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
|
|
|
).
|
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) :- !,
|
|
|
|
(
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(X,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
->
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(Y,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
;
|
2003-05-02 15:37:11 +01:00
|
|
|
'$call'(Z,CP,G0,M)
|
2003-01-29 14:47:17 +00:00
|
|
|
).
|
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) :- !,
|
|
|
|
\+ '$execute'(M:X).
|
2006-03-24 16:26:31 +00:00
|
|
|
'$call'(not(X), _CP, _G0, _M) :- !,
|
2006-11-27 17:42:03 +00:00
|
|
|
\+ '$execute'(M:X).
|
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) ->
|
|
|
|
(
|
|
|
|
user:goal_expansion(G, CurMod, NG) ->
|
|
|
|
'$call'(NG, CP, G0,CurMod)
|
|
|
|
;
|
|
|
|
% repeat other code.
|
|
|
|
'$is_metapredicate'(G,CurMod) ->
|
|
|
|
(
|
|
|
|
'$meta_expansion'(CurMod,CurMod,G,NG,[]) ->
|
|
|
|
'$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).
|
|
|
|
'$check_callable'(M:G1,G) :- var(M), !,
|
|
|
|
'$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]) :-
|
2004-12-08 04:45:04 +00:00
|
|
|
% make sure we do not loop on undefined predicates
|
|
|
|
% for undefined_predicates.
|
|
|
|
'$enter_undefp',
|
2005-10-21 17:09:03 +01:00
|
|
|
'$find_undefp_handler'(G,M,Goal,NM), !,
|
2006-01-08 03:12:02 +00:00
|
|
|
'$execute0'(Goal,NM).
|
2004-12-07 04:35:22 +00:00
|
|
|
|
2006-01-07 02:12:32 +00:00
|
|
|
'$find_undefp_handler'(G,M,G,S) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(G,F,N),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$import','$import'(S,M,F,N),_),
|
2001-06-06 20:10:51 +01:00
|
|
|
S \= M, % can't try importing from the module itself.
|
2001-04-27 17:02:43 +01:00
|
|
|
!,
|
2006-01-07 02:12:32 +00:00
|
|
|
'$exit_undefp'.
|
2006-01-08 03:16:24 +00:00
|
|
|
/*
|
2005-10-21 17:09:03 +01:00
|
|
|
'$find_undefp_handler'(G,M,NG,M) :-
|
2004-12-05 05:01:45 +00:00
|
|
|
'$is_expand_goal_or_meta_predicate'(G,M),
|
2004-12-07 04:35:22 +00:00
|
|
|
'$system_catch'(goal_expansion(G, M, NG), user, _, fail), !,
|
2005-10-21 17:09:03 +01:00
|
|
|
'$exit_undefp'.
|
2006-01-08 03:16:24 +00:00
|
|
|
*/
|
2005-10-21 17:09:03 +01:00
|
|
|
'$find_undefp_handler'(G,M,NG,user) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
\+ '$undefined'(unknown_predicate_handler(_,_,_), user),
|
2005-10-21 17:09:03 +01:00
|
|
|
'$system_catch'(unknown_predicate_handler(G,M,NG), user, Error, '$leave_undefp'(Error)), !,
|
|
|
|
'$exit_undefp'.
|
|
|
|
'$find_undefp_handler'(G,M,US,user) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$unknown','$unknown'(M:G,US),_), !,
|
2005-10-21 17:09:03 +01:00
|
|
|
'$exit_undefp'.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$find_undefp_handler'(_,_,_,_) :-
|
2004-12-08 04:45:04 +00:00
|
|
|
'$exit_undefp',
|
2004-12-07 04:35:22 +00:00
|
|
|
fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-02-24 22:24:44 +00:00
|
|
|
'$leave_undefp'(Ball) :-
|
|
|
|
'$exit_undefp',
|
|
|
|
throw(Ball).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* This is the break predicate,
|
|
|
|
it saves the importante data about current streams and
|
|
|
|
debugger state */
|
|
|
|
|
2004-10-22 17:53:20 +01:00
|
|
|
break :-
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_getval('$trace',Trace),
|
|
|
|
nb_setval('$trace',off),
|
|
|
|
nb_getval('$debug',Debug),
|
|
|
|
nb_setval('$debug',off),
|
|
|
|
nb_getval('$break',BL), NBL is BL+1,
|
|
|
|
nb_getval('$spy_gn',SPY_GN),
|
|
|
|
b_getval('$spy_glist',GList),
|
|
|
|
b_setval('$spy_glist',[]),
|
|
|
|
nb_setval('$break',NBL),
|
2001-04-09 20:54:03 +01:00
|
|
|
current_output(OutStream), current_input(InpStream),
|
2004-07-22 22:32:23 +01:00
|
|
|
format(user_error, '% Break (level ~w)~n', [NBL]),
|
2002-01-16 22:11:55 +00:00
|
|
|
'$do_live',
|
2001-04-09 20:54:03 +01:00
|
|
|
!,
|
2003-08-27 14:37:10 +01:00
|
|
|
set_value('$live','$true'),
|
2006-12-13 16:10:26 +00:00
|
|
|
b_setval('$spy_glist',GList),
|
|
|
|
nb_setval('$spy_gn',SPY_GN),
|
2001-09-21 18:08:36 +01:00
|
|
|
'$set_input'(InpStream), '$set_output'(OutStream),
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_setval('$debug',Debug),
|
|
|
|
nb_setval('$trace',Trace),
|
|
|
|
nb_setval('$break',BL).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
'$silent_bootstrap'(F) :-
|
2006-12-27 12:27:15 +00:00
|
|
|
'$allocate_default_arena'(1024, 64),
|
2005-10-28 18:38:50 +01:00
|
|
|
get_value('$lf_verbose',OldSilent),
|
|
|
|
set_value('$lf_verbose',silent),
|
|
|
|
bootstrap(F),
|
|
|
|
set_value('$lf_verbose', OldSilent).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-19 02:47:43 +01:00
|
|
|
bootstrap(F) :-
|
2006-11-27 17:42:03 +00:00
|
|
|
'$open'(F,'$csult',Stream,0,0),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$current_stream'(File,_,Stream),
|
2005-10-19 02:47:43 +01:00
|
|
|
'$start_consult'(consult, File, LC),
|
|
|
|
file_directory_name(File, Dir),
|
2005-11-23 13:24:00 +00:00
|
|
|
getcwd(OldD),
|
2005-10-19 02:47:43 +01:00
|
|
|
cd(Dir),
|
2005-10-28 18:38:50 +01:00
|
|
|
(
|
|
|
|
get_value('$lf_verbose',silent)
|
|
|
|
->
|
|
|
|
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),
|
2005-10-19 02:47:43 +01:00
|
|
|
cd(OldD),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$end_consult',
|
2005-10-28 18:38:50 +01:00
|
|
|
(
|
|
|
|
get_value('$lf_verbose',silent)
|
|
|
|
->
|
|
|
|
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])
|
|
|
|
),
|
2001-04-09 20:54:03 +01:00
|
|
|
!.
|
|
|
|
|
|
|
|
|
|
|
|
'$loop'(Stream,Status) :-
|
2001-04-16 17:41:04 +01:00
|
|
|
'$change_alias_to_stream'('$loop_stream',Stream),
|
2001-04-09 20:54:03 +01:00
|
|
|
repeat,
|
2002-01-07 06:28:04 +00:00
|
|
|
( '$current_stream'(_,_,Stream) -> true
|
2002-04-09 16:12:14 +01:00
|
|
|
; '$abort_loop'(Stream)
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
|
|
|
prompt('| '), prompt(_,'| '),
|
2002-04-09 16:12:14 +01:00
|
|
|
'$current_module'(OldModule),
|
2002-01-07 06:28:04 +00:00
|
|
|
'$system_catch'('$enter_command'(Stream,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
|
|
|
|
|
|
|
'$enter_command'(Stream,Status) :-
|
2005-10-21 17:09:03 +01:00
|
|
|
'$read_vars'(Stream,Command,_,_,Vars),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$command'(Command,Vars,Status).
|
|
|
|
|
|
|
|
'$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'(_,_).
|
|
|
|
|
|
|
|
% Path predicates
|
|
|
|
|
2005-02-08 18:05:21 +00:00
|
|
|
'$exists'(F,Mode) :-
|
|
|
|
get_value(fileerrors,V),
|
|
|
|
set_value(fileerrors,0),
|
2006-11-27 17:42:03 +00:00
|
|
|
( '$open'(F,Mode,S,0,1) -> '$close'(S), set_value(fileerrors,V) ; set_value(fileerrors,V), fail).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2006-11-18 01:40:42 +00:00
|
|
|
% 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
|
2002-02-08 22:19:24 +00:00
|
|
|
'$find_in_path'(user,user_input, _) :- !.
|
|
|
|
'$find_in_path'(user_input,user_input, _) :- !.
|
2006-08-30 02:06:30 +01:00
|
|
|
'$find_in_path'(library(File),NewFile, _) :-
|
2006-11-18 01:40:42 +00:00
|
|
|
'$dir_separator'(D),
|
2006-08-30 02:06:30 +01:00
|
|
|
atom_codes(A,[D]),
|
2006-12-13 16:10:26 +00:00
|
|
|
user:library_directory(Dir),
|
2006-10-18 14:47:32 +01:00
|
|
|
'$extend_path'(Dir, A, File, NFile, Goal),
|
2006-08-30 02:06:30 +01:00
|
|
|
'$search_in_path'(NFile, NewFile), !.
|
2002-02-08 22:19:24 +00:00
|
|
|
'$find_in_path'(S,NewFile, _) :-
|
|
|
|
S =.. [Name,File], !,
|
|
|
|
'$dir_separator'(D),
|
|
|
|
atom_codes(A,[D]),
|
2006-12-13 16:10:26 +00:00
|
|
|
user:file_search_path(Name, Dir),
|
2006-10-18 14:47:32 +01:00
|
|
|
'$extend_path'(Dir, A, File, NFile, Goal),
|
2006-08-30 02:06:30 +01:00
|
|
|
'$search_in_path'(NFile, NewFile), !.
|
2002-02-08 22:19:24 +00:00
|
|
|
'$find_in_path'(File,NewFile,_) :- atom(File), !,
|
|
|
|
'$search_in_path'(File,NewFile),!.
|
|
|
|
'$find_in_path'(File,_,Call) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(domain_error(source_sink,File),Call).
|
2002-02-08 22:19:24 +00:00
|
|
|
|
|
|
|
'$search_in_path'(New,New) :-
|
|
|
|
'$exists'(New,'$csult'), !.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$search_in_path'(File,New) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$path',Path,_),
|
2002-02-08 22:19:24 +00:00
|
|
|
atom_concat([Path,File],New),
|
|
|
|
'$exists'(New,'$csult').
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2006-10-18 14:47:32 +01:00
|
|
|
'$extend_path'(Dir, A, File, NFile, _) :-
|
2005-03-13 06:26:13 +00:00
|
|
|
atom(Dir), !,
|
|
|
|
atom_concat([Dir,A,File],NFile).
|
2006-10-18 14:47:32 +01:00
|
|
|
'$extend_path'(Name, A, File, NFile, Goal) :-
|
2005-03-13 06:26:13 +00:00
|
|
|
nonvar(Name),
|
2006-10-18 14:47:32 +01:00
|
|
|
Name =.. [_,_],
|
|
|
|
'$find_in_path'(Name, Path, Goal),
|
|
|
|
'$extend_path'(Path, A, File, NFile, Goal).
|
2005-03-13 06:26:13 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
% term expansion
|
|
|
|
%
|
|
|
|
% return two arguments: Expanded0 is the term after "USER" expansion.
|
|
|
|
% Expanded is the final expanded term.
|
|
|
|
%
|
2001-11-15 00:01:43 +00:00
|
|
|
'$precompile_term'(Term, Expanded0, Expanded, Mod) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
|
|
|
'$access_yap_flags'(9,1) /* strict_iso on */
|
|
|
|
->
|
2001-11-15 00:01:43 +00:00
|
|
|
'$expand_term_modules'(Term, Expanded0, Expanded, Mod),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_iso_strict_clause'(Expanded0)
|
|
|
|
;
|
2001-11-15 00:01:43 +00:00
|
|
|
'$expand_term_modules'(Term, Expanded0, ExpandedI, Mod),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_array_accesses_in_term'(ExpandedI,Expanded)
|
|
|
|
).
|
|
|
|
|
|
|
|
expand_term(Term,Expanded) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
( \+ '$undefined'(term_expansion(_,_), user),
|
2006-12-13 16:10:26 +00:00
|
|
|
user:term_expansion(Term,Expanded)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
'$expand_term_grammar'(Term,Expanded)
|
|
|
|
),
|
2005-02-08 04:05:39 +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_term_arith'(G1, G2) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$c_arith',true),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$c_arith'(G1, G2), !.
|
|
|
|
'$expand_term_arith'(G,G).
|
|
|
|
|
|
|
|
|
|
|
|
%
|
|
|
|
% Arithmetic expansion
|
|
|
|
%
|
|
|
|
'$expand_array_accesses_in_term'(Expanded0,ExpandedF) :-
|
|
|
|
'$array_refs_compiled',
|
|
|
|
'$c_arrays'(Expanded0,ExpandedF), !.
|
|
|
|
'$expand_array_accesses_in_term'(Expanded,Expanded).
|
|
|
|
|
|
|
|
%
|
|
|
|
% Module system expansion
|
|
|
|
%
|
2001-11-15 00:01:43 +00:00
|
|
|
'$expand_term_modules'(A,B,C,M) :- '$module_expansion'(A,B,C,M), !.
|
|
|
|
'$expand_term_modules'(A,A,A,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
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,_),
|
2002-01-24 23:55:34 +00:00
|
|
|
'$execute'(G).
|
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,_),
|
2004-05-13 21:54:58 +01:00
|
|
|
'$execute_nonstop'(G, M).
|
2002-01-24 23:55:34 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% throw has to be *exactly* after system catch!
|
|
|
|
%
|
|
|
|
throw(Ball) :-
|
|
|
|
% get this off the unwound computation.
|
|
|
|
copy_term(Ball,NewBall),
|
|
|
|
% get current jump point
|
|
|
|
'$jump_env_and_store_ball'(NewBall).
|
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'(_, _, _).
|
|
|
|
'$handle_throw'(C, A, Ball) :-
|
2002-01-07 06:28:04 +00:00
|
|
|
% reset info
|
2004-11-19 21:32:53 +00:00
|
|
|
(Ball \== '$abort', C = Ball ->
|
2002-01-07 06:28:04 +00:00
|
|
|
'$execute'(A)
|
|
|
|
;
|
|
|
|
throw(Ball)
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$run_toplevel_hooks' :-
|
2006-12-13 16:10:26 +00:00
|
|
|
nb_getval('$break',0),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$toplevel_hooks',H,_), !,
|
2006-12-13 16:10:26 +00:00
|
|
|
( '$execute'(H) -> true ; true).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$run_toplevel_hooks'.
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
'$enter_system_mode' :-
|
|
|
|
nb_setval('$system_mode',on).
|
|
|
|
|
|
|
|
'$exit_system_mode' :-
|
|
|
|
nb_setval('$system_mode',off),
|
|
|
|
( nb_getval('$trace',on) -> '$creep' ; true).
|
|
|
|
|