[m-rev.] diff: Java back-end typeclass RTTI fixes
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Feb 9 22:53:58 AEDT 2004
Estimated hours taken: 3
Branches: main
Some fixes to the Java back-end, to make it work again after
Zoltan's recent type class RTTI changes.
java/runtime/DuExistInfo.java:
Add a new field "exist_constraints" to the DuExistInfo type
and a corresponding argument to the constructor, to match
Zoltan's recent changes.
java/runtime/TypeClassId.java:
java/runtime/TypeClassMethod.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassConstraint.java:
New files. These correspond to the C types MR_TypeClassId,
MR_TypeClassMethod, MR_TypeClassDeclStruct,
and MR_TypeClassConstraint in the C runtime.
java/runtime/TypeCtorInfo_Struct.java:
Add a comment.
compiler/rtti_to_mlds.m:
Don't cast null pointers to mlds__generic_type; they should have
the right type already. Casting to mlds__generic_type here causes
type errors for the Java back-end, because in Java there are no
implicit conversions from Object (unlike C, which allows implicit
conversions from `void *').
compiler/rtti.m:
Change tc_rtti_name_java_type so that it maps the new typeclass-related
RTTI types to the appropriate Java types.
library/private_builtin.m:
Define MR_PREDICATE and MR_FUNCTION.
java/runtime/PredFunc.java:
Fix a bug in my previous change:
s/MR_PRED/MR_PREDICATE/
s/MR_FUNC/MR_FUNCTION/
Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.39
diff -u -d -r1.39 rtti.m
--- compiler/rtti.m 3 Feb 2004 05:40:01 -0000 1.39
+++ compiler/rtti.m 9 Feb 2004 11:18:31 -0000
@@ -1703,11 +1703,27 @@
JavaTypeName = string__append("mercury.runtime.", GenTypeName0)
).
-tc_rtti_name_java_type(_TCRttiName, JavaTypeName, IsArray) :-
- JavaTypeName = "java.lang.Object",
- IsArray = yes.
- % tc_rtti_name_type(TCRttiName, _GenTypeName, IsArray),
- % JavaTypeName = string__append("mercury.runtime.", GenTypeName).
+tc_rtti_name_java_type(TCRttiName, JavaTypeName, IsArray) :-
+ tc_rtti_name_type(TCRttiName, GenTypeName, IsArray),
+ (
+ % BaseTypeClassInfo in C is represented using a
+ % variable-length array as the last field,
+ % so we need to handle it specially in Java
+ GenTypeName = "BaseTypeclassInfo"
+ ->
+ JavaTypeName = "java.lang.Object" /* & IsArray = yes */
+ ;
+ % Java doesn't have typedefs (or "const"),
+ % so we need to use "String" rather than "ConstString"
+ GenTypeName = "ConstString"
+ ->
+ JavaTypeName = "java.lang.String"
+ ;
+ % The rest are all defined in Mercury's Java runtime
+ % (java/runtime/*.java).
+ JavaTypeName = string__append("mercury.runtime.",
+ GenTypeName)
+ ).
% ctor_rtti_name_type(RttiName, Type, IsArray):
:- pred ctor_rtti_name_type(ctor_rtti_name::in, string::out, bool::out) is det.
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.46
diff -u -d -r1.46 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m 3 Feb 2004 05:40:01 -0000 1.46
+++ compiler/rtti_to_mlds.m 9 Feb 2004 09:35:19 -0000
@@ -1507,8 +1507,7 @@
:- func gen_init_null_pointer(mlds__type) = mlds__initializer.
-gen_init_null_pointer(Type) =
- init_obj(mlds__unop(cast(mlds__generic_type), const(null(Type)))).
+gen_init_null_pointer(Type) = init_obj(const(null(Type))).
:- func gen_init_string(string) = mlds__initializer.
Index: java/runtime/DuExistInfo.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/DuExistInfo.java,v
retrieving revision 1.2
diff -u -d -r1.2 DuExistInfo.java
--- java/runtime/DuExistInfo.java 1 Dec 2003 13:17:06 -0000 1.2
+++ java/runtime/DuExistInfo.java 9 Feb 2004 09:27:17 -0000
@@ -12,13 +12,17 @@
public int exist_typeinfos_in_tci;
public int exist_tcis;
public /* final */ mercury.runtime.DuExistLocn[] exist_typeinfo_locns;
+ public /* final */ mercury.runtime.TypeClassConstraint[]
+ exist_constraints;
public DuExistInfo(int typeinfos_plain, int typeinfos_in_tci, int tcis,
- mercury.runtime.DuExistLocn[] typeinfo_locns)
+ mercury.runtime.DuExistLocn[] typeinfo_locns,
+ mercury.runtime.TypeClassConstraint constraints[])
{
exist_typeinfos_plain = typeinfos_plain;
exist_typeinfos_in_tci = typeinfos_in_tci;
exist_tcis = tcis;
exist_typeinfo_locns = typeinfo_locns;
+ exist_constraints = constraints;
}
}
Index: java/runtime/PredFunc.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/PredFunc.java,v
retrieving revision 1.1
diff -u -d -r1.1 PredFunc.java
--- java/runtime/PredFunc.java 9 Feb 2004 09:17:27 -0000 1.1
+++ java/runtime/PredFunc.java 9 Feb 2004 09:29:10 -0000
@@ -8,8 +8,8 @@
public class PredFunc {
- public static final int MR_PRED = 0;
- public static final int MR_FUNC = 1;
+ public static final int MR_PREDICATE = 0;
+ public static final int MR_FUNCTION = 1;
public int value;
Index: java/runtime/TypeClassConstraint.java
===================================================================
RCS file: java/runtime/TypeClassConstraint.java
diff -N java/runtime/TypeClassConstraint.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/runtime/TypeClassConstraint.java 9 Feb 2004 11:41:41 -0000
@@ -0,0 +1,64 @@
+//
+// Copyright (C) 2004 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.
+//
+
+package mercury.runtime;
+
+// This corresponds to the C type MR_TypeClassConstraint
+// in runtime/mercury_type_info.h.
+
+public class TypeClassConstraint {
+ public TypeClassDeclStruct tc_constr_type_class;
+ public PseudoTypeInfo tc_constr_arg_ptis[];
+
+ public TypeClassConstraint(TypeClassDeclStruct type_class)
+ {
+ tc_constr_type_class = type_class;
+ tc_constr_arg_ptis = new PseudoTypeInfo[] {};
+ }
+
+ 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
+}
Index: java/runtime/TypeClassDeclStruct.java
===================================================================
RCS file: java/runtime/TypeClassDeclStruct.java
diff -N java/runtime/TypeClassDeclStruct.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/runtime/TypeClassDeclStruct.java 9 Feb 2004 11:43:43 -0000
@@ -0,0 +1,27 @@
+//
+// Copyright (C) 2004 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.
+//
+
+package mercury.runtime;
+
+// This corresponds to the C typedef "MR_TypeClassDeclStruct"
+// in runtime/mercury_types.h, i.e. the C struct
+// "struct MR_TypeClassDecl_Struct" in runtime/mercury_typeclass_info.h.
+
+public class TypeClassDeclStruct {
+ public TypeClassId tc_decl_id;
+ public int tc_decl_version_number;
+ public int tc_decl_num_supers; // redundant
+ public TypeClassConstraint tc_decl_supers;
+
+ public TypeClassDeclStruct(TypeClassId id, int version_number,
+ int num_supers, TypeClassConstraint supers)
+ {
+ tc_decl_id = id;
+ tc_decl_version_number = version_number;
+ tc_decl_num_supers = num_supers;
+ tc_decl_supers = supers;
+ }
+}
Index: java/runtime/TypeClassId.java
===================================================================
RCS file: java/runtime/TypeClassId.java
diff -N java/runtime/TypeClassId.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/runtime/TypeClassId.java 9 Feb 2004 11:44:31 -0000
@@ -0,0 +1,33 @@
+//
+// Copyright (C) 2004 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.
+//
+
+package mercury.runtime;
+
+// This corresponds to the C type MR_TypeClassId
+// in runtime/mercury_typeclass_info.h.
+
+public class TypeClassId {
+ public String tc_id_module_name;
+ public String tc_id_name;
+ public int tc_id_arity;
+ public int tc_id_num_type_vars; // XXX redundant
+ public int tc_id_num_methods; // XXX redundant
+ public String[] tc_id_var_names;
+ public TypeClassMethod[] tc_id_methods;
+
+ public TypeClassId(String module_name, String name, int arity,
+ int num_type_vars, int num_methods,
+ String[] var_names, TypeClassMethod[] methods)
+ {
+ tc_id_module_name = module_name;
+ tc_id_name = name;
+ tc_id_arity = arity;
+ tc_id_num_type_vars = num_type_vars;
+ tc_id_num_methods = num_methods;
+ tc_id_var_names = var_names;
+ tc_id_methods = methods;
+ }
+}
Index: java/runtime/TypeClassMethod.java
===================================================================
RCS file: java/runtime/TypeClassMethod.java
diff -N java/runtime/TypeClassMethod.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/runtime/TypeClassMethod.java 9 Feb 2004 11:45:02 -0000
@@ -0,0 +1,24 @@
+//
+// Copyright (C) 2004 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.
+//
+
+package mercury.runtime;
+
+// This corresponds to the C type MR_TypeClassMethod
+// in runtime/mercury_typeclass_info.h.
+
+public class TypeClassMethod {
+ public /* final */ java.lang.String tc_method_name;
+ public /* final */ int tc_method_arity;
+ public /* final */ int /* PredFunc */ tc_method_pred_func;
+
+ public TypeClassMethod(java.lang.String name, int arity,
+ int pred_func)
+ {
+ tc_method_name = name;
+ tc_method_arity = arity;
+ tc_method_pred_func = pred_func;
+ }
+}
Index: java/runtime/TypeCtorInfo_Struct.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/TypeCtorInfo_Struct.java,v
retrieving revision 1.5
diff -u -d -r1.5 TypeCtorInfo_Struct.java
--- java/runtime/TypeCtorInfo_Struct.java 2 Dec 2003 10:02:00 -0000 1.5
+++ java/runtime/TypeCtorInfo_Struct.java 9 Feb 2004 11:46:00 -0000
@@ -6,6 +6,9 @@
package mercury.runtime;
+// This corresponds to the C type "struct MR_TypeCtorInfo_Struct"
+// in runtime/mercury_type_info.h.
+
public class TypeCtorInfo_Struct extends PseudoTypeInfo {
public int arity;
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.134
diff -u -d -r1.134 private_builtin.m
--- library/private_builtin.m 21 Jan 2004 04:56:57 -0000 1.134
+++ library/private_builtin.m 9 Feb 2004 10:03:13 -0000
@@ -1288,6 +1288,9 @@
public static final int MR_SECTAG_REMOTE = 2;
public static final int MR_SECTAG_VARIABLE = 3;
+ public static final int MR_PREDICATE = 0;
+ public static final int MR_FUNCTION = 1;
+
// The dummy_var is used to represent io__states and other Mercury
// parameters that are not really passed around. Occasionally a dummy
// variable will be used by the code generator as an lval, so we use
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list