mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
tests/general/interpreter.{m,inp,exp}:
tests/general/Mmakefile:
As above: delete this test case.
samples/interpreter.m:
Delete reference to the deleted test case.
tests/debugger/interpreter.m:
Delete reference to the deleted test case in this copy of
samples/interpreter.m.
tests/debugger/interpreter.exp:
tests/debugger/interpreter.exp2:
The last update of interpreter.exp was in 2003. The command we invoke
this test case with has changed several times since then, but none
of them have been reflected in interpreter.exp, so now there is no way
for it to be matched. This diff deletes interpreter.exp, and renames
the old interpreter.exp2 to become the new interpreter.exp.
tests/general/arithmetic.nl:
tests/general/interpreter.nl:
tests/general/string_test.nl:
Delete these relics of the time when we compared output generated
by Mercury to output generated by NU-Prolog, since NU-Prolog is long dead.
tests/general/arithmetic.m:
tests/general/string_test.m:
Update programming style, and factor out common code.
66 lines
1.9 KiB
Mathematica
66 lines
1.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% A very basic check of integer arithmetic.
|
|
%
|
|
% Note: this test makes use of Mercury-specific features (specifically
|
|
% the use of "`xor`" rather than "^" for the exclusive or operator,
|
|
% and the use of the reverse modes of xor) so it really belongs in
|
|
% the `tests/hard_coded' directory, rather than the `tests/general'
|
|
% directory... but that distinction is pretty much obsolete now that we
|
|
% don't support compiling things with Prolog.
|
|
|
|
:- module arithmetic.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
test(3, 4, !IO).
|
|
|
|
:- pred test(int::in, int::in, io::di, io::uo) is det.
|
|
|
|
test(X, Y, !IO) :-
|
|
Plus = X + Y,
|
|
Times = X * Y,
|
|
Minus = X - Y,
|
|
Div = X // Y,
|
|
Mod = X mod Y,
|
|
LeftShift = X << Y,
|
|
RightShift = X >> Y,
|
|
BitAnd = X /\ Y,
|
|
BitOr = X \/ Y,
|
|
BitXor = X `xor` Y,
|
|
X = BitXor2 `xor` Y,
|
|
Y = X `xor` BitXor3,
|
|
BitNeg = \ X,
|
|
|
|
write_message("X", X, !IO),
|
|
write_message("Y", Y, !IO),
|
|
write_message("X + Y", Plus, !IO),
|
|
write_message("X * Y", Times, !IO),
|
|
write_message("X - Y", Minus, !IO),
|
|
write_message("X / Y", Div, !IO),
|
|
write_message("X mod Y", Mod, !IO),
|
|
write_message("X << Y", LeftShift, !IO),
|
|
write_message("X >> Y", RightShift, !IO),
|
|
write_message("X /\\ Y", BitAnd, !IO),
|
|
write_message("X \\/ Y", BitOr, !IO),
|
|
write_message("X `xor` Y", BitXor, !IO),
|
|
write_message("Z such that X = Z `xor` Y", BitXor2, !IO),
|
|
write_message("Z such that Y = X `xor` Z", BitXor3, !IO),
|
|
write_message("\\ X", BitNeg, !IO).
|
|
|
|
:- pred write_message(string::in, int::in, io::di, io::uo) is det.
|
|
|
|
write_message(Msg, N, !IO) :-
|
|
io.format("%s: %d\n", [s(Msg), i(N)], !IO).
|