Files
mercury/tests/string_format/string_format_uint_x.m
Julien Fischer 9528f326d2 Formatting of uints using string.format etc.
Extend the operations that perform formatted conversion, such as
string.format/2, to be able to handle values of type uint directly. We have
always supported formatting values of type int as unsigned values, but
currently the only way to format uint values is by explicitly casting them to
an int. This addresses Mantis issue #502.

library/string.m:
    Add a new alternative to the poly_type/0 type that wraps uint
    values.

    Update the documentation for string.format. uint values may
    now be formatted using the u, x, X, o or p  conversion specifiers.

library/string.format.m:
   Add the necessary machinery for handling formatting of uint values.

library/string.parse_runtime.m:
library/string.parse_util.m:
   Handle uint poly_types.

library/io.m:a
   Handle uint values in the write_many predicates.

library/pprint.m:
   Handle uint values in the poly/1 function.

compiler/format_call.m:
compiler/parse_string_format.m:
    Conform to the above changes.

compiler/options.m:
    Add a way to detect if a compiler supports this change.

NEWS:
    Announce the above changes.

tests/hard_coded/stream_format.{m,exp}:
    Extend this test to cover uints.

tests/invalid/string_format_bad.m:
tests/invalid/string_format_unknown.m:
    Conform to the above changes.

tests/string_format/Mmakefile:
tests/string_format/string_format_uint_o.{m,exp,exp2}:
tests/string_format/string_format_uint_u.{m,exp,exp2}:
tests/string_format/string_format_uint_x.{m,exp,exp2}:
   Add tests of string.format with uints.
2020-05-23 14:01:01 +10:00

36 lines
1.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Test the x, X specifiers of string.format with uints.
%
% The .exp file is for when uint is 32-bit.
% The .exp2 file is for when uint is 64-bit.
%
%---------------------------------------------------------------------------%
:- module string_format_uint_x.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module string.
:- import_module string_format_lib.
:- import_module uint.
main(!IO) :-
UInts = [u(0u), u(1u), u(10u), u(100u), u(max_uint)],
list.foldl(output_list(UInts), format_strings("x"), !IO),
list.foldl(output_list(UInts), format_strings("X"), !IO).
%---------------------------------------------------------------------------%