Files
mercury/tests/invalid_purity/purity.m
Julien Fischer 1ab13edca6 Switch over unary and binary ops in Java and C# code generators.
Fix more failing test cases in the non-C grades.

compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
    Always switch over unary and binary ops.  The existing code predates
    the addition of multi-arm switches to the language and was intended to
    the code duplication that would result in the absence of that feature.
    Since we now have multi-arm switches it is by far preferable to use
    a switch in these places.

    XXX for binary ops the above change replicates what the existing code
    did; I think it should actually abort in some cases.

    Fix spelling.

    Delete trailing whitespace.

compiler/java_util.m:
    Delete this module, it isn't used anymore.

compiler/ml_backend.m:
    Delete the include of the java_util module.

compiler/c_util.m:
    Update a comment.

tests/exceptions/Mmakefile:
    Fix the failure of 'test_uncaught_exception' in the java grade by
    filtering out the stack trace generated by the JVM.

tests/hard_coded/float_reg.exp4:
    Alternative expected output for this due to the way floats are
    printed.

tests/invalid_purity/purity.m:
tests/invalid_purity/purity.err_exp:
    Add C# and Java foreign_procs and updated the expected output.

tests/warnings/Mmakefile:
    Fix my previous change, which broke things in non-Erlang grades.
2016-02-07 22:38:16 +11:00

219 lines
3.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module purity.
:- interface.
%----------------------------------------------------------------
% Needed for later tests.
:- type foo
---> a
; b.
:- implementation.
:- impure pred imp is det.
:- pragma foreign_proc("C",
imp,
[will_not_call_mercury],
"
;
").
:- pragma foreign_proc("Java",
imp,
[will_not_call_mercury],
"
;
").
:- pragma foreign_proc("C#",
imp,
[will_not_call_mercury],
"
;
").
:- semipure pred semi is semidet.
:- pragma foreign_proc("C",
semi,
[promise_semipure, will_not_call_mercury],
"
SUCCESS_INDICATOR = 0;
").
:- pragma foreign_proc("Java",
semi,
[promise_semipure, will_not_call_mercury],
"
SUCCESS_INDICATOR = false;
").
:- pragma foreign_proc("C#",
semi,
[promise_semipure, will_not_call_mercury],
"
SUCCESS_INDICATOR = false;
").
:- pred in(foo).
:- mode in(in) is semidet.
in(a).
:- semipure pred semi(foo::in) is semidet.
:- pragma foreign_proc("C",
semi(X::in),
[will_not_call_mercury, promise_semipure],
"
/* X */
SUCCESS_INDICATOR = 0;
").
:- pragma foreign_proc("Java",
semi(X::in),
[will_not_call_mercury, promise_semipure],
"
/* X */
SUCCESS_INDICATOR = false;
").
:- pragma foreign_proc("C#",
semi(X::in),
[will_not_call_mercury, promise_semipure],
"
/* X */
SUCCESS_INDICATOR = false;
").
:- impure pred imp1(foo).
:- mode imp1(in) is semidet.
:- pragma foreign_proc("C",
imp1(_X::in),
[will_not_call_mercury],
"
SUCCESS_INDICATOR = 0;
").
:- pragma foreign_proc("Java",
imp1(_X::in),
[will_not_call_mercury],
"
SUCCESS_INDICATOR = false;
").
:- pragma foreign_proc("C#",
imp1(_X::in),
[will_not_call_mercury],
"
SUCCESS_INDICATOR = false;
").
%----------------------------------------------------------------
% Warnings.
:- impure pred w1 is det.
w1.
:- semipure pred w2 is det.
w2.
:- impure pred w3 is semidet.
w3 :- semipure semi.
:- pred w4 is det.
:- pragma promise_pure(w4/0).
w4.
:- impure pred w5 is det.
:- pragma promise_pure(w5/0).
w5 :- impure imp.
:- semipure pred w6 is semidet.
:- pragma promise_pure(w6/0).
w6 :- semipure semi.
%----------------------------------------------------------------
% Errors.
:- pred e1 is det.
e1 :- impure imp.
:- pred e2 is semidet.
e2 :- semipure semi.
:- semipure pred e3 is det.
e3 :- impure imp.
:- impure pred e4 is det.
e4 :- imp.
:- semipure pred e5 is semidet.
e5 :- semi.
:- impure pred e6 is semidet.
e6 :-
in(X),
impure imp,
X = a.
:- impure pred e7 is semidet.
e7 :-
impure imp1(X),
X = a.
:- type e8 ---> e8(foo) where equality is imp2.
:- impure pred imp2(e8, e8).
:- mode imp2(in, in) is semidet.
:- pragma foreign_proc("C",
imp2(_X::in, _Y::in),
[will_not_call_mercury],
"
SUCCESS_INDICATOR = 0;
").
:- type e9 ---> e9(foo) where equality is semi2.
:- semipure pred semi2(e9, e9).
:- mode semi2(in, in) is semidet.
:- pragma foreign_proc("C",
semi2(_X::in, _Y::in),
[promise_semipure, will_not_call_mercury],
"
SUCCESS_INDICATOR = 0;
").
:- pred e10 is semidet.
e10 :-
Goal1 = (pred(X::in) is semidet :- imp1(X)),
call(Goal1, b).
:- pred e11 is semidet.
e11 :-
Goal2 = (pred(X::in) is semidet :- semi(X)),
call(Goal2, b).
imp.
semi :- semidet_fail.
imp1(_) :- semidet_fail.
imp2(_, _) :- semidet_fail.
semi2(_, _) :- semidet_fail.