mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 13:55:07 +00:00
Some fixes to the Java back-end, to make it work again after
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/
This commit is contained in:
@@ -1703,11 +1703,27 @@ ctor_rtti_name_java_type(RttiName, JavaTypeName, IsArray) :-
|
||||
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.
|
||||
|
||||
@@ -1507,8 +1507,7 @@ gen_init_maybe(Type, _Conv, no) = gen_init_null_pointer(Type).
|
||||
|
||||
:- 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.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2001-2003 The University of Melbourne.
|
||||
// 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.
|
||||
//
|
||||
@@ -12,13 +12,17 @@ public class DuExistInfo {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ package mercury.runtime;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
64
java/runtime/TypeClassConstraint.java
Normal file
64
java/runtime/TypeClassConstraint.java
Normal file
@@ -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
|
||||
}
|
||||
27
java/runtime/TypeClassDeclStruct.java
Normal file
27
java/runtime/TypeClassDeclStruct.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
33
java/runtime/TypeClassId.java
Normal file
33
java/runtime/TypeClassId.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
24
java/runtime/TypeClassMethod.java
Normal file
24
java/runtime/TypeClassMethod.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
//
|
||||
// Copyright (C) 2001-2003 The University of Melbourne.
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -1288,6 +1288,9 @@ no_clauses(PredName) :-
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user