32:- system_module( '$_listing', [
listing/0,
37:-
'$do_error'/2
use_system_module(
'$_errors', []).
39:-
'$clause'/4
'$current_predicate'/4
use_system_module(
'$_preds', [,
75 '$current_module'(
Mod),
79 \+ '$hidden_atom'(
Mod ),
81 \+ '$undefined'(
Pred,
Mod),
83 '$listing'(
Name,
Arity,
Mod,
Stream),
106 strip_module(
MV,
M,
I),
107 '$mlisting'(
Stream,
I,
M).
108listing(
_Stream, [])
:- listing.
109listing(
Stream, [
MV|MVs])
:- listing,
113'$mlisting'(
Stream,
MV,
M)
:-
116 '$do_listing'(
Stream,
M,
NA)
120 '$do_listing'(
Stream,
M,
NA)
122 MV = N//Ar -> (
integer(
Ar)
-> Ar2 is Ar+2,
NA is N/Ar2 ; '$do_listing'(
Stream,
NA/Ar2,
M),
Ar2 >= 2,
Ar is Ar2-2 )
125 '$do_listing'(
Stream,
M,
MV)
127 MV = M1:PP -> '$mlisting'(
Stream,
PP,
M1)
129 '$do_error'(type_error(predicate_indicator,
MV),listing(
Stream,
MV) )
132'$do_listing'(
Stream,
M,
Name/Arity)
:-
134 \+ '$is_opaque_predicate'(
Pred,
M),
136 \+ '$undefined'(
Pred,
M),
137 '$listing'(
Name,
Arity,
M,
Stream),
146'$listing'(
Name,
Arity,
M,
Stream)
:-
149 '$list_clauses'(
Stream,
M,
Pred).
152'$funcspec'(
Name/Arity,
Name,
Arity)
:- '$funcspec',
atom(
Name).
153'$funcspec'(
Name,
Name,
_)
:- atom(
Name),
atom.
154'$funcspec'(
Name,
_,
_)
:-
155 '$do_error'(domain_error(predicate_spec,
Name),listing(
Name)).
157'$list_clauses'(
Stream,
M,
Pred)
:-
158 '$predicate_flags'(
Pred,
M,
Flags,
Flags),
159 (
Flags /\ 0x48602000
=\= 0
166'$list_clauses'(
Stream,
M,
Pred)
:-
167 (
'$is_dynamic'(
Pred,
M)
-> '$is_dynamic'
; '$is_log_updatable'(
Pred,
M) ),
169 '$current_module'(
Mod),
173 format(
Stream,
':- dynamic ~q/~d.~n', [
N,
Ar])
175 format(
Stream,
':- dynamic ~q:~q/~d.~n', [
M,
N,
Ar])
178'$list_clauses'(
Stream,
M,
Pred)
:-
179 '$is_thread_local'(
Pred,
M),
181 '$current_module'(
Mod),
185 format(
Stream,
':- thread_local ~q/~d.~n', [
N,
Ar])
187 format(
Stream,
':- thread_local ~q:~q/~d.~n', [
M,
N,
Ar])
190'$list_clauses'(
Stream,
M,
Pred)
:-
191 '$is_multifile'(
Pred,
M),
193 '$current_module'(
Mod),
197 format(
Stream,
':- multifile ~q/~d.~n', [
N,
Ar])
199 format(
Stream,
':- multifile ~q:~q/~d.~n', [
M,
N,
Ar])
202'$list_clauses'(
Stream,
M,
Pred)
:-
203 '$is_meta_predicate'(
Pred,
M),
205 functor(
PredDef,
Name,
Arity ),
206 (
recorded(
'$m',
meta_predicate(
M,
PredDef),
_)
;recorded(
'$m',
meta_predicate(prolog,
PredDef),
_)),
207 '$current_module'(
Mod),
211 format(
Stream,
':- ~q.~n', [
PredDef])
213 format(
Stream,
':- ~q:~q.~n', [
M,
PredDef])
216'$list_clauses'(
Stream,
_M,
_Pred)
:-
219'$list_clauses'(
Stream,
M,
Pred)
:-
220 '$predicate_type'(
Pred,
M,
Type),
221 (
Type == source_procedure
-> true
;
222 Type == updatable_procedure
-> true
;
223 Type == exo_procedure
-> true
;
224 Type == mega_procedure
-> true
226 '$clause'(
Type,
Pred,
M,
Body,
_),
227 '$current_module'(
Mod),
228 (
M \= Mod -> H = M:Pred ; H = Pred ),
229 '$portray_clause'(
Stream,(
H:-Body)),
237 yap_flag(numbervars_functor,
Old,
'$PORTRAY_VAR'),
238 '$portray_clause'(
Stream,
Clause),
252'$portray_clause'(
Stream, (
Pred :- true))
:- '$portray_clause',
253 '$beautify_vars'(
Pred),
254 format(
Stream,
'~q.~n', [
Pred]).
255'$portray_clause'(
Stream, (
Pred:-Body))
:- '$portray_clause',
256 '$beautify_vars'((
Pred:-Body)),
257 format(
Stream,
'~q :-', [
Pred]),
258 '$write_body'(
Body,
3,
',',
Stream),
259 format(
Stream,
'.~n', []).
260'$portray_clause'(
Stream,
Pred)
:-
261 '$beautify_vars'(
Pred),
262 format(
Stream,
'~q.~n', [
Pred]).
264'$write_body'(
X,
I,
T,
Stream)
:- var(
X),
var,
265 '$beforelit'(
T,
I,
Stream),
267'$write_body'((
P,
Q),
I,
T,
Stream)
:-
269 '$write_body'(
P,
I,
T,
Stream),
271 '$write_body'(
Q,
I,
',',
Stream).
272'$write_body'((
P->Q;S),
I,
_,
Stream)
:-
274 format(
Stream,
'~n~*c(',[
I,
0' ]),
276 '$write_body'(
P,
I1,
'(',
Stream),
277 format(
Stream,
'~n~*c->',[
I,
0' ]),
278 '$write_disj'((
Q;S),
I,
I1,
'->',
Stream),
279 format(
Stream,
'~n~*c)',[
I,
0' ]).
280'$write_body'((
P->Q|S),
I,
_,
Stream)
:-
282 format(
Stream,
'~n~*c(',[
I,
0' ]),
284 '$write_body'(
P,
I,
'(',
Stream),
285 format(
Stream,
'~n~*c->',[
I,
0' ]),
286 '$write_disj'((
Q|S),
I,
I1,
'->',
Stream),
287 format(
Stream,
'~n~*c)',[
I,
0' ]).
288'$write_body'((
P->Q),
I,
_,
Stream)
:-
290 format(
Stream,
'~n~*c(',[
I,
0' ]),
292 '$write_body'(
P,
I1,
'(',
Stream),
293 format(
Stream,
'~n~*c->',[
I,
0' ]),
294 '$write_body'(
Q,
I1,
'->',
Stream),
295 format(
Stream,
'~n~*c)',[
I,
0' ]).
296'$write_body'((
P;Q),
I,
_,
Stream)
:-
298 format(
Stream,
'~n~*c(',[
I,
0' ]),
300 '$write_disj'((
P;Q),
I,
I1,
'->',
Stream),
301 format(
Stream,
'~n~*c)',[
I,
0' ]).
302'$write_body'((
P|Q),
I,
_,
Stream)
:-
304 format(
Stream,
'~n~*c(',[
I,
0' ]),
306 '$write_disj'((
P|Q),
I,
I1,
'->',
Stream),
307 format(
Stream,
'~n~*c)',[
I,
0' ]).
308'$write_body'(
X,
I,
T,
Stream)
:-
309 '$beforelit'(
T,
I,
Stream),
315'$write_disj'((
Q;S),
I0,
I,
C,
Stream)
:- '$write_disj',
316 '$write_body'(
Q,
I,
C,
Stream),
317 format(
Stream,
'~n~*c;',[
I0,
0' ]),
318 '$write_disj'(
S,
I0,
I,
';',
Stream).
319'$write_disj'((
Q|S),
I0,
I,
C,
Stream)
:- '$write_disj',
320 '$write_body'(
Q,
I,
C,
Stream),
321 format(
Stream,
'~n~*c|',[
I0,
0' ]),
322 '$write_disj'(
S,
I0,
I,
'|',
Stream).
323'$write_disj'(
S,
_,
I,
C,
Stream)
:-
324 '$write_body'(
S,
I,
C,
Stream).
327'$beforelit'(
'(',
_,
Stream)
:-
329 format(
Stream,
' ',[]).
330'$beforelit'(
_,
I,
Stream)
:- format(
Stream,
'~n~*c',[
I,
0' ]).
332'$beautify_vars'(
T)
:-
333 '$singleton_vs_numbervars'(
T,
0,
_).
336
yap_flag( ?Param, ?Value)