Files
mercury/compiler/int_emu.m
Zoltan Somogyi a19a5f0267 Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
    Delete these modules, which together constitute the Erlang backend.

compiler/notes/compiler_design.html:
    Delete references to the deleted modules.

compiler/parse_tree_out_type_repn.m:
    Update the format we use to represent the sets of foreign_type and
    foreign_enum declarations for a type as part of its item_type_repn_info,
    now that Erlang is no longer a target language.

compiler/parse_type_repn.m:
    Accept both the updated version of the item_type_repn_info and the
    immediately previous version, since the installed compiler will
    initially generate that previous version. However, stop accepting
    an even older version that we stopped generating several months ago.

compiler/parse_pragma_foreign.m:
    When the compiler finds a reference to Erlang as a foreign language,
    add a message about support for Erlang being discontinued to the error
    message.

    Make the code parsing foreign_decls handle the term containing
    the foreign language the same way as the codes parsing foreign
    codes, procs, types and enums.

    Add a mechanism to help parse_mutable.m to do the same.

compiler/parse_mutable.m:
    When the compiler finds a reference to Erlang as a foreign language,
    print an error message about support for Erlang being discontinued.

compiler/compute_grade.m:
    When the compiler finds a reference to Erlang as a grade component,
    print an informational message about support for Erlang being discontinued.

compiler/pickle.m:
compiler/make.build.m:
    Delete Erlang foreign procs and types.

compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
    Remove references to Erlang as a backend or as a target language.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
    Add a test for Erlang as an invalid foreign language. Expect both the
    new error message for this new error, and the updated list of now-valid
    foreign languages on all errors.
2020-10-29 13:24:49 +11:00

179 lines
5.5 KiB
Mathematica

%----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%----------------------------------------------------------------------------%
% Copyright (C) 2015 The Mercury team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%----------------------------------------------------------------------------%
%
% File: int_emu.m.
% Main author: wangp.
%
% Emulate `int' operations for a given number of bits per int. These predicates
% succeed only if the result is defined for the given arguments, and the result
% can be represented by the `int' type of the host compiler.
%
%----------------------------------------------------------------------------%
:- module libs.int_emu.
:- interface.
:- import_module libs.globals.
%----------------------------------------------------------------------------%
:- type bits_per_int
---> bits_per_int(int).
% Return the number of bits per int for the selected compilation target.
%
:- pred target_bits_per_int(globals::in, bits_per_int::out) is det.
%----------------------------------------------------------------------------%
:- pred plus(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred minus(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred times(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred quotient(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred unchecked_quotient(bits_per_int::in, int::in, int::in, int::out)
is semidet.
:- pred mod(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred rem(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred unchecked_rem(bits_per_int::in, int::in, int::in, int::out)
is semidet.
:- pred left_shift(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred unchecked_left_shift(bits_per_int::in, int::in, int::in, int::out)
is semidet.
:- pred right_shift(bits_per_int::in, int::in, int::in, int::out) is semidet.
:- pred unchecked_right_shift(bits_per_int::in, int::in, int::in, int::out)
is semidet.
:- pred floor_to_multiple_of_bits_per_int(int::in, bits_per_int::in, int::out)
is semidet.
:- pred quot_bits_per_int(int::in, bits_per_int::in, int::out) is semidet.
:- pred times_bits_per_int(int::in, bits_per_int::in, int::out) is semidet.
:- pred rem_bits_per_int(int::in, bits_per_int::in, int::out) is semidet.
%----------------------------------------------------------------------------%
%----------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module integer.
:- import_module libs.options.
%----------------------------------------------------------------------------%
target_bits_per_int(Globals, bits_per_int(BitsPerInt)) :-
globals.get_target(Globals, Target),
(
Target = target_c,
globals.lookup_int_option(Globals, bits_per_word, BitsPerInt)
;
( Target = target_csharp
; Target = target_java
),
BitsPerInt = 32
).
%----------------------------------------------------------------------------%
plus(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) + integer(Y), Z).
minus(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) - integer(Y), Z).
times(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) * integer(Y), Z).
quotient(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) // integer(Y), Z).
unchecked_quotient(BitsPerInt, X, Y, Z) :-
Y \= 0,
quotient(BitsPerInt, X, Y, Z).
mod(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) mod integer(Y), Z).
rem(BitsPerInt, X, Y, Z) :-
to_int_in_range(BitsPerInt, integer(X) rem integer(Y), Z).
unchecked_rem(BitsPerInt, X, Y, Z) :-
Y \= 0,
rem(BitsPerInt, X, Y, Z).
left_shift(BitsPerInt, X, Y, Z) :-
BitsPerInt = bits_per_int(N),
to_int_in_range(BitsPerInt, integer(X) << min(Y, N), Z).
unchecked_left_shift(BitsPerInt, X, Y, Z) :-
BitsPerInt = bits_per_int(N),
Y >= 0,
Y < N,
left_shift(BitsPerInt, X, Y, Z).
right_shift(BitsPerInt, X, Y, Z) :-
( if Y < 0 then
left_shift(BitsPerInt, X, -Y, Z)
else
to_int_in_range(BitsPerInt, integer(X) >> Y, Z)
).
unchecked_right_shift(BitsPerInt, X, Y, Z) :-
BitsPerInt = bits_per_int(N),
Y >= 0,
Y < N,
right_shift(BitsPerInt, X, Y, Z).
floor_to_multiple_of_bits_per_int(X, BitsPerInt, FloorInt) :-
BitsPerInt = bits_per_int(N),
Trunc = integer(X) // integer(N),
Floor0 = Trunc * integer(N),
( if Floor0 > integer(X) then
Floor = Floor0 - integer(N)
else
Floor = Floor0
),
to_int_in_range(BitsPerInt, Floor, FloorInt).
quot_bits_per_int(X, BitsPerInt, Z) :-
BitsPerInt = bits_per_int(Y),
quotient(BitsPerInt, X, Y, Z).
times_bits_per_int(X, BitsPerInt, Z) :-
BitsPerInt = bits_per_int(Y),
times(BitsPerInt, X, Y, Z).
rem_bits_per_int(X, BitsPerInt, Z) :-
BitsPerInt = bits_per_int(Y),
rem(BitsPerInt, X, Y, Z).
:- pred to_int_in_range(bits_per_int::in, integer::in, int::out) is semidet.
to_int_in_range(bits_per_int(BitsPerInt), Integer, Int) :-
Integer >= -pow(integer(2), integer(BitsPerInt - 1)),
Integer =< pow(integer(2), integer(BitsPerInt - 1)) - one,
integer.to_int(Integer, Int).
%----------------------------------------------------------------------------%
:- end_module libs.int_emu.
%----------------------------------------------------------------------------%