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.
This commit is contained in:
Peter Wang
2009-04-30 00:43:35 +00:00
parent 7d7ca9866b
commit d1cffc4523
17 changed files with 747 additions and 416 deletions

View File

@@ -15,7 +15,11 @@ public class DuExistInfo {
public /* final */ mercury.runtime.TypeClassConstraint[]
exist_constraints;
public DuExistInfo(int typeinfos_plain, int typeinfos_in_tci, int tcis,
public DuExistInfo()
{
}
public void init(int typeinfos_plain, int typeinfos_in_tci, int tcis,
mercury.runtime.DuExistLocn[] typeinfo_locns,
mercury.runtime.TypeClassConstraint constraints[])
{

View File

@@ -11,6 +11,7 @@ package mercury.runtime;
public class DuExistLocn {
public int exist_arg_num;
public int exist_offset_in_tci;
public DuExistLocn(int arg_num, int offset_in_tci) {
exist_arg_num = arg_num;
exist_offset_in_tci = offset_in_tci;

View File

@@ -21,7 +21,11 @@ public class DuFunctorDesc {
public /*final*/ java.lang.String[] du_functor_arg_names;
public /*final*/ mercury.runtime.DuExistInfo du_functor_exist_info;
public DuFunctorDesc(java.lang.String functor_name, int orig_arity,
public DuFunctorDesc()
{
}
public void init(java.lang.String functor_name, int orig_arity,
int arg_type_contains_var, int sectag_locn, int primary,
int secondary, int ordinal,
// XXX why do we need to use Object here?

View File

@@ -11,7 +11,10 @@ public class EnumFunctorDesc {
public java.lang.String enum_functor_name;
public int enum_functor_ordinal;
public EnumFunctorDesc(String name, int ordinal) {
public EnumFunctorDesc() {
}
public void init(String name, int ordinal) {
enum_functor_name = name;
enum_functor_ordinal = ordinal;
}

View File

@@ -12,7 +12,10 @@ public class ForeignEnumFunctorDesc {
public int foreign_enum_functor_ordinal;
public int foreign_enum_functor_value;
public ForeignEnumFunctorDesc(String name, int ordinal, int value) {
public ForeignEnumFunctorDesc() {
}
public void init(String name, int ordinal, int value) {
foreign_enum_functor_name = name;
foreign_enum_functor_ordinal = ordinal;
foreign_enum_functor_value = value;

View File

@@ -10,6 +10,6 @@
package mercury.runtime;
public interface MethodPtr {
public abstract java.lang.Object call___0_0(java.lang.Object[] args);
public abstract java.lang.Object call___0_0(java.lang.Object... args);
}

View File

@@ -13,20 +13,11 @@ public class TypeClassConstraint {
public TypeClassDeclStruct tc_constr_type_class;
public PseudoTypeInfo tc_constr_arg_ptis[];
public TypeClassConstraint(TypeClassDeclStruct type_class)
public TypeClassConstraint()
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[] {};
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo[] ptis)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = ptis;
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
public void init(TypeClassDeclStruct type_class,
// XXX Object[] should be mercury.runtime.PseudoTypeInfo[],
// but mlds_to_java.m generates Object[] since
// init_array/1 doesn't give type info
@@ -38,47 +29,4 @@ public class TypeClassConstraint {
tc_constr_arg_ptis[i] = (PseudoTypeInfo) ptis[i];
}
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo pti1)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[] { pti1 };
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo pti1, PseudoTypeInfo pti2)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[] { pti1, pti2 };
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo pti1, PseudoTypeInfo pti2,
PseudoTypeInfo pti3)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[] { pti1, pti2, pti3 };
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo pti1, PseudoTypeInfo pti2,
PseudoTypeInfo pti3, PseudoTypeInfo pti4)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[]
{ pti1, pti2, pti3, pti4 };
}
public TypeClassConstraint(TypeClassDeclStruct type_class,
PseudoTypeInfo pti1, PseudoTypeInfo pti2,
PseudoTypeInfo pti3, PseudoTypeInfo pti4,
PseudoTypeInfo pti5)
{
tc_constr_type_class = type_class;
tc_constr_arg_ptis = new PseudoTypeInfo[] {
pti1, pti2, pti3, pti4, pti5 };
}
// XXX type classes with arity > 5 not supported
}

View File

@@ -16,7 +16,11 @@ public class TypeClassDeclStruct {
public int tc_decl_num_supers; // redundant
public TypeClassConstraint tc_decl_supers;
public TypeClassDeclStruct(TypeClassId id, int version_number,
public TypeClassDeclStruct()
{
}
public void init(TypeClassId id, int version_number,
int num_supers, TypeClassConstraint supers)
{
tc_decl_id = id;

View File

@@ -18,7 +18,11 @@ public class TypeClassId {
public String[] tc_id_var_names;
public TypeClassMethod[] tc_id_methods;
public TypeClassId(String module_name, String name, int arity,
public TypeClassId()
{
}
public void init(String module_name, String name, int arity,
int num_type_vars, int num_methods,
String[] var_names, TypeClassMethod[] methods)
{

View File

@@ -25,7 +25,11 @@ public class TypeCtorInfo_Struct extends PseudoTypeInfo {
public /* short */ int type_ctor_flags;
public int[] type_functor_number_map;
public TypeCtorInfo_Struct(
public TypeCtorInfo_Struct()
{
}
public void init(
int type_arity, int version, int num_ptags, int rep,
Object unify_proc, Object compare_proc,
String module, String name,

View File

@@ -11,18 +11,15 @@ public class TypeInfo_Struct extends PseudoTypeInfo {
public TypeCtorInfo_Struct type_ctor;
public PseudoTypeInfo args[];
public TypeInfo_Struct()
{
}
public TypeInfo_Struct(TypeCtorInfo_Struct tc)
{
type_ctor = tc;
}
// raw constructor
public TypeInfo_Struct(TypeCtorInfo_Struct tc, PseudoTypeInfo... as)
{
type_ctor = tc;
args = as;
}
// copy constructor
// XXX Rather than invoking this constructor, and allocating a new
// type_info object on the heap, we should generate code which
@@ -33,42 +30,44 @@ public class TypeInfo_Struct extends PseudoTypeInfo {
args = ti.args;
}
// XXX "as" should have type PseudoTypeInfo[],
// but mlds_to_java.m uses Object[]
// because init_array/1 does not store the type.
public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity, Object[] as)
public void init(TypeCtorInfo_Struct tc, PseudoTypeInfo[] as)
{
assert arity == as.length;
type_ctor = tc;
args = new PseudoTypeInfo[as.length];
for (int i = 0; i < as.length; i++) {
args[i] = (PseudoTypeInfo) as[i];
}
type_ctor = tc;
args = as;
}
// XXX "as" should have type PseudoTypeInfo[],
// but mlds_to_java.m uses Object[]
// because init_array/1 does not store the type.
public TypeInfo_Struct(TypeCtorInfo_Struct tc, Object[] as)
public void init(TypeCtorInfo_Struct tc, int arity, Object[] as)
{
type_ctor = tc;
args = new PseudoTypeInfo[as.length];
assert arity == as.length;
init(tc, as);
}
// XXX "as" should have type PseudoTypeInfo[],
// but mlds_to_java.m uses Object[]
// because init_array/1 does not store the type.
public void init(TypeCtorInfo_Struct tc, Object[] as)
{
PseudoTypeInfo[] ptis = new PseudoTypeInfo[as.length];
for (int i = 0; i < as.length; i++) {
args[i] = (PseudoTypeInfo) as[i];
ptis[i] = (PseudoTypeInfo) as[i];
}
init(tc, ptis);
}
// XXX untested guess
public TypeInfo_Struct(TypeInfo_Struct ti, int arity, Object... as)
{
this(ti.type_ctor, arity, as);
init(ti.type_ctor, arity, as);
}
// XXX untested guess
public TypeInfo_Struct(TypeInfo_Struct ti, Object... as)
{
this(ti.type_ctor, as);
init(ti.type_ctor, as);
}
// XXX a temp hack just to get things to run