[m-rev.] for review: generalise the representation of integers in the term module

Julien Fischer jfischer at opturion.com
Thu Apr 20 01:21:05 AEST 2017


For review by anyone.

I haven't updated the NEWS file to cover these changes; I will do so
separately.

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

Generalise the representation of integers in the term module.

In preparation for supporting uint literals and literals for the fixed size
integer types, generalise the representation of integers in the term module, so
that for every integer literal we record its base, value (as an arbitrary
precision integer), signedness and size (the latter two based on the literal's
suffix or lack thereof).

Have the lexer attach information about the integer base to machine sized ints;
we already did this for the 'big_integer' alternative but not the normal one.
In conjunction with the first change, this fixes a problem where the compiler
was accepting non-decimal integers in like arity specifications.  (The
resulting error messages could be improved, but that's a separate change.)

Support uints in more places; mark other places which require further work with
XXX UINT.

library/term.m:
      Generalise the representation of integer terms so that we can store
      the base, signedness and size of a integer along with its value.
      In the new design the value is always stored as an arbitrary precision
      integer so we no longer require the big_integer/2 alternative; delete it.

      Add some utility predicates that make it easier to work with integer terms.

library/term_conversion.m:
library/term_io.m:
      Conform to the above changes,

      Add missing handling for uints in some spots; add XXX UINT comments
      in others -- these will be addressed later.

library/lexer.m:
      Record the base of word sized integer literals.

library/parser.m:
compiler/analysis_file.m:
compiler/fact_table.m:
compiler/get_dependencies.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/parse_class.m:
compiler/parse_inst_mode_name.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_sym_name.m:
compiler/parse_tree_out_term.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_defn.m:
compiler/parse_util.m:
compiler/prog_ctgc.m:
compiler/prog_util.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/superhomogeneous.m:
mdbcomp/trace_counts.m:
samples/calculator2.m:
extras/moose/moose.m:
     Conform to the above changes.

tests/hard_coded/impl_def_lex.exp:
tests/hard_coded/impl_def_lex_string.exp:
tests/hard_coded/lexer_bigint.exp*:
tests/hard_coded/lexer_zero.exp*:
tests/hard_coded/parse_number_from_string.exp*:
tests/hard_coded/term_to_unit_test.exp:
     Update these expected outputs.

Julien.

diff --git a/compiler/analysis.file.m b/compiler/analysis.file.m
index 7f26795..eb21557 100644
--- a/compiler/analysis.file.m
+++ b/compiler/analysis.file.m
@@ -372,8 +372,7 @@ parse_result_entry(Compiler, Term, !Results) :-
      then
          ( if
              VersionNumber = analysis_version_number(_ : Call, _ : Answer),
-            VersionNumberTerm = term.functor(
-                term.integer(VersionNumber), [], _)
+            term_to_decimal_int(VersionNumberTerm, VersionNumber)
          then
              Result = 'new some_analysis_result'(CallPattern, AnswerPattern,
                  Status),
@@ -425,8 +424,7 @@ parse_request_entry(Compiler, Term, !Requests) :-
      then
          ( if
              VersionNumber = analysis_version_number(_ : Call, _ : Answer),
-            VersionNumberTerm = term.functor(
-                term.integer(VersionNumber), [], _)
+            term_to_decimal_int(VersionNumberTerm, VersionNumber)
          then
              Result = 'new analysis_request'(CallPattern, CallerModule),
              ( if map.search(!.Requests, AnalysisName, AnalysisRequests0) then
@@ -474,8 +472,7 @@ parse_imdg_arc(Compiler, Term, !Arcs) :-
      then
          ( if
              VersionNumber = analysis_version_number(_ : Call, _ : Answer),
-            VersionNumberTerm = term.functor(
-                term.integer(VersionNumber), [], _)
+            term_to_decimal_int(VersionNumberTerm, VersionNumber)
          then
              Arc = 'new imdg_arc'(CallPattern, DependentModule),
              ( if map.search(!.Arcs, AnalysisName, AnalysisArcs0) then
@@ -515,8 +512,8 @@ parse_func_id(Term, FuncId) :-
          PredOrFunc = pf_function
      ),
      NameTerm = functor(atom(Name), [], _),
-    ArityTerm = functor(integer(Arity), [], _),
-    ProcTerm = functor(integer(ProcInt), [], _),
+    term_to_decimal_int(ArityTerm, Arity),
+    term_to_decimal_int(ProcTerm, ProcInt),
      proc_id_to_int(ProcId, ProcInt),
      FuncId = func_id(PredOrFunc, Name, Arity, ProcId).

@@ -598,7 +595,8 @@ read_analysis_file(AnalysisFileName, ParseEntry, ModuleResults0, ModuleResults,
  check_analysis_file_version_number(Stream, !IO) :-
      parser.read_term(Stream, TermResult : read_term, !IO),
      ( if
-        TermResult = term(_, term.functor(term.integer(version_number), [], _))
+        TermResult  = term(_, NumberTerm),
+        term_to_decimal_int(NumberTerm, version_number)
      then
          true
      else
@@ -722,8 +720,8 @@ write_module_analysis_requests(Info, Globals, ModuleName, ModuleRequests,
          parser.read_term(InputStream, VersionResult : read_term, !IO),
          io.close_input(InputStream, !IO),
          ( if
-            VersionResult = term(_, term.functor(
-                term.integer(version_number), [], _))
+            VersionResult = term(_, NumberTerm),
+            term_to_decimal_int(NumberTerm, version_number)
          then
              io.open_append(AnalysisFileName, AppendResult, !IO),
              (
diff --git a/compiler/fact_table.m b/compiler/fact_table.m
index 1c7fe16..3efbdab 100644
--- a/compiler/fact_table.m
+++ b/compiler/fact_table.m
@@ -129,6 +129,7 @@
  :- import_module cord.
  :- import_module float.
  :- import_module int.
+:- import_module integer.
  :- import_module library.
  :- import_module map.
  :- import_module maybe.
@@ -532,11 +533,14 @@ check_fact_type_and_mode(Types0, [Term | Terms], ArgNum0, PredOrFunc,
              Functor = term.string(_),
              RequiredType = yes(builtin_type_string)
          ;
-            Functor = term.integer(_),
-            RequiredType = yes(builtin_type_int)
-        ;
-            Functor = term.big_integer(_, _),
-            RequiredType = yes(builtin_type_int)
+            Functor = term.integer(_, _, Signedness, _),
+            (
+                Signedness = signed,
+                RequiredType = yes(builtin_type_int)
+            ;
+                Signedness = unsigned,
+                RequiredType = yes(builtin_type_uint)
+            )
          ;
              Functor = term.float(_),
              RequiredType = yes(builtin_type_float)
@@ -1095,16 +1099,19 @@ make_key_part(Const) = Key :-
          Const = term.atom(_),
          unexpected($module, $pred, "enumerated types are not supported yet.")
      ;
-        Const = term.integer(I),
-        % Print the integer in base 36 to reduce the amount of I/O we do.
-        Key = string.int_to_base_string(I, 36)
-    ;
-        Const = term.big_integer(Base, Integer),
-        ( if source_integer_to_int(Base, Integer, I) then
-            % As above.
-            Key = string.int_to_base_string(I, 36)
-        else
-            unexpected($module, $pred, "integer too big")
+        Const = term.integer(Base, Integer, Signedness, _Size),
+        (
+            Signedness = signed,
+            ( if source_integer_to_int(Base, Integer, I) then
+                % Print the integer in base 36 to reduce the amount of I/O we
+                % do.
+                Key = string.int_to_base_string(I, 36)
+            else
+                unexpected($module, $pred, "integer too big")
+            )
+        ;
+            Signedness = unsigned,
+            unexpected($module, $pred, "NYI uints and fact tables")
          )
      ;
          Const = term.float(F),
@@ -1345,16 +1352,18 @@ write_fact_args(OutputStream, [Arg | Args], !IO) :-
          c_util.output_quoted_string(OutputStream, String, !IO),
          io.write_string(OutputStream, """, ", !IO)
      ;
-        Arg = term.integer(Int),
-        io.write_int(OutputStream, Int, !IO),
-        io.write_string(OutputStream, ", ", !IO)
-    ;
-        Arg = term.big_integer(Base, Integer),
-        ( if source_integer_to_int(Base, Integer, Int) then
-            io.write_int(OutputStream, Int, !IO),
-            io.write_string(OutputStream, ", ", !IO)
-        else
-            unexpected($module, $pred, "integer too big")
+        Arg = term.integer(Base, Integer, Signedness, _),
+        (
+            Signedness = signed,
+            ( if source_integer_to_int(Base, Integer, Int) then
+                io.write_int(OutputStream, Int, !IO),
+                io.write_string(OutputStream, ", ", !IO)
+            else
+                unexpected($module, $pred, "integer too big")
+            )
+        ;
+            Signedness = unsigned,
+            unexpected($module, $pred, "NYI uints in fact tables")
          )
      ;
          Arg = term.float(Float),
@@ -1931,9 +1940,10 @@ get_output_args_list([Info | Infos], ArgStrings0, Args) :-
      is det.

  convert_key_string_to_arg(ArgString, Type, Arg) :-
+    % XXX UINT - handle uints here too when we support them in fact tables.
      ( if Type = builtin_type(builtin_type_int) then
          ( if string.base_string_to_int(36, ArgString, I) then
-            Arg = term.integer(I)
+            Arg = term.integer(base_10, integer(I), signed, size_word)
          else
              unexpected($module, $pred, "could not convert string to int")
          )
@@ -2089,15 +2099,22 @@ get_free_hash_slot_2(HashTable, Start, Max, Free) :-
  :- pred fact_table_hash(int::in, fact_arg::in, int::out) is det.

  fact_table_hash(HashSize, Key, HashVal) :-
-    ( if Key = term.string(String) then
+    ( if
+        Key = term.string(String)
+    then
          % XXX This method of hashing strings may not work if cross-compiling
          % between systems that have different character representations.
          string.to_char_list(String, Cs),
          list.map((pred(C::in, I::out) is det :- char.to_int(C, I)), Cs, Ns)
-    else if Key = term.integer(Int) then
+    else if
+        Key = term.integer(_, Integer, signed, size_word),
+        integer.to_int(Integer, Int)
+    then
          int.abs(Int, N),
          Ns = [N]
-    else if Key = term.float(Float) then
+    else if
+        Key = term.float(Float)
+    then
          % XXX This method of hashing floats may not work cross-compiling
          % between architectures that have different floating-point
          % representations.
@@ -2204,14 +2221,20 @@ write_hash_table_loop(Stream, HashTable, CurrIndex, MaxIndex, !IO) :-
                  c_util.output_quoted_string(Stream, String, !IO),
                  io.write_string(Stream, """", !IO)
              ;
-                Key = term.integer(Int),
-                io.write_int(Stream, Int, !IO)
+                Key = term.integer(_, Integer, Signedness, _),
+                (
+                    Signedness = signed,
+                    Int = integer.det_to_int(Integer),
+                    io.write_int(Stream, Int, !IO)
+                ;
+                    Signedness = unsigned,
+                    unexpected($pred, "NYI uints in fact tables")
+                )
              ;
                  Key = term.float(Float),
                  io.write_float(Stream, Float, !IO)
              ;
                  ( Key = term.atom(_)
-                ; Key = term.big_integer(_, _)
                  ; Key = term.implementation_defined(_)
                  ),
                  unexpected($pred, "unsupported type")
@@ -2257,7 +2280,7 @@ get_hash_table_type_2(Map, Index, TableType) :-
          Entry = hash_entry(Key, _, _),
          ( if Key = term.string(_) then
              TableType = 's'
-        else if Key = term.integer(_) then
+        else if Key = term.integer(_, _, _, _) then
              TableType = 'i'
          else if Key = term.float(_) then
              TableType = 'f'
diff --git a/compiler/get_dependencies.m b/compiler/get_dependencies.m
index 5518e4c..3ea5995 100644
--- a/compiler/get_dependencies.m
+++ b/compiler/get_dependencies.m
@@ -778,8 +778,7 @@ gather_implicit_import_needs_in_term(Term, !ImplicitImportNeeds) :-
                  true
              )
          ;
-            ( Const = integer(_)
-            ; Const = big_integer(_, _)
+            ( Const = integer(_, _, _, _)
              ; Const = string(_)
              ; Const = float(_)
              ; Const = implementation_defined(_)
diff --git a/compiler/hlds_out_goal.m b/compiler/hlds_out_goal.m
index c9cf98a..7d1b2c6 100644
--- a/compiler/hlds_out_goal.m
+++ b/compiler/hlds_out_goal.m
@@ -1393,7 +1393,7 @@ write_goal_generic_call(Info, _ModuleInfo, VarSet, _TypeQual, VarNamePrint,
          term.context_init(Context),
          Functor = term.atom("class_method_call"),
          TCInfoTerm = term.variable(TCInfoVar, Context),
-        MethodNumTerm = term.functor(term.integer(MethodNum), [], Context),
+        MethodNumTerm = decimal_int_to_term(MethodNum, Context),
          term.var_list_to_term_list(ArgVars, ArgTerms),
          Term = term.functor(Functor, [TCInfoTerm, MethodNumTerm | ArgTerms],
              Context),
diff --git a/compiler/hlds_out_util.m b/compiler/hlds_out_util.m
index 3e0140f..70e8794 100644
--- a/compiler/hlds_out_util.m
+++ b/compiler/hlds_out_util.m
@@ -226,6 +226,7 @@

  :- import_module assoc_list.
  :- import_module int.
+:- import_module integer.
  :- import_module map.
  :- import_module string.
  :- import_module term_io.
@@ -671,13 +672,12 @@ functor_cons_id_to_string(ModuleInfo, VarSet, VarNamePrint, ConsId, ArgVars)
      ;
          ConsId = int_const(Int),
          Str = functor_to_string(VarSet, VarNamePrint,
-            term.integer(Int), ArgVars)
+            term.integer(base_10, integer(Int), signed, size_word), ArgVars)
      ;
          ConsId = uint_const(UInt),
-        Str = uint_to_string(UInt)
-        % XXX UINT - need to extend term module to handle uints.
-        %Str = functor_to_string(VarSet, VarNamePrint,
-        %    term.integer(UInt), ArgVars)
+        Str = functor_to_string(VarSet, VarNamePrint,
+            term.integer(base_10, integer.from_uint(UInt), unsigned, size_word),
+            ArgVars)
      ;
          ConsId = float_const(Float),
          Str = functor_to_string(VarSet, VarNamePrint,
diff --git a/compiler/intermod.m b/compiler/intermod.m
index 1b5ca26..dc34cb3 100644
--- a/compiler/intermod.m
+++ b/compiler/intermod.m
@@ -2257,7 +2257,10 @@ strip_headvar_unifications_from_goal_list([Goal | Goals0], HeadVars,
              RHS = rhs_functor(ConsId, _, Args),
              (
                  ConsId = int_const(Int),
-                RHSTerm = term.functor(term.integer(Int), [], Context)
+                RHSTerm = decimal_int_to_term(Int, Context)
+            ;
+                ConsId  = uint_const(UInt),
+                RHSTerm = decimal_uint_to_term(UInt, Context)
              ;
                  ConsId = float_const(Float),
                  RHSTerm = term.functor(term.float(Float), [], Context)
diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m
index 69cc024..be02cfc 100644
--- a/compiler/make.module_dep_file.m
+++ b/compiler/make.module_dep_file.m
@@ -665,7 +665,7 @@ read_module_dependencies_3(Globals, SearchDirs, ModuleName, ModuleDir,
  :- pred version_number_term(term::in, module_dep_file_version::out) is semidet.

  version_number_term(Term, Version) :-
-    Term = term.functor(term.integer(Int), [], _),
+    term_to_decimal_int(Term, Int),
      version_number(Version, Int).

  :- pred string_term(term::in, string::out) is semidet.
diff --git a/compiler/parse_class.m b/compiler/parse_class.m
index 4ef9e9a..06624a0 100644
--- a/compiler/parse_class.m
+++ b/compiler/parse_class.m
@@ -886,7 +886,7 @@ term_to_instance_method(_ModuleName, VarSet, MethodTerm,
          then
              ( if
                  try_parse_sym_name_and_no_args(PredNameTerm, PredName),
-                ArityTerm = term.functor(term.integer(ArityInt), [], _),
+                term_to_decimal_int(ArityTerm, ArityInt),
                  try_parse_sym_name_and_no_args(InstanceMethodTerm,
                      InstanceMethodName)
              then
@@ -912,7 +912,7 @@ term_to_instance_method(_ModuleName, VarSet, MethodTerm,
          then
              ( if
                  try_parse_sym_name_and_no_args(FuncNameTerm, FuncName),
-                ArityTerm = term.functor(term.integer(ArityInt), [], _),
+                term_to_decimal_int(ArityTerm, ArityInt),
                  try_parse_sym_name_and_no_args(InstanceMethodTerm,
                      InstanceMethodName)
              then
diff --git a/compiler/parse_inst_mode_name.m b/compiler/parse_inst_mode_name.m
index 6d2fb13..353ba12 100644
--- a/compiler/parse_inst_mode_name.m
+++ b/compiler/parse_inst_mode_name.m
@@ -117,10 +117,7 @@ parse_mode(AllowConstrainedInstVar, VarSet, ContextPieces, Term, MaybeMode) :-
          Term = term.functor(TermFunctor, ArgTerms0, Context),
          (
              (
-                TermFunctor = term.integer(_),
-                Name = "an integer"
-            ;
-                TermFunctor = term.big_integer(_, _),
+                TermFunctor = term.integer(_, _, _, _),
                  Name = "an integer"
              ;
                  TermFunctor = term.float(_),
@@ -350,8 +347,7 @@ parse_inst(AllowConstrainedInstVar, VarSet, ContextPieces, Term, MaybeInst) :-
      ;
          Term = term.functor(Functor, ArgTerms, Context),
          (
-            ( Functor = term.integer(_)
-            ; Functor = term.big_integer(_, _)
+            ( Functor = term.integer(_, _, _, _)
              ; Functor = term.string(_)
              ; Functor = term.float(_)
              ; Functor = term.implementation_defined(_)
@@ -931,8 +927,7 @@ parse_bound_inst(AllowConstrainedInstVar, VarSet, ContextPieces, Term,
                  [simple_msg(Context, [always(Pieces)])]),
              MaybeBoundInst = error1([Spec])
          ;
-            ( Functor = term.integer(_)
-            ; Functor = term.big_integer(_, _)
+            ( Functor = term.integer(_, _, _, _)
              ; Functor = term.float(_)
              ; Functor = term.string(_)
              ),
@@ -943,10 +938,9 @@ parse_bound_inst(AllowConstrainedInstVar, VarSet, ContextPieces, Term,
                  MaybeBoundInst = ok1(BoundInst)
              ;
                  ArgTerms0 = [_ | _],
-                ( Functor = term.integer(_),        FunctorStr = "an integer"
-                ; Functor = term.big_integer(_, _), FunctorStr = "an integer"
-                ; Functor = term.float(_),          FunctorStr = "a float"
-                ; Functor = term.string(_),         FunctorStr = "a string"
+                ( Functor = term.integer(_, _, _, _), FunctorStr = "an integer"
+                ; Functor = term.float(_),            FunctorStr = "a float"
+                ; Functor = term.string(_),           FunctorStr = "a string"
                  ),
                  TermStr = describe_error_term(VarSet, Term),
                  Pieces = cord.list(ContextPieces) ++
diff --git a/compiler/parse_item.m b/compiler/parse_item.m
index e94d13a..a7b344b 100644
--- a/compiler/parse_item.m
+++ b/compiler/parse_item.m
@@ -695,8 +695,7 @@ parse_version_numbers_marker(ModuleName, Functor, ArgTerms,
          ArgTerms = [VersionNumberTerm, ModuleNameTerm, VersionNumbersTerm]
      then
          ( if
-            VersionNumberTerm =
-                term.functor(term.integer(VersionNumber), [], _),
+            term_to_decimal_int(VersionNumberTerm, VersionNumber),
              VersionNumber = version_numbers_version_number
          then
              ( if try_parse_symbol_name(ModuleNameTerm, ModuleName) then
diff --git a/compiler/parse_pragma.m b/compiler/parse_pragma.m
index bfac77e..4eb2585 100644
--- a/compiler/parse_pragma.m
+++ b/compiler/parse_pragma.m
@@ -1072,7 +1072,7 @@ parse_pragma_external_proc(ModuleName, VarSet, ErrorTerm,
  parse_symname_arity(VarSet, PredTerm, ContextPieces, MaybeSymNameArity) :-
      ( if PredTerm = term.functor(term.atom("/"), [NameTerm, ArityTerm], _) then
          parse_symbol_name(VarSet, NameTerm, MaybeSymName),
-        ( if ArityTerm = term.functor(term.integer(ArityPrime), [], _) then
+        ( if term_to_decimal_int(ArityTerm, ArityPrime) then
              MaybeArity = ok1(ArityPrime)
          else
              ArityPieces = [words("Error: in")] ++ cord.list(ContextPieces) ++
@@ -1386,8 +1386,8 @@ parse_pragma_unused_args(ModuleName, VarSet, ErrorTerm, PragmaTerms,
      ( if
          PragmaTerms = [PredOrFuncTerm, PredNameTerm, ArityTerm, ModeNumTerm,
              UnusedArgsTerm],
-        ArityTerm = term.functor(term.integer(Arity), [], _),
-        ModeNumTerm = term.functor(term.integer(ModeNum), [], _),
+        term_to_decimal_int(ArityTerm, Arity),
+        term_to_decimal_int(ModeNumTerm, ModeNum),
          parse_predicate_or_function(PredOrFuncTerm, PredOrFunc),
          try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
              PredNameTerm, PredName),
@@ -1560,7 +1560,7 @@ parse_pragma_termination_info(ModuleName, VarSet, ErrorTerm, PragmaTerms,
          ;
              ArgSizeFunctor = "finite",
              ArgSizeArgTerms = [IntTerm, UsedArgsTerm],
-            IntTerm = term.functor(term.integer(Int), [], _),
+            term_to_decimal_int(IntTerm, Int),
              convert_bool_list(VarSet, UsedArgsTerm, UsedArgs),
              MaybeArgSizeInfo = yes(finite(Int, UsedArgs))
          ),
@@ -1765,8 +1765,8 @@ parse_pragma_exceptions(ModuleName, ErrorTerm, PragmaTerms, Context, SeqNum,
          PragmaTerms = [PredOrFuncTerm, PredNameTerm, ArityTerm, ModeNumTerm,
              ThrowStatusTerm],
          parse_predicate_or_function(PredOrFuncTerm, PredOrFunc),
-        ArityTerm = term.functor(term.integer(Arity), [], _),
-        ModeNumTerm = term.functor(term.integer(ModeNum), [], _),
+        term_to_decimal_int(ArityTerm, Arity),
+        term_to_decimal_int(ModeNumTerm, ModeNum),
          try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
              PredNameTerm, PredName),
          ThrowStatusTerm = term.functor(term.atom(ThrowStatusFunctor),
@@ -1822,8 +1822,8 @@ parse_pragma_trailing_info(ModuleName, ErrorTerm, PragmaTerms,
          PragmaTerms = [PredOrFuncTerm, PredNameTerm, ArityTerm, ModeNumTerm,
              TrailingStatusTerm],
          parse_predicate_or_function(PredOrFuncTerm, PredOrFunc),
-        ArityTerm = term.functor(term.integer(Arity), [], _),
-        ModeNumTerm = term.functor(term.integer(ModeNum), [], _),
+        term_to_decimal_int(ArityTerm, Arity),
+        term_to_decimal_int(ModeNumTerm, ModeNum),
          try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
              PredNameTerm, PredName),
          TrailingStatusTerm = term.functor(term.atom(TrailingStatusFunctor),
@@ -1867,8 +1867,8 @@ parse_pragma_mm_tabling_info(ModuleName, ErrorTerm, PragmaTerms,
          PragmaTerms = [PredOrFuncTerm, PredNameTerm, ArityTerm, ModeNumTerm,
              MM_TablingStatusTerm],
          parse_predicate_or_function(PredOrFuncTerm, PredOrFunc),
-        ArityTerm = term.functor(term.integer(Arity), [], _),
-        ModeNumTerm = term.functor(term.integer(ModeNum), [], _),
+        term_to_decimal_int(ArityTerm, Arity),
+        term_to_decimal_int(ModeNumTerm, ModeNum),
          try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
              PredNameTerm, PredName),
          MM_TablingStatusTerm = term.functor(term.atom(MM_TablingStatusFunctor),
@@ -3253,8 +3253,8 @@ parse_tabling_attribute(VarSet, EvalMethod, Term, MaybeContextAttribute) :-
          )
      ;
          Functor = "size_limit",
-        Args = [Arg],
-        Arg = term.functor(term.integer(Limit), [], _),
+        Args = [LimitTerm],
+        term_to_decimal_int(LimitTerm, Limit),
          AllowsSizeLimit = eval_method_allows_size_limit(EvalMethod),
          (
              AllowsSizeLimit = yes,
@@ -3321,7 +3321,7 @@ parse_arity_or_modes(ModuleName, PredAndModesTerm0, ErrorTerm, VarSet,
          ( if
              try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
                  PredNameTerm, PredName),
-            ArityTerm = term.functor(term.integer(Arity), [], _)
+            term_to_decimal_int(ArityTerm, Arity)
          then
              MaybeArityOrModes = ok1(pred_name_arity_mpf_mmode(PredName,
                  Arity, no, no))
@@ -3421,15 +3421,10 @@ convert_bool_list(VarSet, ListTerm, Bools) :-
      convert_list("booleans", yes(VarSet), ListTerm, convert_bool,
          [words("Error: expected boolean")], ok1(Bools)).

-:- pred convert_int(term::in, int::out) is semidet.
-
-convert_int(Term, Int) :-
-    Term = term.functor(term.integer(Int), [], _).
-
  :- pred convert_int_list(varset::in, term::in, maybe1(list(int))::out) is det.

  convert_int_list(VarSet, ListTerm, Result) :-
-    convert_list("integers", yes(VarSet), ListTerm, convert_int,
+    convert_list("integers", yes(VarSet), ListTerm, term_to_decimal_int,
          [words("Error: expected integer")], Result).

      % convert_list(What, MaybeVarSet, Term, Pred, UnrecognizedPieces, Result):
@@ -3651,7 +3646,7 @@ parse_arg_size_constraint(Term, Constr) :-

  parse_lp_term(Term, LpTerm) :-
      Term = term.functor(term.atom("term"), [VarIdTerm, CoeffTerm], _),
-    VarIdTerm = term.functor(term.integer(VarId), [], _),
+    term_to_decimal_int(VarIdTerm, VarId),
      parse_rational(CoeffTerm, Coeff),
      LpTerm = arg_size_term(VarId, Coeff).

@@ -3659,8 +3654,8 @@ parse_lp_term(Term, LpTerm) :-

  parse_rational(Term, Rational) :-
      Term = term.functor(term.atom("r"), [NumerTerm, DenomTerm], _),
-    NumerTerm = term.functor(term.integer(Numer), [], _),
-    DenomTerm = term.functor(term.integer(Denom), [], _),
+    term_to_decimal_int(NumerTerm, Numer),
+    term_to_decimal_int(DenomTerm, Denom),
      Rational = rat.rat(Numer, Denom).

  %---------------------------------------------------------------------------%
diff --git a/compiler/parse_sym_name.m b/compiler/parse_sym_name.m
index 796a1dc..5156ba6 100644
--- a/compiler/parse_sym_name.m
+++ b/compiler/parse_sym_name.m
@@ -393,7 +393,7 @@ parse_symbol_name_specifier(VarSet, Term, MaybeSymNameSpecifier) :-
  parse_implicitly_qualified_symbol_name_specifier(DefaultModule, VarSet, Term,
          MaybeSymNameSpecifier) :-
      ( if Term = term.functor(term.atom("/"), [NameTerm, ArityTerm], _) then
-        ( if ArityTerm = term.functor(term.integer(Arity), [], _) then
+        ( if term_to_decimal_int(ArityTerm, Arity) then
              ( if Arity >= 0 then
                  parse_implicitly_qualified_symbol_name(DefaultModule, VarSet,
                      NameTerm, MaybeName),
diff --git a/compiler/parse_tree_out_term.m b/compiler/parse_tree_out_term.m
index 2c2fcf8..f191b56 100644
--- a/compiler/parse_tree_out_term.m
+++ b/compiler/parse_tree_out_term.m
@@ -465,8 +465,7 @@ mercury_limited_term_nq_to_string(VarSet, VarNamePrint, NextToGraphicToken,
                  ArityStr = int_to_string(list.length(Args)),
                  String = FunctorString ++ "/" ++ ArityStr
              ;
-                ( Functor = term.integer(_)
-                ; Functor = term.big_integer(_, _)
+                ( Functor = term.integer(_, _, _, _)
                  ; Functor = term.float(_)
                  ; Functor = term.string(_)
                  ; Functor = term.implementation_defined(_)
diff --git a/compiler/parse_tree_to_term.m b/compiler/parse_tree_to_term.m
index 568c9a6..b72f2d1 100644
--- a/compiler/parse_tree_to_term.m
+++ b/compiler/parse_tree_to_term.m
@@ -340,7 +340,7 @@ inst_result_contains_inst_names_to_term(Context, ContainsInstNames) = Term :-
          % Inst names can be pretty big, so we print only a count.
          % If necessary, we can later modify this code to actually print them.
          set.count(InstNameSet, NumInstNames),
-        CountTerm = term.functor(term.integer(NumInstNames), [], Context),
+        CountTerm = decimal_int_to_term(NumInstNames, Context),
          Term = term.functor(term.atom("contains_inst_names_known"),
              [CountTerm], Context)
      ).
@@ -646,12 +646,11 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
      ;
          ConsId = int_const(Int),
          term.context_init(Context),
-        Term = term.functor(term.integer(Int), [], Context)
+        Term = decimal_int_to_term(Int, Context)
      ;
-        ConsId = uint_const(_UInt),
+        ConsId = uint_const(UInt),
          term.context_init(Context),
-        % XXX UINT.
-        Term = term.functor(term.string("<<uint>>"), [], Context)
+        Term = decimal_uint_to_term(UInt, Context)
      ;
          ConsId = float_const(Float),
          term.context_init(Context),
@@ -699,7 +698,7 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
              "type_info_const arity != 0"),
          term.context_init(Context),
          FunctorName = "type_info_const",
-        Arg = term.functor(term.integer(TIConstNum), [], Context),
+        Arg = decimal_int_to_term(TIConstNum, Context),
          Term = term.functor(term.string(FunctorName), [Arg], Context)
      ;
          ConsId = typeclass_info_const(TCIConstNum),
@@ -707,7 +706,7 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
              "typeclass_info_const arity != 0"),
          term.context_init(Context),
          FunctorName = "typeclass_info_const",
-        Arg = term.functor(term.integer(TCIConstNum), [], Context),
+        Arg = decimal_int_to_term(TCIConstNum, Context),
          Term = term.functor(term.string(FunctorName), [Arg], Context)
      ;
          ConsId = ground_term_const(TCIConstNum, SubConsId),
@@ -716,7 +715,7 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
          cons_id_and_args_to_term_full(SubConsId, [], SubArg),
          term.context_init(Context),
          FunctorName = "ground_term_const",
-        NumArg = term.functor(term.integer(TCIConstNum), [], Context),
+        NumArg = decimal_int_to_term(TCIConstNum, Context),
          Term = term.functor(term.string(FunctorName), [NumArg, SubArg],
              Context)
      ;
diff --git a/compiler/parse_type_defn.m b/compiler/parse_type_defn.m
index a148530..ad13298 100644
--- a/compiler/parse_type_defn.m
+++ b/compiler/parse_type_defn.m
@@ -721,7 +721,7 @@ parse_where_type_is_abstract_enum(ModuleName, VarSet, HeadTerm, BodyTerm,
      then
          ( if
              Args = [Arg],
-            Arg = term.functor(integer(NumBits), [], _)
+            term_to_decimal_int(Arg, NumBits)
          then
              TypeDefn0 = parse_tree_abstract_type(abstract_enum_type(NumBits)),
              MaybeTypeDefn = ok1(TypeDefn0)
diff --git a/compiler/parse_type_name.m b/compiler/parse_type_name.m
index c7cd7e8..b727284 100644
--- a/compiler/parse_type_name.m
+++ b/compiler/parse_type_name.m
@@ -136,8 +136,7 @@ parse_type(AllowHOInstInfo, VarSet, ContextPieces, Term, Result) :-
      ;
          Term = term.functor(Functor, ArgTerms, FunctorContext),
          (
-            ( Functor = term.integer(_)
-            ; Functor = term.big_integer(_, _)
+            ( Functor = term.integer(_, _, _, _)
              ; Functor = term.float(_)
              ; Functor = term.string(_)
              ; Functor = term.implementation_defined(_)
diff --git a/compiler/parse_util.m b/compiler/parse_util.m
index be95335..44afbe8 100644
--- a/compiler/parse_util.m
+++ b/compiler/parse_util.m
@@ -128,7 +128,7 @@ parse_name_and_arity(ModuleName, PredAndArityTerm, SymName, Arity) :-
          [PredNameTerm, ArityTerm], _),
      try_parse_implicitly_qualified_sym_name_and_no_args(ModuleName,
          PredNameTerm, SymName),
-    ArityTerm = term.functor(term.integer(Arity), [], _).
+    term_to_decimal_int(ArityTerm, Arity).

  parse_name_and_arity_unqualified(PredAndArityTerm, SymName, Arity) :-
      parse_name_and_arity(unqualified(""), PredAndArityTerm, SymName, Arity).
diff --git a/compiler/prog_ctgc.m b/compiler/prog_ctgc.m
index 890ba36..720ecf2 100644
--- a/compiler/prog_ctgc.m
+++ b/compiler/prog_ctgc.m
@@ -201,13 +201,14 @@ parse_unit_selector(Term) = UnitSelector :-
          then
              ( if
                  try_parse_sym_name_and_no_args(ConsTerm, ConsIdName),
-                ArityTerm = term.functor(term.integer(Arity), _, _),
-                PosTerm = term.functor(term.integer(Pos), _, _)
+                term_to_decimal_int(ArityTerm, Arity),
+                term_to_decimal_int(PosTerm, Pos)
              then
                  ConsId = cons(ConsIdName, Arity, cons_id_dummy_type_ctor),
                  UnitSelector = termsel(ConsId, Pos)
              else if
-                ConsTerm = term.functor(term.integer(Int), _, _)
+                % XXX UINT, presuambly we need to handle uints here too.
+                term_to_decimal_int(ConsTerm, Int)
              then
                  ConsId = int_const(Int),
                  UnitSelector = termsel(ConsId, 0)
diff --git a/compiler/prog_util.m b/compiler/prog_util.m
index 2ee3335..28cd580 100644
--- a/compiler/prog_util.m
+++ b/compiler/prog_util.m
@@ -627,7 +627,10 @@ list_to_string_2(Pred, [T | Ts], !Strings) :-

  cons_id_and_args_to_term(int_const(Int), [], Term) :-
      term.context_init(Context),
-    Term = term.functor(term.integer(Int), [], Context).
+    Term = decimal_int_to_term(Int, Context).
+cons_id_and_args_to_term(uint_const(UInt), [], Term) :-
+    term.context_init(Context),
+    Term = decimal_uint_to_term(UInt, Context).
  cons_id_and_args_to_term(float_const(Float), [], Term) :-
      term.context_init(Context),
      Term = term.functor(term.float(Float), [], Context).
@@ -705,12 +708,16 @@ make_functor_cons_id(Functor, Arity, ConsId) :-
          Functor = term.atom(Name),
          ConsId = cons(unqualified(Name), Arity, cons_id_dummy_type_ctor)
      ;
-        Functor = term.integer(Int),
-        ConsId = int_const(Int)
-    ;
-        Functor = term.big_integer(Base, Integer),
-        source_integer_to_int(Base, Integer, Int),
-        ConsId = int_const(Int)
+        Functor = term.integer(Base, Integer, Signedness, size_word),
+        (
+            Signedness = signed,
+            source_integer_to_int(Base, Integer, Int),
+            ConsId = int_const(Int)
+        ;
+            Signedness = unsigned,
+            integer.to_uint(Integer, UInt),
+            ConsId = uint_const(UInt)
+        )
      ;
          Functor = term.string(String),
          ConsId = string_const(String)
diff --git a/compiler/recompilation.check.m b/compiler/recompilation.check.m
index d6d387d..dab4ed2 100644
--- a/compiler/recompilation.check.m
+++ b/compiler/recompilation.check.m
@@ -242,10 +242,10 @@ should_recompile_3(VersionStream, Globals, IsSubModule, FindTargetFiles,
          VersionNumberTerm = term.functor(term.atom(","),
              [UsageFileVersionNumberTerm,
              VersionNumbersVersionNumberTerm], _),
-        UsageFileVersionNumberTerm =
-            term.functor(term.integer(usage_file_version_number), _, _),
-        VersionNumbersVersionNumberTerm =
-            term.functor(term.integer(version_numbers_version_number), _, _)
+        term_to_decimal_int(UsageFileVersionNumberTerm,
+            usage_file_version_number),
+        term_to_decimal_int(VersionNumbersVersionNumberTerm,
+            version_numbers_version_number)
      then
          true
      else
@@ -561,7 +561,7 @@ parse_resolved_functor(Info, Term, Ctor) :-
          ; PredOrFuncStr = "function", PredOrFunc = pf_function
          ),
          try_parse_sym_name_and_no_args(ModuleTerm, ModuleName),
-        ArityTerm = term.functor(term.integer(Arity), [], _)
+        term_to_decimal_int(ArityTerm, Arity)
      then
          PredId = invalid_pred_id,
          Ctor = resolved_functor_pred_or_func(PredId, ModuleName, PredOrFunc,
@@ -619,7 +619,7 @@ parse_resolved_item_arity_matches(Info, ParseMatches, Term,
          Arity - MatchMap) :-
      ( if
          Term = term.functor(term.atom("-"), [ArityTerm, MatchesTerm], _),
-        ArityTerm = term.functor(term.integer(Arity0), [], _),
+        term_to_decimal_int(ArityTerm, Arity0),
          conjunction_to_list(MatchesTerm, MatchTermList)
      then
          Arity = Arity0,
diff --git a/compiler/recompilation.version.m b/compiler/recompilation.version.m
index 73a00c9..46fc4aa 100644
--- a/compiler/recompilation.version.m
+++ b/compiler/recompilation.version.m
@@ -1415,7 +1415,7 @@ parse_key_version_number(ParseName, Term, Result) :-
          ItemNameArityTerm = term.functor(term.atom("/"),
              [NameTerm, ArityTerm], _),
          ParseName(NameTerm, Name),
-        ArityTerm = term.functor(term.integer(Arity), _, _),
+        term_to_decimal_int(ArityTerm, Arity),
          VersionNumber = term_to_version_number(VersionNumberTerm)
      then
          Result = ok1((Name - Arity) - VersionNumber)
@@ -1437,7 +1437,7 @@ parse_item_version_number(ParseName, Term, Result) :-
          ItemNameArityTerm = term.functor(term.atom("/"),
              [NameTerm, ArityTerm], _),
          ParseName(NameTerm, SymName),
-        ArityTerm = term.functor(term.integer(Arity), _, _),
+        term_to_decimal_int(ArityTerm, Arity),
          VersionNumber = term_to_version_number(VersionNumberTerm)
      then
          Result = ok1(item_name(SymName, Arity) - VersionNumber)
diff --git a/compiler/superhomogeneous.m b/compiler/superhomogeneous.m
index dc3579c..ccff047 100644
--- a/compiler/superhomogeneous.m
+++ b/compiler/superhomogeneous.m
@@ -734,24 +734,41 @@ parse_ordinary_cons_id(Functor, ArgTerms, Context, ConsId, !Specs) :-
          list.length(ArgTerms, Arity),
          ConsId = cons(unqualified(Name), Arity, cons_id_dummy_type_ctor)
      ;
-        Functor = term.integer(Int),
-        ConsId = int_const(Int)
-    ;
-        Functor = term.big_integer(Base, Integer),
-        ( if source_integer_to_int(Base, Integer, Int) then
-            ConsId = int_const(Int)
-        else
-            BasePrefix = integer_base_prefix(Base),
-            IntString =
-                integer.to_base_string(Integer, integer_base_int(Base)),
-            Pieces = [words("Error: the integer literal"),
-                quote(BasePrefix ++ IntString),
-                words("is too big to be represented on this machine."), nl],
-            Msg = simple_msg(Context, [always(Pieces)]),
-            Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
-            !:Specs = [Spec | !.Specs],
-            % This is a dummy.
-            ConsId = int_const(0)
+        Functor = term.integer(Base, Integer, Signedness, size_word),
+        (
+            Signedness = signed,
+            ( if source_integer_to_int(Base, Integer, Int) then
+                ConsId = int_const(Int)
+            else
+                BasePrefix = integer_base_prefix(Base),
+                IntString =
+                    integer.to_base_string(Integer, integer_base_int(Base)),
+                Pieces = [words("Error: the integer literal"),
+                    quote(BasePrefix ++ IntString),
+                    words("is too big to be represented on this machine."), nl],
+                Msg = simple_msg(Context, [always(Pieces)]),
+                Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
+                !:Specs = [Spec | !.Specs],
+                % This is a dummy.
+                ConsId = int_const(0)
+            )
+        ;
+            Signedness = unsigned,
+            ( if integer.to_uint(Integer, UInt) then
+                ConsId = uint_const(UInt)
+            else
+                BasePrefix = integer_base_prefix(Base),
+                IntString =
+                    integer.to_base_string(Integer, integer_base_int(Base)),
+                Pieces = [words("Error: the unsigned integer literal"),
+                    quote(BasePrefix ++ IntString ++ "u"),
+                    words("is too big to be represented on this machine."), nl],
+                Msg = simple_msg(Context, [always(Pieces)]),
+                Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
+                !:Specs = [Spec | !.Specs],
+                % This is a dummy.
+                ConsId = int_const(0)
+            )
          )
      ;
          Functor = term.string(String),
diff --git a/extras/moose/moose.m b/extras/moose/moose.m
index e9d2b37..cfe10fc 100644
--- a/extras/moose/moose.m
+++ b/extras/moose/moose.m
@@ -36,6 +36,7 @@
  :- import_module bool.
  :- import_module getopt.
  :- import_module int.
+:- import_module integer.
  :- import_module list.
  :- import_module map.
  :- import_module pair.
@@ -414,7 +415,7 @@ interface_term(functor(atom(":-"), [functor(atom("interface"), [], _)], _)).

  :- pred implementation_term(term::in) is semidet.

-implementation_term(functor(atom(":-"), 
+implementation_term(functor(atom(":-"),
      [functor(atom("implementation"), [], _)], _)).

  :- pred rule_term(term, varset, rule_decl).
@@ -431,16 +432,17 @@ rule_term(functor(atom(":-"), [functor(atom("rule"), [RuleTerm], _)], _),

  parser_term(functor(atom(":-"), [functor(atom("parse"), Args, _)], _),
          _VarSet, WhereAmI, Decl) :-
-    Args = [StartIdTerm, TokTerm, EndTerm, PrefixTerm, InAtomTerm, 
+    Args = [StartIdTerm, TokTerm, EndTerm, PrefixTerm, InAtomTerm,
          OutAtomTerm],
      StartIdTerm = functor(atom("/"), [functor(atom(Name), [], _),
-        functor(integer(Arity), _, _)], _),
+        functor(integer(base_10, ArityInteger, signed, size_word), _, _)], _),
+    integer.to_int(ArityInteger, Arity),
      StartId = Name / Arity,
      TokTerm = functor(atom(TokAtom), [], _),
      PrefixTerm = functor(atom(PrefixAtom), [], _),
      InAtomTerm = functor(atom(InAtom), [], _),
      OutAtomTerm = functor(atom(OutAtom), [], _),
-    Decl = parser(WhereAmI, StartId, EndTerm, TokAtom, PrefixAtom, InAtom, 
+    Decl = parser(WhereAmI, StartId, EndTerm, TokAtom, PrefixAtom, InAtom,
          OutAtom).

  :- pred xform_term(term, xform).
@@ -451,11 +453,12 @@ xform_term(Term, XForm) :-
          functor(atom("action"), [
              functor(atom("/"), [
                  functor(atom(Name), [], _),
-                functor(integer(Arity), _, _)
+                functor(integer(base_10, ArityInteger, signed, size_word), _, _)
              ], _),
              functor(atom(Pred), [], _)
          ], _)
      ], _),
+    integer.to_int(ArityInteger, Arity),
      XForm = xform(Name/Arity, Pred).

  %------------------------------------------------------------------------------%
@@ -525,12 +528,12 @@ write_state_actions(SS, End, StateActions, !IO) :-
          Term = functor(atom(Name),
              [Token,
              functor(atom(Kind), [], Ctxt),
-            functor(integer(Val), [], Ctxt)], Ctxt),
+            decimal_int_to_term(Val, Ctxt)], Ctxt),
          (
              Action = shift(Val),
              Kind = "shift"
          ;
-            Action = reduce(Val), 
+            Action = reduce(Val),
              Kind = "reduce"
          ;
              Action = accept,
@@ -617,7 +620,7 @@ write_state_gotos(SS, StateActions, !IO) :-
          nonterminal_to_term(NT, Token),
          term.context_init(Ctxt),
          Term = functor(atom(Name),
-            [Token, functor(integer(NS), [], Ctxt)], Ctxt),
+            [Token, decimal_int_to_term(NS, Ctxt)], Ctxt),
          varset.init(Varset),
          term_io.write_term_nl(Varset, Term, !IO)
      ), StateActions, !IO),
diff --git a/library/lexer.m b/library/lexer.m
index 1cb2427..822f2de 100644
--- a/library/lexer.m
+++ b/library/lexer.m
@@ -30,7 +30,7 @@
  :- type token
      --->    name(string)
      ;       variable(string)
-    ;       integer(int)
+    ;       integer(integer_base, int)

      ;       big_integer(integer_base, integer)
              % An integer that is too big for `int'.
@@ -195,12 +195,12 @@ get_token_list_2(Stream, Token0, Context0, Tokens, !IO) :-
          get_context(Stream, Context1, !IO),
          get_dot(Stream, Token1, !IO),
          get_token_list_2(Stream, Token1, Context1, Tokens1, !IO),
-        Tokens = token_cons(integer(Int), Context0, Tokens1)
+        Tokens = token_cons(integer(base_10, Int), Context0, Tokens1)
      ;
          ( Token0 = float(_)
          ; Token0 = string(_)
          ; Token0 = variable(_)
-        ; Token0 = integer(_)
+        ; Token0 = integer(_, _)
          ; Token0 = big_integer(_, _)
          ; Token0 = implementation_defined(_)
          ; Token0 = junk(_)
@@ -235,7 +235,7 @@ string_get_token_list_max(String, Len, Tokens, !Posn) :-
          ( Token = float(_)
          ; Token = string(_)
          ; Token = variable(_)
-        ; Token = integer(_)
+        ; Token = integer(_, _)
          ; Token = big_integer(_, _)
          ; Token = integer_dot(_)
          ; Token = implementation_defined(_)
@@ -1955,7 +1955,7 @@ get_zero(Stream, Token, !IO) :-
          Token = io_error(Error)
      ;
          Result = eof,
-        Token = integer(0)
+        Token = integer(base_10, 0)
      ;
          Result = ok,
          ( if char.is_digit(Char) then
@@ -1979,7 +1979,7 @@ get_zero(Stream, Token, !IO) :-
              get_float_exponent(Stream, [Char, '0'], Token, !IO)
          else
              io.putback_char(Stream, Char, !IO),
-            Token = integer(0)
+            Token = integer(base_10, 0)
          )
      ).

@@ -2026,11 +2026,11 @@ string_get_zero(String, Len, Posn0, Token, Context, !Posn) :-
          else
              string_ungetchar(String, !Posn),
              string_get_context(Posn0, Context, !Posn),
-            Token = integer(0)
+            Token = integer(base_10, 0)
          )
      else
          string_get_context(Posn0, Context, !Posn),
-        Token = integer(0)
+        Token = integer(base_10, 0)
      ).

  :- pred get_char_code(io.input_stream::in, token::out, io::di, io::uo) is det.
@@ -2046,7 +2046,7 @@ get_char_code(Stream, Token, !IO) :-
      ;
          Result = ok,
          char.to_int(Char, CharCode),
-        Token = integer(CharCode)
+        Token = integer(base_10, CharCode)
      ).

  :- pred string_get_char_code(string::in, int::in, posn::in, token::out,
@@ -2055,7 +2055,7 @@ get_char_code(Stream, Token, !IO) :-
  string_get_char_code(String, Len, Posn0, Token, Context, !Posn) :-
      ( if string_read_char(String, Len, Char, !Posn) then
          char.to_int(Char, CharCode),
-        Token = integer(CharCode),
+        Token = integer(base_10, CharCode),
          string_get_context(Posn0, Context, !Posn)
      else
          Token = error("unterminated char code literal"),
@@ -2574,7 +2574,7 @@ get_int_dot(Stream, !.LastDigit, !.RevChars, Token, !IO) :-
              (
                  !.LastDigit = last_digit_is_not_underscore,
                  rev_char_list_to_int(!.RevChars, base_10, Token0),
-                ( if Token0 = integer(Int) then
+                ( if Token0 = integer(_, Int) then
                      Token = integer_dot(Int)
                  else
                      Token = Token0
@@ -2911,7 +2911,7 @@ rev_char_list_to_int(RevChars, Base, Token) :-
  conv_string_to_int(String, Base, Token) :-
      BaseInt = integer_base_int(Base),
      ( if string.base_string_to_int_underscore(BaseInt, String, Int) then
-        Token = integer(Int)
+        Token = integer(Base, Int)
      else if integer.from_base_string_underscore(BaseInt, String, Integer) then
          Token = big_integer(Base, Integer)
      else
@@ -2963,28 +2963,13 @@ token_to_string(Token, String) :-
          Token = variable(Var),
          string.append_list(["variable `", Var, "'"], String)
      ;
-        Token = integer(Int),
-        string.int_to_string(Int, IntString),
-        string.append_list(["integer `", IntString, "'"], String)
+        Token = integer(Base, Int),
+        base_to_int_and_prefix(Base, BaseInt, Prefix),
+        string.int_to_base_string(Int, BaseInt, IntString),
+        string.append_list(["integer `", Prefix, IntString, "'"], String)
      ;
          Token = big_integer(Base, Integer),
-        (
-            Base = base_2,
-            BaseInt = 2,
-            Prefix = "0b"
-        ;
-            Base = base_8,
-            BaseInt = 8,
-            Prefix = "0o"
-        ;
-            Base = base_10,
-            BaseInt = 10,
-            Prefix = ""
-        ;
-            Base = base_16,
-            BaseInt = 16,
-            Prefix = "0x"
-        ),
+        base_to_int_and_prefix(Base, BaseInt, Prefix),
          IntString = integer.to_base_string(Integer, BaseInt),
          string.append_list(["integer `", Prefix, IntString, "'"], String)
      ;
@@ -3048,4 +3033,13 @@ token_to_string(Token, String) :-
          string.append_list(["integer `", IntString, "'."], String)
      ).

+:- pred base_to_int_and_prefix(integer_base::in, int::out, string::out)
+    is det.
+
+base_to_int_and_prefix(base_2, 2, "0b").
+base_to_int_and_prefix(base_8, 8, "0o").
+base_to_int_and_prefix(base_10, 10, "").
+base_to_int_and_prefix(base_16, 16, "0x").
+
+
  %---------------------------------------------------------------------------%
diff --git a/library/parser.m b/library/parser.m
index 9aca40d..dbfb3f5 100644
--- a/library/parser.m
+++ b/library/parser.m
@@ -310,7 +310,7 @@ check_for_bad_token(token_cons(Token, LineNum0, Tokens), Message, LineNum) :-
      ;
          ( Token = name(_)
          ; Token = variable(_)
-        ; Token = integer(_)
+        ; Token = integer(_, _)
          ; Token = big_integer(_, _)
          ; Token = float(_)
          ; Token = string(_)
@@ -423,14 +423,16 @@ parse_left_term(MaxPriority, TermKind, OpPriority, Term, !TokensLeft, !PS) :-
              !.TokensLeft =
                  token_cons(NextToken, _NextContext, !:TokensLeft),
              (
-                NextToken = integer(X),
-                NegX = 0 - X,
-                NewFunctor = integer(NegX)
+                NextToken = integer(LexerBase, X),
+                NegX = integer(0 - X),
+                Base = lexer_base_to_term_base(LexerBase),
+                NewFunctor = integer(Base, NegX, signed, size_word)
              ;
-                NextToken = big_integer(_, X),
+                NextToken = big_integer(LexerBase, X),
                  -X = integer(min_int),
-                NegX = int.min_int,
-                NewFunctor = integer(NegX)
+                NegX = integer(int.min_int),
+                Base = lexer_base_to_term_base(LexerBase),
+                NewFunctor = integer(Base, NegX, signed, size_word)
              ;
                  NextToken = float(F),
                  NegF = 0.0 - F,
@@ -734,12 +736,14 @@ parse_simple_term(Token, Context, Prec, TermParse, !TokensLeft, !PS) :-
          BaseTerm = term.variable(Var, TermContext),
          BaseTermParse = ok(BaseTerm)
      ;
-        Token = integer(Int),
+        Token = integer(LexerBase, Int),
          parser_get_term_context(!.PS, Context, TermContext),
-        BaseTerm = functor(integer(Int), [], TermContext),
+        Base = lexer_base_to_term_base(LexerBase),
+        BaseTerm = functor(integer(Base, integer(Int), signed, size_word), [],
+            TermContext),
          BaseTermParse = ok(BaseTerm)
      ;
-        Token = big_integer(LexerBase, String),
+        Token = big_integer(LexerBase, Integer),
          parser_get_term_context(!.PS, Context, TermContext),
          (
              LexerBase = base_2,
@@ -754,7 +758,8 @@ parse_simple_term(Token, Context, Prec, TermParse, !TokensLeft, !PS) :-
              LexerBase = base_16,
              TermBase = base_16
          ),
-        BaseTerm = functor(big_integer(TermBase, String), [], TermContext),
+        BaseTerm = functor(integer(TermBase, Integer, signed, size_word), [],
+            TermContext),
          BaseTermParse = ok(BaseTerm)
      ;
          Token = float(Float),
@@ -1126,7 +1131,7 @@ parser_get_term_context(ParserState, TokenContext, TermContext) :-

  could_start_term(name(_), yes).
  could_start_term(variable(_), yes).
-could_start_term(integer(_), yes).
+could_start_term(integer(_, _), yes).
  could_start_term(big_integer(_, _), yes).
  could_start_term(float(_), yes).
  could_start_term(string(_), yes).
@@ -1148,6 +1153,15 @@ could_start_term(eof, no).
  could_start_term(integer_dot(_), no).

  %---------------------------------------------------------------------------%
+
+:- func lexer_base_to_term_base(lexer.integer_base) = term.integer_base.
+
+lexer_base_to_term_base(base_2) = base_2.
+lexer_base_to_term_base(base_8) = base_8.
+lexer_base_to_term_base(base_10) = base_10.
+lexer_base_to_term_base(base_16) = base_16.
+
+%---------------------------------------------------------------------------%
  %---------------------------------------------------------------------------%
  %
  % The representation of the parser state apart from the remaining token list.
diff --git a/library/term.m b/library/term.m
index feab9cf..fa1b6e3 100644
--- a/library/term.m
+++ b/library/term.m
@@ -55,9 +55,12 @@

  :- type const
      --->    atom(string)
-    ;       integer(int)
-    ;       big_integer(integer_base, integer)
-            % An integer that is too big for `int'.
+    ;       integer(
+                integer_base       :: integer_base,
+                integer_value      :: integer,
+                integer_signedness :: signedness,
+                integer_size       :: integer_size
+            )
      ;       string(string)
      ;       float(float)
      ;       implementation_defined(string).
@@ -68,6 +71,17 @@
      ;       base_10
      ;       base_16.

+:- type signedness
+    --->    signed
+    ;       unsigned.
+
+:- type integer_size
+    --->    size_word.
+    %;       size_8_bit
+    %;       size_16_bit
+    %;       size_32_bit
+    %;       size_64_bit
+
  :- type generic
      --->    generic.

@@ -132,6 +146,18 @@
  :- type substitution    == substitution(generic).

  %---------------------------------------------------------------------------%
+
+:- pred term_to_int(term(T)::in, int::out) is semidet.
+
+:- pred term_to_uint(term(T)::in, uint::out) is semidet.
+
+:- pred term_to_decimal_int(term(T)::in, int::out) is semidet.
+
+:- func decimal_int_to_term(int, context) = term(T).
+
+:- func decimal_uint_to_term(uint, context) = term(T).
+
+%---------------------------------------------------------------------------%
  %
  % Predicates to unify terms.
  %
@@ -762,6 +788,31 @@ var_id(var(VarNum)) = VarNum.

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

+term_to_int(Term, Int) :-
+    Term = functor(Const, [], _),
+    Const = integer(_, Integer, signed, size_word),
+    integer.to_int(Integer, Int).
+
+term_to_uint(Term, UInt) :-
+    Term = functor(Const, [], _),
+    Const = integer(_, Integer, unsigned, size_word),
+    integer.to_uint(Integer, UInt).
+
+term_to_decimal_int(Term, Int) :-
+    Term = functor(Const, [], _),
+    Const = integer(base_10, Integer, signed, size_word),
+    integer.to_int(Integer, Int).
+
+decimal_int_to_term(Int, Context) = Term :-
+    Const = integer(base_10, integer(Int), signed, size_word),
+    Term = functor(Const, [], Context).
+
+decimal_uint_to_term(UInt, Context) = Term :-
+    Const = integer(base_10, integer.from_uint(UInt), unsigned, size_word),
+    Term = functor(Const, [], Context).
+
+%---------------------------------------------------------------------------%
+
  unify_term(TermX, TermY, !Subst) :-
      (
          TermX = variable(X, _),
diff --git a/library/term_conversion.m b/library/term_conversion.m
index 9464c69..7082d17 100644
--- a/library/term_conversion.m
+++ b/library/term_conversion.m
@@ -112,6 +112,7 @@
  :- import_module construct.
  :- import_module deconstruct.
  :- import_module int.
+:- import_module integer.
  :- import_module require.
  :- import_module string.
  :- import_module version_array.
@@ -209,9 +210,15 @@ term_to_univ_special_case(ModuleName, TypeCtorName, TypeArgs, Term,
              type_to_univ(String, Univ)
          ;
              TypeCtorName = "int",
-            Functor = integer(Int),
+            Functor = integer(_, Integer, signed, size_word),
+            integer.to_int(Integer, Int),
              type_to_univ(Int, Univ)
          ;
+            TypeCtorName = "uint",
+            Functor = integer(_, Integer, unsigned, size_word),
+            integer.to_uint(Integer, UInt),
+            type_to_univ(UInt, Univ)
+        ;
              TypeCtorName = "float",
              Functor = float(Float),
              type_to_univ(Float, Univ)
@@ -286,9 +293,13 @@ term_to_univ_special_case(ModuleName, TypeCtorName, TypeArgs, Term,
          ArgTerm = functor(atom(":"), [ValueTerm, TypeTerm], _),
          (
              TypeTerm = functor(atom("int"), [], _),
-            ValueTerm = functor(integer(Int), [], _),
+            term_to_int(ValueTerm, Int),
              Univ = univ(Int)
          ;
+            TypeTerm = functor(atom("uint"), [], _),
+            term_to_uint(ValueTerm, UInt),
+            Univ = univ(UInt)
+        ;
              TypeTerm = functor(atom("string"), [], _),
              ValueTerm = functor(string(String), [], _),
              Univ = univ(String)
@@ -398,7 +409,12 @@ univ_to_term_special_case(ModuleName, TypeCtorName, TypeArgs, Univ, Context,
          ;
              TypeCtorName = "int",
              det_univ_to_type(Univ, Int),
-            Functor = integer(Int)
+            Functor = integer(base_10, integer(Int), signed, size_word)
+        ;
+            TypeCtorName = "uint",
+            det_univ_to_type(Univ, UInt),
+            Functor = integer(base_10, integer.from_uint(UInt), unsigned,
+                size_word)
          ;
              TypeCtorName = "float",
              det_univ_to_type(Univ, Float),
diff --git a/library/term_io.m b/library/term_io.m
index 8139f74..226641e 100644
--- a/library/term_io.m
+++ b/library/term_io.m
@@ -565,7 +565,7 @@ write_list_tail(OutStream, Ops, Term, !VarSet, !N, !IO) :-
      %
  :- pred starts_with_digit(term(T)::in) is semidet.

-starts_with_digit(functor(integer(_), _, _)).
+starts_with_digit(functor(integer(_, _, _, _), _, _)).
  starts_with_digit(functor(float(_), _, _)).
  starts_with_digit(functor(atom(Op), Args, _)) :-
      (
@@ -606,10 +606,8 @@ write_constant(OutStream, Const, !IO) :-

  write_constant(OutStream, Const, NextToGraphicToken, !IO) :-
      (
-        Const = term.integer(I),
-        io.write_int(OutStream, I, !IO)
-    ;
-        Const = term.big_integer(Base, I),
+        Const = term.integer(Base, I, _Signedness, _Size),
+        % XXX UINT hand signedness and size.
          Prefix = integer_base_prefix(Base),
          IntString = integer.to_base_string(I, integer_base_int(Base)),
          io.write_string(OutStream, Prefix, !IO),
@@ -634,9 +632,8 @@ format_constant(Const) =

  :- func term_io.format_constant_agt(const, adjacent_to_graphic_token) = string.

-format_constant_agt(term.integer(I), _) =
-    string.int_to_string(I).
-format_constant_agt(term.big_integer(Base, I), _) =
+    % XXX UINT handle Signedness and Size.
+format_constant_agt(term.integer(Base, I, _Signedness, _Size), _) =
      integer_base_prefix(Base) ++ to_base_string(I, integer_base_int(Base)).
  format_constant_agt(term.float(F), _) =
      string.float_to_string(F).
diff --git a/mdbcomp/trace_counts.m b/mdbcomp/trace_counts.m
index 7c6f45e..0dbddbd 100644
--- a/mdbcomp/trace_counts.m
+++ b/mdbcomp/trace_counts.m
@@ -547,8 +547,8 @@ read_proc_trace_counts(HeaderLineNumber, HeaderLine, CurModuleNameSym,
                  TokenName = "pproc",
                  TokenListRest =
                      token_cons(name(Name), _,
-                    token_cons(integer(Arity), _,
-                    token_cons(integer(Mode), _,
+                    token_cons(integer(base_10, Arity), _,
+                    token_cons(integer(base_10, Mode), _,
                      token_nil))),
                  ProcLabel = ordinary_proc_label(CurModuleNameSym, pf_predicate,
                      CurModuleNameSym, Name, Arity, Mode)
@@ -556,8 +556,8 @@ read_proc_trace_counts(HeaderLineNumber, HeaderLine, CurModuleNameSym,
                  TokenName = "fproc",
                  TokenListRest =
                      token_cons(name(Name), _,
-                    token_cons(integer(Arity), _,
-                    token_cons(integer(Mode), _,
+                    token_cons(integer(base_10, Arity), _,
+                    token_cons(integer(base_10, Mode), _,
                      token_nil))),
                  ProcLabel = ordinary_proc_label(CurModuleNameSym, pf_function,
                      CurModuleNameSym, Name, Arity, Mode)
@@ -566,8 +566,8 @@ read_proc_trace_counts(HeaderLineNumber, HeaderLine, CurModuleNameSym,
                  TokenListRest =
                      token_cons(name(DeclModuleName), _,
                      token_cons(name(Name), _,
-                    token_cons(integer(Arity), _,
-                    token_cons(integer(Mode), _,
+                    token_cons(integer(base_10, Arity), _,
+                    token_cons(integer(base_10, Mode), _,
                      token_nil)))),
                  DeclModuleNameSym = string_to_sym_name(DeclModuleName),
                  ProcLabel = ordinary_proc_label(CurModuleNameSym, pf_predicate,
@@ -577,8 +577,8 @@ read_proc_trace_counts(HeaderLineNumber, HeaderLine, CurModuleNameSym,
                  TokenListRest =
                      token_cons(name(DeclModuleName), _,
                      token_cons(name(Name), _,
-                    token_cons(integer(Arity), _,
-                    token_cons(integer(Mode), _,
+                    token_cons(integer(base_10, Arity), _,
+                    token_cons(integer(base_10, Mode), _,
                      token_nil)))),
                  DeclModuleNameSym = string_to_sym_name(DeclModuleName),
                  ProcLabel = ordinary_proc_label(CurModuleNameSym, pf_function,
diff --git a/samples/calculator2.m b/samples/calculator2.m
index 8e2360b..a810904 100644
--- a/samples/calculator2.m
+++ b/samples/calculator2.m
@@ -129,8 +129,7 @@ report_eval_error(unexpected_const(Const), !IO) :-
          io.write_string(String, !IO),
          io.write_string("""", !IO)
      ;
-        ( Const = term.integer(_)
-        ; Const = term.big_integer(_, _)
+        ( Const = term.integer(_, _, _, _)
          ; Const = term.atom(_)
          ; Const = term.implementation_defined(_)
          ),
@@ -163,9 +162,14 @@ eval_expr(CalcInfo, VarSet, term.functor(term.atom(Op), Args, _)) = Res :-
      else
          throw(unknown_operator(Op, list.length(Args)))
      ).
-eval_expr(_, _, term.functor(term.integer(Int), _, _)) = Int.
-eval_expr(_, _, term.functor(term.big_integer(Base, BigInt), _, Context)) =
-    throw(unexpected_const(term.big_integer(Base, BigInt)) - Context).
+eval_expr(_, _, Term) = Int :-
+    Term = term.functor(Const, _, Context),
+    Const = term.integer(_, _, _, _),
+    ( if term_to_int(Term, Int0) then
+        Int = Int0
+    else
+        throw(unexpected_const(Const) - Context)
+    ).
  eval_expr(_, _, term.functor(term.float(Float), _, Context)) =
      throw(unexpected_const(term.float(Float)) - Context).
  eval_expr(_, _, term.functor(term.string(String), _, Context)) =
diff --git a/tests/hard_coded/impl_def_lex.exp b/tests/hard_coded/impl_def_lex.exp
index 499ad2f..3aae974 100644
--- a/tests/hard_coded/impl_def_lex.exp
+++ b/tests/hard_coded/impl_def_lex.exp
@@ -7,4 +7,4 @@ name("$!$") 5
  name("$") 6
  comma 6
  name("$") 7
-integer(0) 7
+integer(base_10, 0) 7
diff --git a/tests/hard_coded/impl_def_lex_string.exp b/tests/hard_coded/impl_def_lex_string.exp
index 7c0bce0..1f709aa 100644
--- a/tests/hard_coded/impl_def_lex_string.exp
+++ b/tests/hard_coded/impl_def_lex_string.exp
@@ -4,4 +4,4 @@
  {token_cons(name("$"), 1, token_nil), posn(1, 0, 1)}
  {token_cons(name("$!$"), 1, token_nil), posn(1, 0, 3)}
  {token_cons(name("$"), 1, token_cons(comma, 1, token_nil)), posn(1, 0, 2)}
-{token_cons(name("$"), 1, token_cons(integer(0), 1, token_nil)), posn(1, 0, 2)}
+{token_cons(name("$"), 1, token_cons(integer(base_10, 0), 1, token_nil)), posn(1, 0, 2)}
diff --git a/tests/hard_coded/lexer_bigint.exp b/tests/hard_coded/lexer_bigint.exp
index 7aa05ca..ede0670 100644
--- a/tests/hard_coded/lexer_bigint.exp
+++ b/tests/hard_coded/lexer_bigint.exp
@@ -1,8 +1,8 @@
-integer(2147483646)
-integer(2147483647)
+integer(base_10, 2147483646)
+integer(base_10, 2147483647)
  big_integer(base_10, i(3, [8, 0, 0]))
  name("-")
-integer(2147483647)
+integer(base_10, 2147483647)
  name("-")
  big_integer(base_10, i(3, [8, 0, 0]))
  name("-")
@@ -24,11 +24,11 @@ big_integer(base_8, i(5, [255, 16383, 16383, 16383, 16383]))
  big_integer(base_16, i(5, [255, 16383, 16383, 16383, 16383]))
  big_integer(base_10, i(8, [3155, 7268, 4662, 4920, 12374, 12447, 15630, 7857]))

-integer(2147483646)
-integer(2147483647)
+integer(base_10, 2147483646)
+integer(base_10, 2147483647)
  big_integer(base_10, i(3, [8, 0, 0]))
  name("-")
-integer(2147483647)
+integer(base_10, 2147483647)
  name("-")
  big_integer(base_10, i(3, [8, 0, 0]))
  name("-")
diff --git a/tests/hard_coded/lexer_bigint.exp2 b/tests/hard_coded/lexer_bigint.exp2
index 72c723d..e9ade7d 100644
--- a/tests/hard_coded/lexer_bigint.exp2
+++ b/tests/hard_coded/lexer_bigint.exp2
@@ -1,20 +1,20 @@
-integer(2147483646)
-integer(2147483647)
-integer(2147483648)
+integer(base_10, 2147483646)
+integer(base_10, 2147483647)
+integer(base_10, 2147483648)
  name("-")
-integer(2147483647)
+integer(base_10, 2147483647)
  name("-")
-integer(2147483648)
+integer(base_10, 2147483648)
  name("-")
-integer(2147483649)
-integer(4294967295)
-integer(4294967295)
-integer(4294967295)
-integer(9223372036854775807)
+integer(base_10, 2147483649)
+integer(base_2, 4294967295)
+integer(base_8, 4294967295)
+integer(base_16, 4294967295)
+integer(base_10, 9223372036854775807)
  big_integer(base_10, i(5, [128, 0, 0, 0, 0]))
  big_integer(base_10, i(5, [128, 0, 0, 0, 1]))
  name("-")
-integer(9223372036854775807)
+integer(base_10, 9223372036854775807)
  name("-")
  big_integer(base_10, i(5, [128, 0, 0, 0, 0]))
  name("-")
@@ -24,23 +24,23 @@ big_integer(base_8, i(5, [255, 16383, 16383, 16383, 16383]))
  big_integer(base_16, i(5, [255, 16383, 16383, 16383, 16383]))
  big_integer(base_10, i(8, [3155, 7268, 4662, 4920, 12374, 12447, 15630, 7857]))

-integer(2147483646)
-integer(2147483647)
-integer(2147483648)
+integer(base_10, 2147483646)
+integer(base_10, 2147483647)
+integer(base_10, 2147483648)
  name("-")
-integer(2147483647)
+integer(base_10, 2147483647)
  name("-")
-integer(2147483648)
+integer(base_10, 2147483648)
  name("-")
-integer(2147483649)
-integer(4294967295)
-integer(4294967295)
-integer(4294967295)
-integer(9223372036854775807)
+integer(base_10, 2147483649)
+integer(base_2, 4294967295)
+integer(base_8, 4294967295)
+integer(base_16, 4294967295)
+integer(base_10, 9223372036854775807)
  big_integer(base_10, i(5, [128, 0, 0, 0, 0]))
  big_integer(base_10, i(5, [128, 0, 0, 0, 1]))
  name("-")
-integer(9223372036854775807)
+integer(base_10, 9223372036854775807)
  name("-")
  big_integer(base_10, i(5, [128, 0, 0, 0, 0]))
  name("-")
diff --git a/tests/hard_coded/lexer_zero.exp b/tests/hard_coded/lexer_zero.exp
index d947834..dfe7505 100644
--- a/tests/hard_coded/lexer_zero.exp
+++ b/tests/hard_coded/lexer_zero.exp
@@ -1,20 +1,20 @@
-integer(0)
-integer(12345678)
-integer(10)
-integer(97)
-integer(97)
+integer(base_10, 0)
+integer(base_10, 12345678)
+integer(base_10, 10)
+integer(base_10, 97)
+integer(base_10, 97)
  name("bc")
-integer(0)
-integer(1)
-integer(3)
-integer(7)
-integer(0)
-integer(1)
-integer(342391)
-integer(1)
-integer(305419896)
-integer(162254319)
-integer(162254319)
+integer(base_2, 0)
+integer(base_2, 1)
+integer(base_2, 3)
+integer(base_2, 7)
+integer(base_8, 0)
+integer(base_8, 1)
+integer(base_8, 342391)
+integer(base_16, 1)
+integer(base_16, 305419896)
+integer(base_16, 162254319)
+integer(base_16, 162254319)
  float(0.123)
  float(1.23e+44)
  float(0.0)
@@ -22,23 +22,23 @@ float(0.0)
  float(0.0)
  float(0.0)

-integer(0)
-integer(12345678)
-integer(10)
-integer(97)
-integer(97)
+integer(base_10, 0)
+integer(base_10, 12345678)
+integer(base_10, 10)
+integer(base_10, 97)
+integer(base_10, 97)
  name("bc")
-integer(0)
-integer(1)
-integer(3)
-integer(7)
-integer(0)
-integer(1)
-integer(342391)
-integer(1)
-integer(305419896)
-integer(162254319)
-integer(162254319)
+integer(base_2, 0)
+integer(base_2, 1)
+integer(base_2, 3)
+integer(base_2, 7)
+integer(base_8, 0)
+integer(base_8, 1)
+integer(base_8, 342391)
+integer(base_16, 1)
+integer(base_16, 305419896)
+integer(base_16, 162254319)
+integer(base_16, 162254319)
  float(0.123)
  float(1.23e+44)
  float(0.0)
diff --git a/tests/hard_coded/lexer_zero.exp2 b/tests/hard_coded/lexer_zero.exp2
index 38ab4e1..6edcb11 100644
--- a/tests/hard_coded/lexer_zero.exp2
+++ b/tests/hard_coded/lexer_zero.exp2
@@ -1,20 +1,20 @@
-integer(0)
-integer(12345678)
-integer(10)
-integer(97)
-integer(97)
+integer(base_10, 0)
+integer(base_10, 12345678)
+integer(base_10, 10)
+integer(base_10, 97)
+integer(base_10, 97)
  name("bc")
-integer(0)
-integer(1)
-integer(3)
-integer(7)
-integer(0)
-integer(1)
-integer(342391)
-integer(1)
-integer(305419896)
-integer(162254319)
-integer(162254319)
+integer(base_2, 0)
+integer(base_2, 1)
+integer(base_2, 3)
+integer(base_2, 7)
+integer(base_8, 0)
+integer(base_8, 1)
+integer(base_8, 342391)
+integer(base_16, 1)
+integer(base_16, 305419896)
+integer(base_16, 162254319)
+integer(base_16, 162254319)
  float(0.123)
  float(1.23E44)
  float(0.0)
@@ -22,23 +22,23 @@ float(0.0)
  float(0.0)
  float(0.0)

-integer(0)
-integer(12345678)
-integer(10)
-integer(97)
-integer(97)
+integer(base_10, 0)
+integer(base_10, 12345678)
+integer(base_10, 10)
+integer(base_10, 97)
+integer(base_10, 97)
  name("bc")
-integer(0)
-integer(1)
-integer(3)
-integer(7)
-integer(0)
-integer(1)
-integer(342391)
-integer(1)
-integer(305419896)
-integer(162254319)
-integer(162254319)
+integer(base_2, 0)
+integer(base_2, 1)
+integer(base_2, 3)
+integer(base_2, 7)
+integer(base_8, 0)
+integer(base_8, 1)
+integer(base_8, 342391)
+integer(base_16, 1)
+integer(base_16, 305419896)
+integer(base_16, 162254319)
+integer(base_16, 162254319)
  float(0.123)
  float(1.23E44)
  float(0.0)
diff --git a/tests/hard_coded/parse_number_from_string.exp b/tests/hard_coded/parse_number_from_string.exp
index 01eb941..226c8fb 100644
--- a/tests/hard_coded/parse_number_from_string.exp
+++ b/tests/hard_coded/parse_number_from_string.exp
@@ -1,16 +1,16 @@
  Valid decimal literals:
-read_term("0.") = functor(integer(0), [], context("", 1))
-read_term("-0.") = functor(integer(0), [], context("", 1))
-read_term("00.") = functor(integer(0), [], context("", 1))
-read_term("0_0.") = functor(integer(0), [], context("", 1))
-read_term("10.") = functor(integer(10), [], context("", 1))
-read_term("-10.") = functor(integer(-10), [], context("", 1))
-read_term("1_0.") = functor(integer(10), [], context("", 1))
-read_term("-1_0.") = functor(integer(-10), [], context("", 1))
-read_term("01.") = functor(integer(1), [], context("", 1))
-read_term("0_1.") = functor(integer(1), [], context("", 1))
-read_term("1_000_000_000_000_000_000_000.") = functor(big_integer(base_10, i(5, [13877, 12907, 7261, 14976, 0])), [], context("", 1))
-read_term("-1_000_000_000_000_000_000_000.") = functor(atom("-"), [functor(big_integer(base_10, i(5, [13877, 12907, 7261, 14976, 0])), [], context("", 1))], context("", 1))
+read_term("0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("-0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("00.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("0_0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("10.") = functor(integer(base_10, i(1, [10]), signed, size_word), [], context("", 1))
+read_term("-10.") = functor(integer(base_10, i(-1, [-10]), signed, size_word), [], context("", 1))
+read_term("1_0.") = functor(integer(base_10, i(1, [10]), signed, size_word), [], context("", 1))
+read_term("-1_0.") = functor(integer(base_10, i(-1, [-10]), signed, size_word), [], context("", 1))
+read_term("01.") = functor(integer(base_10, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("0_1.") = functor(integer(base_10, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("1_000_000_000_000_000_000_000.") = functor(integer(base_10, i(5, [13877, 12907, 7261, 14976, 0]), signed, size_word), [], context("", 1))
+read_term("-1_000_000_000_000_000_000_000.") = functor(atom("-"), [functor(integer(base_10, i(5, [13877, 12907, 7261, 14976, 0]), signed, size_word), [], context("", 1))], context("", 1))

  Invalid decimal literals:
  read_term("123_.") = Syntax error: unterminated decimal literal
@@ -18,12 +18,12 @@ read_term("-123_.") = Syntax error: unterminated decimal literal
  read_term("-_123") = Syntax error: operator or `.' expected

  Valid binary literals:
-read_term("0b0.") = functor(integer(0), [], context("", 1))
-read_term("-0b0.") = functor(integer(0), [], context("", 1))
-read_term("0b_1.") = functor(integer(1), [], context("", 1))
-read_term("-0b_1.") = functor(integer(-1), [], context("", 1))
-read_term("0b_1000_100.") = functor(integer(68), [], context("", 1))
-read_term("-0b_1000_100.") = functor(integer(-68), [], context("", 1))
+read_term("0b0.") = functor(integer(base_2, i(0, []), signed, size_word), [], context("", 1))
+read_term("-0b0.") = functor(integer(base_2, i(0, []), signed, size_word), [], context("", 1))
+read_term("0b_1.") = functor(integer(base_2, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("-0b_1.") = functor(integer(base_2, i(-1, [-1]), signed, size_word), [], context("", 1))
+read_term("0b_1000_100.") = functor(integer(base_2, i(1, [68]), signed, size_word), [], context("", 1))
+read_term("-0b_1000_100.") = functor(integer(base_2, i(-1, [-68]), signed, size_word), [], context("", 1))

  Invalid binary literals:
  read_term("0b.") = Syntax error: unterminated binary literal
@@ -34,14 +34,14 @@ read_term("0b11_.") = Syntax error: unterminated binary literal
  read_term("-0b11_.") = Syntax error: unterminated binary literal

  Valid octal literals:
-read_term("0o77.") = functor(integer(63), [], context("", 1))
-read_term("-0o77.") = functor(integer(-63), [], context("", 1))
-read_term("0o_77.") = functor(integer(63), [], context("", 1))
-read_term("-0o_77.") = functor(integer(-63), [], context("", 1))
-read_term("0o_7_7.") = functor(integer(63), [], context("", 1))
-read_term("-0o_7_7.") = functor(integer(-63), [], context("", 1))
-read_term("0o_7__7___7.") = functor(integer(511), [], context("", 1))
-read_term("-0o_7__7___7.") = functor(integer(-511), [], context("", 1))
+read_term("0o77.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o77.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_77.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o_77.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_7_7.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o_7_7.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_7__7___7.") = functor(integer(base_8, i(1, [511]), signed, size_word), [], context("", 1))
+read_term("-0o_7__7___7.") = functor(integer(base_8, i(-1, [-511]), signed, size_word), [], context("", 1))

  Invalid octal literals:
  read_term("0o.") = Syntax error: unterminated octal literal
@@ -52,16 +52,16 @@ read_term("0o77_.") = Syntax error: unterminated octal literal
  read_term("-0o77_.") = Syntax error: unterminated octal literal

  Valid hexadecimal literals:
-read_term("0xff.") = functor(integer(255), [], context("", 1))
-read_term("-0xff.") = functor(integer(-255), [], context("", 1))
-read_term("0x_ff.") = functor(integer(255), [], context("", 1))
-read_term("-0x_ff.") = functor(integer(-255), [], context("", 1))
-read_term("0xf_f.") = functor(integer(255), [], context("", 1))
-read_term("-0xf_f.") = functor(integer(-255), [], context("", 1))
-read_term("0x_f_f__f.") = functor(integer(4095), [], context("", 1))
-read_term("-0x_f_f__f.") = functor(integer(-4095), [], context("", 1))
-read_term("0xfffffffffffffffffffffffff.") = functor(big_integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383])), [], context("", 1))
-read_term("-0xfffffffffffffffffffffffff.") = functor(atom("-"), [functor(big_integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383])), [], context("", 1))], context("", 1))
+read_term("0xff.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0xff.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0x_ff.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0x_ff.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0xf_f.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0xf_f.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0x_f_f__f.") = functor(integer(base_16, i(1, [4095]), signed, size_word), [], context("", 1))
+read_term("-0x_f_f__f.") = functor(integer(base_16, i(-1, [-4095]), signed, size_word), [], context("", 1))
+read_term("0xfffffffffffffffffffffffff.") = functor(integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383]), signed, size_word), [], context("", 1))
+read_term("-0xfffffffffffffffffffffffff.") = functor(atom("-"), [functor(integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383]), signed, size_word), [], context("", 1))], context("", 1))

  Invalid hexadecimal literals:
  read_term("0x.") = Syntax error: unterminated hexadecimal literal
diff --git a/tests/hard_coded/parse_number_from_string.exp2 b/tests/hard_coded/parse_number_from_string.exp2
index ad2e577..2481cde 100644
--- a/tests/hard_coded/parse_number_from_string.exp2
+++ b/tests/hard_coded/parse_number_from_string.exp2
@@ -1,16 +1,16 @@
  Valid decimal literals:
-read_term("0.") = functor(integer(0), [], context("", 1))
-read_term("-0.") = functor(integer(0), [], context("", 1))
-read_term("00.") = functor(integer(0), [], context("", 1))
-read_term("0_0.") = functor(integer(0), [], context("", 1))
-read_term("10.") = functor(integer(10), [], context("", 1))
-read_term("-10.") = functor(integer(-10), [], context("", 1))
-read_term("1_0.") = functor(integer(10), [], context("", 1))
-read_term("-1_0.") = functor(integer(-10), [], context("", 1))
-read_term("01.") = functor(integer(1), [], context("", 1))
-read_term("0_1.") = functor(integer(1), [], context("", 1))
-read_term("1_000_000_000_000_000_000_000.") = functor(big_integer(base_10, i(5, [13877, 12907, 7261, 14976, 0])), [], context("", 1))
-read_term("-1_000_000_000_000_000_000_000.") = functor(atom("-"), [functor(big_integer(base_10, i(5, [13877, 12907, 7261, 14976, 0])), [], context("", 1))], context("", 1))
+read_term("0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("-0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("00.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("0_0.") = functor(integer(base_10, i(0, []), signed, size_word), [], context("", 1))
+read_term("10.") = functor(integer(base_10, i(1, [10]), signed, size_word), [], context("", 1))
+read_term("-10.") = functor(integer(base_10, i(-1, [-10]), signed, size_word), [], context("", 1))
+read_term("1_0.") = functor(integer(base_10, i(1, [10]), signed, size_word), [], context("", 1))
+read_term("-1_0.") = functor(integer(base_10, i(-1, [-10]), signed, size_word), [], context("", 1))
+read_term("01.") = functor(integer(base_10, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("0_1.") = functor(integer(base_10, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("1_000_000_000_000_000_000_000.") = functor(integer(base_10, i(5, [13877, 12907, 7261, 14976, 0]), signed, size_word), [], context("", 1))
+read_term("-1_000_000_000_000_000_000_000.") = functor(atom("-"), [functor(integer(base_10, i(5, [13877, 12907, 7261, 14976, 0]), signed, size_word), [], context("", 1))], context("", 1))

  Invalid decimal literals:
  read_term("123_.") = Syntax error: unterminated decimal literal
@@ -18,12 +18,12 @@ read_term("-123_.") = Syntax error: unterminated decimal literal
  read_term("-_123") = Syntax error: operator or `.' expected

  Valid binary literals:
-read_term("0b0.") = functor(integer(0), [], context("", 1))
-read_term("-0b0.") = functor(integer(0), [], context("", 1))
-read_term("0b_1.") = functor(integer(1), [], context("", 1))
-read_term("-0b_1.") = functor(integer(-1), [], context("", 1))
-read_term("0b_1000_100.") = functor(integer(68), [], context("", 1))
-read_term("-0b_1000_100.") = functor(integer(-68), [], context("", 1))
+read_term("0b0.") = functor(integer(base_2, i(0, []), signed, size_word), [], context("", 1))
+read_term("-0b0.") = functor(integer(base_2, i(0, []), signed, size_word), [], context("", 1))
+read_term("0b_1.") = functor(integer(base_2, i(1, [1]), signed, size_word), [], context("", 1))
+read_term("-0b_1.") = functor(integer(base_2, i(-1, [-1]), signed, size_word), [], context("", 1))
+read_term("0b_1000_100.") = functor(integer(base_2, i(1, [68]), signed, size_word), [], context("", 1))
+read_term("-0b_1000_100.") = functor(integer(base_2, i(-1, [-68]), signed, size_word), [], context("", 1))

  Invalid binary literals:
  read_term("0b.") = Syntax error: unterminated binary literal
@@ -34,14 +34,14 @@ read_term("0b11_.") = Syntax error: unterminated binary literal
  read_term("-0b11_.") = Syntax error: unterminated binary literal

  Valid octal literals:
-read_term("0o77.") = functor(integer(63), [], context("", 1))
-read_term("-0o77.") = functor(integer(-63), [], context("", 1))
-read_term("0o_77.") = functor(integer(63), [], context("", 1))
-read_term("-0o_77.") = functor(integer(-63), [], context("", 1))
-read_term("0o_7_7.") = functor(integer(63), [], context("", 1))
-read_term("-0o_7_7.") = functor(integer(-63), [], context("", 1))
-read_term("0o_7__7___7.") = functor(integer(511), [], context("", 1))
-read_term("-0o_7__7___7.") = functor(integer(-511), [], context("", 1))
+read_term("0o77.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o77.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_77.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o_77.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_7_7.") = functor(integer(base_8, i(1, [63]), signed, size_word), [], context("", 1))
+read_term("-0o_7_7.") = functor(integer(base_8, i(-1, [-63]), signed, size_word), [], context("", 1))
+read_term("0o_7__7___7.") = functor(integer(base_8, i(1, [511]), signed, size_word), [], context("", 1))
+read_term("-0o_7__7___7.") = functor(integer(base_8, i(-1, [-511]), signed, size_word), [], context("", 1))

  Invalid octal literals:
  read_term("0o.") = Syntax error: unterminated octal literal
@@ -52,16 +52,16 @@ read_term("0o77_.") = Syntax error: unterminated octal literal
  read_term("-0o77_.") = Syntax error: unterminated octal literal

  Valid hexadecimal literals:
-read_term("0xff.") = functor(integer(255), [], context("", 1))
-read_term("-0xff.") = functor(integer(-255), [], context("", 1))
-read_term("0x_ff.") = functor(integer(255), [], context("", 1))
-read_term("-0x_ff.") = functor(integer(-255), [], context("", 1))
-read_term("0xf_f.") = functor(integer(255), [], context("", 1))
-read_term("-0xf_f.") = functor(integer(-255), [], context("", 1))
-read_term("0x_f_f__f.") = functor(integer(4095), [], context("", 1))
-read_term("-0x_f_f__f.") = functor(integer(-4095), [], context("", 1))
-read_term("0xfffffffffffffffffffffffff.") = functor(big_integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383])), [], context("", 1))
-read_term("-0xfffffffffffffffffffffffff.") = functor(atom("-"), [functor(big_integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383])), [], context("", 1))], context("", 1))
+read_term("0xff.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0xff.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0x_ff.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0x_ff.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0xf_f.") = functor(integer(base_16, i(1, [255]), signed, size_word), [], context("", 1))
+read_term("-0xf_f.") = functor(integer(base_16, i(-1, [-255]), signed, size_word), [], context("", 1))
+read_term("0x_f_f__f.") = functor(integer(base_16, i(1, [4095]), signed, size_word), [], context("", 1))
+read_term("-0x_f_f__f.") = functor(integer(base_16, i(-1, [-4095]), signed, size_word), [], context("", 1))
+read_term("0xfffffffffffffffffffffffff.") = functor(integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383]), signed, size_word), [], context("", 1))
+read_term("-0xfffffffffffffffffffffffff.") = functor(atom("-"), [functor(integer(base_16, i(8, [3, 16383, 16383, 16383, 16383, 16383, 16383, 16383]), signed, size_word), [], context("", 1))], context("", 1))

  Invalid hexadecimal literals:
  read_term("0x.") = Syntax error: unterminated hexadecimal literal
diff --git a/tests/hard_coded/term_to_univ_test.exp b/tests/hard_coded/term_to_univ_test.exp
index c781c51..ebbc95a 100644
--- a/tests/hard_coded/term_to_univ_test.exp
+++ b/tests/hard_coded/term_to_univ_test.exp
@@ -1,2 +1,2 @@
-functor(atom("univ_cons"), [functor(integer(4), [], context("", 0))], context("", 0))
+functor(atom("univ_cons"), [functor(integer(base_10, i(1, [4]), signed, size_word), [], context("", 0))], context("", 0))
  univ_cons(4)


More information about the reviews mailing list