Commit Graph

126 Commits

Author SHA1 Message Date
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
Zoltan Somogyi
409cbcb6a3 Unify getopt.m and getopt_io.m ...
... using an approach proposed by Peter, with an extra twist from Julien.

Instead of having two modules, getopt.m and getopt_io.m, with the former
defining predicates that do not take an I/O state pair, and the latter
defining predicates that do take an I/O state pair, put both kinds of
predicates into a single module. The versions with an I/O state pair
have an "_io" suffix added to their names for disambiguation.
Both versions are a veneer on top of a common infrastructure,
which relies on a simple type class to implement the operation
"give the contents of the file with this name". The predicate versions
with I/O state pairs have a normal implementation of this typeclass,
while the predicate versions that do not have I/O state pairs
have an implementation that always returns an error indication.

The above change just about doubles the number of exported predicates.
We already had two versions of most exported predicates that differed
in whether we returned errors in the form of a string, or in the form
of a structured representation, with names of the latter having
an "_se" suffix. Since we agreed that the structured representation
is the form we want to encourage, this diff deletes the string versions,
and deletes the "_se" suffix from the predicate names that used to have them.
(It still remains at the end of the name of a type.) This "undoubling"
should offset the effect of the doubling in the previous paragraph.

Eventually, we want to have just one module, getopt.m, containing
the updated code described above, but for now, we put the same code
into both getopt_io.m and getopt.m to prevent too big a shock to
people with existing code that uses getopt_io.m.

library/getopt.m:
library/getopt_io.m:
    Make the changes described above.

library/Mmakefile:
    Instead of building both getopt_io.m and getopt.m from getopt_template,
    build getopt.m from getopt_io.m.

tools/bootcheck:
    Delete references to getopt_template.

compiler/typecheck_errors.m:
    When a type error involves one of the getopt/getopt_io predicates
    whose interfaces are changed by this diff, tell the user about
    how these changes could have caused the error, and thus what the
    probable fix is.

compiler/handle_options.m:
browser/parse.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
slice/mcov.m:
slice/mdice.m:
slice/mslice.m:
slice/mtc_diff.m:
slice/mtc_union.m:
tests/hard_coded/space.m:
    Use the updated getopt interface.

compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/deforest.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/ml_top_gen.m:
compiler/module_cmds.m:
compiler/op_mode.m:
compiler/optimization_options.m:
compiler/options.m:
compiler/write_module_interface_files.m:
tools/make_optimization_options_middle:
tools/make_optimization_options_start:
    Replace references to getopt_io.m with references to getopt.m.

tests/invalid/getopt_io_old.{m,err_exp}:
tests/invalid/getopt_old.{m,err_exp}:
tests/invalid/getopt_old_se.{m, err_exp}:
    New test cases for the extra help

tests/invalid/Mmakefile:
    Enable the new test cases.
2020-10-09 19:30:46 +11:00
Zoltan Somogyi
c2f92d5454 Partition extensions into ".m" and "all others".
This is a first step towards a much finer grained partition.

compiler/file_names.m:
    Split the ext type into ext_src and ext_other, as mentioned above.

    Add the first predicate for checking whether a string falls into
    a given category of extensions.

    Add an XXX proposing a better solution for an old problem that does not
    actually arise in practice.

compiler/compile_target_code.m:
    Split the two-moded predicate maybe_pic_object_file_extension into
    two separate one-mode predicates, one for each old mode. The
    implementations of the two modes were already separate, because
    the two modes already did different jobs: while one went from PIC
    to an "extension", the other went from an "extension string" to PIC.
    Until now, "extension" and "extension string" were equivalent;
    after this diff, they aren't anymore.

    Delete an unused argument.

compiler/make.util.m:
    Split the two-moded predicate target_extension into
    two separate one-mode predicates, one for each old mode,
    for the same reason as maybe_pic_object_file_extension above:
    the fact that "extension" and "extension string" are now distinct.

compiler/options_file.m:
    Move debug infrastructure here from mercury_compile_main.m, to help
    debug possible problems with options files. (I had such a problem
    while writing this diff.)

    Improve how progress messages are printed.

compiler/options.m:
    Make an error message more useful.

compiler/mercury_compile_main.m:
    Add infrastructure for debugging possible problems with command lines.
    (I had such a problem while writing this diff.)

compiler/analysis.m:
    Conform to the changes above. Put the arguments of some methods
    into the same order as similar predicates in file_names.m.

compiler/find_module.m:
    Conform to the changes above. Delete an unused argument,

compiler/analysis.file.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.deps_set.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
2020-08-17 23:43:15 +10:00
Zoltan Somogyi
52c0919975 Make filename extensions a separate type, ...
... to allow later changes to its definition.

compiler/file_names.m:
    We used to represent filename extensions simply as strings. This meant
    all calls to the predicates in file_names.m that convert module names
    to file names with various suffixes had to go through a complicated
    sequence of tests that effectively partition the extensions into
    several classes, with all extensions in a class being treated the same
    but different classes being treated differently. And since this general
    translation process is quite convoluted (which is not helped by it
    being spread across several predicates), it is very hard to construct
    a correctness argument for it.

    It would be better to represent the different classes of extensions
    explicitly, in a du type, with each function symbol of that type
    representing all the extensions in the corresponding class (in the sense
    of the paragraph above). However, getting there in one diff would make
    that diff far too hard to test and to review. So this first diff
    starts by simply making extension a notag type.

    The above is the first step in implementing one old XXX. This diff
    fully implements another old XXX, which is to make the argument order
    of several predicates friendly to higher order code.

    Add infrastructure for profiling how often this code makes directories.

    Delete an unused type.

    Add comments outlining proposed future improvements.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.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/mercury_compile_front_end.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/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/module_imports.m:
compiler/parse_tree_out.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the change to file_names.m.

    Consistently use "Ext" for the abstract representation of extensions
    and "ExtStr" for their string representation.

    In a few places, add "XXX EXT" where the code manipulates extensions
    as strings in a way that potentially inferferes with the partition
    of extensions into classes.

    In a few places, rename predicates to avoid ambiguities. factor out
    common code, delete unneeded arguments, replace bools with bespoke types,
    and make similar minor improvements.

    In a few places, remove rafe-isms, such as the use ^elem.
2020-08-14 20:30:36 +10:00
Zoltan Somogyi
01a1744bc2 Remove a workaround. 2020-03-29 14:01:54 +11:00
Zoltan Somogyi
79e8804db9 Fix "this disjunct can't have solutions" warnings in multimode preds.
This fixes github issue #85.

A complication is that the compiler itself has code, in make.util.m,
in which a disjunct has no solutions in only one mode of a two mode
function, but in this case, the code works (though its programming style
is pretty bad), so to get this change to bootstrap, we also need
a way to disable the "this disjunct can't have solutions" warning
in a scope.

compiler/simplify_goal_disj.m:
    When we generate a "this disjunct can't succeed" warning,
    do not insist on all modes generating that warning.
    We used to insist on that because in a multi-mode predicate,
    such warnings can be inappropriate for other modes.
    Instead, achieve the same objective of minimizing programmer
    confusion by adding a codicil explicitly mentioninging
    this possibility.

    Make the generation of this warning conditional on a simplify task
    that can be disabled by "disable_warnings" scope.

compiler/prog_data.m:
    Add "no_solution_disjunct" as a warning kind that may be disabled.

compiler/parse_goal.m:
    Parse the new kind of warning.

compiler/prog_out.m:
    Output the new kind of warning.

    Improve some adjacent though unrelated code.

compiler/make.util.m:
    Add code disable this warning in the affected predicate.
    Comment out this code until installed compilers know how
    to parse it and understand it.

compiler/Mercury.options:
    Don't turn warnings into errors for make.util.m until then.

compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/simplify_tasks.m:
    Provide the mechanism needed to make it possible to disable
    warnings about no solution disjuncts.

doc/reference_manual.texi:
    Document the new disable-able warning.

NEWS:
    Document both the changed behavior of the old warning
    and the new way to disable it.

tests/warnings/gh85.{m,exp}:
    A regression test for the bug, based on the code in the
    github issue. It also tests the way to disable the warning.

tests/warnings/Mmakefile:
    Enable the new test case.
2020-03-24 15:20:59 +11:00
Zoltan Somogyi
1fe767018b Carve make.build.m out of make.util.m.
compiler/make.build.m:
compiler/make.util.m:
    As above. Make.build.m contains the parts of the old make.util.m
    that deal with executing the actions that bring targets up to date.
    This change improves the cohesion of both modules (though make.util.m's
    still isn't great).

compiler/notes/compiler_design.html:
    Document the new module.

compiler/make.m:
    Include the new submodule.

compiler/Mercury.options:
    Insist that all submodules of make.m have definitions in the same order
    as declarations.

compiler/make.dependencies.m:
compiler/options_file.m:
    Fix the order mismatches that Mercury.options used to cover up.

compiler/mercury_compile_main.m:
    Import make.build instead of make.util.
2020-03-16 21:47:08 +11:00
Zoltan Somogyi
e6870d29f9 Make module_and_imports an abstract type.
compiler/module_imports.m:
    Make the definition of module_and_imports private, to make future changes
    to its structure easier.

    Add the construction, deconstruction, getter and setter predicates
    on the type that are now needed by the other compiler modules.

    Put the related fields of module_and_imports next to each other.
    Give some of the fields more descriptive names.

compiler/compile_target_code.m:
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_deps_graph.m:
compiler/modules.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2019-04-14 23:31:16 +10:00
Zoltan Somogyi
2a74a2b6ed Fix misleading names in two enums.
compiler/make.m:
    Replace references to private, long and short interfaces with references
    to int0, int1, int2 and int3 in two types. These two types, even though
    they were adjacent, used the same word, "short", to refer to two DIFFERENT
    interface file kinds: int2 in one, int3 in the other.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the change above.

    Replace the definitions of some predicates, which used to be lists of
    clauses, with a single clause each containing a disjunction, especially
    where the old definitions implemented the DRY principle through recursion
    (because switch arms shared between two or more cons_ids were not yet
    supported when they were written).

    Do some other minor cleanups.
2019-04-10 21:09:40 +10:00
Zoltan Somogyi
e08b8505e9 Import the parents of *all* imported modules. 2019-03-29 12:56:35 +11:00
Zoltan Somogyi
c7f8ebbe2f Avoid warnings from --warn-non-contiguous-{clauses,foreign-procs}.
browser/collect_lib.m:
browser/declarative_execution.m:
browser/dl.m:
browser/io_action.m:
compiler/make.util.m:
compiler/pickle.m:
compiler/process_util.m:
compiler/prog_event.m:
library/array.m:
library/benchmarking.m:
library/bit_buffer.m:
library/builtin.m:
library/char.m:
library/deconstruct.m:
library/dir.m:
library/erlang_rtti_implementation.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/io.m:
library/math.m:
library/mutvar.m:
library/private_builtin.m:
library/profiling_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.format.m:
library/string.m:
library/table_builtin.m:
library/term_size_prof_builtin.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
ssdb/ssdb.m:
    As above. This mostly involved two things.

    The first was grouping foreign_procs by predicate instead of by language.
    In a few cases, this revealed that some predicates *had* no foreign_proc
    for a language, while related predicates did have one that just aborted
    if called. This diff adds similar aborting foreign_procs to predicate/
    language combinations that were missing them, when this seemed obviously
    the right thing to do.

    The second was moving pragmas about a predicate from the middle of the
    block of clauses of that predicate to the start of that block.
2018-10-19 11:01:33 +11:00
Zoltan Somogyi
15aa457e12 Delete $module arg from calls to unexpected. 2018-04-07 18:25:43 +10:00
Zoltan Somogyi
22eefb3c88 Shut up determinism warnings for "sorry" fallback clauses.
Many predicates that do their jobs via foreign_procs in C have a fallback
Mercury clause for non-C backends, which usually throws an exception.
When compiled in non-C grades, these often get a warning that their
determinism declaration could have been tigther, e.g. erroneous instead of det.

*.m:
    Add no_determinism_warnings pragmas before such fallback clauses.

library/dir.m:
    As above, but also remove the unnecessary "dir." prefix on many predicate
    declarations and clause heads.
2017-08-10 18:02:42 +02:00
Zoltan Somogyi
c88a777501 Delete some dead predicates.
compiler/*.m:
    Delete dead predicates that don't look likely to be used in the future
    in their current form.

    For dead predicates that may be needed in the future, shut up warnings
    about them by adding a consider_used pragma for them.

    In intermod.m, delete two unused fields in a structure.
2017-07-11 02:53:35 +02:00
Zoltan Somogyi
1af5bcf2f1 Make module_name_to_file_name currying-friendly.
compiler/file_names.m:
    Change the order of arguments of module_name_to_file_name and related
    predicates to make it easier to construct closures from them. Delete
    the previous higher-order-friendly versions, which the previous step
    has made unnecessary.

compiler/compile_target_code.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/intermod.m:
compiler/llds_out_file.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/mercury_compile_front_end.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/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/modules.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the change above. In several places, this means replacing
    explicit lambda expressions with simple partial application of the
    relevant predicates.
2017-06-12 19:38:20 +02:00
Zoltan Somogyi
3f2f0e1389 Remove unneeded imports from packages.
compiler/Mercury.options:
    Don't disable --warn-unused-imports for any packages.

compiler/make.m:
compiler/recompilation.m:
    Delete the imports in these packages that aren't used in the module itself.
    (These are the imports that --warn-unused-imports warns about.)

    The other packages in the compiler no unused imports.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
    Conform to the above. In most cases, this means adding the imports
    that previously these modules got from their parent package.
    In some cases, it means *deleting* unused imports that previously
    weren't warned about because the import also came from the parent
    module. Some imports deleted from the packages weren't needed
    in *any* of their modules.
2017-05-20 18:35:29 +02:00
Zoltan Somogyi
34858844bf Fix the operation of --rebuild.
This fixes mantis bug #404.

compiler/compile_target_code.m:
compiler/make.dependencies.m:
    Use the value of the rebuild option, not the op_mode, to make decisions
    about executing operations that even when timestamps don't call for them.

    This fixes the bug, because unlike the op_mode, the value of the option
    isn't overridden by setting the invoked_by_mmc_make option when recomputing
    the op_mode.

compiler/make.program_target.m:
compiler/make.util.m:
    Reset the rebuild option, not the op_mode, since this is what matters now.

compiler/op_mode.m:
    Take the value of the --rebuild option out of the op_mode, since it is not
    needed *there* anymore.

    Note that --rebuild still implies --make, so the rebuild option still does
    play a role in selecting the op_mode. (This was the original motivation
    for its inclusion in the op_mode in the first place.) This is why its value
    matters when converting an op_mode back into its original option string.

    Fix the copyright years.

compiler/options.m:
    Since the rebuild option isn't stored in the op_mode anymore, give it back
    its original, non-op_mode internal name.

compiler/handle_options.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2016-10-03 13:25:23 +11:00
Paul Bone
d4d9ad8412 Refactor code that works with temporary files.
It is common to create a temporary file then open it for writing; or create
the temporary file, call another program, then open the file for reading.

This patch implements both these patterns as predicates in file_util.m

compiler/file_util.m:
    Add new utility predicates.

compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/make.util.m:
compiler/prog_event.m:
    Make use of open_temp_input.
2016-04-27 17:20:23 +10:00
Paul Bone
331e829161 io.make_temp now reterns a result rather than throw exceptions
The make_temp predicates would throw an exception if they were unsuccessful,
New versions of make_temp/3 and make_temp/5 have been created (named
make_temp_file).  make_temp/3 and make_temp/5 have been marked as obsolete.
make_temp_directory/3 and make_temp_directory/5 have been modified directly
as they are very new.  This closes bug #408

Some routines in compiler/compile_target_code.m used the name returned by
make_temp and added a suffix before using the resulting file, this could
create unnecessary temporary files that I believe were never cleaned up.  So
I've added a suffix argument to make_temp_file/5 and make_temp_directory/5
(now they're make_temp_file/6 and make_temp_directory/6).

library/io.m:
    As above.

    Remove out-of-date comment.

compiler/compile_target_code.m:
    Conform to changes in io.m.

    Use the new suffix argument to reduce the number of temporary files
    created during linking.

compiler/fact_table.m:
compiler/make.module_target.m:
compiler/make.util.m:
compiler/module_cmds.m:
compiler/prog_event.m:
compiler/write_deps_file.m:
deep_profiler/conf.m:
    Conform to changes in io.m.
2016-04-27 16:43:39 +10:00
Zoltan Somogyi
c8d718ec57 Remove the .regparm and .picreg grade components.
For picreg, this is only the first half of the change; it deletes code
that generates references to this grade component. When this diff has been
installed on all our machines, will come the second half, which will delete
the code that understands references to picreg. The delay is needed because
your current installed compiler is still generating such references.

runtime/mercury_grade.h:
    Remove both regparm and picreg as grade components.

doc/user_guide.texi:
    Remove the (commented out) documentation of picreg; regparm had
    no documentation to delete.

runtime/mercury_std.h:
    Remove the small bit of code that implemented regparm.

runtime/mercury_conf_param.h:
    Don't define MR_PIC_REG.

runtime/machdeps/i386_regs.h:
runtime/mercury_conf_bootstrap.h:
    Remove references to picreg.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
    Keep in place the code that accepts picreg grade components,
    but make them do nothing. Mark such do-nothing code so that
    it can be deleted when this first-half diff has been bootstrapped.

configure.ac:
    Delete the autoconfigured variable EXT_FOR_LINK_WITH_PIC_OBJECTS,
    which could be set to either 'lpic_o' or just 'o', because it is now
    *always* the latter.

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
    Remove code that transmitted the value of EXT_FOR_LINK_WITH_PIC_OBJECTS
    to the compiler via the --link-with-pic-object-file-extension option.

compiler/options.m:
    Keep the --link-with-pic-object-file-extension and --pic-reg options,
    but mark them for deletion in the second half of this change.

compiler/compile_target_code.m:
    Change the code that dealt with the value of the
    --link-with-pic-object-file-extension and --pic-reg options to assume
    that the former is always the same as the non-pic file extension,
    and that --pic-reg is never needed. The former means that we don't need
    to handle link_with_pic as a separate category of object files from
    just plain non_pic.

compiler/compute_grade.m:
    Keep accepting picreg grades, but mark the code that does this
    for deletion.

compiler/make.program_target.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the changes above.
2016-02-25 16:47:16 +11:00
Zoltan Somogyi
1fcdc4cdc0 Use the op_mode, not the options that help determine it.
The options that help determine the op_mode are only sort-of mutually
exclusive; in some cases, more than one can be set. Using the op_mode
instead of the options themselves means that we are using the result
of the process (in op_mode.m) that resolves conflicts between them.

Another benefit is that in some places in the code, many op_modes
have already been processed, which means that the set of remaining op_modes
is a reasonably small set.

compiler/options.m:
    Give all the options that op_mode.m uses to compute the op_mode
    new internal names. (The user-visible names are not affected.)
    Each new internal name is the old internal name with an added
    "only_opmode_" prefix, indicating that the option should not be used
    for any purpose other than computing the op_mode.

    Change the documentation of the --generate-module-order and --imports-graph
    options. (See handle_options.m below for the reason.)

doc/user_guide.texi:
    Change the documentation of the --generate-module-order and --imports-graph
    options, as in compiler/options.m.

compiler/handle_options.m:
    Delete implications that set the values of options that help decide the
    op_mode, since those implications used to be executed *after* we decided
    the op_mode. Replace each of their functionalities with something else.

    For the implication from --rebuild to --make, the replacement is
    new code in op_mode.m (see below).

    For the implication from --invoked-by-mmc-make to --no-make,
    the needed replacement code was already in op_mode.m.

    For the implications from --generate-module-order and --imports-graph
    to --generate-dependencies, do not replace them. Instead, document that
    they are effective only if the op mode is generating dependencies.
    This goes against the current documentation of --generate-module-order,
    though not of --imports-graph (the help message for --imports-graph
    is silent on its relationship with --generate-dependencies). However,
    the new documented (and implemented) behavior is actually more useful,
    since it allows both options to be specified in Mmakefiles or
    Mercury.options files, have them be acted on when making dependencies,
    but not get error messages about incompatible op mode options.
    However, it does mean that "mmc --generate-module-order x.m" would
    now try to compile x.m while ignoring the option, whereas previously
    it would implicitly act as if the command line were "mmc
    --generate-dependencies --generate-module-order x.m". And similarly
    for --imports-graph.

    Simplify the code that disables smart recompilation when it is not
    relevant.

NEWS:
    Mention the changes to --generate-module-order and --imports-graph.

compiler/op_mode.m:
    Make the opm_top_make functor take an argument that says whether we
    are forcing rebuilds or not. The --rebuild option implies we are;
    the --make option without --rebuild implies we are not. This replaces
    the deleted implication in handle_options.m.

    Conform to the name changes in options.m.

compiler/add_type.m:
compiler/compile_target_code.m:
compiler/exception_analysis.m:
compiler/headvar_names.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_errors.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_initial.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/unused_args.m:
    Replace tests of op_mode options with tests of the op_mode itself.

    In mercury_compile*.m, get the op_mode to the places that now need it.

    In a few places in make.*.m, replace code that sets op_mode options
    (temporarily, for the duration of an operation) with code that sets
    the op_mode itself.

compiler/globals.m:
    Add the now-needed capability to set the op_mode.
2015-12-29 13:06:18 +11:00
Zoltan Somogyi
3cb166eb07 Delete some unused predicates; add consider_used pragmas for some others. 2015-12-29 01:50:46 +11:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Zoltan Somogyi
5de235065d Fix too-long lines. 2015-11-16 00:09:26 +11:00
Zoltan Somogyi
08d84a144d Put the op_mode in the globals.
compiler/globals.m:
    Put the op_mode into the globals structure.

compiler/handle_options.m:
    Invoke the code that computes the op_mode *before* creating the globals.
    Delete the code duplication concerning the computation of the Link flag.

compiler/op_mode.m:
    New module containing the definition of the op_mode type,
    and the predicate that figures out the op_mode from the values of options.
    These are taken from mercury_compile.m, and the latter is adapted
    to work on the option_table, not the globals, since it is now invoked
    as *part* of the code to build up the globals.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Include the new module.

    Do not include the atsort.m module in the libs package, since it
    hasn't been used in a long time, and its inclusion adds to the bulk
    of the compiler executable without any compensating gain.

compiler/mercury_compile.m:
    Delete the code now in op_mode.m.

    Conform to the changes above.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/mercury_compile_erl_back_end.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
    Standardise dividing lines.
2015-10-14 03:06:46 +11:00
Zoltan Somogyi
0768cc0832 Have handle_options.m return errors as error_specs, not strings.
compiler/handle_options.m:
    As above.

    Generate warnings the same way as we generate errors, since unlike strings,
    error_specs can support the distinction.

    Use more consistent phraseology in error messages.

    Use auxiliary predicates to lookup up bool, int, string and accumulating
    options, thus factoring out some old common code.

compiler/error_util.m:
    Add a way to assign a phase to errors discovered during option processing.

compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile.m:
    Conform to the changes in handle_options.m.

compiler/make.m:
    Fix white space.
2015-10-13 18:26:53 +11:00
Zoltan Somogyi
baa889df53 Improve the style of the make package.
Convert (C->T;E) to (if C then T else E).

Avoid the use of DCGs.

Rename some predicates to avoid ambiguities.

Delete some unused predicate arguments.

Replace several lambdas with named predicates.

Avoid the use of solutions.m.
2015-10-13 03:24:49 +11:00
Zoltan Somogyi
902bb272f2 Use a mode of operation for *everything* mercury_compile.m does.
compiler/mercury_compile.m:
    A while ago, Julien replaced a bunch of nested if-then-elses at the
    top level of this module by code that
    (a) decided what actions ("operations") the options called for,
    (b) detected and reported any conflicts between these operations, and
    (c) carried out the selected operation in the absence of conflicts.
    The replacement code generates useful diagnostics, and is easier
    to read and to maintain.

    This diff extends the same principle to other parts of mercury_compile.m.
    It represents modes of operation as a nested set of types that has
    one type for each point in mercury_compile.m where we need to decide
    what to do next; the nesting arises naturally from the fact that
    many different ultimate outcomes need the compiler to take the same path
    at earlier decisions.

    Rename mode_of_operation to op_mode, to shorten code.

    Put the argument lists of some predicates in a standard order.

    Replace a boolean with a bespoke type (maybe_write_d_file), and simplify
    the code for setting it, not least by avoiding double negatives.

compiler/mercury_compile_middle_passes.m:
    Don't expect mercury_compile.m to pass a module name separately
    *as well as* in the module itself.

compiler/handle_options.m:
    Make some debugging code more useful.

compiler/make.util.m:
    Make code more readable by changing white space.
2015-10-08 22:16:40 +11:00
Julien Fischer
3dd02876a5 Delete the MLDS->IL backend.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_managed.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/ilds.m:
    Delete the modules making up the MLDS->IL code generator.

compiler/globals.m:
compiler/prog_data.m:
    Delete IL as a target and foreign language.

compiler/prog_io_pragma.m:
    Delete the max_stack_size/1 foreign proc attribute.  This was only
    ever required by the IL backend.

compiler/options.m
    Delete options used for the IL backend.

compiler/write_deps_file.m:
    Don't generate mmake targets for .il files etc.

compiler/*.m:
    Conform to the above changes.

compiler/notes/compiler_design.html
compiler/notes/work_in_progress.html
    Conform to the above changes.

library/*.m:
    Delete IL foreign_proc and foreign_export pragmas.

README.DotNet:
    Delete this file.

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
    Conform the above changes.

configure.ac:
    Don't check that IL is a supported foreign language when performing the
    up-to-date check.

    Delete the '--enable-dotnet-grades' option.

scripts/Mmake.vars.in:
    Delete variables used for the IL backend (and in on case by the Aditi
    backend).

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.rules:
scripts/canonical_grade.sh-subr:
tools/bootcheck:
    Delete stuff related to the 'il' and 'ilc' grades.

doc/reference_manual.texi:
     Delete the documentation of the 'max_stack_size' option.

doc/user_guide.texi:
     Delete stuff related to the IL backend.

tests/hard_coded/csharp_test.{m,exp}:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/valid/csharp_hello.m:
	Delete these tests: they are no longer relevant.

tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/intermod_foreign_type2.m:
tests/hard_coded/lp.m:
tests/hard_coded/user_compare.m:
tests/invalid/foreign_type_2.m:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/invalid/foreign_type_visibility.m:
tests/invalid/illtyped_compare.{m,err_exp}:
tests/submodules/external_unification_pred.m
tests/valid/big_foreign_type.m
tests/valid/solver_type_bug.m
tests/valid_seq/foreign_type_spec.m
tests/valid_seq/intermod_impure2.m
    Delete IL foreign_procs where necessary.

tests/hard_coded/Mmakefile
tests/invalid/Mercury.options
tests/invalid/Mmakefile
tests/submodules/Mmakefile
tests/valid/Mercury.options
tests/valid/Mmake.valid.common
tests/valid/Mmakefile
tests/valid_seq/Mmakefile
tests/valid_seq/Mercury.options
    Conform to the above changes.
2015-09-21 11:34:46 +10:00
Julien Fischer
f903c238fb Fix problems with --use-grade-subdirs with C# and Java backends.
Fix problems that occur when generating executables in the C# and Java grades
with --use-grade-subdirs enabled, namely:

* the compiler aborts when it tries to build the launcher script for a Java
grade executable.
* the compiler does not place generated Java archive files under the Mercury
subdirectory.
* in C# grades, the compiler always places the launcher script in the user's
directory rather than under the Mercury subdirectory.

The above problems were mainly caused by the "link" step for executables being
incorrect for the C# and Java backends.  In other grades, the link step
consists of:

1. use the linker to create the executable in C grades, or generate a launcher
script in the Erlang grade.  This executable or script is placed under the
Mercury subdirectory.

2. create a symlink (or copy if --no-use-symlinks is enabled) the executable
or script into the user's directory.

This does not work for the C# and Java backends since their principle "link
target" is not the launcher script (as is the case with the Erlang backend),
but a ".exe" or ".jar" file.  The launcher script is generated as a side-effect
of creating that.   (This has long been the case for the C# backend and has
recently become the case for the Java backend since we moved to generating
archives for executables.)  The correct sequence of "linking" steps for these
two backends should be:

1. create the .exe or .jar under the Mercury subdirectory.
2. create the launcher script file, if required, under the Mercury subdirectory.
3. symlink or copy the .exe or .jar file to the user's directory.
4. symlink or copy the launcher script to the user's directory, if required.

This diff makes the compiler carry out the latter sequence of steps for the C#
and Java backends.

compiler/compile_target_code.m:
	Make the executable target for the Java backend work more like that of
	the C# backend.  Merge it with the code for handling library targets in the
	Java backend since, apart from the creation of the launcher script, it is
	identical.

	We may need to do multiple create symlink or copy operations when
	creating an executable using the C# or Java backends: one for the
	".exe" or ".jar" and another for the launcher script.

	Separate out the code for determining the launcher script extension into
	a new function.

compiler/make.util.m:
	Conform to the above change.

	Add an XXX comment about the Erlang backend; I'll look into this
	separately.

compiler/file_names.m:
	Update the list of architecture or grade dependent files to include those
	with the extensions ".jar" and ".bat", and also those files with no
	extension at all.  (For Mercury, the latter will either be launcher scripts
	or executables.)   Not covering these cases had a number of untoward
	effects: ".jar" files were not placed in grade specific directories and the
	launcher script in the C# grade was always placed in the user's directory.

compiler/module_cmds.m:
	Create any required subdirectories under the Mercury directory when
	generating launcher scripts.

	If --verbose-commands is enabled, then print a message when creating
	a symlink or copying a file.  I needed this when debugging the above
	problems.

	Use io.format/4 to generate an error message rather than multiple
	calls to io.write_string/3.
2015-06-04 12:47:41 +10:00
Julien Fischer
f292683d49 Merge branch 'version-14_01-branch' 2015-05-28 10:51:18 +10:00
Peter Wang
0a2b1e8fc0 Fixes for FreeBSD.
configure.ac:
	Set flags for thread support on FreeBSD.

compiler/make.util.m:
	Use System V semaphores for `mmc --make' job control.
2015-05-21 11:00:11 +10:00
Julien Fischer
9acc9db555 Generate executables in the Java grade as JARs.
When building an executable in the Java grade, the Mercury compiler generates
all the class files in the Mercury subdirectory and then generates a wrapper
script or batch file that points towards these class files.  This makes
deploying executables built in the Java grade rather awkward.  This change
makes the Mercury compiler package up all the class files for an executable
into a JAR file and modifies the wrapper scripts to point to this JAR file.

NOTE: the JAR file we generate cannot be executed with 'java -jar ...'.  This
is because in that mode of operation the Java interpreter ignores all user
classpath settings, such as those that tell the interpreter where the Mercury
standard library is.  (We could support this mode of operation by setting any
required library classpath directories in the archive's manifest, but that
would mean either hardcoding installation specific directories in the manifest
or copying any required .jars to a known location relative to the executable's
class files.  Generating such self-contained archives may be useful in some
cases, but it is not something this change addresses.)

compiler/compile_target_code.m:
        Rename the link target type for Java executables.

        Add a predicate for creating Java "executables": this involves generating
        an archive (as we do for libraries) and then generating the wrapper script
        or batch file.

        Simplify some code that generates an error message.

compiler/module_cmds.m:
        Change the wrapper scripts for Java executables to point towards
        the .jar file generated instead of the class files in the Mercury
        subdirectory.

        Ditto for the wrapper batch files.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
        Conform to the above changes.

README.Java:
        Mention that class files for the executable are packaged up in
        an archive.

NEWS:
        Announce this change.
2015-04-17 11:27:54 +10:00
Peter Wang
6a267a8f07 Make base_string_to_int check overflow/underflow for all bases.
Make base_string_to_int check for overflow and underflow when converting
from strings in all bases, not only base 10.  Fixes bug #376.

Previously it was stated that "numbers not in base 10 are assumed to
denote bit patterns and are not checked for overflow."  Though not a
safe assumption in general, in Mercury source files it is useful to be
able to write values with the high bit set, e.g. 0x80000000 on 32-bit
machines, that would be greater than max_int if interpreted as a
positive integer.

The changed behaviour of base_string_to_int would reject such literals
from Mercury sources, so additional changes are required to maintain
that usage.  However, unlike before, the compiler will report an
error if some non-zero bits of the literal would be discarded.

library/string.m:
	Enable overflow/underflow checking for base_string_to_int for
	any base.

	Update documentation.

library/lexer.m:
	Allow `big_integer' token functor to represent non-base 10
	literals as well.

	Add `integer_base' type.

library/term.m:
	Add `big_integer' term functor.

	Add `integer_base' type.

library/term_io.m:
	Add private helper functions `integer_base_int' and
	`integer_base_prefix'.

	Conform to changes.

library/parser.m:
	Pass through `big_integer' tokens as `big_integer' terms.

	Conform to changes.

compiler/prog_util.m:
	Add predicate to convert integer terms to ints with the
	aforementioned concession for bit patterns.

	`make_functor_cons_id' can now fail due to integer tokens
	exceeding the range of `int'.

compiler/superhomogeneous.m:
	Make `unravel_var_functor_unification' convert `big_integer'
	tokens on the RHS to a simple `int' with the aforementioned
	concession for bit patterns, or add an error message if any
	significant bits would be discarded.

compiler/fact_table.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/prog_io_util.m:
	Conform to changes.

compiler/make.util.m:
	Delete unused predicate.

tests/general/test_string_to_int_overflow.m:
tests/general/test_string_to_int_overflow.exp:
tests/general/test_string_to_int_overflow.exp2:
tests/general/test_string_to_int_overflow.exp3:
        Rewrite test case.

tests/hard_coded/lexer_bigint.exp:
tests/hard_coded/lexer_bigint.exp2:
tests/hard_coded/read_min_int.exp:
tests/hard_coded/read_min_int.exp2:
	Update expected outputs due to the lexer and term module changes.

tests/invalid/Mmakefile:
tests/invalid/invalid_int.err_exp:
tests/invalid/invalid_int.err_exp2:
tests/invalid/invalid_int.m:
	Add new test case.

NEWS:
	Announce the changes.
2015-02-17 12:14:16 +11:00
Zoltan Somogyi
13b6f03f46 Module qualify end_module declarations.
compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

compiler/table_gen.m:
    Remove an unused predicate, and inline another in the only place
    where it is used.

compiler/add_pragma.m:
    Give some predicates more meaningful names.
2014-09-04 00:24:52 +02:00
Julien Fischer
55283561ed Fix another problem with --detect-libgrades and --make.
Uses of --no-libgrade and --libgrade in Mercury.options files should override
any detected library grades.  For example, in a directory with a Mercury.options
file that contains

   MCFLAGS = --no-libgrade

we should expect "mmc --output-libgrades" to print nothing.  This was not the case.

compiler/mercury_compile.m:
	Do not combine the detected library grade flags with the ones from
	the command line options.  We need to keep them separate because
	they must be injected into the overall set of command line options
	before any flags from Mercury.options files.

	Add a note about a theoretical problem with DEFAULT_MCFLAGS and
	detected library grades.  It is not a problem in practice because
	the entire point of detected library grades was to avoid passing
	any information about library grades via DEFAULT_MCFLAGS.

	Thread the set of flags from detected grades down to places where
	they are needed.

	If the library grade set is empty, don't print out a single newline
	with --output-libgrades.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
	Pass the set of detected grade flags to where they are needed.
2013-09-13 18:11:22 +10:00
Julien Fischer
f6bdd99a80 Delete the MLDS->GCC (assembler) backend.
As discussed in the recent Mercury meeting, remove support for the GCC backend.
It was very much out of date and supporting it proprerly would means having to
track changes to GCC's internals.  Furthermore, its presence complicates
building the compiler.

The main thing this change does not address is the fact that we invoke
the compiler through C code, e.g. main.c in the top-level of the source
tree.  This was required by the GCC backend and can now be removed, but
I will do that as a separate change.

configure.ac:
Mmake.common.in:
scripts/Mmake.rules:
compiler/Mercury.options:
compiler/Mmakefile:

compiler/gcc.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mlds_to_gcc.m:
    Delete the files containing the GCC backend.

compiler/options.m:
compiler/handle_options.m:
    Delete support for `--target asm' and `--pic'.
    (The latter was only used by the GCC backend.)

compiler/*.m:
doc/user_guide.texi:
compiler/notes/comiler_design.html:
compiler/notes/work_in_progress.m:
    Conform to the above change.

README.gcc-backend.m:
    Delete this file.
2013-01-16 15:31:10 +11:00
Julien Fischer
14713ee3ce Fix compilation of the compiler in non C grades.
Branches: main

Fix compilation of the compiler in non C grades.

compiler/equiv_type_hlds.m:
compiler/hlds_out_mode.m:
compiler/inst_match.m:
compiler/make.util.m:
	Provide Mercury clauses for various foreign_procs that have
	been added recently.
2012-06-22 17:20:11 +00:00
Peter Wang
d2e304c7a8 Prevent interleaved error message output when using parallel `mmc --make'.
Branches: main

Prevent interleaved error message output when using parallel `mmc --make'.

compiler/make.m:
	Add a field to `make_info' to hold an inter-process lock.

compiler/make.util.m:
	Reuse the `job_ctl' type as the stdout lock.  Add predicates to acquire
	and release the lock.

	Make `foldl2_maybe_stop_at_error_parallel_processes' set the stdout
	lock in `make_info' for child processes to see.

	Acquire and release the stdout lock in various predicates that write
	errors messages.

compiler/make.module_target.m:
compiler/make.program_target.m:
	Conform to changes.
2012-05-11 03:56:48 +00:00
Julien Fischer
79272760de Avoid warnings from MSVC concerning assignments from uninitialized variables.
Branches: main, 11.07 (maybe)

Avoid warnings from MSVC concerning assignments from uninitialized variables.
These assignments arise due to the assignment of the initial I/O state to the
final I/O state in foreign_proc bodies.  In low-level C grades this leads to
code like the following:

    {
       MR_Word	IO0;
       MR_Word  IO;
       ...
       IO = IO0;
    }

Even though IO is itself unused, MSVC still emits a warning about the
assignment (many hundreds of warnings when the io module is opt-imported).
To avoid this, use don't-care variables for the I/O state in foreign procs
and don't include references to the I/O state in their bodies at all.
(We already did this in some places but not others.)

library/benchmarking.m:
library/dir.m:
library/io.m:
library/par_builtin.m:
library/stm_builtin.m:
library/thread.semaphore.m:
library/time.m:
compiler/make.util.m:
compiler/process_util.m:
	Make the above change.

	Delete the MR_update_io macro that is defined in a couple of spots.

library/io.m:
	Unrelated change: s/MR_CONSERVATIVE_GC/MR_BOEHM_GC/ in a spot
	since the former does not imply the later and the code that is
	protecting is Boehm GC specific.

tests/debugger/poly_io_retry2.m:
	Conform the the above change.
2011-10-11 04:31:05 +00:00
Zoltan Somogyi
295415090e Convert almost all remaining modules in the compiler to use
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all remaining modules in the compiler to use
	"$module, $pred" instead of "this_file" in error messages.

	In a few cases, the old error message was misleading, since it
	contained an incorrect, out-of-date or cut-and-pasted predicate name.

tests/invalid/unresolved_overloading.err_exp:
	Update an expected output containing an updated error message.
2011-05-23 05:08:24 +00:00
Julien Fischer
3a98283d03 Further work on getting the Mercury system to compile in the erlang grade.
Branches: main, 11.01

Further work on getting the Mercury system to compile in the erlang grade.

compiler/Makefile:
	Don't introduce dependencies on archives (and main.o) in non-C
	grades.

compiler/make.util.m:
compiler/pickle.m:
compiler/timestamp.m:
	Add stub Erlang and default Mercury definitions where needed.

profiler/PROF_FLAGS.in:
	Tell the compiler where the .hrl files for the standard library.
2011-01-19 07:01:49 +00:00
Julien Fischer
efba79f074 A step towards getting the compiler to build in the java (and other non-C)
Branches: main, 11.01

A step towards getting the compiler to build in the java (and other non-C)
grade(s).

library/Mmakefile:
	Don't make lib_std depend on Native.so (which is currently
	unused) in the java grade.

	The lib_std target for the java grade *does* need to be
	defined if mmake --use-mmc-make is being used; not the
	other way round.

browser/Mmakefile:
	There is no "jars" target (and in any case the standard
	top-level in this directory works.)

compiler/Mmakefile:
	Bump the heap size for javac since the default is not
	sufficient.

compiler/make.util.m:
compiler/md4.m:
compiler/pickle.m:
compiler/process_util.m:
compiler/prog_events.m:
	Provide definitions of some predicates for the non-C backends.
2011-01-19 01:47:59 +00:00
Zoltan Somogyi
1c3bc03415 Make the system compiler with --warn-unused-imports.
Estimated hours taken: 2
Branches: main, release

Make the system compiler with --warn-unused-imports.

browser/*.m:
library/*.m:
compiler/*.m:
	Remove unnecesary imports as flagged by --warn-unused-imports.

	In some files, do some minor cleanup along the way.
2010-12-30 11:18:04 +00:00
Zoltan Somogyi
8a28e40c9b Add the predicates sorry, unexpected and expect to library/error.m.
Estimated hours taken: 2
Branches: main

Add the predicates sorry, unexpected and expect to library/error.m.

compiler/compiler_util.m:
library/error.m:
	Move the predicates sorry, unexpected and expect from compiler_util
	to error.

	Put the predicates in error.m into the same order as their
	declarations.

compiler/*.m:
	Change imports as needed.

compiler/lp.m:
compiler/lp_rational.m:
	Change imports as needed, and some minor cleanups.

deep_profiler/*.m:
	Switch to using the new library predicates, instead of calling error
	directly. Some other minor cleanups.

NEWS:
	Mention the new predicates in the standard library.
2010-12-15 06:30:36 +00:00
Peter Wang
8426783fc4 Do not assume that pthread_mutexattr_setpshared() is available everywhere
Branches: main, 10.04

Do not assume that pthread_mutexattr_setpshared() is available everywhere
that pthread.h is available.  It is used to synchronise processes in the
`mmc --make --jobs' implementation.

configure.in:
runtime/mercury_conf.h.in:
        Define MR_HAVE_PTHREAD_MUTEXATTR_SETPSHARED if
        `pthread_mutexattr_setpshared' is found.

compiler/make.util.m:
        Only use pthread_mutexattr_setpshared() if it was found.
2010-10-28 23:59:09 +00:00
Peter Wang
9ffc04fef3 Shorten C# identifiers so as not to exceed the maximum length.
Branches: main

compiler/mlds_to_cs.m:
        Shorten C# identifiers so as not to exceed the maximum length.

        Make C# compiler not emit an error when it comes across a hexadecimal
        constant which would be interpreted as a negative integer.

        Make the generated Main() report uncaught Mercury exceptions.

compiler/make.util.m:
        Add C# implementation of get_real_milliseconds.
2010-10-01 07:02:06 +00:00
Peter Wang
fd76da59ff Add support for the csharp' grade to mmc --make', and make it possible to
Branches: main

Add support for the `csharp' grade to `mmc --make', and make it possible to
install the `csharp' grade with `mmake install'.

Also some miscellaneous fixes.


configure.in:
        Require a recent enough bootstrap compiler that recognises C# as a
        language for `pragma foreign_type'.

Mmakefile:
        Use `mmc --make' to install the standard library in csharp grade.

aclocal.m4:
        Search for the Mono C# compiler `gmcs', which is required for generics
        at this time.  Prefer it over the DotGNU C# compiler, which I have not
        tested.

        Search for `mono'.  If found, it will be used in shell scripts to
        launch executables generated via the csharp backend.

        Remove "MS_" prefixes on the variables MS_CSC and MS_ILASM, which are
        not Microsoft-specific.  More importantly, it should be less likely to
        make the mistake of adding an extra underscore to CSCFLAGS and
        ILASMFLAGS.

README.DotNet:
        Conform to variable renamings.

compiler/compile_target_code.m:
        Add new linked target types `csharp_executable', `java_launcher' and
        `erlang_launcher', instead of overloading `executable'.

        Link with `mer_std.dll' and other libraries when generating C#
        executables.  There is no `mer_rt.dll'.

        Pass "/debug" to the C# compiler if `--target-debug' is set.

        Create a shell script to launch the executable if necessary.

        Delete an unused predicate `standard_library_directory_option'.

compiler/file_names.m:
        `.cs' and `.cs_date' are grade-dependent.

compiler/handle_options.m:
        Force `.exe' as the executable file extension in csharp grades.

        Make the `erlang' grade component imply the same options as MLDS
        grades.

compiler/make.m:
        Classify executable target types based on the compilation target.

compiler/make.module_target.m:
        Handle `mmc --grade csharp --make <target>.dll'.

compiler/make.program_target.m:
        Install library DLLs in csharp grades.

        Make clean targets remove files for csharp grades.

        Conform to changes.

compiler/make.util.m:
        Add a stub foreign type.

        Conform to changes.

compiler/module_cmds.m:
        Factor out code to generate the shell scripts which launch programs
        compiled in Java, Erlang and C# grades.

compiler/options.m:
        Add `cli_interpreter' option to remember the name of the program which
        should be used to run CLI (.NET) programs.

        Add C#-related options to the help message.

compiler/options_file.m:
        Remove "MS_" prefixes on MS_ILASM_FLAGS and MS_CSC_FLAGS, and remove
        the extra underscore before "FLAGS".  In all uses of the variables,
        they were spelt without the extra underscore.

doc/user_guide.texi:
        Document options and file types related to the C# grade.

library/Mmakefile:
        Pass `mercury_dotnet.cs' to the C# compiler when building the standard
        library.  Suppress some warnings.

        Allow stubs in this directory for csharp grade.

        Conform to variable renamings.

library/builtin.m:
        Uncomment foreign language pragmas for C#.

        Handle null values in C# implementation of `deep_copy'.

library/private_builtin.m:
library/string.m:
        Compare strings by ordinals in C#, instead of culture-specific rules.
        Although the latter is allowed according to the documentation, it is
        likely to slower, and cause confusion when porting between backends.

        Handle negative index in string.set_char.

library/rtti_implementation.m:
        Uncomment foreign language pragmas for C#.

        `System.Type.GetType' only searches the current executing assembly or
        in mscorlib for a type.  As we have to be able to find types in other
        assemblies (e.g. mer_std.dll or user DLLs), explicitly search through
        a list of assemblies.

library/thread.semaphore.m:
        Uncomment foreign language pragmas for C#.

        Fix missing class qualification.

library/array.m:
library/bitmap.m:
library/bool.m:
library/dir.m:
library/exception.m:
library/io.m:
library/mutvar.m:
library/par_builtin.m:
library/region_builtin.m:
library/store.m:
library/thread.m:
library/time.m:
library/univ.m:
library/version_array.m:
        Uncomment foreign language pragmas for C#.

mdbcomp/rtti_access.m:
        Add type and procedure stubs.

runtime/mercury_dotnet.cs.in:
        Override `Equals(object)' methods in `TypeCtorInfo_Struct' and
        `TypeInfo_Struct' classes.  This requires we override `GetHashCode' as
        well.

        Handle nulls arguments to `Equals' methods as is the expected behaviour.

        Override `ToString' in `TypeCtorInfo_Struct' to produce more useful
        output during debugging.

scripts/Mercury.config.in:
        Record the configured CLI_INTERPRETER and pass that to the compiler as
        a flag.

        Conform to variable renamings.

scripts/Mmake.vars.in:
        Pass value of CSCFLAGS from Mmake through to `mmc --make'.

        Conform to variable renamings.

scripts/Mercury.config.bootstrap.in:
scripts/Mmake.rules:
        Conform to variable renaming.

scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
        Canonicalise high-level code, high-level-data, C# target code to the
        `csharp' grade.

        Handle erlang grades like other grades.

scripts/prepare_install_dir.in:
        Copy `.cs' files from the runtime directory when preparing an install
        directory.

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
ssdb/Mmakefile:
trace/Mmakefile:
        Do as other non-C grades in this directory.

        Conform to variable renamings.

tests/hard_coded/foreign_enum_dummy.m:
tests/hard_coded/sub-modules/non_word_mutable.m:
tests/hard_coded/sub-modules/sm_exp_bug.m:
        Make these tests work in C#.

tests/mmc_make/Mmakefile:
        Update a regular expression to account for `mmc --make' writing
        "Making rebuild.exe" on platforms where the .exe suffix is not normally
        used.

tests/mmc_make/complex_test.exp2:
        Add alternative output (minor difference in floating point precision).

tests/debugger/Mmakefile:
tests/debugger/declarative/Mmakefile:
tests/general/structure_reuse/Mmakefile:
tests/hard_coded/Mmakefile:
tests/hard_coded/sub-modules/Mmakefile:
tests/par_conj/Mmakefile:
tests/stm/Mmakefile:
        Disable some tests in the csharp grade.

tests/invalid/Mmakefile:
        Disable some tests in the csharp grade.

        Enable a test which should work in java grades.

tests/valid/Mmakefile:
        Do as other non-C grades in this directory.

        When testing the csharp grade in this directory, produce only the C#
        target files for now.

tests/run_one_test:
        Don't compress a failing test case executable when the executable is
        actually only a shell script.
2010-09-30 07:23:36 +00:00
Peter Wang
6b7d7b427a .cs' targets were formerly used to tell mmake' and `mmc --make' to generate
Branches: main

`.cs' targets were formerly used to tell `mmake' and `mmc --make' to generate
all the C files for a given target.  However, `.cs' is also the file name
extension for C# source files.  The recent addition of the C# backend
inadvertently changed the behaviour for `mmc --make'.

This patch restores `mmc --make's old interpretation of the `.cs' extension,
but adds new targets `.all_<ext>s' for both `mmake' and `mmc --make'.
The plan is to migrate to the latter syntax.

compiler/make.m:
compiler/make.util.m:
        Restore old behaviour for `.cs'.

        Accept `.all_<ext>s' syntax.

        Accept `.csharp' and `.all_csharps' as targets to generate C# files.
        This is only temporary.

compiler/file_names.m:
        The new `.all_<ext>s' mmake targets need to go in the current directory
        (not that the files actually exist).

compiler/write_deps_file.m:
        Write out `.all_<ext>s' rules in `.dep' files.

doc/user_guide.texi:
        Replace an instance of `.ints' in the documentation with `.all_ints'.

        Delete documentation of `.javas', `.classes', `.ils', `.erls', and
        `.beams' targets in the documentation.  `.cs', `.opts' and other
        targets are not documented either.  As far as I can tell, they are
        really designed to be used by bootcheck.
2010-09-21 07:43:19 +00:00
Peter Wang
57f9013259 Start a C# backend, adapted from mlds_to_java.m.
Branches: main

Start a C# backend, adapted from mlds_to_java.m.

Some `pragma foreign_*' declarations are commented out in this change because
no bootstrap compiler will yet accept "C#" in the language specification.

The compiler already supported C# foreign_procs for the IL backend, but the IL
backend and this new backend do not agree on naming and calling conventions so
the changes to the existing C# foreign_procs will further break the IL backend.
Nobody cares.

Only tested so far with Mono on Linux.

compiler/mlds_to_cs.m:
        New module.  In the CVS Attic there exists an obsolete file named
        mlds_to_csharp.m (replaced by mlds_to_managed.m) which we don't want to
        conflict with.

        For C# we need to know if a `pragma foreign_type' is a value or
        reference type.  Currently this is done by accepting a fake keyword
        `valuetype' before the type name, like for IL.

compiler/ml_backend.m:
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
        Hook up the C# backend.

compiler/globals.m:
        Add `target_csharp' as a target language.

compiler/options.m:
        Add `--csharp' and `--csharp-only' options and their synonyms.

compiler/handle_options.m:
        Handle `target_csharp' like `target_java', except for features which
        are still to be implemented.

compiler/add_pragma.m:
        Allow C# as a `pragma foreign_export' language.

        Allow C# for `pragma foreign_export_enum'.

        Conform to changes.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
        Accept C# as a language for `pragma foreign_type'.

        Accept `csharp' as the name of a grade in trace parameters.

compiler/make_hlds_passes.m:
        Reuse most of the code for implementing mutables on Java for C#.

compiler/mlds.m:
        Add a new MLDS target language, `ml_target_csharp'.

        Conform to changes.

compiler/ml_foreign_proc_gen.m:
        Generate foreign_procs for C#.

compiler/foreign.m:
        Update predicates to support C# targets.

compiler/c_util.m:
        Make `quote_string' use hexadecimal escapes in C# string literals.

compiler/parse_tree.m:
compiler/java_names.m:
        Add C# equivalents for predicates in this module.  `java_names' is a
        misleading module name, but the predicates for C# and Java share some
        code and may possibly be combined in the future.

compiler/rtti.m:
        Add predicates to return the names of RTTI structures in C#.

compiler/simplify.m:
        Handle the trace parameter `grade(csharp)'.

compiler/compile_target_code.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
        Add some support for building of executables and libraries with
        `--target csharp'.

compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/granularity.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modules.m:
compiler/pragma_c_gen.m:
compiler/prog_foreign.m:
compiler/special_pred.m:
compiler/write_deps_file.m:
        Conform to changes.

library/builtin.m:
library/rtti_implementation.m:
library/type_desc.m:
        Implement RTTI procedures for the new backend, which uses a high-level
        data representation (like the Java backend).  The existing C# code was
        designed for the IL backend, which used a low-level representation of
        the RTTI data structures.

        Most (if not all) of the the "new" code is exactly the same as the Java
        versions, with only syntactic changes.

        Rename the C# class `void_0' to `Void_0' to match the naming convention
        used by mlds_to_cs.m.

library/array.m:
        Update the existing C# code to work with the new backend.

        Use `object[]' as the type of all array of non-primitive types.
        The problem is one we encountered on the Java backend: when creating a
        new array based on the type of a single element, we don't know whether
        the new array should contain elements of the class or superclass.

library/bool.m:
        Export `bool' constants to C#.

library/exception.m:
        Update the existing C# code to work with the new backend.

        Move the `mercury.runtime.Exception' C# class to mercury_dotnet.cs.

library/float.m:
        Add C# implementations of `is_nan' and `is_inf'.

library/list.m:
        Add methods for manipulating lists from hand-written C# code.

library/string.m:
        Add C# implementations of string procedures which were missing.

library/dir.m:
library/io.m:
library/library.m:
        Update the existing C# code to work with the new backend.

library/private_builtin.m:
        Update the existing C# code to work with the new backend.

        Delete the static constants which are duplicated in mercury_dotnet.cs.
        The mlds_to_cs.m will emit references to the constants in the latter
        only.

library/backjump.m:
library/bitmap.m:
library/mutvar.m:
library/par_builtin.m:
library/region_builtin.m:
library/store.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/univ.m:
        Make these modules compile with the C# backend.

runtime/mercury_dotnet.cs.in:
        Add RTTI classes to the `mercury.runtime' namespace, equivalent to
        those on the Java backend.

        Use enumerations `MR_TYPECTOR_REP_*' and `MR_SECTAG_*' constants so we
        can switch on them.

        Add the `UnreachableDefault' exception class.

        Hide old classes which are unused with the new backend behind
        #ifdef !MR_HIGHLEVEL_DATA.
2010-09-16 00:39:12 +00:00