mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 13:23:53 +00:00
Estimated hours taken: 6
Fix various invasions of the user's namespace by `mercury_builtin.m',
by splitting mercury_builtin.m into two modules, called builtin.m and
private_builtin.m, and ensuring that the latter is imported as if
by `:- use_module' rather than `:- import_module'.
library/builtin.m:
library/private_builtin.m:
Split mercury_builtin.m into two modules, builtin.m,
which contains stuff intended to be public,
and private_builtin.m, which contains implementation
details that are not supposed to be public.
library/mercury_builtin.m:
Add a comment saying that this module is no longer used, and
should eventually be removed. I have not removed it yet, since
that would prevent bootstrapping with the current compiler. It
will be removed as a seperate change later, once all the
changes have propagated.
compiler/prog_util.m:
Change the definition of mercury_private_builtin_module/1 and
mercury_public_builtin_module so that instead of automatically
importing mercury_builtin.m as if by `import_module', the
copiler will now automatically import builtin.m as if by
`import_module' and private_builtin.m as if by `use_module'.
compiler/polymorphism.m:
Change a call to mercury_private_builtin_module/1 for
unsafe_promise_unique to instead call mercury_public_builtin_module/1.
compiler/unify_proc.m:
Avoid hard-coding "mercury_builtin" by instead
calling one of mercury_{private,public}_builtin_module/1.
runtime/mercury_type_info.[ch]:
library/term.m:
library/std_util.m:
compiler/code_util.m:
Change a few hard-coded instances of "mercury_builtin"
to "builtin" or "private_builtin" as appropriate.
runtime/mercury_trace_util.c:
runtime/mercury_trace_internal.c:
library/prolog.m:
compiler/*.m:
Update comments that refer to "mercury_builtin" to instead
refer to either "builtin" or "private_builtin".
doc/Mmakefile:
Don't include the interface to private_builtin.m in the
library reference manual.
tools/bootcheck:
Add `-p'/`--copy-profiler' option. This is needed to get
the above changes to bootstrap.
tools/test_mercury:
Pass `-p' to tools/bootcheck.
tests/term/*.trans_opt_exp:
s/mercury_builtin/builtin/g
134 lines
3.7 KiB
Mathematica
134 lines
3.7 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998 The 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.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% File: prolog.m.
|
|
% Main author: fjh.
|
|
|
|
% This file contains predicates that are intended to help people
|
|
% porting Prolog programs, or writing programs in the intersection
|
|
% of Mercury and Prolog.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- module prolog.
|
|
:- interface.
|
|
:- import_module std_util, list.
|
|
|
|
% We define !/0 (and !/2 for dcgs) to be equivalent to `true'. This is for
|
|
% backwards compatibility with Prolog systems. But of course it only works
|
|
% if all your cuts are green cuts.
|
|
|
|
/********
|
|
cut is currently defined in builtin.m, for historical reasons.
|
|
|
|
:- pred ! is det.
|
|
|
|
:- pred !(T, T).
|
|
:- mode !(di, uo) is det.
|
|
:- mode !(in, out) is det.
|
|
********/
|
|
|
|
% Prolog arithmetic operators.
|
|
|
|
:- pred T =:= T. % In Mercury, just use =
|
|
:- mode in =:= in is semidet.
|
|
|
|
:- pred T =\= T. % In Mercury, just use \=
|
|
:- mode in =\= in is semidet.
|
|
|
|
/*******
|
|
is/2 is currently defined in int.m, for historical reasons.
|
|
|
|
:- pred is(T, T) is det. % In Mercury, just use =
|
|
:- mode is(uo, di) is det.
|
|
:- mode is(out, in) is det.
|
|
******/
|
|
|
|
% Prolog term comparison operators.
|
|
|
|
:- pred T == T. % In Mercury, just use =
|
|
:- mode in == in is semidet.
|
|
|
|
:- pred T \== T. % In Mercury, just use \=
|
|
:- mode in \== in is semidet.
|
|
|
|
:- pred T @< T.
|
|
:- mode in @< in is semidet.
|
|
|
|
:- pred T @=< T.
|
|
:- mode in @=< in is semidet.
|
|
|
|
:- pred T @> T.
|
|
:- mode in @> in is semidet.
|
|
|
|
:- pred T @>= T.
|
|
:- mode in @>= in is semidet.
|
|
|
|
% Prolog's so-called "univ" operator, `=..'.
|
|
% Note: this is not related to Mercury's "univ" type!
|
|
% In Mercury, use `expand' (defined in module `std_util') instead.
|
|
|
|
:- pred T =.. univ_result.
|
|
:- mode in =.. out is det.
|
|
%
|
|
% Note that the Mercury =.. is a bit different to the Prolog
|
|
% one. We could make it slightly more similar by overloading '.'/2,
|
|
% but that would cause ambiguities that might prevent type
|
|
% inference in a lot of cases.
|
|
%
|
|
% :- type univ_result ---> '.'(string, list(univ)).
|
|
:- type univ_result == pair(string, list(univ)).
|
|
|
|
% arg/3. In Mercury, use argument/3 (defined in module std_util)
|
|
% instead:
|
|
% arg(ArgNum, Term, Data) :- argument(Term, ArgNum - 1, Data).
|
|
%
|
|
:- pred arg(int::in, T::in, univ::out) is semidet.
|
|
|
|
% det_arg/3: like arg/3, but calls error/1 rather than failing
|
|
% if the index is out of range.
|
|
%
|
|
:- pred det_arg(int::in, T::in, univ::out) is det.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
:- import_module require, int.
|
|
|
|
/*********
|
|
% !/0 and !/2 currently defined in builtin.m, for historical reasons.
|
|
!.
|
|
!(X, X).
|
|
*********/
|
|
|
|
% we use module qualifiers here to avoid
|
|
% overriding the builtin Prolog versions
|
|
|
|
'prolog__=='(X, X).
|
|
'prolog__\\=='(X, Y) :- X \= Y.
|
|
|
|
'prolog__=:='(X, X).
|
|
'prolog__=\\='(X, Y) :- X \= Y.
|
|
|
|
'prolog__@<'(X, Y) :- compare(<, X, Y).
|
|
'prolog__@>'(X, Y) :- compare(>, X, Y).
|
|
'prolog__@=<'(X, Y) :- compare(R, X, Y), R \= (>).
|
|
'prolog__@>='(X, Y) :- compare(R, X, Y), R \= (<).
|
|
|
|
'prolog__=..'(Term, Functor - Args) :-
|
|
deconstruct(Term, Functor, _Arity, Args).
|
|
|
|
% we use a module qualifier here to avoid
|
|
% overriding the builtin Prolog version
|
|
prolog__arg(ArgumentIndex, Type, argument(Type, ArgumentIndex - 1)).
|
|
|
|
det_arg(ArgumentIndex, Type, Argument) :-
|
|
( arg(ArgumentIndex, Type, Arg) ->
|
|
Argument = Arg
|
|
;
|
|
error("det_arg: arg failed")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|