[m-dev.] for review: Add new library predicate to reversibly encode two ints in a single int.

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jan 22 11:26:52 AEDT 2000


On 21-Jan-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Wed, Jan 19, 2000 at 07:12:58AM +1100, Fergus Henderson wrote:
> > On 18-Jan-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > > +% XXX we really should check that 0 <= Value < Factor and raise an exception
> > > +% if not.  But for reasons of efficiency, we don't.
> > 
> > But I think that for a standard library predicate it would probably be a
> > better idea to do the check.
> 
> Ok.  But how do I raise an exception from pragma c_code?

You don't; you return a flag, and you write a little bit of wrapper
code on the Mercury side which tests the flag and if it is set
throws an exception.

> The exception doc doesn't give any help on this.

I'll put that on the bug list.
Of course, as usual patches are welcome...

> I don't want to do the
> check in Mercury, because then the check would be done in both modes.

I think that's easily solved: in the mode where you know that no
check is needed, use a mode like `out(bound(no))' for the flag; then
the Mercury compiler will be able to optimize the check away in the
mode which doesn't need it.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list