[m-rev.] diff: add expect/3 as a replacement for require/2 in compiler
Julien Fischer
juliensf at cs.mu.OZ.AU
Fri Nov 18 15:56:47 AEDT 2005
Estimated hours taken: 0.1
Branches: main
compiler/compiler_util.m:
Add expect/3 as a replacement for require/2 in the compiler.
compiler/notes/coding_standards.html:
Update some references: s/error_util/compiler_util/
Mention that in the compiler we should use expect/3 rather
than require/2.
Julien.
Index: compiler/compiler_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compiler_util.m,v
retrieving revision 1.2
diff -u -r1.2 compiler_util.m
--- compiler/compiler_util.m 17 Nov 2005 15:57:05 -0000 1.2
+++ compiler/compiler_util.m 18 Nov 2005 04:47:31 -0000
@@ -36,6 +36,12 @@
%
:- func unexpected(string, string) = _ is erroneous.
:- pred unexpected(string::in, string::in) is erroneous.
+
+ % expect(Goal, ModuleName, Message):
+ %
+ % Call Goal, and call unexpected(ModuleName, Message) if Goal fails.
+ %
+:- pred expect((pred)::((pred) is semidet), string::in, string::in) is det.
% Record the fact that a warning has been issued; set the exit status
% to error if the `--halt-at-warn' option is set.
@@ -81,6 +87,13 @@
string__format("%s: Unexpected: %s", [s(Module), s(What)], ErrorMessage),
error(ErrorMessage).
+expect(Goal, Module, Message) :-
+ ( Goal ->
+ true
+ ;
+ unexpected(Module, Message)
+ ).
+
record_warning(!IO) :-
globals__io_lookup_bool_option(halt_at_warn, HaltAtWarn, !IO),
(
Index: compiler/notes/coding_standards.html
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/notes/coding_standards.html,v
retrieving revision 1.19
diff -u -r1.19 coding_standards.html
--- compiler/notes/coding_standards.html 10 May 2005 04:58:30 -0000 1.19
+++ compiler/notes/coding_standards.html 18 Nov 2005 04:51:23 -0000
@@ -143,8 +143,9 @@
Calls to error/1 should always indicate an internal software error,
not merely incorrect inputs from the user,
or failure of some library routine or system call.
-In the compiler, use unexpected/2 or sorry/2 from error_util.m
-rather than error/1.
+In the compiler, use unexpected/2 or sorry/2 from compiler_util.m
+rather than error/1. Use expect/3 from compiler_util rather than
+require/2.
<p>
--------------------------------------------------------------------------
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