Add reverse modes for int__xor, as suggested by

Estimated hours taken: 1

Add reverse modes for int__xor, as suggested by
Michael Roe <mroe@microsoft.com>.

library/int.m:
	Declare the new modes for int__xor.

library/Mmakefile:
	Compile int.m with `--no-halt-at-warn'.  This is needed
	because when compiling with the old compiler that doesn't
	know about these new modes, the old compiler gives a
	warning about the extra modes.

compiler/code_util.m:
compiler/ml_call_gen.m:
	Add code to implement the new modes for the builtin int__xor.

tests/general/arithmetic.m:
	Add a test of the new modes of int__xor.

NEWS:
	Document the change.
This commit is contained in:
Fergus Henderson
2000-03-13 04:00:43 +00:00
parent b61650251e
commit 00ffa8d3db
6 changed files with 33 additions and 2 deletions

2
NEWS
View File

@@ -31,6 +31,8 @@ Changes to the standard library:
Use `int__xor/2' and `integer__xor/2' instead.
The operator `^' is now used for record syntax.
* We've added reverse modes for `int__xor'.
* There is a new predicate `random__permutation', for
computing a random permutation of a list.

View File

@@ -485,6 +485,10 @@ code_util__translate_builtin_2("int", "builtin_bit_xor", 0, [X, Y, Z],
no, yes(Z - binop((^), var(X), var(Y)))).
code_util__translate_builtin_2("int", "xor", 0, [X, Y, Z],
no, yes(Z - binop((^), var(X), var(Y)))).
code_util__translate_builtin_2("int", "xor", 1, [X, Y, Z],
no, yes(Y - binop((^), var(X), var(Z)))).
code_util__translate_builtin_2("int", "xor", 2, [X, Y, Z],
no, yes(X - binop((^), var(Y), var(Z)))).
code_util__translate_builtin_2("int", "builtin_unary_plus", 0, [X, Y],
no, yes(Y - var(X))).
code_util__translate_builtin_2("int", "+", 0, [X, Y],

View File

@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
% Copyright (C) 1999 The University of Melbourne.
% Copyright (C) 1999-2000 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -722,6 +722,10 @@ ml_translate_builtin_2("int", "^", 0, [X, Y, Z],
no, yes(Z - binop((^), lval(X), lval(Y)))).
ml_translate_builtin_2("int", "xor", 0, [X, Y, Z],
no, yes(Z - binop((^), lval(X), lval(Y)))).
ml_translate_builtin_2("int", "xor", 1, [X, Y, Z],
no, yes(Y - binop((^), lval(X), lval(Z)))).
ml_translate_builtin_2("int", "xor", 2, [X, Y, Z],
no, yes(X - binop((^), lval(Y), lval(Z)))).
ml_translate_builtin_2("int", "builtin_unary_plus", 0, [X, Y],
no, yes(Y - lval(X))).
ml_translate_builtin_2("int", "+", 0, [X, Y],

View File

@@ -1,5 +1,5 @@
#-----------------------------------------------------------------------------#
# Copyright (C) 1997-1999 The University of Melbourne.
# Copyright (C) 1997-2000 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
@@ -14,6 +14,14 @@ MAIN_TARGET=mercury
VPATH=.
#-----------------------------------------------------------------------------#
#
# XXX The following is needed only for bootstrapping
# the new modes of int__xor.
#
MCFLAGS-int = --no-halt-at-warn
#-----------------------------------------------------------------------------#
# If we're going to generate both `.o' files and `.pic_o' files, then

View File

@@ -151,6 +151,8 @@
% bitwise exclusive or (xor)
:- func int__xor(int, int) = int.
:- mode int__xor(in, in) = uo is det.
:- mode int__xor(in, uo) = in is det.
:- mode int__xor(uo, in) = in is det.
% bitwise complement
:- func \ int = int.

View File

@@ -1,5 +1,12 @@
% 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.
@@ -28,6 +35,8 @@ test(X, Y) -->
BitAnd is X /\ Y,
BitOr is X \/ Y,
BitXor is X `xor` Y,
X is BitXor2 `xor` Y,
Y is X `xor` BitXor3,
BitNeg is \ X
},
write_message("X: ", X),
@@ -42,6 +51,8 @@ test(X, Y) -->
write_message("X /\\ Y: ", BitAnd),
write_message("X \\/ Y: ", BitOr),
write_message("X `xor` Y: ", BitXor),
write_message("Z such that X = Z `xor` Y: ", BitXor2),
write_message("Z such that Y = X `xor` Z: ", BitXor3),
write_message("\\ X: ", BitNeg).
:- pred write_message(string, int, io__state, io__state).