mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 20:33:55 +00:00
compiler/add_foreign_proc.m:
The existing code for adding foreign_procs
- tests whether the foreign_proc is for an imported predicate,
and if so, stops with an error message,
- then tests whether the foreign_proc is for the current backend,
and if it is not, ignores the foreign_proc,
- and then both adds the foreign proc to the HLDS, and checks it
for singletons.
Reverse the order of the last two tests, so that we now test
foreign_procs for singletons *even if* they are not for the current
backend. (Though of course we do not add such foreign_procs to the HLDS.)
library/io.environment.m:
library/private_builtin.m:
library/rtti_implementation.m:
Fix the warnings for now result for non-C foreign_procs even during
bootchecks in C grades.
tests/warnings/foreign_singleton.err_exp:
Expect warnings for Java and C# foreign_procs as well as C foreign_procs.
tests/warnings/singleton_test.{m,err_exp}:
tests/warnings/warn_return.{m,err_exp}:
tests/warnings/warn_succ_ind.{m,err_exp}:
Make these test cases more readable. Delete any obsolete parts,
as well as the causes of warnings that these test cases are
not intended to test for. (The latter makes the tests' *outputs*
more readable.)
Expect warnings for Java and C# foreign_procs as well as C foreign_procs,
and expect them with the new line numbers.
tests/warnings/foreign_singleton.err_exp2:
tests/warnings/foreign_singleton.err_exp3:
tests/warnings/singleton_test.err_exp2:
tests/warnings/singleton_test.err_exp3:
tests/warnings/warn_return.err_exp2:
tests/warnings/warn_return.err_exp3:
tests/warnings/warn_succ_ind.err_exp2:
tests/warnings/warn_succ_ind.err_exp3:
Delete these Java- and C#-specific expected outputs, since the warnings
they test for are now in the corresponding .err_exp files.
114 lines
2.8 KiB
Mathematica
114 lines
2.8 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module singleton_test.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
:- import_module list.
|
|
|
|
:- pred my_append(list(int), list(int), list(int)).
|
|
:- mode my_append(in, in, out) is det.
|
|
|
|
:- func my_append_func(list(int), list(int)) = list(int).
|
|
:- mode my_append_func(in, in) = out is det.
|
|
|
|
:- pred test_head(int::in, int::in, int::in, int::in,
|
|
int::out, int::out) is det.
|
|
|
|
:- func my_c_func(int, int) = int.
|
|
:- mode my_c_func(in, in) = out is det.
|
|
|
|
:- pred my_c_pred(int, int, int).
|
|
:- mode my_c_pred(in, in, out) is det.
|
|
|
|
:- pred c_hello_world(string::in, io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- pragma foreign_decl("C", "#include <stdio.h>").
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
my_append([], L, L) :-
|
|
disable_warning [singleton_vars] L = L1,
|
|
L = L2.
|
|
my_append([H | T], L, [H | NT]) :-
|
|
my_append(T, L, NT).
|
|
|
|
my_append_func([], L) = L :- L1 = L2.
|
|
my_append_func([H | T], L) = [H | my_append_func(L, L)].
|
|
|
|
test_head(A, B, C, _D, C, _D).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pragma foreign_proc("C",
|
|
my_c_pred(X::in, Y::in, Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * X;
|
|
").
|
|
:- pragma foreign_proc("C#",
|
|
my_c_pred(X::in, Y::in, Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * X;
|
|
").
|
|
:- pragma foreign_proc("Java",
|
|
my_c_pred(X::in, Y::in, Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * X;
|
|
").
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pragma foreign_proc("C",
|
|
my_c_func(X::in, Y::in) = (Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * Y;
|
|
").
|
|
:- pragma foreign_proc("C#",
|
|
my_c_func(X::in, Y::in) = (Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * Y;
|
|
").
|
|
:- pragma foreign_proc("Java",
|
|
my_c_func(X::in, Y::in) = (Z::out),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
Z = 2 * Y;
|
|
").
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pragma foreign_proc("C",
|
|
c_hello_world(Msg::in, IO0::di, IO::uo),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
printf(""Hello, world"");
|
|
IO = IO0;
|
|
").
|
|
:- pragma foreign_proc("C#",
|
|
c_hello_world(Msg::in, IO0::di, IO::uo),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
System.Console.WriteLine(""Hello, world"");
|
|
IO = IO0;
|
|
").
|
|
:- pragma foreign_proc("Java",
|
|
c_hello_world(Msg::in, IO0::di, IO::uo),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
System.out.println(""Hello, world"");
|
|
IO = IO0;
|
|
").
|
|
|
|
%---------------------------------------------------------------------------%
|