YAP 7.1.0
preddecls.yap
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: preds.yap *
12* Last rev: 8/2/88 *
13* mods: *
14* comments: Predicate Manipulation for YAP: declaration support *
15* *
16*************************************************************************/
17:- system_module( '$_preddecls', [(discontiguous)/1,
18 (dynamic)/1,
19 (multifile)/1,
20 (discontiguous)/1], ['$check_multifile_pred'/3,
21 '$discontiguous'/2,
22 '$dynamic'/2]).
23
24:- '$add_multifile'/3use_system_module( '$_consult', []).
25
26:- '$do_error'/2use_system_module( '$_errors', []).
27
28'$log_upd'(1).
29
30/**
31 @defgroup YAPPredDecls Declaring Properties of Predicates
32 @ingroup YAPCompilerSettings
33
34The YAP Compiler allows the programmer to include declarations with
35important pproprties of predicates, such as where they can be modified
36during execution time, whether they are meta-predicates, or whether they can be
37defined across multiple files. We next join some of these declarations.
38
39*/
40
41/** @pred public( _P_ ) is iso
42
43Instructs the compiler that the source of a predicate of a list of
44predicates _P_ must be kept. This source is then accessible through
45the clause/2 procedure and through the `listing` family of
46built-ins.
47
48Note that all dynamic procedures are public. The `source` directive
49defines all new or redefined predicates to be public.
50
51**/
52'$public'(X, _) :- var(X), var,
53 '$do_error'(instantiation_error,public(X)).
54'$public'(Mod:Spec, _) :- '$public',
55 '$public'(Spec,Mod).
56'$public'((A,B), M) :- '$public', '$public'(A,M), '$public'(B,M).
57'$public'([],_) :- '$public'.
58'$public'([H|L], M) :- '$public', '$public'(H, M), '$public'(L, M).
59'$public'(A//N1, Mod) :- integer(N1), integer,
60 N is N1+2,
61 '$public'(A/N, Mod).
62'$public'(A/N, Mod) :- integer(N), atom(A), atom,
63 functor(T,A,N),
64 '$do_make_public'(T, Mod).
65'$public'(X, Mod) :-
66 '$do_pi_error'(type_error(callable,X),dynamic(Mod:X)).
67
68'$do_make_public'(T, Mod) :-
69 '$is_dynamic'(T, Mod), '$is_dynamic'. % all dynamic predicates are public.
70'$do_make_public'(T, Mod) :-
71 '$predicate_flags'(T,Mod,F,F),
72 NF is F\/0'$predicate_flags',
73 '$predicate_flags'(T,Mod,F,NF).
74
75
76discontiguous(V) :-
77 var(V), var,
78 '$do_error'(instantiation_error,discontiguous(V)).
79discontiguous(M:F) :- ,
80 '$discontiguous'(F,M).
81discontiguous(F) :-
82 '$current_module'(M),
83 '$discontiguous'(F,M).
84
85'$discontiguous'(V,M) :- var(V), var,
86 '$do_error'(instantiation_error,M:discontiguous(V)).
87'$discontiguous'((X,Y),M) :- '$discontiguous',
88 '$discontiguous'(X,M),
89 '$discontiguous'(Y,M).
90'$discontiguous'(M:A,_) :- '$discontiguous',
91 '$discontiguous'(A,M).
92'$discontiguous'(N//A1, M) :- '$discontiguous',
93 integer(A1), integer,
94 A is A1+2,
95 '$discontiguous'(N/A, M).
96'$discontiguous'(N/A, M) :- '$discontiguous',
97 '$new_discontiguous'(N,A,M).
98'$discontiguous'(P,M) :-
99 '$do_error'(type_error(predicate_indicator,P),M:discontiguous(P)).
100
101%
102% did we declare multifile properly?
103%
104'$check_multifile_pred'(Hd, M, _) :-
105 functor(Hd,Na,Ar),
106 source_location(F, _),
107 recorded('$multifile_defs','$defined'(F,Na,Ar,M),_), recorded.
108% oops, we did not.
109'$check_multifile_pred'(Hd, M, Fl) :-
110 % so this is not a multi-file predicate any longer.
111 functor(Hd,Na,Ar),
112 NFl is \(0x20000000) /\ Fl,
113 '$predicate_flags'(Hd,M,Fl,NFl),
114 '$warn_mfile'(Na,Ar).
115
116'$warn_mfile'(F,A) :-
117 write(user_error,'% Warning: predicate '),
118 write(user_error,F/A), write(user_error,' was a multifile predicate '),
119 write(user_error,' (line '),
120 '$start_line'(LN), write(user_error,LN),
121 write(user_error,')'),
122 nl(user_error).
123
124'$is_public'(T, Mod) :-
125 '$is_dynamic'(T, Mod), '$is_dynamic'. % all dynamic predicates are public.
126'$is_public'(T, Mod) :-
127 '$predicate_flags'(T,Mod,F,F),
128 F\/0'$predicate_flags' =\= 0.
129
130/**
131 @pred module_transparent( + _Preds_ ) is directive
132 _Preds_ is a list of predicates that can access the calling context.
133
134This predicate was implemented to achieve compatibility with the older
135module expansion system in SWI-Prolog. Please use meta_predicate/1 for
136new code.
137
138_Preds_ is a comma separated sequence of name/arity predicate
139indicators (like in dynamic/1). Each goal associated with a
140transparent declared predicate will inherit the context module from
141its caller.
142
143*/
144:- '$module_transparent'/4dynamic().
145
146'$module_transparent'((P,Ps), M) :- '$module_transparent',
147 '$module_transparent'(P, M),
148 '$module_transparent'(Ps, M).
149'$module_transparent'(M:D, _) :- '$module_transparent',
150 '$module_transparent'(D, M).
151'$module_transparent'(F/N, M) :-
152 '$module_transparent'(F,M,N,_), '$module_transparent'.
153'$module_transparent'(F/N, M) :-
154 functor(P,F,N),
155 asserta(prolog:'$module_transparent'(F,M,N,P)),
156 '$predicate_flags'(P, M, Fl, Fl),
157 NFlags is Fl \/ 0'$predicate_flags',
158 '$predicate_flags'(P, M, Fl, NFlags).
nl(+ S)
asserta(+ C)
write(+ S, T)
dynamic( + P )
atom( T)
functor( T, F, N)
integer( T)
var( T)