This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/pl/init.yap

260 lines
6.5 KiB
Plaintext
Raw Normal View History

/*************************************************************************
* *
* YAP Prolog *
* *
2015-08-18 21:08:52 +01:00
** Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: init.yap *
* Last rev: *
* mods: *
* comments: initializing the full prolog system *
* *
*************************************************************************/
2018-05-10 13:11:56 +01:00
/**
* @file init.yap
*
* @brief how to boot and run the top-level.
*
*/
2018-05-10 13:11:56 +01:00
/**
2018-06-05 20:51:49 +01:00
* @ingroup YAPControl
* @{
2018-05-10 13:11:56 +01:00
*
*/
2018-03-14 00:41:05 +00:00
'$init_globals' :-
% set_prolog_flag(break_level, 0),
% '$set_read_error_handler'(error), let the user do that
nb_setval('$chr_toplevel_show_store',false).
'$init_consult' :-
2018-07-11 22:15:54 +01:00
set_value('$open_expands_filename',true),
nb_setval('$assert_all',off),
nb_setval('$if_level',0),
nb_setval('$endif',off),
nb_setval('$initialization_goals',off),
nb_setval('$included_file',[]),
nb_setval('$loop_streams',[]),
2018-07-12 11:02:09 +01:00
(
'$undefined'('$init_preds',prolog)
->
true
;
'$init_preds'
).
2018-03-14 00:41:05 +00:00
'$init_win_graphics' :-
'$undefined'(window_title(_,_), system), !.
'$init_win_graphics' :-
load_files([library(win_menu)], [silent(true),if(not_loaded)]),
fail.
'$init_win_graphics'.
'$init_or_threads' :-
'$c_yapor_workers'(W), !,
'$start_orp_threads'(W).
'$init_or_threads'.
'$start_orp_threads'(1) :- !.
'$start_orp_threads'(W) :-
thread_create('$c_worker',_,[detached(true)]),
W1 is W-1,
'$start_orp_threads'(W1).
'$version' :-
current_prolog_flag(verbose, normal), !,
current_prolog_flag(version_git,VersionGit),
current_prolog_flag(compiled_at,AT),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
current_prolog_flag(resource_database, Saved ),
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
2019-02-15 13:50:24 +00:00
format(user_error, '% database loaded from ~a~n', [Saved]),
fail.
2018-03-14 00:41:05 +00:00
'$version'.
/**
* Initialise a Prolog engine.
*
* Must be called after restoring.
*/
'$init_prolog' :-
2019-02-15 13:50:24 +00:00
'$init_step'(_),
fail.
'$init_prolog'.
% do catch as early as possible
'$init_step'(1) :-
'$version'.
'$init_step'(2) :-
2019-02-21 21:03:44 +00:00
set_prolog_flag(file_name_variables, true),
2019-02-15 13:50:24 +00:00
'$init_consult'.
%set_prolog_flag(file_name_variables, OldF),
'$init_step'(3) :-
'$init_globals',
set_prolog_flag(fileerrors, true),
set_value('$gc',on),
('$exit_undefp' -> true ; true),
prompt1(' ?- '),
set_prolog_flag(debug, false).
% simple trick to find out if this is we are booting from Prolog.
% boot from a saved state
'$init_step'(4) :-
'$init_from_saved_state_and_args'.
'$init_step'(5) :-
'$db_clean_queues'(_).
2018-03-14 00:41:05 +00:00
% this must be executed from C-code.
% '$startup_saved_state',
2019-02-15 13:50:24 +00:00
'$init_step'(6) :-
2018-03-14 00:41:05 +00:00
set_input(user_input),
set_output(user_output),
'$init_or_threads',
'$run_at_thread_start'.
% then we can execute the programs.
'$startup_goals' :-
2019-02-15 13:50:24 +00:00
'$startup_step',
fail.
'$startup_step' :-
module(user).
'$startup_step' :-
recorded('$startup_goal',G,_),
catch(once(user:G),Error,user:'$Error'(Error)).
'$startup_step' :-
2018-03-14 00:41:05 +00:00
get_value('$init_goal',GA),
GA \= [],
set_value('$init_goal',[]),
2019-02-15 13:50:24 +00:00
'$run_atom_goal'(GA).
'$startup_step' :-
recorded('$restore_flag', goal(Module:GA), R),
erase(R),
catch(once(Module:GA),Error,user:'$Error'(Error)).
'$startup_step' :-
2018-03-14 00:41:05 +00:00
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)),
2019-02-15 13:50:24 +00:00
'$myddas_import_all'.
'$startup_step'.
2018-03-14 00:41:05 +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'.
% use if we come from a save_program and we have SWI's shlib
'$init_from_saved_state_and_args' :-
2019-02-15 13:50:24 +00:00
'$rebuild',
2018-03-14 00:41:05 +00:00
fail.
2019-02-15 13:50:24 +00:00
'$init_from_saved_state_and_args'.
'$rebuild' :-
current_prolog_flag(hwnd, _HWND),
load_files(library(win_menu), [silent(true)]).
'$rebuild' :-
2018-03-14 00:41:05 +00:00
recorded('$reload_foreign_libraries',_G,R),
erase(R),
2019-02-15 13:50:24 +00:00
shlib:reload_foreign_libraries.
2018-03-14 00:41:05 +00:00
% this should be done before -l kicks in.
2019-02-15 13:50:24 +00:00
'$rebuild' :-
2018-03-14 00:41:05 +00:00
current_prolog_flag(fast_boot, false),
( exists('~/.yaprc') -> load_files('~/.yaprc', []) ; true ),
( exists('~/.prologrc') -> load_files('~/.prologrc', []) ; true ),
( exists('~/prolog.ini') -> load_files('~/prolog.ini', []) ; true ),
fail.
% use if we come from a save_program and we have a goal to execute
2019-02-15 13:50:24 +00:00
'$rebuild' :-
2018-03-14 00:41:05 +00:00
get_value('$consult_on_boot',X), X \= [],
2019-02-15 13:50:24 +00:00
load_files(X, [silent(true)]),
set_value('$consult_on_boot',[]).
'$rebuild' :-
2018-03-14 00:41:05 +00:00
recorded('$restore_flag', init_file(M:B), R),
erase(R),
2019-02-15 13:50:24 +00:00
load_files(M:B, [silent(true)]).
'$rebuild' :-
2018-03-14 00:41:05 +00:00
recorded('$restore_flag', unknown(M:B), R),
erase(R),
2019-02-15 13:50:24 +00:00
load_files(M:B, [silent(true)]),
yap_flag(M:unknown,B).
'$rebuild' :-
'$startup_step'.
'$rebuild' :-
current_prolog_flag(halt_after_consult, true),
halt.
'$rebuild' :-
2018-03-14 00:41:05 +00:00
recorded('$restore_goal',G,R),
erase(R),
prompt(_,'| '),
2019-02-15 13:50:24 +00:00
catch(once(user:G),Error,user:'$Error'(Error)).
2018-03-14 00:41:05 +00:00
'$init_path_extensions' :-
get_value('$extend_file_search_path',P), !,
P \= [],
set_value('$extend_file_search_path',[]),
'$extend_file_search_path'(P).
'$init_path_extensions'.
2019-04-07 00:25:10 +01:00
2019-04-06 10:07:54 +01:00
/**
* @pred top_query(?0 Goal).
*
* run _Goal_ as f it had been called from the Prolog
* top-level.
*/
2019-04-07 00:25:10 +01:00
top_query(G) :-
2019-04-06 10:07:54 +01:00
'$init_step'(2), % consult
'$init_step'(3), % globals
'$init_step'(4), % check if a saved state,
'$init_step'(5), % queues
'$init_step'(6), % I/O, threads.
'$alarm'(0, 0, _, _),
'$clean_up_dead_clauses',
flush_output,
'$run_toplevel_hooks',
prompt1(' ?- '),
nb_setval('$spy_gn',1),
% stop at spy-points if debugging is on.
nb_setval('$debug_run',off),
nb_setval('$debug_jump',off),
'__NB_setval__'('$trace',off),
2019-05-20 01:00:41 +01:00
'$set_debugger_state'( zip, 0, stop,off),
2019-04-07 00:25:10 +01:00
set_prolog_flag(break_level, 0),
catch(user:G, Error, '$Error'(Error)).
2019-04-06 10:07:54 +01:00
2018-06-05 20:51:49 +01:00
/**
*
* @}
*/