[m-rev.] for review: implement det exceptions on the .NET backend.

Simon Taylor stayl at cs.mu.OZ.AU
Mon Aug 27 23:17:47 AEST 2001


On 27-Aug-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> Further investiation reveals that the math library doesn't throw
> exceptions!  It prints Software Error and calls exit(1);
> 
> Probably this is because if you were to generate an exception you
> couldn't mark the predicates as will_not_call_mercury, and thus you
> would pay a performance penalty on certain backends (cough-llds-cough).

No, it's because throwing exceptions across the C interface doesn't
work at all with the LLDS back-end (see the documentation at the top
of library/exception.m).

The better way to do this would be to do the domain checks in Mercury,
as shown below. The C compiler should be able to optimize away the
condition of the if-then-else when domain checks aren't being performed.
With this method, the domain checks aren't duplicated for each foreign
language.

We should also fix the integer and floating point division operators
to throw an exception by default on division by zero, rather than
causing a SIGFPE.

Simon.


math__sqrt(X) = Sqrt :-
	( math__domain_checks, X < 0.0 ->
		throw(math__domain_error("math__sqrt"))
	;
		Sqrt = math__sqrt2(X)
	).

:- func math__sqrt_2(float) = float.
:- pragma foreign_proc("C", math__sqrt_2(X::in) = (SquareRoot::out),
                [will_not_call_mercury, thread_safe], "
	SquareRoot = sqrt(X);
").

:- pred domain_checks is semidet.
:- pragma foreign_proc("C", domain_checks,
		[will_not_call_mercury, thread_safe],
"
#ifdef ML_OMIT_MATH_DOMAIN_CHECKS
	SUCCESS_INDICATOR = FALSE;
#else
	SUCCESS_INDICATOR = TRUE;
#endif
").

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list