[m-dev.] for review: fix Aditi initialization code

Simon Taylor stayl at cs.mu.OZ.AU
Fri Feb 4 15:22:40 AEDT 2000


Estimated hours taken: 1

Remove the dependency of the Aditi interface library in
extras/aditi/aditi.m on code in the automatically generated
C init file.

runtime/mercury_wrapper.h:
	Add a global variable `MR_address_of_do_load_aditi_rl_code'.

	Add a function `MR_load_aditi_rl_code', which calls
	the function pointed to by `MR_address_of_do_load_aditi_rl_code',
	aborting if it is not set.

runtime/mercury_init.h:
	Remove the declaration for `mercury__load_aditi_rl_code()' --
	that is now local to the `<module>_init.c' file.

util/mkinit.c:
	Rename `mercury__load_aditi_rl_code' to `MR_do_load_aditi_rl_code()'
	in the `<module>_init.c' file, and add a static prototype for it.

	Add a statement to `mercury_init()' to fill in the
	`MR_address_of_do_load_aditi_rl_code' variable.

extras/aditi/aditi.m:
	Rename `mercury__load_aditi_rl_code()' to `MR_load_aditi_rl_code()'.



Index: extras/aditi/aditi.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/extras/aditi/aditi.m,v
retrieving revision 1.4
diff -u -u -r1.4 aditi.m
--- aditi.m	1999/10/18 15:46:17	1.4
+++ aditi.m	2000/02/04 02:31:28
@@ -158,7 +158,7 @@
 
 :- pragma c_header_code("
 
-#include ""mercury_init.h""
+#include ""mercury_wrapper.h""
 #include ""aditi_clnt.h""
 
 #define MADITI_throw MR_longjmp(&MADITI_jmp_buf);
@@ -215,7 +215,7 @@
 			DEBUG(ADITI_NAME(disable_ping)());
 
 			DEBUG(printf(""logged in\\n""));
-			if ((Stat = mercury__load_aditi_rl_code())
+			if ((Stat = MR_load_aditi_rl_code())
 					== ADITI_OK) {
 				DEBUG(printf(""code loaded\\n""));
 			} else {
Index: runtime/mercury_init.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_init.h,v
retrieving revision 1.19
diff -u -u -r1.19 mercury_init.h
--- mercury_init.h	1999/12/20 14:03:49	1.19
+++ mercury_init.h	2000/02/04 02:31:58
@@ -158,16 +158,6 @@
 
 /*---------------------------------------------------------------------------*/
 
-/*
-** mercury__load_aditi_rl_code() is defined in the <module>_init.c file.
-** It uploads all the Aditi-RL code for the program to a database to
-** which the program currently has a connection, returning a status value
-** as described in aditi2/src/api/aditi_err.h in the Aditi sources.
-*/
-extern	int	mercury__load_aditi_rl_code(void);
-
-/*---------------------------------------------------------------------------*/
-
 #endif /* not MERCURY_INIT_H */
 
 /*---------------------------------------------------------------------------*/
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.53
diff -u -u -r1.53 mercury_wrapper.c
--- mercury_wrapper.c	2000/01/03 08:53:09	1.53
+++ mercury_wrapper.c	2000/02/04 04:11:43
@@ -130,6 +130,9 @@
 **   calls main/2 in the user's program.
 ** - The Mercury runtime finalization, namely mercury_runtime_terminate(),
 **   calls io__finalize_state/2 in the Mercury library.
+** - `aditi__connect/6' in extras/aditi/aditi.m calls
+**   MR_do_load_aditi_rl_code() in the automatically
+**   generated C init file.
 **
 ** But, to enable Quickstart of shared libraries on Irix 5,
 ** and in general to avoid various other complications
@@ -146,6 +149,8 @@
 void	(*address_of_mercury_init_io)(void);
 void	(*address_of_init_modules)(void);
 
+int	(*MR_address_of_do_load_aditi_rl_code)(void);
+
 char *	(*MR_address_of_trace_getline)(const char *, FILE *, FILE *);
 
 #ifdef	MR_USE_EXTERNAL_DEBUGGER
@@ -1298,6 +1303,22 @@
 	restore_regs_from_mem(c_regs);
 
 	return mercury_exit_status;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+MR_load_aditi_rl_code(void)
+{
+	if (MR_address_of_do_load_aditi_rl_code != NULL) {
+		return (*MR_address_of_do_load_aditi_rl_code)();	
+	} else {
+		fatal_error(
+			"attempt to load Aditi-RL code from an executable\n"
+			"not compiled for Aditi execution.\n"
+			"Add `--aditi' to C2INITFLAGS.\n"
+		);
+	}
 }
 
 /*---------------------------------------------------------------------------*/
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.27
diff -u -u -r1.27 mercury_wrapper.h
--- mercury_wrapper.h	1999/12/20 14:03:51	1.27
+++ mercury_wrapper.h	2000/02/04 02:00:35
@@ -38,6 +38,15 @@
 extern	int	mercury_runtime_terminate(void);
 
 /*
+** MR_load_aditi_rl_code() uploads all the Aditi-RL code for
+** the program to a database to which the program currently has a
+** connection, returning a status value as described in
+** aditi2/src/api/aditi_err.h in the Aditi sources.
+** It aborts if the executable was not compiled for Aditi execution. 
+*/
+extern	int	MR_load_aditi_rl_code(void);
+
+/*
 ** The following global variables are set by mercury_init() on startup.
 ** The entry points are set based on the options to mkinit.c.
 ** The address_of_foo pointers are set to the address of
@@ -60,6 +69,8 @@
 #ifdef CONSERVATIVE_GC
 extern	void		(*address_of_init_gc)(void);
 #endif
+
+extern	int		(*MR_address_of_do_load_aditi_rl_code)(void);
 
 /*
 ** MR_trace_getline(const char *, FILE *, FILE *) is defined in
Index: util/mkinit.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/util/mkinit.c,v
retrieving revision 1.60
diff -u -u -r1.60 mkinit.c
--- mkinit.c	1999/12/22 03:41:58	1.60
+++ mkinit.c	2000/02/04 04:17:51
@@ -98,6 +98,17 @@
 	"\n"
 	;
 
+static const char aditi_header[] =
+	"/*\n"
+	"** MR_do_load_aditi_rl_code() uploads all the Aditi-RL code\n"
+	"** for the program to a database to which the program currently\n"
+	"** has a connection, returning a status value as described in\n"
+	"** aditi2/src/api/aditi_err.h in the Aditi sources.\n"
+	"*/\n"
+	"static int MR_do_load_aditi_rl_code(void);\n"
+	"\n"
+	;
+
 static const char mercury_funcs[] =
 	"\n"
 	"#define MR_TRACE_ENABLED %d\n"
@@ -151,6 +162,7 @@
 	"\n"
 	"	address_of_mercury_init_io = mercury_init_io;\n"
 	"	address_of_init_modules = init_modules;\n"
+	"	MR_address_of_do_load_aditi_rl_code = %s;\n"
 	"#ifdef CONSERVATIVE_GC\n"
 	"	address_of_init_gc = init_gc;\n"
 	"#endif\n"
@@ -476,6 +488,10 @@
 	}
 
 	fputs(header2, stdout);
+
+	if (aditi) {
+		fputs(aditi_header, stdout);
+	}
 }
 
 static void 
@@ -526,7 +542,17 @@
 static void 
 output_main(void)
 {
-	printf(mercury_funcs, need_tracing, entry_point, entry_point);
+	char *aditi_load_func;
+
+	if (aditi) {
+		aditi_load_func = "MR_do_load_aditi_rl_code";
+	} else {
+		aditi_load_func = "NULL";
+	}
+	
+	printf(mercury_funcs, need_tracing, entry_point,
+		aditi_load_func, entry_point);
+
 	if (output_main_func) {
 		fputs(main_func, stdout);
 	}
@@ -708,8 +734,9 @@
 
 	/*
 	** Load the Aditi-RL for each module into the database.
-	** mercury__load_aditi_rl_code() is called by aditi__connect/6
-	** in extras/aditi/aditi.m.
+	** MR_do_load_aditi_rl_code() is called by MR_load_aditi_rl_code()
+	** in runtime/mercury_wrapper.c, which is called by
+	** `aditi__connect/6' in extras/aditi/aditi.m.
 	*/
 static void
 output_aditi_load_function(void)
@@ -734,7 +761,9 @@
 		printf("extern const int %s__length;\n", node->data);
 	}
 
-	printf("int mercury__load_aditi_rl_code(void)\n{\n"),
+	printf("\n");
+	printf("static int\n");
+	printf("MR_do_load_aditi_rl_code(void)\n{\n"),
 
 	/* Build an array containing the addresses of the RL data constants. */
 	printf("\tstatic const char *rl_data[] = {\n\t\t");
--------------------------------------------------------------------------
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