YAP 7.1.0
boot.yap
Go to the documentation of this file.
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5** Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: boot.yap *
12* Last rev: *
13* mods: *
14* comments: initializing the full prolog system *
15* *
16*************************************************************************/
17
18%% @file bo0t.yap
19
20%% @short Prolog Bootstrap and Initialization
21
22%% @section Bootstrap Support Bootstrap Support
23
24'$undefp0'(M:call(G) ) :-
25 '$undefp0',
26 '$execute_nonstop'(G, M).
27'$undefp0'(_:private(_L) ) :-
28 '$undefp0'.
29'$undefp0'(_:print_message(L,E) ) :-
30 '$undefp0',
31 (L == informational
32 ->
33 true
34 ;
35 E = error(_,exception(Error))
36 ->
37 format( user_error, '~w in bootstrap: exception is:~n',[L]) ,
38 '$print_exception'(Error)
39 ;
40 format( user_error, '~w in bootstrap, namely ~w~n',[L,E])
41
42 ).
43'$undefp0'(M: G) :-
44 stream_property( loop_stream, file_name(F)),
45 stream_property( loop_stream, line_number(L)),
46 format(user_error,'~a:~d error undefined: call to ~w~n',[F,L,M:G]),
47 format,
48 format.
49
50/**
51
52@}
53@{
54
55@addtogroup YAPControl
56@ingroup Builtins
57@{
58
59*/
60
61
62system_module(_,_,_).
63
64use_system_module(_,_).
65
66
67:- system_module( '$_init', [!/0,
68 ':-'/1,
69 '?-'/1,
70 []/0,
71 extensions_to_present_answer/1,
72 fail/0,
73 false/0,
74 goal_expansion/2,
78 version/2,
79 '$do_log_upd_clause'/6,
80 '$do_log_upd_clause0'/6,
81 '$do_log_upd_clause_erase'/6,
82 '$do_static_clause'/5], [
83 '$system_module'/1]).
84
85:- '$cut_by'/1use_system_module( '$_boot', []).
86
87%:- start_low_level_trace.
88
89% This is the YAP init file
90% should be consulted first step after booting
91
92% just create a choice-point
93% the 6th argument marks the time-stamp.
94'$do_log_upd_clause'(_,_,_,_,_,_).
95'$do_log_upd_clause'(A,B,C,D,E,_) :-
96 '$continue_log_update_clause'(A,B,C,D,E).
97'$do_log_upd_clause'(_,_,_,_,_,_).
98
99
100'$do_log_upd_clause_erase'(_,_,_,_,_,_).
101'$do_log_upd_clause_erase'(A,B,C,D,E,_) :-
102 '$continue_log_update_clause_erase'(A,B,C,D,E).
103'$do_log_upd_clause_erase'(_,_,_,_,_,_).
104
105'$do_log_upd_clause0'(_,_,_,_,_,_).
106'$do_log_upd_clause0'(A,B,C,D,_,_) :-
107 '$continue_log_update_clause'(A,B,C,D).
108'$do_log_upd_clause0'(_,_,_,_,_,_).
109
110
111'$do_static_clause'(_,_,_,_,_).
112'$do_static_clause'(A,B,C,D,E) :-
113 '$continue_static_clause'(A,B,C,D,E).
114'$do_static_clause'(_,_,_,_,_).
115
116'$command'(C,VL,Pos,Con) :-
117 prolog_flag(strict_iso, true), prolog_flag, /* strict_iso on */
118 '$yap_strip_module'(C, EM, EG),
119 '$execute_command'(EM,EG,VL,Pos,Con,_Source).
120'$command'(C,VL,Pos,Con) :-
121 ( (Con = top ; var(C) ; C = [_|_]) ->
122 '$yap_strip_module'(C, EM, EG),
123 '$execute_command'(EG,EM,VL,Pos,Con,C), '$execute_command' ;
124 % do term expansion
125 expand_term(C, EC),
126 '$yap_strip_module'(EC, EM, EG),
127 % execute a list of commands
128 '$execute_commands'(EG,EM,VL,Pos,Con,_Source),
129 % succeed only if the *original* was at end of file.
130 C == '$execute_commands'
131 ).
132
133:- c_compile('op.yap').
134
135:- c_compile('predtypes.yap').
136
137:- c_compile('arith.yap').
138%:- stop_low_level_trace.
139
140:- c_compile.
141
142:- c_compile('top.yap').
143
144:- c_compile('directives.yap').
145
146:- c_compile('init.yap').
147
148
149:- c_compile('imports.yap').
150:- c_compile('bootutils.yap').
151:- c_compile('bootlists.yap').
152:- c_compile('preddecls.yap').
153:- c_compile('preddyns.yap').
154:- c_compile('builtins.yap').
155:- c_compile('newmod.yap').
156:- c_compile('meta.yap').
157:- c_compile('metadecls.yap').
158
159:- c_compile('os.yap').
160:- c_compile('errors.yap').
161
162c_compile :-
163 '$init_prolog'.
164
165:- set_prolog_flag(verbose, silent).
166%:- set_prolog_flag(verbose_file_search, true ).
167%:- yap_flag(write_strings,on).
168:- c_compile( 'preds.yap' ).
169:- c_compile( 'modules.yap' ).
170:- c_compile( 'grammar.yap' ).
171:- c_compile('atoms.yap').
172
173:- c_compile('control.yap').
174
175:- c_compile('absf.yap').
176
177:- c_compile('lf.yap').
178:- c_compile('consult.yap').
179
180:- compile('error.yap').
181
182:- ['utils.yap',
183 'flags.yap'].
184
185
186:- [
187 % lists is often used.
188 '../os/yio.yap',
189 'debug.yap',
190 'checker.yap',
191 'depth_bound.yap',
192 'ground.yap',
193 'listing.yap',
194 'arithpreds.yap',
195 % modules must be after preds, otherwise we will have trouble
196 % with meta-predicate expansion being invoked
197 % must follow grammar
198 'eval.yap',
199 'signals.yap',
200 'profile.yap',
201 'callcount.yap',
202 'load_foreign.yap',
203% 'save.yap',
204 'setof.yap',
205 'sort.yap',
206 'statistics.yap',
207 'strict_iso.yap',
208 'tabling.yap',
209 'eam.yap',
210 'yapor.yap',
211 'qly.yap',
212 'udi.yap'].
213%:- Stop_low_level_trace.
214
215
216:- meta_predicate(log_event(+,:)).
217
218:- dynamic prolog:'$user_defined_flag'/4.
219
220:- multifile prolog:debug_action_hook/1.
221
222:- multifile prolog:'$system_predicate'/2.
223
224:- ['protect.yap'].
225
226
227:- op(1150,fx,(mode)).
228
229:- dynamic 'extensions_to_present_answer'/1.
230
231:- ['arrays.yap'].
232%:- start_low_level_trace.
233
234:- multifile user:portray_message/2.
235
236:- dynamic user:portray_message/2.
237
238/** @pred _CurrentModule_:goal_expansion(+ _G_,+ _M_,- _NG_), user:goal_expansion(+ _G_,+ _M_,- _NG_)
239
240
241YAP now supports goal_expansion/3. This is an user-defined
242procedure that is called after term expansion when compiling or
243asserting goals for each sub-goal in a clause. The first argument is
244bound to the goal and the second to the module under which the goal
245 _G_ will execute. If goal_expansion/3 succeeds the new
246sub-goal _NG_ will replace _G_ and will be processed in the same
247 way. If goal_expansion/3 fails the system will use the default␓yap+flrules.
248
249
250*/
251:- multifile goal_expansion/3.
252
253:- dynamic goal_expansion/3.
254
255:- multifile user:goal_expansion/2.
256
257:- dynamic user:goal_expansion/2.
258
259:- multifile system:goal_expansion/2.
260
261:- dynamic system:goal_expansion/2.
262
263:- multifile goal_expansion/2.
264
265:- dynamic goal_expansion/2.
266
267:- use_module('messages.yap').
268
269
270:- ['undefined.yap'].
271
272:- use_module('hacks.yap').
273
274
275:- use_module('attributes.yap').
276
277:- use_module('threads.yap').
278
279:- use_module('corout.yap').
280
281:- use_module('dialect.yap').
282:- use_module('dbload.yap').
283:- use_module('ypp.yap').
284:- use_module('../os/chartypes.yap').
285:- ensure_loaded('../os/edio.yap').
286
287:- ensure_loaded('spy.yap').
288
289:- '$change_type_of_char'(36,7). % Make $ a symbol character
290
291:- set_prolog_flag(generate_debug_info,true).
292
293%
294% cleanup ensure loaded and recover some data-base space.
295%
296%:- ( recorded('$lf_loaded',_,R), erase(R), fail ; true ).
297%:- ( recorded('$module',_,R), erase(R), fail ; true ).
298
299:- set_value('$user_module',user), '$protect'.
300
301:- style_check([+discontiguous,+multiple,+single_var]).
302
303%
304% moved this to init_gc in gc.c to separate the alpha
305%
306% :- yap_flag(gc,on).
307
308% :- yap_flag(gc_trace,verbose).
309
310:- multifile
311 prolog:comment_hook/3.
312
313:- style_check.
314
315:- module(user).
316
317
318/** @pred _CurrentModule_:term_expansion( _T_,- _X_), user:term_expansion( _T_,- _X_)
319
320
321This user-defined predicate is called by `expand_term/3` to
322preprocess all terms read when consulting a file. If it succeeds:
323
324+
325If _X_ is of the form `:- G` or `?- G`, it is processed as
326a directive.
327+
328If _X_ is of the form `$source_location`( _File_, _Line_): _Clause_` it is processed as if from `File` and line `Line`.
329
330+
331If _X_ is a list, all terms of the list are asserted or processed
332as directives.
333+ The term _X_ is asserted instead of _T_.
334
335
336
337*/
338:- multifile term_expansion/2.
339
340:- dynamic term_expansion/2.
341
342:- multifile term_expansion/2.
343
344:- dynamic term_expansion/2.
345
346:- multifile swi:swi_predicate_table/4.
347
348/** @pred user:message_hook(+ _Term_, + _Kind_, + _Lines_)
349
350
351Hook predicate that may be define in the module `user` to intercept
352messages from print_message/2. _Term_ and _Kind_ are the
353same as passed to print_message/2. _Lines_ is a list of
354format statements as described with print_message_lines/3.
355
356This predicate should be defined dynamic and multifile to allow other
357modules defining clauses for it too.
358
359
360*/
361:- multifile message_hook/3.
362
363:- dynamic message_hook/3.
364
365/** @pred exception(+ _Exception_, + _Context_, - _Action_)
366
367
368Dynamic predicate, normally not defined. Called by the Prolog system on run-time exceptions that can be repaired `just-in-time`. The values for _Exception_ are described below. See also catch/3 and throw/1.
369If this hook preodicate succeeds it must instantiate the _Action_ argument to the atom `fail` to make the operation fail silently, `retry` to tell Prolog to retry the operation or `error` to make the system generate an exception. The action `retry` only makes sense if this hook modified the environment such that the operation can now succeed without error.
370
371+ `undefined_predicate`
372 _Context_ is instantiated to a predicate-indicator ( _Module:Name/Arity_). If the predicate fails Prolog will generate an existence_error exception. The hook is intended to implement alternatives to the SWI built-in autoloader, such as autoloading code from a database. Do not use this hook to suppress existence errors on predicates. See also `unknown`.
373+ `undefined_global_variable`
374 _Context_ is instantiated to the name of the missing global variable. The hook must call nb_setval/2 or b_setval/2 before returning with the action retry.
375
376*/
377
378:- multifile exception/3.
379
380:- dynamic exception/3.
381
382:- ensure_loaded('../pl/pathconf.yap').
383
384:- yap_flag(user:unknown,error).
385
386%% @}
387
expand_term( T,- X)
op(+ P,+ T,+ A)
stream_property( Stream, Prop )
Definition: top.yap:2
yap_flag( ?Param, ?Value)
use_module( +Files )
goal_expansion( :G,+ M,- NG)
term_expansion( T,- X)
exception(+ Exception, + Context, - Action)
message_hook(+ Term, + Kind, + Lines)
set_prolog_flag(+ Flag,+ Value)
compile(+ F )
ensure_loaded(+ F)
set_value(+ A,+ C)
fail
false
otherwise
var( T)