YAP 7.1.0
ypp.yap
Go to the documentation of this file.
1/**
2 * @file ypp.yap
3 * @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares
4 * @date 2005-05-14
5 *
6 * @brief Yap PreProcessing
7 *
8 *
9*/
10%====================================================================================
11%
12% YPP: Yap PreProcessing
13%
14% Author: Nuno Fonseca (nunofonseca@acm.org)
15% Date:
16% $Id: ypp.yap,v 1.4 2006-03-07 17:30:47 tiagosoares Exp $
17%
18%====================================================================================
19
20%====================================================================================
21% Module declarations
22%====================================================================================
23
24:-ypp_state/1% ypp_state(on|off)ypp_define/2% persistent defines ypp_define(+NAME,VALUE)ypp_undefine/1% persistent defines ypp_undefine(+NAME)ypp_extcmd/1% ypp_extcmd(?command)ypp_consult/1% similiar to standard consult but with preprocessingypp_reconsult/1module(ypp,[
25 ,
26 ,
27 ,
28 ,
29 ,
30
31 ]
32 ).
33
34/**
35* @defgroup Ypp Yap PreProcessing
36* @ingroup YAPLibrary
37*
38*/
39
40%====================================================================================
41% Public Predicates
42%====================================================================================
43
44ypp_state(State):-
45 ground(State),ground,
46 set_state(State).
47
48ypp_state(State):-
49 get_state(State),
50 get_state.
51
52ypp_define(Name,Value):-
53 ground(Name),ground(Value),
54 store_define(Name,Value).
55
56ypp_undefine(Name):-
57 ground(Name),
58 del_define(Name).
59
60ypp_extcmd(Cmd):-
61 ground(Cmd),ground,
62 eraseall('____ypp_extcmd'),
63 recorda('____ypp_extcmd',Cmd,_).
64ypp_extcmd(Cmd):-
65 \+ ground(Cmd),
66 recorded('____ypp_extcmd',Cmd,_).
67
68ypp_consult(File):-
69 (get_state(on)->ypp_file(File,NFile);NFile=File),
70 consult(NFile).
71
72ypp_reconsult(File):-
73 (get_state(on)->ypp_file(File,NFile);NFile=File),
74 reconsult(NFile).
75%====================================================================================
76% Private Predicates
77%====================================================================================
78
79set_state(on):-set_value('____ypp_state',1).
80set_state(off):-set_value('____ypp_state',0).
81
82get_state(State):-
83 get_value('____ypp_state',Val),
84 (Val==0->State=off;State=on).
85
86
87store_define(Name,_Value):-
88 recorded('___ypp',def(Name,_),Ref),
89 erase(Ref),
90 erase.
91store_define(Name,Value):-
92 system_variable( Name ),
93 environ( Name, Value ),
94 environ.
95store_define(Name,Value):-
96 recordz('___ypp',def(Name,Value),_),
97 recordz.
98store_define(_Name,_Value).
99
100system_variable( 'YAPLIBDIR' ).
101system_variable( 'YAPSHAREDIR' ).
102system_variable( 'YAPBINDIR' ).
103
104
105del_define(Name):-
106 (recorded('___ypp',def(Name,_),Ref)->erase(Ref);erase),
107 !.
108
109%defines2string(-DefineString)
110defines2string(S):-
111 findall(d(Name,Val),recorded('___ypp',def(Name,Val),_),AllDefs),
112 mergedefs(AllDefs,'-D',S),
113 mergedefs.
114
115mergedefs([],_,'').
116mergedefs([d(Name,Val)|RDefs],Pref,S):-
117 mergedefs(RDefs,Pref,S1),
118 atom_concat([Pref,Name,'=',Val,' ',S1],S).
119
120
121ypp_file(File,PPFile):-
122 % ppfile
123 atom_concat([File,'.ypp'],PPFile),
124 % Cmdline
125 defines2string(Defs),ypp_extcmd(Cmd),
126 atom_concat([Cmd,' ',PPFile,' ',Defs,' ',File],Cmdline),
127 write(Cmdline),write,
128% current_module(M1,M2),
129% write(M1:M2),nl,
130 system(Cmdline),
131 system.
132
133% initialization
134:-set_state(on),
135 ypp_extcmd('cpp -P -E -w -o ').
136% ypp_extcmd('gpp -o').
137
atom_concat(+ As, ? A)
module(+M)
erase(+ R)
eraseall(+ K)
recordz(+ K, T,- R)
findall( T,+ G,- L)
Definition: setof.yap:70
consult(+ F)
reconsult(+ F )
get_value(+ A,- V)
set_value(+ A,+ C)
ground( T)
environ(? EnvVar,+ EnvValue)
system(+ S)
Definition: system.yap:582