mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +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.
139 lines
4.3 KiB
Mathematica
139 lines
4.3 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Test RTTI foreign enum types.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module foreign_enum_rtti.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module construct.
|
|
:- import_module deconstruct.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
:- import_module type_desc.
|
|
:- import_module univ.
|
|
|
|
main(!IO) :-
|
|
io.write_string("Checking io.write for foreign enum ...\n", !IO),
|
|
io.write_line(foo, !IO),
|
|
io.write_line(bar, !IO),
|
|
io.write_line(baz, !IO),
|
|
io.write_string("Checking deep copy for foreign enum ...\n", !IO),
|
|
X = [foo, bar, baz],
|
|
copy(X, Y),
|
|
io.write_line(Y, !IO),
|
|
TypeDescForFoo = type_of(foo),
|
|
io.write_string("Number of functors of foo/0: ", !IO),
|
|
NumFunctors = det_num_functors(TypeDescForFoo),
|
|
io.write_int(NumFunctors, !IO),
|
|
io.nl(!IO),
|
|
io.write_string("Checking construct.get_functor for foreign_enum ...\n",
|
|
!IO),
|
|
int.fold_up(test_get_functor(TypeDescForFoo), 0, NumFunctors - 1, !IO),
|
|
io.write_string(
|
|
"Checking construct.get_functor_ordinal for foreign_enum ...\n", !IO),
|
|
list.foldl(check_get_functor_ordinal(TypeDescForFoo), [0, 1, 2], !IO),
|
|
io.write_string(
|
|
"Checking construct.construct for foreign_enum ...\n", !IO),
|
|
list.foldl(check_construct(TypeDescForFoo), [0, 1, 2], !IO),
|
|
io.write_string(
|
|
"Checking deconstruct.deconstruct for foreign_enum ...\n", !IO),
|
|
list.foldl(check_deconstruct, [foo, bar, baz], !IO).
|
|
|
|
:- pred check_deconstruct(foo::in, io::di, io::uo) is det.
|
|
|
|
check_deconstruct(Data, !IO) :-
|
|
deconstruct(Data, do_not_allow, Name, Arity, Args),
|
|
io.format(" name = %s\n", [s(Name)], !IO),
|
|
io.format(" arity = %d\n", [i(Arity)], !IO),
|
|
(
|
|
Args = [],
|
|
io.write_string(" no args\n", !IO)
|
|
;
|
|
Args = [_ | _],
|
|
io.write_string("FAILED: unexpected args for foreign enum constant.\n",
|
|
!IO)
|
|
).
|
|
|
|
:- pred check_construct(type_desc::in, functor_number_lex::in,
|
|
io::di, io::uo) is det.
|
|
|
|
check_construct(TypeDesc, LexFunctorNum, !IO) :-
|
|
( if construct(TypeDesc, LexFunctorNum, [], Univ) then
|
|
io.write_string(" ", !IO),
|
|
io.write_line(Univ, !IO)
|
|
else
|
|
io.write_string("FAILED: construct.construct\n", !IO)
|
|
).
|
|
|
|
:- pred check_get_functor_ordinal(type_desc::in, functor_number_lex::in,
|
|
io::di, io::uo) is det.
|
|
|
|
check_get_functor_ordinal(TypeDesc, Lex, !IO) :-
|
|
( if Ordinal = get_functor_ordinal(TypeDesc, Lex) then
|
|
io.format(" lex = %d, ordinal = %d\n", [i(Lex), i(Ordinal)], !IO)
|
|
else
|
|
io.write_string("FAILED: get_functor_ordinal\n", !IO)
|
|
).
|
|
|
|
:- pred test_get_functor(type_desc::in, functor_number_lex::in,
|
|
io::di, io::uo) is det.
|
|
|
|
test_get_functor(TypeDesc, LexFunctorNum, !IO) :-
|
|
io.format("functor_number_lex = %d\n", [i(LexFunctorNum)], !IO),
|
|
( if get_functor(TypeDesc, LexFunctorNum, Name, Arity, ArgTypes) then
|
|
io.format(" name = %s\n", [s(Name)], !IO),
|
|
io.format(" arity = %d\n", [i(Arity)], !IO),
|
|
(
|
|
ArgTypes = [],
|
|
io.write_string(" no arguments\n", !IO)
|
|
;
|
|
ArgTypes = [_ | _],
|
|
io.write_string("FAILED: args for foreign enum functor.\n", !IO)
|
|
)
|
|
else
|
|
io.write_string("FAILED: not a d.u type.\n", !IO)
|
|
).
|
|
|
|
:- type foo
|
|
---> foo
|
|
; bar
|
|
; baz.
|
|
|
|
:- pragma foreign_decl("C",
|
|
"
|
|
#define CONSTANT1 300
|
|
#define CONSTANT2 400
|
|
#define CONSTANT3 500
|
|
").
|
|
|
|
:- pragma foreign_enum("C", foo/0,
|
|
[
|
|
foo - "CONSTANT1",
|
|
bar - "CONSTANT2",
|
|
baz - "CONSTANT3"
|
|
]).
|
|
|
|
:- pragma foreign_enum("C#", foo/0,
|
|
[
|
|
foo - "2",
|
|
bar - "4",
|
|
baz - "6"
|
|
]).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|