[m-rev.] for review: java enumerations

Julien Fischer juliensf at csse.unimelb.edu.au
Tue May 26 20:11:42 AEST 2009

Hi Peter,

On Tue, 26 May 2009, Peter Wang wrote:

> Branches: main
> For Java backend, use static instances to represent enumeration constants
> instead of dynamically allocating them.  This is similar to using native Java
> enums but leaves the possibility of manually assigning ordinal values, which
> might be needed to make `:- pragma foreign_enum' do something sensible.

In principle, there's no reason that `:- pragma foreign_enum' couldn't
use Java enums in the java grade.  I certainly intended it to work with
target languages that support stongly typed enumerations, i.e. not C
style ones.

> Support `:- pragma foreign_export_enum' for Java.
> compiler/add_pragma.m:
>        Don't abort on seeing `:- pragma foreign_export_enum' for Java.
> compiler/export.m:
>        Only output exported enums if `:- pragma foreign_export_enum' was
>        declared for C.  Previously it ignored the language.
> compiler/mlds.m:
>        Remember in `mlds_exported_enum' the type constructor of the exported
>        enumeration.  This is needed for mlds_to_java.m.
>        Delete the `mlds_type' in `mlds_exported_enum' as it was useless.
>        For each exported constant, keep a `mlds_initializer' of its integer
>        value, instead of a `mlds_entity_defn'.
> compiler/ml_type_gen.m:
> compiler/mlds_to_c.m:
>        Conform to previous changes.
> compiler/mlds_to_java.m:
>        Output static instances of enumeration constants.  These are named
>        `K<n>' where <n> is the integer value of the constant.
>        Use the `K<n>' instances instead of dynamically allocating objects
>        for enumeration classes.
>        Don't output int fields which hold the integer value for each
>        enumeration constructor as they are now useless.
>        Output foreign exported enumerations.  These are static class members
>        (at the module level) which point to the `K<n>' instances, giving
>        them predictable names for foreign code.
> library/io.m:
>        Fix Java implementation of `io.file_type_2' which previously relied
>        on the representation of enums.

The diff looks fine.

mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au

More information about the reviews mailing list