[m-rev.] for post-commit review: compatibility with gcc 3.4

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jul 9 16:37:57 AEST 2004


For post-commit review by Fergus. I'd like him to look at the handling
in mercury_regs.h of the abstract machine registers involved in trailing
and the management of the heap in solutions, if nothing else.

Zoltan.

Get Mercury to work with gcc 3.4. This required fixing several problems.

One problem that caused errors is that gcc 3.4 is smart enough to figure out
that in LLDS grades with gcc gotos, the C functions containing our code are
not referred to, and so it optimizes them away. The fix is to ensure that
mercury_<module>_init is defined always to call those functions, even if
the macro that usually controls this, MR_MAY_NEED_INITIALIZATION, is not
defined. The mercury_<module>_init won't be called from the init_modules
function in the program's _init.c file, so there is no impact on initialization
time, but gcc doesn't know this when compiling a module's .c file, so
it doesn't optimize away the code we need. The cost of this change is thus
only a small amount of code space. It is worth paying this cost even with
compilers other than gcc 3.4 for simplicity. Actually, this size increase seems
to be slightly smaller than the size reduction due to the better optimization
capabilities of gcc 3.4 compared to gcc 3.2.2.

A second problem is that gcc 3.4 warns about casts in lvalues being a
deprecated feature. This gave lots of warnings, since we used to define
several Mercury abstract machine registers, including MR_succip, MR_hp, MR_sp,
MR_maxfr and MR_curfr using lvalue casts. The fix is to have two macros
for each of these abstract machine registers, one of type MR_Word that you can
assign to (e.g. MR_sp_word), and one of the original type that is of the right
type but not an lvalue (e.g. MR_sp). The lvalue itself can't be made the right
type, because MR_sp isn't a variable in its own right, but possibly defined
to be a machine register. The machine register could made the right type,
but only at the cost of a lot of complexity.

This problem doesn't apply to the special-purpose Mercury abstract machine
registers that can't be allocated to machine registers. Instead of #defining
these to slots in MR_fake_reg, we make them global variables of the natural
type. This should also make it easier to debug code using these registers.
We treat these global variables as if they were machine registers in that
MR_save_registers copies values from these global variables to slots reserved
for them in the MR_fake_reg array, to allow code to loop over all Mercury
abstract machine registers. These saved slots must of course be of type
MR_Word, so we again need two macros to refer to them, a lvalue of type
MR_Word and an rvalue with the right type.

A third problem is that gcc 3.4 warns about conditionals in lvalues being a
deprecated feature. This gave a few warnings, since we used to define
MR_virtual_reg and MR_saved_reg using lvalues using conditionals. The fix
is to have one macro (MR_virtual_reg_value) for use in rvalues and a
separate macro which uses an if-then-else instead of a conditional
expression (MR_virtual_reg_assign), for assignments.

A fourth problem is that gcc 3.4 warns about comma operators in lvalues
being a deprecated feature. This gave warnings in the few places where
we refer to MR_r(N) for values of N that can map to fake registers directly,
since in those cases we preceded the reference to the fake_reg array with
a range check of the array index. The fix to this is to move the test to
compile time for compiler-generated code. Hand-written code never refers
to MR_r(N) for these values, and is very unlikely to do so in the future;
instead, it refers to the underlying fake_reg array directly, since that way
it doesn't have to worry about which fake registers have their own MR_rN macro
and which don't. Therefore no check mechanism for hand-written code is
necessary. This change mean that changing the number of MR_rN registers
now requires change to the compiler as well as to the runtime system.

A fifth problem is that gcc 3.4 by default assumes -fstrict-aliasing at -O2.
Since we cast between integers and pointers of different types all the time,
and changing that is not practical, at least in the short term, we need to
disable -fstrict-aliasing when we enable -O2.

NEWS:
	Note that Mercury now works with gcc 3.4.

configure.in:
scripts/mgnuc.in:
	Detect whether the compiler supports -fstrict-aliasing, and if so,
	whether it assumes it by default with -O2. If the answer is yes to
	both, make mgnuc specify -fno-strict-aliasing when it specifies -O2.
	By including it in CFLAGS_FOR_OPT, which gets put into Mercury.config,
	we also get -f-no-strict-aliasing when mmc invokes the C compiler
	directly.

compiler/llds_out.m:
	Don't generate #ifdef MR_MAY_NEED_INITIALIZATION around the definitions
	and calls to the bunch functions, which call the functions we don't
	want the C compiler to optimize away.

	Generate the newly required lvalues on the left sides of assignments.

	We still have code to generate LVALUE_CASTs in some cases, but I don't
	think those cases ever arise.

	Add a compile-time check of register numbers. Ideally, the code
	generator should use stack slots instead of registers beyond the max
	number, but I don't recall us ever bumping into this limit by accident.

compiler/fact_table.m:
	Use the newly required lvalues on the left sides of assignments
	in some hand-written C code included in generated .c files.

runtime/mercury_regs.h:
	Make the changes described above to fix the second, third and fourth
	problems. We still use comma operators in lvalues when counting
	references to registers, but it is OK to require anyone who wants
	to enable this feature to use a compiler version that supports comma
	operators in lvalues or to ignore the warnings.

	Use the same mapping from Mercury abstract machine registers to
	the register count array as to the MR_fake_reg array.

	Have this mapping depend as little as possible on whether we need a
	real machine register to store MR_engine base, even if it costs a
	wasted slot in MR_fake_reg.

	Fix an old inconsistency: treat the Mercury abstract machine registers
	used for trailing the same way as the other Mercury abstract machine
	registers, by making MR_save_registers/MR_restore_registers copy them
	to and from their global variable homes.

	Document the requirement for the match between the runtime's and the
	compiler's notions of the maximum MR_rN register number. This
	requirement makes it harder for users to increase the number of
	virtual registers, but as far as I know noone has wanted to do this.

	Change the names of some of the macros to make them clearer.

	Reorder some parts of this file, and add some documentation, also
	in the interest of clarity.

runtime/mercury_regorder.h:
	Delete this file after moving its contents, in much modified form,
	to mercury_regs.h. mercury_regorder.h was always logically part of
	mercury_regs.h, but was separated out to make it easier to change
	the mapping from Mercury abstract machine registers to machine
	registers. However, the cost of incompatibility caused by any such
	changes would be much greater that any likely performance benefit.

runtime/Mmakefile:
	Remove the reference to mercury_regorder.h.

runtime/mercury_regs.[ch]:
runtime/mercury_memory_zones.[ch]:
	Move some functionality dealing with registers from
	mercury_memory_zones to mercury_regs, since it belongs there.

runtime/mercury_regs.[ch]:
	Add a function to make it easiler to debug changes to map from
	Mercury abstract machine to MR_fake_reg slots.

runtime/mercury_regs.[ch]:
runtime/mercury_wrapper.c:
	Move the code to print counts of register uses from mercury_wrapper.c
	to mercury_regs.c.

	Make mercury_wrapper.c call the debugging function in mercury_regs.c
	if -X is specified in MERCURY_OPTIONS.

runtime/mercury_bootstrap.h:
	Move the old MR_saved_reg and MR_virtual_reg macros from mercury_regs.h
	to mercury_bootstrap.h to prevent their accidental use. Since
	they shouldn't be used by user code, move them to the section
	that is not enabled by default.

runtime/mercury_stacks.[ch]:
	Add _word versions of the macros for stack slots, for the same reason
	why we need them for Mercury abstract machine registers, and use them.

	Add global variables for the Mercury abstract machine registers
	for the gen, cut and pneg stacks.

runtime/mercury_heap.h:
	Change the macros for allocating memory to assign to MR_hp_word instead
	of MR_hp.

runtime/mercury_string.h:
	Change the macros for allocating strings to accomodate the updates to
	mercury_heap.h. Also change the expected type of the target to make it
	MR_String instead of MR_ConstString, since the latter requires casts in
	the caller.

runtime/mercury_trail.h:
runtime/mercury_types.h:
	Move the definition of the type MR_TrailEntry from mercury_trail.h
	to mercury_types.h, since it is now used in mercury_regs.h.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_calls.h:
runtime/mercury_context.[ch]:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_engine.[ch]:
runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_layout_util.c:
runtime/mercury_make_type_info_body.h:
runtime/mercury_minimal_model.c:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
runtime/mercury_stack_layout.h:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
runtime/mercury_wrapper.c:
	Conform to the changes in the rest of the runtime.

	In some cases, fix inconsistencies in indentation.

runtime/mercury_stack_trace.c:
	Add some conditionally compiled debugging code controlled by the macro
	MR_ADDR_DEBUG, to help debug some problems with stored stack pointers.

runtime/mercury_grade.h:
	Increment the binary compatibility version number. This is needed to
	avoid potential problems when a Mercury module and the debugger are
	compiled with different versions of the macros in mercury_regs.h.

library/exception.m:
	Update the code that assigns to abstract machine registers.

library/array.m:
library/construct.m:
library/dir.m:
library/io.m:
library/string.m:
	Conform to the new definitions of allocation macros.

library/time.m:
	Delete an unnecessary #include.

trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_util.c:
	Conform to the changes in the rest of the runtime.

tests/hard_coded/qual_test_is_imported.m:
tests/hard_coded/aditi_private_builtin.m:
	Remove an unnecessary import to avoid a warning.

tools/makebatch:
	Add an option --save-stage2-on-error, that saves the stage2 directory
	if a bootcheck fails.

scripts/ml.in:
	Make ml more robust in the face of garbage files.

cvs server: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.335
diff -u -b -r1.335 NEWS
--- NEWS	21 Jun 2004 09:16:11 -0000	1.335
+++ NEWS	7 Jul 2004 06:59:42 -0000
@@ -35,7 +35,7 @@
 * The dir module now handles Microsoft Windows pathnames correctly.
 
 Portability improvements:
-* Nothing yet.
+* We have made the implementation compatible with gcc 3.4.
 
 Changes to the Mercury debugger:
 * Users can now limit the output from stack traces.
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.394
diff -u -b -r1.394 configure.in
--- configure.in	30 Jun 2004 07:04:33 -0000	1.394
+++ configure.in	7 Jul 2004 06:59:43 -0000
@@ -533,6 +533,68 @@
 esac
 
 #-----------------------------------------------------------------------------#
+
+cat > conftest.c << EOF
+	struct MR_TypeInfo_Almost_Struct {
+		int	MR_almost;
+	};
+
+	struct MR_TypeCtorInfo_Struct {
+		int	MR_tci1;
+		int	MR_tci2;
+	};
+
+	typedef struct MR_TypeCtorInfo_Struct		*MR_TypeCtorInfo;
+	typedef const struct MR_TypeInfo_Almost_Struct	*MR_TypeInfo;
+
+	struct MR_FA_TypeInfo_Struct1 {
+		MR_TypeCtorInfo	MR_ti_type_ctor_info;
+		MR_TypeInfo	MR_ti_fixed_arity_arg_typeinfos[1];
+	};
+
+	extern  const struct MR_FA_TypeInfo_Struct1	ML_type_ctor_info;
+
+	MR_TypeInfo
+	f(void)
+	{
+		MR_TypeInfo	x;
+
+		x = (MR_TypeInfo) &ML_type_ctor_info;
+		return x;
+	}
+EOF
+
+AC_MSG_CHECKING(whether we can use -fno-strict-aliasing)
+if $CC -O2 -Wall -fno-strict-aliasing -c conftest.c \
+	</dev/null >&AC_FD_CC 2>&1
+then
+	AC_MSG_RESULT(yes)
+
+	AC_MSG_CHECKING(whether we need to use -fno-strict-aliasing)
+	$CC -O2 -Wall -fno-strict-aliasing -c conftest.c \
+		</dev/null >&conftest1.out
+	$CC -O2 -Wall -c conftest.c \
+		</dev/null >&conftest2.out
+	# get the lines that exist only in conftest2.out
+	comm -13 conftest1.out conftest2.out > conftest.2only
+
+	if test -s conftest.2only
+	then
+		AC_MSG_RESULT(yes)
+		CFLAGS_FOR_NO_STRICT_ALIASING="-fno-strict-aliasing"
+	else
+		AC_MSG_RESULT(no)
+		CFLAGS_FOR_NO_STRICT_ALIASING=""
+	fi
+else
+	AC_MSG_RESULT(no)
+	CFLAGS_FOR_NO_STRICT_ALIASING=
+fi
+
+AC_SUBST(CFLAGS_FOR_NO_STRICT_ALIASING)
+rm -f conftest*
+
+#-----------------------------------------------------------------------------#
 # Make sure we search /usr/local/include and /usr/local/lib for
 # header files and libraries.  GNU C normally searches /usr/local/include
 # by default, but (inconsistently) on some systems, such as Solaris,
@@ -1866,6 +1928,7 @@
 esac
 AC_SUBST(CFLAGS_FOR_REGS)
 AC_SUBST(CFLAGS_FOR_GOTOS)
+
 #-----------------------------------------------------------------------------#
 AC_MSG_CHECKING(whether we can use gcc labels)
 
@@ -3161,6 +3224,8 @@
 	MCFLAGS_FOR_CC=
 	;;
 esac
+
+CFLAGS_FOR_OPT="$CFLAGS_FOR_OPT $CFLAGS_FOR_NO_STRICT_ALIASING"
 
 AC_SUBST(CFLAGS_FOR_ANSI)
 AC_SUBST(CFLAGS_FOR_WARNINGS)
cvs server: Diffing analysis
cvs server: Diffing bindist
cvs server: Diffing boehm_gc
cvs server: Diffing boehm_gc/Mac_files
cvs server: Diffing boehm_gc/cord
cvs server: Diffing boehm_gc/cord/private
cvs server: Diffing boehm_gc/doc
cvs server: Diffing boehm_gc/include
cvs server: Diffing boehm_gc/include/private
cvs server: Diffing boehm_gc/tests
cvs server: Diffing browser
cvs server: Diffing bytecode
cvs server: Diffing compiler
Index: compiler/fact_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/fact_table.m,v
retrieving revision 1.55
diff -u -b -r1.55 fact_table.m
--- compiler/fact_table.m	30 Jun 2004 02:47:59 -0000	1.55
+++ compiler/fact_table.m	7 Jul 2004 06:59:43 -0000
@@ -2430,8 +2430,8 @@
 	** then jump to the code where the work is actually done.
 	*/
 
-	MR_maxfr = MR_prevfr_slot(MR_curfr);
-	MR_curfr = MR_succfr_slot(MR_curfr);
+	MR_maxfr_word = MR_prevfr_slot_word(MR_curfr);
+	MR_curfr_word = MR_succfr_slot_word(MR_curfr);
 	{
 		MR_declare_entry(%s);
 		MR_GOTO(MR_ENTRY(%s));
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.235
diff -u -b -r1.235 llds_out.m
--- compiler/llds_out.m	9 Jun 2004 07:56:11 -0000	1.235
+++ compiler/llds_out.m	7 Jul 2004 06:59:43 -0000
@@ -492,10 +492,8 @@
 	( MaybeInitModuleBunches = [] ->
 		true
 	;
-		io__write_string("#ifdef MR_MAY_NEED_INITIALIZATION\n\n", !IO),
 		output_init_bunch_defs(MaybeInitModuleBunches, ModuleName,
-			"maybe", 0, SplitFiles, !IO),
-		io__write_string("#endif\n\n", !IO)
+			"maybe", 0, SplitFiles, !IO)
 	),
 
 	io__write_string("/* suppress gcc -Wmissing-decls warnings */\n", !IO),
@@ -531,10 +529,8 @@
 	( MaybeInitModuleBunches = [] ->
 		true
 	;
-		io__write_string("\n#ifdef MR_MAY_NEED_INITIALIZATION\n", !IO),
 		output_init_bunch_calls(MaybeInitModuleBunches, ModuleName,
-			"maybe", 0, !IO),
-		io__write_string("#endif\n\n", !IO)
+			"maybe", 0, !IO)
 	),
 
 	output_c_data_init_list(Datas, !IO),
@@ -1871,9 +1867,8 @@
 
 output_instruction(assign(Lval, Rval), _, !IO) :-
 	io__write_string("\t", !IO),
-	output_lval(Lval, !IO),
+	output_lval_for_assign(Lval, Type, !IO),
 	io__write_string(" = ", !IO),
-	llds__lval_type(Lval, Type),
 	output_rval_as_type(Rval, Type, !IO),
 	io__write_string(";\n", !IO).
 
@@ -4674,6 +4669,95 @@
 	output_rval(Rval),
 	io__write_string(")").
 
+:- pred output_lval_for_assign(lval::in, llds_type::out, io::di, io::uo) is det.
+
+output_lval_for_assign(reg(RegType, Num), word, !IO) :-
+	require(unify(RegType, r), "output_lval_for_assign: float reg"),
+	output_reg(RegType, Num, !IO).
+output_lval_for_assign(stackvar(N), word, !IO) :-
+	( N < 0 ->
+		error("stack var out of range")
+	;
+		true
+	),
+	io__write_string("MR_sv(", !IO),
+	io__write_int(N, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(framevar(N), word, !IO) :-
+	( N =< 0 ->
+		error("frame var out of range")
+	;
+		true
+	),
+	io__write_string("MR_fv(", !IO),
+	io__write_int(N, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(succip, word, !IO) :-
+	io__write_string("MR_succip_word", !IO).
+output_lval_for_assign(sp, word, !IO) :-
+	io__write_string("MR_sp_word", !IO).
+output_lval_for_assign(hp, word, !IO) :-
+	io__write_string("MR_hp_word", !IO).
+output_lval_for_assign(maxfr, word, !IO) :-
+	io__write_string("MR_maxfr_word", !IO).
+output_lval_for_assign(curfr, word, !IO) :-
+	io__write_string("MR_curfr_word", !IO).
+output_lval_for_assign(succfr(Rval), word, !IO) :-
+	io__write_string("MR_succfr_slot_word(", !IO),
+	output_rval(Rval, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(prevfr(Rval), word, !IO) :-
+	io__write_string("MR_prevfr_slot_word(", !IO),
+	output_rval(Rval, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(redofr(Rval), word, !IO) :-
+	io__write_string("MR_redofr_slot_word(", !IO),
+	output_rval(Rval, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(redoip(Rval), word, !IO) :-
+	io__write_string("MR_redoip_slot_word(", !IO),
+	output_rval(Rval, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(succip(Rval), word, !IO) :-
+	io__write_string("MR_succip_slot_word(", !IO),
+	output_rval(Rval, !IO),
+	io__write_string(")", !IO).
+output_lval_for_assign(field(MaybeTag, Rval, FieldNumRval), word, !IO) :-
+	(
+		MaybeTag = yes(Tag),
+		io__write_string("MR_tfield(", !IO),
+		io__write_int(Tag, !IO),
+		io__write_string(", ", !IO)
+	;
+		MaybeTag = no,
+		io__write_string("MR_mask_field(", !IO)
+	),
+	output_rval(Rval, !IO),
+	io__write_string(", ", !IO),
+	( FieldNumRval = const(int_const(FieldNum)) ->
+		% Avoid emitting the (MR_Integer) cast.
+		io__write_int(FieldNum, !IO)
+	;
+		output_rval(FieldNumRval, !IO)
+	),
+	io__write_string(")", !IO).
+output_lval_for_assign(lvar(_), _, !IO) :-
+	error("output_lval_for_assign: lvar").
+output_lval_for_assign(temp(RegType, Num), Type, !IO) :-
+	(
+		RegType = r,
+		Type = word,
+		io__write_string("MR_tempr", !IO),
+		io__write_int(Num, !IO)
+	;
+		RegType = f,
+		Type = float,
+		io__write_string("MR_tempf", !IO),
+		io__write_int(Num, !IO)
+	).
+output_lval_for_assign(mem_ref(_), _, !IO) :-
+	error("output_lval_for_assign: mem_ref").
+
 %-----------------------------------------------------------------------------%
 
 :- pred output_set_line_num(prog_context::in, io::di, io::uo) is det.
@@ -4724,16 +4808,24 @@
 	string__append(Tmp, ")", Description).
 
 llds_out__reg_to_string(r, N, Description) :-
-	( N > 32 ->
+	( N =< max_real_r_reg ->
+		Template = "MR_r%d"
+	; N =< max_virtual_r_reg ->
 		Template = "MR_r(%d)"
 	;
-		Template = "MR_r%d"
+		error("llds_out__reg_to_string: register number too large")
 	),
 	string__format(Template, [i(N)], Description).
 llds_out__reg_to_string(f, N, Description) :-
 	string__int_to_string(N, N_String),
 	string__append("MR_f(", N_String, Tmp),
 	string__append(Tmp, ")", Description).
+
+:- func max_real_r_reg = int.
+:- func max_virtual_r_reg = int.
+
+max_real_r_reg = 32.
+max_virtual_r_reg = 1024.
 
 %-----------------------------------------------------------------------------%
 
cvs server: Diffing compiler/notes
cvs server: Diffing debian
cvs server: Diffing deep_profiler
cvs server: Diffing deep_profiler/notes
cvs server: Diffing doc
cvs server: Diffing extras
cvs server: Diffing extras/aditi
cvs server: Diffing extras/cgi
cvs server: Diffing extras/complex_numbers
cvs server: Diffing extras/complex_numbers/samples
cvs server: Diffing extras/complex_numbers/tests
cvs server: Diffing extras/concurrency
cvs server: Diffing extras/curs
cvs server: Diffing extras/curs/samples
cvs server: Diffing extras/curses
cvs server: Diffing extras/curses/sample
cvs server: Diffing extras/dynamic_linking
cvs server: Diffing extras/error
cvs server: Diffing extras/graphics
cvs server: Diffing extras/graphics/mercury_glut
cvs server: Diffing extras/graphics/mercury_opengl
cvs server: Diffing extras/graphics/mercury_tcltk
cvs server: Diffing extras/graphics/samples
cvs server: Diffing extras/graphics/samples/calc
cvs server: Diffing extras/graphics/samples/gears
cvs server: Diffing extras/graphics/samples/maze
cvs server: Diffing extras/graphics/samples/pent
cvs server: Diffing extras/lazy_evaluation
cvs server: Diffing extras/lex
cvs server: Diffing extras/lex/samples
cvs server: Diffing extras/lex/tests
cvs server: Diffing extras/logged_output
cvs server: Diffing extras/moose
cvs server: Diffing extras/moose/samples
cvs server: Diffing extras/moose/tests
cvs server: Diffing extras/morphine
cvs server: Diffing extras/morphine/non-regression-tests
cvs server: Diffing extras/morphine/scripts
cvs server: Diffing extras/morphine/source
cvs server: Diffing extras/odbc
cvs server: Diffing extras/posix
cvs server: Diffing extras/quickcheck
cvs server: Diffing extras/quickcheck/tutes
cvs server: Diffing extras/references
cvs server: Diffing extras/references/samples
cvs server: Diffing extras/references/tests
cvs server: Diffing extras/stream
cvs server: Diffing extras/trailed_update
cvs server: Diffing extras/trailed_update/samples
cvs server: Diffing extras/trailed_update/tests
cvs server: Diffing extras/xml
cvs server: Diffing extras/xml/samples
cvs server: Diffing java
cvs server: Diffing java/runtime
cvs server: Diffing library
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.130
diff -u -b -r1.130 array.m
--- library/array.m	15 Mar 2004 23:49:28 -0000	1.130
+++ library/array.m	7 Jul 2004 06:59:44 -0000
@@ -509,8 +509,12 @@
 */
 
 #define	ML_alloc_array(newarray, arraysize, proclabel)	\
-	MR_offset_incr_hp_msg(MR_LVALUE_CAST(MR_Word, (newarray)), \
-		0, (arraysize), proclabel, ""array:array/1"")
+	do {								\
+		MR_Word	newarray_word;					\
+		MR_offset_incr_hp_msg(newarray_word, 0, (arraysize),	\
+			proclabel, ""array:array/1"");			\
+		(newarray) = (MR_ArrayPtr) newarray_word;		\
+	} while (0)
 ").
 
 :- pragma foreign_decl("C", "
Index: library/construct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/construct.m,v
retrieving revision 1.16
diff -u -b -r1.16 construct.m
--- library/construct.m	15 Mar 2004 23:49:31 -0000	1.16
+++ library/construct.m	7 Jul 2004 06:59:44 -0000
@@ -143,8 +143,7 @@
         */
 
     if (success) {
-        MR_make_aligned_string(FunctorName, (MR_String) (MR_Word)
-            construct_info.functor_name);
+        MR_make_aligned_string(FunctorName, construct_info.functor_name);
         arity = construct_info.arity;
         Arity = arity;
 
@@ -241,8 +240,7 @@
         */
 
     if (success) {
-        MR_make_aligned_string(FunctorName, (MR_String) (MR_Word)
-            construct_info.functor_name);
+        MR_make_aligned_string(FunctorName, construct_info.functor_name);
         arity = construct_info.arity;
         Arity = arity;
 
Index: library/dir.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/dir.m,v
retrieving revision 1.23
diff -u -b -r1.23 dir.m
--- library/dir.m	15 Mar 2004 06:50:14 -0000	1.23
+++ library/dir.m	7 Jul 2004 06:59:44 -0000
@@ -1622,8 +1622,7 @@
 	IO = IO0;
 	if (FindNextFile(Dir, &file_data)) {
 		Status = 1;
-		MR_make_aligned_string_copy(FileName,
-			file_data.cFileName);
+		MR_make_aligned_string_copy(FileName, file_data.cFileName);
 	} else {
 		Error = GetLastError();
 		Status = (Error == ERROR_NO_MORE_FILES ? -1 : 0);
@@ -1641,8 +1640,7 @@
 		FileName = NULL;
 		Status = (Error == 0 ? -1 : 0);
 	} else {
-		MR_make_aligned_string_copy(FileName,
-			dir_entry->d_name);
+		MR_make_aligned_string_copy(FileName, dir_entry->d_name);
 		Error = 0;
 		Status = 1;
 	}
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.92
diff -u -b -r1.92 exception.m
--- library/exception.m	1 Jul 2004 04:50:23 -0000	1.92
+++ library/exception.m	7 Jul 2004 06:59:44 -0000
@@ -1659,8 +1659,8 @@
 			return NULL;
 		}
 		MR_restore_transient_registers();
-		MR_sp = base_sp;
-		MR_curfr = base_curfr;
+		MR_sp_word = (MR_Word) base_sp;
+		MR_curfr_word = (MR_Word) base_curfr;
 		MR_save_transient_registers();
 	}
 	return NULL;
@@ -2126,9 +2126,9 @@
 	while (MR_redoip_slot(MR_curfr)
 			!= MR_ENTRY(MR_exception_handler_do_fail))
 	{
-		MR_curfr = MR_succfr_slot(MR_curfr);
+		MR_curfr_word = MR_succfr_slot_word(MR_curfr);
 		if (MR_curfr < MR_CONTEXT(MR_ctxt_nondetstack_zone)->min) {
-			MR_Word *save_succip;
+			MR_Word save_succip_word;
 			/*
 			** There was no exception handler.
 			**
@@ -2150,12 +2150,12 @@
 			** sufficient since the Mercury code may clobber the
 			** copy of MR_succip in the fake_reg.
 			*/
-			MR_curfr = orig_curfr;
+			MR_curfr_word = (MR_Word) orig_curfr;
 			fflush(stdout);
-			save_succip = MR_succip;
+			save_succip_word = MR_succip_word;
 			MR_save_registers();
 			ML_report_uncaught_exception(exception);
-			MR_succip = save_succip;
+			MR_succip_word = save_succip_word;
 			MR_trace_report(stderr);
 			if (exception_event_number > 0) {
 				if (MR_standardize_event_details) {
@@ -2203,12 +2203,12 @@
 	** This ensures that when we return from this procedure,
 	** we will return to the caller of `builtin_catch'.
 	*/
-	MR_succip = MR_succip_slot(MR_curfr);
+	MR_succip_word = MR_succip_slot_word(MR_curfr);
 
 	/*
 	** Reset the det stack.
 	*/
-	MR_sp = MR_EXCEPTION_STRUCT->MR_excp_stack_ptr;
+	MR_sp_word = (MR_Word) MR_EXCEPTION_STRUCT->MR_excp_stack_ptr;
 
 #ifdef MR_USE_TRAIL
 	/*
@@ -2307,8 +2307,8 @@
 	** and reset the nondet stack top.  (This must be done last,
 	** since it invalidates all the framevars.)
 	*/
-	MR_maxfr = MR_prevfr_slot(MR_curfr);
-	MR_curfr = MR_succfr_slot(MR_curfr);
+	MR_maxfr_word = MR_prevfr_slot_word(MR_curfr);
+	MR_curfr_word = MR_succfr_slot_word(MR_curfr);
 
 	/*
 	** Now longjmp to the catch, which will invoke the handler
@@ -2360,7 +2360,7 @@
 			MR_ENTRY(mercury__exception__builtin_throw_1_0));
 	}
 	MR_incr_sp_push_msg(1, ""pred builtin_throw/1"");
-	MR_stackvar(1) = (MR_Word) MR_succip;
+	MR_stackvar(1) = MR_succip_word;
 	MR_call(MR_ENTRY(mercury__do_call_closure_compact),
 		MR_LABEL(mercury__exception__builtin_throw_1_0_i1),
 		MR_ENTRY(mercury__exception__builtin_throw_1_0));
@@ -2371,7 +2371,7 @@
 	/* we've just returned from mercury__do_call_closure_compact */
 	MR_r2 = MR_r1;
 	MR_r1 = MR_TRUE;
-	MR_succip = (MR_Code *) MR_stackvar(1);
+	MR_succip_word = MR_stackvar(1);
 	MR_decr_sp_pop_msg(1);
 	MR_proceed(); /* return to the caller of `builtin_catch' */
 
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.322
diff -u -b -r1.322 io.m
--- library/io.m	26 Mar 2004 10:13:44 -0000	1.322
+++ library/io.m	7 Jul 2004 06:59:44 -0000
@@ -1743,9 +1743,11 @@
 		}
 	}
 	if (Res == 0) {
-		MR_offset_incr_hp_atomic_msg(MR_LVALUE_CAST(MR_Word, RetString),
+		MR_Word	ret_string_word;
+		MR_offset_incr_hp_atomic_msg(ret_string_word,
 			0, ML_IO_BYTES_TO_WORDS((i + 1) * sizeof(MR_Char)),
 			MR_PROC_LABEL, ""string:string/0"");
+		RetString = (MR_String) ret_string_word;
 		memcpy(RetString, read_buffer, i * sizeof(MR_Char));
 		RetString[i] = '\\0';
 	} else {
@@ -5463,7 +5465,7 @@
 {
 	va_list args;
 	char message[5000];
-	MR_ConstString message_as_mercury_string;
+	MR_String	message_as_mercury_string;
 
 	/* the `mf' parameter is currently not used */
 
@@ -5478,7 +5480,7 @@
 	MR_save_registers(); /* for MR_hp */
 
 	/* call some Mercury code to throw the exception */
-	ML_throw_io_error((MR_String) message_as_mercury_string);
+	ML_throw_io_error(message_as_mercury_string);
 }
 
 ").
@@ -7288,17 +7290,7 @@
 	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
 	if (MR_progname) {
-		/*
-		** The silly casting below is needed to avoid
-		** a gcc warning about casting away const.
-		** PrognameOut is of type `MR_String' (char *);
-		** it should be of type `MR_ConstString' (const char *),
-		** but fixing that requires a fair bit of work
-		** on the compiler.
-		*/
-		MR_make_aligned_string(
-			MR_LVALUE_CAST(MR_ConstString, PrognameOut),
-			MR_progname);
+		MR_make_aligned_string(PrognameOut, MR_progname);
 	} else {
 		PrognameOut = DefaultProgname;
 	}
@@ -7776,12 +7768,14 @@
 	*/
 	int	len, err, fd, num_tries;
 	char	countstr[256];
+	MR_Word	filename_word;
 
 	len = strlen(Dir) + 1 + 5 + 3 + 1 + 3 + 1;
 		/* Dir + / + Prefix + counter_high + . + counter_low + \\0 */
-	MR_offset_incr_hp_atomic_msg(MR_LVALUE_CAST(MR_Word, FileName), 0,
+	MR_offset_incr_hp_atomic_msg(filename_word, 0,
 		(len + sizeof(MR_Word)) / sizeof(MR_Word),
 		MR_PROC_LABEL, ""string:string/0"");
+	FileName = (MR_String) filename_word;
 	if (ML_io_tempnam_counter == 0) {
 		ML_io_tempnam_counter = getpid();
 	}
@@ -8270,8 +8264,7 @@
 		Status = 0;
 	} else {
 		buffer[num_chars] = '\\0';
-		MR_make_aligned_string_copy(TargetFileName,
-			buffer);
+		MR_make_aligned_string_copy(TargetFileName, buffer);
 		Status = 1;
 	}
 #else /* !MR_HAVE_READLINK */
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.217
diff -u -b -r1.217 string.m
--- library/string.m	1 Jul 2004 01:33:24 -0000	1.217
+++ library/string.m	7 Jul 2004 06:59:44 -0000
@@ -1812,9 +1812,9 @@
 	int_length_modifer = (LengthModifier::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "{
-	MR_make_aligned_string(LengthModifier,
-		(MR_String) (MR_Word) MR_INTEGER_LENGTH_MODIFIER);
+	MR_make_aligned_string(LengthModifier, MR_INTEGER_LENGTH_MODIFIER);
 }").
+
 % This predicate is only called if using_sprintf/0, so we produce an error
 % by default.
 int_length_modifer = _ :- error("string.int_length_modifer/0 not defined").
@@ -3477,11 +3477,10 @@
 "{
 	MR_Integer len;
 	MR_Word tmp;
+
 	if (Start < 0) Start = 0;
 	if (Count <= 0) {
-		MR_make_aligned_string(
-			MR_LVALUE_CAST(MR_ConstString, SubString),
-			"""");
+		MR_make_aligned_string(SubString, """");
 	} else {
 		len = strlen(Str);
 		if (Start > len) Start = len;
@@ -3497,6 +3496,7 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "{
 	MR_Integer len;
+
 	MR_allocate_aligned_string_msg(SubString, Count, MR_PROC_LABEL);
 	memcpy(SubString, Str + Start, Count);
 	SubString[Count] = '\\0';
@@ -3520,9 +3520,9 @@
 "{
 	MR_Integer len;
 	MR_Word tmp;
+
 	if (Count <= 0) {
-		MR_make_aligned_string(MR_LVALUE_CAST(MR_ConstString, Left),
-			"""");
+		MR_make_aligned_string(Left, """");
 		Right = Str;
 	} else {
 		len = strlen(Str);
Index: library/time.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.44
diff -u -b -r1.44 time.m
--- library/time.m	15 Mar 2004 23:49:35 -0000	1.44
+++ library/time.m	7 Jul 2004 06:59:44 -0000
@@ -191,7 +191,6 @@
 
 	#define MR_update_io(r_src, r_dest)	((r_dest) = (r_src))
 
-	#include ""mercury_string.h"" /* for MR_make_aligned_string_copy() */
 	#include ""mercury_timing.h"" /* for MR_CLOCK_TICKS_PER_SECOND */
 ").
 
cvs server: Diffing profiler
cvs server: Diffing robdd
cvs server: Diffing runtime
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.111
diff -u -b -r1.111 Mmakefile
--- runtime/Mmakefile	31 May 2004 04:13:04 -0000	1.111
+++ runtime/Mmakefile	7 Jul 2004 06:59:44 -0000
@@ -71,7 +71,6 @@
 			mercury_prof_time.h	\
 			mercury_profiling_builtin.h	\
 			mercury_reg_workarounds.h	\
-			mercury_regorder.h	\
 			mercury_regs.h		\
 			mercury_runtime_util.h	\
 			mercury_signal.h	\
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.37
diff -u -b -r1.37 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	6 Jan 2004 16:49:42 -0000	1.37
+++ runtime/mercury_accurate_gc.c	7 Jul 2004 06:59:44 -0000
@@ -489,13 +489,12 @@
     label_layout = label->i_layout;
 
     if (MR_agc_debug) {
-
         fprintf(stderr, "BEFORE:\n");
 
         MR_agc_dump_stack_frames(label, old_heap, stack_pointer,
                 current_frame);
-        MR_agc_dump_nondet_stack_frames(label, old_heap,
-                stack_pointer, current_frame, max_frame);
+        MR_agc_dump_nondet_stack_frames(label, old_heap, stack_pointer,
+            current_frame, max_frame);
         MR_agc_dump_roots(root_list);
 
         /* 
@@ -618,7 +617,7 @@
     ** and we don't need to traverse that).
     */
     MR_bool registers_live = is_first_frame;
-    if (callee_model_semi && !MR_virtual_reg(1)) {
+    if (callee_model_semi && !MR_virtual_reg_value(1)) {
         registers_live = MR_FALSE;
     }
     return registers_live;
@@ -636,22 +635,20 @@
     
 static void
 traverse_nondet_stack(const MR_Label_Layout *first_frame_layout,
-        MR_bool callee_model_semi,
-        MR_Word *stack_pointer, MR_Word *max_frame, MR_Word *current_frame)
+    MR_bool callee_model_semi, MR_Word *stack_pointer,
+    MR_Word *max_frame, MR_Word *current_frame)
 {
     struct first_frame_data data;
     data.first_frame_layout = first_frame_layout;
     data.first_frame_curfr = current_frame;
     data.first_frame_callee_model_semi = callee_model_semi;
     MR_traverse_nondet_stack_from_layout(max_frame, first_frame_layout,
-            stack_pointer, current_frame, traverse_nondet_frame,
-            &data);
+        stack_pointer, current_frame, traverse_nondet_frame, &data);
 }
 
 static void
-traverse_nondet_frame(void *user_data,
-        const MR_Label_Layout *label_layout, MR_Word *stack_pointer,
-        MR_Word *current_frame)
+traverse_nondet_frame(void *user_data, const MR_Label_Layout *label_layout,
+    MR_Word *stack_pointer, MR_Word *current_frame)
 {   
     MR_bool is_first_frame;
     MR_bool registers_live;
@@ -688,8 +685,10 @@
     MR_TypeInfo                     type_info;
 
     if (MR_agc_debug) {
-        /* XXX we used to print the label name here, but that's
-           not available anymore */
+        /*
+        ** XXX we used to print the label name here, but that's
+        ** not available anymore
+        */
         printf("traverse_frame: traversing frame with label layout %p\n",
             (const void *) label_layout);
         fflush(NULL);
@@ -714,8 +713,7 @@
     **      indicator is false and hence the registers are not live.
     */
     type_params = MR_materialize_type_params_base(label_layout,
-            (registers_live ? MR_fake_reg : NULL),
-            stack_pointer, current_frame);
+        (registers_live ? MR_fake_reg : NULL), stack_pointer, current_frame);
     
     /* Copy each live variable */
 
@@ -762,15 +760,16 @@
         MR_bool registers_live, MR_Word *stack_pointer, MR_Word *current_frame)
 {
     int locn_num;
+    MR_Word copy;
 
     locn_num = MR_LONG_LVAL_NUMBER(locn);
     switch (MR_LONG_LVAL_TYPE(locn)) {
     case MR_LONG_LVAL_TYPE_R:
         if (registers_live) {
-            MR_virtual_reg(locn_num) = MR_agc_deep_copy(
-                    MR_virtual_reg(locn_num), type_info,
+            copy = MR_agc_deep_copy(MR_virtual_reg_value(locn_num), type_info,
                     MR_ENGINE(MR_eng_heap_zone2->min),
                     MR_ENGINE(MR_eng_heap_zone2->hardmax));
+            MR_virtual_reg_assign(locn_num, copy);
         }
         break;
 
@@ -833,47 +832,40 @@
 
 static void
 copy_short_value(MR_Short_Lval locn, MR_TypeInfo type_info,
-                 MR_bool registers_live, MR_Word *stack_pointer,
-                 MR_Word *current_frame)
+     MR_bool registers_live, MR_Word *stack_pointer, MR_Word *current_frame)
 {
     int locn_num;
+    MR_Word copy;
 
     switch (MR_SHORT_LVAL_TYPE(locn)) {
     case MR_SHORT_LVAL_TYPE_R:
         if (registers_live) {
             locn_num = MR_SHORT_LVAL_NUMBER(locn);
-            MR_virtual_reg(locn_num) =
-                    MR_agc_deep_copy(
-                            MR_virtual_reg(locn_num),
-                            type_info,
+            copy = MR_agc_deep_copy(MR_virtual_reg_value(locn_num), type_info,
                             MR_ENGINE(MR_eng_heap_zone2->min),
                             MR_ENGINE(MR_eng_heap_zone2->hardmax));
+            MR_virtual_reg_assign(locn_num, copy);
         }
         break;
 
     case MR_SHORT_LVAL_TYPE_STACKVAR:
         locn_num = MR_SHORT_LVAL_NUMBER(locn);
-        MR_based_stackvar(stack_pointer, locn_num) =
-                MR_agc_deep_copy(
-                        MR_based_stackvar(stack_pointer, locn_num),
-                        type_info,
+        MR_based_stackvar(stack_pointer, locn_num) = MR_agc_deep_copy(
+            MR_based_stackvar(stack_pointer, locn_num), type_info,
                         MR_ENGINE(MR_eng_heap_zone2->min),
                         MR_ENGINE(MR_eng_heap_zone2->hardmax));
         break;
 
     case MR_SHORT_LVAL_TYPE_FRAMEVAR:
         locn_num = MR_SHORT_LVAL_NUMBER(locn);
-        MR_based_framevar(current_frame, locn_num) =
-                MR_agc_deep_copy(
-                        MR_based_framevar(current_frame, locn_num),
-                        type_info,
+        MR_based_framevar(current_frame, locn_num) = MR_agc_deep_copy(
+            MR_based_framevar(current_frame, locn_num), type_info,
                         MR_ENGINE(MR_eng_heap_zone2->min),
                         MR_ENGINE(MR_eng_heap_zone2->hardmax));
         break;
 
     default:
-        MR_fatal_error("Unknown MR_Short_Lval_Type "
-                       "in copy_short_value");
+        MR_fatal_error("Unknown MR_Short_Lval_Type in copy_short_value");
         break;
     }
 }
@@ -1022,8 +1014,7 @@
     MR_RootList current = root_list;
 
     while (current != NULL) {
-        *current->root = MR_agc_deep_copy(
-                *current->root, current->type_info,
+        *current->root = MR_agc_deep_copy(*current->root, current->type_info,
                 MR_ENGINE(MR_eng_heap_zone2->min), 
                 MR_ENGINE(MR_eng_heap_zone2->hardmax));
         current = current->next;
@@ -1037,15 +1028,12 @@
 static void
 maybe_clear_old_heap(MR_MemoryZone *old_heap, MR_Word *old_hp)
 {
-    if (MR_agc_debug) {
-        fprintf(stderr, "Clearing old heap:\n");
-
-        {
             MR_Word *tmp_hp;
 
+    if (MR_agc_debug) {
+        fprintf(stderr, "Clearing old heap:\n");
             for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
                 *tmp_hp = 0xDEADBEAF;
-            }
         }
     }
 }
Index: runtime/mercury_agc_debug.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_agc_debug.c,v
retrieving revision 1.25
diff -u -b -r1.25 mercury_agc_debug.c
--- runtime/mercury_agc_debug.c	6 Jan 2004 16:49:42 -0000	1.25
+++ runtime/mercury_agc_debug.c	7 Jul 2004 06:59:44 -0000
@@ -358,7 +358,7 @@
 	switch (MR_LONG_LVAL_TYPE(locn)) {
 		case MR_LONG_LVAL_TYPE_R:
 			if (do_regs) {
-				value = MR_virtual_reg(locn_num);
+				value = MR_virtual_reg_value(locn_num);
 				have_value = MR_TRUE;
 				fprintf(stderr, "r%d\t", locn_num);
 			} else {
@@ -442,7 +442,7 @@
 	switch (MR_SHORT_LVAL_TYPE(locn)) {
 		case MR_SHORT_LVAL_TYPE_R:
 			if (do_regs) {
-				value = MR_virtual_reg(locn_num);
+				value = MR_virtual_reg_value(locn_num);
 				have_value = MR_TRUE;
 				fprintf(stderr, "r%d\t", locn_num);
 			} else {
Index: runtime/mercury_bootstrap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.h,v
retrieving revision 1.35
diff -u -b -r1.35 mercury_bootstrap.h
--- runtime/mercury_bootstrap.h	1 Apr 2004 04:51:05 -0000	1.35
+++ runtime/mercury_bootstrap.h	7 Jul 2004 06:59:44 -0000
@@ -96,6 +96,13 @@
 */
 #ifdef	MR_EXTRA_BACKWARDS_COMPAT
 
+#define MR_saved_reg(save_area, n)					\
+	MR_LVALUE_COND((n) > MR_MAX_REAL_R_REG,				\
+		(save_area)[(n) + MR_NUM_SPECIAL_REG - 1],		\
+		(save_area)[MR_real_r_reg_map[(n) - 1]])
+
+#define MR_virtual_reg(n) 		MR_saved_reg(MR_fake_reg, n)
+
 /*
 ** bool, TRUE and FALSE used to appear in the generated code.
 */
Index: runtime/mercury_calls.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_calls.h,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_calls.h
--- runtime/mercury_calls.h	14 Apr 2004 01:31:56 -0000	1.11
+++ runtime/mercury_calls.h	7 Jul 2004 06:59:44 -0000
@@ -42,7 +42,7 @@
 		({						\
 			__label__ fixup_gp;			\
 			MR_debugcall((proc), (succ_cont));	\
-			MR_succip = (&&fixup_gp);		\
+			MR_succip_word = (MR_Word) (&&fixup_gp);	\
 			MR_GOTO(proc);				\
 		fixup_gp:					\
 			ASM_FIXUP_REGS				\
@@ -53,7 +53,7 @@
 		({						\
 			__label__ fixup_gp;			\
 			MR_debugcall((proc), (succ_cont));	\
-			MR_succip = (&&fixup_gp);		\
+			MR_succip_word = (MR_Word) (&&fixup_gp);	\
 			MR_GOTO(proc);				\
 		fixup_gp:					\
 			ASM_FIXUP_REGS				\
@@ -63,7 +63,7 @@
   #define	MR_noprof_call(proc, succ_cont)			\
 		do {						\
 			MR_debugcall((proc), (succ_cont));	\
-			MR_succip = (succ_cont);		\
+			MR_succip_word = (MR_Word) (succ_cont);		\
 			MR_GOTO(proc);				\
 		} while (0)
   #define 	MR_noprof_call_localret(proc, succ_cont) 	\
@@ -72,8 +72,8 @@
 
 #define	MR_noprof_localcall(label, succ_cont)			\
 		do {						\
-			MR_debugcall(MR_LABEL(label), (succ_cont));\
-			MR_succip = (succ_cont);		\
+			MR_debugcall(MR_LABEL(label), (succ_cont));	\
+			MR_succip_word = (MR_Word) (succ_cont);		\
 			MR_GOTO_LABEL(label);			\
 		} while (0)
 
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.36
diff -u -b -r1.36 mercury_context.c
--- runtime/mercury_context.c	18 Mar 2003 16:38:09 -0000	1.36
+++ runtime/mercury_context.c	7 Jul 2004 06:59:44 -0000
@@ -119,11 +119,13 @@
 	c->MR_ctxt_maxfr = c->MR_ctxt_nondetstack_zone->min +
 		MR_NONDET_FIXED_SIZE - 1;
 	c->MR_ctxt_curfr = c->MR_ctxt_maxfr;
-	MR_redoip_slot(c->MR_ctxt_curfr) = MR_ENTRY(MR_do_not_reached);
-	MR_redofr_slot(c->MR_ctxt_curfr) = NULL;
-	MR_prevfr_slot(c->MR_ctxt_curfr) = NULL;
-	MR_succip_slot(c->MR_ctxt_curfr) = MR_ENTRY(MR_do_not_reached);
-	MR_succfr_slot(c->MR_ctxt_curfr) = NULL;
+	MR_redoip_slot_word(c->MR_ctxt_curfr) = (MR_Word)
+		MR_ENTRY(MR_do_not_reached);
+	MR_redofr_slot_word(c->MR_ctxt_curfr) = (MR_Word) NULL;
+	MR_prevfr_slot_word(c->MR_ctxt_curfr) = (MR_Word) NULL;
+	MR_succip_slot_word(c->MR_ctxt_curfr) = (MR_Word)
+		MR_ENTRY(MR_do_not_reached);
+	MR_succfr_slot_word(c->MR_ctxt_curfr) = (MR_Word) NULL;
 
   #ifdef MR_USE_MINIMAL_MODEL
 	if (c->MR_ctxt_genstack_zone != NULL) {
Index: runtime/mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.24
diff -u -b -r1.24 mercury_context.h
--- runtime/mercury_context.h	20 May 2003 08:13:46 -0000	1.24
+++ runtime/mercury_context.h	7 Jul 2004 06:59:44 -0000
@@ -349,10 +349,14 @@
 									\
 		load_context_c = (cptr);				\
 		MR_IF_NOT_HIGHLEVEL_CODE(				\
-			MR_succip  = load_context_c->MR_ctxt_succip;	\
-			MR_sp	   = load_context_c->MR_ctxt_sp;	\
-			MR_maxfr   = load_context_c->MR_ctxt_maxfr; 	\
-			MR_curfr   = load_context_c->MR_ctxt_curfr;	\
+			MR_succip_word  = (MR_Word)			\
+				load_context_c->MR_ctxt_succip;		\
+			MR_sp_word	= (MR_Word)			\
+				load_context_c->MR_ctxt_sp;		\
+			MR_maxfr_word   = (MR_Word)			\
+				load_context_c->MR_ctxt_maxfr; 		\
+			MR_curfr_word   = (MR_Word)			\
+				load_context_c->MR_ctxt_curfr;		\
 		  MR_IF_USE_MINIMAL_MODEL(				\
 			MR_gen_next = load_context_c->MR_ctxt_gen_next;	\
 			MR_cut_next = load_context_c->MR_ctxt_cut_next;	\
Index: runtime/mercury_deconstruct_macros.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deconstruct_macros.h,v
retrieving revision 1.2
diff -u -b -r1.2 mercury_deconstruct_macros.h
--- runtime/mercury_deconstruct_macros.h	20 Oct 2003 07:29:31 -0000	1.2
+++ runtime/mercury_deconstruct_macros.h	7 Jul 2004 06:59:44 -0000
@@ -36,8 +36,7 @@
 
 #define MR_deconstruct_get_functor(ei, functor_field, var)          \
     do {                                                            \
-        MR_make_aligned_string(MR_LVALUE_CAST(MR_ConstString, var), \
-            (ei).functor_field);                                    \
+        MR_make_aligned_string(var, (ei).functor_field);            \
     } while (0)
 
 #define MR_deconstruct_get_arity(ei, var)                           \
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.67
diff -u -b -r1.67 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	28 Jun 2004 04:50:04 -0000	1.67
+++ runtime/mercury_deep_copy_body.h	7 Jul 2004 06:59:44 -0000
@@ -384,9 +384,10 @@
             RETURN_IF_OUT_OF_RANGE(data, (MR_Word *) data, 0, MR_Word);
 
             {
-                MR_make_aligned_string_copy_saved_hp(
-                        (MR_LVALUE_CAST(MR_String, new_data)),
+                MR_String   new_string;
+                MR_make_aligned_string_copy_saved_hp(new_string,
                         (MR_String) data);
+                new_data = (MR_Word) new_string;
                 leave_forwarding_pointer(data, 0, new_data);
             }
         }
@@ -414,6 +415,7 @@
                 MR_Unsigned         args, i;
                 MR_Closure          *old_closure;
                 MR_Closure          *new_closure;
+                MR_Word             new_closure_word;
                 MR_Closure_Layout   *closure_layout;
                 MR_TypeInfo         *type_info_arg_vector;
 
@@ -422,8 +424,8 @@
                 args = old_closure->MR_closure_num_hidden_args;
 
                 /* create new closure */
-                MR_offset_incr_saved_hp(MR_LVALUE_CAST(MR_Word, new_closure),
-                    0, args + 3);
+                MR_offset_incr_saved_hp(new_closure_word, 0, args + 3);
+                new_closure = (MR_Closure *) new_closure_word;
 
                 /* copy the fixed fields */
                 new_closure->MR_closure_layout = closure_layout;
@@ -730,6 +732,7 @@
     {
         MR_TypeCtorInfo type_ctor_info;
         MR_Word         *new_type_info_arena;
+        MR_Word         new_type_info_arena_word;
         MR_TypeInfo     *type_info_args;
         MR_TypeInfo     *new_type_info_args;
         int             arity;
@@ -764,20 +767,20 @@
             arity = MR_TYPEINFO_GET_VAR_ARITY_ARITY(type_info);
             type_info_args =
                 MR_TYPEINFO_GET_VAR_ARITY_ARG_VECTOR(type_info);
-            MR_offset_incr_saved_hp(
-                MR_LVALUE_CAST(MR_Word, new_type_info_arena),
+            MR_offset_incr_saved_hp(new_type_info_arena_word,
                 forwarding_pointer_size,
                 MR_var_arity_type_info_size(arity) + forwarding_pointer_size);
+            new_type_info_arena = (MR_Word *) new_type_info_arena_word;
             MR_fill_in_var_arity_type_info(new_type_info_arena,
                 type_ctor_info, arity, new_type_info_args);
         } else {
             arity = type_ctor_info->MR_type_ctor_arity;
             type_info_args = MR_TYPEINFO_GET_FIXED_ARITY_ARG_VECTOR(type_info);
-            MR_offset_incr_saved_hp(
-                MR_LVALUE_CAST(MR_Word, new_type_info_arena),
+            MR_offset_incr_saved_hp(new_type_info_arena_word,
                 forwarding_pointer_size,
                 MR_fixed_arity_type_info_size(arity) + forwarding_pointer_size
             );
+            new_type_info_arena = (MR_Word *) new_type_info_arena_word;
             MR_fill_in_fixed_arity_type_info(new_type_info_arena,
                 type_ctor_info, new_type_info_args);
         }
@@ -805,6 +808,7 @@
     {
         MR_Word *base_typeclass_info;
         MR_Word *new_typeclass_info;
+        MR_Word new_typeclass_info_word;
         int     num_arg_typeinfos;
         int     num_super;
         int     num_instance_constraints;
@@ -833,10 +837,11 @@
                 - num_instance_constraints;
         num_super = MR_typeclass_info_num_superclasses(typeclass_info);
         num_arg_typeinfos = MR_typeclass_info_num_params(typeclass_info);
-        MR_offset_incr_saved_hp(MR_LVALUE_CAST(MR_Word, new_typeclass_info),
+        MR_offset_incr_saved_hp(new_typeclass_info_word,
             forwarding_pointer_size,
             forwarding_pointer_size + 1 /* for basetypeclass_info */
             + num_instance_constraints + num_super + num_arg_typeinfos);
+        new_typeclass_info = (MR_Word *) new_typeclass_info_word;
 
         new_typeclass_info[0] = (MR_Word) base_typeclass_info;
 
Index: runtime/mercury_engine.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.c,v
retrieving revision 1.47
diff -u -b -r1.47 mercury_engine.c
--- runtime/mercury_engine.c	19 May 2004 03:59:45 -0000	1.47
+++ runtime/mercury_engine.c	7 Jul 2004 06:59:44 -0000
@@ -327,8 +327,8 @@
 			** MR_create_exception_handler().
 			*/
 			this_frame = MR_curfr;
-			MR_maxfr = MR_prevfr_slot(this_frame);
-			MR_curfr = MR_succfr_slot(this_frame);
+			MR_maxfr_word = MR_prevfr_slot_word(this_frame);
+			MR_curfr_word = MR_succfr_slot_word(this_frame);
 #ifdef MR_USE_TRAIL
 			MR_prune_ticket();
 #endif
@@ -606,7 +606,7 @@
 engine_init_registers(void)
 {
 	MR_restore_transient_registers();
-	MR_succip = (MR_Code *) engine_done;
+	MR_succip_word = (MR_Word) (MR_Code *) engine_done;
 	return NULL;
 }
 
Index: runtime/mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.34
diff -u -b -r1.34 mercury_engine.h
--- runtime/mercury_engine.h	19 May 2004 03:59:45 -0000	1.34
+++ runtime/mercury_engine.h	7 Jul 2004 06:59:44 -0000
@@ -241,10 +241,10 @@
 		if (setjmp((setjmp_env)->env)) {			\
 			MR_ENGINE(MR_eng_jmp_buf) = (setjmp_env)->mercury_env;\
 			MR_restore_regs_from_mem((setjmp_env)->regs);	\
-			MR_succip = (setjmp_env)->saved_succip;		\
-			MR_sp = (setjmp_env)->saved_sp;			\
-			MR_curfr = (setjmp_env)->saved_curfr;		\
-			MR_maxfr = (setjmp_env)->saved_maxfr;		\
+			MR_succip_word = (MR_Word) (setjmp_env)->saved_succip;\
+			MR_sp_word = (MR_Word) (setjmp_env)->saved_sp;	\
+			MR_curfr_word = (MR_Word) (setjmp_env)->saved_curfr;\
+			MR_maxfr_word = (MR_Word) (setjmp_env)->saved_maxfr;\
 			MR_IF_USE_TRAIL(MR_trail_ptr = 			\
 					(setjmp_env)->saved_trail_ptr);	\
 			MR_IF_USE_TRAIL(MR_ticket_counter = 		\
@@ -386,7 +386,8 @@
 
 #define MR_load_engine_regs(eng)					\
   	do {								\
-		MR_IF_NOT_CONSERVATIVE_GC(MR_hp = (eng)->MR_eng_hp;)	\
+		MR_IF_NOT_CONSERVATIVE_GC(MR_hp_word = (MR_Word)	\
+			(eng)->MR_eng_hp;)				\
 		MR_IF_NOT_CONSERVATIVE_GC(MR_sol_hp =			\
 			(eng)->MR_eng_sol_hp;)				\
 		MR_IF_NOT_CONSERVATIVE_GC(MR_global_hp =		\
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.53
diff -u -b -r1.53 mercury_grade.h
--- runtime/mercury_grade.h	4 Jun 2004 08:36:16 -0000	1.53
+++ runtime/mercury_grade.h	7 Jul 2004 06:59:44 -0000
@@ -58,7 +58,7 @@
 ** compatibility only in debugging and deep profiling grades respectively.
 */
 
-#define MR_GRADE_PART_0	v12_
+#define MR_GRADE_PART_0	v13_
 #define MR_GRADE_EXEC_TRACE_VERSION_NO	1
 #define MR_GRADE_DEEP_PROF_VERSION_NO	1
 
Index: runtime/mercury_hand_compare_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_hand_compare_body.h,v
retrieving revision 1.3
diff -u -b -r1.3 mercury_hand_compare_body.h
--- runtime/mercury_hand_compare_body.h	19 May 2004 03:59:46 -0000	1.3
+++ runtime/mercury_hand_compare_body.h	7 Jul 2004 06:59:44 -0000
@@ -38,7 +38,7 @@
 #ifdef	MR_DEEP_PROFILING
 
 	MR_incr_sp_push_msg(6, name);
-	MR_stackvar(6) = (MR_Word) MR_succip;
+	MR_stackvar(6) = MR_succip_word;
 	MR_stackvar(1) = MR_r1;
 	MR_stackvar(2) = MR_r2;
 
@@ -57,7 +57,7 @@
 		EXIT_PORT_RETURN_LABEL(proc_label));
 
 	MR_r1 = MR_stackvar(1);
-	MR_succip = (MR_Code *) MR_stackvar(6);
+	MR_succip_word = MR_stackvar(6);
 	MR_decr_sp_pop_msg(6);
 	MR_proceed();
 
Index: runtime/mercury_hand_unify_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_hand_unify_body.h,v
retrieving revision 1.3
diff -u -b -r1.3 mercury_hand_unify_body.h
--- runtime/mercury_hand_unify_body.h	19 May 2004 03:59:46 -0000	1.3
+++ runtime/mercury_hand_unify_body.h	7 Jul 2004 06:59:44 -0000
@@ -42,7 +42,7 @@
 #ifdef	MR_DEEP_PROFILING
 
 	MR_incr_sp_push_msg(6, name);
-	MR_stackvar(6) = (MR_Word) MR_succip;
+	MR_stackvar(6) = MR_succip_word;
 	MR_stackvar(1) = MR_r1;
 	MR_stackvar(2) = MR_r2;
 
@@ -64,7 +64,7 @@
 		EXIT_PORT_RETURN_LABEL(proc_label));
 
 	MR_r1 = 1;
-	MR_succip = (MR_Code *) MR_stackvar(6);
+	MR_succip_word = MR_stackvar(6);
 	MR_decr_sp_pop_msg(6);
 	MR_proceed();
 
@@ -74,7 +74,7 @@
 		FAIL_PORT_RETURN_LABEL(proc_label));
 
 	MR_r1 = 0;
-	MR_succip = (MR_Code *) MR_stackvar(6);
+	MR_succip_word = MR_stackvar(6);
 	MR_decr_sp_pop_msg(6);
 	MR_proceed();
 
Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.31
diff -u -b -r1.31 mercury_heap.h
--- runtime/mercury_heap.h	6 Apr 2004 22:29:40 -0000	1.31
+++ runtime/mercury_heap.h	7 Jul 2004 06:59:44 -0000
@@ -129,15 +129,13 @@
 
 			/* we use `MR_hp' as a convenient temporary here */
   #define MR_hp_alloc(count) (						\
-		MR_offset_incr_hp(MR_LVALUE_CAST(MR_Word, MR_hp),	\
-			0, (count)),					\
-		MR_hp += (count),					\
+		MR_offset_incr_hp(MR_hp_word, 0, (count)),		\
+		MR_hp_word = (MR_Word) (MR_hp + (count)),		\
 		(void) 0						\
 	)
   #define MR_hp_alloc_atomic(count) (					\
-		MR_offset_incr_hp_atomic(MR_LVALUE_CAST(MR_Word, MR_hp), \
-			0, (count)),					\
-		MR_hp += (count),					\
+		MR_offset_incr_hp_atomic(MR_hp_word, 0, (count)),	\
+		MR_hp_word = (MR_Word) (MR_hp + (count)),		\
 		(void) 0						\
 	)
 
@@ -152,7 +150,7 @@
 			(((MR_Word *) MR_hp) + (offset))),		\
 		MR_debug_tag_offset_incr_hp_base((dest), (tag), (offset), \
 			(count), (is_atomic)),				\
-		MR_hp += (count),					\
+		MR_hp_word = (MR_Word) (MR_hp + (count)),		\
 		MR_heap_overflow_check(),				\
 		(void) 0						\
 	)
@@ -162,7 +160,7 @@
   #define MR_tag_offset_incr_hp_atomic(dest, tag, offset, count)	\
 	MR_tag_offset_incr_hp_base((dest), (tag), (offset), (count), 1)
 
-  #define MR_mark_hp(dest)		((dest) = (MR_Word) MR_hp)
+  #define MR_mark_hp(dest)		((dest) = MR_hp_word)
 
   /*
   ** When restoring MR_hp, we must make sure that we don't truncate the heap
@@ -172,25 +170,23 @@
   */
   #define MR_restore_hp(src)						\
 		(							\
-			MR_LVALUE_CAST(MR_Word, MR_hp) = (src),		\
+			MR_hp_word = (MR_Word) (src),			\
 			(void) 0					\
 		)
 
   /*
   #define	MR_restore_hp(src)					\
 		(							\
-			MR_LVALUE_CAST(MR_Word, MR_hp) =		\
+			MR_hp_word = (MR_Word)
 			  ( (MR_Word) MR_min_hp_rec < (src) ?		\
 			  (src) : (MR_Word) MR_min_hp_rec ),		\
 			(void) 0					\
 		)
   */
 
-  #define MR_hp_alloc(count)		MR_offset_incr_hp(		\
-					MR_LVALUE_CAST(MR_Word, MR_hp), \
+  #define MR_hp_alloc(count)		MR_offset_incr_hp(MR_hp_word,	\
 						0, (count))
-  #define MR_hp_alloc_atomic(count)	MR_offset_incr_hp_atomic(	\
-					MR_LVALUE_CAST(MR_Word, MR_hp),	\
+  #define MR_hp_alloc_atomic(count)	MR_offset_incr_hp_atomic(MR_hp_word, \
 						0, (count))
 
   #define MR_free_heap(ptr)		((void) 0)
@@ -510,6 +506,7 @@
 		MR_CHECK_EXPR_TYPE((value), T);				\
 		MR_CHECK_EXPR_TYPE((box), MR_Box);			\
 		if (sizeof(T) > sizeof(MR_Box)) {			\
+			MR_Word box_word;				\
 			size_t size_in_words =				\
 				(sizeof(T) + sizeof(MR_Word) - 1)	\
 				 / sizeof(MR_Word);			\
@@ -520,8 +517,8 @@
 			** This assumes that we don't keep term sizes	\
 			** in grades that use boxes.			\
 			*/						\
-			MR_offset_incr_hp(MR_LVALUE_CAST(MR_Word, (box)),\
-				0, size_in_words);			\
+			MR_offset_incr_hp(box_word, 0, size_in_words);	\
+			box = (MR_Box) box_word;			\
 			MR_assign_structure(*(T *)(box), (value));	\
 			MR_maybe_record_allocation(size_in_words,	\
 				"", "foreign type: " MR_STRINGIFY(T));	\
Index: runtime/mercury_ho_call.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ho_call.c,v
retrieving revision 1.72
diff -u -b -r1.72 mercury_ho_call.c
--- runtime/mercury_ho_call.c	23 May 2004 22:16:50 -0000	1.72
+++ runtime/mercury_ho_call.c	7 Jul 2004 06:59:44 -0000
@@ -414,19 +414,21 @@
 	if (num_hidden_args < MR_HO_CALL_INPUTS_COMPACT) {
 		/* copy to the left, from the left */
 		for (i = 1; i <= num_extra_args; i++) {
-			MR_virtual_reg(i + num_hidden_args) =
-				MR_virtual_reg(i + MR_HO_CALL_INPUTS_COMPACT);
+			MR_virtual_reg_assign(i + num_hidden_args,
+				MR_virtual_reg_value(i +
+					MR_HO_CALL_INPUTS_COMPACT));
 		}
 	} else if (num_hidden_args > MR_HO_CALL_INPUTS_COMPACT) {
 		/* copy to the right, from the right */
 		for (i = num_extra_args; i > 0; i--) {
-			MR_virtual_reg(i + num_hidden_args) =
-				MR_virtual_reg(i + MR_HO_CALL_INPUTS_COMPACT);
+			MR_virtual_reg_assign(i + num_hidden_args,
+				MR_virtual_reg_value(i +
+					MR_HO_CALL_INPUTS_COMPACT));
 		}
 	} /* else the new args are in the right place */
 
 	for (i = 1; i <= num_hidden_args; i++) {
-		MR_virtual_reg(i) = closure->MR_closure_hidden_args(i);
+		MR_virtual_reg_assign(i, closure->MR_closure_hidden_args(i));
 	}
 
 	MR_restore_registers();
@@ -474,25 +476,25 @@
 	if (num_extra_instance_args < MR_CLASS_METHOD_CALL_INPUTS_COMPACT) {
 		/* copy to the left, from the left */
 		for (i = 1; i <= num_input_args; i++) {
-			MR_virtual_reg(i + num_extra_instance_args) =
-				MR_virtual_reg(i +
-					MR_CLASS_METHOD_CALL_INPUTS_COMPACT);
+			MR_virtual_reg_assign(i + num_extra_instance_args,
+				MR_virtual_reg_value(i +
+					MR_CLASS_METHOD_CALL_INPUTS_COMPACT));
 		}
 	} else if (num_extra_instance_args >
 			MR_CLASS_METHOD_CALL_INPUTS_COMPACT)
 	{
 		/* copy to the right, from the right */
 		for (i = num_input_args; i > 0; i--) {
-			MR_virtual_reg(i + num_extra_instance_args) =
-				MR_virtual_reg(i +
-					MR_CLASS_METHOD_CALL_INPUTS_COMPACT);
+			MR_virtual_reg_assign(i + num_extra_instance_args,
+				MR_virtual_reg_value(i +
+					MR_CLASS_METHOD_CALL_INPUTS_COMPACT));
 		}
 	} /* else the new args are in the right place */
 
 	for (i = num_extra_instance_args; i > 0; i--) {
-		MR_virtual_reg(i) = 
-			MR_typeclass_info_extra_instance_arg(MR_virtual_reg(1),
-				i);
+		MR_virtual_reg_assign(i,
+			MR_typeclass_info_extra_instance_arg(
+				MR_virtual_reg_value(1), i));
 	}
 
 	MR_restore_registers();
@@ -517,20 +519,20 @@
 	MR_TypeCtorInfo	type_ctor_info;					\
 	MR_TypeInfo	type_info;					\
 	MR_Word		x, y;						\
-	MR_Code		*saved_succip;
+	MR_Word		saved_succip_word;
 
 #define initialize()							\
 	do {								\
 		type_info = (MR_TypeInfo) MR_r1;			\
 		x = MR_r2;						\
 		y = MR_r3;						\
-		saved_succip = MR_succip;				\
+		saved_succip_word = MR_succip_word;			\
 	} while(0)
 
 #define raw_return_answer(answer)					\
 	do {								\
 		MR_r1 = (answer);					\
-		MR_succip = saved_succip;				\
+		MR_succip_word = saved_succip_word;			\
 		MR_proceed();						\
 	} while(0)
 
@@ -593,20 +595,20 @@
 	MR_TypeCtorInfo	type_ctor_info;					\
 	MR_TypeInfo	type_info;					\
 	MR_Word		x, y;						\
-	MR_Code		*saved_succip;
+	MR_Word		saved_succip_word;
 
 #define initialize()							\
 	do {								\
 		type_info = (MR_TypeInfo) MR_r1;			\
 		x = MR_r2;						\
 		y = MR_r3;						\
-		saved_succip = MR_succip;				\
+		saved_succip_word = MR_succip_word;			\
 	} while(0)
 
 #define raw_return_answer(answer)					\
 	do {								\
 		MR_r1 = (answer);					\
-		MR_succip = saved_succip;				\
+		MR_succip_word = saved_succip_word;			\
 		MR_proceed();						\
 	} while(0)
 
@@ -649,20 +651,20 @@
 	MR_TypeCtorInfo	type_ctor_info;					\
 	MR_TypeInfo	type_info;					\
 	MR_Word		x, y;						\
-	MR_Code		*saved_succip;
+	MR_Word		saved_succip_word;
 
 #define initialize()							\
 	do {								\
 		type_info = (MR_TypeInfo) MR_r1;			\
 		x = MR_r2;						\
 		y = MR_r3;						\
-		saved_succip = MR_succip;				\
+		saved_succip_word = MR_succip_word;			\
 	} while(0)
 
 #define raw_return_answer(answer)					\
 	do {								\
 		MR_r1 = (answer);					\
-		MR_succip = saved_succip;				\
+		MR_succip_word = saved_succip_word;			\
 		MR_proceed();						\
 	} while(0)
 
@@ -950,6 +952,7 @@
 {
 	static	int			closure_counter = 0;
 	MR_Closure			*closure;
+	MR_Word				closure_word;
 	MR_Closure_Id			*closure_id;
 	MR_Closure_Dyn_Link_Layout	*closure_layout;
 	char				buf[80];
@@ -1000,8 +1003,8 @@
 #else
 	num_hidden_args = 0;
 #endif
-	MR_offset_incr_hp(MR_LVALUE_CAST(MR_Word, closure), 0,
-		3 + num_hidden_args);
+	MR_offset_incr_hp(closure_word, 0, 3 + num_hidden_args);
+	closure = (MR_Closure *) closure_word;
 
 	closure->MR_closure_layout = (MR_Closure_Layout *) closure_layout;
 	closure->MR_closure_code = proc_addr;
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.35
diff -u -b -r1.35 mercury_layout_util.c
--- runtime/mercury_layout_util.c	23 May 2004 22:16:50 -0000	1.35
+++ runtime/mercury_layout_util.c	7 Jul 2004 06:59:44 -0000
@@ -603,7 +603,8 @@
 				printf("long r%d\n", locn_num);
 			}
 			if (saved_regs != NULL) {
-				value = MR_saved_reg(saved_regs, locn_num);
+				value = MR_saved_reg_value(saved_regs,
+					locn_num);
 				*succeeded = MR_TRUE;
 			}
 			break;
@@ -719,7 +720,8 @@
 				printf("short r%d\n", locn_num);
 			}
 			if (saved_regs != NULL) {
-				value = MR_saved_reg(saved_regs, locn_num);
+				value = MR_saved_reg_value(saved_regs,
+					locn_num);
 				*succeeded = MR_TRUE;
 			}
 			break;
Index: runtime/mercury_make_type_info_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_make_type_info_body.h,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_make_type_info_body.h
--- runtime/mercury_make_type_info_body.h	21 Mar 2003 08:00:30 -0000	1.11
+++ runtime/mercury_make_type_info_body.h	7 Jul 2004 06:59:44 -0000
@@ -29,6 +29,7 @@
 	MR_TypeCtorInfo		type_ctor_info;
 	MR_TypeInfo		expanded_type_info;
 	MR_Word			*type_info_arena;
+	MR_Word			type_info_arena_word;
 	MR_PseudoTypeInfo	*pseudo_type_info_arena;
 	int			arity;
 	int			start_region_size;
@@ -72,7 +73,8 @@
 		** We use void as a space filler until that can be done.
 		*/
 
-		ALLOCATE_WORDS(type_info_arena, 2);
+		ALLOCATE_WORDS(type_info_arena_word, 2);
+		type_info_arena = (MR_Word *) type_info_arena_word;
 		type_info_arena[0] = (MR_Word) type_ctor_info;
 		type_info_arena[1] = (MR_Word)
 			&MR_TYPE_CTOR_INFO_NAME(builtin, void, 0);
@@ -119,8 +121,10 @@
 			** if we haven't done so already.
 			*/
 			if (type_info_arena == NULL) {
-				ALLOCATE_WORDS(type_info_arena,
+				ALLOCATE_WORDS(type_info_arena_word,
 					arity + start_region_size);
+				type_info_arena =
+					(MR_Word *) type_info_arena_word;
 				memcpy(type_info_arena,
 					(MR_Word *) pseudo_type_info,
 					(arity + start_region_size)
Index: runtime/mercury_memory_zones.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_zones.c,v
retrieving revision 1.23
diff -u -b -r1.23 mercury_memory_zones.c
--- runtime/mercury_memory_zones.c	22 Oct 2003 05:56:08 -0000	1.23
+++ runtime/mercury_memory_zones.c	7 Jul 2004 06:59:44 -0000
@@ -183,10 +183,6 @@
 
 /*---------------------------------------------------------------------------*/
 
-MR_Word		MR_virtual_reg_map[MR_MAX_REAL_REG] = MR_VIRTUAL_REG_MAP_BODY;
-
-unsigned long	MR_num_uses[MR_MAX_RN];
-
 #define MAX_ZONES	16
 
 static MR_MemoryZone *used_memory_zones = NULL;
Index: runtime/mercury_memory_zones.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_zones.h,v
retrieving revision 1.14
diff -u -b -r1.14 mercury_memory_zones.h
--- runtime/mercury_memory_zones.h	21 Aug 2002 11:34:19 -0000	1.14
+++ runtime/mercury_memory_zones.h	7 Jul 2004 06:59:44 -0000
@@ -18,32 +18,12 @@
 #ifndef	MERCURY_MEMORY_ZONES_H
 #define	MERCURY_MEMORY_ZONES_H
 
-#include "mercury_regs.h"		/* for MR_NUM_REAL_REGS */
+#include "mercury_regs.h"		/* for MR_NUM_REAL_R_REGS, etc */
 
 #include <stdlib.h>		/* for size_t */
 
 #include "mercury_types.h"	/* for MR_Word */
 #include "mercury_std.h"		/* for MR_bool */
-
-
-/* these cannot be changed without lots of modifications elsewhere */
-#define MR_MAX_REAL_REG 32		/* MR_r1 .. MR_r32 */
-
-/* this can be changed at will, including by -D options to the C compiler */
-#ifndef MR_MAX_VIRTUAL_REG
-#define MR_MAX_VIRTUAL_REG	1024
-#endif
-
-/* allocate enough fake_regs to hold both the special regs */
-/* and all the virtual registers */
-#define MR_MAX_FAKE_REG	(MR_NUM_SPECIAL_REG + MR_MAX_VIRTUAL_REG)
-			/* MR_mr0 .. MR_mr37, MR_mr(38) ... MR_mr(1000) ... */
-
-/* used to lookup the fake_reg for a given real reg */
-extern	MR_Word		MR_virtual_reg_map[MR_MAX_REAL_REG];
-
-/* used for counting register usage */
-extern	unsigned long 	MR_num_uses[MR_MAX_RN];
 
 /*
 ** The Mercury runtime uses a number of memory areas or *zones*. These
Index: runtime/mercury_minimal_model.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_minimal_model.c,v
retrieving revision 1.14
diff -u -b -r1.14 mercury_minimal_model.c
--- runtime/mercury_minimal_model.c	7 Jun 2004 09:07:20 -0000	1.14
+++ runtime/mercury_minimal_model.c	7 Jul 2004 06:59:44 -0000
@@ -1036,10 +1036,10 @@
     MR_minmodel_stats_cnt_restore_state++;
 #endif
 
-    MR_succip = saved_state->MR_ss_succ_ip;
-    MR_sp = saved_state->MR_ss_s_p;
-    MR_curfr = saved_state->MR_ss_cur_fr;
-    MR_maxfr = saved_state->MR_ss_max_fr;
+    MR_succip_word = (MR_Word) saved_state->MR_ss_succ_ip;
+    MR_sp_word = (MR_Word) saved_state->MR_ss_s_p;
+    MR_curfr_word = (MR_Word) saved_state->MR_ss_cur_fr;
+    MR_maxfr_word = (MR_Word) saved_state->MR_ss_max_fr;
     MR_gen_next = saved_state->MR_ss_gen_sp;
 
     MR_table_copy_words(saved_state->MR_ss_non_stack_real_start,
@@ -2186,8 +2186,9 @@
     */
 
     /* MR_gen_next = completion_info->MR_ri_leader_state.MR_ss_gen_next; BUG? */
-    MR_redoip_slot(MR_maxfr) = MR_LABEL(COMPLETION_LABEL(RedoPoint));
-    MR_redofr_slot(MR_maxfr) = MR_maxfr;
+    MR_redoip_slot_word(MR_maxfr) = (MR_Word)
+        MR_LABEL(COMPLETION_LABEL(RedoPoint));
+    MR_redofr_slot_word(MR_maxfr) = MR_maxfr_word;
     MR_based_framevar(MR_maxfr, 1) = (MR_Word) MR_cur_leader;
 
 #ifdef  MR_TABLE_DEBUG
@@ -2399,7 +2400,7 @@
     MR_restore_transient_registers();
 
     /* XXX this will go code that does fail() */
-    MR_succip = completion_info->MR_ri_saved_succip;
+    MR_succip_word = (MR_Word) completion_info->MR_ri_saved_succip;
 
 #ifdef  MR_TABLE_DEBUG
     if (MR_tabledebug) {
Index: runtime/mercury_ml_deconstruct_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ml_deconstruct_body.h,v
retrieving revision 1.4
diff -u -b -r1.4 mercury_ml_deconstruct_body.h
--- runtime/mercury_ml_deconstruct_body.h	2 Dec 2002 15:51:32 -0000	1.4
+++ runtime/mercury_ml_deconstruct_body.h	7 Jul 2004 06:59:44 -0000
@@ -77,6 +77,7 @@
 
     EXPAND_INFO_TYPE	expand_info;
     MR_TypeInfo    		type_info;
+    MR_ConstString      conststring_functor;
 
     type_info = (MR_TypeInfo) TYPEINFO_ARG;
 
@@ -86,7 +87,8 @@
     MR_restore_transient_registers();
 
     max_arity_check_start
-        MR_deconstruct_get_functor(expand_info, functor, FUNCTOR_ARG);
+        MR_deconstruct_get_functor(expand_info, functor, conststring_functor);
+        FUNCTOR_ARG = (MR_String) (MR_Integer) conststring_functor;
         MR_deconstruct_get_arity(expand_info, ARITY_ARG);
         MR_deconstruct_get_arg_list(expand_info, args, ARGUMENTS_ARG);
         MR_deconstruct_free_allocated_arg_type_infos(expand_info, args);
Index: runtime/mercury_ml_functor_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ml_functor_body.h,v
retrieving revision 1.2
diff -u -b -r1.2 mercury_ml_functor_body.h
--- runtime/mercury_ml_functor_body.h	4 Feb 2002 05:22:58 -0000	1.2
+++ runtime/mercury_ml_functor_body.h	7 Jul 2004 06:59:44 -0000
@@ -34,6 +34,7 @@
 
     MR_TypeInfo                 type_info;
     MR_Expand_Functor_Only_Info expand_info;
+    MR_ConstString              conststring_functor;
 
     type_info = (MR_TypeInfo) TYPEINFO_ARG;
 
@@ -41,5 +42,6 @@
     MR_expand_functor_only(type_info, &TERM_ARG, NONCANON, &expand_info);
     MR_restore_transient_registers();
 
-    MR_deconstruct_get_functor(expand_info, functor_only, FUNCTOR_ARG);
+    MR_deconstruct_get_functor(expand_info, functor_only, conststring_functor);
+    FUNCTOR_ARG = (MR_String) (MR_Integer) conststring_functor;
     MR_deconstruct_get_arity(expand_info, ARITY_ARG);
Index: runtime/mercury_regorder.h
===================================================================
RCS file: runtime/mercury_regorder.h
diff -N runtime/mercury_regorder.h
--- runtime/mercury_regorder.h	18 Mar 2003 16:38:10 -0000	1.18
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,420 +0,0 @@
-/*
-** Copyright (C) 1994-1995,1997-2000,2003 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.
-*/
-
-/*
-** mercury_regorder.h - defines the mapping from the Mercury abstract machine
-** registers (MR_r1, MR_r2, ..., MR_hp, MR_sp, etc.) to the underlying
-** intermediate-level abstract machine memory (MR_mr0, MR_mr1, ...).
-**
-** This file should be #included from "mercury_regs.h" and nowhere else.
-** The reason this is separate from "mercury_regs.h" is so that it could,
-** at least in theory, be generated automatically based on
-** profiling feedback from the register usage counts for a particular
-** application.  However, currently we don't do that.
-**
-** If you change this file, you should also change the settings of
-** NUM_REAL_R_REGS in ../configure.in.
-*/
-
-#ifndef MERCURY_REGORDER_H
-#define MERCURY_REGORDER_H
-
-/*
-** If we are using an engine base register, then shift all
-** the machine registers across by 1, and allocate MR_mr0 to
-** MR_engine_base
-*/
-
-#if defined(MR_THREAD_SAFE) && MR_NUM_REAL_REGS > 0
-
-/*
-** MR_r1 .. MR_r32: the general-purpose Mercury registers.
-**
-** If you modify the MR_r<N> to MR_mr<N> mapping, make sure that you update
-** the definition of MR_VIRTUAL_REG_MAP_BODY below and BOTH copies of
-** the definitions of MR_r1-MR_r32.
-*/
-
-#define MR_r1		MR_count_usage(R_RN(1), MR_mr3)
-#define MR_r2		MR_count_usage(R_RN(2), MR_mr4)
-#define MR_r3		MR_count_usage(R_RN(3), MR_mr5)
-#define MR_r4		MR_count_usage(R_RN(4), MR_mr7)
-#define MR_r5		MR_count_usage(R_RN(5), MR_mr8)
-#define MR_r6		MR_count_usage(R_RN(6), MR_mr11)
-#define MR_r7		MR_count_usage(R_RN(7), MR_mr12)
-#define MR_r8		MR_count_usage(R_RN(8), MR_mr13)
-#define MR_r9		MR_count_usage(R_RN(9), MR_mr14)
-#define MR_r10		MR_count_usage(R_RN(10), MR_mr15)
-#define MR_r11		MR_count_usage(R_RN(11), MR_mr16)
-#define MR_r12		MR_count_usage(R_RN(12), MR_mr17)
-#define MR_r13		MR_count_usage(R_RN(13), MR_mr18)
-#define MR_r14		MR_count_usage(R_RN(14), MR_mr19)
-#define MR_r15		MR_count_usage(R_RN(15), MR_mr20)
-#define MR_r16		MR_count_usage(R_RN(16), MR_mr21)
-#define MR_r17		MR_count_usage(R_RN(17), MR_mr22)
-#define MR_r18		MR_count_usage(R_RN(18), MR_mr23)
-#define MR_r19		MR_count_usage(R_RN(19), MR_mr24)
-#define MR_r20		MR_count_usage(R_RN(20), MR_mr25)
-#define MR_r21		MR_count_usage(R_RN(21), MR_mr26)
-#define MR_r22		MR_count_usage(R_RN(22), MR_mr27)
-#define MR_r23		MR_count_usage(R_RN(23), MR_mr28)
-#define MR_r24		MR_count_usage(R_RN(24), MR_mr29)
-#define MR_r25		MR_count_usage(R_RN(25), MR_mr30)
-#define MR_r26		MR_count_usage(R_RN(26), MR_mr31)
-#define MR_r27		MR_count_usage(R_RN(27), MR_mr32)
-#define MR_r28		MR_count_usage(R_RN(28), MR_mr33)
-#define MR_r29		MR_count_usage(R_RN(29), MR_mr34)
-#define MR_r30		MR_count_usage(R_RN(30), MR_mr35)
-#define MR_r31		MR_count_usage(R_RN(31), MR_mr36)
-#define MR_r32		MR_count_usage(R_RN(32), MR_mr37)
-
-	/* Keep this in sync with the actual defintions below */
-#define MR_real_reg_number_sp MR_real_reg_number_mr1
-
-/*
-** The special-purpose Mercury registers:
-**	hp, sp, succip, etc.
-**
-** If you modify the following block, make sure that you update
-** the definitions of MR_NUM_SPECIAL_REG, MR_MAX_SPECIAL_REG_MR,
-** and MR_saved_*.
-*/
-
-/*
-** first, the "very special" registers -- these may go in real machine regs
-*/
-
-#define MR_engine_base		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_SP_RN, MR_mr0))
-#define MR_succip		MR_LVALUE_CAST(MR_Code *,		\
-				MR_count_usage(MR_SI_RN, MR_mr2))
-#define MR_hp			MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_HP_RN, MR_mr6))
-#define MR_sp			MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_SP_RN, MR_mr1))
-#define MR_curfr		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_CF_RN, MR_mr9))
-#define MR_maxfr		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_MF_RN, MR_mr10))
-/*
-** next, the remainder of the special registers -- these go in the
-** fake_reg array, or in some cases in ordinary global variables.
-*/
-
-#define MR_sol_hp		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_SOL_HP_RN, MR_mr(38)))
-#define MR_min_hp_rec		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_MIN_HP_REC, MR_mr(39)))
-#define MR_min_sol_hp_rec	MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_MIN_HP_REC, MR_mr(40)))
-#define MR_global_hp		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_GLOBAL_HP_RN, MR_mr(41)))
-#define MR_gen_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_GEN_NEXT_RN, MR_mr(42)))
-#define MR_gen_stack		MR_LVALUE_CAST(				\
-				struct MR_GenStackFrameStruct *,	\
-				MR_count_usage(MR_GEN_STACK_RN, MR_mr(43)))
-#define MR_cut_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_CUT_NEXT_RN, MR_mr(44)))
-#define MR_cut_stack		MR_LVALUE_CAST(				\
-				struct MR_CutStackFrameStruct *,	\
-				MR_count_usage(MR_CUT_STACK_RN, MR_mr(45)))
-#define MR_pneg_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_CUT_NEXT_RN, MR_mr(46)))
-#define MR_pneg_stack		MR_LVALUE_CAST(				\
-				struct MR_PNegStackFrameStruct *,	\
-				MR_count_usage(MR_CUT_STACK_RN, MR_mr(47)))
-#define MR_trail_ptr		MR_count_usage(MR_TRAIL_PTR_RN,		\
-				MR_trail_ptr_var)
-#define MR_ticket_counter	MR_count_usage(MR_TICKET_COUNTER_RN,	\
-				MR_ticket_counter_var)
-#define MR_ticket_high_water	MR_count_usage(MR_TICKET_HIGH_WATER_RN,	\
-				MR_ticket_high_water_var)
-
-/*
-** the number of "very special" registers, i.e. special registers that can
-** be allocated in real machine registers:
-** MR_engine_base, MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr
-*/
-
-#define MR_NUM_VERY_SPECIAL_REG	6
-
-/* the number of special-purpose Mercury registers */
-#define MR_NUM_SPECIAL_REG	16
-
-/* the maximum MR_mrN number of special registers */
-#define	MR_MAX_SPECIAL_REG_MR	47
-
-/*
-** The MR_saved_foo macros are like MR_foo except that
-** they access the underlying fake_reg slot rather than
-** the real machine register.
-*/
-
-#define MR_saved_succip(save_area)	MR_LVALUE_CAST(MR_Code *, \
-						save_area[2])
-#define MR_saved_hp(save_area)		MR_LVALUE_CAST(MR_Word *, \
-						save_area[6])
-#define MR_saved_sp(save_area)		MR_LVALUE_CAST(MR_Word *, \
-						save_area[1])
-#define MR_saved_curfr(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[9])
-#define MR_saved_maxfr(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[10])
-#define MR_saved_sol_hp(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[38])
-#define MR_saved_min_hp_rec(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[39])
-#define MR_saved_min_sol_hp_rec(save_area) MR_LVALUE_CAST(MR_Word *, \
-						save_area[40])
-#define MR_saved_global_hp(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[41])
-#define MR_saved_gen_next(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[42])
-#define MR_saved_gen_stack(save_area)	MR_LVALUE_CAST(struct \
-						MR_GenStackFrameStruct *, \
-						save_area[43])
-#define MR_saved_cut_next(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[44])
-#define MR_saved_cut_stack(save_area)	MR_LVALUE_CAST(struct \
-						MR_CutStackFrameStruct *, \
-						save_area[45])
-#define MR_saved_pneg_next(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[46])
-#define MR_saved_pneg_stack(save_area)	MR_LVALUE_CAST(struct \
-						MR_PNegStackFrameStruct *, \
-						save_area[47])
-
-#define MR_VIRTUAL_REG_MAP_BODY	{ \
-	3, \
-	4, \
-	5, \
-	7, \
-	8, \
-	11, \
-	12, \
-	13, \
-	14, \
-	15, \
-	16, \
-	17, \
-	18, \
-	19, \
-	20, \
-	21, \
-	22, \
-	23, \
-	24, \
-	25, \
-	26, \
-	27, \
-	28, \
-	29, \
-	30, \
-	31, \
-	32, \
-	33, \
-	34, \
-	35, \
-	36, \
-	37, \
-}
-
-#else /* !MR_THREAD_SAFE or MR_NUM_REAL_REGS == 0 */
-
-/*
-** If you modify the MR_r<N> to MR_mr<N> mapping, make sure that you update
-** the definition of MR_VIRTUAL_REG_MAP_BODY below and BOTH copies of
-** the definitions of MR_r1-MR_r32.
-*/
-
-#define MR_r1		MR_count_usage(R_RN(1), MR_mr2)
-#define MR_r2		MR_count_usage(R_RN(2), MR_mr3)
-#define MR_r3		MR_count_usage(R_RN(3), MR_mr4)
-#define MR_r4		MR_count_usage(R_RN(4), MR_mr6)
-#define MR_r5		MR_count_usage(R_RN(5), MR_mr7)
-#define MR_r6		MR_count_usage(R_RN(6), MR_mr10)
-#define MR_r7		MR_count_usage(R_RN(7), MR_mr11)
-#define MR_r8		MR_count_usage(R_RN(8), MR_mr12)
-#define MR_r9		MR_count_usage(R_RN(9), MR_mr13)
-#define MR_r10		MR_count_usage(R_RN(10), MR_mr14)
-#define MR_r11		MR_count_usage(R_RN(11), MR_mr15)
-#define MR_r12		MR_count_usage(R_RN(12), MR_mr16)
-#define MR_r13		MR_count_usage(R_RN(13), MR_mr17)
-#define MR_r14		MR_count_usage(R_RN(14), MR_mr18)
-#define MR_r15		MR_count_usage(R_RN(15), MR_mr19)
-#define MR_r16		MR_count_usage(R_RN(16), MR_mr20)
-#define MR_r17		MR_count_usage(R_RN(17), MR_mr21)
-#define MR_r18		MR_count_usage(R_RN(18), MR_mr22)
-#define MR_r19		MR_count_usage(R_RN(19), MR_mr23)
-#define MR_r20		MR_count_usage(R_RN(20), MR_mr24)
-#define MR_r21		MR_count_usage(R_RN(21), MR_mr25)
-#define MR_r22		MR_count_usage(R_RN(22), MR_mr26)
-#define MR_r23		MR_count_usage(R_RN(23), MR_mr27)
-#define MR_r24		MR_count_usage(R_RN(24), MR_mr28)
-#define MR_r25		MR_count_usage(R_RN(25), MR_mr29)
-#define MR_r26		MR_count_usage(R_RN(26), MR_mr30)
-#define MR_r27		MR_count_usage(R_RN(27), MR_mr31)
-#define MR_r28		MR_count_usage(R_RN(28), MR_mr32)
-#define MR_r29		MR_count_usage(R_RN(29), MR_mr33)
-#define MR_r30		MR_count_usage(R_RN(30), MR_mr34)
-#define MR_r31		MR_count_usage(R_RN(31), MR_mr35)
-#define MR_r32		MR_count_usage(R_RN(32), MR_mr36)
-
-	/* Keep this in sync with the actual defintions below */
-#define MR_real_reg_number_sp MR_real_reg_number_mr0
-
-/*
-** The special-purpose Mercury registers:
-**	MR_hp, MR_sp, MR_succip, etc.
-**
-** If you modify the following block, make sure that you update
-** the definitions of MR_NUM_SPECIAL_REG, MR_MAX_SPECIAL_REG_MR,
-** and MR_saved_*.
-*/
-
-/*
-** first, the "very special" registers -- these may go in real machine regs
-*/
-
-#define MR_succip		MR_LVALUE_CAST(MR_Code *, \
-					MR_count_usage(MR_SI_RN, MR_mr1))
-#define MR_hp			MR_LVALUE_CAST(MR_Word *, \
-					MR_count_usage(MR_HP_RN, MR_mr5))
-#define MR_sp			MR_LVALUE_CAST(MR_Word *, \
-					MR_count_usage(MR_SP_RN, MR_mr0))
-#define MR_curfr		MR_LVALUE_CAST(MR_Word *, \
-					MR_count_usage(MR_CF_RN, MR_mr8))
-#define MR_maxfr		MR_LVALUE_CAST(MR_Word *, \
-					MR_count_usage(MR_MF_RN, MR_mr9))
-
-/*
-** next, the remainder of the special registers -- these go in the
-** MR_fake_reg array, or in some cases in ordinary global variables.
-*/
-
-#define MR_sol_hp		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_SOL_HP_RN, MR_mr(37)))
-#define MR_min_hp_rec		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_MIN_HP_REC, MR_mr(38)))
-#define MR_min_sol_hp_rec	MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_MIN_HP_REC, MR_mr(39)))
-#define MR_global_hp		MR_LVALUE_CAST(MR_Word *,		\
-				MR_count_usage(MR_GLOBAL_HP_RN, MR_mr(40)))
-#define MR_trail_ptr		MR_count_usage(MR_TRAIL_PTR_RN,		\
-				MR_trail_ptr_var)
-#define MR_ticket_counter	MR_count_usage(MR_TICKET_COUNTER_RN,	\
-				MR_ticket_counter_var)
-#define MR_ticket_high_water	MR_count_usage(MR_TICKET_HIGH_WATER_RN,	\
-				MR_ticket_high_water_var)
-#define MR_gen_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_GEN_NEXT_RN, MR_mr(41)))
-#define MR_gen_stack		MR_LVALUE_CAST(				\
-				struct MR_GenStackFrameStruct *,	\
-				MR_count_usage(MR_GEN_STACK_RN, MR_mr(42)))
-#define MR_cut_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_CUT_NEXT_RN, MR_mr(43)))
-#define MR_cut_stack		MR_LVALUE_CAST(				\
-				struct MR_CutStackFrameStruct *,	\
-				MR_count_usage(MR_CUT_STACK_RN, MR_mr(44)))
-#define MR_pneg_next		MR_LVALUE_CAST(MR_Integer,		\
-				MR_count_usage(MR_CUT_NEXT_RN, MR_mr(45)))
-#define MR_pneg_stack		MR_LVALUE_CAST(				\
-				struct MR_PNegStackFrameStruct *,	\
-				MR_count_usage(MR_CUT_STACK_RN, MR_mr(46)))
-
-/*
-** the number of "very special" registers, i.e. special registers that can
-** be allocated in real machine registers:
-** MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr
-*/
-
-#define MR_NUM_VERY_SPECIAL_REG	5
-
-/* the number of special registers */
-#define MR_NUM_SPECIAL_REG	15
-
-/* the maximum MR_mrN number of special, non rN registers */
-#define	MR_MAX_SPECIAL_REG_MR	46
-
-/*
-** The MR_saved_foo macros are like MR_foo except that
-** they access the underlying fake_reg slot rather than
-** the real machine register.
-*/
-
-#define MR_saved_succip(save_area)	MR_LVALUE_CAST(MR_Code *, \
-						save_area[1])
-#define MR_saved_hp(save_area)		MR_LVALUE_CAST(MR_Word *, \
-						save_area[5])
-#define MR_saved_sp(save_area)		MR_LVALUE_CAST(MR_Word *, \
-						save_area[0])
-#define MR_saved_curfr(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[8])
-#define MR_saved_maxfr(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[9])
-#define MR_saved_sol_hp(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[37])
-#define MR_saved_min_hp_rec(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[38])
-#define MR_saved_min_sol_hp_rec(save_area) MR_LVALUE_CAST(MR_Word *, \
-						save_area[39])
-#define MR_saved_global_hp(save_area)	MR_LVALUE_CAST(MR_Word *, \
-						save_area[40])
-#define MR_saved_gen_stack(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[41])
-#define MR_saved_gen_next(save_area)	MR_LVALUE_CAST(struct \
-						MR_GenStackFrameStruct *, \
-						save_area[42])
-#define MR_saved_cut_stack(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[43])
-#define MR_saved_cut_next(save_area)	MR_LVALUE_CAST(struct \
-						MR_CutStackFrameStruct *,\
-						save_area[44])
-#define MR_saved_pneg_stack(save_area)	MR_LVALUE_CAST(MR_Integer, \
-						save_area[45])
-#define MR_saved_pneg_next(save_area)	MR_LVALUE_CAST(struct \
-						MR_PNegStackFrameStruct *,\
-						save_area[46])
-
-#define MR_VIRTUAL_REG_MAP_BODY	{ \
-	2, \
-	3, \
-	4, \
-	6, \
-	7, \
-	10, \
-	11, \
-	12, \
-	13, \
-	14, \
-	15, \
-	16, \
-	17, \
-	18, \
-	19, \
-	20, \
-	21, \
-	22, \
-	23, \
-	24, \
-	25, \
-	26, \
-	27, \
-	28, \
-	29, \
-	30, \
-	31, \
-	32, \
-	33, \
-	34, \
-	35, \
-	36, \
-}
-
-#endif
-
-#endif /* not MERCURY_REGORDER_H */
Index: runtime/mercury_regs.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regs.c,v
retrieving revision 1.5
diff -u -b -r1.5 mercury_regs.c
--- runtime/mercury_regs.c	13 Jan 2001 09:38:58 -0000	1.5
+++ runtime/mercury_regs.c	7 Jul 2004 06:59:44 -0000
@@ -9,6 +9,126 @@
 
 #include <stdio.h>
 
+MR_Word	*MR_sol_hp_var = NULL;
+MR_Word	*MR_min_hp_rec_var = NULL;
+MR_Word	*MR_min_sol_hp_rec_var = NULL;
+MR_Word	*MR_global_hp_var = NULL;
+
+MR_Word		MR_real_r_reg_map[MR_MAX_REAL_R_REG] = MR_REAL_R_REG_MAP_BODY;
+
+unsigned long	MR_num_uses[MR_MAX_REAL_R_REG + MR_NUM_SPECIAL_REG];
+
+#ifdef MR_MEASURE_REGISTER_USAGE
+
+#define	MR_COUNT_FORMAT	"\t%lu\n"
+
+void 
+MR_print_register_usage_counts(void)
+{
+	int		i;
+
+	printf("register usage counts:\n");
+	for (i = 1; i <= MR_MAX_REAL_R_REG; i++) {
+		printf("r%d", i);
+		printf(MR_COUNT_FORMAT, MR_num_uses[MR_R_SLOT(i)]);
+	}
+
+	printf("MR_succip");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_SI_SLOT]);
+	printf("MR_hp");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_HP_SLOT]);
+	printf("MR_sp");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_SP_SLOT]);
+	printf("MR_curfr");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_CF_SLOT]);
+	printf("MR_maxfr");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_MF_SLOT]);
+	printf("MR_trail_ptr");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_TRAIL_PTR_SLOT]);
+	printf("MR_ticket_counter");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_TICKET_COUNTER_SLOT]);
+	printf("MR_ticket_high_water");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_TICKET_HIGH_WATER_SLOT]);
+	printf("MR_sol_hp");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_SOL_HP_SLOT]);
+	printf("MR_min_hp_rec");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_MIN_HP_REC_SLOT]);
+	printf("MR_min_sol_hp_rec");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_MIN_SOL_HP_REC_SLOT]);
+	printf("MR_global_hp");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_GLOBAL_HP_SLOT]);
+	printf("MR_gen_next");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_GEN_NEXT_SLOT]);
+	printf("MR_gen_stack");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_GEN_STACK_SLOT]);
+	printf("MR_cut_next");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_CUT_NEXT_SLOT]);
+	printf("MR_cut_stack");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_CUT_STACK_SLOT]);
+	printf("MR_pneg_next");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_PNEG_NEXT_SLOT]);
+	printf("MR_pneg_stack");
+	printf(MR_COUNT_FORMAT, MR_num_uses[MR_PNEG_STACK_SLOT]);
+}
+#endif	/* MR_MEASURE_REGISTER_USAGE */
+
+#ifdef	MR_VERIFY_FAKE_REGISTERS
+
+#define	MR_VERIFY_FORMAT	"\t%d\n"
+
+void 
+MR_verify_fake_registers(void)
+{
+	int		i;
+
+	printf("register slots:\n");
+	for (i = 1; i <= MR_MAX_REAL_R_REG; i++) {
+		printf("r%d", i);
+		printf(MR_VERIFY_FORMAT, MR_R_SLOT(i));
+	}
+
+	printf("r%d", MR_MAX_REAL_R_REG + 1);
+	printf(MR_VERIFY_FORMAT, MR_MAX_REAL_R_REG + MR_NUM_SPECIAL_REG);
+
+	printf("MR_succip");
+	printf(MR_VERIFY_FORMAT, MR_SI_SLOT);
+	printf("MR_hp");
+	printf(MR_VERIFY_FORMAT, MR_HP_SLOT);
+	printf("MR_sp");
+	printf(MR_VERIFY_FORMAT, MR_SP_SLOT);
+	printf("MR_curfr");
+	printf(MR_VERIFY_FORMAT, MR_CF_SLOT);
+	printf("MR_maxfr");
+	printf(MR_VERIFY_FORMAT, MR_MF_SLOT);
+	printf("MR_trail_ptr");
+	printf(MR_VERIFY_FORMAT, MR_TRAIL_PTR_SLOT);
+	printf("MR_ticket_counter");
+	printf(MR_VERIFY_FORMAT, MR_TICKET_COUNTER_SLOT);
+	printf("MR_ticket_high_water");
+	printf(MR_VERIFY_FORMAT, MR_TICKET_HIGH_WATER_SLOT);
+	printf("MR_sol_hp");
+	printf(MR_VERIFY_FORMAT, MR_SOL_HP_SLOT);
+	printf("MR_min_hp_rec");
+	printf(MR_VERIFY_FORMAT, MR_MIN_HP_REC_SLOT);
+	printf("MR_min_sol_hp_rec");
+	printf(MR_VERIFY_FORMAT, MR_MIN_SOL_HP_REC_SLOT);
+	printf("MR_global_hp");
+	printf(MR_VERIFY_FORMAT, MR_GLOBAL_HP_SLOT);
+	printf("MR_gen_next");
+	printf(MR_VERIFY_FORMAT, MR_GEN_NEXT_SLOT);
+	printf("MR_gen_stack");
+	printf(MR_VERIFY_FORMAT, MR_GEN_STACK_SLOT);
+	printf("MR_cut_next");
+	printf(MR_VERIFY_FORMAT, MR_CUT_NEXT_SLOT);
+	printf("MR_cut_stack");
+	printf(MR_VERIFY_FORMAT, MR_CUT_STACK_SLOT);
+	printf("MR_pneg_next");
+	printf(MR_VERIFY_FORMAT, MR_PNEG_NEXT_SLOT);
+	printf("MR_pneg_stack");
+	printf(MR_VERIFY_FORMAT, MR_PNEG_STACK_SLOT);
+}
+#endif	/* MR_VERIFY_FAKE_REGISTERS */
+
 MR_Word 
 MR_get_reg(int num)
 {
@@ -54,7 +174,7 @@
 	fprintf(stderr, "register %d out of range in get_reg\n", num);
 	abort();
 	return 0;
-} /* end MR_get_reg() */
+}
 
 MR_Word 
 MR_set_reg(int num, MR_Word val)
@@ -101,4 +221,4 @@
 	fprintf(stderr, "register %d out of range in set_reg\n", num);
 	abort();
 	return 0;
-} /* end MR_set_reg() */
+}
Index: runtime/mercury_regs.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regs.h,v
retrieving revision 1.22
diff -u -b -r1.22 mercury_regs.h
--- runtime/mercury_regs.h	10 Apr 2003 05:51:05 -0000	1.22
+++ runtime/mercury_regs.h	7 Jul 2004 06:59:44 -0000
@@ -29,8 +29,6 @@
   #define MR_LVALUE_COND(expr, x, y)	(*((expr)?&(x):&(y)))
 #endif
 
-#define MR_fake_reg	(MR_ENGINE(MR_eng_fake_reg))
-
 /*---------------------------------------------------------------------------*/
 /*
 ** The registers of the Mercury virtual machine are built up using
@@ -40,20 +38,20 @@
 ** This layer is defined separately for each architecture,
 ** in the header files in the machdeps subdirectory.
 ** The hardware description layer defines the first MR_NUM_REAL_REGS register
-** variables MR_mr0, MR_mr1, etc. as the physical machine registers, and
-** defines an array MR_fake_reg[n] of pseudo registers, with the remaining
-** "registers" MR_mr<MR_NUM_REAL_REGS>, ..., MR_mr36 defined as corresponding
-** slots in this MR_fake_reg array. 
+** variables MR_mr0, ..., MR_mr<MR_NUM_REAL_REGS-1> as the physical machine
+** registers, and with the remaining "registers" MR_mr<MR_NUM_REAL_REGS>, ...,
+** MR_mr36 defined as corresponding slots in the MR_fake_reg array.
+** (The MR_fake_reg array is part of the engine defined in mercury_engine.h.)
 ** This level also provides the macros MR_save_regs_to_mem(),
 ** MR_save_transient_regs_to_mem(), MR_restore_regs_from_mem(),
-** and MR_restore_transient_regs_from_mem().
+** and MR_restore_transient_regs_from_mem(), which copy MR_mr0, ...,
+** MR_mr<MR_NUM_REAL_REGS-1> to and from their MR_fake_reg slots.
 **
-** The next level is the hardware abstraction layer.
-** The hardware abstraction layer is at a similar level to the
-** hardware description layer, and includes that as a subset,
-** but in addition it provides a few more conveniences.
+** The next level is the hardware abstraction layer. The hardware abstraction
+** layer is at a similar level to the hardware description layer, and includes
+** that as a subset, but in addition it provides a few more conveniences.
 ** This layer defines macros MR_mr(n) for n>36, and the macros
-** MR_save_registers(), MR_restore_registers(),
+** MR_save_mhal_registers(), MR_restore_mhal_registers(),
 ** MR_save_transient_registers(), MR_restore_transient_registers(),
 ** MR_save_transient_hp(), and MR_restore_transient_hp().
 ** This layer is defined here in mercury_regs.h.
@@ -65,22 +63,10 @@
 ** real machine registers is given by the macro MR_NUM_REAL_REGS.
 **
 ** The final level is the Mercury abstract machine registers layer.
-** This layer maps the Mercury virtual machine registers
-**
-**	MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr and
-**	MR_r1, ..., MR_r32, MR_r(33), ..., MR_r(MR_MAX_VIRTUAL_REG)
-**
-** to the set MR_mr0..MR_mr37, MR_mr(38), MR_mr(39), ...,
-** MR_mr(MR_MAX_FAKE_REG-1) which were provided by the hardware abstraction
-** layer.
-** It also provides MR_virtual_r(), MR_virtual_succip, MR_virtual_hp, etc.,
-** which are similar to mr<N>, MR_succip, MR_hp, etc. except that they
-** always map to the underlying fake_reg rather than to the physical register.
-**
-** Since the set of most frequently used Mercury virtual machine
-** registers can be different for each program or grade, we want to make
-** this mapping as easy to change as possible. This is why the
-** map is in a minimal header file, mercury_regorder.h.
+** This layer maps the Mercury virtual machine registers to the set
+** MR_mr0..MR_mr37, MR_mr(38), MR_mr(39), ..., MR_mr(MR_MAX_FAKE_REG-1)
+** which were provided by the hardware abstraction layer, and to some
+** global variables.
 */
 
 /*---------------------------------------------------------------------------*/
@@ -113,26 +99,27 @@
 
 /*---------------------------------------------------------------------------*/
 /*
-** Extra stuff for the hardware abstraction layer
+** The hardware abstraction layer
 */
 
 /*
 ** The machdeps header defines MR_mr0 .. MR_mr37;
-** now define MR_mr(n) for n > 37
+** now define MR_mr(n) for n > 37.
+**
+** The value of n should pass MR_assert((n) > 37 && (n) < MR_MAX_FAKE_REG)
 */
 
-#define MR_mr(n) MR_LVALUE_SEQ(MR_assert((n) > 37 && (n) < MR_MAX_FAKE_REG),\
-		MR_fake_reg[n])
+#define MR_mr(n) 			(MR_fake_reg[n])
 
 /* 
-** The MR_save_registers() macro copies the physical machine registers
+** The MR_save_mhal_registers() macro copies the physical machine registers
 ** to their corresponding slots in the MR_fake_reg array.
 */
 
-#define MR_save_registers() 	MR_save_regs_to_mem(MR_fake_reg)
+#define MR_save_mhal_registers() 	MR_save_regs_to_mem(MR_fake_reg)
 
 /* 
-** The MR_restore_registers() macro sets the physical machine registers
+** The MR_restore_mhal_registers() macro sets the physical machine registers
 ** to the values in their corresponding slots in the fake_reg array 
 ** If we're using a register for the engine base, then we'd better
 ** restore that from the thread specific data area, since the fake_reg
@@ -140,21 +127,21 @@
 */
 
 #if defined(MR_THREAD_SAFE) && MR_NUM_REAL_REGS > 0
-  #define MR_restore_registers()					\
+  #define MR_restore_mhal_registers()					\
   	do {							\
-		MR_engine_base = MR_thread_engine_base;		\
+		MR_engine_base_word = (MR_Word) MR_thread_engine_base;	\
 		MR_fake_reg[0] = (MR_Word) MR_engine_base;	\
 		MR_restore_regs_from_mem(MR_fake_reg);		\
 	} while (0)
 #else
-  #define MR_restore_registers() 	MR_restore_regs_from_mem(MR_fake_reg)
+  #define MR_restore_mhal_registers() 	MR_restore_regs_from_mem(MR_fake_reg)
 #endif
 
 /* 
 ** The MR_save_transient_registers() and MR_restore_transient_registers()
-** macros are similar to MR_save_registers() and MR_restore_registers()
-** except that they only save/restore registers which can be
-** affected by calling or returning from a C function (e.g.
+** macros are similar to MR_save_mhal_registers() and
+** MR_restore_mhal_registers() except that they only save/restore registers
+** which can be affected by calling or returning from a C function (e.g.
 ** by sliding register windows on SPARCs).
 */
 
@@ -164,7 +151,7 @@
 #if defined(MR_THREAD_SAFE) && MR_NUM_REAL_REGS > 0
   #define MR_restore_transient_registers()				\
   	do {								\
-		MR_engine_base = MR_thread_engine_base;			\
+		MR_engine_base_word = (MR_Word) MR_thread_engine_base;	\
 		MR_fake_reg[0] = (MR_Word) MR_engine_base;		\
 		MR_restore_transient_regs_from_mem(MR_fake_reg);	\
 	} while (0)
@@ -194,7 +181,65 @@
 
 /*---------------------------------------------------------------------------*/
 /*
-** The Mercury abstract machine registers layer
+** The Mercury abstract machine registers layer.
+**
+** The Mercury abstract machine registers consist of four groups.
+**
+** - The general purpose registers that may be allocated to real machine
+**   registers, MR_rN for 1 <= N <= MR_MAX_REAL_R_REG.
+**
+** - The general purpose registers that cannot be allocated to real machine
+**   registers, MR_r(N) for MR_MAX_REAL_R_REG < N <= MR_MAX_VIRTUAL_R_REG.
+**
+** - The special purpose registers that may be allocated to real machine
+**   registers, namely
+**
+**	MR_succip
+**	MR_hp
+**	MR_sp
+**	MR_curfr
+**	MR_maxfr
+**
+**   and maybe MR_engine_base. The number of these registers is given by
+**   MR_NUM_SPECIAL_MAYBE_REAL_REG.
+**
+** - The special purpose registers that are always stored in global variables,
+**   namely
+**
+**	MR_sol_hp
+**	MR_min_hp_rec
+**	MR_min_sol_hp_rec
+**	MR_global_hp
+**
+**	MR_trail_ptr		if trailing is enabled
+**	MR_ticket_counter	if trailing is enabled
+**	MR_ticket_high_water	if trailing is enabled
+**
+**	MR_gen_next		if minimal model is enabled
+**	MR_gen_stack		if minimal model is enabled
+**	MR_cut_next		if minimal model is enabled
+**	MR_cut_stack		if minimal model is enabled
+**	MR_pneg_next		if minimal model is enabled
+**	MR_pneg_stack		if minimal model is enabled
+**
+**   The number of these registers is given by MR_NUM_SPECIAL_GLOBAL_REG.
+**
+** The Mercury abstract machine registers layer also provides MR_virtual_r(),
+** MR_virtual_succip, MR_virtual_hp, etc., which are similar to mr<N>,
+** MR_succip, MR_hp, etc. except that they always map to the underlying
+** fake_reg rather than to the physical register.
+*/
+
+#define MR_MAX_REAL_R_REG		32
+#define MR_MAX_VIRTUAL_R_REG		1024
+#define	MR_NUM_SPECIAL_MAYBE_REAL_REG	6
+#define MR_NUM_SPECIAL_GLOBAL_REG	13
+#define MR_NUM_SPECIAL_REG		(MR_NUM_SPECIAL_MAYBE_REAL_REG + \
+					MR_NUM_SPECIAL_GLOBAL_REG)
+
+/*
+** The values here should be in sync with the values of the functions
+** max_real_r_reg and max_virtual_r_reg in compiler/llds_out.m.
 */
 
 #ifdef MR_MEASURE_REGISTER_USAGE
@@ -203,35 +248,505 @@
   #define MR_count_usage(num,reg)	(reg)
 #endif
 
-#include "mercury_regorder.h"
+/*
+** The MR_fake_reg array has a slot for every register of the Mercury abstract 
+** machine, both general and special purpose.
+**
+** The first MR_NUM_SPECIAL_MAYBE_REAL_REG + MR_MAX_REAL_R_REG slots are
+** allocated to the virtual machine registers that may be allocated machine
+** registers. The mapping from the virtual machine register to the MR_fake_reg
+** slot depends on whether we use a register to hold MR_engine_base. If we
+** don't, then the last slot in this part of MR_fake_reg is unused. The next
+** MR_NUM_SPECIAL_GLOBAL_REG slots are allocated to the rest of the special
+** purpose abstract machine registers, and the remainder to the rest of the
+** general purpose abstract machine registers.
+*/
+
+#define MR_MAX_FAKE_REG		(MR_NUM_SPECIAL_REG + MR_MAX_VIRTUAL_R_REG)
+
+#define MR_fake_reg		(MR_ENGINE(MR_eng_fake_reg))
+
+/*
+** The definitions of the general purpose and special registers
+** that may go into machine registers.
+**
+** If we are using an engine base register, then allocate MR_mr0 to
+** MR_engine_base, and increase all other MR_mrN numbers by 1.
+**
+** If you change this section, you should also change the settings of
+** NUM_REAL_R_REGS in ../configure.in.
+**
+** You may also wish to use the MR_verify_fake_registers function
+** to check that no MR_fake_reg slot is assigned to two abstract machine
+** registers. (You need to set MR_VERIFY_FAKE_REGISTERS; you can then invoke
+** MR_verify_fake_registers by including -X in MERCURY_OPTIONS.)
+*/
+
+#define	MR_R_SLOT(n)			(MR_real_r_reg_map[(n) - 1])
+
+#if defined(MR_THREAD_SAFE) && MR_NUM_REAL_REGS > 0
+
+  #define MR_engine_base_word		MR_count_usage(MR_SP_SLOT, MR_mr0)
+
+  #define MR_engine_base		((MR_Word *) MR_engine_base_word)
+
+  #define MR_SI_SLOT			2
+  #define MR_HP_SLOT			6
+  #define MR_SP_SLOT			1
+  #define MR_CF_SLOT			9
+  #define MR_MF_SLOT			10
+
+  #define MR_succip_word		MR_count_usage(MR_SI_SLOT, MR_mr2)
+  #define MR_hp_word			MR_count_usage(MR_HP_SLOT, MR_mr6)
+  #define MR_sp_word			MR_count_usage(MR_SP_SLOT, MR_mr1)
+  #define MR_curfr_word			MR_count_usage(MR_CF_SLOT, MR_mr9)
+  #define MR_maxfr_word			MR_count_usage(MR_MF_SLOT, MR_mr10)
+
+  #define MR_real_reg_number_sp		MR_real_reg_number_mr1
+
+  #define MR_r1				MR_count_usage(MR_R_SLOT(1), MR_mr3)
+  #define MR_r2				MR_count_usage(MR_R_SLOT(2), MR_mr4)
+  #define MR_r3				MR_count_usage(MR_R_SLOT(3), MR_mr5)
+  #define MR_r4				MR_count_usage(MR_R_SLOT(4), MR_mr7)
+  #define MR_r5				MR_count_usage(MR_R_SLOT(5), MR_mr8)
+  #define MR_r6				MR_count_usage(MR_R_SLOT(6), MR_mr11)
+  #define MR_r7				MR_count_usage(MR_R_SLOT(7), MR_mr12)
+  #define MR_r8				MR_count_usage(MR_R_SLOT(8), MR_mr13)
+  #define MR_r9				MR_count_usage(MR_R_SLOT(9), MR_mr14)
+  #define MR_r10			MR_count_usage(MR_R_SLOT(10), MR_mr15)
+  #define MR_r11			MR_count_usage(MR_R_SLOT(11), MR_mr16)
+  #define MR_r12			MR_count_usage(MR_R_SLOT(12), MR_mr17)
+  #define MR_r13			MR_count_usage(MR_R_SLOT(13), MR_mr18)
+  #define MR_r14			MR_count_usage(MR_R_SLOT(14), MR_mr19)
+  #define MR_r15			MR_count_usage(MR_R_SLOT(15), MR_mr20)
+  #define MR_r16			MR_count_usage(MR_R_SLOT(16), MR_mr21)
+  #define MR_r17			MR_count_usage(MR_R_SLOT(17), MR_mr22)
+  #define MR_r18			MR_count_usage(MR_R_SLOT(18), MR_mr23)
+  #define MR_r19			MR_count_usage(MR_R_SLOT(19), MR_mr24)
+  #define MR_r20			MR_count_usage(MR_R_SLOT(20), MR_mr25)
+  #define MR_r21			MR_count_usage(MR_R_SLOT(21), MR_mr26)
+  #define MR_r22			MR_count_usage(MR_R_SLOT(22), MR_mr27)
+  #define MR_r23			MR_count_usage(MR_R_SLOT(23), MR_mr28)
+  #define MR_r24			MR_count_usage(MR_R_SLOT(24), MR_mr29)
+  #define MR_r25			MR_count_usage(MR_R_SLOT(25), MR_mr30)
+  #define MR_r26			MR_count_usage(MR_R_SLOT(26), MR_mr31)
+  #define MR_r27			MR_count_usage(MR_R_SLOT(27), MR_mr32)
+  #define MR_r28			MR_count_usage(MR_R_SLOT(28), MR_mr33)
+  #define MR_r29			MR_count_usage(MR_R_SLOT(29), MR_mr34)
+  #define MR_r30			MR_count_usage(MR_R_SLOT(30), MR_mr35)
+  #define MR_r31			MR_count_usage(MR_R_SLOT(31), MR_mr36)
+  #define MR_r32			MR_count_usage(MR_R_SLOT(32), MR_mr37)
+
+  #define MR_REAL_R_REG_MAP_BODY	{ \
+	3, \
+	4, \
+	5, \
+	7, \
+	8, \
+	11, \
+	12, \
+	13, \
+	14, \
+	15, \
+	16, \
+	17, \
+	18, \
+	19, \
+	20, \
+	21, \
+	22, \
+	23, \
+	24, \
+	25, \
+	26, \
+	27, \
+	28, \
+	29, \
+	30, \
+	31, \
+	32, \
+	33, \
+	34, \
+	35, \
+	36, \
+	37, \
+}
+
+#else /* !MR_THREAD_SAFE or MR_NUM_REAL_REGS == 0 */
+
+  #define MR_SI_SLOT			1
+  #define MR_HP_SLOT			5
+  #define MR_SP_SLOT			0
+  #define MR_CF_SLOT			8
+  #define MR_MF_SLOT			9
+
+  #define MR_succip_word		MR_count_usage(MR_SI_SLOT, MR_mr1)
+  #define MR_hp_word			MR_count_usage(MR_HP_SLOT, MR_mr5)
+  #define MR_sp_word			MR_count_usage(MR_SP_SLOT, MR_mr0)
+  #define MR_curfr_word			MR_count_usage(MR_CF_SLOT, MR_mr8)
+  #define MR_maxfr_word			MR_count_usage(MR_MF_SLOT, MR_mr9)
+
+  #define MR_real_reg_number_sp		MR_real_reg_number_mr0
+
+  #define MR_r1				MR_count_usage(MR_R_SLOT(1), MR_mr2)
+  #define MR_r2				MR_count_usage(MR_R_SLOT(2), MR_mr3)
+  #define MR_r3				MR_count_usage(MR_R_SLOT(3), MR_mr4)
+  #define MR_r4				MR_count_usage(MR_R_SLOT(4), MR_mr6)
+  #define MR_r5				MR_count_usage(MR_R_SLOT(5), MR_mr7)
+  #define MR_r6				MR_count_usage(MR_R_SLOT(6), MR_mr10)
+  #define MR_r7				MR_count_usage(MR_R_SLOT(7), MR_mr11)
+  #define MR_r8				MR_count_usage(MR_R_SLOT(8), MR_mr12)
+  #define MR_r9				MR_count_usage(MR_R_SLOT(9), MR_mr13)
+  #define MR_r10			MR_count_usage(MR_R_SLOT(10), MR_mr14)
+  #define MR_r11			MR_count_usage(MR_R_SLOT(11), MR_mr15)
+  #define MR_r12			MR_count_usage(MR_R_SLOT(12), MR_mr16)
+  #define MR_r13			MR_count_usage(MR_R_SLOT(13), MR_mr17)
+  #define MR_r14			MR_count_usage(MR_R_SLOT(14), MR_mr18)
+  #define MR_r15			MR_count_usage(MR_R_SLOT(15), MR_mr19)
+  #define MR_r16			MR_count_usage(MR_R_SLOT(16), MR_mr20)
+  #define MR_r17			MR_count_usage(MR_R_SLOT(17), MR_mr21)
+  #define MR_r18			MR_count_usage(MR_R_SLOT(18), MR_mr22)
+  #define MR_r19			MR_count_usage(MR_R_SLOT(19), MR_mr23)
+  #define MR_r20			MR_count_usage(MR_R_SLOT(20), MR_mr24)
+  #define MR_r21			MR_count_usage(MR_R_SLOT(21), MR_mr25)
+  #define MR_r22			MR_count_usage(MR_R_SLOT(22), MR_mr26)
+  #define MR_r23			MR_count_usage(MR_R_SLOT(23), MR_mr27)
+  #define MR_r24			MR_count_usage(MR_R_SLOT(24), MR_mr28)
+  #define MR_r25			MR_count_usage(MR_R_SLOT(25), MR_mr29)
+  #define MR_r26			MR_count_usage(MR_R_SLOT(26), MR_mr30)
+  #define MR_r27			MR_count_usage(MR_R_SLOT(27), MR_mr31)
+  #define MR_r28			MR_count_usage(MR_R_SLOT(28), MR_mr32)
+  #define MR_r29			MR_count_usage(MR_R_SLOT(29), MR_mr33)
+  #define MR_r30			MR_count_usage(MR_R_SLOT(30), MR_mr34)
+  #define MR_r31			MR_count_usage(MR_R_SLOT(31), MR_mr35)
+  #define MR_r32			MR_count_usage(MR_R_SLOT(32), MR_mr36)
+
+#define MR_REAL_R_REG_MAP_BODY	{ \
+	2, \
+	3, \
+	4, \
+	6, \
+	7, \
+	10, \
+	11, \
+	12, \
+	13, \
+	14, \
+	15, \
+	16, \
+	17, \
+	18, \
+	19, \
+	20, \
+	21, \
+	22, \
+	23, \
+	24, \
+	25, \
+	26, \
+	27, \
+	28, \
+	29, \
+	30, \
+	31, \
+	32, \
+	33, \
+	34, \
+	35, \
+	36, \
+}
+
+#endif
+
+/*
+** The *_SLOT macros define the mapping from special registers and from
+** general purpose registers that may be mapped to machine registers
+** to the slot in the MR_fake_reg array that stores that Mercury abstract
+** machine register. This mapping is also used to map these Mercury abstract
+** machine registers to other save areas, and to map them to their slots in the
+** MR_num_uses array.
+**
+** Any changes to the *_SLOT definitions will also require changes to
+** print_register_usage_counts() in mercury_wrapper.c.
+*/
 
-/* mercury_regorder.h defines MR_r1 .. MR_r32; now define MR_r(n) for n > 32 */
+/*
+** MR_FIRST_UNREAL_SLOT should be the first slot in MR_fake_reg that is
+** not occupied by a Mercury abstract machine register that may possibly be
+** assigned to a real machine register.
+*/
+
+#define	MR_FIRST_UNREAL_SLOT		(MR_MAX_REAL_R_REG + \
+					MR_NUM_SPECIAL_MAYBE_REAL_REG)
+
+#define MR_TRAIL_PTR_SLOT		(MR_FIRST_UNREAL_SLOT + 0)
+#define MR_TICKET_COUNTER_SLOT		(MR_FIRST_UNREAL_SLOT + 1)
+#define MR_TICKET_HIGH_WATER_SLOT	(MR_FIRST_UNREAL_SLOT + 2)
+
+#define	MR_SOL_HP_SLOT			(MR_FIRST_UNREAL_SLOT + 3)
+#define	MR_MIN_HP_REC_SLOT		(MR_FIRST_UNREAL_SLOT + 4)
+#define	MR_MIN_SOL_HP_REC_SLOT		(MR_FIRST_UNREAL_SLOT + 5)
+#define	MR_GLOBAL_HP_SLOT		(MR_FIRST_UNREAL_SLOT + 6)
+
+#define	MR_GEN_STACK_SLOT		(MR_FIRST_UNREAL_SLOT + 7)
+#define	MR_GEN_NEXT_SLOT		(MR_FIRST_UNREAL_SLOT + 8)
+#define	MR_CUT_STACK_SLOT		(MR_FIRST_UNREAL_SLOT + 9)
+#define	MR_CUT_NEXT_SLOT		(MR_FIRST_UNREAL_SLOT + 10)
+#define	MR_PNEG_STACK_SLOT		(MR_FIRST_UNREAL_SLOT + 11)
+#define	MR_PNEG_NEXT_SLOT		(MR_FIRST_UNREAL_SLOT + 12)
+
+#define	MR_FIRST_UNREAL_R_SLOT		(MR_FIRST_UNREAL_SLOT + \
+					MR_NUM_SPECIAL_GLOBAL_REG)
 
 #define MR_r(n) MR_mr((n) + MR_NUM_SPECIAL_REG - 1)
 
 /*
-** saved_reg(save_area, n) accesses the underlying slot in save_area
-** for register n
+** The definitions of the special registers themselves, and their saved
+** versions.
+**
+** The MR_saved_foo macros are like MR_foo except that they access the
+** underlying fake_reg slot rather than the real machine register or global.
+**
+** For the ones that may be allocated to real machine registers, and for all
+** saved versions, assignments should be done to the _word form. Direct
+** assignments to e.g. MR_hp will cause warnings from C compilers that don't
+** like lvalue casts, e.g. gcc 3.4.
+*/
+
+#define MR_succip		((MR_Code *) MR_succip_word)
+#define MR_hp			((MR_Word *) MR_hp_word)
+#define MR_sp			((MR_Word *) MR_sp_word)
+#define MR_curfr		((MR_Word *) MR_curfr_word)
+#define MR_maxfr		((MR_Word *) MR_maxfr_word)
+
+#define MR_sol_hp		MR_count_usage(MR_SOL_HP_SLOT,		\
+					MR_sol_hp_var)
+#define MR_min_hp_rec		MR_count_usage(MR_MIN_HP_REC_SLOT,	\
+					MR_min_hp_rec_var)
+#define MR_min_sol_hp_rec	MR_count_usage(MR_MIN_HP_REC_SLOT,	\
+					MR_min_sol_hp_rec_var)
+#define MR_global_hp		MR_count_usage(MR_GLOBAL_HP_SLOT,	\
+					MR_global_hp_var)
+
+#define MR_trail_ptr		MR_count_usage(MR_TRAIL_PTR_SLOT,	\
+					MR_trail_ptr_var)
+#define MR_ticket_counter	MR_count_usage(MR_TICKET_COUNTER_SLOT,	\
+					MR_ticket_counter_var)
+#define MR_ticket_high_water	MR_count_usage(MR_TICKET_HIGH_WATER_SLOT,\
+					MR_ticket_high_water_var)
+
+#define MR_gen_next		MR_count_usage(MR_GEN_NEXT_SLOT,	\
+					MR_gen_next_var)
+#define MR_gen_stack		MR_count_usage(MR_GEN_STACK_SLOT,	\
+					MR_gen_stack_var)
+#define MR_cut_next		MR_count_usage(MR_CUT_NEXT_SLOT,	\
+					MR_cut_next_var)
+#define MR_cut_stack		MR_count_usage(MR_CUT_STACK_SLOT,	\
+					MR_cut_stack_var)
+#define MR_pneg_next		MR_count_usage(MR_CUT_NEXT_SLOT,	\
+					MR_pneg_next_var)
+#define MR_pneg_stack		MR_count_usage(MR_CUT_STACK_SLOT,	\
+					MR_pneg_stack_var)
+
+#define MR_saved_succip_word(save_area)		(save_area[MR_SI_SLOT])
+#define MR_saved_hp_word(save_area)		(save_area[MR_HP_SLOT])
+#define MR_saved_sp_word(save_area)		(save_area[MR_SP_SLOT])
+#define MR_saved_curfr_word(save_area)		(save_area[MR_CF_SLOT])
+#define MR_saved_maxfr_word(save_area)		(save_area[MR_MF_SLOT])
+
+#define MR_saved_trail_ptr_word(save_area)	(save_area[MR_TRAIL_PTR_SLOT])
+#define MR_saved_ticket_counter_word(save_area) 	\
+					(save_area[MR_TICKET_COUNTER_SLOT])
+#define MR_saved_ticket_high_water_word(save_area)	\
+					(save_area[MR_TICKET_HIGH_WATER_SLOT])
+
+#define MR_saved_sol_hp_word(save_area)		(save_area[MR_SOL_HP_SLOT])
+#define MR_saved_min_hp_rec_word(save_area)	(save_area[MR_MIN_HP_REC_SLOT])
+#define MR_saved_min_sol_hp_rec_word(save_area) 	\
+					(save_area[MR_MIN_SOL_HP_REC_SLOT])
+#define MR_saved_global_hp_word(save_area)	(save_area[MR_GLOBAL_HP_SLOT])
+
+#define MR_saved_gen_next_word(save_area)	(save_area[MR_GEN_NEXT_SLOT])
+#define MR_saved_gen_stack_word(save_area)	(save_area[MR_GEN_STACK_SLOT])
+#define MR_saved_cut_next_word(save_area)	(save_area[MR_CUT_NEXT_SLOT])
+#define MR_saved_cut_stack_word(save_area)	(save_area[MR_CUT_STACK_SLOT])
+#define MR_saved_pneg_next_word(save_area)	(save_area[MR_PNEG_NEXT_SLOT])
+#define MR_saved_pneg_stack_word(save_area)	(save_area[MR_PNEG_STACK_SLOT])
+
+#define MR_saved_succip(save_area)					\
+	((MR_Code *) MR_saved_succip_word(save_area))
+#define MR_saved_hp(save_area)						\
+	((MR_Word *) MR_saved_hp_word(save_area))
+#define MR_saved_sp(save_area)						\
+	((MR_Word *) MR_saved_sp_word(save_area))
+#define MR_saved_curfr(save_area)					\
+	((MR_Word *) MR_saved_curfr_word(save_area))
+#define MR_saved_maxfr(save_area)					\
+	((MR_Word *) MR_saved_maxfr_word(save_area))
+
+#define MR_saved_sol_hp(save_area)					\
+	((MR_Word *) MR_saved_sol_hp_word(save_area))
+#define MR_saved_min_hp_rec(save_area)					\
+	((MR_Word *) MR_saved_min_hp_rec_word(save_area))
+#define MR_saved_min_sol_hp_rec(save_area) 				\
+	((MR_Word *) MR_saved_min_sol_hp_rec_word(save_area))
+#define MR_saved_global_hp(save_area)					\
+	((MR_Word *) MR_saved_global_hp_word(save_area))
+
+#define MR_saved_trail_ptr(save_area)					\
+	((MR_TrailEntryPtr) MR_saved_trail_ptr_word(save_area))
+#define MR_saved_ticket_counter(save_area)				\
+	((MR_Unsigned) MR_saved_ticket_counter_word(save_area))
+#define MR_saved_ticket_high_water(save_area)				\
+	((MR_Unsigned) MR_saved_ticket_high_water_word(save_area))
+
+#define MR_saved_gen_next(save_area)					\
+	((MR_Integer) MR_saved_gen_next_word(save_area))
+#define MR_saved_gen_stack(save_area)					\
+	((MR_GenStackFrame *) MR_saved_gen_stack_word(save_area))
+#define MR_saved_cut_next(save_area)					\
+	((MR_Integer) MR_saved_cut_next_word(save_area))
+#define MR_saved_cut_stack(save_area)					\
+	((MR_CutStackFrame *) MR_saved_cut_stack_word(save_area))
+#define MR_saved_pneg_next(save_area)					\
+	((MR_Integer) MR_saved_pneg_next_word(save_area))
+#define MR_saved_pneg_stack(save_area)					\
+	((MR_PNegStackFrame *) MR_saved_pneg_stack_word(save_area))
+
+/*
+** MR_virtual_reg_value(n) accesses the underlying fake_reg for general
+** register n, while MR_virtual_reg_assign assigns to it.
+**
+** Similarly, MR_virtual_foo access the underlying fake_reg slot for special
+** register foo.
 */
-#define MR_saved_reg(save_area, n)					\
-	MR_LVALUE_COND((n) > MR_MAX_REAL_REG,				\
-		(save_area)[(n) + MR_NUM_SPECIAL_REG - 1],		\
-		(save_area)[MR_virtual_reg_map[(n) - 1]])
 
-/* MR_virtual_reg(n) accesses the underlying fake_reg for register n */
-/* similarly MR_virtual_foo access the underlying fake_reg slot for foo */
+#define MR_saved_reg_value(save_area, n)				\
+	((n) > MR_MAX_REAL_R_REG ?					\
+		(save_area)[(n) + MR_NUM_SPECIAL_REG - 1] :		\
+		(save_area)[MR_real_r_reg_map[(n) - 1]])
+#define MR_saved_reg_assign(save_area, n, val)				\
+	do {								\
+		if ((n) > MR_MAX_REAL_R_REG) {				\
+			(save_area)[(n) + MR_NUM_SPECIAL_REG - 1] = (val); \
+		} else {						\
+			(save_area)[MR_real_r_reg_map[(n) - 1]] = (val); \
+		}							\
+	} while (0)
+
+#define MR_virtual_reg_value(n) 	MR_saved_reg_value(MR_fake_reg, n)
+#define MR_virtual_reg_assign(n, val)	MR_saved_reg_assign(MR_fake_reg, n, val)
 
-#define MR_virtual_reg(n) 		MR_saved_reg(MR_fake_reg, n)
 #define MR_virtual_succip 		MR_saved_succip(MR_fake_reg)
 #define MR_virtual_hp 			MR_saved_hp(MR_fake_reg)
 #define MR_virtual_sp 			MR_saved_sp(MR_fake_reg)
 #define MR_virtual_curfr 		MR_saved_curfr(MR_fake_reg)
 #define MR_virtual_maxfr 		MR_saved_maxfr(MR_fake_reg)
+
 #define MR_virtual_sol_hp 		MR_saved_sol_hp(MR_fake_reg)
 #define MR_virtual_min_hp_rec 		MR_saved_min_hp_rec(MR_fake_reg)
 #define MR_virtual_min_sol_hp_rec 	MR_saved_min_sol_hp_rec(MR_fake_reg)
 #define MR_virtual_global_hp 		MR_saved_global_hp(MR_fake_reg)
 
+#define MR_virtual_trail_ptr		MR_saved_trail_ptr(MR_fake_reg)
+#define MR_virtual_ticket_counter	MR_saved_ticket_counter(MR_fake_reg)
+#define MR_virtual_ticket_high_water	MR_saved_ticket_high_water(MR_fake_reg)
+
+#define MR_virtual_gen_next		MR_saved_gen_next(MR_fake_reg)
+#define MR_virtual_gen_stack		MR_saved_gen_stack(MR_fake_reg)
+#define MR_virtual_cut_next		MR_saved_cut_next(MR_fake_reg)
+#define MR_virtual_cut_stack		MR_saved_cut_stack(MR_fake_reg)
+#define MR_virtual_pneg_next		MR_saved_pneg_next(MR_fake_reg)
+#define MR_virtual_pneg_stack		MR_saved_pneg_stack(MR_fake_reg)
+
+#ifdef	MR_USE_TRAIL
+  #define MR_save_trail_registers()					\
+	do {								\
+		MR_saved_trail_ptr_word(MR_fake_reg) = (MR_Word)	\
+			MR_trail_ptr;					\
+		MR_saved_ticket_counter_word(MR_fake_reg) = (MR_Word)	\
+			MR_ticket_counter;				\
+		MR_saved_ticket_high_water_word(MR_fake_reg) = (MR_Word)\
+			MR_ticket_high_water;				\
+	} while (0)
+  #define MR_restore_trail_registers()					\
+	do {								\
+		MR_trail_ptr_var = MR_virtual_trail_ptr;		\
+		MR_ticket_counter_var = MR_virtual_ticket_counter;	\
+		MR_ticket_high_water_var = MR_virtual_ticket_high_water;\
+	} while (0)
+#else
+  #define MR_save_trail_registers()	((void) 0)
+  #define MR_restore_trail_registers()	((void) 0)
+#endif
+
+#ifdef	MR_USE_MINIMAL_MODEL
+  #define MR_save_mm_registers()					\
+	do {								\
+		MR_saved_gen_next_word(MR_fake_reg) = (MR_Word)		\
+			MR_gen_next;					\
+		MR_saved_gen_stack_word(MR_fake_reg) = (MR_Word)	\
+			MR_gen_stack;					\
+		MR_saved_cut_next_word(MR_fake_reg) = (MR_Word)		\
+			MR_cut_next;					\
+		MR_saved_cut_stack_word(MR_fake_reg) = (MR_Word)	\
+			MR_cut_stack;					\
+		MR_saved_pneg_next_word(MR_fake_reg) = (MR_Word)	\
+			MR_pneg_next;					\
+		MR_saved_pneg_stack_word(MR_fake_reg) = (MR_Word)	\
+			MR_pneg_stack;					\
+	} while (0)
+  #define MR_restore_mm_registers()					\
+	do {								\
+		MR_gen_next_var = MR_virtual_gen_next;			\
+		MR_gen_stack_var = MR_virtual_gen_stack;		\
+		MR_cut_next_var = MR_virtual_cut_next;			\
+		MR_cut_stack_var = MR_virtual_cut_stack;		\
+		MR_pneg_next_var = MR_virtual_pneg_next;		\
+		MR_pneg_stack_var = MR_virtual_pneg_stack;		\
+	} while (0)
+#else
+  #define MR_save_mm_registers()	((void) 0)
+  #define MR_restore_mm_registers()	((void) 0)
+#endif
+
+/*
+** The MR_save_registers() macro copies the physical machine registers
+** and the global variables holding special purpose abstract machine registers
+** to their corresponding slots in the MR_fake_reg array.
+**
+** MR_restore_registers() does the same transfer in the opposite direction.
+**
+** For speed, neither copies the special purpose registers that are known
+** not to be needed in the current grade.
+*/
+
+#define MR_save_registers() 						\
+	do {								\
+		MR_save_mhal_registers();				\
+		MR_saved_sol_hp_word(MR_fake_reg) = (MR_Word)		\
+			MR_sol_hp;					\
+		MR_saved_min_hp_rec_word(MR_fake_reg) = (MR_Word)	\
+			MR_min_hp_rec;					\
+		MR_saved_min_sol_hp_rec_word(MR_fake_reg) = (MR_Word)	\
+			MR_min_sol_hp_rec;				\
+		MR_saved_global_hp_word(MR_fake_reg) = (MR_Word)	\
+			MR_global_hp;					\
+		MR_save_trail_registers();				\
+		MR_save_mm_registers();					\
+	} while (0)
+
+#define MR_restore_registers() 						\
+	do {								\
+		MR_restore_mhal_registers();				\
+		MR_sol_hp = MR_virtual_sol_hp;				\
+		MR_min_hp_rec = MR_virtual_min_hp_rec;			\
+		MR_min_sol_hp_rec = MR_virtual_min_sol_hp_rec;		\
+		MR_global_hp = MR_virtual_global_hp;			\
+		MR_restore_trail_registers();				\
+		MR_restore_mm_registers();				\
+	} while (0)
+
 /*
 ** MR_clear_regs_for_GC() clears all of the Mercury general-purpose
 ** registers.  It is used to avoid unwanted memory retention due to
@@ -239,53 +754,50 @@
 */
 #define MR_clear_regs_for_GC()						\
 	do {								\
+		int i;							\
 		MR_save_registers();					\
-		{ int i;						\
-		  for (i = 1; i <= MR_MAX_VIRTUAL_REG; i++) {		\
-			MR_virtual_reg(i) = 0;				\
-		  }							\
+		for (i = 1; i <= MR_MAX_VIRTUAL_R_REG; i++) {		\
+			MR_virtual_reg_assign(i, 0);			\
 		}							\
 		MR_restore_registers();					\
 	} while (0)
 
+extern	MR_Word	*MR_sol_hp_var;
+extern	MR_Word	*MR_min_hp_rec_var;
+extern	MR_Word	*MR_min_sol_hp_rec_var;
+extern	MR_Word	*MR_global_hp_var;
+
 /*
-** MR_get_reg() and MR_set_reg() provide a different way of addressing
-** the registers; unlike MR_virtual_reg(), you don't need to wrap them
-** inside MR_save_registers()/MR_restore_regs() to copy the real regs to/from
-** the MR_fake_reg, so they may perhaps be more efficient if you are just
-** getting or setting one or two registers?
-** Currently they're buggy for n>32 and are not used except for debugging.
+** Used to lookup the MR_fake_reg slot for a real general purpose register.
 */
 
-extern	MR_Word	MR_get_reg(int);
-extern	MR_Word	MR_set_reg(int, MR_Word);
+extern	MR_Word		MR_real_r_reg_map[MR_MAX_REAL_R_REG];
 
 /*
-** the following macros define a mapping from registers to indices into the
-** MR_num_uses array used for counting register usage
-**
-** any changes to these will also require changes to
-** print_register_usage_counts() in mercury_wrapper.c.
+** Used for counting register usage.
 */
 
-#define	MR_SI_RN		0
-#define MR_R_RN(n)		(n)
-#define MR_ORD_RN		MR_MAX_REAL_REG
-#define	MR_HP_RN		(MR_ORD_RN + 1)
-#define	MR_SP_RN		(MR_ORD_RN + 2)
-#define	MR_CF_RN		(MR_ORD_RN + 3)
-#define	MR_MF_RN		(MR_ORD_RN + 4)
-#define MR_TRAIL_PTR_RN		(MR_ORD_RN + 5)
-#define MR_TICKET_COUNTER_RN	(MR_ORD_RN + 6)
-#define MR_TICKET_HIGH_WATER_RN	(MR_ORD_RN + 7)
-#define	MR_SOL_HP_RN		(MR_ORD_RN + 8)
-#define	MR_MIN_HP_REC		(MR_ORD_RN + 9)
-#define	MR_MIN_SOL_HP_REC	(MR_ORD_RN + 10)
-#define	MR_GLOBAL_HP_RN		(MR_ORD_RN + 11)
-#define	MR_GEN_STACK_RN		(MR_ORD_RN + 12)
-#define	MR_GEN_NEXT_RN		(MR_ORD_RN + 13)
-#define	MR_CUT_STACK_RN		(MR_ORD_RN + 14)
-#define	MR_CUT_NEXT_RN		(MR_ORD_RN + 15)
-#define	MR_MAX_RN		(MR_ORD_RN + 16)
+#ifdef	MR_MEASURE_REGISTER_USAGE
+extern	unsigned long 	MR_num_uses[MR_MAX_REAL_R_REG + MR_NUM_SPECIAL_REG];
+
+static	void		MR_print_register_usage_counts(void);
+#endif
+
+#ifdef	MR_VERIFY_FAKE_REGISTERS
+extern	void		MR_verify_fake_registers(void);
+#endif
+
+/*
+** MR_get_reg() and MR_set_reg() provide a different way of addressing
+** the general purpose registers; unlike MR_virtual_reg_value(), you don't
+** need to wrap them inside MR_save_registers()/MR_restore_regs() to copy
+** the real regs to/from the MR_fake_reg, so they may perhaps be more
+** efficient if you are just getting or setting one or two registers?
+** They are designed to work only for registers at or below MR_MAX_REAL_R_REG
+** and are not used except for debugging.
+*/
+
+extern	MR_Word	MR_get_reg(int);
+extern	MR_Word	MR_set_reg(int, MR_Word);
 
 #endif /* not MERCURY_REGS_H */
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.82
diff -u -b -r1.82 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h	7 Jun 2004 09:07:20 -0000	1.82
+++ runtime/mercury_stack_layout.h	7 Jul 2004 06:59:44 -0000
@@ -782,7 +782,7 @@
 									\
 		max_r_num = (layout)->MR_sll_entry->MR_sle_max_r_num +	\
 			MR_NUM_SPECIAL_REG;				\
-		max_mr_num = MR_max(max_r_num, MR_MAX_SPECIAL_REG_MR);	\
+		max_mr_num = MR_max(max_r_num, MR_FIRST_UNREAL_R_SLOT); \
 	} while (0)
 
 /*-------------------------------------------------------------------------*/
Index: runtime/mercury_stack_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_trace.c,v
retrieving revision 1.65
diff -u -b -r1.65 mercury_stack_trace.c
--- runtime/mercury_stack_trace.c	31 May 2004 04:13:05 -0000	1.65
+++ runtime/mercury_stack_trace.c	7 Jul 2004 06:59:44 -0000
@@ -266,6 +266,7 @@
         ** safe to access the succip and succfr slots
         ** without checking what kind of frame it is.
         */
+
         success = MR_succip_slot(*stack_trace_curfr_ptr);
         *stack_trace_curfr_ptr = MR_succfr_slot(*stack_trace_curfr_ptr);
     }
Index: runtime/mercury_stacks.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.c,v
retrieving revision 1.13
diff -u -b -r1.13 mercury_stacks.c
--- runtime/mercury_stacks.c	31 May 2004 04:13:06 -0000	1.13
+++ runtime/mercury_stacks.c	7 Jul 2004 06:59:44 -0000
@@ -118,6 +118,15 @@
 
 #ifdef	MR_USE_MINIMAL_MODEL
 
+MR_Integer		MR_gen_next_var;
+MR_GenStackFrame	*MR_gen_stack_var;
+
+MR_Integer		MR_cut_next_var;
+MR_CutStackFrame	*MR_cut_stack_var;
+
+MR_Integer		MR_pneg_next_var;
+MR_PNegStackFrame	*MR_pneg_stack_var;
+
 #ifdef	MR_MINIMAL_MODEL_DEBUG
 static	int	MR_pneg_cut_depth = 0;
 #endif
Index: runtime/mercury_stacks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.h,v
retrieving revision 1.47
diff -u -b -r1.47 mercury_stacks.h
--- runtime/mercury_stacks.h	31 May 2004 04:13:06 -0000	1.47
+++ runtime/mercury_stacks.h	7 Jul 2004 06:59:44 -0000
@@ -90,7 +90,7 @@
 
 #define	MR_incr_sp(n)	(					\
 				MR_debugincrsp(n, MR_sp),	\
-				MR_sp = MR_sp + (n),		\
+				MR_sp_word = (MR_Word) (MR_sp + (n)),	\
 				MR_detstack_overflow_check(),	\
 				MR_collect_det_frame_stats(n),	\
 				(void) 0			\
@@ -98,7 +98,7 @@
 
 #define	MR_decr_sp(n)	(					\
 				MR_debugdecrsp(n, MR_sp),	\
-				MR_sp = MR_sp - (n),		\
+				MR_sp_word = (MR_Word) (MR_sp - (n)),	\
 				MR_detstack_underflow_check(),	\
 				(void) 0			\
 			)
@@ -150,26 +150,28 @@
 #define	MR_succfr_addr(fr)	(&((MR_Word *) (fr))[MR_SUCCFR])
 #define	MR_tmp_detfr_addr(fr)	(&((MR_Word *) (fr))[MR_TMP_DETFR])
 #define	MR_table_detfr_addr(fr)	(&((MR_Word *) (fr))[MR_TABLE_DETFR])
-#define	MR_based_framevar_addr(fr, n) \
-				(&(((MR_Word *) (fr))[MR_SAVEVAL + 1 - (n)]))
 
-#define	MR_prevfr_slot(fr)	MR_LVALUE_CAST(MR_Word *,		\
-					((MR_Word *) (fr))[MR_PREVFR])
-#define	MR_redoip_slot(fr)	MR_LVALUE_CAST(MR_Code *,		\
-					((MR_Word *) (fr))[MR_REDOIP])
-#define	MR_redofr_slot(fr)	MR_LVALUE_CAST(MR_Word *,		\
-					((MR_Word *) (fr))[MR_REDOFR])
 #define	MR_succip_slot_addr(fr)	(&(((MR_Code **) (fr))[MR_SUCCIP]))
-#define	MR_succip_slot(fr)	MR_LVALUE_CAST(MR_Code *,		\
-					((MR_Word *) (fr))[MR_SUCCIP])
-#define	MR_succfr_slot(fr)	MR_LVALUE_CAST(MR_Word *,		\
-					((MR_Word *) (fr))[MR_SUCCFR])
-#define	MR_tmp_detfr_slot(fr)	MR_LVALUE_CAST(MR_Word *,		\
-					((MR_Word *) (fr))[MR_TMP_DETFR])
-#define	MR_table_detfr_slot(fr)	MR_LVALUE_CAST(MR_Word *,		\
-					((MR_Word *) (fr))[MR_TABLE_DETFR])
-#define	MR_based_framevar(fr, n) (((MR_Word *) (fr))[MR_SAVEVAL + 1 - (n)])
 
+#define	MR_prevfr_slot_word(fr)		(((MR_Word *) (fr))[MR_PREVFR])
+#define	MR_redoip_slot_word(fr)		(((MR_Word *) (fr))[MR_REDOIP])
+#define	MR_redofr_slot_word(fr)		(((MR_Word *) (fr))[MR_REDOFR])
+#define	MR_succip_slot_word(fr)		(((MR_Word *) (fr))[MR_SUCCIP])
+#define	MR_succfr_slot_word(fr)		(((MR_Word *) (fr))[MR_SUCCFR])
+#define	MR_tmp_detfr_slot_word(fr)	(((MR_Word *) (fr))[MR_TMP_DETFR])
+#define	MR_table_detfr_slot_word(fr)	(((MR_Word *) (fr))[MR_TABLE_DETFR])
+
+#define	MR_prevfr_slot(fr)	((MR_Word *) MR_prevfr_slot_word(fr))
+#define	MR_redoip_slot(fr)	((MR_Code *) MR_redoip_slot_word(fr))
+#define	MR_redofr_slot(fr)	((MR_Word *) MR_redofr_slot_word(fr))
+#define	MR_succip_slot(fr)	((MR_Code *) MR_succip_slot_word(fr))
+#define	MR_succfr_slot(fr)	((MR_Word *) MR_succfr_slot_word(fr))
+#define	MR_tmp_detfr_slot(fr)	((MR_Word *) MR_tmp_detfr_slot_word(fr))
+#define	MR_table_detfr_slot(fr)	((MR_Word *) MR_table_detfr_slot_word(fr))
+
+#define	MR_based_framevar_addr(fr, n) \
+				(&(((MR_Word *) (fr))[MR_SAVEVAL + 1 - (n)]))
+#define	MR_based_framevar(fr, n) (((MR_Word *) (fr))[MR_SAVEVAL + 1 - (n)])
 #define	MR_framevar(n)		MR_based_framevar(MR_curfr, n)
 #define	MR_fv(n)		MR_framevar(n)
 
@@ -179,7 +181,10 @@
 
 #ifdef	MR_USE_MINIMAL_MODEL
   #define	MR_maybe_fill_table_detfr_slot()			\
-				MR_table_detfr_slot(MR_curfr) = MR_sp
+			do {						\
+				MR_table_detfr_slot_word(MR_curfr) =	\
+					MR_sp_word;			\
+			} while (0)
 #else
   #define	MR_maybe_fill_table_detfr_slot()			\
 				((void) 0)
@@ -192,12 +197,13 @@
 									\
 		prevfr = MR_maxfr;					\
 		succfr = MR_curfr;					\
-		MR_maxfr += (MR_NONDET_FIXED_SIZE + (numslots));	\
-		MR_curfr = MR_maxfr;					\
-		MR_prevfr_slot(MR_curfr) = prevfr;			\
-		MR_succip_slot(MR_curfr) = MR_succip;			\
-		MR_succfr_slot(MR_curfr) = succfr;			\
-		MR_redofr_slot(MR_curfr) = MR_curfr;			\
+		MR_maxfr_word = (MR_Word)				\
+			(MR_maxfr + (MR_NONDET_FIXED_SIZE + (numslots))); \
+		MR_curfr_word = MR_maxfr_word;				\
+		MR_prevfr_slot_word(MR_curfr) = (MR_Word) prevfr;	\
+		MR_succip_slot_word(MR_curfr) = (MR_Word) MR_succip;	\
+		MR_succfr_slot_word(MR_curfr) = (MR_Word) succfr;	\
+		MR_redofr_slot_word(MR_curfr) = MR_curfr_word;		\
 		MR_maybe_fill_table_detfr_slot();			\
 		MR_debugmkframe(predname);				\
 		MR_nondstack_overflow_check();				\
@@ -207,7 +213,7 @@
 #define	MR_mkframe(predname, numslots, redoip)				\
 	do {								\
 		MR_mkframe_basic(predname, numslots);			\
-		MR_redoip_slot(MR_curfr) = redoip;			\
+		MR_redoip_slot_word(MR_curfr) = (MR_Word) redoip;	\
 	} while (0)
 
 #define	MR_mkframe_no_redoip(predname, numslots)			\
@@ -221,7 +227,7 @@
 	do {								\
 		MR_mkframe_basic(predname, numslots +			\
 			MR_bytes_to_words(sizeof(struct structname)));	\
-		MR_redoip_slot(MR_curfr) = redoip;			\
+		MR_redoip_slot_word(MR_curfr) = (MR_Word) redoip;	\
 	} while (0)
 
 #define	MR_mkpragmaframe_no_redoip(predname, numslots, structname)	\
@@ -235,10 +241,11 @@
 		MR_Word	*prevfr;					\
 									\
 		prevfr = MR_maxfr;					\
-		MR_maxfr += MR_NONDET_TEMP_SIZE;			\
-		MR_prevfr_slot(MR_maxfr) = prevfr;			\
-		MR_redoip_slot(MR_maxfr) = redoip;			\
-		MR_redofr_slot(MR_maxfr) = MR_curfr;			\
+		MR_maxfr_word = (MR_Word)				\
+			(MR_maxfr + MR_NONDET_TEMP_SIZE);		\
+		MR_prevfr_slot_word(MR_maxfr) = (MR_Word) prevfr;	\
+		MR_redoip_slot_word(MR_maxfr) = (MR_Word) redoip;	\
+		MR_redofr_slot_word(MR_maxfr) = MR_curfr_word;		\
 		MR_debugmktempframe();					\
 		MR_nondstack_overflow_check();				\
 	} while (0)
@@ -248,11 +255,12 @@
 		MR_Word	*prevfr;					\
 									\
 		prevfr = MR_maxfr;					\
-		MR_maxfr += MR_DET_TEMP_SIZE;				\
-		MR_prevfr_slot(MR_maxfr) = prevfr;			\
-		MR_redoip_slot(MR_maxfr) = redoip;			\
-		MR_redofr_slot(MR_maxfr) = MR_curfr;			\
-		MR_tmp_detfr_slot(MR_maxfr)  = MR_sp;			\
+		MR_maxfr_word = (MR_Word)				\
+			(MR_maxfr + MR_DET_TEMP_SIZE);			\
+		MR_prevfr_slot_word(MR_maxfr) = (MR_Word) prevfr;	\
+		MR_redoip_slot_word(MR_maxfr) = (MR_Word) redoip;	\
+		MR_redofr_slot_word(MR_maxfr) = MR_curfr_word;		\
+		MR_tmp_detfr_slot_word(MR_maxfr) = MR_sp_word;		\
 		MR_debugmkdettempframe();				\
 		MR_nondstack_overflow_check();				\
 	} while (0)
@@ -263,7 +271,7 @@
 									\
 		MR_debugsucceed();					\
 		childfr = MR_curfr;					\
-		MR_curfr = MR_succfr_slot(childfr);			\
+		MR_curfr_word = MR_succfr_slot_word(childfr);		\
 		MR_GOTO(MR_succip_slot(childfr));			\
 	} while (0)
 
@@ -273,8 +281,8 @@
 									\
 		MR_debugsucceeddiscard();				\
 		childfr = MR_curfr;					\
-		MR_maxfr = MR_prevfr_slot(childfr);			\
-		MR_curfr = MR_succfr_slot(childfr);			\
+		MR_maxfr_word = MR_prevfr_slot_word(childfr);		\
+		MR_curfr_word = MR_succfr_slot_word(childfr);		\
 		MR_GOTO(MR_succip_slot(childfr));			\
 	} while (0)
 
@@ -282,9 +290,9 @@
 #define	MR_fail()							\
 	do {								\
 		MR_debugfail();						\
-		MR_maxfr = MR_prevfr_slot(MR_maxfr);			\
+		MR_maxfr_word = MR_prevfr_slot_word(MR_maxfr);		\
 		MR_nondstack_underflow_check();				\
-		MR_curfr = MR_redofr_slot(MR_maxfr);			\
+		MR_curfr_word = MR_redofr_slot_word(MR_maxfr);		\
 		MR_GOTO(MR_redoip_slot(MR_maxfr));			\
 	} while (0)
 
@@ -292,7 +300,7 @@
 #define	MR_redo()							\
 	do {								\
 		MR_debugredo();						\
-		MR_curfr = MR_redofr_slot(MR_maxfr);			\
+		MR_curfr_word = MR_redofr_slot_word(MR_maxfr);		\
 		MR_GOTO(MR_redoip_slot(MR_maxfr));			\
 	} while (0)
 
@@ -492,6 +500,9 @@
 	MR_SubgoalPtr		MR_gen_subgoal;
 };
 
+extern	MR_Integer		MR_gen_next_var;
+extern	MR_GenStackFrame	*MR_gen_stack_var;
+
 extern	void			MR_push_generator(MR_Word *frame_addr,
 					MR_SubgoalPtr subgoal);
 extern	MR_Subgoal		*MR_top_generator_table(void);
@@ -547,6 +558,9 @@
 #endif
 };
 
+extern	MR_Integer		MR_cut_next_var;
+extern	MR_CutStackFrame	*MR_cut_stack_var;
+
 extern	void			MR_commit_mark(void);
 extern	void			MR_commit_cut(void);
 
@@ -595,6 +609,9 @@
 	int			MR_pneg_depth;
 #endif
 };
+
+extern	MR_Integer		MR_pneg_next_var;
+extern	MR_PNegStackFrame	*MR_pneg_stack_var;
 
 extern	void			MR_register_suspension(MR_Consumer *consumer);
 extern	void			MR_pneg_enter_cond(void);
Index: runtime/mercury_string.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_string.h,v
retrieving revision 1.30
diff -u -b -r1.30 mercury_string.h
--- runtime/mercury_string.h	20 Oct 2003 07:29:32 -0000	1.30
+++ runtime/mercury_string.h	7 Jul 2004 06:59:44 -0000
@@ -37,6 +37,7 @@
 ** MR_string_const("...", len):
 **	Given a C string literal and its length, returns a Mercury string.
 */
+
 #define MR_string_const(string, len) ((MR_String) string)
 
 #define MR_make_string_const(string) \
@@ -46,10 +47,11 @@
 ** MR_bool MR_string_equal(MR_ConstString s1, MR_ConstString s2):
 **	Return true iff the two Mercury strings s1 and s2 are equal.
 */
+
 #define MR_string_equal(s1,s2) (strcmp((char*)(s1),(char*)(s2))==0)
 
 /* 
-** void MR_make_aligned_string(MR_ConstString & ptr, const char * string):
+** void MR_make_aligned_string(MR_String ptr, const char *string):
 **	Given a C string `string', set `ptr' to be a Mercury string
 **	with the same contents.  (`ptr' must be an lvalue.)
 **	If the resulting Mercury string is to be used by Mercury code,
@@ -65,17 +67,19 @@
 ** Otherwise, allocate space on the heap and copy the C string to
 ** the Mercury string.
 */
+
 #define MR_make_aligned_string(ptr, string) 				\
 	do { 								\
 	    if (MR_tag((MR_Word) (string)) != 0) {			\
 		MR_make_aligned_string_copy((ptr), (string));		\
 	    } else { 							\
-	    	(ptr) = (string);					\
+			/* The cast is there to cast away const, if needed */ \
+			(ptr) = (MR_String) (string);			\
 	    }								\
 	} while(0)
 
 /*
-** void MR_make_aligned_string_copy(MR_ConstString &ptr, const char * string);
+** void MR_make_aligned_string_copy(MR_String ptr, const char * string);
 **	Same as MR_make_aligned_string(ptr, string), except that the string
 **	is guaranteed to be copied. This is useful for copying C strings
 **	onto the Mercury heap.
@@ -85,10 +89,11 @@
 ** rather than inside Mercury code, you may need to call
 ** MR_{save/restore}_transient_hp().
 */
+
 #define MR_make_aligned_string_copy(ptr, string) 			\
 	do {								\
 		MR_Word make_aligned_string_tmp;			\
-		char * make_aligned_string_ptr;				\
+		char	*make_aligned_string_ptr;			\
 									\
 	  	MR_offset_incr_hp_atomic(make_aligned_string_tmp, 0,	\
 	    	    (strlen(string) + sizeof(MR_Word)) / sizeof(MR_Word)); \
@@ -99,15 +104,16 @@
 	} while(0)
 
 /*
-** void MR_make_aligned_string_copy_saved_hp(MR_ConstString &ptr,
+** void MR_make_aligned_string_copy_saved_hp(MR_String ptr,
 ** 		const char * string);
 **	Same as MR_make_aligned_string_copy(ptr, string), except that it uses
 **	MR_offset_incr_saved_hp_atomic instead of MR_offset_incr_hp_atomic.
 */
+
 #define MR_make_aligned_string_copy_saved_hp(ptr, string) 		\
 	do {								\
 		MR_Word make_aligned_string_tmp;			\
-		char * make_aligned_string_ptr;				\
+		char	*make_aligned_string_ptr;			\
 									\
 	  	MR_offset_incr_saved_hp_atomic(make_aligned_string_tmp,	0, \
 	    	    (strlen(string) + sizeof(MR_Word)) / sizeof(MR_Word)); \
@@ -118,15 +124,16 @@
 	} while(0)
 
 /*
-** void MR_make_aligned_string_copy_saved_hp_quote(MR_ConstString &ptr,
+** void MR_make_aligned_string_copy_saved_hp_quote(MR_String ptr,
 ** 		const char * string);
 **	Same as MR_make_aligned_string_copy_saved_hp(ptr, string), except that
 **	it puts double quote marks at the start and end of the string.
 */
+
 #define MR_make_aligned_string_copy_saved_hp_quote(ptr, string)		\
 	do {								\
 		MR_Word make_aligned_string_tmp;			\
-		char * make_aligned_string_ptr;				\
+		char	*make_aligned_string_ptr;			\
 									\
 	  	MR_offset_incr_saved_hp_atomic(make_aligned_string_tmp,	0, \
 	    	    (strlen(string) + 2 + sizeof(MR_Word)) / sizeof(MR_Word)); \
@@ -137,8 +144,8 @@
 	} while(0)
 
 /*
-** void MR_allocate_aligned_string_msg(MR_ConstString &ptr, size_t len,
-**		MR_Code *proclabel, const char *type);
+** void MR_allocate_aligned_string_msg(MR_String ptr, size_t len,
+**		MR_Code *proclabel);
 ** Allocate enough word aligned memory to hold len characters.  Also
 ** record for memory profiling purposes the location, proclabel, of the
 ** allocation if profiling is enabled.
@@ -148,17 +155,18 @@
 ** rather than inside Mercury code, you may need to call
 ** MR_{save/restore}_transient_hp().
 */
+
 #define MR_allocate_aligned_string_msg(ptr, len, proclabel)		\
 	do {								\
 		MR_Word make_aligned_string_tmp;			\
-		char * make_aligned_string_ptr;				\
+		char	*make_aligned_string_ptr;			\
 									\
 	  	MR_offset_incr_hp_atomic_msg(make_aligned_string_tmp, 0,\
 	    	    ((len) + sizeof(MR_Word)) / sizeof(MR_Word),	\
 		    proclabel, "string:string/0");			\
 	    	make_aligned_string_ptr =				\
 		    (char *) make_aligned_string_tmp;			\
-	    	(ptr) = (MR_String) make_aligned_string_ptr;		\
+	    	(ptr) = make_aligned_string_ptr;			\
 	} while(0)
 
 /*
@@ -173,6 +181,7 @@
 ** The definition here and the definition in string.m
 ** must be kept equivalent.
 */
+
 #define MR_do_hash_string(hash, s)			\
 	{						\
 	   int len;					\
@@ -192,11 +201,13 @@
 ** MR_hash_string(s):
 **	Given a Mercury string `s', return a hash value for that string.
 */
+
 MR_Integer	MR_hash_string(MR_ConstString);
 
 #ifdef __GNUC__
 #define MR_hash_string(s)						\
-	({ MR_Integer hash_string_result;				\
+	({								\
+	 	MR_Integer hash_string_result;				\
 	   MR_CHECK_EXPR_TYPE(s, MR_ConstString);			\
 	   MR_do_hash_string(hash_string_result, s);			\
 	   hash_string_result;						\
@@ -225,6 +236,7 @@
 ** You will generally need to call MR_{save/restore}_transient_hp()
 ** before/after calling this function.
 */
+
 MR_String MR_make_string(MR_Code *proclabel, const char *fmt, ...);
 
 #endif /* not MERCURY_STRING_H */
Index: runtime/mercury_trail.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trail.h,v
retrieving revision 1.21
diff -u -b -r1.21 mercury_trail.h
--- runtime/mercury_trail.h	18 Feb 2002 07:01:22 -0000	1.21
+++ runtime/mercury_trail.h	7 Jul 2004 06:59:44 -0000
@@ -199,7 +199,7 @@
 
 typedef void MR_untrail_func_type(void *datum, MR_untrail_reason);
 
-typedef struct {
+struct MR_TrailEntry_Struct {
 #if !(MR_USE_TAGGED_TRAIL)
 	MR_trail_entry_kind MR_entry_kind;
 #endif
@@ -213,7 +213,7 @@
 			void *MR_datum;
 		} MR_func;
 	} MR_union;
-} MR_TrailEntry;
+};
 
 /*
 ** Macros for accessing these fields, taking tagging into account.
Index: runtime/mercury_type_desc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_desc.c,v
retrieving revision 1.6
diff -u -b -r1.6 mercury_type_desc.c
--- runtime/mercury_type_desc.c	20 Oct 2003 07:29:32 -0000	1.6
+++ runtime/mercury_type_desc.c	7 Jul 2004 06:59:44 -0000
@@ -84,6 +84,7 @@
 {
 	MR_TypeCtorInfo type_ctor_info;
 	MR_Word		*new_type_info_arena;
+	MR_Word		new_type_info_arena_word;
 	MR_TypeInfo	*new_type_info_args;
 	int		i;
 
@@ -96,10 +97,10 @@
 			type_ctor_desc);
 
 		MR_restore_transient_registers();
-		MR_offset_incr_hp_atomic_msg(
-			MR_LVALUE_CAST(MR_Word, new_type_info_arena),
+		MR_offset_incr_hp_atomic_msg(new_type_info_arena_word,
 			0, MR_var_arity_type_info_size(arity),
 			"MR_make_type", "type_info");
+		new_type_info_arena = (MR_Word *) new_type_info_arena_word;
 		MR_save_transient_registers();
 		MR_fill_in_var_arity_type_info(new_type_info_arena,
 			type_ctor_info, arity, new_type_info_args);
@@ -113,10 +114,10 @@
 		}
 
 		MR_restore_transient_registers();
-		MR_offset_incr_hp_atomic_msg(
-			MR_LVALUE_CAST(MR_Word, new_type_info_arena),
+		MR_offset_incr_hp_atomic_msg(new_type_info_arena_word,
 			0, MR_fixed_arity_type_info_size(arity),
 			"MR_make_type", "type_info");
+		new_type_info_arena = (MR_Word *) new_type_info_arena_word;
 		MR_save_transient_registers();
 		MR_fill_in_fixed_arity_type_info(new_type_info_arena,
 			type_ctor_info, new_type_info_args);
Index: runtime/mercury_type_desc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_desc.h,v
retrieving revision 1.4
diff -u -b -r1.4 mercury_type_desc.h
--- runtime/mercury_type_desc.h	12 Sep 2002 10:00:54 -0000	1.4
+++ runtime/mercury_type_desc.h	7 Jul 2004 06:59:44 -0000
@@ -62,7 +62,7 @@
 ** 1024 arguments, which is more than ../LIMITATIONS promises.
 */
 
-#define MR_MAX_VARIABLE_ARITY		MR_MAX_VIRTUAL_REG
+#define MR_MAX_VARIABLE_ARITY		MR_MAX_VIRTUAL_R_REG
 
 /*
 ** Constructors for the MR_TypeCtorDesc ADT
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.59
diff -u -b -r1.59 mercury_type_info.c
--- runtime/mercury_type_info.c	21 Jan 2004 02:52:37 -0000	1.59
+++ runtime/mercury_type_info.c	7 Jul 2004 06:59:44 -0000
@@ -39,11 +39,14 @@
 #define	MAYBE_PASS_ALLOC_ARG	, allocated
 #define	ALLOCATE_WORDS(target, size)					      \
 				do {					      \
+					MR_Word		*target_word_ptr;     \
 					MR_MemoryList node;		      \
-					(target) = MR_GC_NEW_ARRAY(MR_Word,   \
+					target_word_ptr = 		      \
+						MR_GC_NEW_ARRAY(MR_Word,      \
 						(size));		      \
+					(target) = (MR_Word) target_word_ptr; \
 					node = MR_GC_malloc(sizeof(*node));   \
-					node->data = (target);		      \
+					node->data = target_word_ptr;	      \
 					node->next = *allocated;	      \
 					*allocated = node;		      \
 				} while (0)
@@ -66,16 +69,13 @@
 	do {								     \
 		/* reserve one extra word for GC forwarding pointer */	     \
 		/* (see comments in compiler/mlds_to_c.m for details) */     \
-		MR_offset_incr_saved_hp(MR_LVALUE_CAST(MR_Word, (target)),   \
-			0, 1);      					     \
-		MR_offset_incr_saved_hp(MR_LVALUE_CAST(MR_Word, (target)),   \
-			0, (size));					     \
+		MR_offset_incr_saved_hp((target), 0, 1);		     \
+		MR_offset_incr_saved_hp((target), 0, (size));		     \
 	} while (0)
 #else /* !MR_NATIVE_GC */
   #define ALLOCATE_WORDS(target, size)					     \
 	do {								     \
-		MR_offset_incr_saved_hp(MR_LVALUE_CAST(MR_Word, (target)),   \
-			0, (size));					     \
+		MR_offset_incr_saved_hp((target), 0, (size));		     \
 	} while (0)
 #endif /* !MR_NATIVE_GC */
 
Index: runtime/mercury_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_types.h,v
retrieving revision 1.37
diff -u -b -r1.37 mercury_types.h
--- runtime/mercury_types.h	19 May 2004 03:59:53 -0000	1.37
+++ runtime/mercury_types.h	7 Jul 2004 06:59:44 -0000
@@ -36,7 +36,7 @@
 ** At the moment, we use variable length arrays that are indexed by
 ** closure argument numbers or by type parameter numbers. We therefore
 ** use a default MR_VARIABLE_SIZED value that is at least as big as
-** both MR_MAX_VIRTUAL_REG and MR_PSEUDOTYPEINFO_MAX_VAR.
+** both MR_MAX_VIRTUAL_R_REG and MR_PSEUDOTYPEINFO_MAX_VAR.
 */
 
 #if __STDC_VERSION__ >= 199901	/* January 1999 */
@@ -195,6 +195,9 @@
 typedef const struct MR_DictId_Struct                   *MR_DictId;
 typedef       struct MR_Dictionary_Struct               MR_DictionaryStruct;
 typedef const struct MR_Dictionary_Struct               *MR_Dictionary;
+
+typedef struct MR_TrailEntry_Struct             MR_TrailEntry;
+typedef struct MR_TrailEntry_Struct             *MR_TrailEntryPtr;
 
 typedef struct MR_Closure_Struct                MR_Closure;
 typedef const MR_Closure                        *MR_ClosurePtr;
Index: runtime/mercury_unify_compare_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_unify_compare_body.h,v
retrieving revision 1.36
diff -u -b -r1.36 mercury_unify_compare_body.h
--- runtime/mercury_unify_compare_body.h	28 Jun 2004 04:50:08 -0000	1.36
+++ runtime/mercury_unify_compare_body.h	7 Jul 2004 06:59:44 -0000
@@ -452,10 +452,10 @@
 
                 /* CompPred(...ArgTypeInfos..., Res, X, Y) * */
                 for (i = 1; i <= type_arity; i++) {
-                    MR_virtual_reg(i) = args_base[i];
+                    MR_virtual_reg_assign(i, args_base[i]);
                 }
-                MR_virtual_reg(type_arity + 1) = x;
-                MR_virtual_reg(type_arity + 2) = y;
+                MR_virtual_reg_assign(type_arity + 1, x);
+                MR_virtual_reg_assign(type_arity + 2, y);
 
                 MR_restore_registers();
             }
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.133
diff -u -b -r1.133 mercury_wrapper.c
--- runtime/mercury_wrapper.c	31 May 2004 04:13:07 -0000	1.133
+++ runtime/mercury_wrapper.c	7 Jul 2004 06:59:45 -0000
@@ -391,9 +391,6 @@
 static	void	process_options(int argc, char **argv);
 static	void	usage(void);
 
-#ifdef MR_MEASURE_REGISTER_USAGE
-static	void	print_register_usage_counts(void);
-#endif
 #ifdef MR_TYPE_CTOR_STATS
 static	void	MR_print_type_ctor_stats(void);
 static	void	MR_print_one_type_ctor_stat(FILE *fp, const char *op,
@@ -958,7 +955,7 @@
 	int		c;
 	int		long_index;
 
-	while ((c = MR_getopt_long(argc, argv, "acC:d:D:e:i:m:n:o:pP:r:sStT:x",
+	while ((c = MR_getopt_long(argc, argv, "acC:d:D:e:i:m:n:o:pP:r:sStT:xX",
 		MR_long_opts, &long_index)) != EOF)
 	{
 		switch (c)
@@ -1319,7 +1316,12 @@
 #ifdef MR_BOEHM_GC
 			GC_dont_gc = MR_TRUE;
 #endif
+			break;
 
+		case 'X':
+#ifdef	MR_VERIFY_FAKE_REGISTERS
+			MR_verify_fake_registers();
+#endif
 			break;
 
 		default:	
@@ -1527,7 +1529,7 @@
 
 #ifdef MR_MEASURE_REGISTER_USAGE
 	printf("\n");
-	print_register_usage_counts();
+	MR_print_register_usage_counts();
 #endif
 
         if (use_own_timer) {
@@ -1651,78 +1653,6 @@
 
 #endif
 
-#ifdef MR_MEASURE_REGISTER_USAGE
-static void 
-print_register_usage_counts(void)
-{
-	int	i;
-
-	printf("register usage counts:\n");
-	for (i = 0; i < MR_MAX_RN; i++) {
-		if (1 <= i && i <= ORD_RN) {
-			printf("r%d", i);
-		} else {
-			switch (i) {
-
-			case SI_RN:
-				printf("MR_succip");
-				break;
-			case HP_RN:
-				printf("MR_hp");
-				break;
-			case SP_RN:
-				printf("MR_sp");
-				break;
-			case CF_RN:
-				printf("MR_curfr");
-				break;
-			case MF_RN:
-				printf("MR_maxfr");
-				break;
-			case MR_TRAIL_PTR_RN:
-				printf("MR_trail_ptr");
-				break;
-			case MR_TICKET_COUNTER_RN:
-				printf("MR_ticket_counter");
-				break;
-			case MR_TICKET_HIGH_WATER_RN:
-				printf("MR_ticket_high_water");
-				break;
-			case MR_SOL_HP_RN:
-				printf("MR_sol_hp");
-				break;
-			case MR_MIN_HP_REC:
-				printf("MR_min_hp_rec");
-				break;
-			case MR_MIN_SOL_HP_REC:
-				printf("MR_min_sol_hp_rec");
-				break;
-			case MR_GLOBAL_HP_RN:
-				printf("MR_global_hp");
-				break;
-			case MR_GEN_STACK_RN:
-				printf("MR_gen_stack");
-				break;
-			case MR_GEN_NEXT_RN:
-				printf("MR_gen_next");
-				break;
-			case MR_CUT_STACK_RN:
-				printf("MR_cut_stack");
-				break;
-			case MR_CUT_NEXT_RN:
-				printf("MR_cut_next");
-				break;
-			default:
-				printf("UNKNOWN%d", i);
-				break;
-			}
-		}
-
-		printf("\t%lu\n", MR_num_uses[i]);
-	} /* end for */
-} /* end print_register_usage_counts() */
-#endif
-
 #ifdef MR_HIGHLEVEL_CODE
 
 static void
@@ -1808,12 +1738,12 @@
 
 MR_define_entry(MR_do_interpreter);
 	MR_incr_sp(4);
-	MR_stackvar(1) = (MR_Word) MR_hp;
-	MR_stackvar(2) = (MR_Word) MR_succip;
-	MR_stackvar(3) = (MR_Word) MR_maxfr;
-	MR_stackvar(4) = (MR_Word) MR_curfr;
+	MR_stackvar(1) = MR_hp_word;
+	MR_stackvar(2) = MR_succip_word;
+	MR_stackvar(3) = MR_maxfr_word;
+	MR_stackvar(4) = MR_curfr_word;
 
-	MR_succip = MR_LABEL(wrapper_not_reached);
+	MR_succip_word = (MR_Word) MR_LABEL(wrapper_not_reached);
 	MR_mkframe("interpreter", 1, MR_LABEL(global_fail));
 
 	MR_nondet_stack_trace_bottom = MR_maxfr;
@@ -1879,10 +1809,10 @@
 	}
 #endif
 
-	MR_hp     = (MR_Word *) MR_stackvar(1);
-	MR_succip = (MR_Code *) MR_stackvar(2);
-	MR_maxfr  = (MR_Word *) MR_stackvar(3);
-	MR_curfr  = (MR_Word *) MR_stackvar(4);
+	MR_hp_word     = MR_stackvar(1);
+	MR_succip_word = MR_stackvar(2);
+	MR_maxfr_word  = MR_stackvar(3);
+	MR_curfr_word  = MR_stackvar(4);
 	MR_decr_sp(4);
 
 #ifdef MR_LOWLEVEL_DEBUG
cvs server: Diffing runtime/GETOPT
cvs server: Diffing runtime/machdeps
cvs server: Diffing samples
cvs server: Diffing samples/c_interface
cvs server: Diffing samples/c_interface/c_calls_mercury
cvs server: Diffing samples/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/c_interface/mercury_calls_c
cvs server: Diffing samples/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/c_interface/mercury_calls_fortran
cvs server: Diffing samples/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/diff
cvs server: Diffing samples/muz
cvs server: Diffing samples/rot13
cvs server: Diffing samples/solutions
cvs server: Diffing samples/tests
cvs server: Diffing samples/tests/c_interface
cvs server: Diffing samples/tests/c_interface/c_calls_mercury
cvs server: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/tests/c_interface/mercury_calls_c
cvs server: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs server: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/tests/diff
cvs server: Diffing samples/tests/muz
cvs server: Diffing samples/tests/rot13
cvs server: Diffing samples/tests/solutions
cvs server: Diffing samples/tests/toplevel
cvs server: Diffing scripts
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.103
diff -u -b -r1.103 mgnuc.in
--- scripts/mgnuc.in	31 May 2004 04:13:12 -0000	1.103
+++ scripts/mgnuc.in	7 Jul 2004 06:59:45 -0000
@@ -23,6 +23,7 @@
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
 CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
+CFLAGS_FOR_NO_STRICT_ALIASING="@CFLAGS_FOR_NO_STRICT_ALIASING@"
 AS="@AS@"
 
 case "$CC" in
@@ -51,7 +52,7 @@
 # -Wenum-clash 		is for C++ only
 # -Wunused		causes various spurious warnings
 
-	OPT_OPTS="-O2 -fomit-frame-pointer"
+	OPT_OPTS="-O2 $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
 	DEBUG_OPT="-g"
 	COMPILER=gcc
 	;;
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.111
diff -u -b -r1.111 ml.in
--- scripts/ml.in	19 May 2004 03:59:58 -0000	1.111
+++ scripts/ml.in	7 Jul 2004 06:59:45 -0000
@@ -410,7 +410,7 @@
 	umask 022
 	try=0
 	until 
-		ML_TMPDIR=$TMPDIR/ml$$
+		ML_TMPDIR=$TMPDIR/ml$$.$try
 		PIPE=$ML_TMPDIR/pipe
 		trap 'rmdir $ML_TMPDIR >/dev/null 2>&1; exit 1' 1 2 3 13 15 
 		mkdir $ML_TMPDIR
cvs server: Diffing tests
cvs server: Diffing tests/benchmarks
cvs server: Diffing tests/debugger
cvs server: Diffing tests/debugger/declarative
cvs server: Diffing tests/dppd
cvs server: Diffing tests/general
cvs server: Diffing tests/general/accumulator
cvs server: Diffing tests/general/string_format
cvs server: Diffing tests/general/structure_reuse
cvs server: Diffing tests/grade_subdirs
cvs server: Diffing tests/hard_coded
Index: tests/hard_coded/qual_is_test_imported.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/qual_is_test_imported.m,v
retrieving revision 1.1
diff -u -b -r1.1 qual_is_test_imported.m
--- tests/hard_coded/qual_is_test_imported.m	19 Oct 1995 05:44:18 -0000	1.1
+++ tests/hard_coded/qual_is_test_imported.m	7 Jul 2004 06:59:45 -0000
@@ -2,7 +2,7 @@
 
 :- interface.
 
-:- import_module io, string.
+:- import_module string.
 
 :- pred is(string::in, string::out) is det.
 :- pred foobar(string::in, string::out) is det.
cvs server: Diffing tests/hard_coded/exceptions
cvs server: Diffing tests/hard_coded/purity
cvs server: Diffing tests/hard_coded/sub-modules
cvs server: Diffing tests/hard_coded/typeclasses
cvs server: Diffing tests/invalid
Index: tests/invalid/aditi_private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/aditi_private_builtin.m,v
retrieving revision 1.2
diff -u -b -r1.2 aditi_private_builtin.m
--- tests/invalid/aditi_private_builtin.m	23 Aug 2003 14:01:53 -0000	1.2
+++ tests/invalid/aditi_private_builtin.m	7 Jul 2004 06:59:46 -0000
@@ -2,7 +2,6 @@
 
 :- interface.
 
-:- import_module io.
 :- import_module aditi.
 
 :- type relation_ticket == c_pointer.
cvs server: Diffing tests/invalid/purity
cvs server: Diffing tests/misc_tests
cvs server: Diffing tests/mmc_make
cvs server: Diffing tests/mmc_make/lib
cvs server: Diffing tests/recompilation
cvs server: Diffing tests/tabling
cvs server: Diffing tests/term
cvs server: Diffing tests/valid
cvs server: Diffing tests/warnings
cvs server: Diffing tools
Index: tools/makebatch
===================================================================
RCS file: /home/mercury1/repository/mercury/tools/makebatch,v
retrieving revision 1.25
diff -u -b -r1.25 makebatch
--- tools/makebatch	12 Apr 2003 03:36:21 -0000	1.25
+++ tools/makebatch	7 Jul 2004 06:59:46 -0000
@@ -25,12 +25,13 @@
 # that version. When makebatch exits normally, it removes the file to indicate
 # completion.
 
-usage="Usage: makebatch [-jN] [-cdeost] [--compile-times] [--test-params] batchname"
+usage="Usage: makebatch [-jN] [-cdeost] [--compile-times] [--save-stage2-on-error] [--test-params] batchname"
 jfactor=-j1
 runtests=""
 objects=""
 cfiles="false"
 save_stage2="false"
+save_stage2_on_error="false"
 errfiles="false"
 compile_times=""
 testparams=""
@@ -59,6 +60,9 @@
 	-o|--object-files)
 		objects="-k" ;;
 
+	--save-stage2-on-error)
+		save_stage2_on_error="true" ;;
+
 	-s|--stop-at-failure)
 		failed="stop" ;;
 
@@ -185,9 +189,11 @@
 	fi
 
 	echo starting bootcheck of version $visn
+	succeeded=false
 	if tools/bootcheck $gradeopt --copy-runtime $jfactor $runtests \
 	   $objects $compile_times $testparams > batch/$batch.out.$visn 2>&1
 	then
+		succeeded=true
 		echo bootcheck of version $visn succeeded
 		cp stage2/compiler/mercury_compile batch/$batch.mercury_compile.$visn
 		size batch/$batch.mercury_compile.$visn | tail -1 | sed -e 's/mercury_compile.//' | sed -e 's/batch\///' >> batch/$batch.sizes
@@ -254,6 +260,10 @@
 		# If a directory with this name already exists,
 		# it probably came from a previous invocation of this script.
 		# This invocation supersedes earlier ones.
+		/bin/rm -fr stage2.batch.$visn > /dev/null
+		mv stage2 stage2.batch.$visn
+	elif $save_stage2_on_error && test $succeeded = false
+	then
 		/bin/rm -fr stage2.batch.$visn > /dev/null
 		mv stage2 stage2.batch.$visn
 	fi
cvs server: Diffing trace
Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.70
diff -u -b -r1.70 mercury_trace.c
--- trace/mercury_trace.c	21 Jun 2004 03:17:03 -0000	1.70
+++ trace/mercury_trace.c	7 Jul 2004 06:59:46 -0000
@@ -480,7 +480,7 @@
 
         /* in case MR_global_hp is transient */
     MR_restore_transient_registers();
-    MR_saved_global_hp(saved_regs) = MR_global_hp;
+    MR_saved_global_hp_word(saved_regs) = (MR_Word) MR_global_hp;
     MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, saved_regs);
     return jumpaddr;
 }
@@ -727,9 +727,9 @@
     ** it reflect its state at the time of the entry to the retried call.
     */
 
-    MR_saved_sp(saved_regs) = base_sp;
-    MR_saved_curfr(saved_regs) = base_curfr;
-    MR_saved_maxfr(saved_regs) = base_maxfr;
+    MR_saved_sp_word(saved_regs) = (MR_Word) base_sp;
+    MR_saved_curfr_word(saved_regs) = (MR_Word) base_curfr;
+    MR_saved_maxfr_word(saved_regs) = (MR_Word) base_maxfr;
 
     /*
     ** If the retried call is shallow traced, it must have been called from
@@ -765,9 +765,10 @@
         MR_print_succip_reg(stdout, saved_regs);
         MR_print_stack_regs(stdout, saved_regs);
 #endif
-        MR_saved_succip(saved_regs) = (MR_Word *) MR_based_stackvar(this_frame,
-                MR_LONG_LVAL_NUMBER(location));
-        MR_saved_sp(saved_regs) -= level_layout->MR_sle_stack_slots;
+        MR_saved_succip_word(saved_regs) =
+            MR_based_stackvar(this_frame, MR_LONG_LVAL_NUMBER(location));
+        MR_saved_sp_word(saved_regs) = (MR_Word)
+            (MR_saved_sp(saved_regs) - level_layout->MR_sle_stack_slots);
 #ifdef  MR_DEBUG_RETRY
         MR_print_succip_reg(stdout, saved_regs);
         MR_print_stack_regs(stdout, saved_regs);
@@ -799,9 +800,9 @@
         MR_print_succip_reg(stdout, saved_regs);
         MR_print_stack_regs(stdout, saved_regs);
 #endif
-        MR_saved_succip(saved_regs) = MR_succip_slot(this_frame);
-        MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
-        MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
+        MR_saved_succip_word(saved_regs) = MR_succip_slot_word(this_frame);
+        MR_saved_curfr_word(saved_regs) = MR_succfr_slot_word(this_frame);
+        MR_saved_maxfr_word(saved_regs) = MR_prevfr_slot_word(this_frame);
 #ifdef  MR_DEBUG_RETRY
         MR_print_succip_reg(stdout, saved_regs);
         MR_print_stack_regs(stdout, saved_regs);
@@ -828,7 +829,7 @@
     }
 
     for (i = 1; i < arg_max; i++) {
-        MR_saved_reg(saved_regs, i) = args[i];
+        MR_saved_reg_assign(saved_regs, i, args[i]);
     }
 
     if (has_io_state && found_io_action_counter) {
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.67
diff -u -b -r1.67 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	15 Jun 2004 05:35:13 -0000	1.67
+++ trace/mercury_trace_declarative.c	7 Jul 2004 06:59:46 -0000
@@ -1061,10 +1061,11 @@
 void
 MR_decl_add_trusted_module(const char *module_name)
 {
-	MR_ConstString aligned_module_name;
+	MR_String aligned_module_name;
 	
 	MR_TRACE_USE_HP(
-		MR_make_aligned_string(aligned_module_name, module_name);
+		MR_make_aligned_string(aligned_module_name,
+			(MR_String) module_name);
 	);
 	MR_trace_decl_ensure_init();
 	MR_TRACE_CALL_MERCURY(
Index: trace/mercury_trace_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.c,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_trace_util.c
--- trace/mercury_trace_util.c	12 Mar 2004 06:02:19 -0000	1.11
+++ trace/mercury_trace_util.c	7 Jul 2004 06:59:46 -0000
@@ -133,20 +133,20 @@
 {
 #ifndef MR_HIGHLEVEL_CODE
 	fprintf(fp, "r1 = %ld (%lx)\n",
-		(long) MR_saved_reg(saved_regs, 1),
-		(long) MR_saved_reg(saved_regs, 1));
+		(long) MR_saved_reg_value(saved_regs, 1),
+		(long) MR_saved_reg_value(saved_regs, 1));
 	fprintf(fp, "r2 = %ld (%lx)\n",
-		(long) MR_saved_reg(saved_regs, 2),
-		(long) MR_saved_reg(saved_regs, 2));
+		(long) MR_saved_reg_value(saved_regs, 2),
+		(long) MR_saved_reg_value(saved_regs, 2));
 	fprintf(fp, "r3 = %ld (%lx)\n",
-		(long) MR_saved_reg(saved_regs, 3),
-		(long) MR_saved_reg(saved_regs, 3));
+		(long) MR_saved_reg_value(saved_regs, 3),
+		(long) MR_saved_reg_value(saved_regs, 3));
 	fprintf(fp, "r4 = %ld (%lx)\n",
-		(long) MR_saved_reg(saved_regs, 4),
-		(long) MR_saved_reg(saved_regs, 4));
+		(long) MR_saved_reg_value(saved_regs, 4),
+		(long) MR_saved_reg_value(saved_regs, 4));
 	fprintf(fp, "r5 = %ld (%lx)\n",
-		(long) MR_saved_reg(saved_regs, 5),
-		(long) MR_saved_reg(saved_regs, 5));
+		(long) MR_saved_reg_value(saved_regs, 5),
+		(long) MR_saved_reg_value(saved_regs, 5));
 #endif
 }
 
cvs server: Diffing util
cvs server: Diffing vim
cvs server: Diffing vim/after
cvs server: Diffing vim/ftplugin
cvs server: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list