[PPL-devel] Re: [Yap-users] Communicating multiple-precision integers to foreign code and back

Roberto Bagnara bagnara at cs.unipr.it
Wed May 5 14:47:46 CEST 2004


Vitor Santos Costa wrote:
> I suppose such an interface is really in order. I haven't done much
> because (1) no one asked before, and (2) it will make the interface
> depend on GMP, which is not always available. But (1) is broken now,
> and (2) should not be strong enough.

I think that the interface should not depend on GMP: the ability
to communicate Prolog integers back and forth should be present
anyway and not depend on the size of those Prolog integers.
In other words, I believe the presence of GMP should only
influence the availability of unbounded integers, not the way
integers of any size are communicated (on YAP systems compiled
without the GMP, trying to convert an externally-provided integer
that is too large will simply cause the C function implementing
the conversion to return an error code).

Which brings me to another question: what is the best way for
foreign code to know whether it is interfaced to a YAP system
with bounded or unbounded integers?  And to obtain the minimum
and maximum integers?  Is there a sensible alternative
to calling current_prolog_flag/2?  For instance, for SWI-Prolog
you can write the following C code:

   Prolog_min_integer = PL_query(PL_QUERY_MIN_INTEGER);
   Prolog_max_integer = PL_query(PL_QUERY_MAX_INTEGER);

whereas this is valid C for interfacing with GNU Prolog

   Prolog_min_integer = INT_LOWEST_VALUE;
   Prolog_max_integer = INT_GREATEST_VALUE;

> That's a good point, actually. Do you know how other systems cope with
> that?

SICStus Prolog offers SP_put_integer_bytes() and SP_get_integer_bytes(),
SP_put_number_chars() and SP_get_number_chars().  I suppose the former
are more efficient than the latter.

Ciao Prolog has ciao_put_number_chars() and ciao_get_number_chars().
Cheers,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it



More information about the PPL-devel mailing list