Commit Graph

8 Commits

Author SHA1 Message Date
Peter Wang
6a345ff5dc Make subtypes share low-level data representation with base type.
Make subtypes share data representation with base type when using
low-level data. High-level data grades are unchanged, so subtypes
are still represented with distinct classes from their base types.

----------------

compiler/prog_data.m:
    Add abstract_subtype option for type_details_abstract.

    Correct XXX comment.

compiler/prog_item.m:
    Add type item_type_repn_info_subtype.

    Add tcrepn_is_subtype_of option for type_ctor_repn_info.

compiler/equiv_type.m:
    Replace equivalences in tcrepn_is_subtype_of.

compiler/module_qual.qualify_items.m:
    Module qualify in tcrepn_is_subtype_of.

compiler/prog_type.m:
    Rename some predicates that can only work on non-subtype du types.

    Update comments.

compiler/check_parse_tree_type_defns.m:
    Classify subtype type definitions as std_mer_type_du_subtype
    instead of std_mer_type_du_all_plain_constants or
    std_mer_type_du_not_all_plain_constants.

    Update some comments.

compiler/du_type_layout.m:
    Add two sub-passes to handle subtypes.

compiler/comp_unit_interface.m:
    Extend this module to handle subtype type definitions,
    analogous to the way equivalence type definitions are handled.

    Rename some predicates to clarify that they must not be used
    to test subtypes.

    Record an abstract version of a subtype type definition using
    the abstract_subtype option in type_details_abstract.
    This allows the super type ctor of the subtype to be known,
    and hence the base type ctor, when a subtype is abstract exported.

    Update comments.

compiler/decide_type_repn.m:
    Extend this module to handle subtype type definitions.

    Generate type_representation items for subtype type definitions
    which include the super type ctor of the subtype.

compiler/parse_tree_out.m:
    Write out abstract_subtype as
    "where type_is_abstract_subtype(Name/Arity)" on type definitions.

compiler/parse_type_defn.m:
    Parse "type_is_abstract_subtype(Name/Arity)" declarations.

compiler/parse_tree_out_type_repn.m:
    Write type_representation items with "is_subtype_of(TypeCtor/Arity)".

compiler/parse_type_repn.m:
    Parse "is_subtype_of(TypeCtor/Arity)" in type_representation items.

compiler/add_type.m:
compiler/convert_parse_tree.m:
compiler/opt_debug.m:
compiler/type_util.m:
    Conform to changes.

    Update comments.

compiler/direct_arg_in_out.m:
    Delete XXX, nothing to do.

compiler/parse_util.m:
    Rename overly specific variable.

----------------

runtime/mercury_type_info.h:
    Add a flag in MR_TypeCtorInfo to indicate if the enum/du layout
    array may be indexed by an enum value or du ptag value.
    Subtypes break the invariant that the layout array contains entries
    for every enum/ptag value from 0 up to the maximum value.
    The presence of the flag MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE tells
    the runtime that it can directly index the layout array instead of
    searching through it (which is the common case, for non-subtypes).

    Add a field MR_du_ptag to MR_DuPtagLayout. This is necessary to find
    an entry for a given primary tag value in a MR_DuPtagLayout array.

    Add a field MR_du_ptag_flags to MR_DuPtagLayout, currently with one
    possible flag MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE.
    As with primary tags, subtypes break the invariant that the
    sectag_alternatives array contains entries for every secondary tag
    value from 0 up to the maximum value. The presence of the flag tells
    the runtime that it can directly index the sectag_alternatives array
    (which is the common case, for non-subtypes).

    The two fields added to MR_DuPtagLayout occupy space that was
    previously padding, so the size of MR_DuPtagLayout is unchanged.

    In MR_EnumFunctorDesc, replace the MR_enum_functor_ordinal field by
    MR_enum_functor_value, i.e. the integer value representing the
    functor in memory. Storing *both* the functor ordinal and enum value
    would increase the size of the MR_EnumFunctorDesc struct, and would
    be redundant in the common case of non-subtype enums (both fields
    would contain equal values). We forgo having the functor ordinal
    directly available, at the cost of needing to search through an
    MR_EnumFunctorDesc array when a functor ordinal is required for a
    subtype enum, which should be rare.

compiler/rtti.m:
    Swap enum "functor ordinal" and "value" in places.

    Use a type 'enum_value' to try to ensure we do not mix up enum
    functor ordinals and enum values.

    Add code to encode the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag.

    Add code to encode the MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE
    flag.

compiler/rtti_out.m:
    Write out "enum_ordinal_ordered_tables" ordered by functor ordinals
    instead of "enum_value_ordered_tables" ordered by enum values.

    Output the enum value for MR_EnumFunctorDesc instead of functor
    ordinal.

    Output the MR_du_ptag and MR_du_ptag_flags fields for
    MR_DuPtagLayout.

    Relax sanity check on primary tags. A subtype may not necessarily
    use ptag 0, and may skip ptag values.

compiler/rtti_to_mlds.m:
    Generate "enum_ordinal_ordered_tables" instead of
    "enum_value_ordered_tables".

    Fill in the enum value for a MR_EnumFunctorDesc instead of
    the functor ordinal.

compiler/type_ctor_info.m:
    Add predicate to generate the MR_du_ptag_flags field.

    Add the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag to type_ctor_infos
    when appropriate.

    Bump the type_ctor_info_rtti_version.

----------------

runtime/mercury_ml_expand_body.h:
    Search through an enum layout array to find the matching enum value,
    unless the array can be indexed.

    Search through a ptag layout array to find the matching ptag value,
    unless the array can be indexed.

    Search through a sectag_alternatives array to find the matching
    secondary tag value, unless the array can be indexed.

    Factor out the code to search through a foreign enum layout array
    into a separate macro.

runtime/mercury_construct.c:
runtime/mercury_construct.h:
    Add a functor_ordinal field to the MR_Construct_Info_Struct.
    This will hold the functor ordinal now that it is not available in
    MR_EnumFunctorDesc.

    Make MR_get_functors_check_range take an argument to indicate if the
    functor_ordinal field needs to be filled in properly. Most callers
    do not need the field.

library/construct.m:
    Conform to changes to MR_get_functors_check_range and
    MR_EnumFunctorDesc.

-------------------

runtime/mercury_dotnet.cs.in:
    Modify RTTI classes for C# backend, analogous to the changes for the
    C runtime.

    Add methods to index/search through enum layout arrays, ptag layout
    arrays, and sectag_alternatives arrays.

java/runtime/DuPtagLayout.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/TypeCtorInfo_Struct.java:
    Modify RTTI classes for Java backend, analogous to the changes for the
    C runtime.

    Add methods to index/search through enum layout arrays, ptag layout
    arrays, and sectag_alternatives arrays.

library/rtti_implementation.m:
    Conform to MR_EnumFunctorDesc field change.

    Index or search through the enum layout array or ptag layout array
    based on the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag.

    Index or search through the sectag_alternatives array depending on
    the MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE flag.

    Add separator lines.

    Slightly reorder some code.

----------------

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/subtype_pack.m:
tests/hard_coded/subtype_pack_2.m:
tests/hard_coded/subtype_pack.exp:
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/subtype_rtti.exp:
tests/hard_coded/subtype_rtti.exp2:
    Add test cases.
2021-04-09 17:36:38 +10:00
Zoltan Somogyi
8e45a89895 Use spaces, not tabs, in the Java and C# runtimes.
Add modelines to keep it that way.

Fix formatting, and english in comments.
2018-07-10 13:52:11 +02:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Peter Wang
b573e83761 Mark Java RTTI classes as implementing java.io.Serializable to
Branches: main

Mark Java RTTI classes as implementing java.io.Serializable to
enable serialization of existentially typed values.

java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/DuPtagLayout.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/MethodPtr.java:
java/runtime/NotagFunctorDesc.java:
java/runtime/PseudoTypeInfo.java:
java/runtime/ReservedAddrFunctorDesc.java:
java/runtime/Sectag_Locn.java:
java/runtime/TypeClassConstraint.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassId.java:
java/runtime/TypeClassMethod.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeCtorRep.java:
java/runtime/TypeFunctors.java:
java/runtime/TypeInfo_Struct.java:
java/runtime/TypeLayout.java:
        As above.

        TypeCtorInfo_Struct.unify() cannot rely on the uniqueness of
        TypeCtorInfo_Struct instances, as deserialisation will create new
        copies.
2009-09-07 03:10:02 +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
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
Fergus Henderson
31a4f2d85e Some fixes to the Java back-end to make it support RTTI
Estimated hours taken: 18
Branches: main

Some fixes to the Java back-end to make it support RTTI
better.  The aim is to at least be able to *compile* code
that makes use of polymorphism (e.g. the Mercury standard
library!), although that aim is not yet achieved with this diff.
Getting code which actually *uses* the RTTI to work is still
a long way off...

compiler/rtti.m:
compiler/mlds_to_java.m:
	Fix some bugs in the code to output RTTI type names.

compiler/mlds_to_java.m:
	Output the RTTI definitions.  This is needed to avoid errors
	in code which references them.

	Handle initializers better; in particular deal with nested
	initializers properly.

	Pass the current module name down to output_lval, so that we can
	module-qualify data names only if they occur in a different
	module.  This is needed to ensure that static data defined
	in other modules gets module-qualified, but local variables don't.
	This also required change some places which were incorrectly
	calling output_fully_qualified_name to instead call output_name.

	Add comments in the generated output code when generating
	"java.lang.Object", so that it is clearer what kind of object
	is involved.

	Add some special treatment for the types with hand-defined RTTI.

java/runtime/*.java:
	Add some definitions of RTTI types, and some new constructors
	for the RTTI types that were already defined.
	These are currently all just stubs.
2003-07-08 10:30:00 +00:00
Michael Wybrow
1203d79326 This change introduces some (partial) Java versions of the mercury library
Estimated hours taken: 3
Branches: main


This change introduces some (partial) Java versions of the mercury library
which are currently needed to compile some .java files generated by the
mercury compiler for the tests/benchmarks test cases.
These additions are required temporarily for testing purposes until the
mercury library can be compiled in grade java.


mercury/java/Commit.java:
mercury/java/DuExistInfo.java:
mercury/java/DuExistLocn.java:
mercury/java/DuFunctorDesc.java:
mercury/java/DuPtagLayout.java:
mercury/java/EnumFunctorDesc.java:
mercury/java/JavaInternal.java:
mercury/java/MethodPtr.java:
mercury/java/NotagFunctorDesc.java:
mercury/java/PseudoTypeInfo.java:
mercury/java/Sectag_Locn.java:
mercury/java/TypeCtorInfo_Struct.java:
mercury/java/TypeCtorRep.java:
mercury/java/TypeFunctors.java:
mercury/java/TypeLayout.java:
mercury/java/UnreachableDefault.java:
	All files that were located in the mercury/java directory have been
	moved to mercury/java/runtime.

mercury/java/Makefile:
	A simple Makefile to set up a couple of symbolic links so we can
	just include the mercury/java directory in our CLASSPATH.

mercury/java/library/assoc_list.java:
mercury/java/library/bool.java:
mercury/java/library/builtin.java:
mercury/java/library/deconstruct.java:
mercury/java/library/enum.java:
mercury/java/library/integer.java:
mercury/java/library/io.java:
mercury/java/library/list.java:
mercury/java/library/map.java:
mercury/java/library/mer_int.java:
mercury/java/library/mr_char.java:
mercury/java/library/mr_float.java:
mercury/java/library/mr_int.java:
mercury/java/library/ops.java:
mercury/java/library/private_builtin.java:
mercury/java/library/require.java:
mercury/java/library/set.java:
mercury/java/library/std_util.java:
mercury/java/library/string.java:
mercury/java/library/term.java:
mercury/java/library/time.java:
mercury/java/library/tree234.java:
mercury/java/library/type_desc.java:
	These are partial Java versions of mercury library modules. They are
	very rough but will currently allow for most of the tests/benchmark
	directory to run in Java.
2002-02-11 06:31:33 +00:00