diff --git a/compiler/ml_switch_gen.m b/compiler/ml_switch_gen.m index 381aad679..2df7c2223 100644 --- a/compiler/ml_switch_gen.m +++ b/compiler/ml_switch_gen.m @@ -600,6 +600,9 @@ ml_tagged_cons_id_to_match_cond(MLDS_Type, TaggedConsId, MatchCond) :- else Rval = ml_const(mlconst_enum(Int, MLDS_Type)) ) + ; + Tag = uint_tag(UInt), + Rval = ml_const(mlconst_uint(UInt)) ; Tag = string_tag(String), Rval = ml_const(mlconst_string(String)) @@ -608,7 +611,6 @@ ml_tagged_cons_id_to_match_cond(MLDS_Type, TaggedConsId, MatchCond) :- Rval = ml_const(mlconst_foreign(ForeignLang, ForeignTag, MLDS_Type)) ; ( Tag = float_tag(_) - ; Tag = uint_tag(_) ; Tag = closure_tag(_, _, _) ; Tag = type_ctor_info_tag(_, _, _) ; Tag = base_typeclass_info_tag(_, _, _) diff --git a/library/string.to_string.m b/library/string.to_string.m index b1179e40b..0a9d0f731 100644 --- a/library/string.to_string.m +++ b/library/string.to_string.m @@ -104,7 +104,7 @@ value_to_revstrings(NonCanon, OpsTable, X, !Rs) :- value_to_revstrings_prio(NonCanon, OpsTable, Priority, X, !Rs) :- % We need to special-case the builtin types: - % int, char, float, string + % int, uint, char, float, string % type_info, univ, c_pointer, array % and private_builtin.type_info @@ -114,6 +114,8 @@ value_to_revstrings_prio(NonCanon, OpsTable, Priority, X, !Rs) :- add_revstring(term_io.quoted_char(Char), !Rs) else if dynamic_cast(X, Int) then add_revstring(string.int_to_string(Int), !Rs) + else if dynamic_cast(X, UInt) then + add_revstring(string.uint_to_string(UInt) ++ "u", !Rs) else if dynamic_cast(X, Float) then add_revstring(string.float_to_string(Float), !Rs) else if dynamic_cast(X, Bitmap) then diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile index a63d8e81d..7bffd236d 100644 --- a/tests/hard_coded/Mmakefile +++ b/tests/hard_coded/Mmakefile @@ -356,6 +356,7 @@ ORDINARY_PROGS = \ type_to_term \ type_to_term_bug \ uc_export_enum \ + uint_switch_test \ unicode_test \ unify_existq_cons \ unify_expression \ diff --git a/tests/hard_coded/uint_switch_test.exp b/tests/hard_coded/uint_switch_test.exp new file mode 100644 index 000000000..a8d5d39a6 --- /dev/null +++ b/tests/hard_coded/uint_switch_test.exp @@ -0,0 +1,9 @@ +foo(0u, _) ==> <> +foo(1u, "one") +foo(2u, _) ==> <> +foo(3u, "three") +foo(4u, _) ==> <> +foo(5u, "five") +foo(6u, _) ==> <> +foo(7u, "seven") +foo(8u, _) ==> <> diff --git a/tests/hard_coded/uint_switch_test.m b/tests/hard_coded/uint_switch_test.m new file mode 100644 index 000000000..662f034cd --- /dev/null +++ b/tests/hard_coded/uint_switch_test.m @@ -0,0 +1,41 @@ +%---------------------------------------------------------------------------% +% vim: ft=mercury ts=4 sw=4 et +%---------------------------------------------------------------------------% + +:- module uint_switch_test. +:- interface. + +:- import_module io. + +:- pred main(io::di, io::uo) is det. + +:- implementation. + +:- import_module list. +:- import_module string. + +main(!IO) :- + test_foo_mode_0([0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u], !IO). + +:- pred foo(uint, string). +:- mode foo(in, out) is semidet. + +foo(1u, "one"). +foo(3u, "three"). +foo(5u, "five"). +foo(7u, "seven"). + +:- pred test_foo_mode_0(list(uint)::in, io::di, io::uo) is det. + +test_foo_mode_0(Values, !IO) :- + ( + Values = [] + ; + Values = [Value | ValuesPrime], + ( if foo(Value, Result) then + io.format("foo(%s, %s)\n", [s(string(Value)), s(string(Result))], !IO) + else + io.format("foo(%s, _) ==> <>\n", [s(string(Value))], !IO) + ), + test_foo_mode_0(ValuesPrime, !IO) + ).