[m-rev.] for review: add uint->uintN conversions

Julien Fischer jfischer at opturion.com
Wed Jun 30 21:38:18 AEST 2021


Hi Zoltan,

On Wed, 30 Jun 2021, Zoltan Somogyi wrote:

> For review by anyone. I would particularly like someone
> to check the Java and C# foreign procs, and I am interested
> in people's opinions on the name of the new op in uint64.m,

The name is fine; it has the virtue of being consistent with
the other modules.

> since for that type, from_uint, det_from_uint, and cast_from_uint
> are effectively the same operation.

...

> Add uint->uintN conversions.
> 
> library/uint16.m:
> library/uint32.m:
> library/uint64.m:
> library/uint8.m:
>     Add to each of these modules whichever subset of {from_uint, det_from_uint,
>     cast_from_uint} makes sense for that module.
> 
> NEWS:
>     Announce the new predicates and functions.

The test suite should be extended to cover these new operations.

> diff --git a/library/uint64.m b/library/uint64.m
> index e61c2defe..ff6067bb5 100644
> --- a/library/uint64.m
> +++ b/library/uint64.m
> @@ -45,6 +45,19 @@
>      %
>  :- func cast_from_int(int) = uint64.
> 
> +%---------------------------------------------------------------------------%
> +%
> +% Conversion from uint.
> +%
> +
> +    % cast_from_uint(U) = U64:
> +    %
> +    % Convert a uint to a uint64.
> +    % Always succeeds, and will always yield a result that is
> +    % mathematically equal U.
> +    %
> +:- func cast_from_uint(int) = uint64.

The argument type is incorrect there; it should be uint *not* int.

> 
> @@ -464,8 +477,6 @@ det_from_int(I) = U64 :-
>          error($pred, "cannot convert int to uint64")
>      ).

...

> +
> +:- pragma foreign_proc("Java",
> +    cast_from_uint(U::in) = (U64::out),
> +    [will_not_call_mercury, promise_pure, thread_safe],
> +"
> +    U64 = U;
> +").

That should be:

       U64 = (long) U & 0xffffffffL;

(Consider what happens when U is max_uint in the Java grade.)

The rest looks fine.

Julien.


More information about the reviews mailing list