[m-rev.] diff: finish change to throw exceptions for division by zero

Simon Taylor stayl at cs.mu.OZ.AU
Thu Sep 6 18:27:28 AEST 2001


Estimated hours taken: 0.25
Branches: main

Finish off the change to throw exceptions for division by zero.

library/float.m:
library/int.m:
	Remove clauses for {int,float}__unchecked_quotient.
	They are now builtin.

compiler/make_hlds.m:
	Reenable `--halt-at-warn' for the warnings for clauses for builtins.

configure.in:
	Check that `X/0' throws an exception when compiled with the
	compiler to be used for bootstrapping. If it doesn't, the old
	compiler will halt after warning about the clauses for
	`int://'/2 and `float:/'/2.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.277
diff -u -u -r1.277 configure.in
--- configure.in	2001/09/04 08:28:47	1.277
+++ configure.in	2001/09/06 08:23:09
@@ -97,23 +97,24 @@
 		:- module conftest.
 		:- interface.
 		:- import_module io.
-		:- pred main(io__state::di, io__state::uo) is det.
+		:- pred main(io__state::di, io__state::uo) is cc_multi.
 
 		:- implementation.
-	
+		:- import_module int, exception.
         
-		% Different bodies for different modes.
-		:- pragma promise_pure(foo/1).
-		:- pred foo(int).
-		:- mode foo(out) is det.
-		:- mode foo(in) is semidet.
-		foo(X::in) :-
-			X = 42.
-		foo(X::out) :-
-			X = 42.
-
+		% Check that X/0 throws an exception. If it doesn't,
+		% the old compiler will report an error for the clauses
+		% for int:// and float:/, which according to the old
+		% compiler should be builtins.
+		% Also check for unchecked_int_quotient, which is a builtin
+		% present only in recent compilers.
 		main --> 
-			( { foo(42) } ->
+			{ try(
+				(pred(Value::out) is det :-
+					Value = 42 // 0 +
+						unchecked_quotient(10, 2)
+				), Result) },
+			( { Result = exception(_) } ->
 				print("Hello, world\n")
 			;
 				print("Nope.\n")
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.383
diff -u -u -r1.383 make_hlds.m
--- compiler/make_hlds.m	2001/08/28 14:30:10	1.383
+++ compiler/make_hlds.m	2001/09/06 06:28:34
@@ -3662,10 +3662,7 @@
 		{ code_util__predinfo_is_builtin(PredInfo1) }
 	->
 		prog_out__write_context(Context),
-		% XXX change this back to use report_warning
-		% after the change to add {int,float}__checked_quotient
-		% is installed everywhere.
-		io__write_string("Warning: clause for builtin.\n"),
+		report_warning("Warning: clause for builtin.\n"),
 		{ ModuleInfo = ModuleInfo1 },
 		{ Info = Info0 }
 	;
Index: library/float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/float.m,v
retrieving revision 1.37
diff -u -u -r1.37 float.m
--- library/float.m	2001/09/02 12:20:12	1.37
+++ library/float.m	2001/09/06 06:51:44
@@ -330,25 +330,13 @@
 % The other arithmetic and comparison operators are builtins,
 % which the compiler expands inline.  We don't need to define them here.
 
-	% XXX This pragma declaration should be uncommented once the
-	% change to make `//'/2 a non-builtin is installed everywhere.
-%:- pragma inline('/'/2).
+:- pragma inline('/'/2).
 X / Y = Z :-
 	( domain_checks, Y = 0.0 ->
 		throw(math__domain_error("float:'/'"))
 	;
 		Z = unchecked_quotient(X, Y)
 	).
-
-	% implementation of int__unchecked_quotient.
-	% XXX Remove this clause once the change to make unchecked_quotient
-	% a builtin is installed everywhere. (Note that this clause doesn't
-	% cause an infinite loop because the compiler will ignore the
-	% clause for `/'/2 or unchecked_quotient/2 depending on how far
-	% it is through the bootstrapping process. When compiling the
-	% stage 1 compiler, `/' is builtin. During stages 2 and 3,
-	% unchecked_quotient is builtin.
-unchecked_quotient(X, Y) = X / Y.
 
 	% This code is included here rather than just calling
 	% the version in math.m because we currently don't do
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.76
diff -u -u -r1.76 int.m
--- library/int.m	2001/09/02 12:20:12	1.76
+++ library/int.m	2001/09/06 06:52:00
@@ -284,9 +284,7 @@
 		Div = Trunc - 1
 	).
 
-	% XXX This pragma declaration should be uncommented once the
-	% change to make `//'/2 a non-builtin is installed everywhere.
-%:- pragma inline('//'/2).
+:- pragma inline('//'/2).
 X // Y = Div :-
 	( domain_checks, Y = 0 ->
 		throw(math__domain_error("int:'//'"))
@@ -319,15 +317,6 @@
 	SUCCESS_INDICATOR = TRUE;
 #endif
 ").
-
-	% XXX Remove this clause once the change to make unchecked_quotient
-	% a builtin is installed everywhere. (Note that this clause doesn't
-	% cause an infinite loop because the compiler will ignore the
-	% clause for `//'/2 or unchecked_quotient/2 depending on how far
-	% it is through the bootstrapping process. When compiling the
-	% stage 1 compiler, `//' is builtin. During stages 2 and 3,
-	% unchecked_quotient is builtin.
-unchecked_quotient(X, Y) = X // Y.
 
 :- pragma inline(floor_to_multiple_of_bits_per_int/1).
 floor_to_multiple_of_bits_per_int(X) = Floor :-
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list