Commit Graph

160 Commits

Author SHA1 Message Date
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
7f62f7d8fa On the Java backend, a functor with the same name and arity as its type is
Branches: main, 10.04

On the Java backend, a functor with the same name and arity as its type is
given an extra "Mr_" prefix to distinguish it.  The Java implementation of
construct needs to account for the extra prefix; it does now.

library/rtti_implementation.m:
        As above.

tests/hard_coded/construct_mangle.exp:
tests/hard_coded/construct_mangle.m:
        Extend this test case.

        Add another name mangling problem, to be fixed some other time.
2010-09-30 03:16:23 +00:00
Peter Wang
417151ca01 Improve the C# backend.
Branches: main

Improve the C# backend.

C# foreign types remain commented out so as not to force an upgrade of the
bootstrap compiler yet.


compiler/handle_options.m:
        Enable static ground cells for C# backend.

compiler/ml_global_data.m:
        Make fields of static vector structures have `public' access.
        Local access doesn't make sense.

        Use structs to hold vector common data in C#.

        Conform to changes.

compiler/ml_proc_gen.m:
        Enable use_common_cells on C#.

        Conform to changes.

compiler/mlds.m:
        Rename `finality' to `overridability'.  The `final' keyword in Java
        has multiple meanings, so avoid that word.  Use the word `sealed'
        to describe classes or virtual methods which cannot be overridden,
        which is the keyword in C#.

compiler/ml_switch_gen.m:
        Remember the types of mlconst_foreign constants.  In the C# backend a
        foreign enum value needs to be cast to the right type.  For some
        reason, there was a field already which could be used for this purpose
        but was only ever set to mlds_native_int_type.

compiler/ml_type_gen.m:
        Replace ml_gen_final_member_decl_flags with
        ml_gen_const_member_decl_flags.  Return flags with the `sealed' flag
        unset, as that wouldn't make sense for member variables.

        Remember the type in mlconst_foreign.

compiler/ml_unify_gen.m:
        Remember the type in mlconst_foreign.

compiler/mlds_to_cs.m:
        Support static data in C#.

        Support foreign enumerations.

        Use the `default(T)' operator to initialise certain types of variables,
        particularly user-defined types, which the Mercury compiler may not
        know enumeration defined in another module, i.e. a value type, which
        cannot be initialised with `null'.

        Remove the requirement to add mark foreign types which are of value
        types with the "valuetype" prefix.

compiler/mlds_to_java.m:
        Write out the `final' keyword when either the `sealed' or `const' flags
        are set.

        Conform to changes.

compiler/rtti_to_mlds.m:
        RTTI data doesn't need the `sealed' flag set.

compiler/ml_code_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/ml_elim_nested.m:
        Conform to changes.

library/builtin.m:
        Export `comparison_result' to C# foreign code.

        Fix `deep_copy' for arrays.

library/bitmap.m:
library/pretty_printer.m:
library/store.m:
library/version_array.m:
library/version_hash_table.m:
        Implement these modules for C#.

library/io.m:
library/dir.m:
        Implement `dir.current_directory' for C#.

library/exception.m:
        Implement `catch_impl' for multi and nondet predicates.

library/rtti_implementation.m:
        Implement `get_typeclass_info_from_term' for C#.

library/string.m:
        Fix `string.set_char' for C#.

library/time.m:
        Delete now-unnecessary "valuetype" prefix on foreign type.

library/type_desc.m:
        Implement `make_type' for C#.

runtime/mercury_dotnet.cs.in:
        Collapse equivalences when comparing TypeInfo_Structs for equality.

tests/hard_coded/Mmakefile:
        Disable some tests in C# grade.

tests/hard_coded/ee_dummy.m:
tests/hard_coded/ee_valid_test.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/exported_foreign_enum.m:
tests/hard_coded/export_test.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/float_gv.m:
tests/hard_coded/foreign_enum_dummy.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_name_mutable.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/impure_init_and_final.m:
tests/hard_coded/intermod_poly_mode_2.m:
tests/hard_coded/loop_inv_test1.m:
tests/hard_coded/loop_inv_test.m:
tests/hard_coded/multimode.m:
tests/hard_coded/pragma_export.m:
tests/hard_coded/pragma_foreign_export.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/trace_goal_4.m:
tests/hard_coded/uc_export_enum.m:
tests/hard_coded/user_compare.m:
tests/hard_coded/write_xml.m:
        Make these test cases work on C#.

tests/hard_coded/deep_copy.exp3:
tests/hard_coded/expand.exp3:
tests/hard_coded/float_reg.exp3:
        Add expected results for C#.

tests/hard_coded/string_strip.exp2:
        Update this result, which was not updated when the test case changed
        previously.
2010-09-23 05:32:01 +00:00
Peter Wang
d953a1d17f Collapse equivalences when comparing type_infos for equality.
Branches: main, 10.04

java/runtime/TypeInfo_Struct.java:
        Collapse equivalences when comparing type_infos for equality.

java/runtime/TypeCtorRep.java:
        Duplicate the required constants which otherwise are in
        private_builtin.m.  They should all be moved here but I don't want to
        make that change on the 10.04 branch.

library/rtti_implementation.m:
        Collapse equivalences in type_info_num_functors.

tests/hard_coded/construct_bug.m:
        Use text streams in this test case, as the current hacky implementation
        of `io.write_binary' doesn't work on the Java backend.
2010-09-22 04:11:34 +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
Julien Fischer
a0277ac414 Avoid a warning from the C compiler.
Branches: main, 10.04

Avoid a warning from the C compiler.

library/rtti_implementation.m:
	Add a missing cast.
2010-07-12 14:32:00 +00:00
Peter Wang
0afad5bba9 Implement deconstruct.named_arg* and deconstruct.functor_number*
Branches: main, 10.04

library/deconstruct.m:
library/rtti_implementation.m:
        Implement deconstruct.named_arg* and deconstruct.functor_number*
        predicates for Java backend.

        Reformat some of the code.

tests/hard_coded/deconstruct_arg.m:
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
        Extend this test case to test named_arg_cc.
2010-07-02 02:35:07 +00:00
Peter Wang
6c549acd64 On startup, check for the SSDB_TTY environment variable.
Branches: main, 10.04

ssdb/ssdb.m:
        On startup, check for the SSDB_TTY environment variable.  If set, all
        debugger I/O is performed through the device named by the environment
        variable.  This is equivalent to the `mdb --tty <file-name>' option.

        Trap SIGINT and stop at the next possible point (C and Java grades).

        Add `print VAR' and `print N' commands.

        Add `vars' command.

library/rtti_implementation.m:
        Make `deconstruct' not escape special characters in the returned
        functor name argument for characters and strings, to match the
        behaviour on C backends.
2010-05-10 06:31:01 +00:00
Peter Wang
c053f90088 Allow inlining of Java foreign_procs.
Branches: main, 10.04

Allow inlining of Java foreign_procs.

This revealed a problem with directly using the `succeeded' flag directly as
the success indicator in Java foreign_procs.  When the code of the foreign_proc
becomes a nested function, and after nested functions are eliminated, there may
not be a variable called `succeeded' in that context; it is moved into
environment struct, and the transformation is not able to update handwritten
code to reflect that.  The solution is to declare a local variable for the
foreign_proc, let the handwritten code assign that, then assign its final
value to the `succeeded' flag with an MLDS statement.

We take the opportunity to name the local variable `SUCCESS_INDICATOR', in
line with other backends.

compiler/inlining.m:
        Allow inlining of Java foreign_procs.

compiler/ml_foreign_proc_gen.m:
        In the code generated for semidet Java foreign_procs, declare a local
        `SUCCESS_INDICATOR' variable and assign its value to the `succeeded'
        flag afterwards.

        Add braces to give the foreign_proc variables a limited scope.

compiler/make_hlds_warn.m:
        Conform to renaming.

doc/reference_manual.texi:
        Update documentation for the renaming of the `succeeded' variable.

library/array.m:
library/bitmap.m:
library/builtin.m:
library/char.m:
library/construct.m:
library/dir.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/string.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/version_array.m:
        Conform to renaming.

        Fix problems with Java foreign_procs that may now be copied into other
        modules when intermodule optimisation is enabled, some by disallowing
        the procedures from being duplicated, some by making referenced
        classes/fields `public'.

        [Some of the `may_not_duplicate' attributes may not indicate actual
        problems, just that it seems not worthwhile inlining calls to the
        procedure.]

extras/solver_types/library/any_array.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/java_test.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/user_compare.m:
tests/valid/exported_foreign_type2.m:
tests/warnings/warn_succ_ind.m:
tests/warnings/warn_succ_ind.exp3:
        Conform to renaming.
2010-05-07 03:12:27 +00:00
Peter Wang
1241e44a16 Mark rtti_implementation.semidet_call_* and result_call_* as builtin predicates
Branches: main, 10.04

Mark rtti_implementation.semidet_call_* and result_call_* as builtin predicates
which don't require typeinfo arguments to be passed.  This specifically
improves the implementation of generic_unify and generic_compare on the Java
backend.

mdbcomp/prim_data.m:
mdbcomp/program_representation.m:
        As above.

library/rtti_implementation.m:
        Add a comment.
2010-04-27 03:39:28 +00:00
Peter Wang
ea45fb3083 Make the Java backend use generics in the output.
Branches: main, 10.04

Make the Java backend use generics in the output.  We do not use generics
everywhere, only where it interfaces with hand written code:

- in classes generated for Mercury types
- in the signatures of foreign_exported procedures
- in the variables which interface with foreign_proc code

Make `--java-export-ref-out' be the default.  Both changes will require users
to update their code so we might as well make them together.


compiler/mlds.m:
compiler/ml_proc_gen.m:
compiler/ml_type_gen.m:
        Record type parameters for classes generated for Mercury types.

        Record universally quantified type variables for exported procedures.

        Assume `--java-export-ref-out'.

compiler/mlds_to_java.m:
        Output type variables in the appropriate places in the Java output.

compiler/ml_code_util.m:
        Add functions to return the MLDS types for jmercury.runtime.MercuryType
        and MercuryEnum.

compiler/ml_elim_nested.m:
compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
        Conform to previous changes.

compiler/hlds_pred.m:
        Change a wrong use of a type synonym.

compiler/options.m:
        Make `--java-export-ref-out' into a synonym for
        compiler_sufficiently_recent.  This may be used to test if the compiler
        supports that behaviour, and for compatibility with existing makefiles.

        Add an option for testing if the compiler generates Java code with
        generics.

doc/reference_manual.texi:
        Update manual to mention use of generics.

        Remove description of `--no-java-export-ref-out'.

library/exception.m:
library/io.m:
library/list.m:
library/rtti_implementation.m:
library/string.m:
library/type_desc.m:
        Update code to comply with use of generics and `--java-export-ref-out'.

tests/hard_coded/exceptions/Mmakefile:
        Allow `java' grade testing in this directory.
2010-04-15 02:56:02 +00:00
Peter Wang
f9757a03b2 Make Java version of get_type_ctor_rep return preallocated values.
Branches: main, 10.04

library/rtti_implementation.m:
        Make Java version of get_type_ctor_rep return preallocated values.

library/private_builtin.m:
        Add a constant which counts the number of MR_TYPECTOR_REP_* values.
2010-03-15 04:02:45 +00:00
Peter Wang
408b1621c9 Implement some RTTI procedures for Java:
Branches: main

Implement some RTTI procedures for Java:

        get_functor_ordinal/2,
        get_functor_lex/2,
        type_ctor/2,
        pseudo_type_ctor_and_args/3,
        make_type/2

Make type_desc/type_ctor_desc/pseudo_type_desc into synonyms for type_info/etc.,
mainly to simplify the hand-written RTTI handling functions.  Previously the
*_desc types were represented by *Desc wrapper classes.


compiler/mlds_to_java.m:
compiler/builtin_lib_types.m:
        Map *_desc types to TypeInfo_Struct, TypeCtorInfo_Struct,
        PseudoTypeInfo_Struct.  We cannot simply use
        `:- pragma foreign_type("Java", ...)' in the library as the compiler
        will complain about missing type definitions for other language
        backends.

library/construct.m:
        Implement get_functor_ordinal, get_functor_lex for Java backend.

        Conform to removal of *Desc classes.

library/rtti_implementation.m:
        Implement get_functor_ordinal, get_functor_lex,
        pseudo_type_ctor_and_args for Java backend.

        Handle existentially quantified arguments in get_functor_du.

        Make type_info/type_ctor_info comparison procedures compare module
        names before constructor names, to match MR_compare_type_info,
        MR_compare_type_ctor_info.

library/type_desc.m:
        Implement type_ctor, pseudo_type_ctor_and_args, make_type on Java
        backend.

        Conform to removal of *Desc wrapper classes.

java/runtime/TypeCtorInfo_Struct.java:
        Add constructor for variable arity type constructors.

java/runtime/TypeCtorRep.java:
        Delete unused constants.
2010-01-20 06:59:35 +00:00
Peter Wang
68a5c0047a On the Java backend, use specialised MethodPtr interfaces so that when calling
Branches: main

On the Java backend, use specialised MethodPtr interfaces so that when calling
a method pointer input arguments do not have to be passed via a temporary
array, for arities up to 15.  For higher arities the temporary array is still
used.

java/runtime/MethodPtr.java:
java/runtime/MethodPtr1.java:
java/runtime/MethodPtr10.java:
java/runtime/MethodPtr11.java:
java/runtime/MethodPtr12.java:
java/runtime/MethodPtr13.java:
java/runtime/MethodPtr14.java:
java/runtime/MethodPtr15.java:
java/runtime/MethodPtr2.java:
java/runtime/MethodPtr3.java:
java/runtime/MethodPtr4.java:
java/runtime/MethodPtr5.java:
java/runtime/MethodPtr6.java:
java/runtime/MethodPtr7.java:
java/runtime/MethodPtr8.java:
java/runtime/MethodPtr9.java:
java/runtime/MethodPtrN.java:
        Add specialised MethodPtr interfaces and MethodPtrN for any higher
        arities.

compiler/mlds_to_java.m:
        Make the code generator use the specialised MethodPtr interfaces.

library/Mmakefile:
        Compile java/runtime/*.java files explicitly as some MethodPtr*.java
        files won't be compiled implicitly when compiling the standard library.

library/exception.m:
java/runtime/Exception.java:
library/rtti_implementation.m:
        Conform to changes.
2009-09-03 05:04:16 +00:00
Peter Wang
ac3d1c6027 Expose correct types to Java foreign code, e.g. a variable with a non-foreign
Branches: main

Expose correct types to Java foreign code, e.g. a variable with a non-foreign
type like `list(T)' is now visible to Java foreign code with the type
`list.List_1' instead of `java.lang.Object'.

A complication is that foreign code for mutables is generated in the compiler
frontend, which doesn't know about the types used by the backends.  For Java,
mutable variables had the generic type `Object' (except for primitives types)
but as we now generate foreign procs with the correct variable types, the code
for accessing a mutable would be type incorrect, e.g.

        X = mutable_var;  /* list.List_1 = Object */

Here we handle generated mutable predicates as a special case, using `Object'
for the global variable and argument types and generating typecasts as before.
The correct fix would be to move mutable code generation into the backends.


compiler/make_hlds_passes.m:
        Make Java mutable variables always have the type `java.lang.Object'.

        Mark Java mutable predicates with `may_not_duplicate' attributes, as
        the generated code doesn't contain class-qualifiers for the mutable
        variable, so copying that code into other Java files won't work.

compiler/mlds.m:
        Add a new target code component `target_code_type(Type)' which is a
        placeholder for a type, to be substituted by the backend when target
        code is being printed out.

compiler/ml_code_gen.m:
        Generate Java foreign procs using `target_code_type' to declare local
        variables, except for mutable predicates as described above.

        Rename a predicate shared for C and Java.

        Assign dummy type variables the value `null' in the Java backend
        instead of `0'.

compiler/foreign.m:
        Add a comment for `exported_type_to_string'.

compiler/mlds_to_java.m:
        Handle the addition of `target_code_type'.

        Output `java.lang.Output' for builtin dummy types.  We were
        inconsistent as to whether builtin dummy types should be represented by
        `int' or `Object'.

        Output line number context in another spot.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
        Conform to the addition of `target_code_type'.

library/exception.m:
library/io.m:
library/list.m:
library/rtti_implementation.m:
library/string.m:
library/type_desc.m:
        Delete casts in some Java foreign code which are no longer required.
2009-09-02 05:48:02 +00:00
Peter Wang
fe4c25c16f Some changes to the Java implementation of the standard library.
Branches: main

Some changes to the Java implementation of the standard library.

library/array.m:
        Use System.arraycopy and java.util.Arrays.fill and avoid using
        reflection to work with arrays in some places.

library/dir.m:
        Implement dir.current_directory.

library/rtti_implementation.m:
        Fix typos where expanded type_infos were not being used.

library/string.m:
        Make string.c_pointer_to_string handle null pointers.

tests/hard_coded/sub-modules/Mmakefile:
        Enable testing of java grade in this directory.

tests/hard_coded/sub-modules/non_word_mutable.m:
tests/hard_coded/sub-modules/sm_exp_bug.m:
        Add Java foreign code.
2009-08-14 06:11:46 +00:00
Peter Wang
83e4aca25e Rename exported enumeration values without ML_ prefixes.
Branches: main

library/bool.m:
library/builtin.m:
        Rename exported enumeration values without ML_ prefixes.

library/list.m:
        Add `empty_list', `cons', `is_empty', `det_head' and `det_tail' methods
        for manipulating lists from Java foreign code.

        Add wrapper class `ListIterator<E>' that allows iteration over
        Mercury lists using Java for-each syntax (undocumented for now).

doc/reference_manual.texi:
doc/user_guide.texi:
        Update documentation pertaining to Java foreign language interface.

library/bitmap.m:
library/rtti_implementation.m:
library/string.m:
        Conform to renamings.

        Use for-each syntax in some places.
2009-08-12 01:56:26 +00:00
Peter Wang
4459a2e9ac The implementation of construct/3 for Java needs to take into account name
Branches: main

The implementation of construct/3 for Java needs to take into account name
mangling of module and functor names.

library/rtti_implementation.m:
        Replicate the name mangling algorithm in the construct implementation
        for Java.

compiler/prog_foreign.m:
        Add a forwarding comment if the name mangling algorithm changes.

tests/hard_coded/Mmakefile:
tests/hard_coded/construct_mangle.exp:
tests/hard_coded/construct_mangle.m:
        Add test case.
2009-08-07 06:14:29 +00:00
Peter Wang
c6b277dd3a Implementation of construct and construct_tuple for Java backend.
Branches: main

Implementation of construct and construct_tuple for Java backend.

java/runtime/TypeCtorInfo_Struct.java:
        The type_ctor_num_functors field was not being initialised.

library/construct.m:
        Call the predicates in rtti_implementation.m when appropriate.

library/rtti_implementation.m:
        Fix get_functor_enum which was confused lexical ordering and functor
        ordinals.

        Implement construct and construct_tuple for Java backend.

        Delete some out of date comments.

library/type_desc.m:
        Add Pseudo_type_desc_0 class which mirrors the
        jmercury.runtime.PseudoTypeInfo class with Type_desc_0 and
        Type_ctor_desc_0 as subclasses.

        Fill in stubs that work with pseudo_type_descs.

library/univ.m:
        Export predicates.

README.Java:
        Update readme.
2009-07-31 06:54:21 +00:00
Peter Wang
03fce105aa Implement collapse_equivalences for Java. Use it for a case in
Branches: main

library/rtti_implementation.m:
        Implement collapse_equivalences for Java.  Use it for a case in
        deconstruct_2.

library/type_desc.m:
        Implement unify/compare on type_descs for Java.
2009-06-26 06:12:18 +00:00
Peter Wang
1b648d0ac2 Put all Mercury-generated Java classes into the package `jmercury' and
Branches: main

Put all Mercury-generated Java classes into the package `jmercury' and
runtime classes into `jmercury.runtime'.  The Mercury module hierarchy is
not reflected in the package name.  We name sub-module classes using
their fully-qualified module names with `__' between components, e.g.
`bit_buffer.read' produces `class bit_buffer__read'.

As all generated Java code is in the same package we don't need to package
qualify identifiers, and we don't need the hack to avoid clashing package
and class names.  It also makes it easier to write Java foreign code because
generated Java class names are easier to predict from Mercury module names.

The package names are not `mercury' and `mercury.runtime' because on
case-insensitive file systems we may end up with a `mercury' directory
that could be confused with the `Mercury' directory.


compiler/java_names.m:
        Delete code related to mangling package names.

        Remove the extra `mercury' prefix added to standard library module
        names, as it is redundant with `jmercury'.

        Change runtime package name.

compiler/mlds_to_java.m:
        Make generated code follow the new packaging scheme.

        Don't automatically import all runtime classes.  It doesn't seem
        necessary.

        Update for new packaging scheme.

compiler/file_names.m:
        Fix Java file paths for the new packaging scheme.

compiler/module_cmds.m:
compiler/rtti.m:
library/array.m:
library/backjump.m:
library/benchmarking.m:
library/bitmap.m:
library/builtin.m:
library/exception.m:
library/io.m:
library/library.m:
library/mutvar.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.m:
library/time.m:
library/type_desc.m:
java/runtime/*.java:
        Rename package names.

        Delete unnecessary package qualification.

compiler/mlds.m:
        Add some XXXs to be fixed later.

library/Mmakefile:
        Update for new packaging scheme.

        Let mmake --use-mmc-make work in this directory.
2009-06-17 07:48:16 +00:00
Peter Wang
79e0b9eb1d Work on RTTI implementation for Java.
Branches: main

Work on RTTI implementation for Java.

library/construct.m:
library/type_desc.m:
        Properly distinguish between type_infos and type_descs.  These are not
        the same in Java grades (for now, at least).
        Use special purpose conversion functions instead of unsafe_casts.

        Don't call erlang_rtti_implementation.m predicates in other grades.

library/rtti_implementation.m:
        Properly distinguish between type_infos and type_descs.
        Use special purpose conversion functions instead of unsafe_casts.

        Implement some stub predicates for Java.

        Fix get_arg_type_info which assumed the usual low-level type_info
        representation.  In Java we have a TypeInfo_Struct class with a
        distinct array for type_info arguments so all the indices to access
        arguments were wrong.

        Try to be consistent about how variables are numbered (start from 1).

        Rename some predicates to make them less ambiguous.

        Don't use field access to call functions as it is confusing.

        Update unsafe_get_enum_value for an earlier change where I renamed the
        `value' field in enumeration classes to `MR_value'.

library/stream.string_writer.m:
library/string.m:
        Convert type_infos to type_descs properly.

library/erlang_rtti_implementation.m:
        Unrelated: use private_builtin.unsafe_type_cast instead of a
        foreign_proc.

library/io.m:
        Unrelated: add Java implementation of io.stdout_stream_2/1.

java/runtime/TypeInfo_Struct.java:
        Add a copy method.
2009-06-10 03:31:57 +00:00
Zoltan Somogyi
a2d52f9246 Document the non-dummy definition of pseudo_type_info as a workaround.
Estimated hours taken: 0.1
Branches: main

library/rtti_implementation.m:
	Document the non-dummy definition of pseudo_type_info as a workaround.
2009-06-04 05:41:26 +00:00
Peter Wang
f429ea2e63 Make the dummy definition of pseudo_type_info not be a dummy type,
Branches: main

library/rtti_implementation.m:
        Make the dummy definition of pseudo_type_info not be a dummy type,
        to work around the Erlang backend to generating invalid code for this
        module.
2009-06-02 10:37:50 +00:00
Peter Wang
5012b8f45e The Java 5 compiler warns about a method with an array argument:
Branches: main

The Java 5 compiler warns about a method with an array argument:

	m1(Object[] args)

overriding a method declared with varargs:

	m1(Object... args)

The Java 6 compiler accepts it, though I don't know if that was intended.


java/runtime/MethodPtr.java:
	Don't use varargs syntax for MethodPtr.call___0_0.

library/rtti_implementation.m:
	Explicitly create the Object[] arrays in foreign_procs.
2009-06-01 11:06:36 +00:00
Peter Wang
297046f7d7 Fix Java implementation of `get_subterm' to look up the name of the
Branches: main

library/rtti_implementation.m:
        Fix Java implementation of `get_subterm' to look up the name of the
        field to extract, which is necessary if the field in the Mercury type
        was named.
2009-05-01 05:54:11 +00:00
Peter Wang
d1cffc4523 RTTI improvements for Java backend. io.write/3 works for some simple types
Branches: main

RTTI improvements for Java backend.  io.write/3 works for some simple types
(builtin types and non-existential d.u. types).

compiler/mlds_to_java.m:
        Fix problem with cyclic RTTI definitions.  Initialisers could refer to
        other RTTI structures which weren't yet allocated, leading to fields
        being null.  The fix is to allocate all top-level RTTI objects first
        and initialise in a second phase.

java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/TypeClassConstraint.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassId.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeInfo_Struct.java:
        Separate constructors into constructors for the initial allocation,
        and an `init' method to fill in the fields.

java/runtime/MethodPtr.java:
        Use variadic method support to simplify semidet_call_* and
        result_call_* in rtti_implementation.m.

library/builtin.m:
        Make Java definitions of builtin.unify/2 and builtin.compare/3 call
        rtti_implementation.generic_unify and generic_compare.

library/private_builtin.m:
        Add missing MR_TYPECTOR_REP_FOREIGN_ENUM{,_USEREQ} constants
        for C# and Java.

library/rtti_implementation.m:
        Fix and add missing Java versions of many foreign_procs.

        Add more attributes to foreign_procs.

        Clean up the code a bit (fewer casts and ^ field access functions).

README.Java:
        Bump Java version requirement to J2SE 1.5 or higher.
2009-04-30 00:43:35 +00:00
Peter Wang
dd53891e9f Assorted library fixes and stubs for the Java backend.
Branches: main

java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeFunctors.java:
library/backjump.m:
library/builtin.m:
library/io.m:
library/math.m:
library/mutvar.m:
library/par_builtin.m:
library/private_builtin.m:
library/region_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.m:
library/thread.semaphore.m:
library/time.m:
library/type_desc.m:
        Assorted library fixes and stubs for the Java backend.
2009-04-22 03:03:17 +00:00
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Julien Fischer
1fac629e6d Add support for foreign enumerations to Mercury.
Estimated hours taken: 50
Branches: main

Add support for foreign enumerations to Mercury.  These allow the
programmer to assign foreign language values as the representation of
enumeration constructors.

e.g.
	:- type status
		--->	optimal
		;	infeasible
		;	unbounded
		;	unknown.

	:- pragma foreign_enum("C", status/0, [
		optimal    - "STATUS_OPTIMAL",
		infeasible - "STATUS_INFEASIBLE",
		unbounded  - "STATUS_UNBOUNDED",
		unknown    - "STATUS_UNKNOWN"
	]).

The advantage of this is that when values of type status/0 are passed to
foreign code (C in this case) no translation is necessary.  This should
simplify the task of writing bindings to foreign language libraries.

Unification and comparison for foreign enumerations are the usual
unification and comparison for enumeration types, except that the default
ordering on them is determined by the foreign representation of the
constructors.  User-defined equality and comparison also work for foreign
enumeration types.

In order to implement foreign enumerations we have to introduce two
new type_ctor representations.  The existing ones for enum type do not
work since they use the value of an enumeration constructor to perform
table lookups in the RTTI data structures.  For foreign enumerations
we need to perform a linear search at the corresponding points.  This
means that some RTTI operations related to deconstruction are more
expensive.

The dummy type optimisation is not applied to foreign enumerations as
the code generators currently initialise the arguments of non-builtin
dummy type foreign_proc arguments to zero.  For unit foreign enumerations
they should be initialised to the correct foreign value.  (This is could be
implemented but in practice it's probably not going to be worth it.)

Currently, foreign enumerations are only supported by the C backends.

compiler/prog_io_pragma.m:
	Parse foreign_enum pragmas.

	Generalise the code used to parse association lists of sym_names
	and strings since this is now used by the code to parse foreign_enum
	pragmas as well as that for foreign_export_enum pragmas.

	Fix a typo: s/foreign_expor_enum/foreign_export_enum/

compiler/prog_item.m:
	Represent foreign_enum pragmas in the parse tree.

compiler/prog_type.m:
	Add a new type category for foreign enumerations.

compiler/modules.m:
	Add any foreign_enum pragmas for enumeration types defined in the
	interface of a module to the interface files.

	Output foreign_import_module pragmas in the interface file
	if any foreign_enum pragmas are included in it.  This ensures that
	the contents that any foreign declarations that are needed by the
	foreign_enum pragmas are visible.

compiler/make_hlds_passes.m:
compiler/add_pragma.m:
	Add pragma foreign_enum items to the HLDS after all the types
	have been added.  As they are added, error check them.

	Change the constructor tag values of foreign enum types to their
	foreign values.

compiler/module_qual.m:
	Module qualify pragma foreign_enum items.

compiler/mercury_to_mercury.m:
	Output foreign_enum pragmas.

	Generalise some of the existing code for writing out association
	lists in foreign_export_enum pragmas for use with foreign_enum
	pragmas as well.

compiler/hlds_data.m:
	Add the alternative `is_foreign_type' to the type enum_or_dummy/0.

	Add new type of cons_tag, foreign_tag, whose values are directly
	embedded in the target language.

compiler/intermod.m:
	Write out any foreign_enum pragmas for opt_exported types.
	(The XXX concerning attaching language information to foreign tags
	will be addressed in a subsequent change.)

compiler/llds.m:
compiler/mlds.m:
	Support new kinds of rval constants: llconst_foreign and
	mlconst_foreign respectively.  Both of these represent tag values
	as strings that are intended to be directly embedded in the target
	language.

compiler/llds_out.m:
	Add code to write out the new kind of rval_const.

	s/Integer/MR_Integer/ in a spot.
	s/Float/MR_Float/ in a spot.

compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/type_ctor_info.m:
	Add support the RTTI required by foreign enums.

compiler/switch_util.m:
	Handle switches on foreign_enums as-per normal enumerations.

compiler/table_gen.m:
	Tabling of foreign_enums is also like normal enumerations.

compiler/type_util.m:
	Add a predicate that tests whether a type is a foreign enumeration.

compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/ml_unify_gen.m:
	Handle unification and comparison of foreign enumeration values.
	They are treated like normal enumerations for the purposes of
	implementing these operations.

compiler/ml_type_gen.m:
	Handle foreign enumerations when generating the MLDS representation
	of enumerations.

compiler/ml_util.m:
	Add a function to create an initializer for an object with a
	foreign tag.

compiler/mlds_to_c.m:
	Handle mlconst_foreign/1 rval constants.

compiler/bytecode_gen.m:
compiler/dupproc.m:
compiler/erl_rtti.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/hlds_out.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/jumpopt.m:
compiler/llds_to_x86_64.m:
compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/polymorphism.m:
compiler/recompilation.version.m:
compiler/term_norm.m:
compiler/trailing_analysis.m:
	Conform to the above changes.

doc/reference_manual.texi:
	Document the new pragma.

	Fix some typos: s/pramga/pragma/, s/behavior/behaviour/

library/construct.m:
	Handle the two new type_ctor reps.

	Break an over-long line.

library/rtti_implementation.m:
	Support the two new type_ctor reps.
	(XXX The Java versions of some of this cannot be implemented until
	support for foreign enumerations is added to mlds_to_java.m.)

	Reformat the inst usereq/0 and extend it to include foreign enums.

runtime/mercury_type_info.h:
	Add two new type_ctor reps.  One for foreign enumerations and
	another for foreign enumerations with user equality.

	Define new types (and extend existing ones) in order to support
	RTTI for foreign enumerations.

runtime/mercury_unify_compare_body.h:
	Implement generic unify and compare for foreign enumerations.
	(It is the same as that for regular enumerations.)

runtime/mercury_construct.[ch]:
runtime/mercury_deconstruct.h:
	Handle (de)construction of foreign enumeration values.

runtime/mercury_deep_copy_body.h:
	Implement deep copy for foreign enumerations.

runtime/mercury_table_type_body.h:
runtime/mercury_term_size.c:
	Handle the new type_ctor representations.

java/runtime/ForeignEnumFunctorDesc.java:
	Add a Java version of the MR_ForeignEnumFuntorDesc structure.
	(Note: this is untested, as the java grade runtime doesn't work
	anyway.)

java/runtime/TypeFunctors.java:
	Add a constructor method for foreign enumerations.
	(Likewise, untested.)

NEWS:
	Announce pragma foreign_enum.

vim/syntax/mercury.vim:
	Highlight the new pragma appropriately.

tests/hard_coded/.cvsignore:
	Ignore executables generated by the new tests.

	Ignore a bunch of other files create by the Mercury compiler.

tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_enum_rtti.{m,exp}:
	Test RTTI for foreign enumerations.

tests/hard_coded/foreign_enum_dummy.{m,exp}:
	Check that dummy type optimisation is disabled for foreign
	enumerations.

tests/hard_coded/Mercury.options:
tests/hard_coded/foreign_enum_mod1.{m,exp}:
tests/hard_coded/foreign_enum_mod2.m:
	Test that foreign_enum pragmas are hoisted into interface files
	and that they are handled correctly in optimization interfaces.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/invalid/foreign_enum_import.{m,err_exp}:
tests/invalid/foreign_enum_invalid.{m,err_exp}:
	Test that errors in foreign_enum pragmas are reported.

tests/tabling/Mmakefile:
tests/hard_coded/table_foreign_enum.{m,exp}:
	Test case for tabling of foreign enumerations.
2007-08-20 03:39:31 +00:00
Peter Ross
05bc429daa Add erlang implementations of construct rtti routines.
Estimated hours taken: 8
Branches: main

Add erlang implementations of construct rtti routines.

library/construct.m:
	Call the erlang_rtti_implementation version of predicates.

library/deconstruct.m:
	Move is_erlang_backend to erlang_rtti_implementation.

library/erlang_rtti_implementation.m:
	Implement num_functors, get_functor and get_functor_with_names.

library/rtti_implementation.m:
	Add an erlang version of unsafe_cast as it is used by construct.
2007-07-25 03:08:50 +00:00
Peter Wang
c2e8e6db5f Delete unnecessary promise_pure for 'unsafe_byte :='.
Estimated hours taken: 0
Branches: main

library/bitmap.m:
	Delete unnecessary promise_pure for 'unsafe_byte :='.

library/rtti_implementation.m:
	Delete stray commented out line.
2007-07-17 06:22:52 +00:00
Peter Ross
4b622b11d7 Implemenation of deconstruct for the Erlang backend.
Estimated hours taken: 3
Branches: main

Implemenation of deconstruct for the Erlang backend.
It doesn't handle du or eqv types yet.

library/erlang_rtti_implementation.m:
	Inititial implementation of deconstruct.

library/rtti_implementation.m:
	Fix two XXX's by calling the appropiate
	routine from term_io.
2007-06-01 08:30:58 +00:00
Peter Ross
85bb27cfe0 New implementation of RTTI for the Erlang backend.
Estimated hours taken: 12
Branches: main

New implementation of RTTI for the Erlang backend.  Currently the RTTI only
supports generic compare and unify, deconstruct and construct are still to
come.

compiler/erl_rtti.m:
	Add a function which converts rtti_data to erlang_rtti_data.
	Change rtti_data_list_to_elds to operate on erlang_rtti_data,
	and output a erlang tuple which represents a type_ctor_info.

compiler/erlang_rtti.m:
	The definition of the RTTI needed for the Erlang backend,
	for the moment only the type_ctor_info differs from the
	low-level backends.
	This was designed in conjunction with zs.

compiler/backend_libs.m:
	Add erlang_rtti.

compiler/elds.m:
	Add a utility predicate which returns the erlang representation
	of enum type for a given functor.

compiler/mercury_compile.m:
	Call the new erl_rtti predicates.

library/builtin.m:
	Call the erlang_rtti_implementation generic compare and unify
	predicates.

library/erlang_rtti_implementation.m:
	An implementation of generic compare and unify in Mercury,
	with some tiny bits of erlang foreign_procs to inspect a type_info
	and type_ctor_info.

library/library.m:
	Reference the erlang_rtti_implementation module.

library/rtti_implementation.m:
	Remove all the Erlang code as this implementation of
	RTTI is too low-level.
2007-06-01 02:13:02 +00:00
Peter Ross
e3f8bbf9aa Implement the TypeCtorInfo RTTI so that generic compare
Estimated hours taken: 16
Branches: main

Implement the TypeCtorInfo RTTI so that generic compare
and unify work via rtti_implementation.

However after discussion with zs, this current design of
RTTI has to be adapted to become more erlang specific, due
to the different data representation on the erlang backend.
The current code will serve as a template for this new design
though, which is why it is being checked in.

Add various erlang library implementations which are
needed to run useful programs when testing the erlang backend.

compiler/elds.m:
	Add a type_info_id.

compiler/elds_to_erlang.m:
	We now generate type_ctor_info's so call them.

compiler/erl_rtti.m:
	After discussions with zs, type_info and pseudo_type_infos
	should never occur on the erlang backend as they are needed
	for gc and the debugger so throw an exception for them.
	Add an implementation of creating a static type_info, but which
	isn't used in case we need it again later.
	Create type_ctor_info with all the fields except the
	TypeFunctors, the TypeLayout and the FunctorNumberMap

compiler/special_pred.m:
	Make sure we generate RTTI for the builtin types.

library/builtin.m:
library/char.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/lexer.m:
library/math.m:
library/mutvar.m:
library/ops.m:
library/par_builtin.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/solutions.m:
library/store.m:
library/string.m:
library/table_builtin.m:
library/thread.semaphore.m:
library/time.m:
library/type_desc.m:
	Erlang implementations of std library functions.
2007-05-30 08:16:09 +00:00
Julien Fischer
62cc99e241 Formatting and style fixes for standard library modules.
Estimated hours taken: 0.2
Branches: main

Formatting and style fixes for standard library modules.

Fix a bunch of minor problems, e.g. unnecessary module imports.

library/bitmap.m:
	s/memcpy/MR_memcpy/ in a spot.

	Call throw/1 rather than error/1 and don't import the require
	module.

library/term_to_xml.m:
	Don't import the require module.  It is unused here.

library/time.m:
	Add some missing `thread_safe' annotations.

library/bool.m:
library/cord.m:
library/gc.m:
library/multi_map.m:
library/queue.m:
library/rtti_implementation.m:
library/set.m:
library/set_bbbtree.m:
library/svarray.m:
library/svbag.m:
library/svbimap.m:
library/sveqvclass.m:
	Formatting and style fixes.
2007-03-06 05:48:34 +00:00
Simon Taylor
9c650e1d83 Improvements for bitmap.m, to make it useable as a general container
Estimated hours taken: 80
Branches: main

Improvements for bitmap.m, to make it useable as a general container
for binary data.

library/bitmap.m:
runtime/mercury_bitmap.c:
runtime/mercury_bitmap.h:
	Specialize the representation of bitmaps to an array of unsigned
	bytes defined as a foreign type.

	This is better than building on top of array(int) because it:
	- is better for interfacing with foreign code
	- has a more sensible machine-independent comparison order
	  (same as array(bool))
	- avoids storing the size twice
	- has more efficient copying, unification, comparison and tabling
	  (although we should probably specialize the handling of array(int)
	  and isomorphic types as well)
	- uses GC_MALLOC_ATOMIC to avoid problems with bit patterns that look
	  like pointers (although we should do that for array(int) as well)

	XXX The code for the Java and IL backends is untested.
	Building the library in grade Java with Sun JDK 1.6 failed (but
	at least passed error checking), and I don't have access to a
	copy of MSVS.NET.  The foreign code that needs to be tested is
	trivial.

	Add fields `bit', `bits' and `byte' to get/set a single bit,
	multiple bits (from an int) or an 8 bit byte.

	Add functions for converting bitmaps to hex strings and back,
	for use by stream.string_writer.write and deconstruct.functor/4.

	bitmap.intersect was buggy in the case where the input bitmaps
	had a different size.  Given that bitmaps are implemented with
	a fixed domain (lookups out of range throw an exception), it
	makes more sense to throw an exception in that case anyway,
	so all of the set operations do that now.

	The difference operation actually performed xor.  Fix it and
	add an xor function.

library/version_bitmap.m:
	This hasn't been fully updated to be the same as bitmap.m.
	The payoff would be much less because foreign code can't
	really do anything with version_bitmaps.

	Add a `bit' field.

	Deprecate the `get/2' function in favour of the `bit' field.

	Fix the union, difference, intersection and xor functions
	as for bitmap.m.

	Fix comparison of version_arrays so that it uses the same
	method as array.m: compare size then elements in order.
	The old code found version_arrays to be equal if one was
	a suffix of the other.

library/char.m:
	Add predicates for converting between hex digits and integers.

library/io.m:
library/stream.string_writer.m:
library/term.m:
	Read and write bitmaps.

runtime/mercury_type_info.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_mcpp.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_unify_compare_body.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_term_size.c:
runtime/mercury_string.h:
library/construct.m:
library/deconstruct.m
compiler/prog_type.m:
compiler/mlds_to_gcc.m:
compiler/rtti.m:
	Add a MR_TypeCtorRep for bitmaps, and handle it in the library
	and runtinme.

library/Mercury.options:
	Compile bitmap.m with `--no-warn-insts-without-matching-type'.

runtime/mercury_type_info.h:
	Bump MR_RTTI_VERSION.

NEWS:
	Document the changes.

tests/hard_coded/Mmakefile:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/bitmap_simple.m:
tests/hard_coded/bitmap_tester.m:
tests/hard_coded/bitmap_test.exp:
tests/tabling/Mmakefile:
tests/tabling/expand_bitmap.m:
tests/tabling/expand_bitmap.exp:
tests/hard_coded/version_array_test.m:
tests/hard_coded/version_array_test.exp:
	Test cases.
2007-02-13 01:59:04 +00:00
Julien Fischer
8528588d3b Fix problems with a few Mercury clauses in the standard library that have C
(This patch is due to Jon Morgan).

Estimated hours taken: 0.2
Branches: main

Fix problems with a few Mercury clauses in the standard library that have C
foreign procedure declarations, and will not build with the default Mercury
clause.

library/rtti_implementation.m:
	Alter num_functors to fail rather than returning -1 for types
	without functors, to conform to the recent change in construct.

library/term_size_prof_builtin.m:
    	Import require, so that error can be used to indicate that the
	function is unsupported for any backends that do not implement this
	module's functionality.

library/Mercury.options:
	Disable `--warn-unused-imports' when compiling the above module
	since the results from it will not be reliable.  (See XXX comment
	at head of compiler/unused_imports.m for details.)
2007-01-23 02:49:50 +00:00
Zoltan Somogyi
2ca194ab17 Rename some function symbols and predicates to eliminate a bunch
Estimated hours taken: 3
Branches: main

library/term_to_xml.m:
library/rtti_implementation.m:
	Rename some function symbols and predicates to eliminate a bunch
	of ambiguities.

browser/browse.m:
tests/hard_coded/write_xml.m:
tests/hard_coded/xmlable_test.m:
	Conform to the change above.
2006-09-25 01:56:17 +00:00
Mark Brown
0731932d14 Construct strings representing c_pointer addresses.
Estimated hours taken: 2
Branches: main

runtime/mercury_ml_expand_body.h:
	Construct strings representing c_pointer addresses.  Used in the
	implementation of functor and deconstruct.

library/deconstruct.m:
	Document the behaviour of functor and deconstruct for c_pointers.

library/string.m:
	Export c_pointer_to_string for getting a string representation
	of the pointer address.

library/io.m:
library/rtti_implementation.m:
	Use c_pointer_to_string/1 to print c_pointers.

	Update comments.

library/pprint.m:
	Undo Ralph's earlier change, since it is no longer required.

tests/debugger/Mmakefile:
tests/debugger/declarative/Mmakefile:
	Canonicalize the output of test cases in which c_pointers appear.

tests:
	Update the expected output of test cases.
2006-08-22 02:33:54 +00:00
Julien Fischer
e006ed939e Fix a bug reported by Jonathan Morgan.
library/rtti_implementation.m:
	s/NULL/null in some C# foreign code.
2006-05-09 05:04:50 +00:00
Julien Fischer
a6508191fc Make the IL backend compile successfully.
(This patch was submitted by Jon Morgan.)

Estimated hours taken: 0.5
Branches: main, release

Make the IL backend compile successfully.

library/private_builtin.m:
       Revert incorrect s/__/. in C# and Java foreign code.
library/rtti_implementation.m:
       s/NULL/null in C# foreign code.
2006-05-01 14:45:19 +00:00
Julien Fischer
e0f5ac47db Make it easier for vi to jump past the initial comments
Estimated hours taken: 0.1
Branches: main

library/*.m:
	Make it easier for vi to jump past the initial comments
	at the head of a module.
2006-04-19 05:18:00 +00:00
Julien Fischer
5e92224eec Improve the library reference manual by formatting the beginning of
Estimated hours taken: 0.2
Branches: main, release

library/*.m:
	Improve the library reference manual by formatting the beginning of
	library modules consistently.

library/integer.m:
	Fix some bad indentation.
2006-04-13 06:08:05 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Julien Fischer
a4519ed079 Move the all-solutions predicates from the library module std_util into their
Estimated hours taken: 4
Branches: main

Move the all-solutions predicates from the library module std_util into their
own module, solutions.

Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from
std_util.m into builtin.m.

Add some more utility functions for performing determinism or purity casts.
(The later are primarily intended for use by solver implementors.)

library/std_util.m:
	Move the all-solutions predicates into their own module, solutions.m.
	For now there are (obsolete) forwarding predicates from this module to
	the new one.  The forwarding predicates will be included in the
	upcoming 0.13 release and then removed in later versions.

	Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast
	to builtin.m

library/solutions.m:
	New file.  This is the new home for the all-solutions predicates.
	This is pretty much cut and pasted from std_util (with module
	qualifiers updated accordingly).  I've rearranged the code in a more
	top-down fashion as per our current coding standard.

library/builtin.m:
	Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and
	dynamic_cast/2 to this module.

	Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0
	and semidet_succeed/0.

	Add impure_true/0 and semipure_true/0.  These are useful for performing
	purity casts, e.g. in solver implementations.

library/library.m:
	Add the new module.

NEWS:
	Announce the changes.

library/*.m:
	Update to conform to the above.

compiler/const_prop.m:
	Update evaluate_semidet_call/5 with the new module name for
	dynamic_cast.

compiler/*.m:
	Module qualify calls to solutions to either disambiguate them from the
	versions in std_util (where they weren't module qualified) or change
	the module qualifier where they were (to avoid warnings about calls to
	the now deprecated versions).

tests/debugger/declarative/solutions.*:
	Rename this module as the name conflicts with the new library module.

tests/debugger/declarative/solns.*:
	Renamed version of above (with updated expected output).

tests/debugger/declarative/Mmakefile:
	Handle the renamed version of the solutions test.

tests/debugger/all_solutions.m:
tests/debugger/declarative/args.m:
tests/debugger/declarative/library_forwarding.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/multisoln_func.m:
tests/invalid/one_member.m:
tests/invalid/promise_equivalent_claueses.m:
tests/valid/simplify_bug2.m:
tests/valid/solv.m:
	Update to conform to the above changes.

sample/solutions/*.m:
	Update to conform to the above changes.
2006-03-24 04:40:59 +00:00
Zoltan Somogyi
ef55b420fd Remove from std_util.m the predicates that merely call predicates in
Estimated hours taken: 12
Branches: main

Remove from std_util.m the predicates that merely call predicates in
the type_desc, construct and deconstruct modules, to reduce clutter
in std_util.m.

library/std_util.m:
	Remove those predicates from std_util.m.

library/deconstruct.m:
	Add a type we need that was previously defined in std_util.m.

library/construct.m:
	Delete some module qualifications that have now become unnecessary,

browser/browse.m:
browser/browser_info.m:
browser/declarative_tree.m:
browser/dl.m:
browser/help.m:
browser/sized_pretty.m:
browser/term_rep.m:
compiler/bytecode_gen.m:
compiler/llds_out.m:
compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
library/assoc_list.m:
library/hash_table.m:
library/io.m:
library/pprint.m:
library/private_builtin.m:
library/prolog.m:
library/require.m:
library/rtti_implementation.m:
library/store.m:
library/term.m:
library/term_to_xml.m:
library/version_hash_table.m:
mdbcomp/program_representation.m:
	Import type_desc.m, construct.m and/or deconstruct.m to provide
	definitions of functions or predicates that up till now were in
	std_util.m. Modify the calls if the called function or predicate
	had a slightly different interface in std_util.m.

	Also, convert term_to_xml.m to four-space indentation, and delete
	unnecessary module qualifications in term.m.

tests/debugger/polymorphic_output.{m,inp,exp,exp2}:
tests/hard_coded/copy_pred_2.m:
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
tests/hard_coded/elim_special_pred.m:
tests/hard_coded/existential_bound_tvar.m:
tests/hard_coded/expand.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/higher_order_type_manip.m:
tests/hard_coded/nullary_ho_func.m:
tests/hard_coded/tuple_test.m:
tests/hard_coded/type_ctor_desc.m:
tests/hard_coded/type_qual.m:
tests/hard_coded/write_xml.m:
tests/hard_coded/sub-modules/class.m:
tests/hard_coded/sub-modules/nested.m:
tests/hard_coded/sub-modules/nested2.m:
tests/hard_coded/sub-modules/nested3.m:
tests/hard_coded/sub-modules/parent.m:
tests/hard_coded/sub-modules/parent2.child.m:
tests/hard_coded/typeclasses/existential_rtti.m:
tests/recompilation/type_qual_re.m.1:
cvs update: Updating tests/submodules
cvs update: Updating tests/tabling
cvs update: Updating tests/term
cvs update: Updating tests/tools
cvs update: Updating tests/trailing
cvs update: Updating tests/typeclasses
cvs update: Updating tests/valid
tests/valid/agc_unbound_typevars.m:
tests/valid/agc_unbound_typevars2.m:
tests/valid/agc_unused_in.m:
	Replace references to the deleted predicates in std_util with
	references to the equivalent predicates in type_desc, construct
	and/or deconstruct. In test cases that already tested both the
	functionality in std_util and in the other modules, simply delete
	the part exercising std_util.
2006-03-22 02:56:44 +00:00
Julien Fischer
c6d91ff386 Add some preliminary support for using the il grade with DotGNU.
Estimated hours taken: 1
Branches: main

aclocal.m4:
scripts/Mmake.vars.in:
	Add some preliminary support for using the il grade with DotGNU.

library/rtti_implementation.m:
	Avoid a warning.
2006-02-01 12:10:17 +00:00
Zoltan Somogyi
b819fbc0a6 Give the compiler the capability of detecting errors that manifest themselves
Estimated hours taken: 16
Branches: main

Give the compiler the capability of detecting errors that manifest themselves
as mismatches between the format string and the list of values to be printed
in calls to string.format and io.format.

This capability is controlled through two new options:

	--warn-known-bad-format-calls
	--warn-unknown-format-calls

The first (which will default to "on" once this change has bootstrapped)
controls whether the compiler emits warnings for statically known mismatches.
The second (which will default to "off") controls whether the compiler emits
warnings in cases where either the format string or the structure of the list
of values to be printed is not available statically to be checked.

NEWS:
	Mention the new capability.

compiler/options.m:
	Add the two new options.

doc/user_guide.texi:
	Document the new options.

compiler/format_call.m:
	New module to implement the new capability.

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

compiler/check_hlds.m:
	Include the new module.

compiler/simplify.m:
	Invoke the new module if the procedure being processed contains calls
	to string.format or io.format.

	Fix an old bug: we could generate warnings or even errors when
	simplifying predicate bodies imported from other modules via
	intermodule optimization.

	Don't export get/set predicates that do not need to be exported.

compiler/det_report.m:
	Add new kinds of error specifications for the errors detected by the
	new module.

	Separate out the context of each error specification, in order
	to allow the error messages to be sorted by context; this makes
	the output much easier to read.

compiler/common.m:
compiler/det_analysis.m:
compiler/simplify.m:
	Conform to the change to det_report.m.

mdbcomp/prim_data.m:
	Add a utility function for forming the possibly qualified names of
	library modules (such as "io" and "string").

library/Mercury.options:
compiler/Mercury.options:
	Add the lines that disable the new checks in the modules that need them
	disabled. The new lines are commented out until installed compilers all
	understand them, at which point in time we will add the requirement to
	understand the option to configure.in.

compiler/fact_table.m:
compiler/mlds_to_il.m:
	Fix three bugs reported by the new check that have apparently escaped
	detection all this time.

library/rtti_implementation.m:
	Change some code to avoid a spurious warning from the new checks.

library/string.m:
	Rename a predicate to avoid an unnecessary and confusing overloading of
	its name.

	Replace __ with . as module qualifier connective.

compiler/handle_options.m:
library/pprint.m:
	Misc cleanups.

tests/invalid/string_format_bad.{m,err_exp}:
tests/invalid/string_format_unknown.{m,err_exp}:
	New test cases to test the new warnings.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
	Enable the new test cases.

tests/general/string_format_test*.exp*:
	Update any expected abort messages to expect . instead of __ as module
	qualifier connective.

tests/invalid/det_errors_cc.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/warnings/simple_code.exp:
	Expect the same error messages in program context order.
2006-01-27 05:52:27 +00:00
Zoltan Somogyi
b9ca44672b Fix the bugs were exposed by my pre-dummy-type-diff cleanup of polymorphism.m.
Estimated hours taken: 24
Branches: main

Fix the bugs were exposed by my pre-dummy-type-diff cleanup of polymorphism.m.
This diff deleted a "semidet_fail" in the predicate that tested whether a
foreign_proc used a variable, making the test a real test, not a dummy.

The main bugs were in unused_args.m, polymorphism.m and ml_unify_gen.m.

compiler/unused_args.m:
	Fix the mismatch between the analysis and fixup passes' treatment of
	foreign_procs. The analysis pass says that variables representing
	unnamed foreign_proc arguments are unused, and therefore the code
	generating them can be optimized away, but the fixup pass used to leave
	those arguments unchanged. This is usually fine, but there was a
	problem if a variable had two or more such conjoined consumers but no
	other consumers. It then had its generator optimized away, but the
	variable was left in the nonlocal set of each consumer, which meant
	that the code generator aborted when trying to save the value of the
	variable after the first consumer.

	The fix is to rename unnamed foreign proc args, ensuring that they are
	local to the foreign_proc they appear in. The code generators can
	already handle such arguments.

compiler/typecheck.m:
	Detect foreign_procs that are supposed to bind type_info variables,
	but don't, and generate error messages for them. This is now necessary,
	since if we accept such predicates, unused_args.m will now rename apart
	the unused type_info argument, and the code generator will abort
	due to the type_info missing its generator.

compiler/typecheck_errors.m:
	Add a predicate for reporting the error.

compiler/goal_util.m:
	Add a utility predicate and export some previously internal predicates
	for use by unused_args.m.

	Delete redundant module prefixes on predicate names to avoid having to
	split long lines.

compiler/polymorphism.m:
	Ensure that all arguments of import foreign_procs are considered used,
	since our contract with foreign language code prevents us from
	optimizing them away.

	Redefine a predicate using the new utility predicate in goal_util.m.

compiler/pragma_c_gen.m:
	Ensure that all arguments of import foreign_procs are considered used,
	since our contract with foreign language code prevents us from
	optimizing them away. This is a belt-and-suspenders fix: the change to
	polymorphism.m should be sufficient to ensure this objective by itself.

compiler/ml_unify_gen.m:
	The mark_static_terms pass was assuming that if X is a static term,
	then after the assignment unification Y = X Y is also a static term.
	However, when processing such assignments, the code generator here
	neglected to copy over the part of the X's state that says what static
	term it is to become part of Y's state. This diff fixes that neglect.

compiler/ml_code_util.m:
	We used to identify MLDS variables holding static terms by a sequence
	number, and then create a name from the number by tacking on the name
	of the HLDS variable referring to it at each reference. This worked
	because each static term was referred to by only one HLDS variable;
	but after the diff to ml_unify_gen, this is no longer the case.
	We therefore now construct the MLDS variable's name when the static
	term is created, and use that name as the translation of all the HLDS
	variables referring to that static term.

compiler/add_pragma.m:
	Minor cleanup.

library/rtti_implementation.m:
library/store.m:
	In some predicates that don't define type_infos for existentially typed
	arguments, mention the type_info that *should* be defined there in
	comments to avoid the error now generated by typecheck.m.

browser/Mercury.options:
deep_profiler/Mercury.options:
	Undo the workaround for the fixed bug.

tests/existential_type_classes.m:
	In predicates that don't define type_infos for existentially typed
	arguments, mention the type_info that *should* be defined there in
	comments to avoid the error now generated by typecheck.m.

tests/existential_type_classes.exp:
	Conform to the changed line numbers in existential_type_classes.m.

tests/invalid/exist_foreign_error.{m,exp}:
	New test case for the error now detected by typecheck.m.

tests/invalid/Mmakefile:
	Enable the new test case.
2005-10-14 01:42:56 +00:00