[m-dev.] for review: add reverse modes of int__xor

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Mar 9 04:19:19 AEDT 2000


Estimated hours taken: 1

Add reverse modes for int__xor, as suggested by
Michael Roe <mroe at 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:
tests/general/arithmetic.exp:
	Add a test of the new modes of int__xor.

NEWS:
	Document the change.

Workspace: /d-drive/home/hg/fjh/mercury
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.163
diff -u -d -r1.163 NEWS
--- NEWS	2000/02/16 08:36:03	1.163
+++ NEWS	2000/03/08 17:05:52
@@ -31,6 +31,8 @@
   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's a new predicate `random__permutation', for
   computing a random permutation of a list.
 
Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.116
diff -u -d -r1.116 code_util.m
--- compiler/code_util.m	2000/01/16 04:34:35	1.116
+++ compiler/code_util.m	2000/03/08 16:27:04
@@ -485,6 +485,10 @@
 	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],
Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.1
diff -u -d -r1.1 ml_call_gen.m
--- compiler/ml_call_gen.m	1999/12/29 08:09:10	1.1
+++ compiler/ml_call_gen.m	2000/03/08 16:28:02
@@ -722,6 +722,10 @@
 	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],
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.44
diff -u -d -r1.44 Mmakefile
--- library/Mmakefile	1999/11/15 08:14:07	1.44
+++ library/Mmakefile	2000/03/08 16:35:12
@@ -15,6 +15,14 @@
 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
 # don't remove the intermediate `.c' files.
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.65
diff -u -d -r1.65 int.m
--- library/int.m	2000/01/16 04:34:28	1.65
+++ library/int.m	2000/03/08 16:32:24
@@ -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.
Index: tests/general/arithmetic.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/arithmetic.m,v
retrieving revision 1.3
diff -u -d -r1.3 arithmetic.m
--- tests/general/arithmetic.m	2000/01/17 05:18:53	1.3
+++ tests/general/arithmetic.m	2000/03/08 16:46:20
@@ -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 @@
 		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 @@
 	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).
Index: tests/general/arithmetic.exp
===================================================================
RCS file: /home/mercury1/repository/tests/general/arithmetic.exp,v
retrieving revision 1.2
diff -u -d -u -r1.2 arithmetic.exp
--- tests/general/arithmetic.exp	2000/01/17 05:18:53	1.2
+++ tests/general/arithmetic.exp	2000/03/08 17:00:16
@@ -10,4 +10,6 @@
 X /\ Y: 0
 X \/ Y: 7
 X `xor` Y: 7
+Z such that X = Z `xor` Y: 7
+Z such that Y = X `xor` Z: 7
 \ X: -4

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list