[m-rev.] diff: Java RTTI fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 19 20:35:26 AEDT 2004


Estimated hours taken: 4
Branches: main

Bug fixes and code simplifications in the RTTI handling
for the Java back-end.

compiler/rtti.m:
	For Java, map all the different C representations for TypeInfos
	to a single Java type "java.runtime.TypeInfo_Struct".
	Likewise map all the different C representations for type class
	constraints to a single Java type "java.runtime.TypeInfo_Struct".
	
java/runtime/FA_PseudoTypeInfo_Struct1.java:
java/runtime/FA_PseudoTypeInfo_Struct2.java:
java/runtime/FA_TypeInfo_Struct1.java:
java/runtime/FA_TypeInfo_Struct2.java:
java/runtime/VA_PseudoTypeInfo_Struct0.java:
java/runtime/VA_PseudoTypeInfo_Struct1.java:
java/runtime/VA_PseudoTypeInfo_Struct2.java:
java/runtime/VA_PseudoTypeInfo_Struct3.java:
java/runtime/VA_PseudoTypeInfo_Struct4.java:
java/runtime/VA_PseudoTypeInfo_Struct8.java:
java/runtime/TypeclassInfo.java:
	Deleted these stub files, since they should no longer be needed.

java/runtime/TypeInfo_Struct.java:
	Add two new constructors, corresponding to the constructors for
	the deleted FA_* and VA_*.java files.

java/runtime/PseudoTypeInfo.java:
	Add some comments.  Make the nullary constructor protected,
	to ensure that it is only used by derived classes, since it
	is only intended to be used for TypeInfo_Struct.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.40
diff -u -d -r1.40 rtti.m
--- compiler/rtti.m	9 Feb 2004 11:54:44 -0000	1.40
+++ compiler/rtti.m	19 Feb 2004 08:37:14 -0000
@@ -1700,6 +1700,28 @@
 	->
 		JavaTypeName = string__append("mercury.runtime.", GenTypeName1)
 	;
+		% In C, we do some nasty hacks to represent type class
+		% constraints of different arities as different structures
+		% ending with arrays of the appropriate length, but in
+		% Java we just use a single type for all of them
+		% (with an extra level of indirection for the array).
+		string__prefix(GenTypeName0, "TypeClassConstraint_")
+	->
+		JavaTypeName = "mercury.runtime.TypeClassConstraint"
+	;
+		% In C, we do some nasty hacks to represent type infos
+		% different arities as different structures
+		% ending with arrays of the appropriate length, but in
+		% Java we just use a single type for all of them
+		% (with an extra level of indirection for the array).
+		( string__prefix(GenTypeName0, "FA_PseudoTypeInfo_Struct")
+		; string__prefix(GenTypeName0, "FA_TypeInfo_Struct")
+		; string__prefix(GenTypeName0, "VA_PseudoTypeInfo_Struct")
+		; string__prefix(GenTypeName0, "VA_TypeInfo_Struct")
+		)
+	->
+		JavaTypeName = "mercury.runtime.TypeInfo_Struct"
+	;
 		JavaTypeName = string__append("mercury.runtime.", GenTypeName0)
 	).
 
Index: java/runtime/FA_PseudoTypeInfo_Struct1.java
===================================================================
RCS file: java/runtime/FA_PseudoTypeInfo_Struct1.java
diff -N java/runtime/FA_PseudoTypeInfo_Struct1.java
--- java/runtime/FA_PseudoTypeInfo_Struct1.java	8 Jul 2003 10:30:00 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class FA_PseudoTypeInfo_Struct1 extends PseudoTypeInfo {
-	public FA_PseudoTypeInfo_Struct1(TypeCtorInfo_Struct type_ctor_info,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/FA_PseudoTypeInfo_Struct2.java
===================================================================
RCS file: java/runtime/FA_PseudoTypeInfo_Struct2.java
diff -N java/runtime/FA_PseudoTypeInfo_Struct2.java
--- java/runtime/FA_PseudoTypeInfo_Struct2.java	8 Jul 2003 10:30:00 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class FA_PseudoTypeInfo_Struct2 extends PseudoTypeInfo {
-	public FA_PseudoTypeInfo_Struct2(TypeCtorInfo_Struct type_ctor_info,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/FA_TypeInfo_Struct1.java
===================================================================
RCS file: java/runtime/FA_TypeInfo_Struct1.java
diff -N java/runtime/FA_TypeInfo_Struct1.java
--- java/runtime/FA_TypeInfo_Struct1.java	2 Dec 2003 10:02:00 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,15 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class FA_TypeInfo_Struct1 extends TypeInfo_Struct {
-	public FA_TypeInfo_Struct1(TypeCtorInfo_Struct type_ctor_info,
-			Object[] args) {
-		// XXX stub only
-		super(type_ctor_info);
-	}
-}
Index: java/runtime/FA_TypeInfo_Struct2.java
===================================================================
RCS file: java/runtime/FA_TypeInfo_Struct2.java
diff -N java/runtime/FA_TypeInfo_Struct2.java
--- java/runtime/FA_TypeInfo_Struct2.java	8 Jul 2003 10:30:00 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class FA_TypeInfo_Struct2 extends PseudoTypeInfo {
-	public FA_TypeInfo_Struct2(TypeCtorInfo_Struct type_ctor_info,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/PseudoTypeInfo.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/PseudoTypeInfo.java,v
retrieving revision 1.2
diff -u -d -r1.2 PseudoTypeInfo.java
--- java/runtime/PseudoTypeInfo.java	1 Dec 2003 06:55:51 -0000	1.2
+++ java/runtime/PseudoTypeInfo.java	19 Feb 2004 09:33:14 -0000
@@ -6,11 +6,23 @@
 
 package mercury.runtime;
 
+// A PseudoTypeInfo represents a possibly non-ground type.
+// There are three possible cases:
+//
+//   - Unbound type variables are represented by directly constructing
+//     a PseudoTypeInfo with the variable number.
+//
+//   - Ground types with arity zero may be represented as TypeCtorInfo_Struct,
+//     which extends PseudoTypeInfo, and uses the protected constructor
+//     which sets variable_number to -1.  This is a slightly optimized
+//     version of the case below.
+//
+//   - Any other types are represented as TypeInfo_Struct,
+//     which extends PseudoTypeInfo, and uses the protected constructor
+//     which sets variable_number to -1.
+//
 public class PseudoTypeInfo {
-	// This class is intentionally empty. 
-	// XXX PsuedoTypeInfo's have not been implemented yet.
-	//     They should all extend this class.
 	public int variable_number;
-	public PseudoTypeInfo()      { variable_number = -1; }
-	public PseudoTypeInfo(int n) { variable_number = n; }
+	public    PseudoTypeInfo(int n) { variable_number = n; }
+	protected PseudoTypeInfo()      { variable_number = -1; }
 }
Index: java/runtime/TypeInfo_Struct.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/TypeInfo_Struct.java,v
retrieving revision 1.3
diff -u -d -r1.3 TypeInfo_Struct.java
--- java/runtime/TypeInfo_Struct.java	2 Dec 2003 10:02:00 -0000	1.3
+++ java/runtime/TypeInfo_Struct.java	19 Feb 2004 09:26:07 -0000
@@ -51,6 +51,19 @@
 		args = new PseudoTypeInfo[] { a1, a2 };
 	}
 
+	public TypeInfo_Struct(TypeCtorInfo_Struct tc,
+			// XXX "as" should have type PseudoTypeInfo[],
+			//     but mlds_to_java.m uses Object[]
+			//     because init_array/1 does not store the type.
+			Object[] as)
+	{
+		type_ctor = tc;
+		args = new PseudoTypeInfo[as.length];
+		for (int i = 0; i < as.length; i++) {
+			args[i] = (PseudoTypeInfo) as[i];
+		}
+	}
+
 	//
 	// constructors for variable-arity type_infos (tuple, pred, func)
 	//
@@ -62,20 +75,36 @@
 		args = new PseudoTypeInfo[] { };
 	}
 
-	public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity, PseudoTypeInfo a1)
+	public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity,
+			PseudoTypeInfo a1)
 	{
 		// assert arity == 1;
 		type_ctor = tc;
 		args = new PseudoTypeInfo[] { a1 };
 	}
 
-	public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity, PseudoTypeInfo a1,
-				PseudoTypeInfo a2)
+	public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity,
+			PseudoTypeInfo a1, PseudoTypeInfo a2)
 	{
 		// assert arity == 2;
 		type_ctor = tc;
 		args = new PseudoTypeInfo[] { a1, a2 };
 	}
+
+	public TypeInfo_Struct(TypeCtorInfo_Struct tc, int arity,
+			// XXX "as" should have type PseudoTypeInfo[],
+			//     but mlds_to_java.m uses Object[]
+			//     because init_array/1 does not store the type.
+			Object[] 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];
+		}
+	}
+
 
 	// XXX a temp hack just to get things to run
 	public TypeInfo_Struct(java.lang.Object obj)
Index: java/runtime/TypeclassInfo.java
===================================================================
RCS file: java/runtime/TypeclassInfo.java
diff -N java/runtime/TypeclassInfo.java
--- java/runtime/TypeclassInfo.java	1 Dec 2003 06:55:51 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,11 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class TypeclassInfo extends PseudoTypeInfo {
-	// stub only
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct0.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct0.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct0.java
--- java/runtime/VA_PseudoTypeInfo_Struct0.java	19 Jan 2004 05:11:03 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-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;
-
-public class VA_PseudoTypeInfo_Struct0 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct0(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct1.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct1.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct1.java
--- java/runtime/VA_PseudoTypeInfo_Struct1.java	1 Dec 2003 06:55:51 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class VA_PseudoTypeInfo_Struct1 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct1(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct2.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct2.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct2.java
--- java/runtime/VA_PseudoTypeInfo_Struct2.java	1 Dec 2003 06:55:51 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class VA_PseudoTypeInfo_Struct2 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct2(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct3.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct3.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct3.java
--- java/runtime/VA_PseudoTypeInfo_Struct3.java	1 Dec 2003 06:55:51 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class VA_PseudoTypeInfo_Struct3 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct3(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct4.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct4.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct4.java
--- java/runtime/VA_PseudoTypeInfo_Struct4.java	1 Dec 2003 06:55:51 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-2003 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;
-
-public class VA_PseudoTypeInfo_Struct4 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct4(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}
Index: java/runtime/VA_PseudoTypeInfo_Struct8.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct8.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct8.java
--- java/runtime/VA_PseudoTypeInfo_Struct8.java	14 Jan 2004 03:31:30 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-//
-// Copyright (C) 2001-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;
-
-public class VA_PseudoTypeInfo_Struct8 extends PseudoTypeInfo {
-	public VA_PseudoTypeInfo_Struct8(
-			TypeCtorInfo_Struct type_ctor_info,
-			int arity,
-			Object[] args) {
-		// XXX stub only
-	}
-}

-- 
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