Two fixes for uint support.

1. Fix an abort in the MLDS backend involving switches on uints.

2. Make string.string/1 handle uints.

compiler/ml_switch_gen.m:
    Handle uints properly in a spot.

library/string.to_string.m:
     Make string.string/1 handle uint values.

tests/hard_coded/Mmakefile:
tests/hard_coded/uint_switch_test.{m,exp}:
     Add a test case.
This commit is contained in:
Julien Fischer
2017-05-24 09:59:01 +10:00
parent 304d989749
commit e9b0c489d2
5 changed files with 57 additions and 2 deletions

View File

@@ -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(_, _, _)

View File

@@ -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

View File

@@ -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 \

View File

@@ -0,0 +1,9 @@
foo(0u, _) ==> <<FALSE>>
foo(1u, "one")
foo(2u, _) ==> <<FALSE>>
foo(3u, "three")
foo(4u, _) ==> <<FALSE>>
foo(5u, "five")
foo(6u, _) ==> <<FALSE>>
foo(7u, "seven")
foo(8u, _) ==> <<FALSE>>

View File

@@ -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, _) ==> <<FALSE>>\n", [s(string(Value))], !IO)
),
test_foo_mode_0(ValuesPrime, !IO)
).