[m-rev.] diff: fix `--make-opt-int' exit status

Simon Taylor stayl at cs.mu.OZ.AU
Mon Feb 17 17:02:38 AEDT 2003


Estimated hours taken: 0.25
Branches: main, release

compiler/mercury_compile.m:
	Return the correct exit status if errors are reported
	when building the `.opt' file.

tests/hard_coded/foreign_type.m:
	Fix a compilation error which did not cause a failure
	before this change.

tests/invalid/Mmakefile:
tests/invalid/make_opt_error.{m,err_exp}:
 	Test case.

Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.274
diff -u -u -r1.274 mercury_compile.m
--- compiler/mercury_compile.m	16 Feb 2003 02:16:36 -0000	1.274
+++ compiler/mercury_compile.m	17 Feb 2003 02:50:55 -0000
@@ -1301,7 +1301,15 @@
 		)
 	    )
 	;
-	    []
+	    	% If the number of errors is > 0, make sure that
+		% the compiler exits with a non-zero exit
+		% status.
+	    io__get_exit_status(ExitStatus),
+	    ( { ExitStatus = 0 } ->
+	    	io__set_exit_status(1)
+	    ;
+	    	[]
+	    )
 	).
 
 	% return `yes' iff this module defines the main/2 entry point.
@@ -1528,7 +1536,8 @@
 	parse_tree_to_hlds(Prog, MQInfo, EqvMap, HLDS, QualInfo,
 		UndefTypes, UndefModes),
 	{ module_info_num_errors(HLDS, NumErrors) },
-	( { NumErrors > 0 } ->
+	io__get_exit_status(Status),
+	( { Status \= 0 ; NumErrors > 0 } ->
 		{ FoundSemanticError = yes },
 		io__set_exit_status(1)
 	;
Index: tests/hard_coded/foreign_type.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/foreign_type.m,v
retrieving revision 1.4
diff -u -u -r1.4 foreign_type.m
--- tests/hard_coded/foreign_type.m	5 Aug 2002 21:46:22 -0000	1.4
+++ tests/hard_coded/foreign_type.m	17 Feb 2003 03:31:21 -0000
@@ -98,8 +98,6 @@
 :- type coord ---> coord(x :: int, y :: int).
 
 new(X, Y) = coord(X, Y).
-x(C) = C ^ x.
-y(C) = C ^ y.
 
 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.134
diff -u -u -r1.134 Mmakefile
--- tests/invalid/Mmakefile	12 Feb 2003 22:58:19 -0000	1.134
+++ tests/invalid/Mmakefile	17 Feb 2003 03:29:51 -0000
@@ -76,6 +76,7 @@
 	invalid_typeclass \
 	io_in_ite_cond \
 	lambda_syntax_error \
+	make_opt_error \
 	merge_ground_any \
 	method_impl \
 	missing_det_decls \
@@ -236,7 +237,17 @@
 # For these test cases, the bug is caught when generating dependencies,
 # so it is easiest just to do that step.
 nested_impl_in_int.err duplicate_module_test.err: %.err: %.m
-	if $(MC) --generate-dependencies $* > $*.err 2>&1; \
+	if $(MC) $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
+			--generate-dependencies $* > $*.err 2>&1; \
+	then false; \
+	else true; \
+	fi
+
+# This test case tests that we set the error status correctly
+# when building the `.opt' files.
+make_opt_error.err: make_opt_error.m
+	if $(MC) $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
+			--make-optimization-interface $* > $*.err 2>&1; \
 	then false; \
 	else true; \
 	fi
Index: tests/invalid/make_opt_error.err_exp
===================================================================
RCS file: tests/invalid/make_opt_error.err_exp
diff -N tests/invalid/make_opt_error.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/make_opt_error.err_exp	17 Feb 2003 03:29:56 -0000
@@ -0,0 +1,5 @@
+make_opt_error.m:101: Error: clause for automatically generated field access
+make_opt_error.m:101:   function `make_opt_error.x/1'.
+make_opt_error.m:102: Error: clause for automatically generated field access
+make_opt_error.m:102:   function `make_opt_error.y/1'.
+For more information, try recompiling with `-E'.
Index: tests/invalid/make_opt_error.m
===================================================================
RCS file: tests/invalid/make_opt_error.m
diff -N tests/invalid/make_opt_error.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/make_opt_error.m	17 Feb 2003 02:58:01 -0000
@@ -0,0 +1,105 @@
+:- module make_opt_error.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- type coord.
+
+:- func new(int, int) = coord.
+:- pragma export(new(in, in) = out, "exported_new").
+
+:- func x(coord) = int.
+:- func y(coord) = int.
+
+main -->
+	{ C = new(4, 5) },
+	io__write_string("X:"),
+	io__write_int(x(C)),
+	io__nl,
+	io__write_string("Y:"),
+	io__write_int(y(C)),
+	io__nl.
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+
+% IL implementation
+:- pragma foreign_type(il, coord,
+	"class [foreign_type__csharp_code]coord").
+
+:- pragma foreign_decl("C#", "
+public class coord {
+	public int x;
+	public int y;
+}
+").
+
+:- pragma foreign_proc("C#", new(X::in, Y::in) = (C::out),
+	[will_not_call_mercury, promise_pure],
+"
+	C = new coord();
+	C.x = X;
+	C.y = Y;
+").
+
+:- pragma foreign_proc("C#", x(C::in) = (X::out),
+	[will_not_call_mercury, promise_pure],
+"
+	X = C.x;
+").
+
+:- pragma foreign_proc("C#", y(C::in) = (Y::out),
+	[will_not_call_mercury, promise_pure],
+"
+	Y = C.y;
+").
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+
+% C implementation
+:- pragma foreign_type(c, coord, "coord *").
+
+:- pragma foreign_decl(c, "
+typedef struct {
+	int x, y;
+} coord;
+").
+
+:- pragma foreign_proc(c, new(X::in, Y::in) = (C::out),
+	[will_not_call_mercury, promise_pure],
+"
+	C = MR_GC_NEW(coord);
+	C->x = X;
+	C->y = Y;
+").
+
+:- pragma foreign_proc(c, x(C::in) = (X::out),
+	[will_not_call_mercury, promise_pure],
+"
+	X = C->x;
+").
+
+:- pragma foreign_proc(c, y(C::in) = (Y::out),
+	[will_not_call_mercury, promise_pure],
+"
+	Y = C->y;
+").
+
+%----------------------------------------------------------------------------%
+
+% Mercury implementation
+:- type coord ---> coord(x :: int, y :: int).
+
+new(X, Y) = coord(X, Y).
+x(C) = C ^ x.
+y(C) = C ^ y.
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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