mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 600 Branches: main Implemented state variable transformation. NEWS: Record new syntax and withdrawl of !/0 as Prolog cut. compiler/hlds_goal.m: compiler/hlds_out.m: Added implicit/1 constructor to unify_main_context for cases where variables are introduced by compiler transformations. compiler/make_hlds.m: Integrated the state variable transformation with the conversion to HLDS. Changed references to foreign_type and du_type constructors to match recent changes to the foreign type interface. compiler/mercury_compile.m: Removed two unnecessary Prolog cuts left over from the Dark Ages. compiler/mercury_to_mercury.m: Added code to output the new goal_expr constructors for state variable quantifiers (some_state_vars and all_state_vars.) Adapted to handle changes to if_then and if_then_else goal_expr constructors which now include lists of state variables that scope over the condition- and then-goals. compiler/module_qual.m: compiler/prog_util.m: Changes to handle some_state_vars, all_state_vars, and changes to if_then and if_then_else goal_expr constructors. compiler/prog_data.m: Added some_state_vars, all_state_vars constructors and changed if_then and if_then_else constructors in type goal_expr. compiler/prog_io_dcg.m: Changes to handle quantified state variables. compiler/prog_io_goal.m: parse_some_vars_goal now also separates out quantified state variables. compiler/prog_io_util.m: Added pred parse_quantifier_vars/3 which also detects state variables. compiler/typecheck.m: Added case to report_error_undef_cons to handle any uncaught uses of !/1. doc/reference_manual.texi: Documented the transformation. library/builtin.m: library/prolog.m: Deleted code for `!' as fake Prolog cut. library/lexer.m: Made `!' a graphic token rather char than a special token. library/ops.m: Added `!', `!.' and `!:' as prefix ops. library/term.m: Added func var_id/1 which returns an int associated with its var argument which is unique in the context of the given var and the varset it belongs to. library/varset.m: Added pred new_uniquely_named_var/4 which creates a named variable with a unique (w.r.t. the varset) number suffix. tests/general/Mmakefile: tests/general/state_vars_tests.exp: tests/general/state_vars_tests.m: tests/general/state_vars_typeclasses.exp: tests/general/state_vars_typeclasses.m: tests/invalid/Mmakefile: tests/invalid/state_vars_test1.err_exp: tests/invalid/state_vars_test1.m: tests/invalid/state_vars_test2.err_exp: tests/invalid/state_vars_test2.m: tests/invalid/state_vars_test3.err_exp: tests/invalid/state_vars_test3.m: tests/invalid/state_vars_test4.err_exp: tests/invalid/state_vars_test4.m: tests/invalid/state_vars_test5.err_exp: tests/invalid/state_vars_test5.m: Added.
114 lines
3.2 KiB
Mathematica
114 lines
3.2 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.
|
|
|
|
% 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.
|
|
|
|
% 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")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|