[m-rev.] for review: add a builtin unsigned word sized integer type -- Part 1

Julien Fischer jfischer at opturion.com
Mon Oct 24 12:50:00 AEDT 2016


For review by anyone.

I won't commit this until I've finished part 2 of this change and posted
that for review.  Once it is committed everyone will need to update
their installed compilers before part 2 is commited.

-------------------------

Add a builtin unsigned word sized integer type -- Part 1.

Add a new builtin type: uint, which is an unsigned word sized integer type.
Support for this new type will need be bootstrapped over several changes.
This is the first such change and does the following:

- Extends the compiler to recognize 'uint' as a builtin type.
- Extends the set of builtin operations to include relational and (some)
   arithmetic operations on uints.
- Extends all of the code generators to handle the above.  There are some
   limitations currently marked by 'XXX UINT'.  These will be lifted once
   the compiler recognised uint and additional library support becomes
   available.
- Extends the runtime to support uints.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
     Recognize uint as a builtin type.

     Add a new alternative to the cons_id/0 type corresponding to the uint type
     -- for bootstrapping purposes its argument is currently an int.

compiler/builtin_ops.m:
     Add builtin relational and arithmetic operations on uints.  Note that the
     existing 'unsigned_le' operation is actually intended for use with signed
     values.  Rather than attempt to modify its meaning, I have just added new
     operations specific to the uint type.

compiler/hlds_data.m:
     Add a new tag type for uints.

compiler/type_ctor_info.m:
     Recognise uint as a builtin.

     Bump the RTTI version number here.

compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/special_pred.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
     Conform to the above changes to the parse tree and HLDS.

compiler/c_util.m:
     Support generating builtin operations for uints.

compiler/llds.m:
     Add a representation for uint constants to the LLDS.

     Map uints onto MR_Unsigned.

compiler/call_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/opt_debug.m:
compiler/opt_util.m:
     Support uints in the LLDS code generator.

compiler/mlds.m:
      Support uint constants in the MLDS.

compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_global_data.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
     Conform to the above change to the MLDS.

compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
      Generate the appropriate target code for uint constants and uint
      relational operations.

compiler/bytecode.m:
compiler/bytecode_gen.m:
      Handle uints in the bytecode generator: we just abort if we
      encounter them for now.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
     Handle uints in the Erlang code generator.

library/private_builtin.m:
     Add placeholders for builtin_{unify,compare}_uint.  Since the
     bootstrapping compiler will not recognize uint as a type, we
     give them polymorphic arguments.  These can be replaced after
     this change has bootstrapped.

     Update the Java list of TypeCtorRep constants, which for some
     reason is defined here.

library/uint.m:
     New module that will eventually contain operations on uints.

library/MODULES_DOCS:
library/library.m:
      Add the uint module.

library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
mdbcomp/program_representation.m:
      Handle uints.

deep_profiler/program_representation_utils.m:
      Conform to the above change.

runtime/mercury_dotnet.cs.in:
      Update the list of TypeCtorReps for C#

java/runtime/TypeCtorRep.java:
      Update this, although the actual TypeCtorRep constants
      are defined the library.

runtime/mercury_type_info.h:
     Bump the RTTI version number.

     Add an alternative for uints to the tyepctor rep enum.

runtime/mercury_builtin_types.{h,c}:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_unify_compare_body.h:
     Add uint as a builtin type and handle it throughout the runtime.

runtime/mercury_grade.h:
     Bump the binary compatibility version.

runtime/mercury_term_size.c:
runtime/mercury_ml_expand_body.h:
     Handle uint and fix probable bugs with the handling of ints on
     64-bit Windows.

diff --git a/compiler/builtin_lib_types.m b/compiler/builtin_lib_types.m
index eef932e..44ab702 100644
--- a/compiler/builtin_lib_types.m
+++ b/compiler/builtin_lib_types.m
@@ -25,6 +25,7 @@
  %

  :- func int_type = mer_type.
+:- func uint_type = mer_type.
  :- func float_type = mer_type.
  :- func string_type = mer_type.
  :- func char_type = mer_type.
@@ -58,6 +59,7 @@
  %

  :- func int_type_ctor = type_ctor.
+:- func uint_type_ctor = type_ctor.
  :- func float_type_ctor = type_ctor.
  :- func char_type_ctor = type_ctor.
  :- func string_type_ctor = type_ctor.
@@ -112,6 +114,8 @@

  int_type = builtin_type(builtin_type_int).

+uint_type = builtin_type(builtin_type_uint).
+
  float_type = builtin_type(builtin_type_float).

  string_type = builtin_type(builtin_type_string).
@@ -212,6 +216,8 @@ future_type(ValueType) = defined_type(Name, [ValueType], kind_star) :-

  int_type_ctor = type_ctor(Name, 0) :-
      Name = unqualified("int").
+uint_type_ctor = type_ctor(Name, 0) :-
+    Name = unqualified("uint").
  float_type_ctor = type_ctor(Name, 0) :-
      Name = unqualified("float").
  char_type_ctor = type_ctor(Name, 0) :-
diff --git a/compiler/builtin_ops.m b/compiler/builtin_ops.m
index 563aa6a..4183ad3 100644
--- a/compiler/builtin_ops.m
+++ b/compiler/builtin_ops.m
@@ -81,19 +81,31 @@
              % or equivalent code on backends which support this, and code
              % equivalent to "strcmp(SA, SB) == 0" on backends which don't.

-    ;       int_lt  % signed integer comparions
+    ;       int_lt  % signed integer comparisons
      ;       int_gt
      ;       int_le
      ;       int_ge
-    ;       unsigned_le % unsigned integer comparison
+
+    ;       unsigned_le % unsigned integer comparison (for signed values)
              % Note that the arguments to `unsigned_le' are just ordinary
              % (signed) Mercury ints, but it does the comparison as
              % if they were first cast to an unsigned type, so e.g.
              % binary(unsigned_le, int_const(1), int_const(-1)) returns true,
              % since (MR_Unsigned) 1 <= (MR_Unsigned) -1.

-    ;       float_plus
-    ;       float_minus
+    ;       uint_eq
+    ;       uint_ne
+    ;       uint_lt
+    ;       uint_gt
+    ;       uint_le
+    ;       uint_ge
+
+    ;       uint_add
+    ;       uint_sub
+    ;       uint_mul
+
+    ;       float_plus      %  XXX the integer versions use different names.
+    ;       float_minus     %  E.g add instead of plus etc.
      ;       float_times
      ;       float_divide
      ;       float_eq
@@ -163,6 +175,7 @@
  :- type simple_expr(T)
      --->    leaf(T)
      ;       int_const(int)
+    ;       uint_const(int)     % XXX until uint is recognised.
      ;       float_const(float)
      ;       unary(unary_op, simple_expr(T))
      ;       binary(binary_op, simple_expr(T), simple_expr(T)).
@@ -371,6 +384,32 @@ builtin_translation(ModuleName, PredName, ProcNum, Args, Code) :-
              Code = test(binary(CompareOp, leaf(X), leaf(Y)))
          )
      ;
+        ModuleName = "uint",
+        (
+            PredName = "+",
+            Args = [X, Y, Z],
+            ProcNum = 0,
+            Code = assign(Z, binary(uint_add, leaf(X), leaf(Y)))
+        ;
+            PredName = "-",
+            Args = [X, Y, Z],
+            ProcNum = 0,
+            Code = assign(Z, binary(uint_sub, leaf(X), leaf(Y)))
+        ;
+            PredName = "*",
+            Args = [X, Y, Z],
+            ProcNum = 0,
+            Code = assign(Z, binary(uint_mul, leaf(X), leaf(Y)))
+        ;
+            ( PredName = ">", CompareOp = uint_gt
+            ; PredName = "<", CompareOp = uint_lt
+            ; PredName = ">=", CompareOp = uint_ge
+            ; PredName = "=<", CompareOp = uint_le
+            ),
+            ProcNum = 0, Args = [X, Y],
+            Code = test(binary(CompareOp, leaf(X), leaf(Y)))
+        )
+    ;
          ModuleName = "float",
          (
              PredName = "+",
diff --git a/compiler/bytecode.m b/compiler/bytecode.m
index 56d7baa..66c9166 100644
--- a/compiler/bytecode.m
+++ b/compiler/bytecode.m
@@ -1076,6 +1076,15 @@ binop_code(float_from_dword,        41).
  binop_code(pointer_equal_conservative, 42).
  binop_code(offset_str_eq(_),        43).
  binop_code(string_unsafe_index_code_unit, 44).
+binop_code(uint_eq,                 45).
+binop_code(uint_ne,                 46).
+binop_code(uint_lt,                 47).
+binop_code(uint_gt,                 48).
+binop_code(uint_le,                 49).
+binop_code(uint_ge,                 50).
+binop_code(uint_add,                51).
+binop_code(uint_sub,                52).
+binop_code(uint_mul,                53).

  :- pred binop_debug(binary_op::in, string::out) is det.

@@ -1124,6 +1133,15 @@ binop_debug(float_from_dword,       "float_from_dword").
  binop_debug(pointer_equal_conservative, "pointer_equal_conservative").
  binop_debug(offset_str_eq(_),       "offset_str_eq").
  binop_debug(string_unsafe_index_code_unit, "string_unsafe_index_code_unit").
+binop_debug(uint_eq,                "uint_eq").
+binop_debug(uint_ne,                "uint_ne").
+binop_debug(uint_lt,                "uint_lt").
+binop_debug(uint_gt,                "uint_gt").
+binop_debug(uint_le,                "uint_le").
+binop_debug(uint_ge,                "uint_ge").
+binop_debug(uint_add,               "uint_add").
+binop_debug(uint_sub,               "uint_sub").
+binop_debug(uint_mul,               "uint_mul").

  :- pred unop_code(unary_op::in, int::out) is det.

diff --git a/compiler/bytecode_gen.m b/compiler/bytecode_gen.m
index ff0b66e..e6364d4 100644
--- a/compiler/bytecode_gen.m
+++ b/compiler/bytecode_gen.m
@@ -580,6 +580,9 @@ gen_unify(Unification, ByteInfo, Code) :-
              TypeCategory = ctor_cat_builtin(cat_builtin_int),
              TestId = int_test
          ;
+            TypeCategory = ctor_cat_builtin(cat_builtin_uint),
+            sorry($module, $pred, "uint")
+        ;
              TypeCategory = ctor_cat_builtin(cat_builtin_char),
              TestId = char_test
          ;
@@ -765,6 +768,9 @@ map_cons_id(ByteInfo, ConsId, ByteConsId) :-
          ConsId = int_const(IntVal),
          ByteConsId = byte_int_const(IntVal)
      ;
+        ConsId = uint_const(_),
+        unexpected($file, $pred, "uint")
+    ;
          ConsId = float_const(FloatVal),
          ByteConsId = byte_float_const(FloatVal)
      ;
@@ -827,6 +833,8 @@ map_cons_tag(string_tag(_), _) :-
      unexpected($module, $pred, "string_tag cons tag " ++
          "for non-string_constant cons id").
  map_cons_tag(int_tag(IntVal), byte_enum_tag(IntVal)).
+map_cons_tag(uint_tag(_), _) :-
+    sorry($module, $pred, "bytecode with uints").
  map_cons_tag(foreign_tag(_, _), _) :-
      sorry($module, $pred, "bytecode with foreign tags").
  map_cons_tag(float_tag(_), _) :-
diff --git a/compiler/c_util.m b/compiler/c_util.m
index 0642041..8c6a66b 100644
--- a/compiler/c_util.m
+++ b/compiler/c_util.m
@@ -217,6 +217,8 @@
      ;       general_string_compare_binop
      ;       string_compare_binop
      ;       unsigned_compare_binop
+    ;       uint_compare_binop
+    ;       uint_arith_binop
      ;       float_compare_binop
      ;       float_arith_binop
      ;       int_or_bool_binary_infix_binop
@@ -818,6 +820,17 @@ binop_category_string(str_gt, string_compare_binop, ">").

  binop_category_string(unsigned_le, unsigned_compare_binop, "<=").

+binop_category_string(uint_eq, uint_compare_binop, "==").
+binop_category_string(uint_ne, uint_compare_binop, "!=").
+binop_category_string(uint_le, uint_compare_binop, "<=").
+binop_category_string(uint_ge, uint_compare_binop, ">=").
+binop_category_string(uint_lt, uint_compare_binop, "<").
+binop_category_string(uint_gt, uint_compare_binop, ">").
+
+binop_category_string(uint_add, uint_arith_binop, "+").
+binop_category_string(uint_sub, uint_arith_binop, "-").
+binop_category_string(uint_mul, uint_arith_binop, "*").
+
  binop_category_string(float_plus, float_arith_binop, "+").
  binop_category_string(float_minus, float_arith_binop, "-").
  binop_category_string(float_times, float_arith_binop, "*").
diff --git a/compiler/call_gen.m b/compiler/call_gen.m
index 7c33e78..a4a9e17 100644
--- a/compiler/call_gen.m
+++ b/compiler/call_gen.m
@@ -746,6 +746,7 @@ generate_assign_builtin(Var, AssignExpr, Code, !CLD) :-

  convert_simple_expr(leaf(Var)) = var(Var).
  convert_simple_expr(int_const(Int)) = const(llconst_int(Int)).
+convert_simple_expr(uint_const(UInt)) = const(llconst_uint(UInt)).
  convert_simple_expr(float_const(Float)) = const(llconst_float(Float)).
  convert_simple_expr(unary(UnOp, Expr)) =
      unop(UnOp, convert_simple_expr(Expr)).
diff --git a/compiler/ctgc.selector.m b/compiler/ctgc.selector.m
index d8b35d8..7f1465e 100644
--- a/compiler/ctgc.selector.m
+++ b/compiler/ctgc.selector.m
@@ -116,6 +116,7 @@ selector_init(ConsId, Index) = [TermSel] :-
      ;
          ( ConsId = closure_cons(_, _)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/dead_proc_elim.m b/compiler/dead_proc_elim.m
index 4bfd201..e6de0ea 100644
--- a/compiler/dead_proc_elim.m
+++ b/compiler/dead_proc_elim.m
@@ -818,6 +818,7 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
                  ( ConsId = cons(_, _, _)
                  ; ConsId = tuple_cons(_)
                  ; ConsId = int_const(_)
+                ; ConsId = uint_const(_)
                  ; ConsId = float_const(_)
                  ; ConsId = char_const(_)
                  ; ConsId = string_const(_)
diff --git a/compiler/dependency_graph.m b/compiler/dependency_graph.m
index 10039bc..32c5dbe 100644
--- a/compiler/dependency_graph.m
+++ b/compiler/dependency_graph.m
@@ -492,6 +492,7 @@ add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph) :-
          ( ConsId = cons(_, _, _)
          ; ConsId = tuple_cons(_)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/dupproc.m b/compiler/dupproc.m
index 1e8b7d1..483e27a 100644
--- a/compiler/dupproc.m
+++ b/compiler/dupproc.m
@@ -436,6 +436,9 @@ standardize_rval_const(Const, StdConst, DupProcMap) :-
          Const = llconst_int(_),
          StdConst = Const
      ;
+        Const = llconst_uint(_),
+        StdConst = Const
+    ;
          Const = llconst_foreign(_, _),
          StdConst = Const
      ;
diff --git a/compiler/elds.m b/compiler/elds.m
index 7444479..b01e4a5 100644
--- a/compiler/elds.m
+++ b/compiler/elds.m
@@ -214,6 +214,7 @@
  :- type elds_term
      --->    elds_char(char)
      ;       elds_int(int)
+    ;       elds_uint(int)  % XXX UINT.
      ;       elds_float(float)

      ;       elds_binary(string)
diff --git a/compiler/elds_to_erlang.m b/compiler/elds_to_erlang.m
index 46d98a7..2993540 100644
--- a/compiler/elds_to_erlang.m
+++ b/compiler/elds_to_erlang.m
@@ -778,6 +778,10 @@ output_term(ModuleInfo, VarSet, Indent, Term, !IO) :-
          io.write_int(Int, !IO),
          space(!IO)
      ;
+        Term = elds_uint(UInt),
+        io.write_int(UInt, !IO),    % XXX UINT.
+        space(!IO)
+    ;
          Term = elds_float(Float),
          output_float(Float, !IO),
          space(!IO)
diff --git a/compiler/erl_call_gen.m b/compiler/erl_call_gen.m
index 7b6542e..b496945 100644
--- a/compiler/erl_call_gen.m
+++ b/compiler/erl_call_gen.m
@@ -445,6 +445,9 @@ erl_gen_simple_expr(ModuleInfo, VarTypes, SimpleExpr) = Expr :-
          SimpleExpr = int_const(Int),
          Expr = elds_term(elds_int(Int))
      ;
+        SimpleExpr = uint_const(UInt),
+        Expr = elds_term(elds_uint(UInt))
+    ;
          SimpleExpr = float_const(Float),
          Expr = elds_term(elds_float(Float))
      ;
@@ -549,6 +552,15 @@ std_binop_to_elds(StdBinOp, EldsBinOp) :-
          ; StdBinOp = float_ge,              EldsBinOp = elds.(>=)
          ; StdBinOp = compound_eq,           EldsBinOp = elds.(=:=)
          ; StdBinOp = compound_lt,           EldsBinOp = elds.(<)
+        ; StdBinOp = uint_eq,               EldsBinOp = elds.(=:=)
+        ; StdBinOp = uint_ne,               EldsBinOp = elds.(=/=)
+        ; StdBinOp = uint_lt,               EldsBinOp = elds.(<)
+        ; StdBinOp = uint_gt,               EldsBinOp = elds.(>)
+        ; StdBinOp = uint_le,               EldsBinOp = elds.(=<)
+        ; StdBinOp = uint_ge,               EldsBinOp = elds.(>=)
+        ; StdBinOp = uint_add,              EldsBinOp = elds.add
+        ; StdBinOp = uint_sub,              EldsBinOp = elds.sub
+        ; StdBinOp = uint_mul,              EldsBinOp = elds.mul
          )
      ).

diff --git a/compiler/erl_code_util.m b/compiler/erl_code_util.m
index da7a276..e91689b 100644
--- a/compiler/erl_code_util.m
+++ b/compiler/erl_code_util.m
@@ -650,6 +650,7 @@ erl_rename_vars_in_terms(Subn, Terms0, Terms) :-
  erl_rename_vars_in_term(Subn, Term0, Term) :-
      (
          ( Term0 = elds_int(_)
+        ; Term0 = elds_uint(_)
          ; Term0 = elds_float(_)
          ; Term0 = elds_binary(_)
          ; Term0 = elds_list_of_ints(_)
@@ -814,6 +815,7 @@ erl_vars_in_terms(Terms, !Set) :-
  erl_vars_in_term(Term, !Set) :-
      (
          ( Term = elds_int(_)
+        ; Term = elds_uint(_)
          ; Term = elds_float(_)
          ; Term = elds_binary(_)
          ; Term = elds_list_of_ints(_)
@@ -952,6 +954,7 @@ erl_terms_size(Terms) = sum(list.map(erl_term_size, Terms)).
  erl_term_size(Term) = Size :-
      (
          ( Term = elds_int(_)
+        ; Term = elds_uint(_)
          ; Term = elds_float(_)
          ; Term = elds_binary(_)
          ; Term = elds_list_of_ints(_)
diff --git a/compiler/erl_rtti.m b/compiler/erl_rtti.m
index a174b08..3dac2c8 100644
--- a/compiler/erl_rtti.m
+++ b/compiler/erl_rtti.m
@@ -608,6 +608,8 @@ erlang_type_ctor_rep(erlang_eqv(_)) =
      elds_term(make_enum_alternative("etcr_eqv")).
  erlang_type_ctor_rep(erlang_builtin(builtin_ctor_int)) =
      elds_term(make_enum_alternative("etcr_int")).
+erlang_type_ctor_rep(erlang_builtin(builtin_ctor_uint)) =
+    elds_term(make_enum_alternative("etcr_uint")).
  erlang_type_ctor_rep(erlang_builtin(builtin_ctor_float)) =
      elds_term(make_enum_alternative("etcr_float")).
  erlang_type_ctor_rep(erlang_builtin(builtin_ctor_char)) =
diff --git a/compiler/erl_unify_gen.m b/compiler/erl_unify_gen.m
index e2448e5..ae0cdd0 100644
--- a/compiler/erl_unify_gen.m
+++ b/compiler/erl_unify_gen.m
@@ -65,6 +65,7 @@
      --->    cons(ground, ground, ground)
      ;       tuple_cons(ground)
      ;       int_const(ground)
+    ;       uint_const(ground)
      ;       float_const(ground)
      ;       char_const(ground)
      ;       string_const(ground).
@@ -278,6 +279,9 @@ cons_id_to_term(ConsId, Args, DummyVarReplacement, Term, !Info) :-
          ConsId = int_const(Int),
          Term = elds_int(Int)
      ;
+        ConsId = uint_const(UInt),
+        Term = elds_uint(UInt)
+    ;
          ConsId = float_const(Float),
          Term = elds_float(Float)
      ;
@@ -293,6 +297,7 @@ cons_id_to_expr(ConsId, Args, DummyVarReplacement, Expr, !Info) :-
          ( ConsId = cons(_, _, _)
          ; ConsId = tuple_cons(_)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/export.m b/compiler/export.m
index 130f6bb..a73102d 100644
--- a/compiler/export.m
+++ b/compiler/export.m
@@ -653,7 +653,9 @@ convert_type_to_mercury(Rval, Type, TargetArgLoc, ConvertedRval) :-
              % is signed.
              ConvertedRval = "(MR_UnsignedChar) " ++ Rval
          ;
-            BuiltinType = builtin_type_int,
+            ( BuiltinType = builtin_type_int
+            ; BuiltinType = builtin_type_uint
+            ),
              ConvertedRval = Rval
          )
      ;
@@ -684,6 +686,7 @@ convert_type_from_mercury(SourceArgLoc, Rval, Type, ConvertedRval) :-
              )
          ;
              ( BuiltinType = builtin_type_int
+            ; BuiltinType = builtin_type_uint
              ; BuiltinType = builtin_type_char
              ),
              ConvertedRval = Rval
@@ -976,6 +979,7 @@ foreign_const_name_and_tag(TypeCtor, Mapping, TagValues, Ctor,
          Tag    = ee_tag_rep_string(ForeignTag)
      ;
          ( TagVal = string_tag(_)
+        ; TagVal = uint_tag(_)
          ; TagVal = float_tag(_)
          ; TagVal = closure_tag(_, _, _)
          ; TagVal = type_ctor_info_tag(_, _, _)
diff --git a/compiler/exprn_aux.m b/compiler/exprn_aux.m
index eda52fb..f0c860d 100644
--- a/compiler/exprn_aux.m
+++ b/compiler/exprn_aux.m
@@ -110,6 +110,7 @@ const_is_constant(Const, ExprnOpts, IsConst) :-
          ( Const = llconst_true
          ; Const = llconst_false
          ; Const = llconst_int(_)
+        ; Const = llconst_uint(_)
          ; Const = llconst_foreign(_, _)
          ; Const = llconst_string(_)
          ; Const = llconst_multi_string(_)
diff --git a/compiler/foreign.m b/compiler/foreign.m
index 06ea974..e613876 100644
--- a/compiler/foreign.m
+++ b/compiler/foreign.m
@@ -231,6 +231,9 @@ exported_type_to_string(Lang, ExportedType) = Result :-
                      BuiltinType = builtin_type_int,
                      Result = "MR_Integer"
                  ;
+                    BuiltinType = builtin_type_uint,
+                    Result = "MR_Unsigned"
+                ;
                      BuiltinType = builtin_type_float,
                      Result = "MR_Float"
                  ;
@@ -266,6 +269,9 @@ exported_type_to_string(Lang, ExportedType) = Result :-
                      BuiltinType = builtin_type_int,
                      Result = "int"
                  ;
+                    BuiltinType = builtin_type_uint,
+                    Result = "uint"
+                ;
                      BuiltinType = builtin_type_float,
                      Result = "double"
                  ;
@@ -295,6 +301,9 @@ exported_type_to_string(Lang, ExportedType) = Result :-
                      BuiltinType = builtin_type_int,
                      Result = "int"
                  ;
+                    BuiltinType = builtin_type_uint,
+                    Result = "int"
+                ;
                      BuiltinType = builtin_type_float,
                      Result = "double"
                  ;
diff --git a/compiler/global_data.m b/compiler/global_data.m
index 2f09104..56149e6 100644
--- a/compiler/global_data.m
+++ b/compiler/global_data.m
@@ -1345,6 +1345,7 @@ remap_rval_const(Remap, Const0, Const) :-
          ( Const0 = llconst_true
          ; Const0 = llconst_false
          ; Const0 = llconst_int(_)
+        ; Const0 = llconst_uint(_)
          ; Const0 = llconst_foreign(_, _)
          ; Const0 = llconst_float(_)
          ; Const0 = llconst_string(_)
diff --git a/compiler/goal_util.m b/compiler/goal_util.m
index d3c6d41..f8d0516 100644
--- a/compiler/goal_util.m
+++ b/compiler/goal_util.m
@@ -1192,6 +1192,7 @@ cons_id_proc_refs_acc(ConsId, !ReferredToProcs) :-
          ( ConsId = cons(_, _, _)
          ; ConsId = tuple_cons(_)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/higher_order.m b/compiler/higher_order.m
index 1b73804..ef044b7 100644
--- a/compiler/higher_order.m
+++ b/compiler/higher_order.m
@@ -914,6 +914,7 @@ is_interesting_cons_id(Params, ConsId) = IsInteresting :-
      (
          ( ConsId = cons(_, _, _)
          ; ConsId = tuple_cons(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/hlds_code_util.m b/compiler/hlds_code_util.m
index e2640fc..ae2b94f 100644
--- a/compiler/hlds_code_util.m
+++ b/compiler/hlds_code_util.m
@@ -90,6 +90,9 @@ cons_id_to_tag(ModuleInfo, ConsId) = Tag:-
          ConsId = int_const(Int),
          Tag = int_tag(Int)
      ;
+        ConsId = uint_const(UInt),
+        Tag = uint_tag(UInt)
+    ;
          ConsId = float_const(Float),
          Tag = float_tag(Float)
      ;
diff --git a/compiler/hlds_data.m b/compiler/hlds_data.m
index 7e46947..7f2f0d7 100644
--- a/compiler/hlds_data.m
+++ b/compiler/hlds_data.m
@@ -597,6 +597,8 @@ cons_table_optimize(!ConsTable) :-
              % the specified integer value. This is used for enumerations and
              % character constants as well as for int constants.

+    ;       uint_tag(int)
+
      ;       foreign_tag(foreign_language, string)
              % This means the constant is represented by the string which is
              % embedded directly in the target language. This is used for
@@ -779,6 +781,7 @@ get_primary_tag(Tag) = MaybePrimaryTag :-
          % it would probably be OK to return `yes(0)'.
          % But it's safe to be conservative...
          ( Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = float_tag(_)
          ; Tag = string_tag(_)
          ; Tag = foreign_tag(_, _)
@@ -815,6 +818,7 @@ get_primary_tag(Tag) = MaybePrimaryTag :-
  get_secondary_tag(Tag) = MaybeSecondaryTag :-
      (
          ( Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = float_tag(_)
          ; Tag = string_tag(_)
          ; Tag = foreign_tag(_, _)
diff --git a/compiler/hlds_out_pred.m b/compiler/hlds_out_pred.m
index 222bc2f..04d276a 100644
--- a/compiler/hlds_out_pred.m
+++ b/compiler/hlds_out_pred.m
@@ -1221,6 +1221,9 @@ table_trie_step_desc(TVarSet, Step) = Str :-
          Step = table_trie_step_int,
          Str = "int"
      ;
+        Step = table_trie_step_uint,
+        Str = "uint"
+    ;
          Step = table_trie_step_char,
          Str = "char"
      ;
diff --git a/compiler/hlds_out_util.m b/compiler/hlds_out_util.m
index 62186c4..13e3ff4 100644
--- a/compiler/hlds_out_util.m
+++ b/compiler/hlds_out_util.m
@@ -673,6 +673,10 @@ functor_cons_id_to_string(ModuleInfo, VarSet, VarNamePrint, ConsId, ArgVars)
          Str = functor_to_string(VarSet, VarNamePrint,
              term.integer(Int), ArgVars)
      ;
+        ConsId = uint_const(UInt), % XXX UINT.
+        Str = functor_to_string(VarSet, VarNamePrint,
+            term.integer(UInt), ArgVars)
+    ;
          ConsId = float_const(Float),
          Str = functor_to_string(VarSet, VarNamePrint,
              term.float(Float), ArgVars)
@@ -827,6 +831,9 @@ cons_id_and_vars_or_arity_to_string(VarSet, Qual, ConsId, MaybeArgVars)
          ConsId = int_const(Int),
          string.int_to_string(Int, String)
      ;
+        ConsId = uint_const(UInt),
+        string.int_to_string(UInt, String)  % XXX UINT.
+    ;
          ConsId = float_const(Float),
          String = float_to_string(Float)
      ;
diff --git a/compiler/hlds_pred.m b/compiler/hlds_pred.m
index 9bad7f2..4231c43 100644
--- a/compiler/hlds_pred.m
+++ b/compiler/hlds_pred.m
@@ -1993,6 +1993,7 @@ attribute_list_to_attributes(Attributes, AttributeSet) :-
  :- type table_trie_step
      --->    table_trie_step_dummy
      ;       table_trie_step_int
+    ;       table_trie_step_uint
      ;       table_trie_step_char
      ;       table_trie_step_string
      ;       table_trie_step_float
@@ -2846,6 +2847,7 @@ structure_reuse_info_init = structure_reuse_info(no, no).
  table_step_stats_kind(Step) = KindStr :-
      (
          ( Step = table_trie_step_int
+        ; Step = table_trie_step_uint
          ; Step = table_trie_step_char
          ; Step = table_trie_step_string
          ; Step = table_trie_step_float
diff --git a/compiler/implementation_defined_literals.m b/compiler/implementation_defined_literals.m
index eb00b9a..e13e7a2 100644
--- a/compiler/implementation_defined_literals.m
+++ b/compiler/implementation_defined_literals.m
@@ -103,6 +103,7 @@ subst_literals_in_goal(Info, Goal0, Goal) :-
                  ; ConsId = tuple_cons(_)
                  ; ConsId = closure_cons(_, _)
                  ; ConsId = int_const(_)
+                ; ConsId = uint_const(_)
                  ; ConsId = float_const(_)
                  ; ConsId = char_const(_)
                  ; ConsId = string_const(_)
diff --git a/compiler/inst_check.m b/compiler/inst_check.m
index 1b83548..7b289d4 100644
--- a/compiler/inst_check.m
+++ b/compiler/inst_check.m
@@ -249,6 +249,15 @@ check_inst_defn_has_matching_type(TypeTable, FunctorsToTypesMap, InstId,
                      ForTypeCtor = int_type_ctor,
                      MaybeForTypeKind = yes(ftk_int)
                  else if
+                    ( ForTypeCtorName = unqualified("uint")
+                    ; ForTypeCtorName = qualified(unqualified(""), "uint")
+                    ; ForTypeCtorName = qualified(unqualified("uint"), "uint")
+                    ),
+                    ForTypeCtorArity = 0
+                then
+                    ForTypeCtor = uint_type_ctor,
+                    MaybeForTypeKind = yes(ftk_uint)
+                else if
                      ( ForTypeCtorName = unqualified("float")
                      ; ForTypeCtorName = qualified(unqualified(""), "float")
                      ; ForTypeCtorName = qualified(unqualified("float"),
@@ -377,6 +386,9 @@ type_defn_or_builtin_to_type_ctor(TypeDefnOrBuiltin, TypeCtor) :-
              BuiltinType = builtin_type_int,
              TypeCtor = type_ctor(unqualified("int"), 0)
          ;
+            BuiltinType = builtin_type_uint,
+            TypeCtor = type_ctor(unqualified("uint"), 0)
+        ;
              BuiltinType = builtin_type_float,
              TypeCtor = type_ctor(unqualified("float"), 0)
          ;
@@ -396,6 +408,7 @@ type_defn_or_builtin_to_type_ctor(TypeDefnOrBuiltin, TypeCtor) :-
  :- type for_type_kind
      --->    ftk_user(type_ctor, hlds_type_defn)
      ;       ftk_int
+    ;       ftk_uint
      ;       ftk_float
      ;       ftk_char
      ;       ftk_string.
@@ -473,6 +486,7 @@ check_for_type_bound_insts(ForTypeKind, [BoundInst | BoundInsts],
              )
          ;
              ( ForTypeKind = ftk_int
+            ; ForTypeKind = ftk_uint
              ; ForTypeKind = ftk_float
              ; ForTypeKind = ftk_string
              ),
@@ -484,6 +498,20 @@ check_for_type_bound_insts(ForTypeKind, [BoundInst | BoundInsts],
              ForTypeKind = ftk_int
          ;
              ( ForTypeKind = ftk_user(_, _)
+            ; ForTypeKind = ftk_uint
+            ; ForTypeKind = ftk_float
+            ; ForTypeKind = ftk_char
+            ; ForTypeKind = ftk_string
+            ),
+            !:RevMismatchConsIdStrs = [ConsIdStr | !.RevMismatchConsIdStrs]
+        )
+    ;
+        ConsId = uint_const(_),
+        (
+            ForTypeKind = ftk_uint
+        ;
+            ( ForTypeKind = ftk_user(_, _)
+            ; ForTypeKind = ftk_int
              ; ForTypeKind = ftk_float
              ; ForTypeKind = ftk_char
              ; ForTypeKind = ftk_string
@@ -497,6 +525,7 @@ check_for_type_bound_insts(ForTypeKind, [BoundInst | BoundInsts],
          ;
              ( ForTypeKind = ftk_user(_, _)
              ; ForTypeKind = ftk_int
+            ; ForTypeKind = ftk_uint
              ; ForTypeKind = ftk_char
              ; ForTypeKind = ftk_string
              ),
@@ -509,6 +538,7 @@ check_for_type_bound_insts(ForTypeKind, [BoundInst | BoundInsts],
          ;
              ( ForTypeKind = ftk_user(_, _)
              ; ForTypeKind = ftk_int
+            ; ForTypeKind = ftk_uint
              ; ForTypeKind = ftk_float
              ; ForTypeKind = ftk_string
              ),
@@ -521,6 +551,7 @@ check_for_type_bound_insts(ForTypeKind, [BoundInst | BoundInsts],
          ;
              ( ForTypeKind = ftk_user(_, _)
              ; ForTypeKind = ftk_int
+            ; ForTypeKind = ftk_uint
              ; ForTypeKind = ftk_float
              ; ForTypeKind = ftk_char
              ),
@@ -622,6 +653,9 @@ get_possible_types_for_bound_inst(FunctorsToTypesMap, BoundInst, MaybeTypes) :-
          ConsId = int_const(_),
          MaybeTypes = yes([type_builtin(builtin_type_int)])
      ;
+        ConsId = uint_const(_),
+        MaybeTypes = yes([type_builtin(builtin_type_uint)])
+    ;
          ConsId = float_const(_),
          MaybeTypes = yes([type_builtin(builtin_type_float)])
      ;
@@ -722,6 +756,9 @@ maybe_issue_type_match_error(InstId, InstDefn, ForTypeKind, MismatchConsIdStrs,
              ForTypeKind = ftk_int,
              ForTypeCtor = int_type_ctor
          ;
+            ForTypeKind = ftk_uint,
+            ForTypeCtor = uint_type_ctor
+        ;
              ForTypeKind = ftk_float,
              ForTypeCtor = float_type_ctor
          ;
@@ -1019,6 +1056,13 @@ find_mismatches_from_builtin(ExpectedBuiltinType, CurNum,
              record_mismatch(CurNum, BoundInst, !NumMismatches, !PiecesCord)
          )
      ;
+        ExpectedBuiltinType = builtin_type_uint,
+        ( if ConsId = uint_const(_) then
+            true
+        else
+            record_mismatch(CurNum, BoundInst, !NumMismatches, !PiecesCord)
+        )
+    ;
          ExpectedBuiltinType = builtin_type_float,
          ( if ConsId = float_const(_) then
              true
@@ -1177,6 +1221,9 @@ type_defn_or_builtin_to_string(TypeDefnOrBuiltin) = Str :-
              BuiltinType = builtin_type_int,
              Str = "int"
          ;
+            BuiltinType = builtin_type_uint,
+            Str = "uint"
+        ;
              BuiltinType = builtin_type_float,
              Str = "float"
          ;
diff --git a/compiler/jumpopt.m b/compiler/jumpopt.m
index 7a806cc..cdc64b0 100644
--- a/compiler/jumpopt.m
+++ b/compiler/jumpopt.m
@@ -1156,6 +1156,7 @@ short_circuit_labels_const(InstrMap, RvalConst0, RvalConst) :-
          ( RvalConst0 = llconst_true
          ; RvalConst0 = llconst_false
          ; RvalConst0 = llconst_int(_I)
+        ; RvalConst0 = llconst_uint(_U)
          ; RvalConst0 = llconst_foreign(_V, _T)
          ; RvalConst0 = llconst_float(_F)
          ; RvalConst0 = llconst_string(_S)
diff --git a/compiler/llds.m b/compiler/llds.m
index cbae88c..0a2c093 100644
--- a/compiler/llds.m
+++ b/compiler/llds.m
@@ -1202,6 +1202,7 @@
      --->    llconst_true
      ;       llconst_false
      ;       llconst_int(int)
+    ;       llconst_uint(int)   % XXX UINT.
      ;       llconst_foreign(string, llds_type)
              % A constant in the target language.
              % It may be a #defined constant in C which is why
@@ -1669,6 +1670,7 @@ rval_type(mem_addr(_), lt_data_ptr).
  const_type(llconst_true, lt_bool).
  const_type(llconst_false, lt_bool).
  const_type(llconst_int(_), lt_integer).
+const_type(llconst_uint(_), lt_unsigned).
  const_type(llconst_foreign(_, Type), Type).
  const_type(llconst_float(_), lt_float).
  const_type(llconst_string(_), lt_string).
@@ -1751,6 +1753,15 @@ binop_return_type(body, lt_word).
  binop_return_type(compound_eq, lt_bool).
  binop_return_type(compound_lt, lt_bool).
  binop_return_type(pointer_equal_conservative, lt_bool).
+binop_return_type(uint_eq, lt_bool).
+binop_return_type(uint_ne, lt_bool).
+binop_return_type(uint_lt, lt_bool).
+binop_return_type(uint_gt, lt_bool).
+binop_return_type(uint_le, lt_bool).
+binop_return_type(uint_ge, lt_bool).
+binop_return_type(uint_add, lt_unsigned).
+binop_return_type(uint_sub, lt_unsigned).
+binop_return_type(uint_mul, lt_unsigned).

  register_type(reg_r, lt_word).
  register_type(reg_f, lt_float).
diff --git a/compiler/llds_out_data.m b/compiler/llds_out_data.m
index 17069ea..2617aad 100644
--- a/compiler/llds_out_data.m
+++ b/compiler/llds_out_data.m
@@ -1010,6 +1010,24 @@ output_rval(Info, Rval, !IO) :-
                  io.write_string(")", !IO)
              )
          ;
+            ( Op = uint_eq, OpStr = "=="
+            ; Op = uint_ne, OpStr = "!="
+            ; Op = uint_lt, OpStr = "<"
+            ; Op = uint_gt, OpStr = ">"
+            ; Op = uint_le, OpStr = "<="
+            ; Op = uint_ge, OpStr = ">="
+            ; Op = uint_add, OpStr = "+"
+            ; Op = uint_sub, OpStr = "-"
+            ; Op = uint_mul, OpStr = "*"
+            ),
+            io.write_string("(", !IO),
+            output_rval_as_type(Info, SubRvalA, lt_unsigned, !IO),
+            io.write_string(" ", !IO),
+            io.write_string(OpStr, !IO),
+            io.write_string(" ", !IO),
+            output_rval_as_type(Info, SubRvalB, lt_unsigned, !IO),
+            io.write_string(")", !IO)
+        ;
              Op = str_cmp,
              io.write_string("MR_strcmp(", !IO),
              output_rval_as_type(Info, SubRvalA, lt_data_ptr, !IO),
@@ -1175,6 +1193,9 @@ output_rval_const(Info, Const, !IO) :-
          Const = llconst_int(N),
          c_util.output_int_expr_cur_stream(N, !IO)
      ;
+        Const = llconst_uint(N),     % XXX UINT.
+        c_util.output_int_expr_cur_stream(N, !IO)
+    ;
          Const = llconst_foreign(Value, Type),
          io.write_char('(', !IO),
          output_llds_type_cast(Type, !IO),
@@ -1266,6 +1287,8 @@ output_type_ctor_addr(Module0, Name, Arity, !IO) :-
              ModuleStr = "builtin",
              ( if Name = "int" then
                  Macro = "MR_INT_CTOR_ADDR"
+            else if Name = "uint" then
+                Macro = "MR_UINT_CTOR_ADDR"
              else if Name = "float" then
                  Macro = "MR_FLOAT_CTOR_ADDR"
              else if Name = "string" then
diff --git a/compiler/llds_out_instr.m b/compiler/llds_out_instr.m
index 09024f1..7bc51b5 100644
--- a/compiler/llds_out_instr.m
+++ b/compiler/llds_out_instr.m
@@ -2093,6 +2093,11 @@ output_foreign_proc_output(Info, Output, !IO) :-
                      output_lval_as_word(Info, Lval, !IO),
                      io.write_string(" = ", !IO),
                      io.write_string(VarName, !IO)
+                ;
+                    BuiltinType = builtin_type_uint,
+                    output_lval_as_word(Info, Lval, !IO),
+                    io.write_string(" = ", !IO),
+                    io.write_string(VarName, !IO)
                  )
              else
                  output_lval_as_word(Info, Lval, !IO),
diff --git a/compiler/mercury_to_mercury.m b/compiler/mercury_to_mercury.m
index 1777438..8889a8a 100644
--- a/compiler/mercury_to_mercury.m
+++ b/compiler/mercury_to_mercury.m
@@ -264,6 +264,9 @@ mercury_format_cons_id(NeedsBrackets, ConsId, !U) :-
          ConsId = int_const(Int),
          add_int(Int, !U)
      ;
+        ConsId = uint_const(UInt),
+        add_int(UInt, !U)   % XXX UINT.
+    ;
          ConsId = float_const(Float),
          add_float(Float, !U)
      ;
diff --git a/compiler/ml_accurate_gc.m b/compiler/ml_accurate_gc.m
index 52a0889..ccffa9d 100644
--- a/compiler/ml_accurate_gc.m
+++ b/compiler/ml_accurate_gc.m
@@ -229,6 +229,7 @@ ml_type_might_contain_pointers_for_gc(Type) = MightContainPointers :-
          MightContainPointers = yes
      ;
          ( Type = mlds_native_int_type
+        ; Type = mlds_native_uint_type
          ; Type = mlds_native_float_type
          ; Type = mlds_native_bool_type
          ; Type = mlds_native_char_type
@@ -250,6 +251,7 @@ ml_type_might_contain_pointers_for_gc(Type) = MightContainPointers :-
  ml_type_category_might_contain_pointers(CtorCat) = MayContainPointers :-
      (
          ( CtorCat = ctor_cat_builtin(cat_builtin_int)
+        ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
          ; CtorCat = ctor_cat_builtin(cat_builtin_char)
          ; CtorCat = ctor_cat_builtin(cat_builtin_float)
          ; CtorCat = ctor_cat_builtin_dummy
diff --git a/compiler/ml_call_gen.m b/compiler/ml_call_gen.m
index 53798b0..b0705e4 100644
--- a/compiler/ml_call_gen.m
+++ b/compiler/ml_call_gen.m
@@ -798,6 +798,7 @@ ml_gen_builtin(PredId, ProcId, ArgVars, CodeModel, Context, Decls, Statements,

  ml_gen_simple_expr(leaf(Lval)) = ml_lval(Lval).
  ml_gen_simple_expr(int_const(Int)) = ml_const(mlconst_int(Int)).
+ml_gen_simple_expr(uint_const(UInt)) = ml_const(mlconst_uint(UInt)).
  ml_gen_simple_expr(float_const(Float)) = ml_const(mlconst_float(Float)).
  ml_gen_simple_expr(unary(Op, Expr)) =
      ml_unop(std_unop(Op), ml_gen_simple_expr(Expr)).
diff --git a/compiler/ml_code_util.m b/compiler/ml_code_util.m
index 31c9306..b86c728 100644
--- a/compiler/ml_code_util.m
+++ b/compiler/ml_code_util.m
@@ -1408,6 +1408,7 @@ ml_must_box_field_type(ModuleInfo, Type, Width) :-
  ml_must_box_field_type_category(CtorCat, UnboxedFloat, Width) = MustBox :-
      (
          ( CtorCat = ctor_cat_builtin(cat_builtin_int)
+        ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
          ; CtorCat = ctor_cat_builtin(cat_builtin_string)
          ; CtorCat = ctor_cat_builtin_dummy
          ; CtorCat = ctor_cat_higher_order
diff --git a/compiler/ml_global_data.m b/compiler/ml_global_data.m
index 6275f4f..b511d95 100644
--- a/compiler/ml_global_data.m
+++ b/compiler/ml_global_data.m
@@ -589,6 +589,15 @@ ml_specialize_generic_array_binop(Op, IsFloat) :-
          ; Op = int_le
          ; Op = int_ge
          ; Op = unsigned_le
+        ; Op = uint_eq
+        ; Op = uint_ne
+        ; Op = uint_lt
+        ; Op = uint_gt
+        ; Op = uint_le
+        ; Op = uint_ge
+        ; Op = uint_add
+        ; Op = uint_sub
+        ; Op = uint_mul
          ; Op = float_eq
          ; Op = float_ne
          ; Op = float_lt
@@ -792,6 +801,7 @@ cons_id_to_alloc_site_string(ConsId) = TypeStr :-
          TypeStr = "ground_term_const"
      ;
          ( ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/ml_lookup_switch.m b/compiler/ml_lookup_switch.m
index b63dc2d..b8c99f5 100644
--- a/compiler/ml_lookup_switch.m
+++ b/compiler/ml_lookup_switch.m
@@ -824,6 +824,9 @@ ml_default_value_for_type(MLDS_Type) = DefaultRval :-
          MLDS_Type = mlds_native_int_type,
          DefaultRval = ml_const(mlconst_int(0))
      ;
+        MLDS_Type = mlds_native_uint_type,
+        DefaultRval = ml_const(mlconst_uint(0))
+    ;
          MLDS_Type = mlds_native_char_type,
          DefaultRval = ml_const(mlconst_char(0))
      ;
diff --git a/compiler/ml_simplify_switch.m b/compiler/ml_simplify_switch.m
index 25ac957..b521515 100644
--- a/compiler/ml_simplify_switch.m
+++ b/compiler/ml_simplify_switch.m
@@ -124,6 +124,7 @@ ml_simplify_switch(Stmt0, MLDS_Context, Statement, !Info) :-
  is_integral_type(MLDSType) = IsIntegral :-
      (
          ( MLDSType = mlds_native_int_type
+        ; MLDSType = mlds_native_uint_type
          ; MLDSType = mlds_native_char_type
          ),
          IsIntegral = yes
@@ -152,6 +153,7 @@ is_integral_type(MLDSType) = IsIntegral :-
          MLDSType = mercury_type(_, CtorCat, _),
          (
              ( CtorCat = ctor_cat_builtin(cat_builtin_int)
+            ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
              ; CtorCat = ctor_cat_builtin(cat_builtin_char)
              ; CtorCat = ctor_cat_enum(cat_enum_mercury)
              ),
diff --git a/compiler/ml_switch_gen.m b/compiler/ml_switch_gen.m
index 611e170..381aad6 100644
--- a/compiler/ml_switch_gen.m
+++ b/compiler/ml_switch_gen.m
@@ -608,6 +608,7 @@ 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/compiler/ml_tailcall.m b/compiler/ml_tailcall.m
index a24d3bd..82c5cd1 100644
--- a/compiler/ml_tailcall.m
+++ b/compiler/ml_tailcall.m
@@ -888,6 +888,7 @@ check_const(Const, Locals) = MayYieldDanglingStackRef :-
          ( Const = mlconst_true
          ; Const = mlconst_false
          ; Const = mlconst_int(_)
+        ; Const = mlconst_uint(_)
          ; Const = mlconst_enum(_, _)
          ; Const = mlconst_char(_)
          ; Const = mlconst_foreign(_, _, _)
diff --git a/compiler/ml_type_gen.m b/compiler/ml_type_gen.m
index 47859df..37d259b 100644
--- a/compiler/ml_type_gen.m
+++ b/compiler/ml_type_gen.m
@@ -310,7 +310,8 @@ ml_gen_enum_constant(Context, TypeCtor, ConsTagValues, MLDS_Type, Ctor)
          ConstValue = ml_const(mlconst_foreign(ForeignLang, ForeignTagValue,
              MLDS_Type))
      ;
-        ( TagVal = string_tag(_)
+        ( TagVal = uint_tag(_)
+        ; TagVal = string_tag(_)
          ; TagVal = float_tag(_)
          ; TagVal = closure_tag(_, _, _)
          ; TagVal = type_ctor_info_tag(_, _, _)
@@ -864,6 +865,7 @@ ml_tag_uses_base_class(Tag) = UsesBaseClass :-
          ( Tag = string_tag(_)
          ; Tag = float_tag(_)
          ; Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = closure_tag(_, _, _)
          ; Tag = type_ctor_info_tag(_, _, _)
@@ -1234,6 +1236,7 @@ generate_foreign_enum_constant(TypeCtor, Mapping, TagValues, MLDS_Type, Ctor,
      ;
          ( TagVal = string_tag(_)
          ; TagVal = float_tag(_)
+        ; TagVal = uint_tag(_)
          ; TagVal = closure_tag(_, _, _)
          ; TagVal = type_ctor_info_tag(_, _, _)
          ; TagVal = base_typeclass_info_tag(_, _, _)
diff --git a/compiler/ml_unify_gen.m b/compiler/ml_unify_gen.m
index b861bf3..359ed20 100644
--- a/compiler/ml_unify_gen.m
+++ b/compiler/ml_unify_gen.m
@@ -404,6 +404,7 @@ ml_gen_construct_tag(Tag, Type, Var, ConsId, Args, ArgModes, TakeAddr,
      ;
          % Constants.
          ( Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = float_tag(_)
          ; Tag = string_tag(_)
@@ -454,6 +455,9 @@ ml_gen_constant(Tag, VarType, MLDS_VarType, Rval, !Info) :-
              Rval = ml_const(mlconst_enum(Int, MLDS_VarType))
          )
      ;
+        Tag = uint_tag(UInt),
+        Rval = ml_const(mlconst_uint(UInt))
+    ;
          Tag = float_tag(Float),
          Rval = ml_const(mlconst_float(Float))
      ;
@@ -1484,6 +1488,7 @@ ml_gen_det_deconstruct_tag(Tag, Type, Var, ConsId, Args, Modes, Context,
      (
          ( Tag = string_tag(_String)
          ; Tag = int_tag(_Int)
+        ; Tag = uint_tag(_UInt)
          ; Tag = foreign_tag(_, _)
          ; Tag = float_tag(_Float)
          ; Tag = shared_local_tag(_Bits1, _Num1)
@@ -1588,6 +1593,7 @@ ml_tag_offset_and_argnum(Tag, TagBits, Offset, ArgNum) :-
      ;
          ( Tag = string_tag(_String)
          ; Tag = int_tag(_Int)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = float_tag(_Float)
          ; Tag = closure_tag(_, _, _)
@@ -2213,6 +2219,9 @@ ml_gen_tag_test_rval(Tag, Type, ModuleInfo, Rval) = TagTestRval :-
          ),
          TagTestRval = ml_binop(eq, Rval, ConstRval)
      ;
+        Tag = uint_tag(UInt),
+        TagTestRval = ml_binop(eq, Rval, ml_const(mlconst_uint(UInt))) % XXX is that right?
+    ;
          Tag = foreign_tag(ForeignLang, ForeignVal),
          MLDS_Type = mercury_type_to_mlds_type(ModuleInfo, Type),
          Const = ml_const(mlconst_foreign(ForeignLang, ForeignVal, MLDS_Type)),
@@ -2511,6 +2520,9 @@ ml_gen_ground_term_conjunct_tag(ModuleInfo, Target, HighLevelData, VarTypes,
                  ConstRval = ml_const(mlconst_enum(Int, MLDS_Type))
              )
          ;
+            ConsTag = uint_tag(UInt),
+            ConstRval = ml_const(mlconst_uint(UInt))
+        ;
              ConsTag = float_tag(Float),
              ConstRval = ml_const(mlconst_float(Float))
          ;
@@ -2904,6 +2916,7 @@ ml_gen_const_struct_tag(Info, ConstNum, Type, MLDS_Type, ConsId, ConsTag,
      ;
          % These tags don't build heap cells.
          ( ConsTag = int_tag(_)
+        ; ConsTag = uint_tag(_)
          ; ConsTag = float_tag(_)
          ; ConsTag = string_tag(_)
          ; ConsTag = reserved_address_tag(_)
@@ -3081,6 +3094,9 @@ ml_gen_const_struct_arg_tag(ModuleInfo, ConsId, ConsTag, Type, MLDS_Type,
              Rval = ml_const(mlconst_enum(Int, MLDS_Type))
          )
      ;
+        ConsTag = uint_tag(UInt),
+        Rval = ml_const(mlconst_uint(UInt))
+    ;
          ConsTag = float_tag(Float),
          Rval = ml_const(mlconst_float(Float))
      ;
diff --git a/compiler/ml_util.m b/compiler/ml_util.m
index b6ce9fe..4349d0a 100644
--- a/compiler/ml_util.m
+++ b/compiler/ml_util.m
@@ -860,6 +860,7 @@ rval_contains_var(Rval, DataName) = ContainsVar :-
              ( Const = mlconst_true
              ; Const = mlconst_false
              ; Const = mlconst_int(_)
+            ; Const = mlconst_uint(_)
              ; Const = mlconst_enum(_, _)
              ; Const = mlconst_char(_)
              ; Const = mlconst_float(_)
diff --git a/compiler/mlds.m b/compiler/mlds.m
index 5729ed1..f9238b9 100644
--- a/compiler/mlds.m
+++ b/compiler/mlds.m
@@ -782,6 +782,7 @@

      ;       mlds_native_bool_type
      ;       mlds_native_int_type
+    ;       mlds_native_uint_type
      ;       mlds_native_float_type
      ;       mlds_native_char_type
              % MLDS native builtin types.
@@ -1678,6 +1679,7 @@
      --->    mlconst_true
      ;       mlconst_false
      ;       mlconst_int(int)
+    ;       mlconst_uint(int)   % XXX UINT.
      ;       mlconst_enum(int, mlds_type)
      ;       mlconst_char(int)
      ;       mlconst_float(float)
diff --git a/compiler/mlds_to_c.m b/compiler/mlds_to_c.m
index e6b63a0..8e998db 100644
--- a/compiler/mlds_to_c.m
+++ b/compiler/mlds_to_c.m
@@ -1146,6 +1146,9 @@ mlds_output_pragma_export_type(PrefixSuffix, MLDS_Type, !IO) :-
              MLDS_Type = mlds_native_int_type,
              io.write_string("MR_Integer", !IO)
          ;
+            MLDS_Type = mlds_native_uint_type,
+            io.write_string("MR_Unsigned", !IO)
+        ;
              MLDS_Type = mlds_native_float_type,
              io.write_string("MR_Float", !IO)
          ;
@@ -2780,6 +2783,9 @@ mlds_output_type_prefix(Opts, MLDS_Type, !IO) :-
          MLDS_Type = mlds_native_int_type,
          io.write_string("MR_Integer", !IO)
      ;
+        MLDS_Type = mlds_native_uint_type,
+        io.write_string("MR_Unsigned", !IO)
+    ;
          MLDS_Type = mlds_native_float_type,
          io.write_string("MR_Float", !IO)
      ;
@@ -2904,6 +2910,9 @@ mlds_output_mercury_type_prefix(Opts, Type, CtorCat, !IO) :-
          CtorCat = ctor_cat_builtin(cat_builtin_int),
          io.write_string("MR_Integer", !IO)
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        io.write_string("MR_Unsigned", !IO)
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_string),
          io.write_string("MR_String", !IO)
      ;
@@ -3039,6 +3048,7 @@ mlds_output_type_suffix(Opts, MLDS_Type, ArraySize, !IO) :-
          ( MLDS_Type = mercury_type(_, _, _)
          ; MLDS_Type = mlds_mercury_array_type(_)
          ; MLDS_Type = mlds_native_int_type
+        ; MLDS_Type = mlds_native_uint_type
          ; MLDS_Type = mlds_native_float_type
          ; MLDS_Type = mlds_native_bool_type
          ; MLDS_Type = mlds_native_char_type
@@ -4007,6 +4017,7 @@ type_needs_forwarding_pointer_space(mlds_cont_type(_)) = no.
  type_needs_forwarding_pointer_space(mlds_commit_type) = no.
  type_needs_forwarding_pointer_space(mlds_native_bool_type) = no.
  type_needs_forwarding_pointer_space(mlds_native_int_type) = no.
+type_needs_forwarding_pointer_space(mlds_native_uint_type) = no.
  type_needs_forwarding_pointer_space(mlds_native_float_type) = no.
  type_needs_forwarding_pointer_space(mlds_native_char_type) = no.
  type_needs_forwarding_pointer_space(mlds_foreign_type(_)) = no.
@@ -4590,6 +4601,24 @@ mlds_output_binop(Opts, Op, X, Y, !IO) :-
          mlds_output_rval_as_op_arg(Opts, Y, !IO),
          io.write_string(")", !IO)
      ;
+        ( Op = uint_eq, OpStr = "=="
+        ; Op = uint_ne, OpStr = "!="
+        ; Op = uint_lt, OpStr = "<"
+        ; Op = uint_gt, OpStr = ">"
+        ; Op = uint_le, OpStr = "<="
+        ; Op = uint_ge, OpStr = ">="
+        ; Op = uint_add, OpStr = "+"
+        ; Op = uint_sub, OpStr = "-"
+        ; Op = uint_mul, OpStr = "*"
+        ),
+        io.write_string("(", !IO),
+        mlds_output_rval_as_op_arg(Opts, X, !IO),
+        io.write_string(" ", !IO),
+        io.write_string(OpStr, !IO),
+        io.write_string(" ", !IO),
+        mlds_output_rval_as_op_arg(Opts, Y, !IO),
+        io.write_string(")", !IO)
+    ;
          Op = str_cmp,
          io.write_string("MR_strcmp(", !IO),
          mlds_output_rval_as_op_arg(Opts, X, !IO),
@@ -4651,6 +4680,9 @@ mlds_output_rval_const(_Opts, Const, !IO) :-
          ),
          c_util.output_int_expr_cur_stream(N, !IO)
      ;
+        Const = mlconst_uint(U),
+        c_util.output_int_expr_cur_stream(U, !IO)   % XXX UINT.
+    ;
          Const = mlconst_char(C),
          io.write_string("(MR_Char) ", !IO),
          io.write_int(C, !IO)
diff --git a/compiler/mlds_to_cs.m b/compiler/mlds_to_cs.m
index b034d77..f8844c4 100644
--- a/compiler/mlds_to_cs.m
+++ b/compiler/mlds_to_cs.m
@@ -658,6 +658,7 @@ method_ptrs_in_rval(Rval, !CodeAddrs) :-
              ( RvalConst = mlconst_true
              ; RvalConst = mlconst_false
              ; RvalConst = mlconst_int(_)
+            ; RvalConst = mlconst_uint(_)
              ; RvalConst = mlconst_char(_)
              ; RvalConst = mlconst_enum(_, _)
              ; RvalConst = mlconst_foreign(_, _, _)
@@ -1417,6 +1418,7 @@ add_scalar_deps_rval_const(FromScalar, RvalConst, !Graph) :-
          ( RvalConst = mlconst_true
          ; RvalConst = mlconst_false
          ; RvalConst = mlconst_int(_)
+        ; RvalConst = mlconst_uint(_)
          ; RvalConst = mlconst_enum(_, _)
          ; RvalConst = mlconst_char(_)
          ; RvalConst = mlconst_float(_)
@@ -1505,6 +1507,9 @@ get_type_initializer(Info, Type) = Initializer :-
              ),
              Initializer = "0"
          ;
+            CtorCat = ctor_cat_builtin(cat_builtin_uint),
+            Initializer = "0U"
+        ;
              CtorCat = ctor_cat_builtin(cat_builtin_char),
              Initializer = "'\\u0000'"
          ;
@@ -1530,6 +1535,9 @@ get_type_initializer(Info, Type) = Initializer :-
          ),
          Initializer = "0"
      ;
+        Type = mlds_native_uint_type,
+        Initializer = "0U"
+    ;
          Type = mlds_native_char_type,
          Initializer = "'\\u0000'"
      ;
@@ -2263,6 +2271,10 @@ type_to_string(Info, MLDS_Type, String, ArrayDims) :-
          String = "int",
          ArrayDims = []
      ;
+        MLDS_Type = mlds_native_uint_type,
+        String = "uint",
+        ArrayDims = []
+    ;
          MLDS_Type = mlds_native_float_type,
          String = "double",
          ArrayDims = []
@@ -2378,6 +2390,10 @@ mercury_type_to_string(Info, Type, CtorCat, String, ArrayDims) :-
          String = "int",
          ArrayDims = []
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        String = "uint",
+        ArrayDims = []
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_string),
          String = "string",
          ArrayDims = []
@@ -3668,6 +3684,15 @@ output_binop(Info, Op, X, Y, !IO) :-
          ; Op = int_le
          ; Op = int_ge
          ; Op = unsigned_le
+        ; Op = uint_eq
+        ; Op = uint_ne
+        ; Op = uint_lt
+        ; Op = uint_gt
+        ; Op = uint_le
+        ; Op = uint_ge
+        ; Op = uint_add
+        ; Op = uint_sub
+        ; Op = uint_mul
          ; Op = float_plus
          ; Op = float_minus
          ; Op = float_times
@@ -3715,6 +3740,16 @@ output_binary_op(Op, !IO) :-
          ; Op = int_le, OpStr = "<="
          ; Op = int_ge, OpStr = ">="

+        ; Op = uint_eq, OpStr = "=="
+        ; Op = uint_ne, OpStr = "!="
+        ; Op = uint_lt, OpStr = "<"
+        ; Op = uint_gt, OpStr = ">"
+        ; Op = uint_le, OpStr = "<="
+        ; Op = uint_ge, OpStr = ">="
+
+        ; Op = uint_add, OpStr = "+"
+        ; Op = uint_sub, OpStr = "-"
+        ; Op = uint_mul, OpStr = "*"

          ; Op = float_eq, OpStr = "=="
          ; Op = float_ne, OpStr = "!="
@@ -3765,6 +3800,9 @@ output_rval_const(Info, Const, !IO) :-
          Const = mlconst_int(N),
          output_int_const(N, !IO)
      ;
+        Const = mlconst_uint(U),
+        output_int_const(U, !IO)    % XXX UINT.
+    ;
          Const = mlconst_char(N),
          io.write_string("( ", !IO),
          output_int_const(N, !IO),
diff --git a/compiler/mlds_to_java.m b/compiler/mlds_to_java.m
index 32be1d8..e23805b 100644
--- a/compiler/mlds_to_java.m
+++ b/compiler/mlds_to_java.m
@@ -915,6 +915,7 @@ method_ptrs_in_rval(Rval, !CodeAddrs) :-
              ( RvalConst = mlconst_true
              ; RvalConst = mlconst_false
              ; RvalConst = mlconst_int(_)
+            ; RvalConst = mlconst_uint(_)
              ; RvalConst = mlconst_char(_)
              ; RvalConst = mlconst_enum(_, _)
              ; RvalConst = mlconst_foreign(_, _, _)
@@ -1487,6 +1488,7 @@ rename_class_names_type(Renaming, !Type) :-
          ; !.Type = mlds_commit_type
          ; !.Type = mlds_native_bool_type
          ; !.Type = mlds_native_int_type
+        ; !.Type = mlds_native_uint_type
          ; !.Type = mlds_native_float_type
          ; !.Type = mlds_native_char_type
          ; !.Type = mlds_foreign_type(_)
@@ -1792,6 +1794,7 @@ rename_class_names_rval_const(Renaming, !Const) :-
          ( !.Const = mlconst_true
          ; !.Const = mlconst_false
          ; !.Const = mlconst_int(_)
+        ; !.Const = mlconst_uint(_)
          ; !.Const = mlconst_char(_)
          ; !.Const = mlconst_enum(_, _)
          ; !.Const = mlconst_float(_)
@@ -2653,6 +2656,7 @@ add_scalar_deps_rval_const(FromScalar, RvalConst, !Graph) :-
          ( RvalConst = mlconst_true
          ; RvalConst = mlconst_false
          ; RvalConst = mlconst_int(_)
+        ; RvalConst = mlconst_uint(_)
          ; RvalConst = mlconst_enum(_, _)
          ; RvalConst = mlconst_char(_)
          ; RvalConst = mlconst_float(_)
@@ -2737,6 +2741,7 @@ get_java_type_initializer(Type) = Initializer :-
          Type = mercury_type(_, CtorCat, _),
          (
              ( CtorCat = ctor_cat_builtin(cat_builtin_int)
+            ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
              ; CtorCat = ctor_cat_builtin(cat_builtin_float)
              ),
              Initializer = "0"
@@ -2758,6 +2763,7 @@ get_java_type_initializer(Type) = Initializer :-
          )
      ;
          ( Type = mlds_native_int_type
+        ; Type = mlds_native_uint_type
          ; Type = mlds_native_float_type
          ),
          Initializer = "0"
@@ -3436,6 +3442,10 @@ type_to_string(Info, MLDS_Type, String, ArrayDims) :-
          String = "int",
          ArrayDims = []
      ;
+        MLDS_Type = mlds_native_uint_type,
+        String = "int", % Java lacks unsigned integers.
+        ArrayDims = []
+    ;
          MLDS_Type = mlds_native_float_type,
          String = "double",
          ArrayDims = []
@@ -3550,6 +3560,10 @@ mercury_type_to_string(Info, Type, CtorCat, String, ArrayDims) :-
          String = "int",
          ArrayDims = []
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        String = "int",     % Java has no unsigned types.
+        ArrayDims = []
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_string),
          String = "java.lang.String",
          ArrayDims = []
@@ -5110,6 +5124,33 @@ output_binop(Info, Op, X, Y, !IO) :-
              output_rval(Info, Y, !IO),
              io.write_string(")", !IO)
          )
+    ;
+        ( Op = uint_eq
+        ; Op = uint_ne
+        ; Op = uint_add
+        ; Op = uint_sub
+        ; Op = uint_mul
+        ),
+        io.write_string("(", !IO),
+        output_rval(Info, X, !IO),
+        io.write_string(" ", !IO),
+        output_binary_op(Op, !IO),
+        io.write_string(" ", !IO),
+        output_rval(Info, Y, !IO),
+        io.write_string(")", !IO)
+    ;
+        ( Op = uint_lt
+        ; Op = uint_gt
+        ; Op = uint_le
+        ; Op = uint_ge
+        ),
+        io.write_string("(((", !IO),
+        output_rval(Info, X, !IO),
+        io.write_string(") & 0xffffffffL) ", !IO),
+        output_binary_op(Op, !IO),
+        io.write_string(" ((", !IO),
+        output_rval(Info, Y, !IO),
+        io.write_string(") & 0xffffffffL))", !IO)
      ).

      % Output an Rval and if the Rval is an enumeration object append the string
@@ -5157,6 +5198,18 @@ output_binary_op(Op, !IO) :-
          ; Op = int_le, OpStr = "<="
          ; Op = int_ge, OpStr = ">="

+        ; Op = uint_eq, OpStr = "=="
+        ; Op = uint_ne, OpStr = "!="
+        % NOTE: unsigned comparisons require special handling
+        % in Java.  See output_binop/6 above.
+        ; Op = uint_lt, OpStr = "<"
+        ; Op = uint_gt, OpStr = ">"
+        ; Op = uint_le, OpStr = "<="
+        ; Op = uint_ge, OpStr = ">="
+
+        ; Op = uint_add, OpStr = "+"
+        ; Op = uint_sub, OpStr = "-"
+        ; Op = uint_mul, OpStr = "*"

          ; Op = float_eq, OpStr = "=="
          ; Op = float_ne, OpStr = "!="
@@ -5207,6 +5260,9 @@ output_rval_const(Info, Const, !IO) :-
          Const = mlconst_int(N),
          output_int_const(N, !IO)
      ;
+        Const = mlconst_uint(U),
+        output_int_const(U, !IO)    % XXX UINT.
+    ;
          Const = mlconst_char(N),
          io.write_string("(", !IO),
          output_int_const(N, !IO),
diff --git a/compiler/mode_util.m b/compiler/mode_util.m
index 0145923..e86b308 100644
--- a/compiler/mode_util.m
+++ b/compiler/mode_util.m
@@ -1893,6 +1893,7 @@ cons_id_to_shared_inst(ModuleInfo, ConsId, NumArgs) = MaybeInst :-
          % Note that before the change that introduced the char_const functor,
          % we used to handle character constants as user-defined cons_ids.
          ( ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/module_qual.qualify_items.m b/compiler/module_qual.qualify_items.m
index d412127..bd729b6 100644
--- a/compiler/module_qual.qualify_items.m
+++ b/compiler/module_qual.qualify_items.m
@@ -474,6 +474,9 @@ qualify_type(InInt, ErrorContext, Type0, Type, !Info, !Specs) :-
              BuiltinType = builtin_type_int,
              mq_info_set_module_used(InInt, unqualified("int"), !Info)
          ;
+            BuiltinType = builtin_type_uint,
+            mq_info_set_module_used(InInt, unqualified("uint"), !Info)
+        ;
              BuiltinType = builtin_type_float,
              mq_info_set_module_used(InInt, unqualified("float"), !Info)
          ;
@@ -533,6 +536,7 @@ qualify_type_ctor(InInt, ErrorContext, TypeCtor0, TypeCtor,
  :- pred is_builtin_atomic_type(type_ctor::in) is semidet.

  is_builtin_atomic_type(type_ctor(unqualified("int"), 0)).
+is_builtin_atomic_type(type_ctor(unqualified("uint"), 0)).
  is_builtin_atomic_type(type_ctor(unqualified("float"), 0)).
  is_builtin_atomic_type(type_ctor(unqualified("string"), 0)).
  is_builtin_atomic_type(type_ctor(unqualified("character"), 0)).
@@ -716,6 +720,7 @@ qualify_bound_inst(InInt, ErrorContext, BoundInst0, BoundInst,
          ( ConsId = tuple_cons(_)
          ; ConsId = closure_cons(_, _)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
diff --git a/compiler/opt_debug.m b/compiler/opt_debug.m
index 8679b8c..af16259 100644
--- a/compiler/opt_debug.m
+++ b/compiler/opt_debug.m
@@ -441,6 +441,9 @@ dump_const(MaybeProcLabel, Const) = Str :-
          Const = llconst_int(I),
          Str = int_to_string(I)
      ;
+        Const = llconst_uint(U),
+        Str = int_to_string(U)      % XXX UINT.
+    ;
          Const = llconst_foreign(F, _),
          Str = F
      ;
@@ -852,6 +855,15 @@ dump_binop(str_ge) = "str>=".
  dump_binop(str_lt) = "str<".
  dump_binop(str_gt) = "str>".
  dump_binop(unsigned_le) = "unsigned<=".
+dump_binop(uint_eq) = "uint==".
+dump_binop(uint_ne) = "uint!=".
+dump_binop(uint_lt) = "uint<".
+dump_binop(uint_gt) = "uint>".
+dump_binop(uint_le) = "uint<=".
+dump_binop(uint_ge) = "uint>=".
+dump_binop(uint_add) = "uint+".
+dump_binop(uint_sub) = "uint-".
+dump_binop(uint_mul) = "uint*".
  dump_binop(float_plus) = "fl+".
  dump_binop(float_minus) = "fl-".
  dump_binop(float_times) = "fl*".
diff --git a/compiler/opt_util.m b/compiler/opt_util.m
index eaa77eb..4ff5c9e 100644
--- a/compiler/opt_util.m
+++ b/compiler/opt_util.m
@@ -2645,6 +2645,7 @@ replace_labels_rval_const(Const0, Const, ReplMap) :-
          ( Const0 = llconst_true
          ; Const0 = llconst_false
          ; Const0 = llconst_int(_)
+        ; Const0 = llconst_uint(_)
          ; Const0 = llconst_foreign(_, _)
          ; Const0 = llconst_float(_)
          ; Const0 = llconst_string(_)
diff --git a/compiler/parse_tree_to_term.m b/compiler/parse_tree_to_term.m
index 4104cba..846fb00 100644
--- a/compiler/parse_tree_to_term.m
+++ b/compiler/parse_tree_to_term.m
@@ -649,6 +649,11 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
          term.context_init(Context),
          Term = term.functor(term.integer(Int), [], Context)
      ;
+        ConsId = uint_const(_UInt),
+        term.context_init(Context),
+        % XXX UINT.
+        Term = term.functor(term.string("<<uint>>"), [], Context)
+    ;
          ConsId = float_const(Float),
          term.context_init(Context),
          Term = term.functor(term.float(Float), [], Context)
diff --git a/compiler/parse_type_name.m b/compiler/parse_type_name.m
index fb93356..c7cd7e8 100644
--- a/compiler/parse_type_name.m
+++ b/compiler/parse_type_name.m
@@ -642,6 +642,9 @@ is_known_type_name_args(Name, Args, KnownType) :-
              Name = "int",
              BuiltinType = builtin_type_int
          ;
+            Name = "uint",
+            BuiltinType = builtin_type_uint
+        ;
              Name = "float",
              BuiltinType = builtin_type_float
          ;
diff --git a/compiler/polymorphism.m b/compiler/polymorphism.m
index 9dc5f71..8e170b0 100644
--- a/compiler/polymorphism.m
+++ b/compiler/polymorphism.m
@@ -3585,6 +3585,9 @@ get_category_name(CtorCat) = MaybeName :-
          CtorCat = ctor_cat_builtin(cat_builtin_int),
          MaybeName = yes("int")
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        MaybeName = yes("uint")
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_char),
          MaybeName = yes("character")
      ;
diff --git a/compiler/prog_data.m b/compiler/prog_data.m
index edd0fee..b926045 100644
--- a/compiler/prog_data.m
+++ b/compiler/prog_data.m
@@ -106,6 +106,7 @@
              % XXX We should have a pred_or_func field as well.

      ;       int_const(int)
+    ;       uint_const(int) % XXX until uint is bootstrapped.
      ;       float_const(float)
      ;       char_const(char)
      ;       string_const(string)
@@ -222,6 +223,7 @@ cons_id_is_const_struct(ConsId, ConstNum) :-
          ; ConsId = tuple_cons(_)
          ; ConsId = closure_cons(_, _)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
@@ -482,6 +484,7 @@ cons_id_is_const_struct(ConsId, ConstNum) :-

  :- type builtin_type
      --->    builtin_type_int
+    ;       builtin_type_uint
      ;       builtin_type_float
      ;       builtin_type_string
      ;       builtin_type_char.
diff --git a/compiler/prog_out.m b/compiler/prog_out.m
index 8f9c9f5..282862e 100644
--- a/compiler/prog_out.m
+++ b/compiler/prog_out.m
@@ -339,6 +339,9 @@ cons_id_and_arity_to_string_maybe_quoted(QuoteCons, ConsId) = String :-
          ConsId = int_const(Int),
          string.int_to_string(Int, String)
      ;
+        ConsId = uint_const(UInt),  % XXX UINT.
+        string.int_to_string(UInt, String)
+    ;
          ConsId = float_const(Float),
          String = float_to_string(Float)
      ;
@@ -428,6 +431,7 @@ type_name_to_string(type_ctor(Name, _Arity)) =
      sym_name_to_escaped_string(Name).

  builtin_type_to_string(builtin_type_int, "int").
+builtin_type_to_string(builtin_type_uint, "uint").
  builtin_type_to_string(builtin_type_float, "float").
  builtin_type_to_string(builtin_type_string, "string").
  builtin_type_to_string(builtin_type_char, "character").
diff --git a/compiler/prog_rep.m b/compiler/prog_rep.m
index 9fbb1f4..e9c95ab 100644
--- a/compiler/prog_rep.m
+++ b/compiler/prog_rep.m
@@ -870,6 +870,7 @@ cons_id_rep(cons(SymName, _, _)) =
      prog_rep.sym_base_name_to_string(SymName).
  cons_id_rep(tuple_cons(_)) = "{}".
  cons_id_rep(int_const(Int)) = string.int_to_string(Int).
+cons_id_rep(uint_const(UInt)) = string.int_to_string(UInt). % XXX UINT.
  cons_id_rep(float_const(Float)) = string.float_to_string(Float).
  cons_id_rep(char_const(Char)) = string.char_to_string(Char).
  cons_id_rep(string_const(String)) = """" ++ String ++ """".
diff --git a/compiler/prog_rep_tables.m b/compiler/prog_rep_tables.m
index 36e6d72..306c9da 100644
--- a/compiler/prog_rep_tables.m
+++ b/compiler/prog_rep_tables.m
@@ -330,19 +330,22 @@ add_type_to_table(Type, TypeCode, !StringTable, !TypeTable) :-
              BuiltinType = builtin_type_int,
              Selector = 5
          ;
-            BuiltinType = builtin_type_float,
+            BuiltinType = builtin_type_uint,
              Selector = 6
          ;
-            BuiltinType = builtin_type_string,
+            BuiltinType = builtin_type_float,
              Selector = 7
          ;
-            BuiltinType = builtin_type_char,
+            BuiltinType = builtin_type_string,
              Selector = 8
+        ;
+            BuiltinType = builtin_type_char,
+            Selector = 9
          ),
          TypeBytesCord = cord.singleton(Selector)
      ;
          Type = tuple_type(ArgTypes, _Kind),
-        Selector = 9,
+        Selector = 10,
          list.map_foldl2(lookup_type_in_table, ArgTypes, ArgTypeCodes,
              !StringTable, !TypeTable),
          encode_arg_type_codes(ArgTypeCodes, ArgTypeBytesCord),
@@ -355,10 +358,10 @@ add_type_to_table(Type, TypeCode, !StringTable, !TypeTable) :-
          encode_arg_type_codes(ArgTypeCodes, ArgTypeBytesCord),
          (
              PorF = pf_predicate,
-            Selector = 10
+            Selector = 11
          ;
              PorF = pf_function,
-            Selector = 11
+            Selector = 12
          ),
          TypeBytesCord = cord.singleton(Selector) ++ ArgTypeBytesCord
      ;
@@ -369,7 +372,7 @@ add_type_to_table(Type, TypeCode, !StringTable, !TypeTable) :-
          unexpected($module, $pred, "kinded_type")
      ;
          Type = type_variable(TVar, _Kind),
-        Selector = 12,
+        Selector = 13,
          var_to_int(TVar, TVarNum),
          encode_num_det(TVarNum, TVarNumBytes),
          TypeBytesCord = cord.singleton(Selector) ++
diff --git a/compiler/prog_type.m b/compiler/prog_type.m
index d001cb2..30b5445 100644
--- a/compiler/prog_type.m
+++ b/compiler/prog_type.m
@@ -279,6 +279,7 @@

  :- type type_ctor_cat_builtin
      --->    cat_builtin_int
+    ;       cat_builtin_uint
      ;       cat_builtin_float
      ;       cat_builtin_char
      ;       cat_builtin_string.
@@ -780,6 +781,7 @@ get_unconstrained_tvars(Tvars, Constraints, Unconstrained) :-
      % builtin_type_ctor in type_ctor_info.m.
  builtin_type_ctors_with_no_hlds_type_defn =
      [ type_ctor(qualified(mercury_public_builtin_module, "int"), 0),
+      type_ctor(qualified(mercury_public_builtin_module, "uint"), 0),
        type_ctor(qualified(mercury_public_builtin_module, "string"), 0),
        type_ctor(qualified(mercury_public_builtin_module, "character"), 0),
        type_ctor(qualified(mercury_public_builtin_module, "float"), 0),
@@ -911,6 +913,7 @@ qualify_cons_id(Args, ConsId0, ConsId, InstConsId) :-
          ( ConsId0 = tuple_cons(_)
          ; ConsId0 = closure_cons(_, _)
          ; ConsId0 = int_const(_)
+        ; ConsId0 = uint_const(_)
          ; ConsId0 = float_const(_)
          ; ConsId0 = char_const(_)
          ; ConsId0 = string_const(_)
diff --git a/compiler/prog_util.m b/compiler/prog_util.m
index 7455d21..ff62625 100644
--- a/compiler/prog_util.m
+++ b/compiler/prog_util.m
@@ -632,6 +632,7 @@ cons_id_arity(ConsId) = Arity :-
          Arity = cons_id_arity(SubConsId)
      ;
          ( ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
@@ -656,6 +657,7 @@ cons_id_arity(ConsId) = Arity :-
  cons_id_maybe_arity(cons(_, Arity, _)) = yes(Arity).
  cons_id_maybe_arity(tuple_cons(Arity)) = yes(Arity).
  cons_id_maybe_arity(int_const(_)) = yes(0).
+cons_id_maybe_arity(uint_const(_)) = yes(0).
  cons_id_maybe_arity(float_const(_)) = yes(0).
  cons_id_maybe_arity(char_const(_)) = yes(0).
  cons_id_maybe_arity(string_const(_)) = yes(0).
diff --git a/compiler/rbmm.execution_path.m b/compiler/rbmm.execution_path.m
index 7335f0c..84c7782 100644
--- a/compiler/rbmm.execution_path.m
+++ b/compiler/rbmm.execution_path.m
@@ -229,6 +229,7 @@ execution_paths_covered_cases(ProcInfo, Switch, [Case | Cases], !ExecPaths) :-
          )
      ;
          ( MainConsId = int_const(_Int)
+        ; MainConsId = uint_const(_UInt)
          ; MainConsId = float_const(_Float)
          ; MainConsId = char_const(_Char)
          ; MainConsId = string_const(_String)
diff --git a/compiler/rtti.m b/compiler/rtti.m
index cf537e2..fc8a737 100644
--- a/compiler/rtti.m
+++ b/compiler/rtti.m
@@ -433,6 +433,7 @@
      %
  :- type builtin_ctor
      --->    builtin_ctor_int
+    ;       builtin_ctor_uint
      ;       builtin_ctor_float
      ;       builtin_ctor_char
      ;       builtin_ctor_string
@@ -1723,6 +1724,7 @@ type_ctor_rep_to_string(TypeCtorData, RepStr) :-
  :- pred builtin_ctor_rep_to_string(builtin_ctor::in, string::out) is det.

  builtin_ctor_rep_to_string(builtin_ctor_int, "MR_TYPECTOR_REP_INT").
+builtin_ctor_rep_to_string(builtin_ctor_uint, "MR_TYPECTOR_REP_UINT").
  builtin_ctor_rep_to_string(builtin_ctor_string, "MR_TYPECTOR_REP_STRING").
  builtin_ctor_rep_to_string(builtin_ctor_float, "MR_TYPECTOR_REP_FLOAT").
  builtin_ctor_rep_to_string(builtin_ctor_char, "MR_TYPECTOR_REP_CHAR").
@@ -2354,6 +2356,7 @@ tabling_id_has_array_type(Id) = IsArray :-

  table_trie_step_to_c(table_trie_step_dummy, "MR_TABLE_STEP_DUMMY", no).
  table_trie_step_to_c(table_trie_step_int, "MR_TABLE_STEP_INT", no).
+table_trie_step_to_c(table_trie_step_uint, "MR_TABLE_STEP_UINT", no).
  table_trie_step_to_c(table_trie_step_char, "MR_TABLE_STEP_CHAR", no).
  table_trie_step_to_c(table_trie_step_string, "MR_TABLE_STEP_STRING", no).
  table_trie_step_to_c(table_trie_step_float, "MR_TABLE_STEP_FLOAT", no).
diff --git a/compiler/rtti_to_mlds.m b/compiler/rtti_to_mlds.m
index fc1a741..842ef84 100644
--- a/compiler/rtti_to_mlds.m
+++ b/compiler/rtti_to_mlds.m
@@ -1888,6 +1888,7 @@ add_rtti_defn_arcs_const(DefnDataName, Const, !Graph) :-
          ( Const = mlconst_true
          ; Const = mlconst_false
          ; Const = mlconst_int(_)
+        ; Const = mlconst_uint(_)
          ; Const = mlconst_enum(_, _)
          ; Const = mlconst_char(_)
          ; Const = mlconst_foreign(_, _, _)
diff --git a/compiler/special_pred.m b/compiler/special_pred.m
index 93a4ad2..afa3e19 100644
--- a/compiler/special_pred.m
+++ b/compiler/special_pred.m
@@ -341,6 +341,7 @@ is_builtin_type_special_preds_defined_in_mercury(TypeCtor, TypeName) :-
      Builtin = mercury_public_builtin_module,
      TypeCtor = type_ctor(qualified(Builtin, TypeName), 0),
      ( TypeName = "int"
+    ; TypeName = "uint"
      ; TypeName = "string"
      ; TypeName = "character"
      ; TypeName = "float"
diff --git a/compiler/switch_gen.m b/compiler/switch_gen.m
index 6f3dddb..fe10858 100644
--- a/compiler/switch_gen.m
+++ b/compiler/switch_gen.m
@@ -456,6 +456,7 @@ is_reserved_addr_tag(ConsTag) = IsReservedAddr :-
          IsReservedAddr = is_reserved_addr_tag(SubConsTag)
      ;
          ( ConsTag = int_tag(_)
+        ; ConsTag = uint_tag(_)
          ; ConsTag = float_tag(_)
          ; ConsTag = string_tag(_)
          ; ConsTag = foreign_tag(_, _)
diff --git a/compiler/switch_util.m b/compiler/switch_util.m
index 552defc..2e213a3 100644
--- a/compiler/switch_util.m
+++ b/compiler/switch_util.m
@@ -507,6 +507,7 @@ type_ctor_cat_to_switch_cat(CtorCat) = SwitchCat :-
      (
          ( CtorCat = ctor_cat_enum(_)
          ; CtorCat = ctor_cat_builtin(cat_builtin_int)
+        ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
          ; CtorCat = ctor_cat_builtin(cat_builtin_char)
          ),
          SwitchCat = atomic_switch
@@ -537,6 +538,7 @@ type_ctor_cat_to_switch_cat(CtorCat) = SwitchCat :-
  estimate_switch_tag_test_cost(Tag) = Cost :-
      (
          ( Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = reserved_address_tag(_)
          ; Tag = shared_local_tag(_, _)
@@ -560,6 +562,7 @@ estimate_switch_tag_test_cost(Tag) = Cost :-
          Tag = float_tag(_),
          % You need to follow a pointer and then compare 64 bits
          % (two words on 32 bit machines, which are still the most common).
+        % XXX they're not that common anymore.
          Cost = 3
      ;
          Tag = shared_remote_tag(_, _),
@@ -1226,6 +1229,7 @@ get_ptag_counts_loop([Tag | Tags], !MaxPrimary, !PtagCountMap) :-
          ; Tag = string_tag(_)
          ; Tag = float_tag(_)
          ; Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = closure_tag(_, _, _)
          ; Tag = type_ctor_info_tag(_, _, _)
@@ -1330,6 +1334,7 @@ group_case_by_ptag(CaseId, CaseRep, TaggedConsId,
          ; Tag = string_tag(_)
          ; Tag = float_tag(_)
          ; Tag = int_tag(_)
+        ; Tag = uint_tag(_)
          ; Tag = foreign_tag(_, _)
          ; Tag = closure_tag(_, _, _)
          ; Tag = type_ctor_info_tag(_, _, _)
diff --git a/compiler/table_gen.m b/compiler/table_gen.m
index 82d0d87..9bcf5bf 100644
--- a/compiler/table_gen.m
+++ b/compiler/table_gen.m
@@ -2461,6 +2461,7 @@ gen_lookup_call_for_type(ArgTablingMethod0, CtorCat, Type, ArgVar, VarSeqNum,
      (
          ( CtorCat = ctor_cat_enum(_)
          ; CtorCat = ctor_cat_builtin(cat_builtin_int)
+        ; CtorCat = ctor_cat_builtin(cat_builtin_uint)
          ; CtorCat = ctor_cat_builtin(cat_builtin_char)
          ; CtorCat = ctor_cat_void
          ),
@@ -2552,6 +2553,10 @@ gen_lookup_call_for_type(ArgTablingMethod0, CtorCat, Type, ArgVar, VarSeqNum,
                  CatString = "int",
                  Step = table_trie_step_int
              ;
+                CtorCat = ctor_cat_builtin(cat_builtin_uint),
+                CatString = "uint",
+                Step = table_trie_step_uint
+            ;
                  CtorCat = ctor_cat_builtin(cat_builtin_char),
                  CatString = "char",
                  Step = table_trie_step_char
@@ -2609,6 +2614,9 @@ gen_lookup_call_for_type(ArgTablingMethod0, CtorCat, Type, ArgVar, VarSeqNum,
              CtorCat = ctor_cat_builtin(cat_builtin_int),
              unexpected($module, $pred, "tabling ints by addr")
          ;
+            CtorCat = ctor_cat_builtin(cat_builtin_uint),
+            unexpected($module, $pred, "tabling uints by addr")
+        ;
              CtorCat = ctor_cat_builtin(cat_builtin_char),
              unexpected($module, $pred, "tabling chars by addr")
          ;
@@ -3629,6 +3637,9 @@ type_save_category(CtorCat, Name) :-
          CtorCat = ctor_cat_builtin(cat_builtin_int),
          Name = "int"
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        Name = "uint"
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_float),
          Name = "float"
      ;
diff --git a/compiler/type_constraints.m b/compiler/type_constraints.m
index 1dce3d4..560371d 100644
--- a/compiler/type_constraints.m
+++ b/compiler/type_constraints.m
@@ -2427,6 +2427,9 @@ type_to_string(TVarSet, Type, Name) :-
          Type = builtin_type(builtin_type_int),
          Name = "int"
      ;
+        Type = builtin_type(builtin_type_uint),
+        Name = "uint"
+    ;
          Type = builtin_type(builtin_type_float),
          Name = "float"
      ;
diff --git a/compiler/type_ctor_info.m b/compiler/type_ctor_info.m
index c532b07..d6696b5 100644
--- a/compiler/type_ctor_info.m
+++ b/compiler/type_ctor_info.m
@@ -435,6 +435,7 @@ construct_type_ctor_info(TypeCtorGenInfo, ModuleInfo, RttiData) :-
  % builtin_type_ctors_with_no_hlds_type_defn; any changes here may need
  % to be done there as well.
  builtin_type_ctor("builtin", "int", 0, builtin_ctor_int).
+builtin_type_ctor("builtin", "uint", 0, builtin_ctor_uint).
  builtin_type_ctor("builtin", "string", 0, builtin_ctor_string).
  builtin_type_ctor("builtin", "float", 0, builtin_ctor_float).
  builtin_type_ctor("builtin", "character", 0, builtin_ctor_char).
@@ -488,7 +489,7 @@ impl_type_ctor("table_builtin", "ml_subgoal", 0, impl_ctor_subgoal).
      %
  :- func type_ctor_info_rtti_version = int.

-type_ctor_info_rtti_version = 16.
+type_ctor_info_rtti_version = 17.

  %---------------------------------------------------------------------------%

@@ -651,6 +652,7 @@ make_foreign_enum_functors(TypeCtor, Lang, [Functor | Functors], NextOrdinal,
          ( ConsTag = string_tag(_)
          ; ConsTag = float_tag(_)
          ; ConsTag = int_tag(_)
+        ; ConsTag = uint_tag(_)
          ; ConsTag = closure_tag(_, _, _)
          ; ConsTag = type_ctor_info_tag(_, _, _)
          ; ConsTag = base_typeclass_info_tag(_, _, _)
@@ -832,6 +834,7 @@ get_maybe_reserved_rep(ConsTag, ConsRep) :-
          ( ConsTag = no_tag
          ; ConsTag = string_tag(_)
          ; ConsTag = int_tag(_)
+        ; ConsTag = uint_tag(_)
          ; ConsTag = foreign_tag(_, _)
          ; ConsTag = float_tag(_)
          ; ConsTag = closure_tag(_, _, _)
diff --git a/compiler/type_util.m b/compiler/type_util.m
index 8b2b98a..994fca0 100644
--- a/compiler/type_util.m
+++ b/compiler/type_util.m
@@ -753,6 +753,9 @@ classify_type_ctor(ModuleInfo, TypeCtor) = TypeCategory :-
              TypeName = "character",
              TypeCategoryPrime = ctor_cat_builtin(cat_builtin_char)
          ;
+            TypeName = "uint",
+            TypeCategoryPrime = ctor_cat_builtin(cat_builtin_uint)
+        ;
              TypeName = "int",
              TypeCategoryPrime = ctor_cat_builtin(cat_builtin_int)
          ;
@@ -875,6 +878,7 @@ type_may_use_atomic_alloc(ModuleInfo, Type) = TypeMayUseAtomic :-
      TypeCategory = classify_type(ModuleInfo, Type),
      (
          ( TypeCategory = ctor_cat_builtin(cat_builtin_int)
+        ; TypeCategory = ctor_cat_builtin(cat_builtin_uint)
          ; TypeCategory = ctor_cat_builtin(cat_builtin_char)
          ; TypeCategory = ctor_cat_enum(_)
          ; TypeCategory = ctor_cat_builtin_dummy
diff --git a/compiler/typecheck.m b/compiler/typecheck.m
index 7a799d0..21d15fe 100644
--- a/compiler/typecheck.m
+++ b/compiler/typecheck.m
@@ -2235,6 +2235,10 @@ cons_id_must_be_builtin_type(ConsId, ConsType, BuiltinTypeName) :-
          BuiltinTypeName = "int",
          BuiltinType = builtin_type_int
      ;
+        ConsId = uint_const(_),
+        BuiltinTypeName = "uint",
+        BuiltinType = builtin_type_uint
+    ;
          ConsId = float_const(_),
          BuiltinTypeName = "float",
          BuiltinType = builtin_type_float
@@ -2768,6 +2772,7 @@ type_assign_unify_type(X, Y, TypeAssign0, TypeAssign) :-
  :- pred builtin_atomic_type(cons_id::in, string::out) is semidet.

  builtin_atomic_type(int_const(_), "int").
+builtin_atomic_type(uint_const(_), "uint").
  builtin_atomic_type(float_const(_), "float").
  builtin_atomic_type(char_const(_), "character").
  builtin_atomic_type(string_const(_), "string").
diff --git a/compiler/unify_gen.m b/compiler/unify_gen.m
index 776c0ad..6ec77d9 100644
--- a/compiler/unify_gen.m
+++ b/compiler/unify_gen.m
@@ -420,6 +420,9 @@ raw_tag_test(Rval, ConsTag, TestRval) :-
          ConsTag = int_tag(Int),
          TestRval = binop(eq, Rval, const(llconst_int(Int)))
      ;
+        ConsTag = uint_tag(UInt),
+        TestRval = binop(uint_eq, Rval, const(llconst_uint(UInt)))
+    ;
          ConsTag = foreign_tag(ForeignLang, ForeignVal),
          expect(unify(ForeignLang, lang_c), $module, $pred,
              "foreign tag for language other than C"),
@@ -551,6 +554,10 @@ generate_construction_2(ConsTag, LHSVar, RHSVars, ArgModes, ArgWidths,
          assign_const_to_var(LHSVar, const(llconst_int(Int)), !.CI, !CLD),
          Code = empty
      ;
+        ConsTag = uint_tag(UInt),
+        assign_const_to_var(LHSVar, const(llconst_uint(UInt)), !.CI, !CLD),
+        Code = empty
+    ;
          ConsTag = foreign_tag(Lang, Val),
          expect(unify(Lang, lang_c), $module, $pred,
              "foreign_tag for language other than C"),
@@ -1296,6 +1303,7 @@ generate_det_deconstruction_2(Var, Cons, Args, Modes, ArgWidths, Tag,
      (
          ( Tag = string_tag(_String)
          ; Tag = int_tag(_Int)
+        ; Tag = uint_tag(_UInt)
          ; Tag = foreign_tag(_, _)
          ; Tag = float_tag(_Float)
          ; Tag = closure_tag(_, _, _)
@@ -1798,6 +1806,7 @@ generate_const_struct_rval(ModuleInfo, UnboxedFloats, ConstStructMap,
      ;
          ( ConsTag = string_tag(_)
          ; ConsTag = int_tag(_)
+        ; ConsTag = uint_tag(_)
          ; ConsTag = foreign_tag(_, _)
          ; ConsTag = float_tag(_)
          ; ConsTag = shared_local_tag(_, _)
@@ -1856,6 +1865,10 @@ generate_const_struct_arg_tag(ModuleInfo, UnboxedFloats, ConstStructMap,
              Const = llconst_int(Int),
              Type = lt_integer
          ;
+            ConsTag = uint_tag(UInt),
+            Const = llconst_uint(UInt),
+            Type = lt_unsigned
+        ;
              ConsTag = foreign_tag(Lang, Val),
              expect(unify(Lang, lang_c), $module, $pred,
                  "foreign_tag for language other than C"),
@@ -2033,6 +2046,10 @@ generate_ground_term_conjunct_tag(Var, ConsTag, Args, ConsArgWidths,
              Const = llconst_int(Int),
              Type = lt_integer
          ;
+            ConsTag = uint_tag(UInt),
+            Const = llconst_uint(UInt),
+            Type = lt_unsigned
+        ;
              ConsTag = foreign_tag(Lang, Val),
              expect(unify(Lang, lang_c), $module, $pred,
                  "foreign_tag for language other than C"),
diff --git a/compiler/unify_proc.m b/compiler/unify_proc.m
index cdcf48a..8be1edc 100644
--- a/compiler/unify_proc.m
+++ b/compiler/unify_proc.m
@@ -671,6 +671,9 @@ generate_builtin_unify(CtorCat, X, Y, Context, Clause, !Info) :-
          CtorCat = ctor_cat_builtin(cat_builtin_int),
          Name = "builtin_unify_int"
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        Name = "builtin_unify_uint"
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_char),
          Name = "builtin_unify_character"
      ;
@@ -995,6 +998,9 @@ generate_builtin_compare(CtorCat, Res, X, Y, Context, Clause, !Info) :-
          CtorCat = ctor_cat_builtin(cat_builtin_int),
          Name = "builtin_compare_int"
      ;
+        CtorCat = ctor_cat_builtin(cat_builtin_uint),
+        Name = "builtin_compare_uint"
+    ;
          CtorCat = ctor_cat_builtin(cat_builtin_char),
          Name = "builtin_compare_character"
      ;
diff --git a/compiler/unused_imports.m b/compiler/unused_imports.m
index a9aa765..40f070d 100644
--- a/compiler/unused_imports.m
+++ b/compiler/unused_imports.m
@@ -799,6 +799,7 @@ cons_id_used_modules(Visibility, ConsId, !UsedModules) :-
          ( ConsId = tuple_cons(_)
          ; ConsId = closure_cons(_, _)
          ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
          ; ConsId = float_const(_)
          ; ConsId = char_const(_)
          ; ConsId = string_const(_)
@@ -830,6 +831,7 @@ mer_type_used_modules(Visibility, Type, !UsedModules) :-
          Type = builtin_type(BuiltinType),
          (
              ( BuiltinType = builtin_type_int
+            ; BuiltinType = builtin_type_uint
              ; BuiltinType = builtin_type_float
              ; BuiltinType = builtin_type_string
              )
diff --git a/compiler/write_module_interface_files.m b/compiler/write_module_interface_files.m
index 248858b..ba09cb5 100644
--- a/compiler/write_module_interface_files.m
+++ b/compiler/write_module_interface_files.m
@@ -1197,6 +1197,7 @@ type_to_type_ctor_set(Type, !TypeCtors) :-
              true
          else if
              ( SymName = unqualified("int")
+            ; SymName = unqualified("uint")
              ; SymName = unqualified("float")
              ; SymName = unqualified("string")
              ; SymName = unqualified("character")
diff --git a/compiler/xml_documentation.m b/compiler/xml_documentation.m
index b43ebd1..2fe3a9e 100644
--- a/compiler/xml_documentation.m
+++ b/compiler/xml_documentation.m
@@ -456,6 +456,7 @@ mer_type_to_xml(TVarset, defined_type(TypeName, Args, _)) = Xml :-
      XmlArgs = xml_list("type_args", mer_type_to_xml(TVarset), Args),
      Xml = elem("type", [Ref], [XmlName, XmlArgs]).
  mer_type_to_xml(_, builtin_type(builtin_type_int)) = elem("int", [], []).
+mer_type_to_xml(_, builtin_type(builtin_type_uint)) = elem("uint", [], []).
  mer_type_to_xml(_, builtin_type(builtin_type_float)) = elem("float", [], []).
  mer_type_to_xml(_, builtin_type(builtin_type_string)) = elem("string", [], []).
  mer_type_to_xml(_, builtin_type(builtin_type_char)) =
@@ -685,6 +686,8 @@ cons_id_to_xml(cons(Name, Arity, _)) =
  cons_id_to_xml(tuple_cons(Arity)) =
      elem("cons", [], [name_to_xml(unqualified("{}")), arity_to_xml(Arity)]).
  cons_id_to_xml(int_const(I)) = tagged_int("int", I).
+cons_id_to_xml(uint_const(_)) = _ :-
+    unexpected($file, $pred, "NYI uint").
  cons_id_to_xml(float_const(F)) = tagged_float("float", F).
  cons_id_to_xml(char_const(C)) = tagged_char("char", C).
  cons_id_to_xml(string_const(S)) = tagged_string("string", S).
diff --git a/deep_profiler/program_representation_utils.m b/deep_profiler/program_representation_utils.m
index ff19d06..d403bd4 100644
--- a/deep_profiler/program_representation_utils.m
+++ b/deep_profiler/program_representation_utils.m
@@ -301,6 +301,9 @@ type_rep_to_strings(TypeRep, Cord) :-
              BuiltinTypeRep = builtin_type_int_rep,
              TypeNameStr = "int"
          ;
+            BuiltinTypeRep = builtin_type_uint_rep,
+            TypeNameStr = "uint"
+        ;
              BuiltinTypeRep = builtin_type_float_rep,
              TypeNameStr = "float"
          ;
diff --git a/java/runtime/TypeCtorRep.java b/java/runtime/TypeCtorRep.java
index 1f374c8..5ab0d24 100644
--- a/java/runtime/TypeCtorRep.java
+++ b/java/runtime/TypeCtorRep.java
@@ -15,7 +15,7 @@ public class TypeCtorRep implements java.io.Serializable {
  	// should generate references to these constants instead of those in
  	// private_builtin.
  	public static final int MR_TYPECTOR_REP_EQUIV		= 6;
-	public static final int MR_TYPECTOR_REP_EQUIV_GROUND	= 29;
+	public static final int MR_TYPECTOR_REP_EQUIV_GROUND	= 30;

  	// Instance variable for TypeCtorRep objects.

diff --git a/library/MODULES_DOC b/library/MODULES_DOC
index 3fdb5c1..10f8a58 100644
--- a/library/MODULES_DOC
+++ b/library/MODULES_DOC
@@ -86,6 +86,7 @@ time.m
  tree234.m
  tree_bitset.m
  type_desc.m
+uint.m
  unit.m
  univ.m
  varset.m
diff --git a/library/construct.m b/library/construct.m
index 90caf9c..17566e0 100644
--- a/library/construct.m
+++ b/library/construct.m
@@ -458,6 +458,7 @@ get_functor_ordinal(TypeDesc, FunctorNumber, Ordinal) :-
          case MR_TYPECTOR_REP_FUNC:
          case MR_TYPECTOR_REP_PRED:
          case MR_TYPECTOR_REP_INT:
+        case MR_TYPECTOR_REP_UINT:
          case MR_TYPECTOR_REP_FLOAT:
          case MR_TYPECTOR_REP_CHAR:
          case MR_TYPECTOR_REP_STRING:
@@ -893,6 +894,12 @@ find_functor_2(TypeInfo, Functor, Arity, Num0, FunctorNumber, ArgTypes) :-
                  ""cannot construct int with construct.construct"");
              break;

+        case MR_TYPECTOR_REP_UINT:
+            /* uints don't have functor ordinals. */
+            MR_fatal_error(
+                ""cannot construct uint with construct.construct"");
+            break;
+
          case MR_TYPECTOR_REP_FLOAT:
              /* floats don't have functor ordinals. */
              MR_fatal_error(
diff --git a/library/erlang_rtti_implementation.m b/library/erlang_rtti_implementation.m
index 0e102fe..e869f60 100644
--- a/library/erlang_rtti_implementation.m
+++ b/library/erlang_rtti_implementation.m
@@ -166,6 +166,7 @@
      ;       etcr_array
      ;       etcr_eqv
      ;       etcr_int
+    ;       etcr_uint
      ;       etcr_float
      ;       etcr_char
      ;       etcr_string
@@ -824,6 +825,12 @@ deconstruct_2(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
          Arity = 0,
          Arguments = []
      ;
+        TypeCtorRep = etcr_uint,
+        Functor = "<<uint>>",
+        FunctorNumber = 0,
+        Arity = 0,
+        Arguments = []
+    ;
          TypeCtorRep = etcr_float,
          det_dynamic_cast(Term, Float),
          Functor = float_to_string(Float),
@@ -1184,6 +1191,7 @@ num_functors(TypeInfo, MaybeNumFunctors) :-
      ;
          ( TypeCtorRep = etcr_array
          ; TypeCtorRep = etcr_int
+        ; TypeCtorRep = etcr_uint
          ; TypeCtorRep = etcr_float
          ; TypeCtorRep = etcr_char
          ; TypeCtorRep = etcr_string
@@ -1301,6 +1309,7 @@ get_functor_with_names(TypeInfo, NumFunctor) = Result :-
      ;
          ( TypeCtorRep = etcr_array
          ; TypeCtorRep = etcr_int
+        ; TypeCtorRep = etcr_uint
          ; TypeCtorRep = etcr_float
          ; TypeCtorRep = etcr_char
          ; TypeCtorRep = etcr_string
diff --git a/library/library.m b/library/library.m
index b0e8585..3b92042 100644
--- a/library/library.m
+++ b/library/library.m
@@ -147,6 +147,7 @@
  :- import_module tree234.
  :- import_module tree_bitset.
  :- import_module type_desc.
+:- import_module uint.
  :- import_module unit.
  :- import_module univ.
  :- import_module varset.
@@ -334,6 +335,7 @@ mercury_std_library_module("thread.semaphore").
  mercury_std_library_module("tree234").
  mercury_std_library_module("tree_bitset").
  mercury_std_library_module("type_desc").
+mercury_std_library_module("uint").
  mercury_std_library_module("unit").
  mercury_std_library_module("univ").
  mercury_std_library_module("varset").
diff --git a/library/private_builtin.m b/library/private_builtin.m
index d7596f1..ad73dcc 100644
--- a/library/private_builtin.m
+++ b/library/private_builtin.m
@@ -48,6 +48,9 @@
  :- pred builtin_unify_int(int::in, int::in) is semidet.
  :- pred builtin_compare_int(comparison_result::uo, int::in, int::in) is det.

+:- pred builtin_unify_uint(T::in, T::in) is semidet.
+:- pred builtin_compare_uint(comparison_result::uo, T::in, T::in) is det.
+
  :- pred builtin_unify_character(character::in, character::in) is semidet.
  :- pred builtin_compare_character(comparison_result::uo, character::in,
      character::in) is det.
@@ -164,6 +167,20 @@ builtin_compare_int(R, X, Y) :-
          R = (>)
      ).

+builtin_unify_uint(_, _) :-
+    ( if semidet_succeed then
+        sorry("unify for uint")
+    else
+        semidet_succeed
+    ).
+
+builtin_compare_uint(Result, _, _) :-
+    ( if semidet_succeed then
+        sorry("compare for uint")
+    else
+        Result = (=)
+    ).
+
  builtin_unify_character(C, C).

  builtin_compare_character(R, X, Y) :-
@@ -1698,54 +1715,55 @@ const MR_FA_TypeInfo_Struct1 ML_type_info_for_list_of_pseudo_type_info = {
      }

      // TypeCtorRep constants
-    public static final int MR_TYPECTOR_REP_ENUM = 0;
-    public static final int MR_TYPECTOR_REP_ENUM_USEREQ = 1;
-    public static final int MR_TYPECTOR_REP_DU = 2;
+    public static final int MR_TYPECTOR_REP_ENUM                    = 0;
+    public static final int MR_TYPECTOR_REP_ENUM_USEREQ             = 1;
+    public static final int MR_TYPECTOR_REP_DU                      = 2;
      public static final int MR_TYPECTOR_REP_DU_USEREQ               = 3;
      public static final int MR_TYPECTOR_REP_NOTAG                   = 4;
      public static final int MR_TYPECTOR_REP_NOTAG_USEREQ            = 5;
      public static final int MR_TYPECTOR_REP_EQUIV                   = 6;
      public static final int MR_TYPECTOR_REP_FUNC                    = 7;
      public static final int MR_TYPECTOR_REP_INT                     = 8;
-    public static final int MR_TYPECTOR_REP_CHAR                    = 9;
-    public static final int MR_TYPECTOR_REP_FLOAT                   = 10;
-    public static final int MR_TYPECTOR_REP_STRING                  = 11;
-    public static final int MR_TYPECTOR_REP_PRED                    = 12;
-    public static final int MR_TYPECTOR_REP_SUBGOAL                 = 13;
-    public static final int MR_TYPECTOR_REP_VOID                    = 14;
-    public static final int MR_TYPECTOR_REP_C_POINTER               = 15;
-    public static final int MR_TYPECTOR_REP_TYPEINFO                = 16;
-    public static final int MR_TYPECTOR_REP_TYPECLASSINFO           = 17;
-    public static final int MR_TYPECTOR_REP_ARRAY                   = 18;
-    public static final int MR_TYPECTOR_REP_SUCCIP                  = 19;
-    public static final int MR_TYPECTOR_REP_HP                      = 20;
-    public static final int MR_TYPECTOR_REP_CURFR                   = 21;
-    public static final int MR_TYPECTOR_REP_MAXFR                   = 22;
-    public static final int MR_TYPECTOR_REP_REDOFR                  = 23;
-    public static final int MR_TYPECTOR_REP_REDOIP                  = 24;
-    public static final int MR_TYPECTOR_REP_TRAIL_PTR               = 25;
-    public static final int MR_TYPECTOR_REP_TICKET                  = 26;
-    public static final int MR_TYPECTOR_REP_NOTAG_GROUND            = 27;
-    public static final int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ     = 28;
-    public static final int MR_TYPECTOR_REP_EQUIV_GROUND            = 29;
-    public static final int MR_TYPECTOR_REP_TUPLE                   = 30;
-    public static final int MR_TYPECTOR_REP_RESERVED_ADDR           = 31;
-    public static final int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ    = 32;
-    public static final int MR_TYPECTOR_REP_TYPECTORINFO            = 33;
-    public static final int MR_TYPECTOR_REP_BASETYPECLASSINFO       = 34;
-    public static final int MR_TYPECTOR_REP_TYPEDESC                = 35;
-    public static final int MR_TYPECTOR_REP_TYPECTORDESC            = 36;
-    public static final int MR_TYPECTOR_REP_FOREIGN                 = 37;
-    public static final int MR_TYPECTOR_REP_REFERENCE               = 38;
-    public static final int MR_TYPECTOR_REP_STABLE_C_POINTER        = 39;
-    public static final int MR_TYPECTOR_REP_STABLE_FOREIGN          = 40;
-    public static final int MR_TYPECTOR_REP_PSEUDOTYPEDESC          = 41;
-    public static final int MR_TYPECTOR_REP_DUMMY                   = 42;
-    public static final int MR_TYPECTOR_REP_BITMAP                  = 43;
-    public static final int MR_TYPECTOR_REP_FOREIGN_ENUM            = 44;
-    public static final int MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 45;
-    public static final int MR_TYPECTOR_REP_UNKNOWN                 = 46;
-    public static final int MR_TYPECTOR_REP_MAX                     = 47;
+    public static final int MR_TYPECTOR_REP_UINT                    = 9;
+    public static final int MR_TYPECTOR_REP_CHAR                    = 10;
+    public static final int MR_TYPECTOR_REP_FLOAT                   = 11;
+    public static final int MR_TYPECTOR_REP_STRING                  = 12;
+    public static final int MR_TYPECTOR_REP_PRED                    = 13;
+    public static final int MR_TYPECTOR_REP_SUBGOAL                 = 14;
+    public static final int MR_TYPECTOR_REP_VOID                    = 15;
+    public static final int MR_TYPECTOR_REP_C_POINTER               = 16;
+    public static final int MR_TYPECTOR_REP_TYPEINFO                = 17;
+    public static final int MR_TYPECTOR_REP_TYPECLASSINFO           = 18;
+    public static final int MR_TYPECTOR_REP_ARRAY                   = 19;
+    public static final int MR_TYPECTOR_REP_SUCCIP                  = 20;
+    public static final int MR_TYPECTOR_REP_HP                      = 21;
+    public static final int MR_TYPECTOR_REP_CURFR                   = 22;
+    public static final int MR_TYPECTOR_REP_MAXFR                   = 23;
+    public static final int MR_TYPECTOR_REP_REDOFR                  = 24;
+    public static final int MR_TYPECTOR_REP_REDOIP                  = 25;
+    public static final int MR_TYPECTOR_REP_TRAIL_PTR               = 26;
+    public static final int MR_TYPECTOR_REP_TICKET                  = 27;
+    public static final int MR_TYPECTOR_REP_NOTAG_GROUND            = 28;
+    public static final int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ     = 29;
+    public static final int MR_TYPECTOR_REP_EQUIV_GROUND            = 30;
+    public static final int MR_TYPECTOR_REP_TUPLE                   = 31;
+    public static final int MR_TYPECTOR_REP_RESERVED_ADDR           = 32;
+    public static final int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ    = 33;
+    public static final int MR_TYPECTOR_REP_TYPECTORINFO            = 34;
+    public static final int MR_TYPECTOR_REP_BASETYPECLASSINFO       = 35;
+    public static final int MR_TYPECTOR_REP_TYPEDESC                = 36;
+    public static final int MR_TYPECTOR_REP_TYPECTORDESC            = 37;
+    public static final int MR_TYPECTOR_REP_FOREIGN                 = 38;
+    public static final int MR_TYPECTOR_REP_REFERENCE               = 39;
+    public static final int MR_TYPECTOR_REP_STABLE_C_POINTER        = 40;
+    public static final int MR_TYPECTOR_REP_STABLE_FOREIGN          = 41;
+    public static final int MR_TYPECTOR_REP_PSEUDOTYPEDESC          = 42;
+    public static final int MR_TYPECTOR_REP_DUMMY                   = 43;
+    public static final int MR_TYPECTOR_REP_BITMAP                  = 44;
+    public static final int MR_TYPECTOR_REP_FOREIGN_ENUM            = 45;
+    public static final int MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 46;
+    public static final int MR_TYPECTOR_REP_UNKNOWN                 = 47;
+    public static final int MR_TYPECTOR_REP_MAX                     = 48;

      public static final int MR_SECTAG_NONE              = 0;
      public static final int MR_SECTAG_NONE_DIRECT_ARG   = 1;
diff --git a/library/rtti_implementation.m b/library/rtti_implementation.m
index 40c4454..0bb75cf 100644
--- a/library/rtti_implementation.m
+++ b/library/rtti_implementation.m
@@ -141,6 +141,7 @@
      ;       tcr_equiv
      ;       tcr_func
      ;       tcr_int
+    ;       tcr_uint
      ;       tcr_char
      ;       tcr_float
      ;       tcr_string
@@ -1671,6 +1672,11 @@ is_exist_pseudo_type_info(_, _) :-
                  throw new System.Exception(
                      ""cannot construct int with construct.construct"");

+            case runtime.TypeCtorRep.MR_TYPECTOR_REP_UINT:
+                /* uints don't have functor ordinals. */
+                throw new System.Exception(
+                    ""cannot construct uint with construct.construct"");
+
              case runtime.TypeCtorRep.MR_TYPECTOR_REP_FLOAT:
                  /* floats don't have functor ordinals. */
                  throw new System.Exception(
@@ -2056,6 +2062,11 @@ is_exist_pseudo_type_info(_, _) :-
                  throw new Error(
                      ""cannot construct int with construct.construct"");

+            case private_builtin.MR_TYPECTOR_REP_UINT:
+                /* ints don't have functor ordinals. */
+                throw new Error(
+                    ""cannot construct uint with construct.construct"");
+
              case private_builtin.MR_TYPECTOR_REP_FLOAT:
                  /* floats don't have functor ordinals. */
                  throw new Error(
@@ -2625,6 +2636,12 @@ deconstruct_2(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
          Arity = 0,
          Arguments = []
      ;
+        TypeCtorRep = tcr_uint,
+        Functor = "<<uint>>",
+        Ordinal = -1,
+        Arity = 0,
+        Arguments = []
+    ;
          TypeCtorRep = tcr_char,
          det_dynamic_cast(Term, Char),
          Functor = string.from_char_list(['\'', Char, '\'']),
@@ -2890,6 +2907,7 @@ univ_named_arg_2(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon, Name,
          ; TypeCtorRep = tcr_equiv
          ; TypeCtorRep = tcr_func
          ; TypeCtorRep = tcr_int
+        ; TypeCtorRep = tcr_uint
          ; TypeCtorRep = tcr_char
          ; TypeCtorRep = tcr_float
          ; TypeCtorRep = tcr_string
diff --git a/library/uint.m b/library/uint.m
index e69de29..a89ea25 100644
--- a/library/uint.m
+++ b/library/uint.m
@@ -0,0 +1,19 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+% Copyright (C) 2016 The Mercury team.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%---------------------------------------------------------------------------%
+
+:- module uint.
+:- interface.
+
+    % uints are NYI -- this module is just a placeholder for their
+    % library support.
+    %
+:- type placeholder_uint ---> placeholder_uint.
+
+%---------------------------------------------------------------------------%
+:- end_module uint.
+%---------------------------------------------------------------------------%
diff --git a/mdbcomp/program_representation.m b/mdbcomp/program_representation.m
index 5decf0a..2b9eb9e 100644
--- a/mdbcomp/program_representation.m
+++ b/mdbcomp/program_representation.m
@@ -96,6 +96,7 @@

  :- type builtin_type_rep
      --->    builtin_type_int_rep
+    ;       builtin_type_uint_rep
      ;       builtin_type_float_rep
      ;       builtin_type_string_rep
      ;       builtin_type_char_rep.
@@ -1256,27 +1257,30 @@ read_encoded_type(ByteCode, StringTable, TypeTable, TypeRep, !Pos) :-
          TypeRep = builtin_type_rep(builtin_type_int_rep)
      ;
          Selector = 6,
-        TypeRep = builtin_type_rep(builtin_type_float_rep)
+        TypeRep = builtin_type_rep(builtin_type_uint_rep)
      ;
          Selector = 7,
-        TypeRep = builtin_type_rep(builtin_type_string_rep)
+        TypeRep = builtin_type_rep(builtin_type_float_rep)
      ;
          Selector = 8,
-        TypeRep = builtin_type_rep(builtin_type_char_rep)
+        TypeRep = builtin_type_rep(builtin_type_string_rep)
      ;
          Selector = 9,
+        TypeRep = builtin_type_rep(builtin_type_char_rep)
+    ;
+        Selector = 10,
          read_num(ByteCode, NumArgs, !Pos),
          read_n_items(read_num(ByteCode), NumArgs, TypeNumArgs, !Pos),
          list.map(map.lookup(TypeTable), TypeNumArgs, TypeRepArgs),
          TypeRep = tuple_type_rep(TypeRepArgs)
      ;
-        Selector = 10,
+        Selector = 11,
          read_num(ByteCode, NumArgs, !Pos),
          read_n_items(read_num(ByteCode), NumArgs, TypeNumArgs, !Pos),
          list.map(map.lookup(TypeTable), TypeNumArgs, TypeRepArgs),
          TypeRep = higher_order_type_rep(TypeRepArgs, no)
      ;
-        Selector = 11,
+        Selector = 12,
          read_num(ByteCode, NumArgs, !Pos),
          read_n_items(read_num(ByteCode), NumArgs, TypeNumArgs, !Pos),
          list.map(map.lookup(TypeTable), TypeNumArgs, TypeRepArgs),
@@ -1284,7 +1288,7 @@ read_encoded_type(ByteCode, StringTable, TypeTable, TypeRep, !Pos) :-
          map.lookup(TypeTable, TypeNumReturn, TypeRepReturn),
          TypeRep = higher_order_type_rep(TypeRepArgs, yes(TypeRepReturn))
      ;
-        Selector = 12,
+        Selector = 13,
          read_num(ByteCode, VarNum, !Pos),
          TypeRep = type_var_rep(VarNum)
      ).
diff --git a/runtime/mercury_builtin_types.c b/runtime/mercury_builtin_types.c
index 42f0e8a..d4fdb6d 100644
--- a/runtime/mercury_builtin_types.c
+++ b/runtime/mercury_builtin_types.c
@@ -39,6 +39,7 @@
  #undef VOID

  MR_DEFINE_TYPE_CTOR_INFO(builtin, int, 0, INT);
+MR_DEFINE_TYPE_CTOR_INFO(builtin, uint, 0, UINT);
  MR_DEFINE_TYPE_CTOR_INFO(builtin, character, 0, CHAR);
  MR_DEFINE_TYPE_CTOR_INFO(builtin, string, 0, STRING);
  MR_DEFINE_TYPE_CTOR_INFO(builtin, float, 0, FLOAT);
@@ -107,6 +108,12 @@ mercury__builtin____Unify____int_0_0(MR_Integer x, MR_Integer y)
  }

  MR_bool MR_CALL
+mercury__builtin____Unify____uint_0_0(MR_Unsigned x, MR_Unsigned y)
+{
+    return x == y;
+}
+
+MR_bool MR_CALL
  mercury__builtin____Unify____string_0_0(MR_String x, MR_String y)
  {
      return strcmp(x, y) == 0;
@@ -249,6 +256,15 @@ mercury__builtin____Compare____int_0_0(
  }

  void MR_CALL
+mercury__builtin____Compare____uint_0_0(
+    MR_Comparison_Result *result, MR_Unsigned x, MR_Unsigned y)
+{
+    *result = (x > y ? MR_COMPARE_GREATER :
+          x == y ? MR_COMPARE_EQUAL :
+          MR_COMPARE_LESS);
+}
+
+void MR_CALL
  mercury__builtin____Compare____string_0_0(MR_Comparison_Result *result,
      MR_String x, MR_String y)
  {
@@ -404,6 +420,13 @@ mercury__builtin__do_unify__int_0_0(MR_Box x, MR_Box y)
  }

  MR_bool MR_CALL
+mercury__builtin__do_unify__uint_0_0(MR_Box x, MR_Box y)
+{
+    return mercury__builtin____Unify____uint_0_0(
+        (MR_Unsigned) x, (MR_Unsigned) y);
+}
+
+MR_bool MR_CALL
  mercury__builtin__do_unify__string_0_0(MR_Box x, MR_Box y)
  {
      return mercury__builtin____Unify____string_0_0(
@@ -545,6 +568,14 @@ mercury__builtin__do_compare__int_0_0(
  }

  void MR_CALL
+mercury__builtin__do_compare__uint_0_0(
+    MR_Comparison_Result *result, MR_Box x, MR_Box y)
+{
+    mercury__builtin____Compare____uint_0_0(result,
+        (MR_Unsigned) x, (MR_Unsigned) y);
+}
+
+void MR_CALL
  mercury__builtin__do_compare__string_0_0(
      MR_Comparison_Result *result, MR_Box x, MR_Box y)
  {
@@ -729,6 +760,7 @@ MR_MODULE_STATIC_OR_EXTERN MR_ModuleFunc mercury_builtin_types;
    #endif // MR_DEEP_PROFILING

  MR_UNIFY_COMPARE_REP_DECLS(builtin, int, 0)
+MR_UNIFY_COMPARE_REP_DECLS(builtin, uint, 0)
  MR_UNIFY_COMPARE_REP_DECLS(builtin, string, 0)
  MR_UNIFY_COMPARE_REP_DECLS(builtin, float, 0)
  MR_UNIFY_COMPARE_REP_DECLS(builtin, character, 0)
@@ -758,6 +790,7 @@ MR_UNIFY_COMPARE_REP_DECLS(builtin, user_by_rtti, 0);
  MR_UNIFY_COMPARE_REP_DECLS(builtin, dummy, 0);

  MR_UNIFY_COMPARE_REP_DEFNS(builtin, int, 0)
+MR_UNIFY_COMPARE_REP_DEFNS(builtin, uint, 0)
  MR_UNIFY_COMPARE_REP_DEFNS(builtin, string, 0)
  MR_UNIFY_COMPARE_REP_DEFNS(builtin, float, 0)
  MR_UNIFY_COMPARE_REP_DEFNS(builtin, character, 0)
@@ -830,6 +863,7 @@ MR_UNIFY_COMPARE_REP_DEFNS(builtin, dummy, 0)
  // mercury_sys_init_mercury_builtin_types_write_out_proc_statics() below.

  MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, int, 0);
+MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, uint, 0);
  MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, string, 0);
  MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, float, 0);
  MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, character, 0);
@@ -862,6 +896,7 @@ MR_DEFINE_PROC_STATIC_LAYOUTS(builtin, dummy, 0);

  MR_BEGIN_MODULE(mercury_builtin_types)
      MR_UNIFY_COMPARE_REP_LABELS(builtin, int, 0)
+    MR_UNIFY_COMPARE_REP_LABELS(builtin, uint, 0)
      MR_UNIFY_COMPARE_REP_LABELS(builtin, string, 0)
      MR_UNIFY_COMPARE_REP_LABELS(builtin, float, 0)
      MR_UNIFY_COMPARE_REP_LABELS(builtin, character, 0)
@@ -915,6 +950,27 @@ MR_BEGIN_CODE
  ////////////////////////////////////////////////////////////////////////////

  #define module          builtin
+#define type            uint
+#define arity           0
+#define unify_code      MR_r1 = ((MR_Unsigned) MR_r1 == (MR_Unsigned) MR_r2);
+#define compare_code    MR_r1 =                                         \
+                            ((MR_Unsigned) MR_r1 == (MR_Unsigned) MR_r2 ? \
+                                MR_COMPARE_EQUAL :                      \
+                            (MR_Unsigned) MR_r1 < (MR_Unsigned) MR_r2 ?   \
+                                MR_COMPARE_LESS :                       \
+                            MR_COMPARE_GREATER);
+
+#include "mercury_hand_unify_compare_body.h"
+
+#undef  module
+#undef  type
+#undef  arity
+#undef  unify_code
+#undef  compare_code
+
+////////////////////////////////////////////////////////////////////////////
+
+#define module          builtin
  #define type            string
  #define arity           0
  #define unify_code      MR_r1 = strcmp((char *) MR_r1, (char *) MR_r2) == 0;
@@ -1546,6 +1602,7 @@ mercury_sys_init_mercury_builtin_types_init(void)
      // library/builtin.m.)

      MR_init_entry(mercury__builtin____Unify____int_0_0);
+    MR_init_entry(mercury__builtin____Unify____uint_0_0);
      MR_init_entry(mercury__builtin____Unify____string_0_0);
      MR_init_entry(mercury__builtin____Unify____float_0_0);
      MR_init_entry(mercury__builtin____Unify____character_0_0);
@@ -1555,6 +1612,7 @@ mercury_sys_init_mercury_builtin_types_init(void)
      MR_init_entry(mercury__builtin____Unify____tuple_0_0);

      MR_init_entry(mercury__builtin____Compare____int_0_0);
+    MR_init_entry(mercury__builtin____Compare____uint_0_0);
      MR_init_entry(mercury__builtin____Compare____float_0_0);
      MR_init_entry(mercury__builtin____Compare____string_0_0);
      MR_init_entry(mercury__builtin____Compare____character_0_0);
@@ -1570,6 +1628,7 @@ mercury_sys_init_mercury_builtin_types_init(void)
  #endif  // MR_HIGHLEVEL_CODE

      MR_INIT_TYPE_CTOR_INFO_MNA(builtin, int, 0);
+    MR_INIT_TYPE_CTOR_INFO_MNA(builtin, uint, 0);
      MR_INIT_TYPE_CTOR_INFO_MNA(builtin, string, 0);
      MR_INIT_TYPE_CTOR_INFO_MNA(builtin, float, 0);
      MR_INIT_TYPE_CTOR_INFO_MNA(builtin, character, 0);
@@ -1603,6 +1662,7 @@ void
  mercury_sys_init_mercury_builtin_types_init_type_tables(void)
  {
      MR_REGISTER_TYPE_CTOR_INFO(builtin, int, 0);
+    MR_REGISTER_TYPE_CTOR_INFO(builtin, uint, 0);
      MR_REGISTER_TYPE_CTOR_INFO(builtin, string, 0);
      MR_REGISTER_TYPE_CTOR_INFO(builtin, float, 0);
      MR_REGISTER_TYPE_CTOR_INFO(builtin, character, 0);
@@ -1638,6 +1698,7 @@ mercury_sys_init_mercury_builtin_types_write_out_proc_statics(FILE *deep_fp,
      FILE *procrep_fp)
  {
      MR_WRITE_OUT_PROC_STATIC_LAYOUTS(deep_fp, builtin, int, 0);
+    MR_WRITE_OUT_PROC_STATIC_LAYOUTS(deep_fp, builtin, uint, 0);
      MR_WRITE_OUT_PROC_STATIC_LAYOUTS(deep_fp, builtin, string, 0);
      MR_WRITE_OUT_PROC_STATIC_LAYOUTS(deep_fp, builtin, float, 0);
      MR_WRITE_OUT_PROC_STATIC_LAYOUTS(deep_fp, builtin, character, 0);
diff --git a/runtime/mercury_builtin_types.h b/runtime/mercury_builtin_types.h
index 6000974..0d6e41e 100644
--- a/runtime/mercury_builtin_types.h
+++ b/runtime/mercury_builtin_types.h
@@ -24,6 +24,8 @@
  MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
      MR_TYPE_CTOR_INFO_NAME(builtin, int, 0));
  MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+    MR_TYPE_CTOR_INFO_NAME(builtin, uint, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
      MR_TYPE_CTOR_INFO_NAME(builtin, string, 0));
  MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
      MR_TYPE_CTOR_INFO_NAME(builtin, float, 0));
@@ -67,6 +69,8 @@ MR_DECLARE_TYPE_CTOR_INFO_STRUCT(

  MR_bool MR_CALL mercury__builtin____Unify____int_0_0(MR_Integer x,
                      MR_Integer y);
+MR_bool MR_CALL mercury__builtin____Unify____uint_0_0(MR_Unsigned x,
+                    MR_Unsigned y);
  MR_bool MR_CALL mercury__builtin____Unify____string_0_0(MR_String x,
                      MR_String y);
  MR_bool MR_CALL mercury__builtin____Unify____float_0_0(MR_Float x, MR_Float y);
@@ -100,6 +104,8 @@ MR_bool MR_CALL mercury__private_builtin____Unify____base_typeclass_info_0_0(

  void MR_CALL    mercury__builtin____Compare____int_0_0(
                      MR_Comparison_Result *result, MR_Integer x, MR_Integer y);
+void MR_CALL    mercury__builtin____Compare____uint_0_0(
+                    MR_Comparison_Result *result, MR_Unsigned x, MR_Unsigned y);
  void MR_CALL    mercury__builtin____Compare____string_0_0(
                      MR_Comparison_Result *result, MR_String x, MR_String y);
  void MR_CALL    mercury__builtin____Compare____float_0_0(
diff --git a/runtime/mercury_builtin_types_proc_layouts.h b/runtime/mercury_builtin_types_proc_layouts.h
index d036df0..772a164 100644
--- a/runtime/mercury_builtin_types_proc_layouts.h
+++ b/runtime/mercury_builtin_types_proc_layouts.h
@@ -37,6 +37,7 @@
  #ifdef  MR_DEEP_PROFILING

  MR_DECLARE_UCI_PROC_STATIC_LAYOUTS(builtin, int, 0);
+MR_DECLARE_UCI_PROC_STATIC_LAYOUTS(builtin, uint, 0);
  MR_DECLARE_UCI_PROC_STATIC_LAYOUTS(builtin, string, 0);
  MR_DECLARE_UCI_PROC_STATIC_LAYOUTS(builtin, float, 0);
  MR_DECLARE_UCI_PROC_STATIC_LAYOUTS(builtin, character, 0);
diff --git a/runtime/mercury_construct.c b/runtime/mercury_construct.c
index 3532b71..2c62c79 100644
--- a/runtime/mercury_construct.c
+++ b/runtime/mercury_construct.c
@@ -159,6 +159,7 @@ MR_get_functor_info(MR_TypeInfo type_info, int functor_number,
          return MR_TRUE;

      case MR_TYPECTOR_REP_INT:
+    case MR_TYPECTOR_REP_UINT:
      case MR_TYPECTOR_REP_CHAR:
      case MR_TYPECTOR_REP_FLOAT:
      case MR_TYPECTOR_REP_STRING:
@@ -315,6 +316,7 @@ MR_get_num_functors(MR_TypeInfo type_info)
                      MR_type_ctor_layout(type_ctor_info).MR_layout_equiv));

          case MR_TYPECTOR_REP_INT:
+        case MR_TYPECTOR_REP_UINT:
          case MR_TYPECTOR_REP_CHAR:
          case MR_TYPECTOR_REP_FLOAT:
          case MR_TYPECTOR_REP_STRING:
diff --git a/runtime/mercury_deconstruct.c b/runtime/mercury_deconstruct.c
index b4210de..ed36984 100644
--- a/runtime/mercury_deconstruct.c
+++ b/runtime/mercury_deconstruct.c
@@ -264,6 +264,7 @@ MR_named_arg_num(MR_TypeInfo type_info, MR_Word *term_ptr,
          case MR_TYPECTOR_REP_ENUM_USEREQ:
          case MR_TYPECTOR_REP_DUMMY:
          case MR_TYPECTOR_REP_INT:
+        case MR_TYPECTOR_REP_UINT:
          case MR_TYPECTOR_REP_FLOAT:
          case MR_TYPECTOR_REP_CHAR:
          case MR_TYPECTOR_REP_STRING:
diff --git a/runtime/mercury_deep_copy_body.h b/runtime/mercury_deep_copy_body.h
index e6d0770..df0aa33 100644
--- a/runtime/mercury_deep_copy_body.h
+++ b/runtime/mercury_deep_copy_body.h
@@ -407,6 +407,7 @@ try_again:
          goto try_again;

      case MR_TYPECTOR_REP_INT:  // fallthru
+    case MR_TYPECTOR_REP_UINT: // fallthru
      case MR_TYPECTOR_REP_CHAR:
          return data;

diff --git a/runtime/mercury_dotnet.cs.in b/runtime/mercury_dotnet.cs.in
index 9e01c28..2e3cb1a 100644
--- a/runtime/mercury_dotnet.cs.in
+++ b/runtime/mercury_dotnet.cs.in
@@ -300,45 +300,46 @@ public enum TypeCtorRep {
      MR_TYPECTOR_REP_EQUIV                   = 6,
      MR_TYPECTOR_REP_FUNC                    = 7,
      MR_TYPECTOR_REP_INT                     = 8,
-    MR_TYPECTOR_REP_CHAR                    = 9,
-    MR_TYPECTOR_REP_FLOAT                   = 10,
-    MR_TYPECTOR_REP_STRING                  = 11,
-    MR_TYPECTOR_REP_PRED                    = 12,
-    MR_TYPECTOR_REP_SUBGOAL                 = 13,
-    MR_TYPECTOR_REP_VOID                    = 14,
-    MR_TYPECTOR_REP_C_POINTER               = 15,
-    MR_TYPECTOR_REP_TYPEINFO                = 16,
-    MR_TYPECTOR_REP_TYPECLASSINFO           = 17,
-    MR_TYPECTOR_REP_ARRAY                   = 18,
-    MR_TYPECTOR_REP_SUCCIP                  = 19,
-    MR_TYPECTOR_REP_HP                      = 20,
-    MR_TYPECTOR_REP_CURFR                   = 21,
-    MR_TYPECTOR_REP_MAXFR                   = 22,
-    MR_TYPECTOR_REP_REDOFR                  = 23,
-    MR_TYPECTOR_REP_REDOIP                  = 24,
-    MR_TYPECTOR_REP_TRAIL_PTR               = 25,
-    MR_TYPECTOR_REP_TICKET                  = 26,
-    MR_TYPECTOR_REP_NOTAG_GROUND            = 27,
-    MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ     = 28,
-    MR_TYPECTOR_REP_EQUIV_GROUND            = 29,
-    MR_TYPECTOR_REP_TUPLE                   = 30,
-    MR_TYPECTOR_REP_RESERVED_ADDR           = 31,
-    MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ    = 32,
-    MR_TYPECTOR_REP_TYPECTORINFO            = 33,
-    MR_TYPECTOR_REP_BASETYPECLASSINFO       = 34,
-    MR_TYPECTOR_REP_TYPEDESC                = 35,
-    MR_TYPECTOR_REP_TYPECTORDESC            = 36,
-    MR_TYPECTOR_REP_FOREIGN                 = 37,
-    MR_TYPECTOR_REP_REFERENCE               = 38,
-    MR_TYPECTOR_REP_STABLE_C_POINTER        = 39,
-    MR_TYPECTOR_REP_STABLE_FOREIGN          = 40,
-    MR_TYPECTOR_REP_PSEUDOTYPEDESC          = 41,
-    MR_TYPECTOR_REP_DUMMY                   = 42,
-    MR_TYPECTOR_REP_BITMAP                  = 43,
-    MR_TYPECTOR_REP_FOREIGN_ENUM            = 44,
-    MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 45,
-    MR_TYPECTOR_REP_UNKNOWN                 = 46,
-    MR_TYPECTOR_REP_MAX                     = 47
+    MR_TYPECTOR_REP_UINT                    = 9,
+    MR_TYPECTOR_REP_CHAR                    = 10,
+    MR_TYPECTOR_REP_FLOAT                   = 11,
+    MR_TYPECTOR_REP_STRING                  = 12,
+    MR_TYPECTOR_REP_PRED                    = 13,
+    MR_TYPECTOR_REP_SUBGOAL                 = 14,
+    MR_TYPECTOR_REP_VOID                    = 15,
+    MR_TYPECTOR_REP_C_POINTER               = 16,
+    MR_TYPECTOR_REP_TYPEINFO                = 17,
+    MR_TYPECTOR_REP_TYPECLASSINFO           = 18,
+    MR_TYPECTOR_REP_ARRAY                   = 19,
+    MR_TYPECTOR_REP_SUCCIP                  = 20,
+    MR_TYPECTOR_REP_HP                      = 21,
+    MR_TYPECTOR_REP_CURFR                   = 22,
+    MR_TYPECTOR_REP_MAXFR                   = 23,
+    MR_TYPECTOR_REP_REDOFR                  = 24,
+    MR_TYPECTOR_REP_REDOIP                  = 25,
+    MR_TYPECTOR_REP_TRAIL_PTR               = 26,
+    MR_TYPECTOR_REP_TICKET                  = 27,
+    MR_TYPECTOR_REP_NOTAG_GROUND            = 28,
+    MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ     = 29,
+    MR_TYPECTOR_REP_EQUIV_GROUND            = 30,
+    MR_TYPECTOR_REP_TUPLE                   = 31,
+    MR_TYPECTOR_REP_RESERVED_ADDR           = 32,
+    MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ    = 33,
+    MR_TYPECTOR_REP_TYPECTORINFO            = 34,
+    MR_TYPECTOR_REP_BASETYPECLASSINFO       = 35,
+    MR_TYPECTOR_REP_TYPEDESC                = 36,
+    MR_TYPECTOR_REP_TYPECTORDESC            = 37,
+    MR_TYPECTOR_REP_FOREIGN                 = 38,
+    MR_TYPECTOR_REP_REFERENCE               = 39,
+    MR_TYPECTOR_REP_STABLE_C_POINTER        = 40,
+    MR_TYPECTOR_REP_STABLE_FOREIGN          = 41,
+    MR_TYPECTOR_REP_PSEUDOTYPEDESC          = 42,
+    MR_TYPECTOR_REP_DUMMY                   = 43,
+    MR_TYPECTOR_REP_BITMAP                  = 44,
+    MR_TYPECTOR_REP_FOREIGN_ENUM            = 45,
+    MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 46,
+    MR_TYPECTOR_REP_UNKNOWN                 = 47,
+    MR_TYPECTOR_REP_MAX                     = 48
  }

  public class PseudoTypeInfo {
diff --git a/runtime/mercury_grade.h b/runtime/mercury_grade.h
index 49ff462..28473aa 100644
--- a/runtime/mercury_grade.h
+++ b/runtime/mercury_grade.h
@@ -76,7 +76,7 @@
  // breaks binary backwards compatibility only in debugging, deep profiling
  // and low-level C parallel grades respectively.

-#define MR_GRADE_PART_0 v18_
+#define MR_GRADE_PART_0 v19_
  #define MR_GRADE_EXEC_TRACE_VERSION_NO  12
  #define MR_GRADE_DEEP_PROF_VERSION_NO   4
  #define MR_GRADE_LLC_PAR_VERSION_NO 1
diff --git a/runtime/mercury_ml_expand_body.h b/runtime/mercury_ml_expand_body.h
index 29eeb73..2eb2fd9 100644
--- a/runtime/mercury_ml_expand_body.h
+++ b/runtime/mercury_ml_expand_body.h
@@ -765,7 +765,8 @@ EXPAND_FUNCTION_NAME(MR_TypeInfo type_info, MR_Word *data_word_ptr,
                  char    *str;

                  data_word = *data_word_ptr;
-                sprintf(buf, "%ld", (long) data_word);
+                sprintf(buf, "%" MR_INTEGER_LENGTH_MODIFIER "d",
+                    (MR_Integer) data_word);
                  MR_make_aligned_string_copy_saved_hp(str, buf, NULL);
                  expand_info->EXPAND_FUNCTOR_FIELD = str;
              }
@@ -774,6 +775,21 @@ EXPAND_FUNCTION_NAME(MR_TypeInfo type_info, MR_Word *data_word_ptr,
              handle_zero_arity_args();
              return;

+        case MR_TYPECTOR_REP_UINT:
+#ifdef  EXPAND_FUNCTOR_FIELD
+            {
+                MR_Word data_word;
+                char    buf[500];
+                char    *str;
+
+                data_word = *data_word_ptr;
+                sprintf(buf, "%" MR_INTEGER_LENGTH_MODIFIER "u",
+                    (MR_Unsigned) data_word);
+                MR_make_aligned_string_copy_saved_hp(str, buf, NULL);
+                expand_info->EXPAND_FUNCTOR_FIELD = str;
+            }
+#endif  // EXPAND_FUNCTOR_FIELD
+
          case MR_TYPECTOR_REP_CHAR:
  #ifdef  EXPAND_FUNCTOR_FIELD
              {
diff --git a/runtime/mercury_table_type_body.h b/runtime/mercury_table_type_body.h
index 9123d5c..1de1e39 100644
--- a/runtime/mercury_table_type_body.h
+++ b/runtime/mercury_table_type_body.h
@@ -302,6 +302,11 @@
              table = table_next;
              return table;

+        case MR_TYPECTOR_REP_UINT:
+            MR_TABLE_UINT(STATS, DEBUG, BACK, table_next, table, data);
+            table = table_next;
+            return table;
+
          case MR_TYPECTOR_REP_CHAR:
              MR_TABLE_CHAR(STATS, DEBUG, BACK, table_next, table, data);
              table = table_next;
diff --git a/runtime/mercury_tabling.h b/runtime/mercury_tabling.h
index 1090d57..ba8a294 100644
--- a/runtime/mercury_tabling.h
+++ b/runtime/mercury_tabling.h
@@ -238,6 +238,7 @@ typedef enum {
  typedef enum {
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_DUMMY),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_INT),
+    MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_UINT),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_CHAR),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_STRING),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_FLOAT),
diff --git a/runtime/mercury_tabling_macros.h b/runtime/mercury_tabling_macros.h
index dc2f21d..f904391 100644
--- a/runtime/mercury_tabling_macros.h
+++ b/runtime/mercury_tabling_macros.h
@@ -71,6 +71,12 @@
  #define MR_RAW_TABLE_INT_STATS(stats, table, value)                         \
      MR_int_hash_lookup_or_add_stats((stats), (table), (value));

+#define MR_RAW_TABLE_UINT(table, value)                                      \
+    MR_word_hash_lookup_or_add((table), (value));
+
+#define MR_RAW_TABLE_UINT_STATS(stats, table, value)                         \
+    MR_word_hash_lookup_or_add_stats((stats), (table), (value));
+
  #define MR_RAW_TABLE_CHAR(table, value)                                     \
      MR_int_hash_lookup_or_add((table), (value));

@@ -217,6 +223,19 @@
          }                                                                   \
      } while (0)

+#define MR_TABLE_UINT(stats, debug, back, t, t0, value)                     \
+    do {                                                                    \
+        if (stats != NULL) {                                                \
+            (t) = MR_RAW_TABLE_UINT_STATS((stats), (t0), (value));          \
+        } else {                                                            \
+            (t) = MR_RAW_TABLE_UINT((t0), (value));                         \
+        }                                                                   \
+        if (MR_tabledebug) {                                                \
+            printf("TABLE %p: uint %ud => %p\n",                            \
+                (t0), (long) (value), (t));                                 \
+        }                                                                   \
+    } while (0)
+
  #define MR_TABLE_CHAR(stats, debug, back, t, t0, value)                     \
      do {                                                                    \
          if (stats != NULL) {                                                \
diff --git a/runtime/mercury_term_size.c b/runtime/mercury_term_size.c
index 9f87c76..4a87837 100644
--- a/runtime/mercury_term_size.c
+++ b/runtime/mercury_term_size.c
@@ -245,8 +245,19 @@ try_again:
          case MR_TYPECTOR_REP_INT:
  #ifdef MR_DEBUG_TERM_SIZES
              if (MR_heapdebug && MR_lld_print_enabled) {
-                printf("MR_term_size: int %p %ld\n",
-                    (void *) term, (long) term);
+                printf(
+                    "MR_term_size: int %p %" MR_INTEGER_LENGTH_MODIFIER "d\n",
+                    (void *) term, (MR_Integer) term);
+            }
+#endif
+            return 0;
+
+        case MR_TYPECTOR_REP_UINT:
+#ifdef MR_DEBUG_TERM_SIZES
+            if (MR_heapdebug && MR_lld_print_enabled) {
+                printf(
+                    "MR_term_size: uint %p %" MR_INTEGER_LENGTH_MODIFIER "u\n",
+                    (void *) term, (MR_Unsigned) term);
              }
  #endif
              return 0;
diff --git a/runtime/mercury_type_info.h b/runtime/mercury_type_info.h
index 0784b3b..9c4878a 100644
--- a/runtime/mercury_type_info.h
+++ b/runtime/mercury_type_info.h
@@ -69,7 +69,7 @@
  // This number should be kept in sync with type_ctor_info_rtti_version in
  // compiler/type_ctor_info.m.

-#define MR_RTTI_VERSION                     MR_RTTI_VERSION__FUNCTOR_SUBTYPE
+#define MR_RTTI_VERSION                     MR_RTTI_VERSION__UINT
  #define MR_RTTI_VERSION__INITIAL            2
  #define MR_RTTI_VERSION__USEREQ             3
  #define MR_RTTI_VERSION__CLEAN_LAYOUT       4
@@ -85,6 +85,7 @@
  #define MR_RTTI_VERSION__DIRECT_ARG         14
  #define MR_RTTI_VERSION__ARG_WIDTHS         15
  #define MR_RTTI_VERSION__FUNCTOR_SUBTYPE    16
+#define MR_RTTI_VERSION__UINT               17

  // Check that the RTTI version is in a sensible range.
  // The lower bound should be the lowest currently supported version number.
@@ -564,6 +565,7 @@ typedef enum {
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_EQUIV),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_FUNC),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_INT),
+    MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_UINT),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_CHAR),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_FLOAT),
      MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_STRING),
@@ -633,6 +635,7 @@ typedef MR_int_least16_t  MR_TypeCtorRepInt;
      "EQUIV",                                                            \
      "FUNC",                                                             \
      "INT",                                                              \
+    "UINT",                                                             \
      "CHAR",                                                             \
      "FLOAT",                                                            \
      "STRING",                                                           \
@@ -1409,6 +1412,9 @@ typedef void MR_CALL MR_CompareFunc_5(MR_Mercury_Type_Info,
    #define MR_INT_CTOR_ADDR                                                \
        (MR_Word *) &mercury__builtin__builtin__type_ctor_info_int_0
        // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, int, 0)
+  #define MR_UINT_CTOR_ADDR                                               \
+      (MR_Word *) &mercury__builtin__builtin__type_ctor_info_uint_0
+      // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, uint, 0)
    #define MR_FLOAT_CTOR_ADDR                                              \
        (MR_Word *) &mercury__builtin__builtin__type_ctor_info_float_0
        // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, float, 0)
@@ -1436,6 +1442,9 @@ typedef void MR_CALL MR_CompareFunc_5(MR_Mercury_Type_Info,
    #define MR_INT_CTOR_ADDR                                                \
        (MR_Word *) &mercury_data_builtin__type_ctor_info_int_0
        // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, int, 0)
+  #define MR_UINT_CTOR_ADDR                                               \
+      (MR_Word *) &mercury_data_builtin__type_ctor_info_uint_0
+      // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, uint, 0)
    #define MR_FLOAT_CTOR_ADDR                                              \
        (MR_Word *) &mercury_data_builtin__type_ctor_info_float_0
        // (MR_Word *) &MR_TYPE_CTOR_INFO_NAME(builtin, float, 0)
diff --git a/runtime/mercury_unify_compare_body.h b/runtime/mercury_unify_compare_body.h
index 8a46e14..1209e0f 100644
--- a/runtime/mercury_unify_compare_body.h
+++ b/runtime/mercury_unify_compare_body.h
@@ -630,6 +630,20 @@ start_label:
              return_unify_answer(builtin, int, 0,
                  (MR_Integer) x == (MR_Integer) y);
  #endif
+        case MR_TYPECTOR_REP_UINT:
+
+#ifdef  select_compare_code
+            if ((MR_Unsigned) x == (MR_Unsigned) y) {
+                return_compare_answer(builtin, uint, 0, MR_COMPARE_EQUAL);
+            } else if ((MR_Unsigned) x < (MR_Unsigned) y) {
+                return_compare_answer(builtin, uint, 0, MR_COMPARE_LESS);
+            } else {
+                return_compare_answer(builtin, uint, 0, MR_COMPARE_GREATER);
+            }
+#else
+            return_unify_answer(builtin, uint, 0,
+                (MR_Unsigned) x == (MR_Unsigned) y);
+#endif

          case MR_TYPECTOR_REP_DUMMY:
              // Since dummy types contain only value, all unifies succeed and


More information about the reviews mailing list