Files
mercury/library/require.m
Fergus Henderson 39eaab90c0 Move the C implementation of various builtins from the `runtime' directory
Estimated hours taken: 24

Move the C implementation of various builtins from the `runtime' directory
to inside pragma(c_code) declarations in the `library' directory sources.

library/{io,string,require,std_util,mercury_builtin}.m:
	Add lots of pragma(c_code) and pragma(c_header_code) declarations.

Also a few other miscellaneous changes.

library/list.m:
	Fix a bug in the as yet unused list__merge_sort.

library/io.m:
	Combine io__do_open_{input,output,append} into a single
	predicate io__do_open.

library/std_util.m:
	Fix the implementation of report_statistics so that it gives
	useful information when using conservative garbage collection.
1996-02-28 14:52:32 +00:00

62 lines
1.6 KiB
Mathematica

%---------------------------------------------------------------------------%
% Copyright (C) 1995 University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
:- module require.
% Main author: fjh.
% Stability: medium to high.
% This module provides features similar to <assert.h> in C.
%-----------------------------------------------------------------------------%
:- interface.
:- pred error(string).
:- mode error(in) is erroneous.
% error(Message).
% Abort with error message.
:- pred require(pred, string).
:- mode require((pred) is semidet, in) is det.
% require(Goal, Message).
% Call goal, and abort with error message if Goal fails.
% This is not as useful as you might imagine, since it requires
% that the goal not produce any output variables. In
% most circumstances you should use an explicit if-then-else
% with a call to error/1 in the "else".
%-----------------------------------------------------------------------------%
:- implementation.
require(Goal, Message) :-
( call(Goal) ->
true
;
error(Message),
fail
).
%-----------------------------------------------------------------------------%
/* error/1, from require.m */
:- pragma(c_code, error(Message::in), "
fflush(stdout);
fprintf(stderr, ""Software error: %s\\n"", Message);
exit(1);
#ifndef USE_GCC_NONLOCAL_GOTOS
return 0; /* suppress some dumb warnings */
#endif
").
:- end_module require.
/*---------------------------------------------------------------------------*/