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

137 lines
3.3 KiB
Plaintext
Raw Normal View History

2015-11-18 15:06:25 +00:00
/**
* @file ypp.yap
* @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares
* @date 2005-05-14
*
* @brief Yap PreProcessing
*
*
*/
%====================================================================================
%
% YPP: Yap PreProcessing
%
% Author: Nuno Fonseca (nunofonseca@acm.org)
2015-11-18 15:06:25 +00:00
% Date:
% $Id: ypp.yap,v 1.4 2006-03-07 17:30:47 tiagosoares Exp $
%
%====================================================================================
%====================================================================================
% Module declarations
%====================================================================================
:-module(ypp,[
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 preprocessing
ypp_reconsult/1
]
2015-11-18 15:06:25 +00:00
).
/**
* @defgroup ypp Yap PreProcessing
* @ingroup library
*
*/
%====================================================================================
% Public Predicates
%====================================================================================
ypp_state(State):-
ground(State),!,
set_state(State).
ypp_state(State):-
get_state(State),
!.
ypp_define(Name,Value):-
ground(Name),ground(Value),
store_define(Name,Value).
ypp_undefine(Name):-
ground(Name),
del_define(Name).
ypp_extcmd(Cmd):-
ground(Cmd),!,
eraseall('____ypp_extcmd'),
recorda('____ypp_extcmd',Cmd,_).
ypp_extcmd(Cmd):-
\+ ground(Cmd),
recorded('____ypp_extcmd',Cmd,_).
ypp_consult(File):-
(get_state(on)->ypp_file(File,NFile);NFile=File),
consult(NFile).
ypp_reconsult(File):-
(get_state(on)->ypp_file(File,NFile);NFile=File),
reconsult(NFile).
%====================================================================================
% Private Predicates
%====================================================================================
set_state(on):-set_value('____ypp_state',1).
set_state(off):-set_value('____ypp_state',0).
get_state(State):-
get_value('____ypp_state',Val),
(Val==0->State=off;State=on).
2015-02-17 20:27:31 +00:00
store_define(Name,_Value):-
recorded('___ypp',def(Name,_),Ref),
erase(Ref),
2015-02-15 02:33:54 +00:00
fail.
store_define(Name,Value):-
2015-02-17 20:27:31 +00:00
system_variable( Name ),
2015-02-15 02:33:54 +00:00
environ( Name, Value ),
fail.
store_define(Name,Value):-
recordz('___ypp',def(Name,Value),_),
fail.
store_define(_Name,_Value).
2015-02-17 20:27:31 +00:00
system_variable( 'YAPLIBDIR' ).
system_variable( 'YAPSHAREDIR' ).
system_variable( 'YAPBINDIR' ).
2015-02-15 02:33:54 +00:00
del_define(Name):-
(recorded('___ypp',def(Name,_),Ref)->erase(Ref);true),
!.
%defines2string(-DefineString)
defines2string(S):-
findall(d(Name,Val),recorded('___ypp',def(Name,Val),_),AllDefs),
mergedefs(AllDefs,'-D',S),
!.
mergedefs([],_,'').
mergedefs([d(Name,Val)|RDefs],Pref,S):-
mergedefs(RDefs,Pref,S1),
atom_concat([Pref,Name,'=',Val,' ',S1],S).
ypp_file(File,PPFile):-
% ppfile
atom_concat([File,'.ypp'],PPFile),
% Cmdline
defines2string(Defs),ypp_extcmd(Cmd),
atom_concat([Cmd,' ',PPFile,' ',Defs,' ',File],Cmdline),
write(Cmdline),nl,
% current_module(M1,M2),
% write(M1:M2),nl,
system(Cmdline),
!.
% initialization
:-set_state(on),
ypp_extcmd('cpp -P -E -w -o ').
% ypp_extcmd('gpp -o').