View source with formatted comments or as raw
    1/*
    2
    3    Part of CLP(Q,R) (Constraint Logic Programming over Rationals and Reals)
    4
    5    Author:        Leslie De Koninck
    6    E-mail:        Leslie.DeKoninck@cs.kuleuven.be
    7    WWW:           http://www.swi-prolog.org
    8		   http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09
    9    Copyright (C): 2006, K.U. Leuven and
   10		   1992-1995, Austrian Research Institute for
   11		              Artificial Intelligence (OFAI),
   12			      Vienna, Austria
   13
   14    This software is based on CLP(Q,R) by Christian Holzbaur for SICStus
   15    Prolog and distributed under the license details below with permission from
   16    all mentioned authors.
   17
   18    This program is free software; you can redistribute it and/or
   19    modify it under the terms of the GNU General Public License
   20    as published by the Free Software Foundation; either version 2
   21    of the License, or (at your option) any later version.
   22
   23    This program is distributed in the hope that it will be useful,
   24    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26    GNU General Public License for more details.
   27
   28    You should have received a copy of the GNU Lesser General Public
   29    License along with this library; if not, write to the Free Software
   30    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   31
   32    As a special exception, if you link this library with other files,
   33    compiled with a Free Software compiler, to produce an executable, this
   34    library does not by itself cause the resulting executable to be covered
   35    by the GNU General Public License. This exception does not however
   36    invalidate any other reasons why the executable file might be covered by
   37    the GNU General Public License.
   38*/
   39
   40
   41% attribute = t(CLP,type(_),strictness(_),lin(_),order(_),class(_),forward(_),
   42%		nonzero,target,keep_indep,keep)
   43
   44:- module(itf,
   45	[
   46	    dump_linear/3,
   47	    dump_nonzero/3,
   48	    clp_type/2
   49	]).   50
   51
   52clp_type(Var,Type) :-
   53	(   get_attr(Var,itf,Att)
   54	->  arg(1,Att,Type)
   55	;   get_attr(Var,geler,Att)
   56	->  arg(1,Att,Type)
   57	).
   58
   59dump_linear(V) -->
   60	{
   61	    get_attr(V,itf,Att),
   62	    arg(1,Att,CLP),
   63	    arg(2,Att,type(Type)),
   64	    arg(4,Att,lin(Lin)),
   65	    !,
   66	    Lin = [I,_|H]
   67	},
   68	(   {
   69		Type=t_none
   70	    ;	arg(9,Att,n)
   71	    }
   72	->  []
   73	;   dump_v(CLP,t_none,V,I,H)
   74	),
   75	(   {
   76		Type=t_none,
   77		arg(9,Att,n) % attribute should not have changed by dump_v...
   78	    }
   79	->  % nonzero produces such
   80	    []
   81	;   dump_v(CLP,Type,V,I,H)
   82	).
   83dump_linear(_) --> [].
   84
   85dump_v(clpq,Type,V,I,H) --> bv_q:dump_var(Type,V,I,H).
   86dump_v(clpr,Type,V,I,H) --> bv_r:dump_var(Type,V,I,H).
   87
   88dump_nonzero(V) -->
   89	{
   90	    get_attr(V,itf,Att),
   91	    arg(1,Att,CLP),
   92	    arg(4,Att,lin(Lin)),
   93	    arg(8,Att,nonzero),
   94	    !,
   95	    Lin = [I,_|H]
   96	},
   97	dump_nz(CLP,V,H,I).
   98dump_nonzero(_) --> [].
   99
  100dump_nz(clpq,V,H,I) --> bv_q:dump_nz(V,H,I).
  101dump_nz(clpr,V,H,I) --> bv_r:dump_nz(V,H,I).
  102
  103attr_unify_hook(t(CLP,n,n,n,n,n,n,n,_,_,_),Y) :-
  104	!,
  105	(   get_attr(Y,itf,AttY),
  106	    \+ arg(1,AttY,CLP)
  107	->  throw(error(permission_error('mix CLP(Q) variables with',
  108		'CLP(R) variables:',Y),context(_)))
  109	;   true
  110	).
  111attr_unify_hook(t(CLP,Ty,St,Li,Or,Cl,_,No,_,_,_),Y) :-
  112	(   get_attr(Y,itf,AttY),
  113	    \+ arg(1,AttY,CLP)
  114	->  throw(error(permission_error('mix CLP(Q) variables with',
  115		'CLP(R) variables:',Y),context(_)))
  116	;   true
  117	),
  118	do_checks(CLP,Y,Ty,St,Li,Or,Cl,No,Later),
  119	maplist(call,Later).
  120
  121do_checks(clpq,Y,Ty,St,Li,Or,Cl,No,Later) :-
  122	itf_q:do_checks(Y,Ty,St,Li,Or,Cl,No,Later).
  123do_checks(clpr,Y,Ty,St,Li,Or,Cl,No,Later) :-
  124	itf_r:do_checks(Y,Ty,St,Li,Or,Cl,No,Later).
  125
  126		 /*******************************
  127		 *	       SANDBOX		*
  128		 *******************************/
  129:- multifile
  130	sandbox:safe_primitive/1.  131
  132sandbox:safe_primitive(itf:clp_type(_,_))