[m-rev.] diff: define type_ctor_Rep constants in the Java runtime

Julien Fischer jfischer at opturion.com
Mon Nov 20 10:43:55 AEDT 2017


Define type_ctor_rep constants in the Java runtime.

In the Java grade, the type_ctor_rep constants are currently defined in the
private_builtin module of the standard library.  The Java version of the
runtime currently duplicates some of these constants for its own use (since it
cannot refer to the library ones).  This means changes to the set of
type_ctor_reps need to potentially occur in two places, which is a maintenance
headache.

This changes shifts the definitions of all the type_ctor_rep constants in the
Java grade into the runtime and updates the compiler to generate code that
uses these new definitions.

library/private_builtin.m:
      Add a note mentioning that the type_ctor_rep constants defined here
      will eventually be removed.

java/runtime/TypeCtorRep.java:
      Define constants for *all* of the type_ctor_reps in this class.

library/rtti_implementation.m:
library/type_desc.m:
      Update code to refer to the new version of the type_ctor_rep constants.

compiler/rtti.m:
      Update the compiler to generate references to the new version of the
      type_ctor_rep constants.

Julien.

diff --git a/compiler/rtti.m b/compiler/rtti.m
index 9845fa7..733aa47 100644
--- a/compiler/rtti.m
+++ b/compiler/rtti.m
@@ -1646,7 +1646,7 @@ functor_subtype_info_to_string(FunctorSubtypeInfo, TargetPrefixes, String) :-

  type_ctor_rep_to_string(TypeCtorData, TargetPrefixes, RepStr) :-
      TargetPrefixes =
-        target_prefixes("private_builtin.", "runtime.TypeCtorRep."),
+        target_prefixes("jmercury.runtime.TypeCtorRep.", "runtime.TypeCtorRep."),
      TypeCtorDetails = TypeCtorData ^ tcr_rep_details,
      (
          TypeCtorDetails = tcd_enum(TypeCtorUserEq, _, _, _, IsDummy, _),
diff --git a/java/runtime/TypeCtorRep.java b/java/runtime/TypeCtorRep.java
index 5ab0d24..dc241a9 100644
--- a/java/runtime/TypeCtorRep.java
+++ b/java/runtime/TypeCtorRep.java
@@ -7,17 +7,64 @@
  package jmercury.runtime;

  public class TypeCtorRep implements java.io.Serializable {
- 
-	// Constants are in private_builtin.m, named MR_TYPECTOR_REP_*.
-	//
-	// XXX We have to duplicate these here for use by TypeInfo_Struct.java
-	// In fact, all the values should be moved here, and the compiler
-	// should generate references to these constants instead of those in
-	// private_builtin.
-	public static final int MR_TYPECTOR_REP_EQUIV		= 6;
-	public static final int MR_TYPECTOR_REP_EQUIV_GROUND	= 30;

-	// Instance variable for TypeCtorRep objects.
+        public static final int MR_TYPECTOR_REP_ENUM                    = 0;
+        public static final int MR_TYPECTOR_REP_ENUM_USEREQ             = 1;
+        public static final int MR_TYPECTOR_REP_DU                      = 2;
+        public static final int MR_TYPECTOR_REP_DU_USEREQ               = 3;
+        public static final int MR_TYPECTOR_REP_NOTAG                   = 4;
+        public static final int MR_TYPECTOR_REP_NOTAG_USEREQ            = 5;
+        public static final int MR_TYPECTOR_REP_EQUIV                   = 6;
+        public static final int MR_TYPECTOR_REP_FUNC                    = 7;
+        public static final int MR_TYPECTOR_REP_INT                     = 8;
+        public static final int MR_TYPECTOR_REP_UINT                    = 9;
+        public static final int MR_TYPECTOR_REP_CHAR                    = 10;
+        public static final int MR_TYPECTOR_REP_FLOAT                   = 11;
+        public static final int MR_TYPECTOR_REP_STRING                  = 12;
+        public static final int MR_TYPECTOR_REP_PRED                    = 13;
+        public static final int MR_TYPECTOR_REP_SUBGOAL                 = 14;
+        public static final int MR_TYPECTOR_REP_VOID                    = 15;
+        public static final int MR_TYPECTOR_REP_C_POINTER               = 16;
+        public static final int MR_TYPECTOR_REP_TYPEINFO                = 17;
+        public static final int MR_TYPECTOR_REP_TYPECLASSINFO           = 18;
+        public static final int MR_TYPECTOR_REP_ARRAY                   = 19;
+        public static final int MR_TYPECTOR_REP_SUCCIP                  = 20;
+        public static final int MR_TYPECTOR_REP_HP                      = 21;
+        public static final int MR_TYPECTOR_REP_CURFR                   = 22;
+        public static final int MR_TYPECTOR_REP_MAXFR                   = 23;
+        public static final int MR_TYPECTOR_REP_REDOFR                  = 24;
+        public static final int MR_TYPECTOR_REP_REDOIP                  = 25;
+        public static final int MR_TYPECTOR_REP_TRAIL_PTR               = 26;
+        public static final int MR_TYPECTOR_REP_TICKET                  = 27;
+        public static final int MR_TYPECTOR_REP_NOTAG_GROUND            = 28;
+        public static final int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ     = 29;
+        public static final int MR_TYPECTOR_REP_EQUIV_GROUND            = 30;
+        public static final int MR_TYPECTOR_REP_TUPLE                   = 31;
+        public static final int MR_TYPECTOR_REP_RESERVED_ADDR           = 32;
+        public static final int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ    = 33;
+        public static final int MR_TYPECTOR_REP_TYPECTORINFO            = 34;
+        public static final int MR_TYPECTOR_REP_BASETYPECLASSINFO       = 35;
+        public static final int MR_TYPECTOR_REP_TYPEDESC                = 36;
+        public static final int MR_TYPECTOR_REP_TYPECTORDESC            = 37;
+        public static final int MR_TYPECTOR_REP_FOREIGN                 = 38;
+        public static final int MR_TYPECTOR_REP_REFERENCE               = 39;
+        public static final int MR_TYPECTOR_REP_STABLE_C_POINTER        = 40;
+        public static final int MR_TYPECTOR_REP_STABLE_FOREIGN          = 41;
+        public static final int MR_TYPECTOR_REP_PSEUDOTYPEDESC          = 42;
+        public static final int MR_TYPECTOR_REP_DUMMY                   = 43;
+        public static final int MR_TYPECTOR_REP_BITMAP                  = 44;
+        public static final int MR_TYPECTOR_REP_FOREIGN_ENUM            = 45;
+        public static final int MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 46;
+        public static final int MR_TYPECTOR_REP_INT8                    = 47;
+        public static final int MR_TYPECTOR_REP_UINT8                   = 48;
+        public static final int MR_TYPECTOR_REP_INT16                   = 49;
+        public static final int MR_TYPECTOR_REP_UINT16                  = 50;
+        public static final int MR_TYPECTOR_REP_INT32                   = 51;
+        public static final int MR_TYPECTOR_REP_UINT32                  = 52;
+        public static final int MR_TYPECTOR_REP_UNKNOWN                 = 53;
+        public static final int MR_TYPECTOR_REP_MAX                     = 54;
+
+        // Instance variable for TypeCtorRep objects.

  	public int value;

@@ -28,3 +75,4 @@ public class TypeCtorRep implements java.io.Serializable {
  	}
  }

+// vim: set ts=8 sts=8 sw=8 noet:
diff --git a/library/private_builtin.m b/library/private_builtin.m
index 04fa671..b7c3eca 100644
--- a/library/private_builtin.m
+++ b/library/private_builtin.m
@@ -1800,6 +1800,10 @@ const MR_FA_TypeInfo_Struct1 ML_type_info_for_list_of_pseudo_type_info = {
      }

      // TypeCtorRep constants
+    //
+    // NOTE: the actual definitions of these constants are now in
+    // java/runtime/TypeCtorRep.java.  These copies are for backwards
+    // compatibility with existing code -- they will eventually be removed.
      public static final int MR_TYPECTOR_REP_ENUM                    = 0;
      public static final int MR_TYPECTOR_REP_ENUM_USEREQ             = 1;
      public static final int MR_TYPECTOR_REP_DU                      = 2;
diff --git a/library/rtti_implementation.m b/library/rtti_implementation.m
index 9e4271c..b0292dd 100644
--- a/library/rtti_implementation.m
+++ b/library/rtti_implementation.m
@@ -263,9 +263,9 @@
  :- pragma foreign_code("Java",
  "
      public static final Type_ctor_rep_0[] static_type_ctor_rep
-        = new Type_ctor_rep_0[private_builtin.MR_TYPECTOR_REP_MAX];
+        = new Type_ctor_rep_0[jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_MAX];
      static {
-        for (int i = 0; i < private_builtin.MR_TYPECTOR_REP_MAX; i++) {
+        for (int i = 0; i < jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_MAX; i++) {
              static_type_ctor_rep[i] = new Type_ctor_rep_0(i);
          }
      }
@@ -2105,8 +2105,8 @@ is_exist_pseudo_type_info(_, _) :-

              switch (tc.type_ctor_rep.value) {

-            case private_builtin.MR_TYPECTOR_REP_ENUM:
-            case private_builtin.MR_TYPECTOR_REP_ENUM_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_ENUM:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_ENUM_USEREQ:
                  EnumFunctorDesc[] functors_enum =
                      tc.type_functors.functors_enum();
                  if (FunctorNumber >= 0 && FunctorNumber < functors_enum.length)
@@ -2116,19 +2116,19 @@ is_exist_pseudo_type_info(_, _) :-
                  }
                  break;

-            case private_builtin.MR_TYPECTOR_REP_FOREIGN_ENUM:
-            case private_builtin.MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ:
-            case private_builtin.MR_TYPECTOR_REP_NOTAG:
-            case private_builtin.MR_TYPECTOR_REP_NOTAG_USEREQ:
-            case private_builtin.MR_TYPECTOR_REP_NOTAG_GROUND:
-            case private_builtin.MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
-            case private_builtin.MR_TYPECTOR_REP_RESERVED_ADDR:
-            case private_builtin.MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FOREIGN_ENUM:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_NOTAG:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_NOTAG_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_NOTAG_GROUND:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_RESERVED_ADDR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
                  /* These don't exist in the Java backend yet. */
                  break;

-            case private_builtin.MR_TYPECTOR_REP_DU:
-            case private_builtin.MR_TYPECTOR_REP_DU_USEREQ:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_DU:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_DU_USEREQ:
                  DuFunctorDesc[] functor_descs = tc.type_functors.functors_du();
                  if (FunctorNumber >= 0 && FunctorNumber < functor_descs.length)
                  {
@@ -2142,12 +2142,12 @@ is_exist_pseudo_type_info(_, _) :-
                  }
                  break;

-            case private_builtin.MR_TYPECTOR_REP_TUPLE:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TUPLE:
                  int arity = TypeInfo.args.length;
                  new_data = ML_univ_list_to_array(ArgList, arity);
                  break;

-            case private_builtin.MR_TYPECTOR_REP_DUMMY:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_DUMMY:
                  if (FunctorNumber == 0 &&
                      ArgList instanceof list.List_1.F_nil_0)
                  {
@@ -2155,142 +2155,142 @@ is_exist_pseudo_type_info(_, _) :-
                  }
                  break;

-            case private_builtin.MR_TYPECTOR_REP_INT:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_INT:
                  /* ints don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct int with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_UINT:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_UINT:
                  /* ints don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct uint with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_FLOAT:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FLOAT:
                  /* floats don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct float with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_CHAR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_CHAR:
                  /* chars don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct chars with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_STRING:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_STRING:
                  /* strings don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct strings with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_BITMAP:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_BITMAP:
                  /* bitmaps don't have functor ordinals. */
                  throw new Error(
                      ""cannot construct bitmaps with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_EQUIV:
-            case private_builtin.MR_TYPECTOR_REP_EQUIV_GROUND:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_EQUIV:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_EQUIV_GROUND:
                  /* These should be eliminated above. */
                  throw new Error(""equiv type in construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_VOID:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_VOID:
                  /* These should be eliminated above. */
                  throw new Error(
                      ""cannot construct void values with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_FUNC:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FUNC:
                  throw new Error(
                      ""cannot construct functions with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_PRED:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_PRED:
                  throw new Error(
                      ""cannot construct predicates with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_SUBGOAL:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_SUBGOAL:
                  throw new Error(
                      ""cannot construct subgoals with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TYPEDESC:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TYPEDESC:
                  throw new Error(
                      ""cannot construct type_descs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TYPECTORDESC:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TYPECTORDESC:
                  throw new Error(
                      ""cannot construct type_descs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_PSEUDOTYPEDESC:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_PSEUDOTYPEDESC:
                  throw new Error(
                      ""cannot construct pseudotype_descs with "" +
                      ""construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TYPEINFO:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TYPEINFO:
                  throw new Error(
                      ""cannot construct type_infos with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TYPECTORINFO:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TYPECTORINFO:
                  throw new Error(
                      ""cannot construct type_ctor_infos with "" +
                      ""construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TYPECLASSINFO:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TYPECLASSINFO:
                  throw new Error(
                      ""cannot construct type_class_infos with "" +
                      ""construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_BASETYPECLASSINFO:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_BASETYPECLASSINFO:
                  throw new Error(
                      ""cannot construct base_type_class_infos "" +
                      ""with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_SUCCIP:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_SUCCIP:
                  throw new Error(
                      ""cannot construct succips with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_HP:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_HP:
                  throw new Error(
                      ""cannot construct hps with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_CURFR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_CURFR:
                  throw new Error(
                      ""cannot construct curfrs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_MAXFR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_MAXFR:
                  throw new Error(
                      ""cannot construct maxfrs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_REDOFR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_REDOFR:
                  throw new Error(
                      ""cannot construct redofrs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_REDOIP:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_REDOIP:
                  throw new Error(
                      ""cannot construct redoips with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TRAIL_PTR:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TRAIL_PTR:
                  throw new Error(
                      ""cannot construct trail_ptrs with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_TICKET:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TICKET:
                  throw new Error(
                      ""cannot construct tickets with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_C_POINTER:
-            case private_builtin.MR_TYPECTOR_REP_STABLE_C_POINTER:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_C_POINTER:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_STABLE_C_POINTER:
                  throw new Error(
                      ""cannot construct c_pointers with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_ARRAY:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_ARRAY:
                  throw new Error(
                      ""cannot construct arrays with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_REFERENCE:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_REFERENCE:
                  throw new Error(
                      ""cannot construct references with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_FOREIGN:
-            case private_builtin.MR_TYPECTOR_REP_STABLE_FOREIGN:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FOREIGN:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_STABLE_FOREIGN:
                  throw new Error(
                      ""cannot construct values of foreign types "" +
                      ""with construct.construct"");

-            case private_builtin.MR_TYPECTOR_REP_UNKNOWN:
+            case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_UNKNOWN:
                  throw new Error(
                      ""cannot construct values of unknown types "" +
                      ""with construct.construct"");
@@ -4499,7 +4499,7 @@ type_ctor_module_name(_) = _ :-
      [will_not_call_mercury, promise_pure, thread_safe],
  "
      if (TypeCtorInfo.type_ctor_rep.value
-            == private_builtin.MR_TYPECTOR_REP_TUPLE) {
+            == jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TUPLE) {
          Name = ""{}"";
      } else {
          Name = TypeCtorInfo.type_ctor_name;
diff --git a/library/type_desc.m b/library/type_desc.m
index d20a332..e729190 100644
--- a/library/type_desc.m
+++ b/library/type_desc.m
@@ -741,9 +741,9 @@ type_ctor_arity(TypeCtor) = Arity :-

      /* Handle variable arity types. */
      switch (tci.type_ctor_rep.value) {
-        case private_builtin.MR_TYPECTOR_REP_PRED:
-        case private_builtin.MR_TYPECTOR_REP_FUNC:
-        case private_builtin.MR_TYPECTOR_REP_TUPLE:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_PRED:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FUNC:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TUPLE:
              tci = new TypeCtorInfo_Struct(tci, TypeInfo.args.length);
              break;
          default:
@@ -791,9 +791,9 @@ make_type_ctor_desc(_, _, _) :-

      /* Handle variable arity types. */
      switch (tci.type_ctor_rep.value) {
-        case private_builtin.MR_TYPECTOR_REP_PRED:
-        case private_builtin.MR_TYPECTOR_REP_FUNC:
-        case private_builtin.MR_TYPECTOR_REP_TUPLE:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_PRED:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_FUNC:
+        case jmercury.runtime.TypeCtorRep.MR_TYPECTOR_REP_TUPLE:
              tci = new TypeCtorInfo_Struct(tci, Arity);
              break;
          default:



More information about the reviews mailing list