[m-rev.] for review: allow sized integers as format arguments

Julien Fischer jfischer at opturion.com
Mon Nov 9 18:00:31 AEDT 2020


On Mon, 9 Nov 2020, Zoltan Somogyi wrote:

> For review by anyone.
>
> The diff does not update the expected output files
> of the two extended test cases, since that is best done
> after this diff is installed, and my machine is just now
> working on that. I will post a proposed update to NEWS
> after this diff has been reviewed.


> Allow formatting of sized integers.
> 
> library/string.m:
>     Add {i,u}{8.16,32,64} as function symbols in the poly_type type,
>     each with a single argument containing an integer with the named
>     size and signedness.
>
>     The idea is that each of these poly_type values works exactly
>     the same way as the i(_) poly_type (if signed) or the u(_) poly_type
>     (if unsigned), with the exception that the value specified by the call
>     is cast to int or uint before being processed.

That's fine for 8-, 16- and 32-bit integer types.  It won't work for 64-bit integer
types on systems where int / uint are 32-bit.

> library/string.parse_runtime.m:
>     Parse the new kinds of poly_types. Change the representation of the result
>     of the parsing to allow recording of the sizes of ints and uints.
>
>     Put the code that does the parsing into a predicate of its own.
> 
> library/string.format.m:
>     Do a cast to int or uint if the size information recorded in the
>     specification of a signed or unsigned integer value calls for it.
>
>     Provide functions to do the casting that do not require the import
>     of {int,uint}{8,16,32,64}.m. This is to allow the compiler to generate
>     calls to do such casts without having to implicitly import those modules.
> 
> compiler/parse_string_format.m:
>     Make the same changes as in string.parse_runtime.m, mutatis mutandis.
> 
> compiler/format_call.m:
>     Handle the new kinds of poly_types by adding a cast to int or uint
>     if necessary, using the predicates added to library/string.format.m.
>
>     Use a convenience function to make code creating instmap deltas
>     more readable.

...

> +%---------------------------------------------------------------------------%
> diff --git a/library/string.m b/library/string.m
> index 6c92168..730cc3c 100644
> --- a/library/string.m
> +++ b/library/string.m
> @@ -1556,7 +1556,15 @@
>  :- type poly_type
>      --->    f(float)
>      ;       i(int)
> +    ;       i8(int8)
> +    ;       i16(int16)
> +    ;       i32(int32)
> +    ;       i64(int64)
>      ;       u(uint)
> +    ;       u8(uint8)
> +    ;       u16(uint16)
> +    ;       u32(uint32)
> +    ;       u64(uint64)
>      ;       s(string)
>      ;       c(char).

The documentation directly below this type declaration (for string.format) should
also be updated.

That's fine otherwise.

Julien.


More information about the reviews mailing list