[m-dev.] for review: fix array dependency problem

Peter Ross peter.ross at miscrit.be
Fri Jan 12 22:40:50 AEDT 2001


On Fri, Dec 22, 2000 at 03:40:08AM +1100, Fergus Henderson wrote:
> On 21-Dec-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > Hi,
> > 
> > This change bootchecks, but has one outstanding issue.
> > 
> > That is that there exists the following declaration in mercury.c:
> > 
> > static MR_UnifyFunc_1 mercury__array__do_unify__array_1_0;
> > 
> > and I am not sure what to do with it?
> 
> That declaration is used by the following macro invocation
> in mercury.c:
> 
> 	MR_define_type_ctor_info(array, array, 1, MR_TYPECTOR_REP_ARRAY);
> 
> So you haven't actually removed the dependency.
> 
> One possible solution might be to move the line
> 
> 	MR_define_type_ctor_info(array, array, 1, MR_TYPECTOR_REP_ARRAY);
> 
> into library/array.m, and move the macros that it references (directly
> or indirectly) from runtime/mercury.c into one of the header files,
> e.g. runtime/mercury.h or runtime/mercury_type_info.h.
> However, I don't know if the array type_ctor_info is referred to
> from elsewhere in the runtime.
> 
> Another possible solution would be to use function pointers,
> like we currently do with the MR_address_of_* variables.
> 

===================================================================


Estimated hours taken: 5

Avoid a dependency where the runtime depends on the library.

library/array.m:
runtime/mercury.c:
runtime/mercury.h:
runtime/mercury_type_info.h:
    Move code for doing array comparisons and unifications into the std
    library.


Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.81
diff -u -r1.81 array.m
--- library/array.m	2001/01/01 04:03:49	1.81
+++ library/array.m	2001/01/12 11:16:03
@@ -334,19 +334,61 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pragma foreign_decl("C", "
+#ifdef MR_HIGHLEVEL_CODE
+  bool MR_CALL mercury__array__do_unify__array_1_0(
+  	MR_Mercury_Type_Info type_info, MR_Box x, MR_Box y);
+  bool MR_CALL mercury__array____Unify____array_1_0(
+	MR_Mercury_Type_Info type_info, MR_Array x, MR_Array y);
+  void MR_CALL mercury__array__do_compare__array_1_0(MR_Mercury_Type_Info
+ 	 type_info, MR_Comparison_Result *result, MR_Box x, MR_Box y);
+  void MR_CALL mercury__array____Compare____array_1_0(MR_Mercury_Type_Info
+	type_info, MR_Comparison_Result *result, MR_Array x, MR_Array y);
+#endif
+").
+
 :- pragma foreign_code("C", "
 
 #ifdef MR_HIGHLEVEL_CODE
+
+MR_define_type_ctor_info(array, array, 1, MR_TYPECTOR_REP_ARRAY);
+
 void sys_init_array_module_builtins(void);
 void sys_init_array_module_builtins(void) {
+	MR_init_entry(mercury__array____Unify____array_1_0);
+	MR_init_entry(mercury__array____Compare____array_1_0);
 	return;
 }
 
 bool MR_CALL
+mercury__array__do_unify__array_1_0(MR_Mercury_Type_Info type_info,
+	MR_Box x, MR_Box y)
+{
+	return mercury__array____Unify____array_1_0(
+		type_info, (MR_Array) x, (MR_Array) y);
+}
+
+bool MR_CALL
 mercury__array____Unify____array_1_0(MR_Mercury_Type_Info type_info,
 	MR_Array x, MR_Array y)
 {
 	return mercury__array__array_equal_2_p_0(type_info, x, y);
+}
+
+void MR_CALL
+mercury__array__do_compare__array_1_0(
+	MR_Mercury_Type_Info type_info, MR_Comparison_Result *result,
+	MR_Box x, MR_Box y)
+{
+	mercury__array____Compare____array_1_0(
+		type_info, result, (MR_Array) x, (MR_Array) y);
 }
 
 void MR_CALL
Index: runtime/mercury.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.c,v
retrieving revision 1.21
diff -u -r1.21 mercury.c
--- runtime/mercury.c	2001/01/11 17:05:14	1.21
+++ runtime/mercury.c	2001/01/12 11:16:04
@@ -85,7 +85,6 @@
 	mercury__std_util__do_unify__type_desc_0_0;
 
 static MR_UnifyFunc_1
-	mercury__array__do_unify__array_1_0,
 	mercury__builtin__do_unify__tuple_0_0,
 	mercury__private_builtin__do_unify__type_ctor_info_1_0,
 	mercury__private_builtin__do_unify__type_info_1_0,
@@ -104,7 +103,6 @@
 	mercury__std_util__do_compare__type_desc_0_0;
 
 static MR_CompareFunc_1
-	mercury__array__do_compare__array_1_0,
 	mercury__builtin__do_compare__tuple_0_0,
 	mercury__private_builtin__do_compare__type_ctor_info_1_0,
 	mercury__private_builtin__do_compare__type_info_1_0,
@@ -120,53 +118,6 @@
 ** Define MR_TypeCtorInfos for the builtin types
 */
 
-#define MR_type_ctor_info_name(MODULE, TYPE, ARITY)			      \
-	MR_PASTE2(mercury__,						      \
-	MR_PASTE2(MODULE,						      \
-	MR_PASTE2(__,							      \
-	MR_PASTE2(MODULE,						      \
-	MR_PASTE2(__type_ctor_info_,					      \
-	MR_PASTE2(TYPE,							      \
-	MR_PASTE2(_,							      \
-	          ARITY)))))))
-
-#define MR_type_ctor_info_func_name(MODULE, TYPE, ARITY, FUNC)		      \
-	MR_PASTE2(mercury__,						      \
-	MR_PASTE2(MODULE,						      \
-	MR_PASTE2(__,							      \
-	MR_PASTE2(FUNC,							      \
-	MR_PASTE2(__,							      \
-	MR_PASTE2(TYPE,							      \
-	MR_PASTE2(_,							      \
-	MR_PASTE2(ARITY,						      \
-	          _0))))))))
-
-#define MR_special_func_type(NAME, ARITY) \
-	MR_PASTE2(MR_, MR_PASTE2(NAME, MR_PASTE2(Func_, ARITY)))
-
-#define MR_define_type_ctor_info(module, type, arity, type_rep)		      \
-	const struct MR_TypeCtorInfo_Struct				      \
-		MR_type_ctor_info_name(module, type, arity) =		      \
-	{								      \
-		arity,							      \
-		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
-				do_unify),				      \
-		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
-				do_unify),				      \
-		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
-				do_compare),				      \
-		type_rep,						      \
-		NULL,							      \
-		NULL,							      \
-		MR_STRINGIFY(module),					      \
-		MR_STRINGIFY(type),					      \
-		MR_RTTI_VERSION,					      \
-		{ 0 },							      \
-		{ 0 },							      \
-		-1,							      \
-		-1							      \
-	}
-
 MR_define_type_ctor_info(builtin, int, 0, MR_TYPECTOR_REP_INT);
 MR_define_type_ctor_info(builtin, string, 0, MR_TYPECTOR_REP_STRING);
 MR_define_type_ctor_info(builtin, float, 0, MR_TYPECTOR_REP_FLOAT);
@@ -176,7 +127,6 @@
 MR_define_type_ctor_info(builtin, pred, 0, MR_TYPECTOR_REP_PRED);
 MR_define_type_ctor_info(builtin, func, 0, MR_TYPECTOR_REP_PRED);
 MR_define_type_ctor_info(builtin, tuple, 0, MR_TYPECTOR_REP_TUPLE);
-MR_define_type_ctor_info(array, array, 1, MR_TYPECTOR_REP_ARRAY);
 MR_define_type_ctor_info(std_util, type_desc, 0, MR_TYPECTOR_REP_TYPEINFO);
 MR_define_type_ctor_info(private_builtin, type_ctor_info, 1,
 	MR_TYPECTOR_REP_TYPEINFO);
@@ -697,14 +647,6 @@
 }
 
 static bool MR_CALL
-mercury__array__do_unify__array_1_0(MR_Mercury_Type_Info type_info,
-	MR_Box x, MR_Box y)
-{
-	return mercury__array____Unify____array_1_0(
-		type_info, (MR_Array) x, (MR_Array) y);
-}
-
-static bool MR_CALL
 mercury__std_util__do_unify__type_desc_0_0(MR_Box x, MR_Box y)
 {
 	return mercury__std_util____Unify____type_desc_0_0(
@@ -822,15 +764,6 @@
 }
 
 static void MR_CALL
-mercury__array__do_compare__array_1_0(
-	MR_Mercury_Type_Info type_info, MR_Comparison_Result *result,
-	MR_Box x, MR_Box y)
-{
-	mercury__array____Compare____array_1_0(
-		type_info, result, (MR_Array) x, (MR_Array) y);
-}
-
-static void MR_CALL
 mercury__std_util__do_compare__type_desc_0_0(
 	MR_Comparison_Result *result, MR_Box x, MR_Box y)
 {
@@ -961,7 +894,6 @@
 	MR_init_entry(mercury__builtin____Unify____c_pointer_0_0);
 	MR_init_entry(mercury__builtin____Unify____func_0_0);
 	MR_init_entry(mercury__builtin____Unify____pred_0_0);
-	MR_init_entry(mercury__array____Unify____array_1_0);
 	MR_init_entry(mercury__std_util____Unify____type_desc_0_0);
 	MR_init_entry(mercury__private_builtin____Unify____type_ctor_info_1_0);
 	MR_init_entry(mercury__private_builtin____Unify____type_info_1_0);
@@ -976,7 +908,6 @@
 	MR_init_entry(mercury__builtin____Compare____c_pointer_0_0);
 	MR_init_entry(mercury__builtin____Compare____func_0_0);
 	MR_init_entry(mercury__builtin____Compare____pred_0_0);
-	MR_init_entry(mercury__array____Compare____array_1_0);
 	MR_init_entry(mercury__std_util____Compare____type_desc_0_0);
 	MR_init_entry(mercury__private_builtin____Compare____type_ctor_info_1_0);
 	MR_init_entry(mercury__private_builtin____Compare____type_info_1_0);
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.30
diff -u -r1.30 mercury.h
--- runtime/mercury.h	2001/01/10 10:57:25	1.30
+++ runtime/mercury.h	2001/01/12 11:16:05
@@ -33,6 +33,7 @@
 #include "mercury_bootstrap.h"
 #include "mercury_memory.h"	/* for memory allocation routines */
 #include "mercury_type_tables.h"	/* for MR_register_type_ctor_info */
+#include "mercury_goto.h"		/* for MR_init_entry */
 
 #ifdef CONSERVATIVE_GC
   #include "gc.h"
@@ -379,8 +380,6 @@
 bool MR_CALL mercury__builtin____Unify____pred_0_0(MR_Pred x, MR_Pred y); 
 bool MR_CALL mercury__builtin____Unify____tuple_0_0(
 	MR_Mercury_Type_Info type_info, MR_Tuple x, MR_Tuple y); 
-bool MR_CALL mercury__array____Unify____array_1_0(
-	MR_Mercury_Type_Info type_info, MR_Array x, MR_Array y);
 bool MR_CALL mercury__std_util____Unify____univ_0_0(MR_Univ x, MR_Univ y); 
 bool MR_CALL mercury__std_util____Unify____type_desc_0_0(
 	MR_Type_Desc x, MR_Type_Desc y); 
@@ -416,8 +415,6 @@
 void MR_CALL mercury__builtin____Compare____tuple_0_0(
 	MR_Mercury_Type_Info type_info, MR_Comparison_Result *result,
 	MR_Tuple x, MR_Tuple y); 
-void MR_CALL mercury__array____Compare____array_1_0(MR_Mercury_Type_Info
-	type_info, MR_Comparison_Result *result, MR_Array x, MR_Array y);
 void MR_CALL mercury__std_util____Compare____univ_0_0(
 	MR_Comparison_Result *result, MR_Univ x, MR_Univ y);
 void MR_CALL mercury__std_util____Compare____type_desc_0_0(
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.61
diff -u -r1.61 mercury_type_info.h
--- runtime/mercury_type_info.h	2000/12/18 07:42:58	1.61
+++ runtime/mercury_type_info.h	2001/01/12 11:16:06
@@ -281,6 +281,61 @@
 #define MR_fill_in_tuple_type_info(arena, type_ctor_info, arity, vector) \
     MR_fill_in_higher_order_type_info(arena, type_ctor_info, arity, vector)
 
+/*
+** Used to define MR_TypeCtorInfos for the builtin types in the hlc grades.
+** This needs to be exported for use by the array type in the library.
+*/
+#ifdef MR_HIGHLEVEL_CODE
+
+#define MR_type_ctor_info_name(MODULE, TYPE, ARITY)			      \
+	MR_PASTE2(mercury__,						      \
+	MR_PASTE2(MODULE,						      \
+	MR_PASTE2(__,							      \
+	MR_PASTE2(MODULE,						      \
+	MR_PASTE2(__type_ctor_info_,					      \
+	MR_PASTE2(TYPE,							      \
+	MR_PASTE2(_,							      \
+	          ARITY)))))))
+
+#define MR_type_ctor_info_func_name(MODULE, TYPE, ARITY, FUNC)		      \
+	MR_PASTE2(mercury__,						      \
+	MR_PASTE2(MODULE,						      \
+	MR_PASTE2(__,							      \
+	MR_PASTE2(FUNC,							      \
+	MR_PASTE2(__,							      \
+	MR_PASTE2(TYPE,							      \
+	MR_PASTE2(_,							      \
+	MR_PASTE2(ARITY,						      \
+	          _0))))))))
+
+#define MR_special_func_type(NAME, ARITY) \
+	MR_PASTE2(MR_, MR_PASTE2(NAME, MR_PASTE2(Func_, ARITY)))
+
+#define MR_define_type_ctor_info(module, type, arity, type_rep)		      \
+	const struct MR_TypeCtorInfo_Struct				      \
+		MR_type_ctor_info_name(module, type, arity) =		      \
+	{								      \
+		arity,							      \
+		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
+				do_unify),				      \
+		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
+				do_unify),				      \
+		(MR_Box) MR_type_ctor_info_func_name(module, type, arity,     \
+				do_compare),				      \
+		type_rep,						      \
+		NULL,							      \
+		NULL,							      \
+		MR_STRINGIFY(module),					      \
+		MR_STRINGIFY(type),					      \
+		MR_RTTI_VERSION,					      \
+		{ 0 },							      \
+		{ 0 },							      \
+		-1,							      \
+		-1							      \
+	}
+
+#endif /* MR_HIGHLEVEL_CODE */
+
 /*---------------------------------------------------------------------------*/
 
 /*

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list