[m-rev.] for review: mercury implementation of string__format

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 22 03:20:27 AEDT 2002


On 21-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> Estimated hours taken: 216 (200 from paulai)
> Branches: main
> 
> Add a Mercury implementation of string__format for use on backends
> which don't support sprintf.
> 
> library/string.m:
> 	Mercury implemenation of string__format.

s/implemenation/implementation/

> configure.in:
> 	Test for the existences of the header file ieeefp.h.

s/existences/existence/

> library/float.m:
> 	Add is_nan and is_inf which test whether a float is not a
> 	number or an infinity respectively.

These should be mentioned in the NEWS file.

> runtime/mercury_conf.h.in:
> 	#define for existence of ieeefp.h.

It would be nice to also check for isnan() and isinf() in <math.h>, which
is where C99 puts them.

> +:- pragma promise_pure(is_nan/1).
> +:- pragma foreign_proc(c, is_nan(Flt::in),
> +		[will_not_call_mercury, thread_safe], "
> +#if MR_USE_SINGLE_PREC_FLOAT
> +	SUCCESS_INDICATOR = isnanf(Flt);
> +#else
> +	SUCCESS_INDICATOR = isnan(Flt);
> +#endif

The use of isnan() and isnanf() need to be protected by
conditional compilation, since not all systems support them.

Likewise for isinf() and isinff().

> +is_nan(_) :-
> +	% This version is only used for back-ends for which there is no
> +	% matching foreign_proc version.
> +	private_builtin__sorry("float__is_nan").
...
> +is_inf(_) :-
> +	% This version is only used for back-ends for which there is no
> +	% matching foreign_proc version.
> +	private_builtin__sorry("float__is_inf").

> Index: library/string.m
...
> +		( using_sprintf, semidet_fail ->
> +			FormatStr = make_format(Flags, Width, Prec, "", "s"),
> +			String = native_format_string(FormatStr, Str)
> +		;
> +			String = format_string(Flags,
> +					conv(Width), conv(Prec), Str)
> +		)

What's the call to semidet_fail for?

> +:- type flags == list(char).
> +:- type maybe_width == maybe(int).
> +:- type maybe_precision == maybe(int).
> +
> +:- import_module integer.

All imports should be listed at the top of the corresponding
interface or implementation section.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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