[m-rev.] for review: improve standard library error handling
Tyson Dowd
trd at cs.mu.OZ.AU
Fri Aug 31 20:58:26 AEST 2001
On 30-Aug-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
>
> Estimated hours taken: 6
> Branches: main
>
> Generate exceptions rather than program aborts for domain errors
> and out of bounds array accesses.
>
> Improve the handling of the arithmetic functions.
>
> library/float.m:
> library/int.m:
> compiler/builtin_ops.m:
> Handle division by zero with an exception rather than a
> program abort.
>
> Add int__unchecked_quotient and float__unchecked_quotient,
> which don't check for division by zero.
>
> Remove reverse modes of the arithmetic functions in float.m.
> Richard O'Keefe pointed out a while ago that they don't work
> because of rounding errors.
>
> Remove the long obsolete `int__builtin_*' and
> `float__builtin_float_*' predicates.
>
> library/math.m:
> library/array.m:
> Generate exceptions rather than program aborts.
> The bounds and domain checks are now implemented in
> Mercury, so they do not need to be duplicated for each
> target language.
>
> As discussed on mercury-users a while ago, math__pow(0.0, 0.0)
> should return 1.0. This is also consistent with float__pow.
> See <http://www.cs.mu.oz.au/research/mercury/mailing-lists/mercury-users/mercury-users.0104/0130.html>.
>
> NEWS:
> Document the changes.
>
> tests/general/float_test.m:
> tests/general/string_format_test.m:
> tests/hard_coded/ho_solns.m:
> tests/hard_coded/ho_univ_to_type.m:
> tests/hard_coded/qual_strang.m:
> tests/hard_coded/qual_strung.m:
> Rename occurrences of `builtin_*'.
>
>
> Index: NEWS
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/NEWS,v
> retrieving revision 1.216
> diff -u -u -r1.216 NEWS
> --- NEWS 2001/08/13 05:49:27 1.216
> +++ NEWS 2001/08/29 16:13:50
> @@ -22,6 +22,16 @@
> Reference Manual.
>
> Changes to the Mercury standard library:
> +* The predicates and functions in int.m, float, math.m and array.m now
> + generate exceptions rather than program aborts on domain errors and
> + out-of-bounds array accesses.
> +
> +* We've removed the buggy reverse modes of the arithmetic functions in
> + float.m (because of rounding errors the functions aren't actually
> + reversible).
> +
> +* math__pow(0.0, 0.0) now returns 1.0, not 0.0.
> +
> * The exception module has a new predicate `try_store', which is
> like `try_io', but which works with stores rather than io__states.
>
> @@ -46,6 +56,11 @@
> representations of term components as strings.
>
> * We've made the outputs of the string concatenation primitives unique.
> +
> +* We've removed the long obsolete `int__builtin_*' and
> + `float__builtin_float_*' predicates, which were synonyms
> + for the arithmetic functions dating from when Mercury didn't
> + have functions.
>
> Index: library/array.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/array.m,v
> retrieving revision 1.97
> diff -u -u -r1.97 array.m
> --- library/array.m 2001/08/13 01:19:56 1.97
> +++ library/array.m 2001/08/29 13:52:47
> @@ -91,6 +91,11 @@
> :- mode array_muo == out(mostly_uniq_array).
> :- mode array_mui == in(mostly_uniq_array).
>
> + % An `array__error' is the exception thrown if any of the
> + % operations fail. The string is a description of the error.
> +:- type array__error
> + ---> array__error(string).
> +
I feel a specific error for array index out-of-bounds would be nice, but
I'm not adamant about it.
> -#ifdef ML_ARRAY_THROW_EXCEPTIONS
> - #include ""exception.h"" /* for ML_throw_string */
> - /* shut up warnings about casting away const */
> - #define ML_array_raise(s) ML_throw_string((char *) (void *) s)
> +:- pragma foreign_proc("C#", bounds_checks,
> + [thread_safe], "
> +#if ML_OMIT_ARRAY_BOUNDS_CHECKS
> + SUCCESS_INDICATOR = FALSE;
> #else
> - #include ""mercury_misc.h"" /* for MR_fatal_error() */
> - #define ML_array_raise(s) MR_fatal_error(s)
> + SUCCESS_INDICATOR = TRUE;
> #endif
> +").
> +
Unfortunately there is no C# support for SUCCESS_INDICATOR (yet).
Instead please use MC++ for the moment (the code is fine, just change
"C#" to be "MC++".
Same in math.m.
It's also not worth putting in #if ML_OMIT_ARRAY_BOUNDS_CHECKS
because array bounds checking is done by the .NET runtime, and cannot be
switched off.
The issue regarding pow should be resolved before making any changes --
I'll leave that up to you and Fergus and whoever else wants to duke it
out.
Otherwise the change looks good, thanks.
Tyson.
--------------------------------------------------------------------------
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