mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Replace placeholder types with int64 and uint64 as appropriate throughout the
system.
Enable support for 64-bit integer literals in the compiler.
Add initial library support for 64-bit integers.
configure.ac:
Check that the bootstrap compiler recognises int64 and uint64 as
builtins.
library/int64.m:
library/uint64.m:
Populate these two modules to the extent that we can now run
basic tests of 64-bit integer support.
Note that since the bootstrap compiler will not recognise
64-bit integer literals, any such literals are current written
as conversions from ints; this will be replaced once this change
has bootstrapped.
library/private_builtin.m:
Replace the placeholder definitions for builtin unification and
comparison of 64-bit integers with their actual definitions.
library/integer.m:
Add procedures for converting integers to- and from int64 and uint64.
library/string.m:
Add functions for converting 64-bit integers into strings.
library/io.m:
Add predicates for writing 64-bit integers to text streams.
(Support for 64-bit integers with binary streams will be done
separately.)
library/stream.string_writer.m:
Add put_int64/4 and put_uint/64.
Extend the implementations of print and write to cover int64 and
uint64.
library/pprint.m:
Make int64 and uint64 instances of the doc/1 type class.
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
Handle int64 and uint64 properly in deconstruct.
library/term.m:
Add functions for converting 64-bit integers into terms.
library/term_conversion.m:
Support int64 and uint64 in univ -> term conversion.
library/Mercury.options:
Avoid a warning about the import of the require being
unused in the int64 and uint64 modules. It *is* used,
but only in the definitions used by the Erlang backend.
compiler/superhomogeneous.m:
Accept 64-bit integer literals.
compiler/c_util.m:
In C, write out the value of the min_int64 as the symbolic
constant INT64_MIN. This expands in such a way as to avoid
generating warnings from the C compiler.
compiler/builtin_ops.m:
compiler/bytecode.m:
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/hlds_data.m:
compiler/hlds_out_util.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/lookup_switch.m:
compiler/mercury_to_mercury.m:
compiler/mlds.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_to_term.m:
compiler/prog_data.m:
compiler/prog_out.m:
compiler/prog_rep.m:
Replace the use of int as a placeholder with int64 or uint64 as
appropriate.
tests/hard_coded/Mmakefile:
tests/hard_coded/arith_int64.{m,exp}:
tests/hard_coded/arith_uint64.{m,exp}:
tests/hard_coded/bitwise_int64.{m,exp}:
tests/hard_coded/bitwise_uint64.{m,exp}:
tests/hard_coded/cmp_int64.{m,exp}:
tests/hard_coded/cmp_uint64.{m,exp}:
tests/hard_coded/integer_int64_conv.{m,exp}:
tests/hard_coded/integer_uint64_conv.{m,exp}:
Add tests of basic operations on 64-bit integers.
tests/hard_coded/construct_test.{m,exp}:
Extend this test to cover 64-bit integers.
112 lines
2.9 KiB
Mathematica
112 lines
2.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% Test conversion of int64s to integers and integers to int64s.
|
|
|
|
:- module integer_int64_conv.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module integer.
|
|
:- import_module int64.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
io.write_string("*** Testing int64 -> integer conversion ***\n\n", !IO),
|
|
list.foldl(do_to_integer_test, test_int64s, !IO),
|
|
io.nl(!IO),
|
|
io.write_string("*** Testing integer -> int64 conversion ***\n\n", !IO),
|
|
list.foldl(do_from_integer_test, test_integers, !IO).
|
|
|
|
:- pred do_to_integer_test(int64::in, io::di, io::uo) is det.
|
|
|
|
do_to_integer_test(U, !IO) :-
|
|
Integer = integer.from_int64(U),
|
|
io.write_string("int64 = ", !IO),
|
|
io.write_int64(U, !IO),
|
|
io.write_string(", integer = ", !IO),
|
|
io.print(Integer, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred do_from_integer_test(integer::in, io::di, io::uo) is det.
|
|
|
|
do_from_integer_test(Integer, !IO) :-
|
|
io.write_string("integer = ", !IO),
|
|
io.print(Integer, !IO),
|
|
io.write_string(", int64 = ", !IO),
|
|
( if integer.to_int64(Integer, U) then
|
|
io.write_int64(U, !IO)
|
|
else
|
|
io.write_string("<<OUT-OF-RANGE>>", !IO)
|
|
),
|
|
io.nl(!IO).
|
|
|
|
:- func test_int64s = list(int64).
|
|
|
|
test_int64s = [
|
|
-9223372036854775808i64,
|
|
-2147483648i64,
|
|
-32768i64,
|
|
-128i64,
|
|
-64i64,
|
|
-32i64,
|
|
-1i64,
|
|
0i64,
|
|
1i64,
|
|
2i64,
|
|
4i64,
|
|
8i64,
|
|
10i64,
|
|
16i64,
|
|
32i64,
|
|
64i64,
|
|
127i64,
|
|
16383i64, % i.e. integer.base - 1
|
|
16384i64, % i.e. integer.base
|
|
16385i64, % i.e. integer.base + 1,
|
|
32767i64,
|
|
2147483647i64,
|
|
9223372036854775807i64
|
|
].
|
|
|
|
:- func test_integers = list(integer).
|
|
|
|
test_integers = [
|
|
det_from_string("-9223372036854775808"),
|
|
det_from_string("-4294967296"),
|
|
det_from_string("-2147483649"),
|
|
det_from_string("-2147483648"),
|
|
det_from_string("-32768"),
|
|
det_from_string("-2"),
|
|
det_from_string("-1"),
|
|
det_from_string("0"),
|
|
det_from_string("1"),
|
|
det_from_string("2"),
|
|
det_from_string("16383"),
|
|
det_from_string("16384"),
|
|
det_from_string("16385"),
|
|
det_from_string("32767"),
|
|
det_from_string("1073741824"),
|
|
det_from_string("2147483647"),
|
|
det_from_string("2147483648"),
|
|
det_from_string("4294967295"),
|
|
det_from_string("4294967296"),
|
|
det_from_string("4294967297"),
|
|
det_from_string("9223372036854775807"),
|
|
det_from_string("9223372036854775808"),
|
|
det_from_string("18446744073709551615"),
|
|
det_from_string("18446744073709551616")
|
|
].
|