ppl_gprolog_sd.cc File Reference

#include "ppl.hh"
#include "pwl.hh"
#include <gprolog.h>
#include <cassert>
#include "../exceptions.hh"
#include <iostream>
#include "../ppl_prolog.icc"

Include dependency graph for ppl_gprolog_sd.cc:

Go to the source code of this file.

Typedefs

typedef PlTerm Prolog_term_ref
typedef int Prolog_atom
typedef Bool Prolog_foreign_return_type

Functions

void ppl_Prolog_sysdep_init ()
void ppl_Prolog_sysdep_deinit ()
Prolog_term_ref Prolog_new_term_ref ()
int Prolog_put_term (Prolog_term_ref &t, Prolog_term_ref u)
int Prolog_put_long (Prolog_term_ref &t, long l)
int Prolog_put_ulong (Prolog_term_ref &t, unsigned long ul)
int Prolog_put_atom_chars (Prolog_term_ref &t, const char *s)
int Prolog_put_atom (Prolog_term_ref &t, Prolog_atom a)
Prolog_atom Prolog_atom_from_string (const char *s)
int Prolog_construct_compound (Prolog_term_ref &t, Prolog_atom f, Prolog_term_ref a1)
int Prolog_construct_compound (Prolog_term_ref &t, Prolog_atom f, Prolog_term_ref a1, Prolog_term_ref a2)
int Prolog_construct_compound (Prolog_term_ref &t, Prolog_atom f, Prolog_term_ref a1, Prolog_term_ref a2, Prolog_term_ref a3)
int Prolog_construct_compound (Prolog_term_ref &t, Prolog_atom f, Prolog_term_ref a1, Prolog_term_ref a2, Prolog_term_ref a3, Prolog_term_ref a4)
int Prolog_construct_cons (Prolog_term_ref &c, Prolog_term_ref h, Prolog_term_ref t)
int Prolog_put_address (Prolog_term_ref &t, void *p)
void Prolog_raise_exception (Prolog_term_ref t)
int Prolog_is_variable (Prolog_term_ref t)
int Prolog_is_atom (Prolog_term_ref t)
int Prolog_is_integer (Prolog_term_ref t)
int Prolog_is_compound (Prolog_term_ref t)
int Prolog_is_cons (Prolog_term_ref t)
int Prolog_get_long (Prolog_term_ref t, long *lp)
int Prolog_is_address (Prolog_term_ref t)
int Prolog_get_address (Prolog_term_ref t, void **vpp)
int Prolog_get_atom_name (Prolog_term_ref t, Prolog_atom *ap)
int Prolog_get_compound_name_arity (Prolog_term_ref t, Prolog_atom *ap, int *ip)
int Prolog_get_arg (int i, Prolog_term_ref t, Prolog_term_ref &a)
int Prolog_get_cons (Prolog_term_ref c, Prolog_term_ref &h, Prolog_term_ref &t)
int Prolog_unify (Prolog_term_ref t, Prolog_term_ref u)
PPL::Coefficient integer_term_to_Coefficient (Prolog_term_ref t)
Prolog_term_ref Coefficient_to_integer_term (const PPL::Coefficient &n)

Variables

const Prolog_foreign_return_type PROLOG_SUCCESS = TRUE
const Prolog_foreign_return_type PROLOG_FAILURE = FALSE
Prolog_atom a_dollar_address
Prolog_atom a_throw
bool Prolog_has_unbounded_integers
long Prolog_min_integer
long Prolog_max_integer
Prolog_term_ref args [4]


Typedef Documentation

typedef int Prolog_atom

Definition at line 29 of file ppl_gprolog_sd.cc.

Definition at line 30 of file ppl_gprolog_sd.cc.

typedef PlTerm Prolog_term_ref

Definition at line 28 of file ppl_gprolog_sd.cc.


Function Documentation

Prolog_term_ref @200::Coefficient_to_integer_term ( const PPL::Coefficient &  n  )  [static]

Definition at line 425 of file ppl_gprolog_sd.cc.

References Parma_Polyhedra_Library::assign_r(), Prolog_new_term_ref(), and Prolog_put_long().

00425                                                      {
00426   long l = 0;
00427   if (PPL::assign_r(l, n, PPL::ROUND_NOT_NEEDED) != PPL::V_EQ)
00428     throw PPL_integer_out_of_range(n);
00429   Prolog_term_ref t = Prolog_new_term_ref();
00430   Prolog_put_long(t, l);
00431   return t;
00432 }

PPL::Coefficient @200::integer_term_to_Coefficient ( Prolog_term_ref  t  )  [static]

Definition at line 418 of file ppl_gprolog_sd.cc.

References Prolog_get_long().

00418                                                {
00419   long v;
00420   Prolog_get_long(t, &v);
00421   return PPL::Coefficient(v);
00422 }

void @200::ppl_Prolog_sysdep_deinit (  )  [static]

Perform system-dependent de-itialization.

Definition at line 87 of file ppl_gprolog_sd.cc.

00087                            {
00088 }

void @200::ppl_Prolog_sysdep_init (  )  [static]

Performs system-dependent initialization.

Definition at line 74 of file ppl_gprolog_sd.cc.

References a_dollar_address, a_throw, Prolog_has_unbounded_integers, Prolog_max_integer, and Prolog_min_integer.

00074                          {
00075   Prolog_has_unbounded_integers = false;
00076   Prolog_min_integer = INT_LOWEST_VALUE;
00077   Prolog_max_integer = INT_GREATEST_VALUE;
00078 
00079   a_dollar_address = Create_Allocate_Atom("$address");
00080   a_throw = Find_Atom("throw");
00081 }

Prolog_atom @200::Prolog_atom_from_string ( const char *  s  )  [static]

Return an atom whose name is given by the null-terminated string s.

Definition at line 156 of file ppl_gprolog_sd.cc.

00156                                        {
00157   // TODO: remove the const_cast when the GNU Prolog people fix gprolog.h.
00158   return Create_Allocate_Atom(const_cast<char*>(s));
00159 }

int @200::Prolog_construct_compound ( Prolog_term_ref t,
Prolog_atom  f,
Prolog_term_ref  a1,
Prolog_term_ref  a2,
Prolog_term_ref  a3,
Prolog_term_ref  a4 
) [inline, static]

Assign to t a compound term whose principal functor is f of arity 4 with arguments a1, a2, a3 and a4.

Definition at line 208 of file ppl_gprolog_sd.cc.

References args.

00210                                                                   {
00211   args[0] = a1;
00212   args[1] = a2;
00213   args[2] = a3;
00214   args[3] = a4;
00215   t = Mk_Compound(f, 4, args);
00216   return 1;
00217 }

int @200::Prolog_construct_compound ( Prolog_term_ref t,
Prolog_atom  f,
Prolog_term_ref  a1,
Prolog_term_ref  a2,
Prolog_term_ref  a3 
) [inline, static]

Assign to t a compound term whose principal functor is f of arity 3 with arguments a1, a2 and a3.

Definition at line 193 of file ppl_gprolog_sd.cc.

References args.

00195                                               {
00196   args[0] = a1;
00197   args[1] = a2;
00198   args[2] = a3;
00199   t = Mk_Compound(f, 3, args);
00200   return 1;
00201 }

int @200::Prolog_construct_compound ( Prolog_term_ref t,
Prolog_atom  f,
Prolog_term_ref  a1,
Prolog_term_ref  a2 
) [inline, static]

Assign to t a compound term whose principal functor is f of arity 2 with arguments a1 and a2.

Definition at line 180 of file ppl_gprolog_sd.cc.

References args.

00181                                                                   {
00182   args[0] = a1;
00183   args[1] = a2;
00184   t = Mk_Compound(f, 2, args);
00185   return 1;
00186 }

int @200::Prolog_construct_compound ( Prolog_term_ref t,
Prolog_atom  f,
Prolog_term_ref  a1 
) [inline, static]

Assign to t a compound term whose principal functor is f of arity 1 with argument a1.

Definition at line 168 of file ppl_gprolog_sd.cc.

References args.

00169                                               {
00170   args[0] = a1;
00171   t = Mk_Compound(f, 1, args);
00172   return 1;
00173 }

int @200::Prolog_construct_cons ( Prolog_term_ref c,
Prolog_term_ref  h,
Prolog_term_ref  t 
) [inline, static]

Assign to c a Prolog list whose head is h and tail is t.

Definition at line 223 of file ppl_gprolog_sd.cc.

References args.

00224                                                             {
00225   args[0] = h;
00226   args[1] = t;
00227   c = Mk_List(args);
00228   return 1;
00229 }

int @200::Prolog_get_address ( Prolog_term_ref  t,
void **  vpp 
) [inline, static]

If t is the Prolog representation for a memory address, return true and store that address into v; return false otherwise. The behavior is undefined if t is not an address.

Definition at line 341 of file ppl_gprolog_sd.cc.

References Prolog_is_address().

00341                                                   {
00342   assert(Prolog_is_address(t));
00343   static Prolog_atom dummy_name;
00344   static int dummy_arity;
00345   Prolog_term_ref* a = Rd_Compound_Check(t, &dummy_name, &dummy_arity);
00346   union {
00347     unsigned long l;
00348     unsigned short s[2];
00349   } u;
00350   u.s[0] = Rd_Integer_Check(a[0]);
00351   u.s[1] = Rd_Integer_Check(a[1]);
00352   *vpp = reinterpret_cast<void*>(u.l);
00353   return 1;
00354 }

int @200::Prolog_get_arg ( int  i,
Prolog_term_ref  t,
Prolog_term_ref a 
) [inline, static]

If t is a Prolog compound term and i is a positive integer less than or equal to its arity, return true and assign to a the i-th (principal) argument of t. The behavior is undefined if t is not a Prolog compound term.

Definition at line 386 of file ppl_gprolog_sd.cc.

References Prolog_is_compound().

00386                                                              {
00387   assert(Prolog_is_compound(t));
00388   static Prolog_atom dummy_name;
00389   static int dummy_arity;
00390   a = Rd_Compound_Check(t, &dummy_name, &dummy_arity)[i-1];
00391   return 1;
00392 }

int @200::Prolog_get_atom_name ( Prolog_term_ref  t,
Prolog_atom ap 
) [inline, static]

If t is a Prolog atom, return true and store its name into name. The behavior is undefined if t is not a Prolog atom.

Definition at line 361 of file ppl_gprolog_sd.cc.

References Prolog_is_atom().

00361                                                          {
00362   assert(Prolog_is_atom(t));
00363   *ap = Rd_Atom_Check(t);
00364   return 1;
00365 }

int @200::Prolog_get_compound_name_arity ( Prolog_term_ref  t,
Prolog_atom ap,
int *  ip 
) [inline, static]

If t is a Prolog compound term, return true and store its name and arity into name and arity, respectively. The behavior is undefined if t is not a Prolog compound term.

Definition at line 373 of file ppl_gprolog_sd.cc.

References Prolog_is_compound().

00373                                                                             {
00374   assert(Prolog_is_compound(t));
00375   Rd_Compound_Check(t, ap, ip);
00376   return 1;
00377 }

int @200::Prolog_get_cons ( Prolog_term_ref  c,
Prolog_term_ref h,
Prolog_term_ref t 
) [inline, static]

If c is a Prolog cons (list constructor), assign its head and tail to h and t, respectively. The behavior is undefined if c is not a Prolog cons.

Definition at line 400 of file ppl_gprolog_sd.cc.

References Prolog_is_cons().

00400                                                                            {
00401   assert(Prolog_is_cons(c));
00402   Prolog_term_ref* ht = Rd_List_Check(c);
00403   h = ht[0];
00404   t = ht[1];
00405   return 1;
00406 }

int @200::Prolog_get_long ( Prolog_term_ref  t,
long *  lp 
) [inline, static]

Assuming t is a Prolog integer, return true if its value fits in a long, in which case the value is assigned to v, return false otherwise. The behavior is undefined if t is not a Prolog integer.

Definition at line 305 of file ppl_gprolog_sd.cc.

References Prolog_is_integer().

00305                                              {
00306   assert(Prolog_is_integer(t));
00307   *lp = Rd_Integer_Check(t);
00308   return 1;
00309 }

int @200::Prolog_is_address ( Prolog_term_ref  t  )  [inline, static]

Return true if t is the representation of an address, false otherwise.

Definition at line 315 of file ppl_gprolog_sd.cc.

References a_dollar_address, name, Prolog_get_long(), Prolog_is_compound(), and Prolog_is_integer().

00315                                      {
00316   if (!Prolog_is_compound(t))
00317     return 0;
00318   Prolog_atom name;
00319   int arity;
00320   Prolog_term_ref* a = Rd_Compound_Check(t, &name, &arity);
00321   if (name != a_dollar_address || arity != 2)
00322     return 0;
00323   for (int i = 0; i <= 1; ++i) {
00324     if (!Prolog_is_integer(a[i]))
00325       return 0;
00326     long l;
00327     if (!Prolog_get_long(a[i], &l))
00328       return 0;
00329     if (l < 0 || l > USHRT_MAX)
00330       return 0;
00331   }
00332   return 1;
00333 }

int @200::Prolog_is_atom ( Prolog_term_ref  t  )  [inline, static]

Return true if t is a Prolog atom, false otherwise.

Definition at line 265 of file ppl_gprolog_sd.cc.

00265                                   {
00266   return Blt_Atom(t) != FALSE;
00267 }

int @200::Prolog_is_compound ( Prolog_term_ref  t  )  [inline, static]

Return true if t is a Prolog compound term, false otherwise.

Definition at line 281 of file ppl_gprolog_sd.cc.

00281                                       {
00282   return Blt_Compound(t) != FALSE;
00283 }

int @200::Prolog_is_cons ( Prolog_term_ref  t  )  [inline, static]

Return true if t is a Prolog list, false otherwise.

Definition at line 289 of file ppl_gprolog_sd.cc.

References name.

00289                                   {
00290   if (Blt_Compound(t) == FALSE)
00291     return 0;
00292   Prolog_atom name;
00293   int arity;
00294   Rd_Compound(t, &name, &arity);
00295   return name == ATOM_CHAR('.') && arity == 2;
00296 }

int @200::Prolog_is_integer ( Prolog_term_ref  t  )  [inline, static]

Return true if t is a Prolog integer, false otherwise.

Definition at line 273 of file ppl_gprolog_sd.cc.

00273                                      {
00274   return Blt_Integer(t) != FALSE;
00275 }

int @200::Prolog_is_variable ( Prolog_term_ref  t  )  [inline, static]

Return true if t is a Prolog variable, false otherwise.

Definition at line 257 of file ppl_gprolog_sd.cc.

00257                                       {
00258   return Blt_Var(t) != FALSE;
00259 }

Prolog_term_ref @200::Prolog_new_term_ref (  )  [inline, static]

Return a new term reference.

Definition at line 94 of file ppl_gprolog_sd.cc.

00094                       {
00095   return 0;
00096 }

int @200::Prolog_put_address ( Prolog_term_ref t,
void *  p 
) [inline, static]

Assign to t a term representing the address contained in p.

Definition at line 235 of file ppl_gprolog_sd.cc.

References a_dollar_address, and Prolog_construct_compound().

00235                                                 {
00236   union {
00237     unsigned long l;
00238     unsigned short s[2];
00239   } u;
00240   u.l = reinterpret_cast<unsigned long>(p);
00241   return Prolog_construct_compound(t, a_dollar_address,
00242                                    Mk_Positive(u.s[0]), Mk_Positive(u.s[1]));
00243 }

int @200::Prolog_put_atom ( Prolog_term_ref t,
Prolog_atom  a 
) [inline, static]

Assign to t the Prolog atom a.

Definition at line 147 of file ppl_gprolog_sd.cc.

00147                                                    {
00148   t = Mk_Atom(a);
00149   return 1;
00150 }

int @200::Prolog_put_atom_chars ( Prolog_term_ref t,
const char *  s 
) [inline, static]

Assign to t an atom whose name is given by the null-terminated string s.

Definition at line 135 of file ppl_gprolog_sd.cc.

00135                                                          {
00136   // TODO: remove the const_cast when the GNU Prolog people fix gprolog.h.
00137   // NOTE: at the time of writing this comment (January 14, 2006), and since
00138   // a long time before, "GNU Prolog people" stands for the empty set.
00139   t = Mk_Atom(Create_Allocate_Atom(const_cast<char*>(s)));
00140   return 1;
00141 }

int @200::Prolog_put_long ( Prolog_term_ref t,
long  l 
) [inline, static]

Assign to t a Prolog integer with value l.

Definition at line 112 of file ppl_gprolog_sd.cc.

References Prolog_max_integer.

00112                                             {
00113   if (l < Prolog_min_integer || l > Prolog_max_integer)
00114     throw PPL_integer_out_of_range(l);
00115   t = Mk_Integer(l);
00116   return 1;
00117 }

int @200::Prolog_put_term ( Prolog_term_ref t,
Prolog_term_ref  u 
) [inline, static]

Make t be a reference to the same term referenced by u, i.e., assign u to t.

Definition at line 103 of file ppl_gprolog_sd.cc.

00103                                                        {
00104   t = u;
00105   return 1;
00106 }

int @200::Prolog_put_ulong ( Prolog_term_ref t,
unsigned long  ul 
) [inline, static]

Assign to t a Prolog integer with value ul.

Definition at line 123 of file ppl_gprolog_sd.cc.

References Prolog_max_integer.

00123                                                        {
00124   if (ul > static_cast<unsigned long>(Prolog_max_integer))
00125     throw PPL_integer_out_of_range(ul);
00126   t = Mk_Integer(ul);
00127   return 1;
00128 }

void @200::Prolog_raise_exception ( Prolog_term_ref  t  )  [inline, static]

Raise a Prolog exception with t as the exception term.

Definition at line 249 of file ppl_gprolog_sd.cc.

References a_throw.

00249                                           {
00250   Pl_Exec_Continuation(a_throw, 1, &t);
00251 }

int @200::Prolog_unify ( Prolog_term_ref  t,
Prolog_term_ref  u 
) [inline, static]

Unify the terms referenced by t and u and return true if the unification is successful; return false otherwise.

Definition at line 413 of file ppl_gprolog_sd.cc.

00413                                                    {
00414   return Unify(t, u) != FALSE;
00415 }


Variable Documentation

Definition at line 45 of file ppl_gprolog_sd.cc.

Referenced by ppl_Prolog_sysdep_init(), Prolog_is_address(), and Prolog_put_address().

Prolog_atom a_throw [static]

Definition at line 46 of file ppl_gprolog_sd.cc.

Referenced by ppl_Prolog_sysdep_init(), and Prolog_raise_exception().

Prolog_term_ref args[4] [static]

Definition at line 161 of file ppl_gprolog_sd.cc.

Definition at line 35 of file ppl_gprolog_sd.cc.

True if and only if the Prolog engine supports unbounded integers.

Definition at line 51 of file ppl_gprolog_sd.cc.

long Prolog_max_integer [static]

If Prolog_has_unbounded_integers is false, holds the maximum integer value representable by a Prolog integer. Holds zero otherwise.

Definition at line 65 of file ppl_gprolog_sd.cc.

long Prolog_min_integer [static]

If Prolog_has_unbounded_integers is false, holds the minimum integer value representable by a Prolog integer. Holds zero otherwise.

Definition at line 58 of file ppl_gprolog_sd.cc.

Definition at line 34 of file ppl_gprolog_sd.cc.


Generated on Wed Jul 16 22:55:26 2008 for PPL by  doxygen 1.5.6