mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
library/array.m:
library/assoc_list.m:
library/bimap.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/hash_table.m:
library/injection.m:
library/io.stream_db.m:
library/kv_list.m:
library/list.m:
library/map.m:
library/robdd.m:
library/stream.string_writer.m:
library/term_conversion.m:
library/term_to_xml.m:
library/tree234.m:
library/type_desc.m:
library/version_hash_table.m:
For nearly every ordinary function in this directory that can fail in its
primary mode (all of which were semidet functions),
- provide a semidet predicate as an alternative, if it did not
already exist,
- implement the function in terms of the predicate, instead of vice versa,
- mark the semidet function as obsolete in favor of the semidet predicate
version,
- fix all the resulting warnings, and then
- comment out the obsolete pragmas (at least for now).
Note that this diff does not touch the semidet function in the
enum typeclass, or the functions that implement that method
in instances.
NEWS.md:
Announce the new predicates in the (documented) modules of the library.
browser/term_rep.m:
compiler/lp_rational.m:
compiler/mcsolver.m:
compiler/mode_ordering.m:
compiler/mode_robdd.equiv_vars.m:
compiler/mode_robdd.implications.m:
compiler/old_type_constraints.m:
compiler/pickle.m:
compiler/prog_event.m:
compiler/type_ctor_info.m:
compiler/var_table.m:
tests/hard_coded/bitmap_empty.m:
tests/hard_coded/construct_mangle.m:
tests/hard_coded/construct_packed.m:
tests/hard_coded/construct_test.m:
tests/hard_coded/dummy_type_construct.m:
tests/hard_coded/expand.m:
tests/hard_coded/foreign_enum_rtti.m:
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/term_to_univ_test.m:
tests/hard_coded/type_to_term.m:
tests/hard_coded/type_to_term_bug.m:
Stop calling the semidet functions from the library that were temporarily
marked obsolete.
In a few places, add explicit type qualification to avoid warnings
about unresolved polymorphism.
tests/hard_coded/test_injection.exp:
Expect an abort message from the predicate version of a semidet function.
tests/declarative_debugger/ho_2.exp2:
Update this .exp file for a previous commit.
270 lines
6.9 KiB
Mathematica
270 lines
6.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
% Test operations on empty (zero-length) bitmaps.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module bitmap_empty.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module bitmap.
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
io.write_string("-- new\n", !IO),
|
|
A0 = bitmap.init(0, no) : bitmap,
|
|
io.write_line(A0, !IO),
|
|
|
|
io.write_string("-- copy\n", !IO),
|
|
some [B] (
|
|
copy(A0, B),
|
|
io.write_line(B, !IO)
|
|
),
|
|
|
|
io.write_string("-- resize\n", !IO),
|
|
some [B0, B1, B2, B3] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = resize(B0, 0, no), % no change
|
|
io.write_line(B1, !IO),
|
|
B2 = resize(B1, 4, yes), % enlarge
|
|
io.write_line(B2, !IO),
|
|
B3 = resize(B2, 0, yes), % shrink
|
|
io.write_line(B3, !IO)
|
|
),
|
|
|
|
io.write_string("-- shrink_without_copying\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(4, no),
|
|
B1 = shrink_without_copying(B0, 0),
|
|
io.write_line(B1, !IO)
|
|
),
|
|
|
|
io.write_string("-- in_range\n", !IO),
|
|
( if in_range(A0, -1) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
( if in_range(A0, 0) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
( if in_range(A0, 1) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
|
|
io.write_string("-- byte_in_range\n", !IO),
|
|
( if byte_in_range(A0, -1) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
( if byte_in_range(A0, 0) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
( if byte_in_range(A0, 1) then
|
|
io.write_string("error\n", !IO)
|
|
else
|
|
io.write_string("ok\n", !IO)
|
|
),
|
|
|
|
io.write_string("-- num_bits\n", !IO),
|
|
NumBits = num_bits(A0),
|
|
io.write_int(NumBits, !IO),
|
|
io.nl(!IO),
|
|
|
|
io.write_string("-- det_num_bytes\n", !IO),
|
|
NumBytes = det_num_bytes(A0),
|
|
io.write_int(NumBytes, !IO),
|
|
io.nl(!IO),
|
|
|
|
io.write_string("-- ^bit\n", !IO),
|
|
( try []
|
|
Bit = A0 ^ bit(0)
|
|
then
|
|
io.write_line(Bit, !IO)
|
|
catch_any BitExcp ->
|
|
io.write_string("expected: ", !IO),
|
|
io.write_line(BitExcp, !IO)
|
|
),
|
|
|
|
io.write_string("-- ^bits\n", !IO),
|
|
Bits = A0 ^ bits(0, 0),
|
|
io.write_line(Bits, !IO),
|
|
|
|
io.write_string("-- ^bits:=\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = B0 ^ bits(0, 0) := 0,
|
|
io.write_line(B1, !IO)
|
|
),
|
|
|
|
io.write_string("-- ^byte\n", !IO),
|
|
( try []
|
|
Byte = A0 ^ byte(0)
|
|
then
|
|
io.write_line(Byte, !IO)
|
|
catch_any ByteExcp ->
|
|
io.write_string("expected: ", !IO),
|
|
io.write_line(ByteExcp, !IO)
|
|
),
|
|
|
|
io.write_string("-- ^byte:=\n", !IO),
|
|
some [B0, B1] (
|
|
( try []
|
|
(
|
|
B0 = bitmap.init(0, no),
|
|
B1 = B0 ^ byte(0) := 0
|
|
)
|
|
then
|
|
io.write_line(B1, !IO)
|
|
catch_any SetByteExcp ->
|
|
io.write_string("expected: ", !IO),
|
|
io.write_line(SetByteExcp, !IO)
|
|
)
|
|
),
|
|
|
|
io.write_string("-- slice\n", !IO),
|
|
some [S] (
|
|
S = bitmap.slice(A0, 0, 0),
|
|
io.write_line(S, !IO)
|
|
),
|
|
|
|
io.write_string("-- byte_slice\n", !IO),
|
|
some [S] (
|
|
S = bitmap.byte_slice(A0, 0, 0),
|
|
io.write_line(S, !IO)
|
|
),
|
|
|
|
io.write_string("-- flip\n", !IO),
|
|
some [B0, B1] (
|
|
( try []
|
|
(
|
|
B0 = bitmap.init(0, no),
|
|
B1 = flip(B0, 0)
|
|
)
|
|
then
|
|
io.write_line(B1, !IO)
|
|
catch_any E18 ->
|
|
io.write_string("expected: ", !IO),
|
|
io.write_line(E18, !IO)
|
|
)
|
|
),
|
|
|
|
A1 = bitmap.init(0, no),
|
|
A2 = bitmap.init(0, no),
|
|
|
|
io.write_string("-- complement\n", !IO),
|
|
Bcompl = complement(A1),
|
|
io.write_line(Bcompl, !IO),
|
|
|
|
io.write_string("-- union\n", !IO),
|
|
Bunion = union(A1, A2),
|
|
io.write_line(Bunion, !IO),
|
|
|
|
io.write_string("-- intersect\n", !IO),
|
|
Bintersect = intersect(A1, A2),
|
|
io.write_line(Bintersect, !IO),
|
|
|
|
io.write_string("-- difference\n", !IO),
|
|
Bdiff = difference(A1, A2),
|
|
io.write_line(Bdiff, !IO),
|
|
|
|
io.write_string("-- xor\n", !IO),
|
|
Bxor = xor(A1, A2),
|
|
io.write_line(Bxor, !IO),
|
|
|
|
io.write_string("-- append_list\n", !IO),
|
|
some [B0, B1, B2, B3] (
|
|
B0 = bitmap.init(1, yes),
|
|
B1 = bitmap.init(0, yes),
|
|
B2 = bitmap.init(1, yes),
|
|
B3 = append_list([B0, B1, B2]),
|
|
io.write_line(B3, !IO)
|
|
),
|
|
|
|
io.write_string("-- copy_bits\n", !IO),
|
|
some [B0, B1, B2] (
|
|
B0 = bitmap.init(1, yes),
|
|
B1 = bitmap.init(0, yes),
|
|
B2 = copy_bits(B0, 0, B1, 0, 0),
|
|
io.write_line(B2, !IO)
|
|
),
|
|
|
|
io.write_string("-- copy_bits_in_bitmap\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = copy_bits_in_bitmap(B0, 0, 0, 0),
|
|
io.write_line(B1, !IO)
|
|
),
|
|
|
|
io.write_string("-- copy_bytes\n", !IO),
|
|
some [B0, B1, B2] (
|
|
B0 = bitmap.init(8, yes),
|
|
B1 = bitmap.init(0, no),
|
|
B2 = copy_bytes(B0, 0, B1, 0, 0),
|
|
io.write_line(B2, !IO)
|
|
),
|
|
|
|
io.write_string("-- copy_bytes_in_bitmap\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = copy_bytes_in_bitmap(B0, 0, 0, 0),
|
|
io.write_line(B1, !IO)
|
|
),
|
|
|
|
io.write_string("-- from_string\n", !IO),
|
|
String = to_string(A0),
|
|
( if bitmap.from_string(String, Bstring) then
|
|
io.write_line(Bstring, !IO)
|
|
else
|
|
io.write_string("error\n", !IO)
|
|
),
|
|
|
|
io.write_string("-- to_byte_string\n", !IO),
|
|
ByteString = bitmap.to_byte_string(A0),
|
|
io.write_string("<", !IO),
|
|
io.write_string(ByteString, !IO),
|
|
io.write_string(">\n", !IO),
|
|
|
|
io.write_string("-- hash\n", !IO),
|
|
Hash = bitmap.hash(A0),
|
|
io.write_int(Hash, !IO),
|
|
io.nl(!IO),
|
|
|
|
io.write_string("-- bitmap_equal\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = bitmap.init(0, no),
|
|
( if B0 = B1 then
|
|
io.write_string("equal\n", !IO)
|
|
else
|
|
io.write_string("not equal\n", !IO)
|
|
)
|
|
),
|
|
|
|
io.write_string("-- bitmap_compare\n", !IO),
|
|
some [B0, B1] (
|
|
B0 = bitmap.init(0, no),
|
|
B1 = bitmap.init(0, no),
|
|
compare(Compare, B0, B1),
|
|
io.write_line(Compare, !IO)
|
|
).
|