[m-dev.] for review: .agc fixes needed to compile runtime

Tyson Dowd trd at cs.mu.OZ.AU
Mon Nov 6 18:39:01 AEDT 2000


Hi,

This is for Zoltan -- much of this code is prototype code, but it should
fix the immediate problem that the .agc grades don't compile.
Then Zoltan can compile his fix for the code generator and .agc grades,
and I then keep debugging the prototype code.

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


Estimated hours taken: 8

Updates to the accurage garbage collector (including fixes to get it to
compile and also to use the MR_Long_Lval and MR_Short_Lval code).
A prototype of non-det stack tracing is also in this code.

runtime/mercury_accurate_gc.c:
runtime/mercury_accurate_gc.h:
runtime/mercury_agc_debug.c:
runtime/mercury_agc_debug.h:
	Updates to the GC necessary to get it to compile.

runtime/mercury_conf_param.h:
runtime/mercury_wrapper.c:
	Add an option to set the heap very small (useful for debugging).

runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
	Start adding checks for traversal range (things that aren't on
	the heap, but might contain pointers into the heap).
	Not all of the checks have been done yet.

runtime/mercury_layout_util.c:
runtime/mercury_layout_util.h:
	Fix a type -- MR_TypeInfo instead of MR_Word.

runtime/mercury_memory_handlers.c:
	Add get_curfr_from_context

runtime/mercury_stack_layout.h:
	Fix a comment.
	Define MR_SHORT_LVAL_NUMBER to find the number (e.g. register
	number or stack from) from a short lval. 

	

Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.8
diff -u -r1.8 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	2000/08/03 06:18:32	1.8
+++ runtime/mercury_accurate_gc.c	2000/11/06 03:03:50
@@ -20,10 +20,12 @@
 ** Function prototypes.
 */
 static	void	garbage_collect(MR_Code *saved_success, MR_Word *stack_pointer,
-			MR_Word *current_frame);
+			MR_Word *max_frame, MR_Word *current_frame);
 static	void	garbage_collect_roots(void);
-static	void	copy_value(MR_Live_Lval locn, MR_Word *type_info, bool copy_regs,
-			MR_Word *stack_pointer, MR_Word *current_frame);
+static	void	copy_long_value(MR_Long_Lval locn, MR_TypeInfo type_info, 
+		bool copy_regs, MR_Word *stack_pointer, MR_Word *current_frame);
+static	void	copy_short_value(MR_Short_Lval locn, MR_TypeInfo type_info,
+		bool copy_regs, MR_Word *stack_pointer, MR_Word *current_frame);
 
 /*
 ** Global variables (only used in this module, however).
@@ -58,12 +60,13 @@
 ** 	that the code will return to).
 */
 void
-MR_schedule_agc(MR_Code *pc_at_signal, MR_Word *sp_at_signal)
+MR_schedule_agc(MR_Code *pc_at_signal, MR_Word *sp_at_signal, 
+	MR_Word *curfr_at_signal)
 {
 	MR_Stack_Layout_Label		*layout;
 	const MR_Stack_Layout_Entry	*entry_layout;
-	MR_Lval_Type			type;
-	MR_Live_Lval			location;
+	MR_Long_Lval_Type		type;
+	MR_Long_Lval			location;
 	const char			*reason;
 	MR_Entry			*entry_label = NULL;
 	int				number;
@@ -92,6 +95,8 @@
 		(long) pc_at_signal, (long) pc_at_signal);
 	fprintf(stderr, "SP at signal: %ld (%lx)\n",
 		(long) sp_at_signal, (long) sp_at_signal);
+	fprintf(stderr, "curfr at signal: %ld (%lx)\n",
+		(long) curfr_at_signal, (long) curfr_at_signal);
 	fflush(NULL);
 #endif
 
@@ -147,12 +152,12 @@
 	}
 	gc_scheduled = TRUE;
 
+	location = entry_layout->MR_sle_succip_locn;
+	type = MR_LONG_LVAL_TYPE(location);
+	number = MR_LONG_LVAL_NUMBER(location);
 	if (MR_DETISM_DET_STACK(determinism)) {
-		location = entry_layout->MR_sle_succip_locn;
-		type = MR_LIVE_LVAL_TYPE(location);
-		number = MR_LIVE_LVAL_NUMBER(location);
 
-		if (type != MR_LVAL_TYPE_STACKVAR) {
+		if (type != MR_LONG_LVAL_TYPE_STACKVAR) {
 			fatal_error("can only handle stackvars");
 		}
 
@@ -162,29 +167,30 @@
 		saved_success_location = &MR_based_stackvar(sp_at_signal,
 			number);
 		saved_success = (MR_Code *) *saved_success_location;
-
-#ifdef MR_DEBUG_AGC_SCHEDULING
-		fprintf(stderr, "old succip: %ld (%lx) new: %ld (%lx)", 
-			(long) saved_success,
-			(long) saved_success,
-			(long) ENTRY(mercury__garbage_collect_0_0),
-			(long) ENTRY(mercury__garbage_collect_0_0));
-#endif
-
-		/*
-		** Replace the old succip with the address of the
-		** garbage collector.
-		*/
-		*saved_success_location = (MR_Word) mercury__garbage_collect_0_0;
-
 	} else {
 		/*
 		** XXX we don't support nondet stack frames yet.
-		*/
 		fatal_error("cannot schedule in nondet stack frame");
+		*/
+
+		saved_success_location = &MR_based_framevar(curfr_at_signal,
+			number);
+		saved_success = (Code *) *saved_success_location;
 	}
 
+#ifdef MR_DEBUG_AGC_SCHEDULING
+	fprintf(stderr, "old succip: %ld (%lx) new: %ld (%lx)\n", 
+		(long) saved_success, (long) saved_success,
+		(long) ENTRY(mercury__garbage_collect_0_0),
+		(long) ENTRY(mercury__garbage_collect_0_0));
+#endif
 
+	/*
+	** Replace the old succip with the address of the
+	** garbage collector.
+	*/
+	*saved_success_location = (Word) mercury__garbage_collect_0_0;
+
 #ifdef MR_DEBUG_AGC_SCHEDULING
 	fprintf(stderr, "Accurate GC scheduled.\n");
 #endif
@@ -205,7 +211,7 @@
 	gc_running = TRUE;
 
 	save_registers();
-	garbage_collect(saved_success, MR_sp, MR_curfr);
+	garbage_collect(saved_success, MR_sp, MR_maxfr, MR_curfr);
 	restore_registers();
 	gc_scheduled = FALSE;
 	gc_running = FALSE;
@@ -225,22 +231,24 @@
 **
 **  (We use 4 space tabs here because of the depth of indentation).
 */
-void
-garbage_collect(MR_Code *success_ip, MR_Word *stack_pointer, MR_Word *current_frame)
+static void
+garbage_collect(MR_Code *success_ip, MR_Word *stack_pointer, 
+		MR_Word *max_frame, MR_Word *current_frame)
 {
     MR_Internal                     *label, *first_label;
-    int                             i, var_count, count;
+    int                             i, count;
     const MR_Stack_Layout_Label     *internal_layout;
     const MR_Stack_Layout_Vars      *vars;
     MemoryZone                      *old_heap, *new_heap;
-    MR_Word                            *type_params;
+    MR_TypeInfoParams               type_params;
     bool                            succeeded;
     bool                            top_frame = TRUE;
     MR_MemoryList                   allocated_memory_cells = NULL;
-    MR_Word                            *old_hp;
+    MR_Word                            *old_hp, *new_hp;
     MR_Stack_Layout_Entry           *entry_layout;
-    MR_Word                            *first_stack_pointer, *first_current_frame;
-
+    MR_Word                            *first_stack_pointer,
+    					*first_current_frame,
+    					*first_max_frame;
 
     old_heap = MR_ENGINE(heap_zone);
     new_heap = MR_ENGINE(heap_zone2);
@@ -281,18 +289,30 @@
 
     label = MR_lookup_internal_by_addr(success_ip);
     internal_layout = label->i_layout;
-    entry_layout = internal_layout->MR_sll_entry;
 
 #ifdef MR_DEBUG_AGC_COLLECTION
     first_label = label;
     first_stack_pointer = stack_pointer;
     first_current_frame = current_frame;
+    first_max_frame = max_frame;
     fprintf(stderr, "BEFORE:\n");
     MR_agc_dump_stack_frames(first_label, old_heap, first_stack_pointer,
         first_current_frame);
+    MR_agc_dump_nondet_stack_frames(first_label, old_heap, first_stack_pointer,
+        first_current_frame, first_max_frame);
     MR_agc_dump_roots(root_list);
+
+      /* 
+      ** XXX the debug code seems to be messing up the heap pointer.
+      ** easier to reset it than debug the problem at the moment
+      */
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+    MR_virtual_hp = new_heap->min;
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
 #endif
 
+
+
     /*
     ** For each stack frame ...
     */
@@ -300,9 +320,16 @@
         MR_Stack_Walk_Step_Result       result;
         const char                      *problem;
         const MR_Stack_Layout_Label     *return_label_layout;
+	int				short_var_count, long_var_count;
+
+#ifdef MR_DEBUG_AGC_COLLECTION
+	printlabel((Code *) (Word) label->i_addr);
+        fflush(NULL);
+#endif
 
-        var_count = internal_layout->MR_sll_var_count;
         vars = &(internal_layout->MR_sll_var_info);
+        short_var_count = MR_short_desc_var_count(vars);
+        long_var_count = MR_long_desc_var_count(vars);
 
         /* Get the type parameters from the stack frame. */
 
@@ -313,59 +340,207 @@
         
         /* Copy each live variable */
 
-        for (i = 0; i < var_count; i++) {
-            MR_Stack_Layout_Var sl_var;
-            MR_Live_Type sl_type;
-            MR_Word *pseudo_type_info, *type_info;
-
-            sl_var = vars->MR_slvs_pairs[i];
-            if (MR_LIVE_TYPE_IS_VAR(sl_var.MR_slv_live_type)) {
-                pseudo_type_info = MR_LIVE_TYPE_GET_VAR_TYPE(
-                    sl_var.MR_slv_live_type);
-                type_info = MR_make_type_info(type_params, pseudo_type_info,
-                    &allocated_memory_cells);
-                copy_value(sl_var.MR_slv_locn, type_info, top_frame,
-                    stack_pointer, current_frame);
-                MR_deallocate(allocated_memory_cells);
-                allocated_memory_cells = NULL;
-            }
+        for (i = 0; i < long_var_count; i++) {
+            MR_Long_Lval locn;
+            MR_PseudoTypeInfo pseudo_type_info;
+            MR_TypeInfo type_info;
+
+	    locn = MR_long_desc_var_locn(vars, i);
+            pseudo_type_info = MR_var_pti(vars, i);
+
+            type_info = MR_make_type_info(type_params, pseudo_type_info,
+                &allocated_memory_cells);
+            copy_long_value(locn, type_info, top_frame,
+                stack_pointer, current_frame);
+            MR_deallocate(allocated_memory_cells);
+            allocated_memory_cells = NULL;
         }
 
+        for (; i < short_var_count; i++) {
+            MR_Short_Lval locn;
+            MR_PseudoTypeInfo pseudo_type_info;
+            MR_TypeInfo type_info;
+
+	    locn = MR_short_desc_var_locn(vars, i);
+            pseudo_type_info = MR_var_pti(vars, i);
+
+            type_info = MR_make_type_info(type_params, pseudo_type_info,
+                &allocated_memory_cells);
+            copy_short_value(locn, type_info, top_frame,
+                stack_pointer, current_frame);
+            MR_deallocate(allocated_memory_cells);
+            allocated_memory_cells = NULL;
+        }
+
         MR_free(type_params);
+
+        entry_layout = internal_layout->MR_sll_entry;
+
+	{
+		MR_Long_Lval            location;
+		MR_Long_Lval_Type            type;
+		int                     number;
+
+		location = entry_layout->MR_sle_succip_locn;
+		type = MR_LONG_LVAL_TYPE(location);
+		number = MR_LONG_LVAL_NUMBER(location);
+		if (type != MR_LONG_LVAL_TYPE_STACKVAR) {
+			fatal_error("can only handle stackvars");
+			}
+		
+		success_ip = (Code *) MR_based_stackvar(stack_pointer, number);
+		stack_pointer = stack_pointer - 
+			entry_layout->MR_sle_stack_slots;
+		label = MR_lookup_internal_by_addr(success_ip);
+	}
 
-        result = MR_stack_walk_step(entry_layout, &return_label_layout,
+/*
+	we should use this code eventually, but it requires a bit of
+	a redesign of the code around here.
+ 
+        result = MR_stack_walk_step(entry_layout, &internal_layout,
             (MR_Word **) &stack_pointer, &current_frame, &problem);
 
         if (result == STEP_ERROR_BEFORE || result == STEP_ERROR_AFTER) {
             fatal_error(problem);
         } 
+*/
 
-        if (return_label_layout == NULL) {
+        if (label == NULL) {
             break;
         }
-        entry_layout = return_label_layout->MR_sll_entry;
+	return_label_layout = label->i_layout;
         internal_layout = return_label_layout;
         top_frame = FALSE;
-    } while (TRUE); /* end for each stack frame... */
+    } while (internal_layout != NULL); /* end for each stack frame... */
+
+
+    /* 
+    ** New code for nondet.
+    ** XXX Will we need correct value of stack_pointer?
+    */ 
+    
+
+    while (max_frame > MR_nondet_stack_trace_bottom) {
+	bool registers_valid;
+	int frame_size;
 
+	registers_valid = (max_frame == current_frame);
+	frame_size = max_frame - MR_prevfr_slot(max_frame);
+
+	if (frame_size == MR_NONDET_TEMP_SIZE) {
+#ifdef MR_DEBUG_AGC_COLLECTION
+		printlabel(MR_redoip_slot(max_frame));
+		fflush(NULL);
+#endif
+	} else if (frame_size == MR_DET_TEMP_SIZE) {
+#ifdef MR_DEBUG_AGC_COLLECTION
+		printlabel(MR_redoip_slot(max_frame));
+		fflush(NULL);
+#endif
+	} else {
+#ifdef MR_DEBUG_AGC_COLLECTION
+		printlabel(MR_redoip_slot(max_frame));
+		fflush(NULL);
+#endif
+	}
+	label = MR_lookup_internal_by_addr(MR_redoip_slot(max_frame));
+
+	if (label != NULL) {
+		int short_var_count, long_var_count;
+
+		internal_layout = label->i_layout;
+		short_var_count = MR_short_desc_var_count(vars);
+		long_var_count = MR_long_desc_var_count(vars);
+		/* var_count = internal_layout->MR_sll_var_count; */
+		vars = &(internal_layout->MR_sll_var_info);
+
+		/* 
+		** XXX We must pass NULL since the registers have not
+		** been saved This is probably a bug; Tyson should look
+		** into it
+		*/
+		type_params = MR_materialize_typeinfos_base(vars,
+		    NULL, stack_pointer, MR_redofr_slot(max_frame));
+        
+		/* Copy each live variable */
+		for (i = 0; i < long_var_count; i++) {
+		    MR_Long_Lval locn;
+		    MR_PseudoTypeInfo pseudo_type_info;
+		    MR_TypeInfo type_info;
+
+		    locn = MR_long_desc_var_locn(vars, i);
+		    pseudo_type_info = MR_var_pti(vars, i);
+
+		    type_info = MR_make_type_info(type_params, pseudo_type_info,
+			&allocated_memory_cells);
+		    copy_long_value(locn, type_info, top_frame,
+			stack_pointer, current_frame);
+		    MR_deallocate(allocated_memory_cells);
+		    allocated_memory_cells = NULL;
+		}
+
+		for (; i < short_var_count; i++) {
+		    MR_Short_Lval locn;
+		    MR_PseudoTypeInfo pseudo_type_info;
+		    MR_TypeInfo type_info;
+
+		    locn = MR_short_desc_var_locn(vars, i);
+		    pseudo_type_info = MR_var_pti(vars, i);
+
+		    type_info = MR_make_type_info(type_params, pseudo_type_info,
+			&allocated_memory_cells);
+		    copy_short_value(locn, type_info, top_frame,
+			stack_pointer, current_frame);
+		    MR_deallocate(allocated_memory_cells);
+		    allocated_memory_cells = NULL;
+		}
+	}
+	max_frame = MR_prevfr_slot(max_frame);
+    }
+    
+
     /*
     ** Copy any roots that are not on the stack.
     */
     garbage_collect_roots();
 
 #ifdef MR_DEBUG_AGC_COLLECTION
+    fprintf(stderr, "Clearing old heap:\n");
+
+    {
+	Word *tmp_hp;
+
+	for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
+		*tmp_hp = 1;
+	}
+    }
+
     fprintf(stderr, "AFTER:\n");
 
+    	/* XXX save this, it appears to get clobbered */
+    new_hp = MR_virtual_hp;
+
     MR_agc_dump_stack_frames(first_label, new_heap, first_stack_pointer,
         first_current_frame);
     MR_agc_dump_roots(root_list);
+    MR_agc_dump_nondet_stack_frames(first_label, new_heap, first_stack_pointer,
+        first_current_frame, first_max_frame);
 
+    	/* XXX restore this, it appears to get clobbered */
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+    MR_virtual_hp = new_hp;
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+
     fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
         (long) ((char *) old_hp - (char *) old_heap->min),
         (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
     fprintf(stderr, "%ld bytes recovered\n", 
         (long) ((char *) old_hp - (char *) old_heap->min) -
         ((char *) MR_virtual_hp - (char *) new_heap->min));
+
+
 #endif
 
     /* Reset the redzone on the old heap */
@@ -378,7 +553,7 @@
 }
 
 /*
-** copy_value:
+** copy_long_value:
 ** 	Copies a value in a register or stack frame,
 ** 	replacing the original with the new copy.
 **
@@ -387,15 +562,15 @@
 ** 	forwarding pointers in the old copy of the data, if
 ** 	it is on the old heap).
 */
-void
-copy_value(MR_Live_Lval locn, MR_Word *type_info, bool copy_regs,
+static void
+copy_long_value(MR_Long_Lval locn, MR_TypeInfo type_info, bool copy_regs,
 	MR_Word *stack_pointer, MR_Word *current_frame)
 {
 	int	locn_num;
 
-	locn_num = (int) MR_LIVE_LVAL_NUMBER(locn);
-	switch (MR_LIVE_LVAL_TYPE(locn)) {
-		case MR_LVAL_TYPE_R:
+	locn_num = MR_LONG_LVAL_NUMBER(locn);
+	switch (MR_LONG_LVAL_TYPE(locn)) {
+		case MR_LONG_LVAL_TYPE_R:
 			if (copy_regs) {
 				virtual_reg(locn_num) = agc_deep_copy(
 					&virtual_reg(locn_num), type_info,
@@ -404,10 +579,10 @@
 			}
 			break;
 
-		case MR_LVAL_TYPE_F:
+		case MR_LONG_LVAL_TYPE_F:
 			break;
 
-		case MR_LVAL_TYPE_STACKVAR:
+		case MR_LONG_LVAL_TYPE_STACKVAR:
 			MR_based_stackvar(stack_pointer, locn_num) =
 				agc_deep_copy(&MR_based_stackvar(
 						stack_pointer,locn_num),
@@ -415,7 +590,7 @@
 					MR_ENGINE(heap_zone2->hardmax));
 			break;
 
-		case MR_LVAL_TYPE_FRAMEVAR:
+		case MR_LONG_LVAL_TYPE_FRAMEVAR:
 			MR_based_framevar(current_frame, locn_num) =
 				agc_deep_copy(
 				&MR_based_framevar(current_frame, locn_num),
@@ -424,40 +599,84 @@
 				MR_ENGINE(heap_zone2->hardmax));
 			break;
 
-		case MR_LVAL_TYPE_SUCCIP:
+		case MR_LONG_LVAL_TYPE_SUCCIP:
 			break;
 
-		case MR_LVAL_TYPE_MAXFR:
+		case MR_LONG_LVAL_TYPE_MAXFR:
 			break;
 
-		case MR_LVAL_TYPE_CURFR:
+		case MR_LONG_LVAL_TYPE_CURFR:
 			break;
 
-		case MR_LVAL_TYPE_HP:
+		case MR_LONG_LVAL_TYPE_HP:
 			break;
 
-		case MR_LVAL_TYPE_SP:
+		case MR_LONG_LVAL_TYPE_SP:
 			break;
 
-		case MR_LVAL_TYPE_INDIRECT:
+		case MR_LONG_LVAL_TYPE_INDIRECT:
 			/* XXX Tyson will have to write the code for this */
 			break;
 
-		case MR_LVAL_TYPE_UNKNOWN:
+		case MR_LONG_LVAL_TYPE_UNKNOWN:
 			break;
 
 		default:
+			fatal_error("Unknown MR_Long_Lval_Type in copy_long_value");
 			break;
 	}
 }
 
+static void
+copy_short_value(MR_Short_Lval locn, MR_TypeInfo type_info, bool copy_regs,
+	MR_Word *stack_pointer, MR_Word *current_frame)
+{
+	int	locn_num;
+
+	switch (MR_SHORT_LVAL_TYPE(locn)) {
+		case MR_SHORT_LVAL_TYPE_R:
+			if (copy_regs) {
+				locn_num = MR_SHORT_LVAL_NUMBER(locn);
+				virtual_reg(locn_num) = agc_deep_copy(
+					&virtual_reg(locn_num), type_info,
+					MR_ENGINE(heap_zone2->min),
+					MR_ENGINE(heap_zone2->hardmax));
+			}
+			break;
+
+		case MR_SHORT_LVAL_TYPE_STACKVAR:
+			locn_num = MR_SHORT_LVAL_NUMBER(locn);
+			MR_based_stackvar(stack_pointer, locn_num) =
+				agc_deep_copy(&MR_based_stackvar(
+						stack_pointer,locn_num),
+					type_info, MR_ENGINE(heap_zone2->min),
+					MR_ENGINE(heap_zone2->hardmax));
+			break;
+
+		case MR_SHORT_LVAL_TYPE_FRAMEVAR:
+			locn_num = MR_SHORT_LVAL_NUMBER(locn);
+			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;
+
+		default:
+			fatal_error("Unknown MR_Short_Lval_Type in copy_short_value");
+			break;
+	}
+}
+
+
 /*
 ** garbage_collect_roots:
 ** 
 ** 	Copies the extra roots.  The roots are overwritten
 ** 	with the new data.
 */
-void
+static void
 garbage_collect_roots(void) 
 {
 	MR_RootList current = root_list;
@@ -477,7 +696,7 @@
 ** 	Adds a new root to the extra roots.
 */
 void
-MR_agc_add_root(MR_Word *root_addr, MR_Word *type_info)
+MR_agc_add_root(MR_Word *root_addr, MR_TypeInfo type_info)
 {
 	MR_RootList node;
 
Index: runtime/mercury_accurate_gc.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_accurate_gc.h,v
retrieving revision 1.10
diff -u -r1.10 mercury_accurate_gc.h
--- runtime/mercury_accurate_gc.h	2000/08/03 06:18:33	1.10
+++ runtime/mercury_accurate_gc.h	2000/09/27 02:05:30
@@ -14,6 +14,7 @@
 */
 
 #include "mercury_types.h"
+#include "mercury_type_info.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -25,7 +26,8 @@
 ** 	continuation pointer with the address of the garbage collector
 ** 	routine.
 */
-extern	void	MR_schedule_agc(MR_Code *pc_at_signal, MR_Word *sp_at_signal);
+extern	void	MR_schedule_agc(MR_Code *pc_at_signal, MR_Word *sp_at_signal,
+			MR_Word *curfr_at_signal);
 
 /*
 ** Roots apart from the stacks are stored in this data structure.
@@ -39,7 +41,7 @@
 
 struct	MR_RootNode {
 	MR_Word *root;
-	MR_Word *type_info;
+	MR_TypeInfo type_info;
 	struct MR_RootNode* next;
 };
 
@@ -51,7 +53,7 @@
 ** 	described by type_info to the list of additional roots.
 */
 
-extern	void	MR_agc_add_root(MR_Word *root_addr, MR_Word *type_info);
+extern	void	MR_agc_add_root(MR_Word *root_addr, MR_TypeInfo type_info);
 
 /*---------------------------------------------------------------------------*/
 #endif /* not MERCURY_ACCURATE_GC_H */
Index: runtime/mercury_agc_debug.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_agc_debug.c,v
retrieving revision 1.11
diff -u -r1.11 mercury_agc_debug.c
--- runtime/mercury_agc_debug.c	2000/08/03 06:18:33	1.11
+++ runtime/mercury_agc_debug.c	2000/10/17 09:33:38
@@ -18,9 +18,15 @@
 /*
 ** Function prototypes.
 */
-static	void	dump_live_value(MR_Live_Lval locn, MemoryZone *heap_zone,
+static	void	dump_long_value(MR_Long_Lval locn, MemoryZone *heap_zone,
 			MR_Word * stack_pointer, MR_Word *current_frame,
 			bool do_regs);
+static	void	dump_short_value(MR_Short_Lval locn, MemoryZone *heap_zone,
+			Word * stack_pointer, Word *current_frame,
+			bool do_regs);
+static  void	dump_live_variables(const MR_Stack_Layout_Label *layout, 
+			MemoryZone *heap_zone, bool top_frame,
+			Word *stack_pointer, Word *current_frame);
 
 /*---------------------------------------------------------------------------*/
 
@@ -28,12 +34,13 @@
 void
 MR_agc_dump_roots(MR_RootList roots)
 {
+#ifdef NATIVE_GC
 	MR_Word	saved_regs[MAX_FAKE_REG];
 
 	fflush(NULL);
 	fprintf(stderr, "Dumping roots\n");
 
-#ifdef MR_DEBUG_AGC_PRINT_VARS
+  #ifdef MR_DEBUG_AGC_PRINT_VARS
 	while (roots != NULL) {
 
 
@@ -44,33 +51,121 @@
 		** the saved registers).
 		*/
 		restore_registers();
-		/* XXX this is unsafe -- should use MAX_FAKE_REG */
-		MR_copy_regs_to_saved_regs(MAX_REAL_REG + MR_NUM_SPECIAL_REG,
-			saved_regs);
+		MR_copy_regs_to_saved_regs(MAX_FAKE_REG, saved_regs);
 
 		MR_hp = MR_ENGINE(debug_heap_zone->min);
 		MR_virtual_hp = MR_ENGINE(debug_heap_zone->min);
 
 		fflush(NULL);
-		MR_write_variable((MR_Word) roots->type_info, *roots->root);
+		MR_write_variable(roots->type_info, *roots->root);
 		fflush(NULL);
 		fprintf(stderr, "\n");
 
-		/* XXX this is unsafe -- should use MAX_FAKE_REG */
-		MR_copy_saved_regs_to_regs(MAX_REAL_REG + MR_NUM_SPECIAL_REG,
-			saved_regs);
+		MR_copy_saved_regs_to_regs(MAX_FAKE_REG, saved_regs);
 		save_registers();
 		roots = roots->next;
 	}
-#endif
+  #endif /* MR_DEBUG_AGC_PRINT_VARS */
+#endif /* NATIVE_GC */
 }
 
 void
+MR_agc_dump_nondet_stack_frames(MR_Internal *label, MemoryZone *heap_zone,
+	Word *stack_pointer, Word *current_frame, Word *max_frame)
+{
+	Code *success_ip;
+	int frame_size;
+	bool registers_valid;
+
+	while (max_frame > MR_nondet_stack_trace_bottom) {
+
+		registers_valid = (max_frame == current_frame);
+
+		frame_size = max_frame - MR_prevfr_slot(max_frame);
+		if (frame_size == MR_NONDET_TEMP_SIZE) {
+			fprintf(stderr, "%p: nondet temp\n", max_frame);
+			fprintf(stderr, " redoip: ");
+			fflush(NULL);
+			printlabel(MR_redoip_slot(max_frame));
+			fflush(NULL);
+			fprintf(stderr, " redofr: %p\n",
+				MR_redofr_slot(max_frame));
+
+			label = MR_lookup_internal_by_addr(MR_redoip_slot(
+					max_frame));
+
+			if (label && label->i_layout) {
+				dump_live_variables(label->i_layout, heap_zone,
+					registers_valid, stack_pointer,
+					MR_redofr_slot(max_frame));
+			}
+
+		} else if (frame_size == MR_DET_TEMP_SIZE) {
+			fprintf(stderr, "%p: nondet temp\n", max_frame);
+			fprintf(stderr, " redoip: ");
+			fflush(NULL);
+			printlabel(MR_redoip_slot(max_frame));
+			fflush(NULL);
+			fprintf(stderr, " redofr: %p\n",
+				MR_redofr_slot(max_frame));
+			fprintf(stderr, " detfr:  %p\n",
+				MR_detfr_slot(max_frame));
+
+			label = MR_lookup_internal_by_addr(MR_redoip_slot(
+					max_frame));
+
+			if (label && label->i_layout) {
+				dump_live_variables(label->i_layout, heap_zone,
+					registers_valid,
+					MR_detfr_slot(max_frame), max_frame);
+				/* 
+				** XXX should max_frame above be
+				** MR_redoip_slot(max_frame) instead?
+				*/
+			}
+
+		} else {
+			fprintf(stderr, "%p: nondet ordinary\n", max_frame);
+			fprintf(stderr, " redoip: ");
+			fflush(NULL);
+			printlabel(MR_redoip_slot(max_frame));
+			fflush(NULL);
+			fprintf(stderr, " redofr: %p\n",
+				MR_redofr_slot(max_frame));
+			fprintf(stderr, " succip: ");
+			fflush(NULL);
+			printlabel(MR_succip_slot(max_frame));
+			fflush(NULL);
+			fprintf(stderr, " succfr: %p\n",
+				MR_succfr_slot(max_frame));
+		
+			label = MR_lookup_internal_by_addr(MR_redoip_slot(
+					max_frame));
+
+			if (label && label->i_layout) {
+				dump_live_variables(label->i_layout, heap_zone,
+					registers_valid, stack_pointer,
+					MR_redofr_slot(max_frame));
+				fprintf(stderr, " this label: %s\n", label->i_name);
+			}
+		}
+
+		max_frame = MR_prevfr_slot(max_frame);
+	}
+
+    	/* XXX Lookup the address (redoip?) and dump the variables */
+
+	fflush(NULL);
+}
+
+void
 MR_agc_dump_stack_frames(MR_Internal *label, MemoryZone *heap_zone,
 	MR_Word *stack_pointer, MR_Word *current_frame)
 {
+#ifdef NATIVE_GC
 	MR_Word saved_regs[MAX_FAKE_REG];
-	int i, var_count;
+	int i, short_var_count, long_var_count;
 	const MR_Stack_Layout_Vars *vars;
 	MR_Word *type_params, type_info, value;
 	MR_Stack_Layout_Entry *entry_layout;
@@ -96,86 +191,21 @@
 		if (success_ip == MR_stack_trace_bottom) {
 			break;
 		}
-
-		var_count = layout->MR_sll_var_count;
-		vars = &(layout->MR_sll_var_info);
-
-		/*
-		** XXX For the top stack frame, we should pass a pointer to
-		** a filled-in saved_regs instead of NULL. For other stack
-		** frames, passing NULL is fine, since output arguments are
-		** not live yet for any call except the top one.
-		*/
-		type_params = MR_materialize_typeinfos_base(vars,
-			NULL, stack_pointer, current_frame);
-
-		for (i = 0; i < var_count; i++) {
-			MR_Stack_Layout_Var sl_var;
-			MR_Live_Type sl_type;
 
-
-			fprintf(stderr, "%-12s\t", vars->MR_slvs_names[i]);
-
-			sl_var = vars->MR_slvs_pairs[i];
-	
-			dump_live_value(sl_var.MR_slv_locn, heap_zone,
-				stack_pointer, current_frame, top_frame);
-			fprintf(stderr, "\n");
-			fflush(NULL);
-		
-#ifdef MR_DEBUG_AGC_PRINT_VARS
-			/*
-			** Restore the registers, because we need to
-			** save them to a more permanent backing store
-			** (we are going to call Mercury soon, and we
-			** don't want it messing with the saved
-			** registers).
-			*/
-			restore_registers();
-			/* XXX this is unsafe -- should use MAX_FAKE_REG */
-			MR_copy_regs_to_saved_regs(MAX_REAL_REG +
-				MR_NUM_SPECIAL_REG, saved_regs);
-
-			MR_hp = MR_ENGINE(debug_heap_zone->min);
-			MR_virtual_hp = MR_ENGINE(debug_heap_zone->min);
-
-			/*
-			** XXX We must pass NULL here because the registers
-			** have not been saved. This is probably a bug;
-			** Tyson should look into it.
-			*/
-			if (MR_get_type_and_value_base(&sl_var, 
-					NULL, stack_pointer,
-					current_frame, type_params,
-					&type_info, &value)) {
-				printf("\t");
-				MR_write_variable(type_info, value);
-				printf("\n");
-			}
-
-			/* XXX this is unsafe -- should use MAX_FAKE_REG */
-			MR_copy_saved_regs_to_regs(MAX_REAL_REG +
-				MR_NUM_SPECIAL_REG, saved_regs);
-			save_registers();
-#endif	/* MR_DEBUG_AGC_PRINT_VARS */
-
-			fflush(NULL);
-
-		}
-		MR_free(type_params);
-
+		dump_live_variables(layout, heap_zone, top_frame,
+			stack_pointer, current_frame);
 		/* 
 		** Move to the next stack frame.
 		*/
 		{
-			MR_Live_Lval            location;
-			MR_Lval_Type            type;
+			MR_Long_Lval            location;
+			MR_Long_Lval_Type            type;
 			int                     number;
 
 			location = entry_layout->MR_sle_succip_locn;
-			type = MR_LIVE_LVAL_TYPE(location);
-			number = MR_LIVE_LVAL_NUMBER(location);
-			if (type != MR_LVAL_TYPE_STACKVAR) {
+			type = MR_LONG_LVAL_TYPE(location);
+			number = MR_LONG_LVAL_NUMBER(location);
+			if (type != MR_LONG_LVAL_TYPE_STACKVAR) {
 				fatal_error("can only handle stackvars");
 			}
 			                                
@@ -187,82 +217,263 @@
 		}
 
 		top_frame = FALSE;
-
 		layout = label->i_layout;
-		entry_layout = layout->MR_sll_entry;
+		
+		if (layout != NULL) {
+			entry_layout = layout->MR_sll_entry;
+		}
+	}
+#endif /* NATIVE_GC */
+}
+
+static void
+dump_live_variables(const MR_Stack_Layout_Label *layout, 
+		MemoryZone *heap_zone, bool top_frame,
+		Word *stack_pointer, Word *current_frame)
+{
+	int short_var_count, long_var_count, i;
+	const MR_Stack_Layout_Vars *vars;
+	MR_TypeInfo type_info;
+	MR_Word value;
+	MR_TypeInfoParams type_params;
+        MR_Word saved_regs[MAX_FAKE_REG];
+        MR_Word *current_regs;
+
+	vars = &(layout->MR_sll_var_info);
+	short_var_count = MR_short_desc_var_count(vars);
+	long_var_count = MR_long_desc_var_count(vars);
+
+	/*
+	** For the top stack frame, we should pass a pointer to
+	** a filled-in saved_regs instead of NULL. For other stack
+	** frames, passing NULL is fine, since output arguments are
+	** not live yet for any call except the top one.
+	*/
+	restore_registers();
+	MR_copy_regs_to_saved_regs(MAX_FAKE_REG, saved_regs);
+	if (top_frame) {
+		current_regs = saved_regs;
+	} else {
+		current_regs = NULL;
+	}
+	type_params = MR_materialize_typeinfos_base(vars,
+		current_regs, stack_pointer, current_frame);
+
+	for (i = 0; i < long_var_count; i++) {
+		fprintf(stderr, "%-12s\t", "");
+		MR_print_proc_id(stderr, layout->MR_sll_entry);
+
+		dump_long_value(MR_long_desc_var_locn(vars, i), heap_zone,
+			stack_pointer, current_frame, top_frame);
+		fprintf(stderr, "\n");
+		fflush(NULL);
+
+#ifdef MR_DEBUG_AGC_PRINT_VARS
+		/*
+		** Call Mercury but use the debugging heap. 
+		*/
+
+		MR_hp = MR_ENGINE(debug_heap_zone->min);
+		MR_virtual_hp = MR_ENGINE(debug_heap_zone->min);
+
+		if (MR_get_type_and_value_base(vars, i,
+				current_regs, stack_pointer,
+				current_frame, type_params,
+				&type_info, &value)) {
+			printf("\t");
+			MR_write_variable(type_info, value);
+			printf("\n");
+		}
+
+#endif	/* MR_DEBUG_AGC_PRINT_VARS */
+
+		fflush(NULL);
 	}
+
+	for (; i < short_var_count; i++) {
+		fprintf(stderr, "%-12s\t", "");
+		MR_print_proc_id(stderr, layout->MR_sll_entry);
+
+		dump_short_value(MR_short_desc_var_locn(vars, i), heap_zone,
+			stack_pointer, current_frame, top_frame);
+		fprintf(stderr, "\n");
+		fflush(NULL);
+		
+#ifdef MR_DEBUG_AGC_PRINT_VARS
+		/*
+		** Call Mercury but use the debugging heap. 
+		*/
+
+		MR_hp = MR_ENGINE(debug_heap_zone->min);
+		MR_virtual_hp = MR_ENGINE(debug_heap_zone->min);
+
+		if (MR_get_type_and_value_base(vars, i,
+				current_regs, stack_pointer,
+				current_frame, type_params,
+				&type_info, &value)) {
+			printf("\t");
+			MR_write_variable(type_info, value);
+			printf("\n");
+		}
+
+#endif	/* MR_DEBUG_AGC_PRINT_VARS */
+
+		fflush(NULL);
+	}
+
+
+	MR_copy_saved_regs_to_regs(MAX_FAKE_REG, saved_regs);
+	save_registers();
+	free(type_params);
 }
 
 static void
-dump_live_value(MR_Live_Lval locn, MemoryZone *heap_zone, MR_Word *stack_pointer,
-	MR_Word *current_frame, bool do_regs)
+dump_long_value(MR_Long_Lval locn, MemoryZone *heap_zone, 
+	MR_Word *stack_pointer, MR_Word *current_frame, bool do_regs)
 {
+#ifdef NATIVE_GC
 	int	locn_num;
 	MR_Word	value = 0;
 	int	difference;
 	bool 	have_value = FALSE;
 
-	locn_num = (int) MR_LIVE_LVAL_NUMBER(locn);
-	switch (MR_LIVE_LVAL_TYPE(locn)) {
-		case MR_LVAL_TYPE_R:
+	locn_num = MR_LONG_LVAL_NUMBER(locn);
+	switch (MR_LONG_LVAL_TYPE(locn)) {
+		case MR_LONG_LVAL_TYPE_R:
 			if (do_regs) {
 				value = virtual_reg(locn_num);
 				have_value = TRUE;
 				fprintf(stderr, "r%d\t", locn_num);
+			} else {
+				fprintf(stderr, "r%d (invalid)\t", locn_num);
 			}
 			break;
 
-		case MR_LVAL_TYPE_F:
+		case MR_LONG_LVAL_TYPE_F:
 			fprintf(stderr, "f%d\t", locn_num);
 			break;
 
-		case MR_LVAL_TYPE_STACKVAR:
+		case MR_LONG_LVAL_TYPE_STACKVAR:
 			value = MR_based_stackvar(stack_pointer, locn_num);
 			have_value = TRUE;
 			fprintf(stderr, "stackvar%d", locn_num);
 			break;
 
-		case MR_LVAL_TYPE_FRAMEVAR:
+		case MR_LONG_LVAL_TYPE_FRAMEVAR:
 			value = MR_based_framevar(current_frame, locn_num);
 			have_value = TRUE;
 			fprintf(stderr, "framevar%d", locn_num);
 			break;
 
-		case MR_LVAL_TYPE_SUCCIP:
+		case MR_LONG_LVAL_TYPE_SUCCIP:
 			fprintf(stderr, "succip");
 			break;
 
-		case MR_LVAL_TYPE_MAXFR:
+		case MR_LONG_LVAL_TYPE_MAXFR:
 			fprintf(stderr, "maxfr");
 			break;
 
-		case MR_LVAL_TYPE_CURFR:
+		case MR_LONG_LVAL_TYPE_CURFR:
 			fprintf(stderr, "curfr");
 			break;
 
-		case MR_LVAL_TYPE_HP:
+		case MR_LONG_LVAL_TYPE_HP:
 			fprintf(stderr, "hp");
 			break;
 
-		case MR_LVAL_TYPE_SP:
+		case MR_LONG_LVAL_TYPE_SP:
 			fprintf(stderr, "sp");
 			break;
 
-		case MR_LVAL_TYPE_INDIRECT:
+		case MR_LONG_LVAL_TYPE_INDIRECT:
 			fprintf(stderr, "offset %d from ",
-				MR_LIVE_LVAL_INDIRECT_OFFSET(locn_num));
+				MR_LONG_LVAL_INDIRECT_OFFSET(locn_num));
 			/* XXX Tyson will have to complete this */
 			/* based on what he wants this function to do */
 
-		case MR_LVAL_TYPE_UNKNOWN:
+		case MR_LONG_LVAL_TYPE_UNKNOWN:
 			fprintf(stderr, "unknown");
 			break;
 
 		default:
-			fprintf(stderr, "DEFAULT");
+			fprintf(stderr, "LONG DEFAULT");
 			break;
 	}
 	if (have_value) {
+		if (value >= (Word) heap_zone->min && 
+				value < (Word) heap_zone->hardmax) {
+			difference = (Word *) value - (Word *) heap_zone->min;
+			fprintf(stderr, "\thp[%d]\t(%lx)", difference,
+				(long) value);
+		} else {
+			fprintf(stderr, "\t       \t(%lx)", (long) value);
+		}
+	}
+#endif /* NATIVE_GC */
+}
+
+static void
+dump_short_value(MR_Short_Lval locn, MemoryZone *heap_zone, Word *stack_pointer,
+	Word *current_frame, bool do_regs)
+{
+#ifdef NATIVE_GC
+	int	locn_num;
+	Word	value = 0;
+	int	difference;
+	bool 	have_value = FALSE;
+
+	locn_num = (int) locn >> MR_SHORT_LVAL_TAGBITS;
+	switch (MR_SHORT_LVAL_TYPE(locn)) {
+		case MR_SHORT_LVAL_TYPE_R:
+			if (do_regs) {
+				value = virtual_reg(locn_num);
+				have_value = TRUE;
+				fprintf(stderr, "r%d\t", locn_num);
+			} else {
+				fprintf(stderr, "r%d (invalid)\t", locn_num);
+			}
+			break;
+
+		case MR_SHORT_LVAL_TYPE_STACKVAR:
+			value = MR_based_stackvar(stack_pointer, locn_num);
+			have_value = TRUE;
+			fprintf(stderr, "stackvar%d", locn_num);
+			break;
+
+		case MR_SHORT_LVAL_TYPE_FRAMEVAR:
+			value = MR_based_framevar(current_frame, locn_num);
+			have_value = TRUE;
+			fprintf(stderr, "framevar%d", locn_num);
+			break;
+
+		case MR_SHORT_LVAL_TYPE_SPECIAL:
+			switch (locn_num) {
+				case MR_LONG_LVAL_TYPE_SUCCIP:
+					fprintf(stderr, "succip");
+				break;
+				case MR_LONG_LVAL_TYPE_MAXFR:
+					fprintf(stderr, "succip");
+				break;
+				case MR_LONG_LVAL_TYPE_CURFR:
+					fprintf(stderr, "curfr");
+				break;
+				case MR_LONG_LVAL_TYPE_HP:
+					fprintf(stderr, "hp");
+				break;
+				case MR_LONG_LVAL_TYPE_SP:
+					fprintf(stderr, "sp");
+				break;
+				default:
+					fprintf(stderr, "SPECIAL DEFAULT");
+				break;
+			}
+			break;
+
+		default:
+			fprintf(stderr, "SHORT DEFAULT");
+			break;
+	}
+	if (have_value) {
 		if (value >= (MR_Word) heap_zone->min && 
 				value < (MR_Word) heap_zone->hardmax) {
 			difference = (MR_Word *) value - (MR_Word *) heap_zone->min;
@@ -272,7 +483,7 @@
 			fprintf(stderr, "\t       \t(%lx)", (long) value);
 		}
 	}
+#endif /* NATIVE_GC */
 }
 
 #endif /* NATIVE_GC */
-
Index: runtime/mercury_agc_debug.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_agc_debug.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_agc_debug.h
--- runtime/mercury_agc_debug.h	2000/08/03 06:18:34	1.3
+++ runtime/mercury_agc_debug.h	2000/09/27 02:05:30
@@ -21,7 +21,7 @@
 
 /*
 ** MR_agc_dump_stack_frames:
-** 	Dump the stack, writing all information available about each
+** 	Dump the det stack, writing all information available about each
 ** 	stack frame.
 ** 	
 ** 	label is the topmost label on the stack, heap_zone is the zone
@@ -30,6 +30,18 @@
 
 extern	void	MR_agc_dump_stack_frames(MR_Internal *label, MemoryZone
 		*heap_zone, MR_Word *stack_pointer, MR_Word *current_frame);
+
+/*
+** MR_agc_dump_nondet_stack_frames:
+** 	Dump the nondet stack, writing all information available about each
+** 	stack frame.
+** 	
+** 	label is the topmost label on the stack, heap_zone is the zone
+** 	which the data is stored upon. 
+*/
+extern	void	MR_agc_dump_nondet_stack_frames(MR_Internal *label,
+			MemoryZone *heap_zone, Word *stack_pointer,
+			Word *current_frame, Word *max_frame);
 
 /*
 ** MR_agc_dump_roots:
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.39
diff -u -r1.39 mercury_conf_param.h
--- runtime/mercury_conf_param.h	2000/08/03 06:18:36	1.39
+++ runtime/mercury_conf_param.h	2000/09/27 02:05:30
@@ -148,7 +148,10 @@
 **	Display the values of live variables during accurate garbage
 **	collection.
 **
-** MR_DEBUG_AGC
+** MR_DEBUG_AGC_SMALL_HEAP
+**	Use a small heap to trigger garbage collection more often.
+**
+** MR_DEBUG_AGC_ALL
 ** 	Turn on all debugging information for accurate garbage
 ** 	collection.  (Equivalent to all MR_DEBUG_AGC_* macros above).
 **
@@ -160,11 +163,12 @@
 ** 	code handling exceptions.
 */
 
-#if MR_DEBUG_AGC
+#if MR_DEBUG_AGC_ALL
   #define MR_DEBUG_AGC_SCHEDULING
   #define MR_DEBUG_AGC_COLLECTION
   #define MR_DEBUG_AGC_FORWARDING
   #define MR_DEBUG_AGC_PRINT_VARS
+  #define MR_DEBUG_AGC_SMALL_HEAP
 #endif
 
 /*
Index: runtime/mercury_deep_copy.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_deep_copy.c,v
retrieving revision 1.19
diff -u -r1.19 mercury_deep_copy.c
--- runtime/mercury_deep_copy.c	2000/08/03 06:18:38	1.19
+++ runtime/mercury_deep_copy.c	2000/11/06 03:06:33
@@ -27,6 +27,9 @@
 #define in_range(X)	(lower_limit == NULL || \
 				((X) >= lower_limit && (X) <= upper_limit))
 
+#undef  in_traverse_range(X)
+#define in_traverse_range(X)	(FALSE)
+
 #undef	maybeconst
 #define	maybeconst	const
 
@@ -54,10 +57,16 @@
 /*
 ** agc_deep_copy(): see mercury_deep_copy.h for documentation.
 */
+#ifdef NATIVE_GC
 
 #undef  in_range
 #define in_range(X)	((X) >= lower_limit && (X) <= upper_limit)
 
+#undef  in_traverse_range(X)
+#define in_traverse_range(X)	\
+		((X) >= MR_ENGINE(solutions_heap_zone)->min && \
+			(X) <= MR_ENGINE(solutions_heap_zone)->hardmax)
+
 #undef	maybeconst
 #define	maybeconst
 
@@ -93,6 +102,8 @@
 		FORWARD_DEBUG_MSG("not on this heap: %lx\n", (long) Data);
 
 #include "mercury_deep_copy_body.h"
+
+#endif
 
 /*---------------------------------------------------------------------------*/
 
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.27
diff -u -r1.27 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	2000/10/16 01:33:56	1.27
+++ runtime/mercury_deep_copy_body.h	2000/10/17 04:31:20
@@ -397,6 +397,8 @@
             **
             ** Their type-infos have a pointer to type_ctor_info for
             ** pred/0, arity, and then argument typeinfos.
+	    **
+	    ** XXX pred needs to handle traversals.
             */
             if (in_range(data_value)) {
                 MR_Unsigned            args, i;
@@ -409,6 +411,9 @@
                 closure_layout = old_closure->MR_closure_layout;
                 args = old_closure->MR_closure_num_hidden_args;
 
+                /* get number of curried arguments */
+                args = data_value[0];
+
                 /* create new closure */
                 incr_saved_hp(LVALUE_CAST(MR_Word, new_closure), args + 3);
 
@@ -438,6 +443,8 @@
 
                 new_data = (MR_Word) new_closure;
                 leave_forwarding_pointer(data_ptr, new_data);
+	    } else if (in_range(data_value)) {
+		fatal_error("sorry, unimplemented: traversal of closures");
             } else {
                 new_data = data;
                 found_forwarding_pointer(data);
@@ -514,6 +521,15 @@
                         (MR_TypeInfo *) &data_value[UNIV_OFFSET_FOR_TYPEINFO],
                         lower_limit, upper_limit);
                 leave_forwarding_pointer(data_ptr, new_data);
+	    } else if (in_traverse_range(data_value)) {
+		copy(&data_value[UNIV_OFFSET_FOR_DATA],
+			(const MR_TypeInfo) 
+			    data_value[UNIV_OFFSET_FOR_TYPEINFO],
+			lower_limit, upper_limit);
+	        copy_type_info(
+			(MR_TypeInfo *) &data_value[UNIV_OFFSET_FOR_TYPEINFO],
+			lower_limit, upper_limit);
+		new_data = data;
             } else {
                 new_data = data;
                 found_forwarding_pointer(data);
@@ -550,6 +566,19 @@
                 }
                 new_data = (MR_Word) new_array;
                 leave_forwarding_pointer(data_ptr, new_data);
+            } else if (in_traverse_range(data_value)) {
+                MR_ArrayType *old_array;
+                Integer array_size;
+
+                old_array = (MR_ArrayType *) data_value;
+                array_size = old_array->size;
+                for (i = 0; i < array_size; i++) {
+                    copy_arg(NULL, 
+			&old_array->elements[i], NULL, 
+                        MR_TYPEINFO_GET_FIRST_ORDER_ARG_VECTOR(type_info),
+                        (const MR_PseudoTypeInfo) 1, lower_limit, upper_limit);
+                }
+                new_data = data;
             } else {
                 new_data = data;
                 found_forwarding_pointer(data);
@@ -571,7 +600,7 @@
             data_tag = MR_tag(data);
             data_value = (MR_Word *) MR_body(data, data_tag);
 
-            if (in_range(data_value)) {
+            if (in_range(data_value) || in_traverse_range(data_value)) {
                 /*
                 ** This error occurs if we try to copy() a
                 ** `c_pointer' type that points to memory allocated
@@ -653,8 +682,8 @@
 }
 
 static MR_TypeInfo
-copy_type_info(maybeconst MR_TypeInfo *type_info_ptr, const MR_Word *lower_limit,
-    const MR_Word *upper_limit)
+copy_type_info(maybeconst MR_TypeInfo *type_info_ptr,
+	const MR_Word *lower_limit, const MR_Word *upper_limit)
 {
     MR_TypeInfo type_info = *type_info_ptr;
 
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.19
diff -u -r1.19 mercury_layout_util.c
--- runtime/mercury_layout_util.c	2000/10/16 01:33:58	1.19
+++ runtime/mercury_layout_util.c	2000/11/06 07:23:55
@@ -399,7 +399,7 @@
 }
 
 void
-MR_write_variable(MR_Word type_info, MR_Word value)
+MR_write_variable(MR_TypeInfo type_info, MR_Word value)
 {
 	MR_Word	stdout_stream;
 
Index: runtime/mercury_layout_util.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_layout_util.h,v
retrieving revision 1.11
diff -u -r1.11 mercury_layout_util.h
--- runtime/mercury_layout_util.h	2000/08/03 06:18:48	1.11
+++ runtime/mercury_layout_util.h	2000/09/27 02:05:33
@@ -135,6 +135,6 @@
 **	and it may also clobber the real registers.
 */
 
-extern	void	MR_write_variable(MR_Word type_info, MR_Word value);
+extern	void	MR_write_variable(MR_TypeInfo type_info, MR_Word value);
 
 #endif	/* MERCURY_LAYOUT_UTIL_H */
Index: runtime/mercury_memory_handlers.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_memory_handlers.c,v
retrieving revision 1.16
diff -u -r1.16 mercury_memory_handlers.c
--- runtime/mercury_memory_handlers.c	2000/09/12 19:51:06	1.16
+++ runtime/mercury_memory_handlers.c	2000/11/06 07:25:26
@@ -130,6 +130,7 @@
 static	char	*explain_context(void *context);
 static	MR_Code	*get_pc_from_context(void *the_context);
 static	MR_Word	*get_sp_from_context(void *the_context);
+static	MR_Word	*get_curfr_from_context(void *the_context);
 
 #define STDERR 2
 
@@ -245,7 +246,8 @@
 	}
   #ifdef NATIVE_GC
 	MR_schedule_agc(get_pc_from_context(context),
-		get_sp_from_context(context));
+		get_sp_from_context(context),
+		get_curfr_from_context(context));
   #endif
 	return TRUE;
     } else {
@@ -942,6 +944,37 @@
 #endif /* !NATIVE_GC */
 
 	return sp_at_signal;
+}
+
+/*
+** get_sp_from_context:
+** 	Given the signal context, return the Mercury register "MR_sp" at
+** 	the time of the signal, if available.  If it is unavailable,
+** 	return NULL.
+**
+** XXX We only define this function in accurate gc grades for the moment,
+** because it's unlikely to compile everywhere.  It relies on
+** MR_real_reg_number_sp being defined, which is the name/number of the
+** machine register that is used for MR_sp.
+** Need to fix this so it works when the register is in a fake reg too.
+*/
+static MR_Word *
+get_curfr_from_context(void *the_context)
+{
+	MR_Word *curfr_at_signal;
+	
+	/*
+	** XXX this is implementation dependent, need a better way
+	** to do register accesses at signals.
+	**
+	** It's in mr8 or mr9 which is in the fake regs on some architectures,
+	** and is a machine register on others.
+	** So don't run the garbage collector on those archs.
+	*/
+
+	curfr_at_signal = MR_curfr;
+
+	return curfr_at_signal;
 }
 
 static void 
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.41
diff -u -r1.41 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h	2000/10/16 03:31:01	1.41
+++ runtime/mercury_stack_layout.h	2000/10/17 04:31:24
@@ -77,9 +77,9 @@
 ** lval.
 **
 ** What kind of location an MR_Long_Lval refers to is encoded using
-** a low tag with MR_LONG_LVAL_TAGBITS bits; the type MR_Lval_Type describes
-** the different tag values. The interpretation of the rest of the word
-** depends on the location type:
+** a low tag with MR_LONG_LVAL_TAGBITS bits; the type MR_Long_Lval_Type
+** describes the different tag values. The interpretation of the rest of
+** the word depends on the location type:
 **
 **  Locn		Tag	Rest
 **  r(Num)		 0	Num (register number)
@@ -186,6 +186,9 @@
 #define MR_SHORT_LVAL_TYPE(Locn) 					\
 	((MR_Short_Lval_Type)						\
 		(((MR_Word) Locn) & ((1 << MR_SHORT_LVAL_TAGBITS) - 1)))
+
+#define MR_SHORT_LVAL_NUMBER(Locn) 					\
+	((int) ((MR_Word) Locn) >> MR_SHORT_LVAL_TAGBITS)
 
 #define	MR_SHORT_LVAL_STACKVAR(n)					\
 	((MR_Short_Lval) (((n) << MR_SHORT_LVAL_TAGBITS)		\
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.76
diff -u -r1.76 mercury_wrapper.c
--- runtime/mercury_wrapper.c	2000/11/05 12:04:18	1.76
+++ runtime/mercury_wrapper.c	2000/11/06 07:30:33
@@ -50,8 +50,8 @@
 
 /* size of data areas (including redzones), in kilobytes */
 /* (but we later multiply by 1024 to convert to bytes) */
-#ifdef MR_DEBUG_AGC
-  size_t	heap_size =		  128;
+#ifdef MR_DEBUG_AGC_SMALL_HEAP
+  size_t	heap_size =      	   52;
 #else
   size_t	heap_size =		 4096;
 #endif
@@ -66,11 +66,7 @@
 
 /* size of the redzones at the end of data areas, in kilobytes */
 /* (but we later multiply by 1024 to convert to bytes) */
-#ifdef NATIVE_GC
-  size_t	heap_zone_size =	   96;
-#else
-  size_t	heap_zone_size =	   16;
-#endif
+size_t		heap_zone_size =	   16;
 size_t		detstack_zone_size =	   16;
 size_t		nondstack_zone_size =	   16;
 size_t		solutions_heap_zone_size = 16;


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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