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/boot.yap

313 lines
7.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 *
* *
2014-04-09 12:39:29 +01:00
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2014 *
* *
**************************************************************************
2016-05-10 15:23:22 +01:00
* *
* File: boot.yap *
* Last rev: 8/2/88 *
* mods: *
2016-06-03 16:53:43 +01:00
* commen ts: boot file for Prolog *
* *
*************************************************************************/
2014-11-02 12:10:32 +00:00
/**
2017-10-27 13:50:40 +01:00
@file boot.yap
@brief YAP bootstrap
2017-05-02 04:07:23 +01:00
2018-04-27 13:01:08 +01:00
2018-05-20 18:40:56 +01:00
@addtogroup TopLevel Top-Level and Boot Predicates
2017-10-27 13:50:40 +01:00
@ingroup builtins
2018-06-05 11:20:39 +01:00
@{
2015-07-06 12:04:42 +01:00
2016-01-20 22:36:16 +00:00
2017-04-07 23:10:59 +01:00
*/
2014-09-11 20:06:57 +01:00
2019-01-30 10:44:28 +00:00
/**
2019-01-30 15:24:06 +00:00
* @pred system_module( _Mod_, _ListOfPublicPredicates, ListOfPrivatePredicates *
2019-01-30 10:44:28 +00:00
* Define a system module _Mod_. _ListOfPublicPredicates_ . Currentlt, all
* predicates are in the 'prolog' module. The first
* are visible outside the Prolog module, all others are hidden at the end of booting.
*
*/
system_module(Mod, SysExps) :-
system_module(Mod, SysExps, []).
2019-01-31 12:46:35 +00:00
system_module(_Mod, _SysExps, _Decls) :- !.
2019-01-31 11:54:17 +00:00
system_module(_Mod, _SysExps, _Decls) :-
2019-01-30 15:24:06 +00:00
% '$new_system_predicates'(SysExps),
fail.
2019-01-31 11:52:03 +00:00
system_module(_Mod, _SysExps, _Decls) :-
stream_property(loop_stream,[file_name(File)]),
!,
recordz(system_file, File, _ ).
system_module(_Mod, _SysExps, _Decls) :-
recordz(system_file, loop_stream, _ ).
2014-04-09 12:39:29 +01:00
2019-01-30 15:24:06 +00:00
'$new_system_predicates'([]).
'$new_system_predicates'([N/Ar|_Ps]) :-
2019-01-30 10:44:28 +00:00
'$new_system_predicate'(N, Ar, prolog).
'$new_system_predicates'([_P|Ps]) :-
'$new_system_predicates'(Ps).
2014-04-09 12:39:29 +01:00
2019-01-31 11:52:03 +00:00
use_system_module(_Module, _SysExps).
private(_).
2014-04-09 12:39:29 +01:00
%
% boootstrap predicates.
%
2014-11-02 12:10:32 +00:00
:- system_module( '$_boot', [
2014-04-09 12:39:29 +01:00
bootstrap/1,
call/1,
catch/3,
catch_ball/2,
expand_term/2,
2019-01-30 10:44:28 +00:00
print_message/2,
2014-04-09 12:39:29 +01:00
import_system_module/2,
2019-01-30 10:44:28 +00:00
system_module/2,
private/1,
2014-04-09 12:39:29 +01:00
incore/1,
(not)/1,
repeat/0,
throw/1,
2019-01-31 12:46:35 +00:00
true/0]).
:- system_module( '$_init', [!/0,
':-'/1,
'?-'/1,
[]/0,
extensions_to_present_answer/1,
fail/0,
false/0,
goal_expansion/2,
goal_expansion/3,
otherwise/0,
term_expansion/2,
version/2],
[
'$do_log_upd_clause'/6,
'$do_log_upd_clause0'/6,
'$do_log_upd_clause_erase'/6,
'$do_static_clause'/5],
'$system_module'/1]).
:- use_system_module( '$_boot', ['$cut_by'/1]).
2014-04-09 12:39:29 +01:00
2018-02-21 13:02:20 +00:00
% be careful here not to generate an undefined exception..
2019-01-31 11:52:03 +00:00
print_message(informational,_) :-
yap_flag(verbose, silent),
!.
print_message(informational,E) :-
format('informational message ~q.~n',[E]),
!.
%%
% boot:print_message( Type, Error )
%
print_message(Type,error(_,exception(Desc))) :-
2019-01-30 10:44:28 +00:00
'$get_exception'(Desc),
2019-01-31 11:52:03 +00:00
print_boot_message(Type,Error,Desc),
'$print_exception'(Desc),
!.
print_message(Type,Error) :-
format( user_error, '~w while bootstraping: event is ~q~n',[Type,Error]).
print_boot_message(Type,Error,Desc) :-
'$query_exception'(parserFile, Desc, File),
'$query_exception'(parserLine, Desc, FilePos),
!,
format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]).
print_boot_message(Type,Error,Desc) :-
2019-01-30 10:44:28 +00:00
'$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos),
2019-01-31 11:52:03 +00:00
format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]).
print_boot_message(Type,Error,Desc) :-
'$query_exception'(errorFile, Desc, File),
'$query_exception'(errorLine, Desc, FilePos),
format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]).
2018-01-22 13:53:17 +00:00
'$undefp0'([M|G], _Action) :-
2019-01-31 11:54:17 +00:00
functor(G,N,A),
print_message( error, error(error(unknown, M:N/A),M:G)),
fail.
2011-03-09 23:28:30 +00:00
2018-01-22 13:53:17 +00:00
:- '$undefp_handler'('$undefp0'(_,_),prolog).
2018-01-18 14:47:27 +00:00
2018-04-07 19:45:18 +01:00
/**
* @pred $system_meta_predicates'( +L )
*
* @param L declare a set of system meta-predicates
*
* @return system predicates
*/
'$system_meta_predicates'([]).
'$system_meta_predicates'([P|L]) :-
functor(P,N,A),
'$new_meta_pred'(P, prolog),
G = ('$meta_predicate'(N,_M2,A,P) :- true),
'$compile'(G, assertz, G, prolog, _R),
'$system_meta_predicates'(L).
2019-01-30 10:44:28 +00:00
:- '$mk_dynamic'( prolog_file_type(_Ext, _NType), user).
:- '$new_multifile'( prolog_file_type(_Ext, _NType), user).
2019-01-09 09:32:09 +00:00
2019-01-30 10:44:28 +00:00
:- '$mk_dynamic'( '$meta_predicate'(_N,_M,_A,_P), prolog).
:- '$new_multifile'( '$meta_predicate'(_N,_M,_A,_P), prolog).
2019-01-09 09:32:09 +00:00
2018-04-07 19:45:18 +01:00
:- '$new_multifile'('$full_clause_optimisation'(_H, _M, _B0, _BF), prolog).
:- '$new_multifile'('$exec_directive'(_,_,_,_,_), prolog).
2018-01-18 14:47:27 +00:00
2018-02-14 00:13:13 +00:00
2018-01-18 14:47:27 +00:00
%:- start_low_level_trace.
% This is the YAP init file
% should be consulted first step after booting
2018-02-07 21:48:37 +00:00
:- yap_flag(prolog:unknown, error).
2018-01-22 13:53:17 +00:00
:- c_compile('top.yap').
2018-01-18 14:47:27 +00:00
% These are pseudo declarations
% so that the user will get a redefining system predicate
% just create a choice-point
% the 6th argument marks the time-stamp.
'$do_log_upd_clause'(_,_,_,_,_,_).
'$do_log_upd_clause'(A,B,C,D,E,_) :-
'$continue_log_update_clause'(A,B,C,D,E).
'$do_log_upd_clause'(_,_,_,_,_,_).
'$do_log_upd_clause_erase'(_,_,_,_,_,_).
'$do_log_upd_clause_erase'(A,B,C,D,E,_) :-
'$continue_log_update_clause_erase'(A,B,C,D,E).
'$do_log_upd_clause_erase'(_,_,_,_,_,_).
'$do_log_upd_clause0'(_,_,_,_,_,_).
'$do_log_upd_clause0'(A,B,C,D,_,_) :-
'$continue_log_update_clause'(A,B,C,D).
'$do_log_upd_clause0'(_,_,_,_,_,_).
'$do_static_clause'(_,_,_,_,_).
'$do_static_clause'(A,B,C,D,E) :-
'$continue_static_clause'(A,B,C,D,E).
'$do_static_clause'(_,_,_,_,_).
2018-01-22 13:53:17 +00:00
:- c_compile('directives.yap').
2018-03-14 00:41:05 +00:00
:- c_compile('init.yap').
2018-01-22 13:53:17 +00:00
2018-11-03 10:49:35 +00:00
'$command'(C,VL,Pos,Con) :-
2018-01-22 13:53:17 +00:00
current_prolog_flag(strict_iso, true), !, /* strict_iso on */
2018-02-07 21:48:37 +00:00
'$yap_strip_module'(C, EM, EG),
2018-05-16 00:00:12 +01:00
'$execute_command'(EG,EM,VL,Pos,Con,_Source).
2018-11-03 10:49:35 +00:00
'$command'(C,VL,Pos,Con) :-
2018-01-22 13:53:17 +00:00
( (Con = top ; var(C) ; C = [_|_]) ->
2019-01-30 10:44:28 +00:00
'$yap_strip_module'(C, EM, EG),
2018-04-09 13:42:06 +01:00
'$execute_command'(EG,EM,VL,Pos,Con,C) ;
2018-01-22 13:53:17 +00:00
% do term expansion
2018-02-20 22:59:17 +00:00
'$expand_term'(C, Con, EC),
2019-01-31 12:46:35 +00:00
( nonvar(EC) ->
2019-01-30 10:44:28 +00:00
'$yap_strip_module'(EC, EM2, EG2)
;
'$yap_strip_module'(C, EM2, EG2)
),
2018-01-22 13:53:17 +00:00
% execute a list of commands
2018-05-16 00:00:12 +01:00
'$execute_commands'(EG2,EM2,VL,Pos,Con,_Source)
2018-04-09 13:42:06 +01:00
),
2019-01-30 10:44:28 +00:00
% succeed only if the *original* was at end of file.
2018-04-09 13:42:06 +01:00
C == end_of_file.
2018-01-22 13:53:17 +00:00
2018-01-18 14:47:27 +00:00
:- c_compile('arith.yap').
%:- stop_low_level_trace.
:- compile_expressions.
:- c_compile('imports.yap').
:- c_compile('bootutils.yap').
:- c_compile('bootlists.yap').
:- c_compile('consult.yap').
:- c_compile('preddecls.yap').
:- c_compile('meta.yap').
2018-04-07 19:45:18 +01:00
:- c_compile('metadecls.yap').
:- c_compile('preddyns.yap').
2018-02-01 01:44:34 +00:00
:- c_compile('builtins.yap').
2018-01-18 14:47:27 +00:00
:- c_compile('newmod.yap').
:- c_compile('atoms.yap').
:- c_compile('os.yap').
:- c_compile('errors.yap').
2018-01-22 13:53:17 +00:00
2018-05-20 18:40:56 +01:00
%%
% @pred initialize_prolog
%
% User-interface to Prolog bootstrap routine.
%
2018-01-27 10:17:27 +00:00
initialize_prolog :-
'$init_prolog'.
2018-01-18 14:47:27 +00:00
2018-01-27 10:17:27 +00:00
:- set_prolog_flag(verbose, silent).
2018-01-18 14:47:27 +00:00
%:- set_prolog_flag(verbose_file_search, true ).
%:- yap_flag(write_strings,on).
2018-01-22 13:53:17 +00:00
:- c_compile( 'preds.yap' ).
:- c_compile( 'modules.yap' ).
:- c_compile( 'grammar.yap' ).
2019-01-31 11:52:03 +00:00
:- c_compile( 'protect.yap' ).
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
:- ['absf.yap'].
2018-02-14 14:17:57 +00:00
2018-01-22 13:53:17 +00:00
:- use_module('error.yap').
2018-01-18 14:47:27 +00:00
:- [
'utils.yap',
'control.yap',
'flags.yap'
].
:- [
% lists is often used.
'../os/yio.yap',
2018-03-02 21:18:24 +00:00
'debug.yap',
2018-01-18 14:47:27 +00:00
'checker.yap',
'depth_bound.yap',
'ground.yap',
'listing.yap',
'arithpreds.yap',
% modules must be after preds, otherwise we will have trouble
% with meta-predicate expansion being invoked
% must follow grammar
'eval.yap',
'signals.yap',
'profile.yap',
'callcount.yap',
'load_foreign.yap',
% 'save.yap',
'setof.yap',
'sort.yap',
'statistics.yap',
'strict_iso.yap',
'tabling.yap',
'threads.yap',
'eam.yap',
'yapor.yap',
'qly.yap',
'spy.yap',
2019-01-09 09:32:09 +00:00
'udi.yap',
'boot2.yap'].
2018-07-15 13:46:26 +01:00
2018-05-20 18:40:56 +01:00
%% @}
2018-11-22 13:48:21 +00:00