Files
mercury/java/runtime
Peter Wang e0a564f0f4 Fix two problems implementation of arrays for Java backend:
Branches: main

Fix two problems implementation of arrays for Java backend:

- array.from_list([1, 2, 3]) didn't work because it would create an Integer[]
  array, but the code generated by the Mercury compiler would try to assign
  it to a int[] variable.  Fix this by special casing the primitive types to
  create arrays with the expected types.

- We used the class of a representative element to determine the type of
  an array to create.  Enumeration types only have the one class
  corresponding to the Mercury type, so the class of the representative
  element is correct.

  However, general d.u. types have subclasses for each functor, so the class
  of a representative element could correspond to a functor.  This meant that
  arrays could only hold more elements with the same functor.  What is needed
  is actually the super class, corresponding to a Mercury type.

  The solution adopted here is to make Java classes corresponding to Mercury
  types implement an interface called `MercuryType'.  Then we can tell
  whether the class or the superclass of the representative element is the
  one needed.


java/runtime/MercuryType.java:
        Add the new interface.

compiler/ml_type_gen.m:
        When the target language is Java, make d.u. parent types implement
        the `MercuryType' interface.

compiler/mlds_to_java.m:
        Make the `MercuryType' interface special so it is printed without an
        arity suffix.

library/array.m:
        Fix the problems with creating/resizing ararys.
2009-06-05 04:17:10 +00:00
..