mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 01:43:35 +00:00
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.
This commit is contained in:
13
java/runtime/MercuryType.java
Normal file
13
java/runtime/MercuryType.java
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Copyright (C) 2009 The University of Melbourne.
|
||||
// This file may only be copied under the terms of the GNU Library General
|
||||
// Public License - see the file COPYING.LIB in the Mercury distribution.
|
||||
//
|
||||
// This interface is implemented by wrapper classes which are automatically
|
||||
// generated by the Java back-end to implement method pointers in Java.
|
||||
//
|
||||
|
||||
package mercury.runtime;
|
||||
|
||||
public interface MercuryType {
|
||||
}
|
||||
Reference in New Issue
Block a user