[PPL-devel] Re: [Yap-users] Communicating multiple-precision integers to foreign code and back
Vitor Santos Costa
vitor at biostat.wisc.edu
Fri May 14 20:00:33 CEST 2004
Sorry for the previous message, I actually grepped for a message from
you and Christian I did not answered at the time and found the other
message, which I suppose I never did reply :-(.
> 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).
Yes, YAP_WriteBuffer and YAP_ReadBuffer should do what you want. They
are a bit heavier than what one would like, but I suspect the actual
overhead of generating a text representation for a bignum is more than
the overhead of parsing.
> 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;
No, Yap should have something like PL_query, that's quite easy to do
and other people have asked for it, I'll see if I can have today (you
can always call Prolog to call call current_prolog_flag, but it is
kind of overkill).
> 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().
I suppose I could have a specialised routine eventually...
More information about the PPL-devel