[m-rev.] diff: use uint literals in library and compiler
Julien Fischer
jfischer at opturion.com
Mon Jun 12 00:18:34 AEST 2017
Use uint literals in library and compiler.
configure.ac:
Require that the bootstrap compiler support uint literals.
library/integer.m:
library/uint.m:
compiler/const_prop.m:
compiler/ml_lookup_switch.m:
compiler/simplify_goal_call.m:
compiler/uint_emu.m:
Use uint literals rather than casting from ints.
Delete imports of the uint module where we can now do so.
Julien.
diff --git a/compiler/const_prop.m b/compiler/const_prop.m
index 3c6bb26c7..f33df7255 100644
--- a/compiler/const_prop.m
+++ b/compiler/const_prop.m
@@ -612,7 +612,7 @@ evaluate_det_call_uint_3(Globals, ProcName, ModeNum, X, Y, Z,
ModeNum = 0,
X ^ arg_inst = bound(_, _, [bound_functor(uint_const(XVal), [])]),
Y ^ arg_inst = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
OutputArg = Z,
globals.lookup_bool_option(Globals, pregenerated_dist, no),
uint_emu.target_bits_per_uint(Globals, BitsPerUInt),
@@ -622,7 +622,7 @@ evaluate_det_call_uint_3(Globals, ProcName, ModeNum, X, Y, Z,
ModeNum = 0,
X ^ arg_inst = bound(_, _, [bound_functor(uint_const(XVal), [])]),
Y ^ arg_inst = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
OutputArg = Z,
globals.lookup_bool_option(Globals, pregenerated_dist, no),
uint_emu.target_bits_per_uint(Globals, BitsPerUInt),
@@ -632,7 +632,7 @@ evaluate_det_call_uint_3(Globals, ProcName, ModeNum, X, Y, Z,
ModeNum = 0,
X ^ arg_inst = bound(_, _, [bound_functor(uint_const(XVal), [])]),
Y ^ arg_inst = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
OutputArg = Z,
globals.lookup_bool_option(Globals, pregenerated_dist, no),
uint_emu.target_bits_per_uint(Globals, BitsPerUInt),
@@ -642,7 +642,7 @@ evaluate_det_call_uint_3(Globals, ProcName, ModeNum, X, Y, Z,
ModeNum = 0,
X ^ arg_inst = bound(_, _, [bound_functor(uint_const(XVal), [])]),
Y ^ arg_inst = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
OutputArg = Z,
globals.lookup_bool_option(Globals, pregenerated_dist, no),
uint_emu.target_bits_per_uint(Globals, BitsPerUInt),
diff --git a/compiler/ml_lookup_switch.m b/compiler/ml_lookup_switch.m
index 035acb07c..0d481bca2 100644
--- a/compiler/ml_lookup_switch.m
+++ b/compiler/ml_lookup_switch.m
@@ -138,7 +138,6 @@
:- import_module int.
:- import_module pair.
:- import_module require.
-:- import_module uint.
%-----------------------------------------------------------------------------%
@@ -829,8 +828,7 @@ ml_default_value_for_type(MLDS_Type) = DefaultRval :-
DefaultRval = ml_const(mlconst_int(0))
;
MLDS_Type = mlds_native_uint_type,
- % XXX UINT - replace the cast when we have uint literals.
- DefaultRval = ml_const(mlconst_uint(cast_from_int(0)))
+ DefaultRval = ml_const(mlconst_uint(0u))
;
MLDS_Type = mlds_native_char_type,
DefaultRval = ml_const(mlconst_char(0))
diff --git a/compiler/simplify_goal_call.m b/compiler/simplify_goal_call.m
index 4f0c56fee..56d765c5e 100644
--- a/compiler/simplify_goal_call.m
+++ b/compiler/simplify_goal_call.m
@@ -103,7 +103,6 @@
:- import_module pair.
:- import_module require.
:- import_module string.
-:- import_module uint.
:- import_module varset.
%---------------------------------------------------------------------------%
@@ -969,7 +968,7 @@ simplify_improve_uint_call(InstMap0, PredName, _ModeNum, Args, ImprovedGoalExpr,
Args = [X, Y, Z],
instmap_lookup_var(InstMap0, Y, InstY),
InstY = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
Op = "unchecked_quotient",
simplify_make_uint_binary_op_goal_expr(!.Info, Op, inline_builtin,
X, Y, Z, ImprovedGoalExpr)
@@ -978,7 +977,7 @@ simplify_improve_uint_call(InstMap0, PredName, _ModeNum, Args, ImprovedGoalExpr,
Args = [X, Y, Z],
instmap_lookup_var(InstMap0, Y, InstY),
InstY = bound(_, _, [bound_functor(uint_const(YVal), [])]),
- YVal \= cast_from_int(0),
+ YVal \= 0u,
Op = "unchecked_rem",
simplify_make_uint_binary_op_goal_expr(!.Info, Op, inline_builtin,
X, Y, Z, ImprovedGoalExpr)
diff --git a/compiler/uint_emu.m b/compiler/uint_emu.m
index aa5dc6dd8..16f7d3928 100644
--- a/compiler/uint_emu.m
+++ b/compiler/uint_emu.m
@@ -66,7 +66,6 @@
:- import_module int.
:- import_module integer.
-:- import_module uint.
:- import_module libs.options.
@@ -104,7 +103,7 @@ quotient(BitsPerUInt, X, Y, Z) :-
Z).
unchecked_quotient(BitsPerUInt, X, Y, Z) :-
- Y \= cast_from_int(0),
+ Y \= 0u,
quotient(BitsPerUInt, X, Y, Z).
mod(BitsPerUInt, X, Y, Z) :-
@@ -116,7 +115,7 @@ rem(BitsPerUInt, X, Y, Z) :-
Z).
unchecked_rem(BitsPerUInt, X, Y, Z) :-
- Y \= cast_from_int(0),
+ Y \= 0u,
rem(BitsPerUInt, X, Y, Z).
left_shift(BitsPerUInt, X, Y, Z) :-
diff --git a/configure.ac b/configure.ac
index 83195e9ed..4f043572d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -362,7 +362,7 @@ then
:- implementation.
- :- import_module bool, char, string, int, list, univ.
+ :- import_module bool, char, string, int, list, uint, univ.
:- mutable(global_var,
int,
@@ -406,7 +406,10 @@ then
:- type bear ---> brown ; black ; teddy.
:- pragma foreign_export_enum("Java", bear/0).
- :- type my_uint ---> my_uint(uint).
+ :- pred my_uint_xor(uint::in, uint::out) is det.
+
+ my_uint_xor(A, B) :-
+ 561u = uint.xor(A, B).
:- pred p(t::out) is det.
diff --git a/library/integer.m b/library/integer.m
index b82afa1d2..630067a1f 100644
--- a/library/integer.m
+++ b/library/integer.m
@@ -1302,7 +1302,7 @@ to_uint(Integer, UInt) :-
Integer >= integer.zero,
Integer =< integer.from_uint(uint.max_uint),
Integer = i(_Sign, Digits),
- UInt = uint_list(Digits, cast_from_int(0)).
+ UInt = uint_list(Digits, 0u).
:- func uint_list(list(int), uint) = uint.
@@ -1564,8 +1564,7 @@ pos_int_to_digits_2(D, Tail) = Result :-
%
from_uint(U) = Integer :-
- % XXX UINT use uint literals here when we have them.
- ( if U = cast_from_int(0) then
+ ( if U = 0u then
Integer = integer.zero
else if U < cast_from_int(base) then
Integer = i(1, [cast_to_int(U)])
@@ -1580,7 +1579,7 @@ uint_to_digits(U) = uint_to_digits_2(U, integer.zero).
:- func uint_to_digits_2(uint, integer) = integer.
uint_to_digits_2(U, Tail) = Result :-
- ( if U = cast_from_int(0) then
+ ( if U = 0u then
Result = Tail
else
Tail = i(Length, Digits),
diff --git a/library/uint.m b/library/uint.m
index f58dd73d5..dc3f8d9ac 100644
--- a/library/uint.m
+++ b/library/uint.m
@@ -287,7 +287,7 @@ X div Y = X // Y.
:- pragma inline('//'/2).
X // Y = Div :-
- ( if Y = cast_from_int(0) then
+ ( if Y = 0u then
throw(math.domain_error("uint.'//': division by zero"))
else
Div = unchecked_quotient(X, Y)
@@ -300,7 +300,7 @@ X mod Y = X rem Y.
:- pragma inline(rem/2).
X rem Y = Rem :-
- ( if Y = cast_from_int(0) then
+ ( if Y = 0u then
throw(math.domain_error("uint.rem: division by zero"))
else
Rem = unchecked_rem(X, Y)
@@ -336,11 +336,11 @@ min(X, Y) =
:- pragma inline(even/1).
even(X) :-
- (X /\ cast_from_int(1)) = cast_from_int(0).
+ (X /\ 1u) = 0u.
:- pragma inline(odd/1).
odd(X) :-
- (X /\ cast_from_int(1)) \= cast_from_int(0).
+ (X /\ 1u) \= 0u.
%---------------------------------------------------------------------------%
More information about the reviews
mailing list