Files
mercury/tests/hard_coded/impure_foreign.m
Zoltan Somogyi 38f1f5faf2 Shut up many warnings in executable test dirs.
tests/hard_coded/bitmap_test_helper_1.m:
tests/hard_coded/curry_2_helper_1.m:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/ho_float_reg.m:
tests/hard_coded/impl_def_lex_string.m:
tests/hard_coded/impure_foreign.m:
tests/hard_coded/intermod_multimode_helper_1.m:
tests/hard_coded/multimode.m:
tests/hard_coded/qual_is_test.m:
tests/hard_coded/string_codepoint.m:
tests/hard_coded/string_codepoint_offset_ilseq.m:
tests/hard_coded/string_count_codepoints_ilseq.m:
tests/hard_coded/string_set_char.m:
tests/hard_coded/version_hash_table_test_2.m:
tests/submodules/parent_t2.m:
tests/typeclasses/arbitrary_constraint_pred_1.m:
tests/typeclasses/arbitrary_constraint_pred_2.m:
tests/typeclasses/instance_unconstrained_tvar_type_spec.m:
tests/typeclasses/typeclass_order_bug_1.m:
    Change code to avoid compiler warnings where this is (a) possible,
    and (b) does not interfere with the purpose of the test.

tests/hard_coded/string_codepoint.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp2:
    The changes to the source files of these tests changed all references
    to "codepoint" to "code_point", including in the text they output.
    Expect the updated output.

tests/general/Mercury.options:
tests/hard_coded/Mercury.options:
tests/typeclasses/Mercury.options:
tests/submodules/Mercury.options:
    Disable many of the remaining warnings.
2025-02-20 23:11:53 +11:00

103 lines
2.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module impure_foreign.
:- interface.
:- import_module io.
:- impure pred main(io::di, io::uo) is det.
:- implementation.
:- import_module require.
main(!IO) :-
% Inlining this call forces recomputation of purity for main/2
% (because of the `:- pragma promise_pure').
% In some versions of this compiler, this recomputation would
% erroneously infer that the inlined calls to incr/1 below
% were `pure'. Duplicate call elimination would then remove
% all but one of them.
unsafe_get(Val0),
io.write_int(Val0, !IO),
io.nl(!IO),
impure incr(_),
impure incr(_),
impure incr(_),
semipure get(Val),
io.write_int(Val, !IO),
io.nl(!IO).
:- pragma foreign_decl("C",
"
int counter;
").
:- pragma foreign_code("C",
"
int counter = 1;
").
:- pragma foreign_code("C#", "static int counter = 1;").
:- pragma foreign_code("Java", "static int counter = 1;").
:- impure pred incr(int::out) is det.
incr(_) :-
error("incr/1 called for language other than C").
:- pragma foreign_proc("C",
incr(Val::out),
[will_not_call_mercury],
"
counter++; Val = counter;
").
:- pragma foreign_proc("C#",
incr(Val::out),
[will_not_call_mercury],
"
counter++; Val = counter;
").
:- pragma foreign_proc("Java",
incr(Val::out),
[will_not_call_mercury],
"
counter++; Val = counter;
").
:- semipure pred get(int::out) is det.
get(_) :-
error("get/1 called for language other than C").
:- pragma foreign_proc("C",
get(Val::out),
[will_not_call_mercury, promise_semipure],
"
Val = counter
").
:- pragma foreign_proc("C#",
get(Val::out),
[will_not_call_mercury, promise_semipure],
"
Val = counter;
").
:- pragma foreign_proc("Java",
get(Val::out),
[will_not_call_mercury, promise_semipure],
"
Val = counter;
").
:- pred unsafe_get(int::out) is det.
:- pragma promise_pure(unsafe_get/1).
unsafe_get(X) :-
semipure get(X).