mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 18:33:58 +00:00
Most modules that imported the old term.m need only a small subset
of its functionality. After this diff, most modules that used to import
term.m will need to import just one more module, and will import many
fewer predicates and functions in total.
library/term_int.m:
A new module carved out of term.m containing the predicates
that recognize terms containing integers, and the functions
that construct such terms.
While this job has *some* similarity to the job of the existing
term_conversion.m module, most modules in the compiler use only one
of those two modules, so merging them would not be a good idea.
library/term_subst.m:
A new module carved out of term.m containing code to do
substitutions and renames of various kinds.
Rename the occurs predicate as var_occurs_in_subst_term,
and occurs_list as var_occurs_in_subst_terms, since the latter
are much more descriptive. Change the argument order to match
the new names (var, subst, term/terms), as the old one did not
even have the term/terms and the substitution next to each other,
even though neither makes sense without the other.
library/term_unify.m:
A new module carved out of term.m containing code to do unifications.
Give all the predicates more meaningful names:
unify_term -> unify_terms
unify_term_list -> unify_term_lists
unify_term_dont_bind -> unify_terms_dont_bind
unify_term_list_dont_bind -> unify_term_lists_dont_bind
list_subsumes -> first_term_list_subsumes_second
library/term_vars.m:
A new module carved out of term.m containing code that find variables
in terms.
Give all the predicates more meaningful names:
vars -> vars_in_term
vars_2 -> vars_in_term_acc
vars_list -> vars_in_terms
contains_var -> term_contains_var
contains_var_list -> terms_contain_var
Don't move the function version of vars_2 to term_vars.m, effectively
deleting it, since operations that update an accumulator are awkward
for functions.
library/term.m:
Keep the moved predicates and functions in term.m, but
- change their implementation to simply call the moved copy, and
- obsolete the original in favor of the moved copy.
Eventually, after either the next release or the release after the next,
we should delete the obsoleted predicates and functions.
library/MODULES_DOC:
library/library.m:
Add the new modules as documented parts of the standard library.
browser/interactive_query.m:
compiler/analysis.file.m:
compiler/det_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/parse_class.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_sym_name.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_defn.m:
compiler/parse_util.m:
compiler/prog_ctgc.m:
compiler/prog_util.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/typecheck.m:
library/io.m:
library/term_conversion.m:
library/varset.m:
Conform to the changes above.
186 lines
6.8 KiB
Mathematica
186 lines
6.8 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1993-2000,2003-2009,2011-2012 The University of Melbourne.
|
|
% Copyright (C) 2014-2022 The Mercury team.
|
|
% This file is distributed under the terms specified in COPYING.LIB.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: term_in.m.
|
|
% Main author: fjh.
|
|
% Stability: medium.
|
|
%
|
|
% This file provides ways to test whether terms represent integers,
|
|
% and ways to construct terms representing integers.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module term_int.
|
|
:- interface.
|
|
|
|
:- import_module term.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred decimal_term_to_int(term(T)::in, int::out) is semidet.
|
|
% NOTE_TO_IMPLEMENTORS This predicate was added for use by the compiler
|
|
% NOTE_TO_IMPLEMENTORS to process various numbers such as arities in pragmas.
|
|
% NOTE_TO_IMPLEMENTORS All of these should be decimal, and we have to check
|
|
% NOTE_TO_IMPLEMENTORS that they are. They are also signed, because their
|
|
% NOTE_TO_IMPLEMENTORS specifications were set before unsigned ints were
|
|
% NOTE_TO_IMPLEMENTORS added to the language. This is why we ourselves
|
|
% NOTE_TO_IMPLEMENTORS don't need versions of this predicate for sized
|
|
% NOTE_TO_IMPLEMENTORS and/or unsigned ints.
|
|
% NOTE_TO_IMPLEMENTORS
|
|
% NOTE_TO_IMPLEMENTORS Of course, we could still provide them for others.
|
|
|
|
:- pred term_to_int(term(T)::in, int::out) is semidet.
|
|
:- pred term_to_int8(term(T)::in, int8::out) is semidet.
|
|
:- pred term_to_int16(term(T)::in, int16::out) is semidet.
|
|
:- pred term_to_int32(term(T)::in, int32::out) is semidet.
|
|
:- pred term_to_int64(term(T)::in, int64::out) is semidet.
|
|
|
|
:- pred term_to_uint(term(T)::in, uint::out) is semidet.
|
|
:- pred term_to_uint8(term(T)::in, uint8::out) is semidet.
|
|
:- pred term_to_uint16(term(T)::in, uint16::out) is semidet.
|
|
:- pred term_to_uint32(term(T)::in, uint32::out) is semidet.
|
|
:- pred term_to_uint64(term(T)::in, uint64::out) is semidet.
|
|
|
|
:- func int_to_decimal_term(int, context) = term(T).
|
|
:- func int8_to_decimal_term(int8, context) = term(T).
|
|
:- func int16_to_decimal_term(int16, context) = term(T).
|
|
:- func int32_to_decimal_term(int32, context) = term(T).
|
|
:- func int64_to_decimal_term(int64, context) = term(T).
|
|
|
|
:- func uint_to_decimal_term(uint, context) = term(T).
|
|
:- func uint8_to_decimal_term(uint8, context) = term(T).
|
|
:- func uint16_to_decimal_term(uint16, context) = term(T).
|
|
:- func uint32_to_decimal_term(uint32, context) = term(T).
|
|
:- func uint64_to_decimal_term(uint64, context) = term(T).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module integer.
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
decimal_term_to_int(Term, Int) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(base_10, Integer, signed, size_word),
|
|
integer.to_int(Integer, Int).
|
|
|
|
%---------------------%
|
|
|
|
term_to_int(Term, Int) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, signed, size_word),
|
|
integer.to_int(Integer, Int).
|
|
|
|
term_to_int8(Term, Int8) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, signed, size_8_bit),
|
|
integer.to_int8(Integer, Int8).
|
|
|
|
term_to_int16(Term, Int16) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, signed, size_16_bit),
|
|
integer.to_int16(Integer, Int16).
|
|
|
|
term_to_int32(Term, Int32) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, signed, size_32_bit),
|
|
integer.to_int32(Integer, Int32).
|
|
|
|
term_to_int64(Term, Int64) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, signed, size_64_bit),
|
|
integer.to_int64(Integer, Int64).
|
|
|
|
%---------------------%
|
|
|
|
term_to_uint(Term, UInt) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, unsigned, size_word),
|
|
integer.to_uint(Integer, UInt).
|
|
|
|
term_to_uint8(Term, UInt8) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, unsigned, size_8_bit),
|
|
integer.to_uint8(Integer, UInt8).
|
|
|
|
term_to_uint16(Term, UInt16) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, unsigned, size_16_bit),
|
|
integer.to_uint16(Integer, UInt16).
|
|
|
|
term_to_uint32(Term, UInt32) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, unsigned, size_32_bit),
|
|
integer.to_uint32(Integer, UInt32).
|
|
|
|
term_to_uint64(Term, UInt64) :-
|
|
Term = functor(Const, [], _Context),
|
|
Const = integer(_Base, Integer, unsigned, size_64_bit),
|
|
integer.to_uint64(Integer, UInt64).
|
|
|
|
%---------------------%
|
|
|
|
int_to_decimal_term(Int, Context) = Term :-
|
|
Const = integer(base_10, integer(Int), signed, size_word),
|
|
Term = functor(Const, [], Context).
|
|
|
|
int8_to_decimal_term(Int8, Context) = Term :-
|
|
Const = integer(base_10, integer.from_int8(Int8), signed,
|
|
size_8_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
int16_to_decimal_term(Int16, Context) = Term :-
|
|
Const = integer(base_10, integer.from_int16(Int16), signed,
|
|
size_16_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
int32_to_decimal_term(Int32, Context) = Term :-
|
|
Const = integer(base_10, integer.from_int32(Int32), signed,
|
|
size_32_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
int64_to_decimal_term(Int64, Context) = Term :-
|
|
Const = integer(base_10, integer.from_int64(Int64), signed,
|
|
size_64_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
%---------------------%
|
|
|
|
uint_to_decimal_term(UInt, Context) = Term :-
|
|
Const = integer(base_10, integer.from_uint(UInt), unsigned, size_word),
|
|
Term = functor(Const, [], Context).
|
|
|
|
uint8_to_decimal_term(UInt8, Context) = Term :-
|
|
Const = integer(base_10, integer.from_uint8(UInt8), unsigned,
|
|
size_8_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
uint16_to_decimal_term(UInt16, Context) = Term :-
|
|
Const = integer(base_10, integer.from_uint16(UInt16), unsigned,
|
|
size_16_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
uint32_to_decimal_term(UInt32, Context) = Term :-
|
|
Const = integer(base_10, integer.from_uint32(UInt32), unsigned,
|
|
size_32_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
uint64_to_decimal_term(UInt64, Context) = Term :-
|
|
Const = integer(base_10, integer.from_uint64(UInt64), unsigned,
|
|
size_64_bit),
|
|
Term = functor(Const, [], Context).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module term_int.
|
|
%---------------------------------------------------------------------------%
|