[m-dev.] for review: bug fixes & cleanups in runtime/*

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 11 13:01:07 AEDT 1998


On 10-Nov-1998, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> 
> > runtime/mercury_imp.h:
> > 	Make mercury_bootstrap the first header file that is #included,
> > 	in case some of the macros defined in it are used in declarations
> > 	in other header files.
> 
> Are there any occasions where that is the case? I don't believe so.

You're correct.  That change was a mistake.  I will undo it.

> > --- mercury_bootstrap.h	1998/11/05 06:27:41	1.1
> > +++ mercury_bootstrap.h	1998/11/09 11:18:21
> > +
> > +#define	framevar(n)		MR_framevar((n) + 1)
> 
> The framevar definition should be close to the register definitions.

Done.

> It should also be accompanied by the blocks of macro definitions headed
> by the definitions of bt_prevfr and curprevfr from mercury_stacks.h,
> as well as the definitions of detstackvar, push, pop and modframe.

Unfortunately most of these macros were still used in the code.
For the most part, I have modified the code to avoid using the old names.
However, I left push() and pop() in there since they are
used in mercury_wrapper.c.

Here's a diff that addresses those concerns.

--------------------

Estimated hours taken: 1

runtime/mercury_bootstrap.h:
runtime/mercury_stacks.h:
	Move some more #defines that were there just for backwards
	compatibility into mercury_bootstrap.h.

runtime/mercury_imp.h:
runtime/mercury_bootstrap.h:
	Put the #include of "mercury_bootstrap.h" last rather than first,
	since the macros defined in mercury_bootstrap.h should not be
	used in other header files.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_context.h:
runtime/mercury_context.c:
runtime/mercury_misc.c:
runtime/mercury_type_info.c:
	Use the new macros instead of the old ones that have now been
	moved to "mercury_bootstrap.h".

Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_accurate_gc.c
--- mercury_accurate_gc.c	1998/10/23 00:41:23	1.3
+++ mercury_accurate_gc.c	1998/11/11 01:39:41
@@ -402,8 +402,10 @@
 			break;
 
 		case MR_LVAL_TYPE_FRAMEVAR:
-			bt_var(current_frame, locn_num) = agc_deep_copy(
-				&bt_var(current_frame, locn_num), type_info,
+			MR_based_framevar(current_frame, locn_num) =
+				agc_deep_copy(
+				&MR_based_framevar(current_frame, locn_num),
+				type_info,
 				MR_ENGINE(heap_zone2->min),
 				MR_ENGINE(heap_zone2->hardmax));
 			break;
Index: runtime/mercury_agc_debug.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_agc_debug.c,v
retrieving revision 1.7
diff -u -r1.7 mercury_agc_debug.c
--- mercury_agc_debug.c	1998/11/09 14:35:28	1.7
+++ mercury_agc_debug.c	1998/11/11 01:39:58
@@ -219,7 +219,7 @@
 			break;
 
 		case MR_LVAL_TYPE_FRAMEVAR:
-			value = bt_var(current_frame, locn_num);
+			value = MR_based_framevar(current_frame, locn_num);
 			have_value = TRUE;
 			fprintf(stderr, "framevar%d", locn_num);
 			break;
Index: runtime/mercury_bootstrap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.h,v
retrieving revision 1.2
diff -u -r1.2 mercury_bootstrap.h
--- mercury_bootstrap.h	1998/11/09 14:35:29	1.2
+++ mercury_bootstrap.h	1998/11/11 01:33:44
@@ -10,8 +10,6 @@
 ** Temporary definitions only needed for bootstrapping and/or
 ** for backwards compatibility.  All of the definitions here
 ** will go away eventually, so don't use them!
-**
-** This file should contain MACROS ONLY -- see mercury_imp.h for why.
 */
 
 #ifndef	MERCURY_BOOTSTRAP_H
@@ -19,11 +17,38 @@
 
 #define	NONDET_FIXED_SIZE	MR_NONDET_FIXED_SIZE
 
-#define succip		MR_succip
-#define hp		MR_hp
-#define sp		MR_sp
-#define curfr		MR_curfr
-#define maxfr		MR_maxfr
+#define succip			MR_succip
+#define hp			MR_hp
+#define sp			MR_sp
+#define curfr			MR_curfr
+#define maxfr			MR_maxfr
+
+#define	detstackvar(n)		MR_stackvar(n)
+#define	framevar(n)		MR_framevar((n) + 1)
+
+#define	bt_prevfr(fr)		MR_prevfr_slot(fr)
+#define	bt_redoip(fr)		MR_redoip_slot(fr)
+#define	bt_redofr(fr)		MR_redofr_slot(fr)
+#define	bt_succip(fr)		MR_succip_slot(fr)
+#define	bt_succfr(fr)		MR_succfr_slot(fr)
+#define	bt_prednm(fr)		MR_prednm_slot(fr)
+#define	bt_var(fr, n)		MR_based_framevar(fr, (n) + 1)
+
+#define	curprevfr		bt_prevfr(MR_curfr)
+#define	curredoip		bt_redoip(MR_curfr)
+#define	curredofr		bt_redofr(MR_curfr)
+#define	cursuccip		bt_succip(MR_curfr)
+#define	cursuccfr		bt_succfr(MR_curfr)
+#define	curprednm		bt_prednm(MR_curfr)
+
+/*
+** This should be removed soon - the latest compiler does not generate it.
+*/
+#define modframe(redoip)						\
+			do {						\
+				curredoip = redoip;			\
+			} while (0)
+
 
 #define TYPELAYOUT_UNASSIGNED_VALUE	(MR_TYPELAYOUT_UNASSIGNED_VALUE)
 #define TYPELAYOUT_UNUSED_VALUE		(MR_TYPELAYOUT_UNUSED_VALUE)
@@ -37,7 +62,5 @@
 #define TYPELAYOUT_ARRAY_VALUE		(MR_TYPELAYOUT_ARRAY_VALUE)
 #define TYPELAYOUT_TYPEINFO_VALUE	(MR_TYPELAYOUT_TYPEINFO_VALUE)
 #define TYPELAYOUT_C_POINTER_VALUE	(MR_TYPELAYOUT_C_POINTER_VALUE)
-
-#define	framevar(n)		MR_framevar((n) + 1)
 
 #endif	/* MERCURY_BOOTSTRAP_H */
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.15
diff -u -r1.15 mercury_context.c
--- mercury_context.c	1998/11/09 05:20:41	1.15
+++ mercury_context.c	1998/11/11 01:37:09
@@ -100,10 +100,10 @@
 	}
 	c->context_maxfr = c->nondetstack_zone->min;
 	c->context_curfr = c->nondetstack_zone->min;
-	bt_redoip(c->context_curfr) = ENTRY(do_not_reached);
-	bt_prevfr(c->context_curfr) = NULL;
-	bt_succip(c->context_curfr) = ENTRY(do_not_reached);
-	bt_succfr(c->context_curfr) = NULL;
+	MR_redoip_slot(c->context_curfr) = ENTRY(do_not_reached);
+	MR_prevfr_slot(c->context_curfr) = NULL;
+	MR_succip_slot(c->context_curfr) = ENTRY(do_not_reached);
+	MR_succfr_slot(c->context_curfr) = NULL;
 
 #ifdef MR_USE_TRAIL
 	if (c->trail_zone != NULL) {
Index: runtime/mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.7
diff -u -r1.7 mercury_context.h
--- mercury_context.h	1998/08/24 04:46:59	1.7
+++ mercury_context.h	1998/11/11 01:32:33
@@ -225,7 +225,7 @@
 				fork_new_context_i > 0 ;		\
 				fork_new_context_i--) {			\
 			*(f_n_c_context->context_sp) = 			\
-				detstackvar(fork_new_context_i);	\
+				MR_stackvar(fork_new_context_i);	\
 			f_n_c_context->context_sp++;			\
 		}							\
 		f_n_c_context->resume = (child);			\
Index: runtime/mercury_imp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_imp.h,v
retrieving revision 1.13
diff -u -r1.13 mercury_imp.h
--- mercury_imp.h	1998/11/09 14:35:33	1.13
+++ mercury_imp.h	1998/11/11 01:13:40
@@ -20,12 +20,6 @@
 #define MERCURY_IMP_H
 
 /*
-** mercury_bootstrap.h should come first, since may defines macros
-** used in other header files.
-*/
-#include	"mercury_bootstrap.h"
-
-/*
 ** The #include of "mercury_conf.h" must come before the `#ifdef USE_DLLS',
 ** because mercury_conf.h defines the USE_DLLS macro.
 */
@@ -81,5 +75,7 @@
 #include	"mercury_tabling.h"
 
 #include	"mercury_grade.h"
+
+#include	"mercury_bootstrap.h"
 
 #endif /* not MERCURY_IMP_H */
Index: runtime/mercury_misc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.c,v
retrieving revision 1.13
diff -u -r1.13 mercury_misc.c
--- mercury_misc.c	1998/09/29 05:11:02	1.13
+++ mercury_misc.c	1998/11/11 01:47:54
@@ -27,12 +27,13 @@
 {
 	restore_transient_registers();
 
-	printf("\nnew choice point for procedure %s\n", curprednm);
-	printf("new  fr: "); printnondstack(curfr);
-	printf("prev fr: "); printnondstack(curprevfr);
-	printf("succ fr: "); printnondstack(cursuccfr);
-	printf("succ ip: "); printlabel(cursuccip);
-	printf("redo ip: "); printlabel(curredoip);
+	printf("\nnew choice point for procedure %s\n",
+		MR_prednm_slot(MR_curfr));
+	printf("new  fr: "); printnondstack(MR_curfr);
+	printf("prev fr: "); printnondstack(MR_prevfr_slot(MR_curfr));
+	printf("succ fr: "); printnondstack(MR_succfr_slot(MR_curfr));
+	printf("succ ip: "); printlabel(MR_succip_slot(MR_curfr));
+	printf("redo ip: "); printlabel(MR_redoip_slot(MR_curfr));
 
 	if (MR_detaildebug) {
 		dumpnondstack();
@@ -46,10 +47,10 @@
 {
 	restore_transient_registers();
 
-	printf("\nsucceeding from procedure %s\n", curprednm);
-	printf("curr fr: "); printnondstack(curfr);
-	printf("succ fr: "); printnondstack(cursuccfr);
-	printf("succ ip: "); printlabel(cursuccip);
+	printf("\nsucceeding from procedure %s\n", MR_prednm_slot(MR_curfr));
+	printf("curr fr: "); printnondstack(MR_curfr);
+	printf("succ fr: "); printnondstack(MR_succfr_slot(MR_curfr));
+	printf("succ ip: "); printlabel(MR_succip_slot(MR_curfr));
 
 	if (MR_detaildebug) {
 		printregs("registers at success");
@@ -63,10 +64,10 @@
 {
 	restore_transient_registers();
 
-	printf("\nsucceeding from procedure %s, discarding frame\n", curprednm);
-	printf("curr fr: "); printnondstack(curfr);
-	printf("succ fr: "); printnondstack(cursuccfr);
-	printf("succ ip: "); printlabel(cursuccip);
+	printf("\nsucceeding from procedure %s, discarding frame\n", MR_prednm_slot(MR_curfr));
+	printf("curr fr: "); printnondstack(MR_curfr);
+	printf("succ fr: "); printnondstack(MR_succfr_slot(MR_curfr));
+	printf("succ ip: "); printlabel(MR_succip_slot(MR_curfr));
 
 	if (MR_detaildebug) {
 		printregs("registers at success");
@@ -80,10 +81,10 @@
 {
 	restore_transient_registers();
 
-	printf("\nfailing from procedure %s\n", curprednm);
-	printf("curr fr: "); printnondstack(curfr);
-	printf("fail fr: "); printnondstack(curprevfr);
-	printf("fail ip: "); printlabel(bt_redoip(curprevfr));
+	printf("\nfailing from procedure %s\n", MR_prednm_slot(MR_curfr));
+	printf("curr fr: "); printnondstack(MR_curfr);
+	printf("fail fr: "); printnondstack(MR_prevfr_slot(MR_curfr));
+	printf("fail ip: "); printlabel(MR_redoip_slot(curprevfr_slot(MR_curfr)));
 
 	return;
 }
@@ -93,10 +94,10 @@
 {
 	restore_transient_registers();
 
-	printf("\nredo from procedure %s\n", curprednm);
-	printf("curr fr: "); printnondstack(curfr);
-	printf("redo fr: "); printnondstack(maxfr);
-	printf("redo ip: "); printlabel(bt_redoip(maxfr));
+	printf("\nredo from procedure %s\n", MR_prednm_slot(MR_curfr));
+	printf("curr fr: "); printnondstack(MR_curfr);
+	printf("redo fr: "); printnondstack(MR_maxfr);
+	printf("redo ip: "); printlabel(MR_redoip_slot(MR_maxfr));
 
 	return;
 }
@@ -117,7 +118,7 @@
 	restore_transient_registers();
 
 	printf("\ntail calling "); printlabel(proc);
-	printf("continuation "); printlabel(succip);
+	printf("continuation "); printlabel(MR_succip);
 	printregs("registers at tailcall");
 
 	return;
@@ -315,17 +316,17 @@
 		(const void *) fr, 
 		(long) (Integer) (fr - MR_CONTEXT(nondetstack_zone)->min));
 #ifdef	MR_DEBUG_NONDET_STACK
-	printf("\t predname  %s\n", bt_prednm(fr));
+	printf("\t predname  %s\n", MR_prednm_slot(fr));
 #endif
-	printf("\t succip    "); printlabel(bt_succip(fr));
-	printf("\t redoip    "); printlabel(bt_redoip(fr));
-	printf("\t succfr    "); printnondstack(bt_succfr(fr));
-	printf("\t prevfr    "); printnondstack(bt_prevfr(fr));
+	printf("\t succip    "); printlabel(MR_succip_slot(fr));
+	printf("\t redoip    "); printlabel(MR_redoip_slot(fr));
+	printf("\t succfr    "); printnondstack(MR_succfr_slot(fr));
+	printf("\t prevfr    "); printnondstack(MR_prevfr_slot(fr));
 
-	for (i = 0; &bt_var(fr,i) > bt_prevfr(fr); i++) {
+	for (i = 1; &MR_based_framevar(fr,i) > MR_prevfr_slot(fr); i++) {
 		printf("\t framevar(%d)  %ld 0x%lx\n",
-			i, (long) (Integer) bt_var(fr,i),
-			(unsigned long) bt_var(fr,i));
+			i, (long) (Integer) MR_based_framevar(fr,i),
+			(unsigned long) MR_based_framevar(fr,i));
 	}
 	return;
 }
@@ -336,8 +337,8 @@
 	reg	Word	*fr;
 
 	printf("\nnondstack dump\n");
-	for (fr = maxfr; fr > MR_CONTEXT(nondetstack_zone)->min;
-			fr = bt_prevfr(fr)) {
+	for (fr = MR_maxfr; fr > MR_CONTEXT(nondetstack_zone)->min;
+			fr = MR_prevfr_slot(fr)) {
 		dumpframe(fr);
 	}
 	return;
@@ -347,7 +348,7 @@
 printframe(const char *msg)
 {
 	printf("\n%s\n", msg);
-	dumpframe(curfr);
+	dumpframe(MR_curfr);
 
 	print_ordinary_regs();
 	return;
@@ -360,11 +361,11 @@
 
 	printf("\n%s\n", msg);
 
-	printf("%-9s", "succip:");  printlabel(succip);
-	printf("%-9s", "curfr:");   printnondstack(curfr);
-	printf("%-9s", "maxfr:");   printnondstack(maxfr);
-	printf("%-9s", "hp:");      printheap(hp);
-	printf("%-9s", "sp:");      printdetstack(sp);
+	printf("%-9s", "succip:");  printlabel(MR_succip);
+	printf("%-9s", "curfr:");   printnondstack(MR_curfr);
+	printf("%-9s", "maxfr:");   printnondstack(MR_maxfr);
+	printf("%-9s", "hp:");      printheap(MR_hp);
+	printf("%-9s", "sp:");      printdetstack(MR_sp);
 
 	print_ordinary_regs();
 
Index: runtime/mercury_stacks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.h,v
retrieving revision 1.12
diff -u -r1.12 mercury_stacks.h
--- mercury_stacks.h	1998/11/09 14:35:38	1.12
+++ mercury_stacks.h	1998/11/11 01:32:52
@@ -20,8 +20,6 @@
 #define	MR_based_stackvar(base_sp, n)	((base_sp)[-n])
 #define	MR_stackvar(n)			MR_based_stackvar(MR_sp, n)
 
-#define	detstackvar(n)			MR_based_stackvar(MR_sp, n)
-
 #define	incr_sp_push_msg(n, msg)				\
 			(					\
 				debugincrsp(n, MR_sp),		\
@@ -107,21 +105,6 @@
 #define	MR_detfr_slot(fr)	LVALUE_CAST(Word *, ((Word *) (fr))[MR_DETFR])
 #define	MR_based_framevar(fr, n) (((Word *) (fr))[MR_SAVEVAL + 1 - (n)])
 
-#define	bt_prevfr(fr)		MR_prevfr_slot(fr)
-#define	bt_redoip(fr)		MR_redoip_slot(fr)
-#define	bt_redofr(fr)		MR_redofr_slot(fr)
-#define	bt_succip(fr)		MR_succip_slot(fr)
-#define	bt_succfr(fr)		MR_succfr_slot(fr)
-#define	bt_prednm(fr)		MR_prednm_slot(fr)
-#define	bt_var(fr, n)		MR_based_framevar(fr, (n) + 1)
-
-#define	curprevfr		bt_prevfr(MR_curfr)
-#define	curredoip		bt_redoip(MR_curfr)
-#define	curredofr		bt_redofr(MR_curfr)
-#define	cursuccip		bt_succip(MR_curfr)
-#define	cursuccfr		bt_succfr(MR_curfr)
-#define	curprednm		bt_prednm(MR_curfr)
-
 #define	MR_framevar(n)		MR_based_framevar(MR_curfr, n)
 
 /* DEFINITIONS FOR MANIPULATING THE NONDET STACK */
@@ -200,14 +183,6 @@
 				MR_redofr_slot(MR_maxfr) = MR_curfr;	\
 				MR_detfr_slot(MR_maxfr)  = MR_sp;	\
 				nondstack_overflow_check();		\
-			} while (0)
-
-/*
-** This should be removed soon - the latest compiler does not generate it.
-*/
-#define modframe(redoip)						\
-			do {						\
-				curredoip = redoip;			\
 			} while (0)
 
 #define	succeed()	do {						\
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.13
diff -u -r1.13 mercury_type_info.c
--- mercury_type_info.c	1998/11/09 05:20:44	1.13
+++ mercury_type_info.c	1998/11/11 01:49:28
@@ -26,7 +26,7 @@
 	TYPE_LAYOUT_FIELDS
 } mercury_data___base_type_layout_pred_0 = {
 	make_typelayout_for_all_tags(TYPELAYOUT_CONST_TAG, 
-		mkbody(TYPELAYOUT_PREDICATE_VALUE))
+		mkbody(MR_TYPELAYOUT_PREDICATE_VALUE))
 };
 
 	/* base_type_functors for `pred' */

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list