ppl_swiprolog.cc File Reference

#include "ppl.hh"
#include "pwl.hh"
#include <gmp.h>
#include <SWI-Prolog.h>
#include <cassert>
#include "../exceptions.hh"
#include "../ppl_prolog.icc"

Include dependency graph for ppl_swiprolog.cc:

Go to the source code of this file.

Defines

#define PL_EXTENSION_ENTRY(name, arity)   { #name, arity, (void*) name, 0 },

Typedefs

typedef term_t Prolog_term_ref
typedef atom_t Prolog_atom
typedef foreign_t 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)
int Prolog_put_address (Prolog_term_ref t, void *p)
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)
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_address (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_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)
install_t install ()
install_t uninstall ()

Variables

const Prolog_foreign_return_type PROLOG_SUCCESS = TRUE
const Prolog_foreign_return_type PROLOG_FAILURE = FALSE
bool Prolog_has_unbounded_integers
long Prolog_min_integer
long Prolog_max_integer
mpz_class tmp_mpz_class
PL_extension predicates []


Define Documentation

#define PL_EXTENSION_ENTRY ( name,
arity   )     { #name, arity, (void*) name, 0 },

Definition at line 383 of file ppl_swiprolog.cc.


Typedef Documentation

typedef atom_t Prolog_atom

Definition at line 40 of file ppl_swiprolog.cc.

typedef foreign_t Prolog_foreign_return_type

Definition at line 41 of file ppl_swiprolog.cc.

typedef term_t Prolog_term_ref

Definition at line 39 of file ppl_swiprolog.cc.


Function Documentation

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

Definition at line 372 of file ppl_swiprolog.cc.

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

00372                                                      {
00373   PPL::assign_r(tmp_mpz_class, n, PPL::ROUND_NOT_NEEDED);
00374   Prolog_term_ref t = Prolog_new_term_ref();
00375   PL_unify_mpz(t, tmp_mpz_class.get_mpz_t());
00376   return t;
00377 }

install_t install (  ) 

Definition at line 516 of file ppl_swiprolog.cc.

References ppl_initialize(), and predicates.

00516           {
00517   ppl_initialize();
00518   PL_register_extensions(predicates);
00519 }

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

Definition at line 365 of file ppl_swiprolog.cc.

References Prolog_is_integer(), and tmp_mpz_class.

00365                                                {
00366   assert(Prolog_is_integer(t));
00367   PL_get_mpz(t, tmp_mpz_class.get_mpz_t());
00368   return PPL::Coefficient(tmp_mpz_class);
00369 }

void @202::ppl_Prolog_sysdep_deinit (  )  [static]

Perform system-dependent de-itialization.

Definition at line 94 of file ppl_swiprolog.cc.

00094                            {
00095 }

void @202::ppl_Prolog_sysdep_init (  )  [static]

Performs system-dependent initialization.

Definition at line 84 of file ppl_swiprolog.cc.

References Prolog_has_unbounded_integers, Prolog_max_integer, and Prolog_min_integer.

00084                          {
00085   Prolog_has_unbounded_integers = true;
00086   Prolog_min_integer = 0;
00087   Prolog_max_integer = 0;
00088 }

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

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

Definition at line 172 of file ppl_swiprolog.cc.

00172                                        {
00173   return PL_new_atom(s);
00174 }

int @202::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 215 of file ppl_swiprolog.cc.

00217                                                                   {
00218   PL_cons_functor(t, PL_new_functor(f, 4), a1, a2, a3, a4);
00219   return 1;
00220 }

int @202::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 203 of file ppl_swiprolog.cc.

00205                                               {
00206   PL_cons_functor(t, PL_new_functor(f, 3), a1, a2, a3);
00207   return 1;
00208 }

int @202::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 192 of file ppl_swiprolog.cc.

00193                                                                   {
00194   PL_cons_functor(t, PL_new_functor(f, 2), a1, a2);
00195   return 1;
00196 }

int @202::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 181 of file ppl_swiprolog.cc.

00182                                               {
00183   PL_cons_functor(t, PL_new_functor(f, 1), a1);
00184   return 1;
00185 }

int @202::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 226 of file ppl_swiprolog.cc.

00227                                                             {
00228   PL_cons_list(c, h, t);
00229   return 1;
00230 }

int @202::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 306 of file ppl_swiprolog.cc.

References Prolog_is_address().

00306                                                   {
00307   assert(Prolog_is_address(t));
00308   return PL_get_pointer(t, vpp);
00309 }

int @202::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 339 of file ppl_swiprolog.cc.

References Prolog_is_compound().

00339                                                             {
00340   assert(Prolog_is_compound(t));
00341   return PL_get_arg(i, t, a);
00342 }

int @202::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 316 of file ppl_swiprolog.cc.

References Prolog_is_atom().

00316                                                          {
00317   assert(Prolog_is_atom(t));
00318   return PL_get_atom(t, ap);
00319 }

int @202::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 327 of file ppl_swiprolog.cc.

References Prolog_is_compound().

00327                                                                             {
00328   assert(Prolog_is_compound(t));
00329   return PL_get_name_arity(t, ap, ip);
00330 }

int @202::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 350 of file ppl_swiprolog.cc.

References Prolog_is_cons().

00350                                                                          {
00351   assert(Prolog_is_cons(c));
00352   return PL_get_list(c, h, t);
00353 }

int @202::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 295 of file ppl_swiprolog.cc.

References Prolog_is_integer().

00295                                              {
00296   assert(Prolog_is_integer(t));
00297   return PL_get_long(t, lp);
00298 }

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

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

Definition at line 268 of file ppl_swiprolog.cc.

00268                                      {
00269   return PL_is_integer(t);
00270 }

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

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

Definition at line 252 of file ppl_swiprolog.cc.

00252                                   {
00253   return PL_is_atom(t);
00254 }

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

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

Definition at line 276 of file ppl_swiprolog.cc.

00276                                       {
00277   return PL_is_compound(t);
00278 }

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

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

Definition at line 284 of file ppl_swiprolog.cc.

00284                                   {
00285   return !PL_is_atom(t) && PL_is_list(t);
00286 }

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

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

Definition at line 260 of file ppl_swiprolog.cc.

00260                                      {
00261   return PL_is_integer(t);
00262 }

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

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

Definition at line 244 of file ppl_swiprolog.cc.

00244                                       {
00245   return PL_is_variable(t);
00246 }

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

Return a new term reference.

Definition at line 101 of file ppl_swiprolog.cc.

00101                       {
00102   return PL_new_term_ref();
00103 }

int @202::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 163 of file ppl_swiprolog.cc.

00163                                                {
00164   PL_put_pointer(t, p);
00165   return 1;
00166 }

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

Assign to t the Prolog atom a.

Definition at line 154 of file ppl_swiprolog.cc.

00154                                                   {
00155   PL_put_atom(t, a);
00156   return 1;
00157 }

int @202::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 145 of file ppl_swiprolog.cc.

00145                                                         {
00146   PL_put_atom_chars(t, s);
00147   return 1;
00148 }

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

Assign to t a Prolog integer with value l.

Definition at line 119 of file ppl_swiprolog.cc.

00119                                            {
00120   PL_put_integer(t, l);
00121   return 1;
00122 }

int @202::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 110 of file ppl_swiprolog.cc.

00110                                                       {
00111   PL_put_term(t, u);
00112   return 1;
00113 }

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

Assign to t a Prolog integer with value ul.

Definition at line 128 of file ppl_swiprolog.cc.

References Parma_Polyhedra_Library::assign_r(), and tmp_mpz_class.

00128                                                       {
00129   if (ul <= LONG_MAX)
00130     PL_put_integer(t, ul);
00131   else if (ul <= static_cast<uint64_t>(std::numeric_limits<int64_t>::max()))
00132     PL_put_int64(t, static_cast<int64_t>(ul));
00133   else {
00134     PPL::assign_r(tmp_mpz_class, ul, PPL::ROUND_NOT_NEEDED);
00135     PL_unify_mpz(t, tmp_mpz_class.get_mpz_t());
00136   }
00137   return 1;
00138 }

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

Raise a Prolog exception with t as the exception term.

Definition at line 236 of file ppl_swiprolog.cc.

00236                                           {
00237   (void) PL_raise_exception(t);
00238 }

int @202::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 360 of file ppl_swiprolog.cc.

00360                                                    {
00361   return PL_unify(t, u);
00362 }

install_t uninstall (  ) 

Definition at line 522 of file ppl_swiprolog.cc.

References ppl_finalize().

00522             {
00523   ppl_finalize();
00524 }


Variable Documentation

PL_extension predicates[] [static]

Definition at line 387 of file ppl_swiprolog.cc.

Referenced by install().

Definition at line 46 of file ppl_swiprolog.cc.

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

Definition at line 59 of file ppl_swiprolog.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 73 of file ppl_swiprolog.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 66 of file ppl_swiprolog.cc.

Definition at line 45 of file ppl_swiprolog.cc.

mpz_class tmp_mpz_class [static]

Temporary used to communicate big integers between C++ and Prolog.

Definition at line 78 of file ppl_swiprolog.cc.

Referenced by Coefficient_to_integer_term(), integer_term_to_Coefficient(), Prolog_get_long(), and Prolog_put_ulong().


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