[m-rev.] Re: for review: user-friendly representation of streams

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 25 20:43:10 AEST 2002


Here's the large part.

----------

The large change is the change in the representation of io__streams. The
change allows the debugger to print meaningful information about streams,
not just <<c_pointer>>. It also allows the library and the debugger to handle
streams much more safely internally.

runtime/mercury_library_types.h:
	Add an MR_ prefix to the name of the MercuryFile type. Redefine both
	versions of the type (with and without the new MercuryFile configure
	option) to contain a name and a unique identifier. Update the macros
	operating on both versions of the type accordingly. Define the type
	MR_MercuryFilePtr to point to these structures.

	Add prefixes to structure field names and to macros.

library/io.m:
	Change the definition of the io__stream type to be a foreign type,
	to wit, MR_MercuryFilePtr. This improves safety by allowing us to
	avoid a *large* number of casts.

	Delete the map from I/O streams to names, since it is not needed
	anymore.

	Add a new type, mercury_file_ptr, with the same definition as
	io__stream, but this one exported to the debugger. (The export is
	in the hidden, undocumented part of the interface.) Add predicates
	for use by the debugger to convert io__streams to mercury_file_ptrs
	and vice versa.

	Standardize the formating of foreign_proc pragmas.

browser/browse.m:
browser/help.m:
browser/debugger_interface.m:
browser/declarative_debugger.m:
browser/declarative_execution.m:
browser/interactive_query.m:
browser/util.m:
	Instead of exporting to the trace directory predicates that expect
	stream arguments, define and export predicates that expect
	mercury_file_ptrs. Convert these to streams as necessary.

	Make Erwan's code conform to our style conventions.

runtime/mercury_file.[ch]:
	Change the code that creates MR_MercuryFile structures accordingly.

runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
	Update the prototypes of C functions exported by io.m to reflect that
	the C type of io__streams has changed.

runtime/mercury_layout_util.c:
	Conform to the changed prototypes.

runtime/mercury_builtin_types.[ch]:
	Declare and define the type_ctor_infos of the types used by the LLDS
	backend in all the grades used by the LLDS backend. They may not be
	needed in all such grades, but keeping track of which ones are defined
	under what conditions can be complex, and the payoff (a few dozen bytes
	less memory consumption) isn't worth it.
 
trace/mercury_trace_util.[ch]:
	Delete a now unnecessary utility function.

trace/mercury_trace_browse.c:
trace/mercury_trace_declarative.[ch]:
trace/mercury_trace_external.[ch]:
trace/mercury_trace_internal.[ch]:
	Call the mercury_file_ptr versions of the relevant predicates in the
	browser directory. This avoids many casts.

	Convert FILE *s to MR_MercuryFilePtrs just once, not once for each
	call that has a mercury_file_ptr argument.
 
trace/mercury_trace_vars.c:
	Convert arguments of whose types represents streams to the more
	user-friendly representation when collecting their values. This helps
	users of all flavours of the debugger, external, procedural and
	declarative.

	Convert the lists of references to type_ctor_infos to use higher level
	names, and remove the now unnecessary #ifdefs.

tests/debugger/stream.{m,inp,exp}:
tests/debugger/DATA.in:
tests/debugger/declarative/stream.{m,inp,exp}:
tests/debugger/declarative/DATA.in:
	Two new test cases to test the printing of I/O streams. Their code
	is the same, but the input scripts differ, checking the handling
	of streams by the procedural and declarative debuggers respectively.

tests/debugger/Mmakefile:
tests/debugger/Mmakefile:
	Enable the new test cases.

cvs diff: Diffing .
cvs diff: Diffing bench
cvs diff: Diffing bench/progs
cvs diff: Diffing bench/progs/compress
cvs diff: Diffing bench/progs/icfp2000
cvs diff: Diffing bench/progs/icfp2001
cvs diff: Diffing bench/progs/nuc
cvs diff: Diffing bench/progs/ray
cvs diff: Diffing bench/progs/tree234
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
Index: browser/browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.29
diff -u -d -u -r1.29 browse.m
--- browser/browse.m	3 Jul 2002 08:25:02 -0000	1.29
+++ browser/browse.m	25 Sep 2002 10:22:50 -0000
@@ -127,24 +127,122 @@
 % they are used in trace/mercury_trace_browser.c.
 %
 
-:- pragma export(browse__browse(in, in, in, out, in, out, di, uo),
-	"ML_BROWSE_browse").
-:- pragma export(browse__browse_format(in, in, in, in, in, out, di, uo),
-	"ML_BROWSE_browse_format").
-:- pragma export(browse__browse_synthetic(in, in, in, in, in, out,
-	in, out, di, uo), "ML_BROWSE_browse_synthetic").
-:- pragma export(browse__browse_format_synthetic(in, in, in, in, in, in,
-	in, out, di, uo), "ML_BROWSE_browse_format_synthetic").
-:- pragma export(browse__browse_external(in, in, in, in, out, di, uo),
-	"ML_BROWSE_browse_external").
-:- pragma export(browse__print(in, in, in, in, di, uo),
-	"ML_BROWSE_print").
-:- pragma export(browse__print_format(in, in, in, in, in, di, uo),
-	"ML_BROWSE_print_format").
-:- pragma export(browse__print_synthetic(in, in, in, in, in, in, di, uo),
-	"ML_BROWSE_print_synthetic").
-:- pragma export(browse__print_format_synthetic(in, in, in, in, in, in, in,
-	di, uo), "ML_BROWSE_print_format_synthetic").
+:- pragma export(browse__browse_mfp(in, in, in, out, in, out, di, uo),
+	"ML_BROWSE_browse_mfp").
+:- pragma export(browse__browse_format_mfp(in, in, in, in, in, out, di, uo),
+	"ML_BROWSE_browse_format_mfp").
+:- pragma export(browse__browse_synthetic_mfp(in, in, in, in, in, out,
+	in, out, di, uo), "ML_BROWSE_browse_synthetic_mfp").
+:- pragma export(browse__browse_format_synthetic_mfp(in, in, in, in, in, in,
+	in, out, di, uo), "ML_BROWSE_browse_format_synthetic_mfp").
+:- pragma export(browse__browse_external_mfp(in, in, in, in, out, di, uo),
+	"ML_BROWSE_browse_external_mfp").
+:- pragma export(browse__print_mfp(in, in, in, in, di, uo),
+	"ML_BROWSE_print_mfp").
+:- pragma export(browse__print_format_mfp(in, in, in, in, in, di, uo),
+	"ML_BROWSE_print_format_mfp").
+:- pragma export(browse__print_synthetic_mfp(in, in, in, in, in, in, di, uo),
+	"ML_BROWSE_print_synthetic_mfp").
+:- pragma export(browse__print_format_synthetic_mfp(in, in, in, in, in, in, in,
+	di, uo), "ML_BROWSE_print_format_synthetic_mfp").
+
+:- pred browse__browse_mfp(T::in, mercury_file_ptr::in, mercury_file_ptr::in,
+	maybe(list(dir))::out,
+	browser_persistent_state::in, browser_persistent_state::out,
+	io__state::di, io__state::uo) is cc_multi.
+
+browse__browse_mfp(Object, InputMfp, OutputMfp, MaybeMark, State0, State) -->
+	{ io__input_stream_from_mfp(InputStream, InputMfp) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__browse(Object, InputStream, OutputStream, MaybeMark,
+		State0, State).
+
+:- pred browse__browse_format_mfp(T::in, mercury_file_ptr::in,
+	mercury_file_ptr::in, portray_format::in,
+	browser_persistent_state::in, browser_persistent_state::out,
+	io__state::di, io__state::uo) is cc_multi.
+
+browse__browse_format_mfp(Object, InputMfp, OutputMfp, Format, State0, State)
+		-->
+	{ io__input_stream_from_mfp(InputStream, InputMfp) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__browse_format(Object, InputStream, OutputStream, Format,
+		State0, State).
+
+:- pred browse__browse_synthetic_mfp(string::in, list(univ)::in, bool::in,
+	mercury_file_ptr::in, mercury_file_ptr::in, maybe(list(dir))::out,
+	browser_persistent_state::in, browser_persistent_state::out,
+	io__state::di, io__state::uo) is cc_multi.
+
+browse__browse_synthetic_mfp(FunctorString, Args, IsFunc,
+		InputMfp, OutputMfp, MaybeMark, State0, State) -->
+	{ io__input_stream_from_mfp(InputStream, InputMfp) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__browse_synthetic(FunctorString, Args, IsFunc,
+		InputStream, OutputStream, MaybeMark, State0, State).
+
+:- pred browse__browse_format_synthetic_mfp(string::in, list(univ)::in,
+	bool::in, mercury_file_ptr::in, mercury_file_ptr::in,
+	portray_format::in,
+	browser_persistent_state::in, browser_persistent_state::out,
+	io__state::di, io__state::uo) is cc_multi.
+
+browse__browse_format_synthetic_mfp(FunctorString, Args, IsFunc,
+		InputMfp, OutputMfp, Format, State0, State) -->
+	{ io__input_stream_from_mfp(InputStream, InputMfp) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__browse_format_synthetic(FunctorString, Args, IsFunc,
+		InputStream, OutputStream, Format, State0, State).
+
+:- pred browse__browse_external_mfp(T::in,
+	mercury_file_ptr::in, mercury_file_ptr::in,
+	browser_persistent_state::in, browser_persistent_state::out,
+	io__state::di, io__state::uo) is cc_multi.
+
+browse__browse_external_mfp(Object, InputMfp, OutputMfp, State0, State) -->
+	{ io__input_stream_from_mfp(InputStream, InputMfp) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__browse_external(Object, InputStream, OutputStream,
+		State0, State).
+
+:- pred browse__print_mfp(T::in, mercury_file_ptr::in, browse_caller_type::in,
+	browser_persistent_state::in, io__state::di, io__state::uo)
+	is cc_multi.
+
+browse__print_mfp(Term, OutputMfp, Caller, State) -->
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__print(Term, OutputStream, Caller, State).
+
+:- pred browse__print_synthetic_mfp(string::in, list(univ)::in, bool::in,
+	mercury_file_ptr::in, browse_caller_type::in,
+	browser_persistent_state::in, io__state::di, io__state::uo)
+	is cc_multi.
+
+browse__print_synthetic_mfp(FunctorString, Args, IsFunc, OutputMfp, Caller,
+		State) -->
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__print_synthetic(FunctorString, Args, IsFunc,
+		OutputStream, Caller, State).
+
+:- pred browse__print_format_mfp(T::in, mercury_file_ptr::in,
+	browse_caller_type::in, portray_format::in,
+	browser_persistent_state::in, io__state::di, io__state::uo)
+	is cc_multi.
+
+browse__print_format_mfp(Term, OutputMfp, Caller, Format, State) -->
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__print_format(Term, OutputStream, Caller, Format, State).
+
+:- pred browse__print_format_synthetic_mfp(string::in, list(univ)::in, bool::in,
+	mercury_file_ptr::in, browse_caller_type::in, portray_format::in,
+	browser_persistent_state::in, io__state::di, io__state::uo)
+	is cc_multi.
+
+browse__print_format_synthetic_mfp(FunctorString, Args, IsFunc, OutputMfp,
+		Caller, Format, State) -->
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
+	browse__print_format_synthetic(FunctorString, Args, IsFunc,
+		OutputStream, Caller, Format, State).
 
 %---------------------------------------------------------------------------%
 % If the term browser is called from the internal debugger, input is
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.19
diff -u -d -u -r1.19 debugger_interface.m
--- browser/debugger_interface.m	22 Jun 2001 15:20:22 -0000	1.19
+++ browser/debugger_interface.m	25 Sep 2002 10:22:50 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998-2001 The University of Melbourne.
+% Copyright (C) 1998-2002 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.
 %-----------------------------------------------------------------------------%
@@ -44,7 +44,6 @@
 	% encoded as specified in ../runtime/mercury_stack_layout.h
 	% and ../compiler/stack_layout.m.
 
-
 % Depending whether the Opium side is requesting for a user defined procedure
 % or a compiler generated one, the event has not exactly the same structure.
 % The differences between the two types of event are gathered in a forward_move
@@ -159,7 +158,6 @@
 :- type call_number == int.
 :- type depth_number == int.
 
-
 % `match' is called "get status" in the Opium documentation.
 % This type defines a unary predicate which determines whether
 % or not a particular value will be selected.
@@ -171,7 +169,6 @@
 	;	interval(T,T)	% interval(Low, High): Low =< X, X =< High
 	.
 
-
 % The debugger_response type is used for response sent
 % to the debugger process from the Mercury program being debugged.
 :- type debugger_response
@@ -268,7 +265,6 @@
 	;	collect_arg_off_ok
 	.
 
-
 %-----------------------------------------------------------------------------%
 %	send to the debugger (e.g. Opium) the wanted features.
 
@@ -283,18 +279,17 @@
 	trace_port_type, pred_or_func, /* declarated module name */ string,
 	/* definition module name */ string, /* pred name */ string, arity, 
 	/* mode num */ int, determinism, goal_path_string, line_number,
-	io__output_stream, io__state, io__state).
+	mercury_file_ptr, io__state, io__state).
 :- mode output_current_slots_user(in, in, in, in, in, in, in, in, in, in, 
 	in, in, in, in, di, uo) is det.
 
-
 output_current_slots_user(EventNumber, CallNumber, DepthNumber, Port, 
-	PredOrFunc, DeclModuleName, DefModuleName, PredName, Arity, ModeNum, 
-	Determinism, Path, LineNo, OutputStream) -->
-	
+		PredOrFunc, DeclModuleName, DefModuleName, PredName, Arity,
+		ModeNum, Determinism, Path, LineNo, OutputMfp) -->
 	{ CurrentTraceInfo = current_slots_user(EventNumber, CallNumber, 
 		DepthNumber, Port, PredOrFunc, DeclModuleName, DefModuleName, 
 		PredName, Arity, ModeNum, Determinism, Path, LineNo) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
@@ -310,18 +305,17 @@
 	trace_port_type, /* name type */ string, /* module type */ string,
 	/* definition module */ string, /* pred name */ string, arity, 
 	/* mode num */ int, determinism, goal_path_string, line_number,
-	io__output_stream, io__state, io__state).
+	mercury_file_ptr, io__state, io__state).
 :- mode output_current_slots_comp(in, in, in, in, in, in, in, in, in, in, 
 	in, in, in, in, di, uo) is det.
 
-
 output_current_slots_comp(EventNumber, CallNumber, DepthNumber, Port, 
 	NameType, ModuleType, DefModuleName, PredName, Arity, 
-	ModeNum, Determinism, Path, LineNo, OutputStream) -->
-	
+		ModeNum, Determinism, Path, LineNo, OutputMfp) -->
 	{ CurrentTraceInfo = current_slots_comp(EventNumber, CallNumber, 
 		DepthNumber, Port, NameType, ModuleType, DefModuleName, 
 		PredName, Arity, ModeNum, Determinism, Path, LineNo) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
@@ -334,13 +328,12 @@
 	"ML_DI_output_current_vars").
 			
 :- pred output_current_vars(list(univ), list(string), 
-	io__output_stream, io__state, io__state).
+	mercury_file_ptr, io__state, io__state).
 :- mode output_current_vars(in, in, in, di, uo) is det.
 
-
-output_current_vars(VarList, StringList, OutputStream) -->
-		
+output_current_vars(VarList, StringList, OutputMfp) -->
 	{ CurrentTraceInfo = current_vars(VarList, StringList) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
@@ -351,31 +344,27 @@
 :- pragma export(output_current_nth_var(in, in, di, uo), 
 	"ML_DI_output_current_nth_var").
 			
-:- pred output_current_nth_var(univ, io__output_stream, io__state, io__state).
+:- pred output_current_nth_var(univ, mercury_file_ptr, io__state, io__state).
 :- mode output_current_nth_var(in, in, di, uo) is det.
 
-
-output_current_nth_var(Var, OutputStream) -->
-		
+output_current_nth_var(Var, OutputMfp) -->
 	{ CurrentTraceInfo = current_nth_var(Var) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
 
-
 :- pragma export(output_current_live_var_names(in, in, in, di, uo), 
 	"ML_DI_output_current_live_var_names").
 			
 :- pred output_current_live_var_names(list(string), list(string),
-	io__output_stream, io__state, io__state).
+	mercury_file_ptr, io__state, io__state).
 :- mode output_current_live_var_names(in, in, in, di, uo) is det.
 
-
-output_current_live_var_names(LiveVarNameList, LiveVarTypeList, 
-	OutputStream) -->
-		
-	{ CurrentTraceInfo = current_live_var_names(
-				LiveVarNameList, LiveVarTypeList) },
+output_current_live_var_names(LiveVarNameList, LiveVarTypeList, OutputMfp) -->
+	{ CurrentTraceInfo = current_live_var_names(LiveVarNameList,
+		LiveVarTypeList) },
+	{ io__output_stream_from_mfp(OutputStream, OutputMfp) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
@@ -428,13 +417,12 @@
 		match(MatchDepthNumber, DepthNumber),
 		match(MatchPort, Port),
 		(
-		if
 			UserPredMatch = match_user_pred(
 				MatchPredOrFunc, MatchDeclModuleName)
-		then
+		->
 			match(MatchPredOrFunc, PredOrFunc),
 			match(MatchDeclModuleName, DeclModuleName)
-		else
+		;
 			UserPredMatch = match_any_pred
 		),
 		match(MatchDefModuleName, DefModuleName),
@@ -448,7 +436,6 @@
 		error("found_match: forward_move expected")
 	).
 
-
 % match(MatchPattern, Value) is true iff Value matches the specified pattern.
 :- pred match(match(T), T).
 :- mode match(in, in) is semidet.
@@ -464,7 +451,6 @@
 	compare(GE, X, Low), 
 	(GE = (>) ; GE = (=)).
 
-
 :- pragma export(found_match_comp(in, in, in, in, in, in, in, in, in, in, in,
 			in, in, in), "ML_DI_found_match_comp").
 			
@@ -493,14 +479,13 @@
 		match(MatchDepthNumber, DepthNumber),
 		match(MatchPort, Port),
 		(
-		if
 			CompilerGeneratedPredMatch = 
 				match_compiler_generated_pred(MatchNameType,
 			MatchModuleType)
-		then
+		->
 			match(MatchNameType, NameType),
 			match(MatchModuleType, ModuleType)
-		else
+		;
 			CompilerGeneratedPredMatch = match_any_pred
 		),
 		match(MatchDefModuleName, DefModuleName),
@@ -514,18 +499,16 @@
 		error("found_match: forward_move expected")
 	).
 
-
 %-----------------------------------------------------------------------------%
 
-:- pred read_request_from_socket(io__input_stream, debugger_request, int,
-		io__state, io__state).
-			
-:- mode read_request_from_socket(in, out, out, di, uo) is det.
+:- pred read_request_from_socket(mercury_file_ptr::in, debugger_request::out,
+	int::out, io__state::di, io__state::uo) is det.
 
 :- pragma export(read_request_from_socket(in, out, out, di, uo),
 		"ML_DI_read_request_from_socket").
 
-read_request_from_socket(SocketStream, Request, RequestType) -->
+read_request_from_socket(SocketMfp, Request, RequestType) -->
+	{ io__input_stream_from_mfp(SocketStream, SocketMfp) },
 	io__read(SocketStream, MaybeRequest),
 	( { MaybeRequest = ok(Request0) },
 		{ Request = Request0 }
@@ -546,7 +529,6 @@
 	io__print(StdErr, ".\n").
 	***********/
 
-
 %-----------------------------------------------------------------------------%
 
 :- pred get_list_modules_to_import(debugger_request, int, imports).
@@ -588,6 +570,7 @@
 	;
 		error("get_mmc_options: not a mmc_options request")
 	).
+
 %-----------------------------------------------------------------------------%
 
 :- pred get_object_file_name(debugger_request, string).
@@ -663,6 +646,5 @@
 classify_request(current_grade,20).
 classify_request(collect_arg_on,21).
 classify_request(collect_arg_off,22).
-
 
 %-----------------------------------------------------------------------------%
Index: browser/declarative_debugger.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_debugger.m,v
retrieving revision 1.32
diff -u -d -u -r1.32 declarative_debugger.m
--- browser/declarative_debugger.m	13 Sep 2002 04:17:39 -0000	1.32
+++ browser/declarative_debugger.m	25 Sep 2002 10:22:50 -0000
@@ -401,14 +401,16 @@
 	% Export a monomorphic version of diagnosis_state_init/4, to
 	% make it easier to call from C code.
 	%
-:- pred diagnoser_state_init_store(io__input_stream, io__output_stream,
+:- pred diagnoser_state_init_store(mercury_file_ptr, mercury_file_ptr,
 		diagnoser_state(trace_node_id)).
 :- mode diagnoser_state_init_store(in, in, out) is det.
 
 :- pragma export(diagnoser_state_init_store(in, in, out),
 		"MR_DD_decl_diagnosis_state_init").
 
-diagnoser_state_init_store(InStr, OutStr, Diagnoser) :-
+diagnoser_state_init_store(InMfp, OutMfp, Diagnoser) :-
+	io__input_stream_from_mfp(InStr, InMfp),
+	io__output_stream_from_mfp(OutStr, OutMfp),
 	diagnoser_state_init(map__init, InStr, OutStr, Diagnoser).
 
 	% Export a monomorphic version of diagnosis/10, to make it
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.21
diff -u -d -u -r1.21 declarative_execution.m
--- browser/declarative_execution.m	13 Sep 2002 04:17:40 -0000	1.21
+++ browser/declarative_execution.m	25 Sep 2002 10:22:50 -0000
@@ -1063,8 +1063,15 @@
 		throw(io_error("load_trace_node_map", Msg))
 	}.
 
-:- pragma export(save_trace_node_store(in, in, in, di, uo),
-		"MR_DD_save_trace").
+:- pred save_trace_node_store_mfp(mercury_file_ptr::in, trace_node_store::in,
+	trace_node_id::in, io__state::di, io__state::uo) is det.
+
+:- pragma export(save_trace_node_store_mfp(in, in, in, di, uo),
+	"MR_DD_save_trace_mfp").
+
+save_trace_node_store_mfp(Mfp, Store, NodeId) -->
+	{ io__output_stream_from_mfp(Stream, Mfp) },
+	save_trace_node_store(Stream, Store, NodeId).
 
 save_trace_node_store(Stream, Store, NodeId) -->
 	{ map__init(Map0) },
Index: browser/help.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/help.m,v
retrieving revision 1.3
diff -u -d -u -r1.3 help.m
--- browser/help.m	24 Mar 2000 10:27:20 -0000	1.3
+++ browser/help.m	25 Sep 2002 10:22:50 -0000
@@ -99,11 +99,32 @@
 :- pragma export(help__init(out), "ML_HELP_init").
 :- pragma export(help__add_help_node(in, in, in, in, in, out, out),
 	"ML_HELP_add_help_node").
-:- pragma export(help__help(in, in, di, uo), "ML_HELP_help").
-:- pragma export(help__path(in, in, in, out, di, uo), "ML_HELP_path").
-:- pragma export(help__name(in, in, in, di, uo), "ML_HELP_name").
+:- pragma export(help__help_mfp(in, in, di, uo), "ML_HELP_help_mfp").
+:- pragma export(help__path_mfp(in, in, in, out, di, uo), "ML_HELP_path_mfp").
+:- pragma export(help__name_mfp(in, in, in, di, uo), "ML_HELP_name_mfp").
 :- pragma export(help__help_system_type(out), "ML_HELP_help_system_type").
 :- pragma export(help__result_is_error(in, out), "ML_HELP_result_is_error").
+
+:- pred help__help_mfp(help__system::in, mercury_file_ptr::in,
+	io__state::di, io__state::uo) is det.
+
+help__help_mfp(Sys, Mfp) -->
+	{ io__output_stream_from_mfp(Stream, Mfp) },
+	help__help(Sys, Stream).
+
+:- pred help__path_mfp(help__system::in, help__path::in, mercury_file_ptr::in,
+	help__res::out, io__state::di, io__state::uo) is det.
+
+help__path_mfp(Entries, Path, Mfp, Result) -->
+	{ io__output_stream_from_mfp(Stream, Mfp) },
+	help__path(Entries, Path, Stream, Result).
+
+:- pred help__name_mfp(help__system::in, string::in, mercury_file_ptr::in,
+	io__state::di, io__state::uo) is det.
+
+help__name_mfp(Sys, Name, Mfp) -->
+	{ io__output_stream_from_mfp(Stream, Mfp) },
+	help__name(Sys, Name, Stream).
 
 %-----------------------------------------------------------------------------%
 
Index: browser/interactive_query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/interactive_query.m,v
retrieving revision 1.16
diff -u -d -u -r1.16 interactive_query.m
--- browser/interactive_query.m	1 Jul 2002 09:27:10 -0000	1.16
+++ browser/interactive_query.m	25 Sep 2002 10:22:50 -0000
@@ -21,13 +21,13 @@
 
 :- pred query(query_type::in, imports::in, options::in,
 		io__input_stream::in, io__output_stream::in,
-		state::di, state::uo) is det.
+	io__state::di, io__state::uo) is det.
 
 % query_external/7 is the same as query/7 but for the use of the external 
 % debugger.
 :- pred query_external(query_type::in, imports::in, options::in,
 		io__input_stream::in, io__output_stream::in,
-		state::di, state::uo) is det.
+	io__state::di, io__state::uo) is det.
 
 :- type query_type ---> normal_query ; cc_query ; io_query.
 :- type imports == list(string).
@@ -38,10 +38,19 @@
 :- import_module mdb__dl, mdb__name_mangle.
 :- import_module mdb__util.
 
-:- pragma export(query(in, in, in, in, in, di, uo), "ML_query").
-
 :- type prog ---> prog(query_type, imports, term, varset).
 
+:- pragma export(query_mfp(in, in, in, in, in, di, uo), "ML_query_mfp").
+
+:- pred query_mfp(query_type::in, imports::in, options::in,
+	mercury_file_ptr::in, mercury_file_ptr::in,
+	io__state::di, io__state::uo) is det.
+
+query_mfp(QueryType, Imports, Options, MDB_StdinMfp, MDB_StdoutMfp) -->
+	{ io__input_stream_from_mfp(MDB_Stdin, MDB_StdinMfp) },
+	{ io__output_stream_from_mfp(MDB_Stdout, MDB_StdoutMfp) },
+	query(QueryType, Imports, Options, MDB_Stdin, MDB_Stdout).
+
 query(QueryType, Imports, Options, MDB_Stdin, MDB_Stdout) -->
 	% write_import_list(Imports),
 	util__trace_getline(query_prompt(QueryType), Result,
@@ -61,7 +70,7 @@
 
 :- pred query_2(query_type::in, imports::in, options::in,
 		io__input_stream::in, io__output_stream::in,
-		read_term(generic)::in, state::di, state::uo) is det.
+	read_term(generic)::in, io__state::di, io__state::uo) is det.
 
 query_2(QueryType, Imports, Options, MDB_Stdin, MDB_Stdout, ReadTerm) -->
 	( { ReadTerm = eof },
@@ -108,8 +117,17 @@
 	;	iq_error(string)
 	.
 
-:- pragma export(query_external(in, in, in, in, in, di, uo), 
-	"ML_query_external").
+:- pred query_external_mfp(query_type::in, imports::in, options::in,
+	mercury_file_ptr::in, mercury_file_ptr::in,
+	io__state::di, io__state::uo) is det.
+
+:- pragma export(query_external_mfp(in, in, in, in, in, di, uo), 
+	"ML_query_external_mfp").
+
+query_external_mfp(QueryType, Imports, Options, SocketInMfp, SocketOutMfp) -->
+	{ io__input_stream_from_mfp(SocketIn, SocketInMfp) },
+	{ io__output_stream_from_mfp(SocketOut, SocketOutMfp) },
+	query_external(QueryType, Imports, Options, SocketIn, SocketOut).
 
 query_external(QueryType, Imports, Options, SocketIn, SocketOut) -->
 	io__set_input_stream(SocketIn, OldStdin),
Index: browser/util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/util.m,v
retrieving revision 1.20
diff -u -d -u -r1.20 util.m
--- browser/util.m	16 Sep 2002 02:26:15 -0000	1.20
+++ browser/util.m	25 Sep 2002 10:22:50 -0000
@@ -96,8 +96,14 @@
 		Result = eof
 	}.
 
-:- pred call_trace_getline(input_stream::in, output_stream::in, string::in,
-	string::out, int::out, io__state::di, io__state::uo) is det.
+:- pred call_trace_getline(io__input_stream::in, io__output_stream::in,
+	string::in, string::out, int::out, io__state::di, io__state::uo)
+	is det.
+
+call_trace_getline(MdbIn, MdbOut, Prompt, Line, Success) -->
+	{ io__input_stream_to_mfp(MdbIn, MdbInMfp) },
+	{ io__output_stream_to_mfp(MdbOut, MdbOutMfp) },
+	call_trace_getline_mfp(MdbInMfp, MdbOutMfp, Prompt, Line, Success).
 
 :- pragma c_header_code("
 	#include ""mercury_wrapper.h""
@@ -107,8 +113,12 @@
 	#include ""mercury_library_types.h""
 ").
 
+:- pred call_trace_getline_mfp(mercury_file_ptr::in, mercury_file_ptr::in,
+	string::in, string::out, int::out, io__state::di, io__state::uo)
+	is det.
+
 :- pragma foreign_proc("C",
-	call_trace_getline(MdbIn::in, MdbOut::in, Prompt::in, Line::out,
+	call_trace_getline_mfp(MdbIn::in, MdbOut::in, Prompt::in, Line::out,
 		Success::out, IO0::di, IO::uo),
 	% We need to use will_not_call_mercury here,
 	% because MR_make_aligned_string_copy() references MR_hp,
@@ -116,12 +126,10 @@
 	[will_not_call_mercury, promise_pure, tabled_for_io],
 "
 	char		*line;
-	MercuryFile	*mdb_in = (MercuryFile *) MdbIn;
-	MercuryFile	*mdb_out = (MercuryFile *) MdbOut;
 
 	if (MR_address_of_trace_getline != NULL) {
 		line = (*MR_address_of_trace_getline)((char *) Prompt,
-				MR_file(*mdb_in), MR_file(*mdb_out));
+			MR_mf_file(*MdbIn), MR_mf_file(*MdbOut));
 	} else {
 		MR_tracing_not_enabled();
 		/* not reached */
@@ -145,19 +153,25 @@
 	io__output_stream(MdbOut),
 	util__trace_get_command(Prompt, Result, MdbIn, MdbOut).
 
+util__trace_get_command(Prompt, Result, In, Out) -->
+	{ io__input_stream_to_mfp(In, InMfp) },
+	{ io__output_stream_to_mfp(Out, OutMfp) },
+	util__trace_get_command_mfp(Prompt, Result, InMfp, OutMfp).
+
+:- pred util__trace_get_command_mfp(string::in, string::out,
+	mercury_file_ptr::in, mercury_file_ptr::in,
+	io__state::di, io__state::uo) is det.
+
 :- pragma foreign_proc("C",
-	util__trace_get_command(Prompt::in, Line::out, MdbIn::in,
-		MdbOut::in, State0::di, State::uo),
+	util__trace_get_command_mfp(Prompt::in, Line::out,
+		In::in, Out::in, State0::di, State::uo),
 	[will_not_call_mercury, promise_pure, tabled_for_io],
 "
 	char		*line;
-	MercuryFile	*mdb_in = (MercuryFile *) MdbIn;
-	MercuryFile	*mdb_out = (MercuryFile *) MdbOut;
 
 	if (MR_address_of_trace_getline != NULL) {
-		line = (*MR_address_of_trace_get_command)(
-				(char *) Prompt,
-				MR_file(*mdb_in), MR_file(*mdb_out));
+		line = (*MR_address_of_trace_get_command)((char *) Prompt,
+			MR_mf_file(*In), MR_mf_file(*Out));
 	} else {
 		MR_tracing_not_enabled();
 		/* not reached */
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.266
diff -u -d -u -r1.266 io.m
--- library/io.m	24 Sep 2002 06:55:17 -0000	1.266
+++ library/io.m	25 Sep 2002 10:23:04 -0000
@@ -317,8 +317,6 @@
 :- mode io__ignore_whitespace(in, out, di, uo) is det.
 %		Discards all the whitespace from the specified stream.
 
-
-
 %-----------------------------------------------------------------------------%
 
 % Text output predicates.
@@ -713,7 +711,6 @@
 :- mode io__set_output_line_number(in, in, di, uo) is det.
 %	Set the line number of the specified output stream.
 
-
 %-----------------------------------------------------------------------------%
 
 % Binary input predicates.
@@ -1270,6 +1267,37 @@
 :- func io__handle_system_command_exit_status(int) =
 		io__res(io__system_result).
 
+	% This type represents io__streams (input and output, text and binary)
+	% for the C code in the debugger implementation. It and the predicates
+	% that operate on it are exported to the debugger.
+
+	% The definition of io__stream should be kept the same as the
+	% definition of mercury_file_ptr.
+:- type mercury_file_ptr --->	mercury_file_ptr(c_pointer).
+:- pragma foreign_type("C", mercury_file_ptr, "MR_MercuryFilePtr").
+:- pragma foreign_type(il, mercury_file_ptr, "class [mscorlib]System.Object").
+
+:- pred io__input_stream_to_mfp(io__input_stream::in, mercury_file_ptr::out)
+	is det.
+:- pred io__output_stream_to_mfp(io__output_stream::in, mercury_file_ptr::out)
+	is det.
+
+:- pred io__input_stream_from_mfp(io__input_stream::out, mercury_file_ptr::in)
+	is det.
+:- pred io__output_stream_from_mfp(io__output_stream::out, mercury_file_ptr::in)
+	is det.
+
+	% This type represents io__streams (input and output, text and binary)
+	% for the users of the debugger. It and the predicates that operate
+	% on it are exported to the debugger.
+	%
+	% The arguments give the values of the id and name fields of
+	% MR_MercuryFile structures respectively.
+
+:- type io__stream_rep	--->	stream_rep(int, string).
+
+:- pred io__make_stream_rep(int::in, string::in, io__stream_rep::out) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -1279,15 +1307,58 @@
 :- use_module table_builtin.
 :- use_module rtti_implementation.
 
-:- type io__state ---> io__state(c_pointer).
 	% Values of type `io__state' are never really used:
 	% instead we store data in global variables.
 	% The reason this is not defined simply as `io__state == c_pointer'
 	% is so that `type_name' produces more informative results
 	% for cases such as `type_name(main)'.
 
+:- type io__state --->	io__state(c_pointer).
+
+	% We should have a foreign_type definition of the type io__stream for
+	% every backend. The Mercury definition of the io__stream type should 
+	% never be used.
+	%
+	% The definition of io__stream should be kept the same as the
+	% definition of mercury_file_ptr.
+
+:- type io__stream --->	io__stream(c_pointer).
+:- pragma foreign_type("C", io__stream, "MR_MercuryFilePtr").
+:- pragma foreign_type(il, io__stream, "class [mscorlib]System.Object").
+% The il definition is a placeholder only.
+
+:- pragma foreign_proc("C",
+	io__input_stream_to_mfp(Stream::in, Mfp:: out),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+	Mfp = Stream;
+").
+
+:- pragma foreign_proc("C",
+	io__output_stream_to_mfp(Stream::in, Mfp:: out),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+	Mfp = Stream;
+").
+
+:- pragma foreign_proc("C",
+	io__input_stream_from_mfp(Stream::out, Mfp:: in),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+	Stream = Mfp;
+").
+
+:- pragma foreign_proc("C",
+	io__output_stream_from_mfp(Stream::out, Mfp:: in),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+	Stream = Mfp;
+").
+
+:- pragma export(io__make_stream_rep(in, in, out), "ML_io_make_stream_rep").
+io__make_stream_rep(SeqNo, Name, stream_rep(SeqNo, Name)).
+
 :- pragma foreign_decl("C", "
-	extern MR_Word		ML_io_stream_names;
 	extern MR_Word		ML_io_user_globals;
 	#if 0
 	  extern MR_Word	ML_io_ops_table;
@@ -1295,7 +1366,6 @@
 ").
 
 :- pragma foreign_code("C", "
-	MR_Word			ML_io_stream_names;
 	MR_Word			ML_io_user_globals;
 	#if 0
 	  MR_Word		ML_io_ops_table;
@@ -1303,18 +1373,11 @@
 ").
 
 :- pragma foreign_code("MC++", "
-#ifdef MR_HIGHLEVEL_DATA
-	static mercury::tree234::tree234_2 __gc	*ML_io_stream_names;
-#else
-	static MR_Word		ML_io_stream_names;
-#endif
 	static MR_Univ		ML_io_user_globals;
 	static int next_id;
 	static System::Text::ASCIIEncoding *ascii_encoder;
 ").
 
-
-:- type io__stream_names ==	map(io__stream_id, string).
 :- type io__stream_putback ==	map(io__stream_id, list(char)).
 
 :- type io__input_stream ==	io__stream.
@@ -1322,24 +1385,11 @@
 
 :- type io__binary_stream ==	io__stream.
 
-:- type io__stream == c_pointer.
-
 	% a unique identifier for an IO stream
 :- type io__stream_id == int.
 
 :- func io__get_stream_id(io__stream) = io__stream_id.
 
-/*
- * In NU-Prolog: 
- *	io__stream	--->	stream(int, int)
- *			;	user_input
- *			;	user_output
- *			;	user_error.
- * In C:
- *	io__stream	==	pointer to MercuryFile (which is defined
- *				in runtime/mercury_library_types.h)
- */
-
 	% This inter-language stuff is tricky.
 	% We communicate via ints rather than via io__result_codes because
 	% we don't want the C code to depend on how Mercury stores its
@@ -1548,10 +1598,10 @@
 		io__state, io__state).
 :- mode io__read_line_as_string_2(in, out, out, di, uo) is det.
 
-:- pragma foreign_proc("C", io__read_line_as_string_2(File::in, Res :: out,
-			RetString::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure,
-			tabled_for_io, thread_safe],
+:- pragma foreign_proc("C",
+	io__read_line_as_string_2(File::in, Res :: out, RetString::out,
+		IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
 #define ML_IO_READ_LINE_GROW(n)	((n) * 3 / 2)
 #define ML_IO_BYTES_TO_WORDS(n)	(((n) + sizeof(MR_Word) - 1) / sizeof(MR_Word))
@@ -1565,7 +1615,7 @@
 
 	Res = 0;
 	for (i = 0; char_code != '\\n'; ) {
-		char_code = mercury_getc((MercuryFile *) File);
+		char_code = mercury_getc(File);
 		if (char_code == EOF) {
 			if (i == 0) {
 				Res = -1;
@@ -1763,21 +1813,20 @@
 :- mode io__clear_err(in, di, uo) is det.
 % same as ANSI C's clearerr().
 
-:- pragma foreign_proc("C", io__clear_err(Stream::in, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure,
-			tabled_for_io, thread_safe],
+:- pragma foreign_proc("C",
+	io__clear_err(Stream::in, IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *f = (MercuryFile *) Stream;
-
-	if (MR_IS_FILE_STREAM(*f)) {
-		clearerr(MR_file(*f));
+	if (MR_IS_FILE_STREAM(*Stream)) {
+		clearerr(MR_mf_file(*Stream));
 	} else {
 		/* Not a file stream so do nothing */
 	}
 	MR_update_io(IO0, IO);
 }").
 
-:- pragma foreign_proc("MC++", io__clear_err(_Stream::in, IO0::di, IO::uo),
+:- pragma foreign_proc("MC++",
+	io__clear_err(_Stream::in, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, thread_safe],
 "{
 	// XXX no error flag to reset as in MC++ an error throws directly an
@@ -1791,7 +1840,6 @@
 	% matching foreign_proc version.
 	{ private_builtin__sorry("io__clear_err") }.
 
-
 :- pred io__check_err(stream, io__res, io__state, io__state).
 :- mode io__check_err(in, out, di, uo) is det.
 
@@ -1807,15 +1855,12 @@
 :- mode io__ferror(in, out, out, di, uo) is det.
 % similar to ANSI C's ferror().
 
-:- pragma foreign_proc("C", ferror(Stream::in, RetVal::out, RetStr::out,
-		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure,
-			tabled_for_io, thread_safe],
+:- pragma foreign_proc("C",
+	io__ferror(Stream::in, RetVal::out, RetStr::out, IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *f = (MercuryFile *) Stream;
-
-	if (MR_IS_FILE_STREAM(*f)) {
-		RetVal = ferror(MR_file(*f));
+	if (MR_IS_FILE_STREAM(*Stream)) {
+		RetVal = ferror(MR_mf_file(*Stream));
 	} else {
 		RetVal = -1;
 	}
@@ -1825,8 +1870,8 @@
 	MR_update_io(IO0, IO);
 }").
 
-:- pragma foreign_proc("MC++", ferror(_Stream::in, RetVal::out, _RetStr::out,
-		IO0::di, IO::uo),
+:- pragma foreign_proc("MC++",
+	io__ferror(_Stream::in, RetVal::out, _RetStr::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, thread_safe],
 "{
 	// XXX see clearerr
@@ -1834,10 +1879,10 @@
 	MR_update_io(IO0, IO);
 }").
 
-ferror(_, _, _) -->
+io__ferror(_, _, _) -->
 	% This version is only used for back-ends for which there is no
 	% matching foreign_proc version.
-	{ private_builtin__sorry("ferror") }.
+	{ private_builtin__sorry("io__ferror") }.
 
 % io__make_err_msg(MessagePrefix, Message):
 %	`Message' is an error message obtained by looking up the
@@ -1866,7 +1911,6 @@
 	% matching foreign_proc version.
 	{ private_builtin__sorry("io__make_err_msg") }.
 
-
 %-----------------------------------------------------------------------------%
 
 :- pred io__stream_file_size(stream, int, io__state, io__state).
@@ -1884,18 +1928,16 @@
 #endif
 ").
 
-:- pragma foreign_proc("C", io__stream_file_size(Stream::in, Size::out,
-		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+:- pragma foreign_proc("C",
+	io__stream_file_size(Stream::in, Size::out, IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *f = (MercuryFile *) Stream;
 #if defined(MR_HAVE_FSTAT) && \
     (defined(MR_HAVE_FILENO) || defined(fileno)) && \
     defined(S_ISREG)
 	struct stat s;
-	if (MR_IS_FILE_STREAM(*f)) {
-		if (fstat(fileno(MR_file(*f)), &s) == 0 &&
+	if (MR_IS_FILE_STREAM(*Stream)) {
+		if (fstat(fileno(MR_mf_file(*Stream)), &s) == 0 &&
 				S_ISREG(s.st_mode))
 		{
 			Size = s.st_size;
@@ -1911,8 +1953,8 @@
 	MR_update_io(IO0, IO);
 }").
 
-:- pragma foreign_proc("MC++", io__stream_file_size(Stream::in, Size::out,
-		IO0::di, IO::uo),
+:- pragma foreign_proc("MC++",
+	io__stream_file_size(Stream::in, Size::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, thread_safe],
 "{
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile, 
@@ -1930,7 +1972,6 @@
 	% matching foreign_proc version.
 	{ private_builtin__sorry("io__stream_file_size") }.
 	
-
 io__file_modification_time(File, Result) -->
 	io__file_modification_time_2(File, Status, Msg, Time),
 	{ Status = 1 ->
@@ -1997,6 +2038,7 @@
 	private_builtin__sorry("io__alloc_buffer").
 
 :- pred io__resize_buffer(buffer::di, int::in, int::in, buffer::uo) is det.
+
 :- pragma foreign_proc("C",
 	io__resize_buffer(Buffer0::di, OldSize::in,
 		NewSize::in, Buffer::uo),
@@ -2073,21 +2115,18 @@
 :- pragma foreign_proc("C",
 	io__read_into_buffer(Stream::in, Buffer0::di, Pos0::in, Size::in,
 		    Buffer::uo, Pos::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *f = (MercuryFile *) Stream;
 	char *buffer = (MR_Char *) Buffer0;
 	int items_read;
 
-	items_read = MR_READ(*f, buffer + Pos0, Size - Pos0);
+	items_read = MR_READ(*Stream, buffer + Pos0, Size - Pos0);
 
 	Buffer = (MR_Word) buffer;
 	Pos = Pos0 + items_read;
 	MR_update_io(IO0, IO);
 }").
 
-
 io__read_into_buffer(_, _, _, _, _, _) -->
 	% This version is only used for back-ends for which there is no
 	% matching foreign_proc version.
@@ -2785,8 +2824,7 @@
 io__open_input(FileName, Result) -->
 	io__do_open(FileName, "r", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't open input file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2795,8 +2833,7 @@
 io__open_output(FileName, Result) -->
 	io__do_open(FileName, "w", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't open output file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2805,8 +2842,7 @@
 io__open_append(FileName, Result) -->
 	io__do_open(FileName, "a", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't append to file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2815,8 +2851,7 @@
 io__open_binary_input(FileName, Result) -->
 	io__do_open(FileName, "rb", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't open input file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2825,8 +2860,7 @@
 io__open_binary_output(FileName, Result) -->
 	io__do_open(FileName, "wb", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't open output file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2835,8 +2869,7 @@
 io__open_binary_append(FileName, Result) -->
 	io__do_open(FileName, "ab", Result0, NewStream),
 	( { Result0 \= -1 } ->
-		{ Result = ok(NewStream) },
-		io__insert_stream_name(NewStream, FileName)
+		{ Result = ok(NewStream) }
 	;
 		io__make_err_msg("can't append to file: ", Msg),
 		{ Result = error(io_error(Msg)) }
@@ -2952,79 +2985,14 @@
 :- pred io__stream_name(io__stream, string, io__state, io__state).
 :- mode io__stream_name(in, out, di, uo) is det.
 
-io__stream_name(Stream, Name) -->
-	io__get_stream_names(StreamNames),
-	{ map__search(StreamNames, get_stream_id(Stream), Name1) ->
-		Name = Name1
-	;
-		Name = "<stream name unavailable>"
-	},
-	io__set_stream_names(StreamNames).
-
-:- pred io__get_stream_names(io__stream_names, io__state, io__state).
-:- mode io__get_stream_names(out, di, uo) is det.
-
-:- pred io__set_stream_names(io__stream_names, io__state, io__state).
-:- mode io__set_stream_names(in, di, uo) is det.
-
-:- pragma foreign_proc("C", 
-		io__get_stream_names(StreamNames::out, IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io],
-"
-	StreamNames = ML_io_stream_names;
-	MR_update_io(IO0, IO);
-").
-
 :- pragma foreign_proc("C", 
-		io__set_stream_names(StreamNames::in, IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io],
-"
-	ML_io_stream_names = StreamNames;
-	MR_update_io(IO0, IO);
-").
-
-:- pragma foreign_proc("MC++", 
-		io__get_stream_names(StreamNames::out, IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io],
-"
-	StreamNames = ML_io_stream_names;
-	MR_update_io(IO0, IO);
-").
-
-:- pragma foreign_proc("MC++", 
-		io__set_stream_names(StreamNames::in, IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io],
+	io__stream_name(Stream::in, Name::out, IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	ML_io_stream_names = StreamNames;
+	MR_make_aligned_string_copy(Name, MR_mf_name(*Stream));
 	MR_update_io(IO0, IO);
 ").
 
-io__get_stream_names(_) -->
-	% This version is only used for back-ends for which there is no
-	% matching foreign_proc version.
-	{ private_builtin__sorry("io__get_stream_names") }.
-
-io__set_stream_names(_) -->
-	% This version is only used for back-ends for which there is no
-	% matching foreign_proc version.
-	{ private_builtin__sorry("io__set_stream_names") }.
-
-:- pred io__delete_stream_name(io__stream, io__state, io__state).
-:- mode io__delete_stream_name(in, di, uo) is det.
-
-io__delete_stream_name(Stream) -->
-	io__get_stream_names(StreamNames0),
-	{ map__delete(StreamNames0, get_stream_id(Stream), StreamNames) },
-	io__set_stream_names(StreamNames).
-
-:- pred io__insert_stream_name(io__stream, string, io__state, io__state).
-:- mode io__insert_stream_name(in, in, di, uo) is det.
-
-io__insert_stream_name(Stream, Name) -->
-	io__get_stream_names(StreamNames0),
-	{ map__set(StreamNames0, get_stream_id(Stream), Name, StreamNames) },
-	io__set_stream_names(StreamNames).
-
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -3080,7 +3048,6 @@
 	io__progname(DefaultName, Progname),
 	{ dir__basename(Progname, PrognameBase) }.
 
-
 	% XXX we call a pred version of io__get_stream_id, which is a
 	% bit inelegant.  We should either fix the MC++ interface so you
 	% can implement functions, or implement everything in this
@@ -3092,26 +3059,15 @@
 
 :- pragma foreign_proc("C",
 	io__get_stream_id(Stream::in, Id::out), 
-		[will_not_call_mercury, promise_pure], "
-
-#ifndef MR_NATIVE_GC
-	/* 
-	** Most of the time, we can just use the pointer to the stream
-	** as a unique identifier.
-	*/
-	Id = (MR_Word) Stream;
-#else
-	/* 
-	** for accurate GC we embed an ID in the MercuryFile
-	** and retrieve it here.
-	*/
-	Id = ((MercuryFile *) Stream)->id;
-#endif
+	[will_not_call_mercury, promise_pure],
+"
+	Id = MR_mf_id(Stream);
 ").
 
 :- pragma foreign_proc("MC++",
 	io__get_stream_id(Stream::in, Id::out), 
-		[will_not_call_mercury, promise_pure], "
+	[will_not_call_mercury, promise_pure],
+"
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile,
 		MR_word_to_c_pointer(Stream));
 	Id = mf->id;
@@ -3194,13 +3150,10 @@
 :- pragma export(io__init_state(di, uo), "ML_io_init_state").
 
 io__init_state -->
-	io__gc_init(type_of(StreamNames), type_of(Globals)),
-	{ map__init(StreamNames) },
+	io__gc_init(type_of(Globals)),
 	{ type_to_univ("<globals>", Globals) },
-	io__set_stream_names(StreamNames),
 	io__set_op_table(ops__init_mercury_op_table),
-	io__set_globals(Globals),
-	io__insert_std_stream_names.
+	io__set_globals(Globals).
 
 :- pred io__finalize_state(io__state, io__state).
 :- mode io__finalize_state(di, uo) is det.
@@ -3215,42 +3168,30 @@
 	% we don't bother.)
 	[].
 
-:- pred io__gc_init(type_desc, type_desc, io__state, io__state).
-:- mode io__gc_init(in, in, di, uo) is det.
+:- pred io__gc_init(type_desc, io__state, io__state).
+:- mode io__gc_init(in, di, uo) is det.
 
 :- pragma foreign_proc("C", 
-		io__gc_init(StreamNamesType::in, UserGlobalsType::in,
-		IO0::di, IO::uo),
+	io__gc_init(UserGlobalsType::in, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
 	/* for Windows DLLs, we need to call GC_INIT() from each DLL */
 #ifdef MR_CONSERVATIVE_GC
 	GC_INIT();
 #endif
-	MR_add_root(&ML_io_stream_names, (MR_TypeInfo) StreamNamesType);
 	MR_add_root(&ML_io_user_globals, (MR_TypeInfo) UserGlobalsType);
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("MC++", 
-		io__gc_init(_StreamNamesType::in, _UserGlobalsType::in,
-		IO0::di, IO::uo), [will_not_call_mercury, promise_pure], "
+	io__gc_init(_UserGlobalsType::in, IO0::di, IO::uo),
+	[will_not_call_mercury, promise_pure],
+"
 	MR_update_io(IO0, IO);
 	ascii_encoder =	new System::Text::ASCIIEncoding();
 ").
 
-io__gc_init(_, _) --> [].
-
-:- pred io__insert_std_stream_names(io__state, io__state).
-:- mode io__insert_std_stream_names(di, uo) is det.
-
-io__insert_std_stream_names -->
-	io__stdin_stream(Stdin),
-	io__insert_stream_name(Stdin, "<standard input>"),
-	io__stdout_stream(Stdout),
-	io__insert_stream_name(Stdout, "<standard output>"),
-	io__stderr_stream(Stderr),
-	io__insert_stream_name(Stderr, "<standard error>").
+io__gc_init(_) --> [].
 
 io__call_system(Command, Result) -->
 	io__call_system_return_signal(Command, Result0),
@@ -3346,32 +3287,35 @@
   #include <sys/wait.h>		/* for WIFEXITED, WEXITSTATUS, etc. */
 #endif
 
-extern MercuryFile mercury_stdin;
-extern MercuryFile mercury_stdout;
-extern MercuryFile mercury_stderr;
-extern MercuryFile mercury_stdin_binary;
-extern MercuryFile mercury_stdout_binary;
-extern MercuryFile *mercury_current_text_input;
-extern MercuryFile *mercury_current_text_output;
-extern MercuryFile *mercury_current_binary_input;
-extern MercuryFile *mercury_current_binary_output;
+extern	MR_MercuryFile		mercury_stdin;
+extern	MR_MercuryFile		mercury_stdout;
+extern	MR_MercuryFile		mercury_stderr;
+extern	MR_MercuryFile		mercury_stdin_binary;
+extern	MR_MercuryFile		mercury_stdout_binary;
+extern	MR_MercuryFilePtr	mercury_current_text_input;
+extern	MR_MercuryFilePtr	mercury_current_text_output;
+extern	MR_MercuryFilePtr	mercury_current_binary_input;
+extern	MR_MercuryFilePtr	mercury_current_binary_output;
 
 #define MR_initial_io_state()		0	/* some random number */
 #define MR_final_io_state(r)		((void)0)
 
 #define MR_update_io(r_src, r_dest)	((r_dest) = (r_src))
 
-void 		mercury_init_io(void);
-MercuryFile*	mercury_open(const char *filename, const char *openmode);
-void		mercury_io_error(MercuryFile* mf, const char *format, ...);
-void		mercury_output_error(MercuryFile* mf);
-void		mercury_print_string(MercuryFile* mf, const char *s);
-void		mercury_print_binary_string(MercuryFile* mf, const char *s);
-int		mercury_getc(MercuryFile* mf);
-void		mercury_close(MercuryFile* mf);
-int		ML_fprintf(MercuryFile* mf, const char *format, ...);
-").
+extern	void 	mercury_init_io(void);
+extern	MR_MercuryFilePtr
+		mercury_open(const char *filename, const char *openmode);
+extern	void	mercury_io_error(MR_MercuryFilePtr mfp, const char *format,
+			...);
+extern	void	mercury_output_error(MR_MercuryFilePtr mfp);
+extern	void	mercury_print_string(MR_MercuryFilePtr mfp, const char *s);
+extern	void	mercury_print_binary_string(MR_MercuryFilePtr mfp,
+			const char *s);
+extern	int	mercury_getc(MR_MercuryFilePtr mfp);
+extern	void	mercury_close(MR_MercuryFilePtr mfp);
+extern	int	ML_fprintf(MR_MercuryFilePtr mfp, const char *format, ...);
 
+").
 
 :- pragma foreign_decl("MC++", "
 
@@ -3407,42 +3351,43 @@
 #define MR_update_io(r_src, r_dest)	(0)
 #define MR_final_io_state(r)
 
-
 ").
 
 :- pragma foreign_code("C", "
 
-MercuryFile mercury_stdin;
-MercuryFile mercury_stdout;
-MercuryFile mercury_stderr;
-MercuryFile mercury_stdin_binary;
-MercuryFile mercury_stdout_binary;
+MR_MercuryFile		mercury_stdin;
+MR_MercuryFile		mercury_stdout;
+MR_MercuryFile		mercury_stderr;
+MR_MercuryFile		mercury_stdin_binary;
+MR_MercuryFile		mercury_stdout_binary;
 
-MercuryFile *mercury_current_text_input = &mercury_stdin;
-MercuryFile *mercury_current_text_output = &mercury_stdout;
-MercuryFile *mercury_current_binary_input = &mercury_stdin_binary;
-MercuryFile *mercury_current_binary_output = &mercury_stdout_binary;
+MR_MercuryFilePtr	mercury_current_text_input = &mercury_stdin;
+MR_MercuryFilePtr	mercury_current_text_output = &mercury_stdout;
+MR_MercuryFilePtr	mercury_current_binary_input = &mercury_stdin_binary;
+MR_MercuryFilePtr	mercury_current_binary_output = &mercury_stdout_binary;
 
 void
 mercury_init_io(void)
 {
-	MR_mercuryfile_init(stdin, 1, &mercury_stdin);
-	MR_mercuryfile_init(stdout, 1, &mercury_stdout);
-	MR_mercuryfile_init(stderr, 1, &mercury_stderr);
+	MR_mercuryfile_init(stdin,  ""<stdin>"",  1, &mercury_stdin);
+	MR_mercuryfile_init(stdout, ""<stdout>"", 1, &mercury_stdout);
+	MR_mercuryfile_init(stderr, ""<stderr>"", 1, &mercury_stderr);
 
-	MR_mercuryfile_init(NULL, 1, &mercury_stdin_binary);
-	MR_mercuryfile_init(NULL, 1, &mercury_stdout_binary);
+	MR_mercuryfile_init(NULL, ""<stdin_binary>"",  1,
+		&mercury_stdin_binary);
+	MR_mercuryfile_init(NULL, ""<stdout_binary>"", 1,
+		&mercury_stdout_binary);
 
 #if defined(MR_HAVE_FDOPEN) && (defined(MR_HAVE_FILENO) || defined(fileno)) && \
     defined(MR_HAVE_DUP)
-	MR_file(mercury_stdin_binary) = fdopen(dup(fileno(stdin)), ""rb"");
-	if (MR_file(mercury_stdin_binary) == NULL) {
+	MR_mf_file(mercury_stdin_binary) = fdopen(dup(fileno(stdin)), ""rb"");
+	if (MR_mf_file(mercury_stdin_binary) == NULL) {
 		MR_fatal_error(""error opening standard input stream in ""
 			""binary mode:\\n\\tfdopen() failed: %s"",
 			strerror(errno));
 	}
-	MR_file(mercury_stdout_binary) = fdopen(dup(fileno(stdout)), ""wb"");
-	if (MR_file(mercury_stdout_binary) == NULL) {
+	MR_mf_file(mercury_stdout_binary) = fdopen(dup(fileno(stdout)), ""wb"");
+	if (MR_mf_file(mercury_stdout_binary) == NULL) {
 		MR_fatal_error(""error opening standard output stream in ""
 			""binary mode:\\n\\tfdopen() failed: %s"",
 			strerror(errno));
@@ -3452,8 +3397,8 @@
 	** XXX Standard ANSI/ISO C provides no way to set stdin/stdout
 	** to binary mode.  I guess we just have to punt...
 	*/
-	MR_file(mercury_stdin_binary) = stdin;
-	MR_file(mercury_stdout_binary) = stdout;
+	MR_mf_file(mercury_stdin_binary) = stdin;
+	MR_mf_file(mercury_stdout_binary) = stdout;
 #endif
 }
 
@@ -3520,20 +3465,22 @@
 
 ").
 
-
 :- pragma foreign_code("C", "
 
-MercuryFile*
+MR_MercuryFilePtr
 mercury_open(const char *filename, const char *openmode)
 {
-	MercuryFile *mf;
-	FILE *f;
+	MR_MercuryFilePtr	mfp;
+	FILE			*fp;
 
-	f = fopen(filename, openmode);
-	if (!f) return NULL;
-	mf = MR_GC_NEW(MercuryFile);
-	MR_mercuryfile_init(f, 1, mf);
-	return mf;
+	fp = fopen(filename, openmode);
+	if (fp == NULL) {
+		return NULL;
+	}
+
+	mfp = MR_GC_NEW(MR_MercuryFile);
+	MR_mercuryfile_init(fp, filename, 1, mfp);
+	return mfp;
 }
 
 ").
@@ -3586,7 +3533,6 @@
 
 ").
 
-
 :- pred throw_io_error(string::in) is erroneous.
 :- pragma export(throw_io_error(in), "ML_throw_io_error").
 throw_io_error(Message) :- throw(io_error(Message)).
@@ -3594,19 +3540,21 @@
 :- pragma foreign_code("C", "
 
 void
-mercury_io_error(MercuryFile* mf, const char *format, ...)
+mercury_io_error(MR_MercuryFilePtr mfp, const char *format, ...)
 {
 	va_list args;
 	char message[5000];
+	char fdmsg[5000];
 	MR_ConstString message_as_mercury_string;
 
-	/* the `mf' parameter is currently not used */
-
 	/* format the error message using vsprintf() */
 	va_start(args, format);
 	vsprintf(message, format, args);
 	va_end(args);
 
+	snprintf(fdmsg, 5000, "" (fd %d)"", MR_fp_to_fileno(MR_mf_file(*mfp)));
+	strncat(message, fdmsg, 5000);
+
 	/* copy the error message to a Mercury string */
 	MR_restore_registers(); /* for MR_hp */
 	MR_make_aligned_string_copy(message_as_mercury_string, message);
@@ -3621,9 +3569,9 @@
 :- pragma foreign_code("C", "
 
 void
-mercury_output_error(MercuryFile *mf)
+mercury_output_error(MR_MercuryFilePtr mfp)
 {
-	mercury_io_error(mf, ""error writing to output file: %s"",
+	mercury_io_error(mfp, ""error writing to output file: %s"",
 		strerror(errno));
 }
 
@@ -3632,14 +3580,14 @@
 :- pragma foreign_code("C", "
 
 void
-mercury_print_string(MercuryFile* mf, const char *s)
+mercury_print_string(MR_MercuryFilePtr mfp, const char *s)
 {
-	if (ML_fprintf(mf, ""%s"", s) < 0) {
-		mercury_output_error(mf);
+	if (ML_fprintf(mfp, ""%s"", s) < 0) {
+		mercury_output_error(mfp);
 	}
 	while (*s) {
 		if (*s++ == '\\n') {
-			MR_line_number(*mf)++;
+			MR_mf_line_number(*mfp)++;
 		}
 	}
 }
@@ -3667,10 +3615,10 @@
 :- pragma foreign_code("C", "
 
 void
-mercury_print_binary_string(MercuryFile* mf, const char *s)
+mercury_print_binary_string(MR_MercuryFilePtr mfp, const char *s)
 {
-	if (ML_fprintf(mf, ""%s"", s) < 0) {
-		mercury_output_error(mf);
+	if (ML_fprintf(mfp, ""%s"", s) < 0) {
+		mercury_output_error(mfp);
 	}
 }
 
@@ -3679,18 +3627,17 @@
 :- pragma foreign_code("C", "
 
 int
-mercury_getc(MercuryFile* mf)
+mercury_getc(MR_MercuryFilePtr mfp)
 {
-	int c = MR_GETCH(*mf);
+	int c = MR_GETCH(*mfp);
 	if (c == '\\n') {
-		MR_line_number(*mf)++;
+		MR_mf_line_number(*mfp)++;
 	}
 	return c;
 }
 
 ").
 
-
 :- pragma foreign_code("MC++", "
 
 static void
@@ -3718,7 +3665,6 @@
 
 ").
 
-
 %------------------------------------------------------------------------------%
 %------------------------------------------------------------------------------%
 
@@ -3791,10 +3737,13 @@
 	return EOF;
 }
 
-static const MercuryFile MR_closed_stream = {
+static const MR_MercuryFile MR_closed_stream = {
 	/* stream_type	= */	MR_USER_STREAM,
 	/* stream_info	= */	{ NULL },
 	/* line_number	= */	0,
+	/* fd		= */	-1,
+	/* id		= */	-1,
+	/* name		= */	""<closed stream>"",
 
 	/* close	= */	ME_closed_stream_close,
 	/* read		= */	ME_closed_stream_read,
@@ -3810,19 +3759,19 @@
 #endif /* MR_NEW_MERCURYFILE_STRUCT */
 
 void
-mercury_close(MercuryFile* mf)
+mercury_close(MR_MercuryFilePtr mfp)
 {
-	if (mf == &mercury_stdin ||
-	    mf == &mercury_stdout ||
-	    mf == &mercury_stderr ||
-	    mf == &mercury_stdin_binary ||
-	    mf == &mercury_stdout_binary)
+	if (mfp == &mercury_stdin ||
+	    mfp == &mercury_stdout ||
+	    mfp == &mercury_stderr ||
+	    mfp == &mercury_stdin_binary ||
+	    mfp == &mercury_stdout_binary)
 	{
-		mercury_io_error(mf,
+		mercury_io_error(mfp,
 			""attempt to close stdin, stdout or stderr"");	
 	} else {
-		if (MR_CLOSE(*mf) < 0) {
-			mercury_io_error(mf, ""error closing file: %s"",
+		if (MR_CLOSE(*mfp) < 0) {
+			mercury_io_error(mfp, ""error closing file: %s"",
 				strerror(errno));
 		}
 
@@ -3839,7 +3788,7 @@
 		** gcc 2.95.2 barfs on `*mf = MR_closed_stream;'
 		** so we use MR_memcpy() instead.
 		*/
-		MR_memcpy(mf, &MR_closed_stream, sizeof(*mf));
+		MR_memcpy(mfp, &MR_closed_stream, sizeof(*mfp));
 
 /*
 ** XXX it would be nice to have an autoconf check
@@ -3850,7 +3799,7 @@
 
 /****
 #elif defined(HAVE_FOPENCOOKIE)
-		MR_file(*mf) = MR_closed_file;
+		MR_mf_file(*mfp) = MR_closed_file;
 ****/
 
 #else
@@ -3867,7 +3816,7 @@
 		** accessing closed files traps immediately rather than
 		** causing problems at some later point.
 		*/
-		MR_mercuryfile_init(NULL, 0, mf);
+		MR_mercuryfile_init(NULL, ""<closed file>"", 0, mfp);
 
 #endif /* ! MR_NEW_MERCURYFILE_STRUCT */
 
@@ -3880,7 +3829,7 @@
 		** io_streams, since the io__stream type is defined
 		** as a foreign_type.
 		*/
-  		MR_GC_free(mf);
+  		MR_GC_free(mfp);
 #endif /* !MR_CONSERVATIVE_GC */
 
 	}
@@ -3909,17 +3858,16 @@
 
 ").
 
-
 :- pragma foreign_code("C", "
 
 int
-ML_fprintf(MercuryFile* mf, const char *format, ...)
+ML_fprintf(MR_MercuryFilePtr mfp, const char *format, ...)
 {
 	int rc;
 	va_list args;
 
 	va_start(args, format);
-	rc = MR_VFPRINTF(*mf, format, args);
+	rc = MR_VFPRINTF(*mfp, format, args);
 	va_end(args);
 
 	return rc;
@@ -3933,40 +3881,39 @@
 	io__read_char_code(File::in, CharCode::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	CharCode = mercury_getc((MercuryFile *) File);
+	CharCode = mercury_getc(File);
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("C", 
-	io__putback_char(File::in, Character::in, IO0::di, IO::uo),
+	io__putback_char(Stream::in, Character::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile* mf = (MercuryFile *) File;
 	if (Character == '\\n') {
-		MR_line_number(*mf)--;
+		MR_mf_line_number(*Stream)--;
 	}
 	/* XXX should work even if ungetc() fails */
-	if (MR_UNGETCH(*mf, Character) == EOF) {
-		mercury_io_error(mf, ""io__putback_char: ungetc failed"");
+	if (MR_UNGETCH(*Stream, Character) == EOF) {
+		mercury_io_error(Stream, ""io__putback_char: ungetc failed"");
 	}
 	MR_update_io(IO0, IO);
 }").
 
 :- pragma foreign_proc("C",
-	io__putback_byte(File::in, Character::in, IO0::di, IO::uo),
+	io__putback_byte(Stream::in, Character::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile* mf = (MercuryFile *) File;
 	/* XXX should work even if ungetc() fails */
-	if (MR_UNGETCH(*mf, Character) == EOF) {
-		mercury_io_error(mf, ""io__putback_byte: ungetc failed"");
+	if (MR_UNGETCH(*Stream, Character) == EOF) {
+		mercury_io_error(Stream, ""io__putback_byte: ungetc failed"");
 	}
 	MR_update_io(IO0, IO);
 }").
 
 :- pragma foreign_proc("MC++", 
 	io__read_char_code(File::in, CharCode::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure], "
+	[will_not_call_mercury, promise_pure],
+"
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile, 
 		MR_word_to_c_pointer(File));
 	CharCode = mercury_getc(mf);
@@ -3975,8 +3922,8 @@
 
 :- pragma foreign_proc("MC++", 
 	io__putback_char(File::in, Character::in, IO0::di, IO::uo),
-		[may_call_mercury, promise_pure], "{
-
+	[may_call_mercury, promise_pure],
+"{
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile,
 		MR_word_to_c_pointer(File));
 	if (Character == '\\n') {
@@ -3988,8 +3935,8 @@
 
 :- pragma foreign_proc("MC++",
 	io__putback_byte(File::in, _Character::in, IO0::di, IO::uo),
-		[may_call_mercury, promise_pure], "{
-
+	[may_call_mercury, promise_pure],
+"{
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile, 
 		MR_word_to_c_pointer(File));
 	mf->stream->Seek(-1, System::IO::SeekOrigin::Current);
@@ -4029,7 +3976,7 @@
 		mercury_output_error(mercury_current_text_output);
 	}
 	if (Character == '\\n') {
-		MR_line_number(*mercury_current_text_output)++;
+		MR_mf_line_number(*mercury_current_text_output)++;
 	}
 	MR_update_io(IO0, IO);
 ").
@@ -4227,17 +4174,15 @@
 :- pragma foreign_proc("C",
 	io__seek_binary_2(Stream::in, Flag::in, Off::in,
 		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
 	static const int seek_flags[] = { SEEK_SET, SEEK_CUR, SEEK_END };
-	MercuryFile *stream = (MercuryFile *) Stream;
 	/* XXX should check for failure */
 	/* XXX should also check if the stream is seekable */
-	if (MR_IS_FILE_STREAM(*stream)) {
-		fseek(MR_file(*stream), Off, seek_flags[Flag]);
+	if (MR_IS_FILE_STREAM(*Stream)) {
+		fseek(MR_mf_file(*Stream), Off, seek_flags[Flag]);
 	} else {
-		mercury_io_error(stream,
+		mercury_io_error(Stream,
 				""io__seek_binary_2: unseekable stream"");
 	}
 	MR_update_io(IO0, IO);
@@ -4246,16 +4191,14 @@
 :- pragma foreign_proc("C",
 	io__binary_stream_offset(Stream::in, Offset::out,
 		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
 	/* XXX should check for failure */
 	/* XXX should check if the stream is tellable */
-	if (MR_IS_FILE_STREAM(*stream)) {
-		Offset = ftell(MR_file(*stream));
+	if (MR_IS_FILE_STREAM(*Stream)) {
+		Offset = ftell(MR_mf_file(*Stream));
 	} else {
-		mercury_io_error(stream,
+		mercury_io_error(Stream,
 			""io__binary_stream_offset: untellable stream"");
 	}
 	MR_update_io(IO0, IO);
@@ -4277,8 +4220,7 @@
 	io__write_string(Stream::in, Message::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe], 
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	mercury_print_string(stream, Message);
+	mercury_print_string(Stream, Message);
 	MR_update_io(IO0, IO);
 }").
 
@@ -4286,12 +4228,11 @@
 	io__write_char(Stream::in, Character::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe], 
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	if (MR_PUTCH(*stream, Character) < 0) {
-		mercury_output_error(stream);
+	if (MR_PUTCH(*Stream, Character) < 0) {
+		mercury_output_error(Stream);
 	}
 	if (Character == '\\n') {
-		MR_line_number(*stream)++;
+		MR_mf_line_number(*Stream)++;
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4300,9 +4241,8 @@
 	io__write_int(Stream::in, Val::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	if (ML_fprintf(stream, ""%ld"", (long) Val) < 0) {
-		mercury_output_error(stream);
+	if (ML_fprintf(Stream, ""%ld"", (long) Val) < 0) {
+		mercury_output_error(Stream);
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4311,9 +4251,8 @@
 	io__write_float(Stream::in, Val::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	if (ML_fprintf(stream, ""%#.15g"", Val) < 0) {
-		mercury_output_error(stream);
+	if (ML_fprintf(Stream, ""%#.15g"", Val) < 0) {
+		mercury_output_error(Stream);
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4322,10 +4261,9 @@
 	io__write_byte(Stream::in, Byte::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
 	/* call putc with a strictly non-negative byte-sized integer */
-	if (MR_PUTCH(*stream, (int) ((unsigned char) Byte)) < 0) {
-		mercury_output_error(stream);
+	if (MR_PUTCH(*Stream, (int) ((unsigned char) Byte)) < 0) {
+		mercury_output_error(Stream);
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4334,8 +4272,7 @@
 	io__write_bytes(Stream::in, Message::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	mercury_print_binary_string(stream, Message);
+	mercury_print_binary_string(Stream, Message);
 	MR_update_io(IO0, IO);
 }").
 
@@ -4343,9 +4280,8 @@
 	io__flush_output(Stream::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	if (MR_FLUSH(*stream) < 0) {
-		mercury_output_error(stream);
+	if (MR_FLUSH(*Stream) < 0) {
+		mercury_output_error(Stream);
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4354,9 +4290,8 @@
 	io__flush_binary_output(Stream::in, IO0::di, IO::uo),
 		[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	if (MR_FLUSH(*stream) < 0) {
-		mercury_output_error(stream);
+	if (MR_FLUSH(*Stream) < 0) {
+		mercury_output_error(Stream);
 	}
 	MR_update_io(IO0, IO);
 }").
@@ -4503,46 +4438,41 @@
 
 :- pragma foreign_proc("C",
 	io__stdin_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) &mercury_stdin;
+	Stream = &mercury_stdin;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("C",
 	io__stdout_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) &mercury_stdout;
+	Stream = &mercury_stdout;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("C",
 	io__stderr_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) &mercury_stderr;
+	Stream = &mercury_stderr;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("C",
 	io__stdin_binary_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) &mercury_stdin_binary;
+	Stream = &mercury_stdin_binary;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("C",
 	io__stdout_binary_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) &mercury_stdout_binary;
+	Stream = &mercury_stdout_binary;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4550,7 +4480,7 @@
 	io__input_stream(Stream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	Stream = (MR_Word) mercury_current_text_input;
+	Stream = mercury_current_text_input;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4558,7 +4488,7 @@
 	io__output_stream(Stream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	Stream = (MR_Word) mercury_current_text_output;
+	Stream = mercury_current_text_output;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4566,7 +4496,7 @@
 	io__binary_input_stream(Stream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	Stream = (MR_Word) mercury_current_binary_input;
+	Stream = mercury_current_binary_input;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4574,7 +4504,7 @@
 	io__binary_output_stream(Stream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	Stream = (MR_Word) mercury_current_binary_output;
+	Stream = mercury_current_binary_output;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4582,7 +4512,7 @@
 	io__get_line_number(LineNum::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	LineNum = MR_line_number(*mercury_current_text_input);
+	LineNum = MR_mf_line_number(*mercury_current_text_input);
 	MR_update_io(IO0, IO);
 ").
 
@@ -4590,8 +4520,7 @@
 	io__get_line_number(Stream::in, LineNum::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	LineNum = MR_line_number(*stream);
+	LineNum = MR_mf_line_number(*Stream);
 	MR_update_io(IO0, IO);
 }").
 
@@ -4599,7 +4528,7 @@
 	io__set_line_number(LineNum::in, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	MR_line_number(*mercury_current_text_input) = LineNum;
+	MR_mf_line_number(*mercury_current_text_input) = LineNum;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4607,8 +4536,7 @@
 	io__set_line_number(Stream::in, LineNum::in, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	MR_line_number(*stream) = LineNum;
+	MR_mf_line_number(*Stream) = LineNum;
 	MR_update_io(IO0, IO);
 }").
 
@@ -4616,7 +4544,7 @@
 	io__get_output_line_number(LineNum::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	LineNum = MR_line_number(*mercury_current_text_output);
+	LineNum = MR_mf_line_number(*mercury_current_text_output);
 	MR_update_io(IO0, IO);
 ").
 	
@@ -4624,8 +4552,7 @@
 	io__get_output_line_number(Stream::in, LineNum::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	LineNum = MR_line_number(*stream);
+	LineNum = MR_mf_line_number(*Stream);
 	MR_update_io(IO0, IO);
 }").
 
@@ -4633,7 +4560,7 @@
 	io__set_output_line_number(LineNum::in, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	MR_line_number(*mercury_current_text_output) = LineNum;
+	MR_mf_line_number(*mercury_current_text_output) = LineNum;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4642,8 +4569,7 @@
 		IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "{
-	MercuryFile *stream = (MercuryFile *) Stream;
-	MR_line_number(*stream) = LineNum;
+	MR_mf_line_number(*Stream) = LineNum;
 	MR_update_io(IO0, IO);
 }").
 
@@ -4651,7 +4577,7 @@
 	io__current_input_stream(OutStream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_text_input;
+	OutStream = mercury_current_text_input;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4659,7 +4585,7 @@
 	io__current_output_stream(OutStream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_text_output;
+	OutStream = mercury_current_text_output;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4667,7 +4593,7 @@
 	io__current_binary_input_stream(OutStream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_binary_input;
+	OutStream = mercury_current_binary_input;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4675,7 +4601,7 @@
 	io__current_binary_output_stream(OutStream::out, IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_binary_output;
+	OutStream = mercury_current_binary_output;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4687,8 +4613,8 @@
 		IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_text_input;
-	mercury_current_text_input = (MercuryFile *) NewStream;
+	OutStream = mercury_current_text_input;
+	mercury_current_text_input = NewStream;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4697,8 +4623,8 @@
 		IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_text_output;
-	mercury_current_text_output = (MercuryFile *) NewStream;
+	OutStream = mercury_current_text_output;
+	mercury_current_text_output = NewStream;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4707,8 +4633,8 @@
 		IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_binary_input;
-	mercury_current_binary_input = (MercuryFile *) NewStream;
+	OutStream = mercury_current_binary_input;
+	mercury_current_binary_input = NewStream;
 	MR_update_io(IO0, IO);
 ").
 
@@ -4717,15 +4643,14 @@
 		IO0::di, IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-	OutStream = (MR_Word) mercury_current_binary_output;
-	mercury_current_binary_output = (MercuryFile *) NewStream;
+	OutStream = mercury_current_binary_output;
+	mercury_current_binary_output = NewStream;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("MC++",
 	io__stdin_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, thread_safe,
-			tabled_for_io],
+	[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
 "
 	MR_c_pointer_to_word(Stream, mercury_stdin);
 	MR_update_io(IO0, IO);
@@ -4733,8 +4658,7 @@
 
 :- pragma foreign_proc("MC++",
 	io__stdout_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, thread_safe,
-			tabled_for_io],
+	[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
 "
 	MR_c_pointer_to_word(Stream, mercury_stdout);
 	MR_update_io(IO0, IO);
@@ -4742,8 +4666,7 @@
 
 :- pragma foreign_proc("MC++",
 	io__stderr_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, thread_safe,
-			tabled_for_io],
+	[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
 "
 	MR_c_pointer_to_word(Stream, mercury_stderr);
 	MR_update_io(IO0, IO);
@@ -4751,8 +4674,7 @@
 
 :- pragma foreign_proc("MC++",
 	io__stdin_binary_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, thread_safe,
-			tabled_for_io],
+	[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
 "
 	MR_c_pointer_to_word(Stream, mercury_stdin_binary);
 	MR_update_io(IO0, IO);
@@ -4760,8 +4682,7 @@
 
 :- pragma foreign_proc("MC++",
 	io__stdout_binary_stream(Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, thread_safe,
-			tabled_for_io],
+	[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
 "
 	MR_c_pointer_to_word(Stream, mercury_stdout_binary);
 	MR_update_io(IO0, IO);
@@ -4837,14 +4758,16 @@
 
 :- pragma foreign_proc("MC++",
 	io__get_output_line_number(LineNum::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	LineNum = mercury_current_text_output->line_number;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("MC++",
 	io__get_output_line_number(Stream::in, LineNum::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "{
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"{
 	MR_MercuryFile stream = ML_DownCast(MR_MercuryFile, 
 		MR_word_to_c_pointer(Stream));
 	LineNum = stream->line_number;
@@ -4853,14 +4776,16 @@
 
 :- pragma foreign_proc("MC++",
 	io__set_output_line_number(LineNum::in, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	mercury_current_text_output->line_number = LineNum;
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("MC++",
 	io__set_output_line_number(Stream::in, LineNum::in, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "{
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"{
 	MR_MercuryFile stream = ML_DownCast(MR_MercuryFile, 
 		MR_word_to_c_pointer(Stream));
 	stream->line_number = LineNum;
@@ -4872,7 +4797,8 @@
 %	Returns the previous stream.
 :- pragma foreign_proc("MC++",
 	io__set_input_stream(NewStream::in, OutStream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	MR_c_pointer_to_word(OutStream, mercury_current_text_input);
 	mercury_current_text_input = 
 		ML_DownCast(MR_MercuryFile, MR_word_to_c_pointer(NewStream));
@@ -4881,7 +4807,8 @@
 
 :- pragma foreign_proc("MC++",
 	io__set_output_stream(NewStream::in, OutStream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	MR_c_pointer_to_word(OutStream, mercury_current_text_output);
 	mercury_current_text_output = 
 		ML_DownCast(MR_MercuryFile, MR_word_to_c_pointer(NewStream));
@@ -4891,7 +4818,8 @@
 :- pragma foreign_proc("MC++",
 	io__set_binary_input_stream(NewStream::in, OutStream::out,
 		IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	MR_c_pointer_to_word(OutStream, mercury_current_binary_input);
 	mercury_current_binary_input = 
 		ML_DownCast(MR_MercuryFile, MR_word_to_c_pointer(NewStream));
@@ -4901,7 +4829,8 @@
 :- pragma foreign_proc("MC++",
 	io__set_binary_output_stream(NewStream::in, OutStream::out,
 		IO0::di, IO::uo), 
-		[will_not_call_mercury, promise_pure, tabled_for_io], "
+	[will_not_call_mercury, promise_pure, tabled_for_io],
+"
 	MR_c_pointer_to_word(OutStream, mercury_current_binary_output);
 	mercury_current_binary_output = 
 		ML_DownCast(MR_MercuryFile, MR_word_to_c_pointer(NewStream));
@@ -5041,19 +4970,17 @@
 :- pragma foreign_proc("C",
 	io__do_open(FileName::in, Mode::in, ResultCode::out,
 		Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-	Stream = (MR_Word) mercury_open(FileName, Mode);
-	ResultCode = (Stream ? 0 : -1);
+	Stream = mercury_open(FileName, Mode);
+	ResultCode = ((Stream != NULL) ? 0 : -1);
 	MR_update_io(IO0, IO);
 ").
 
 :- pragma foreign_proc("MC++",
 	io__do_open(FileName::in, Mode::in, ResultCode::out,
 		Stream::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
 	MR_MercuryFile mf = mercury_open(FileName, Mode);
 	MR_c_pointer_to_word(Stream, mf);
@@ -5067,31 +4994,31 @@
 	{ private_builtin__sorry("io__do_open") }.
 
 io__close_input(Stream) -->
-	io__delete_stream_name(Stream),
 	io__close_stream(Stream).
 
 io__close_output(Stream) -->
-	io__delete_stream_name(Stream),
 	io__close_stream(Stream).
 
 io__close_binary_input(Stream) -->
-	io__delete_stream_name(Stream),
 	io__close_stream(Stream).
 
 io__close_binary_output(Stream) -->
-	io__delete_stream_name(Stream),
 	io__close_stream(Stream).
 
 :- pred io__close_stream(stream::in, io__state::di, io__state::uo) is det.
 
-:- pragma foreign_proc("C", io__close_stream(Stream::in, IO0::di, IO::uo),
-		[may_call_mercury, promise_pure, tabled_for_io, thread_safe], "
-	mercury_close((MercuryFile *) Stream);
+:- pragma foreign_proc("C",
+	io__close_stream(Stream::in, IO0::di, IO::uo),
+	[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+	mercury_close(Stream);
 	MR_update_io(IO0, IO);
 ").
 
-:- pragma foreign_proc("MC++", io__close_stream(Stream::in, IO0::di, IO::uo),
-		[may_call_mercury, promise_pure, tabled_for_io, thread_safe], "
+:- pragma foreign_proc("MC++",
+	io__close_stream(Stream::in, IO0::di, IO::uo),
+	[may_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
 	MR_MercuryFile mf = ML_DownCast(MR_MercuryFile, 
 		MR_word_to_c_pointer(Stream));
 	mercury_close(mf);
@@ -5107,8 +5034,7 @@
 
 :- pragma foreign_proc("C",
 	io__progname(DefaultProgname::in, PrognameOut::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
 	if (MR_progname) {
 		/*
@@ -5130,15 +5056,15 @@
 
 :- pragma foreign_proc("C",
 	io__command_line_arguments(Args::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
 	/* convert mercury_argv from a vector to a list */
-	{ int i = mercury_argc;
+	{
+		int i = mercury_argc;
 	  Args = MR_list_empty_msg(MR_PROC_LABEL);
 	  while (--i >= 0) {
-		Args = MR_list_cons_msg((MR_Word) mercury_argv[i], Args,
-			MR_PROC_LABEL);
+			Args = MR_list_cons_msg((MR_Word) mercury_argv[i],
+				Args, MR_PROC_LABEL);
 	  }
 	}
 	MR_update_io(IO0, IO);
@@ -5182,7 +5108,6 @@
 	MR_update_io(IO0, IO);
 ").
 
-
 io__progname(DefaultProgName::in, ProgName::out, IO::di, IO::uo) :-
 	% This is a fall-back for back-ends which don't support the
 	% C interface.
@@ -5241,8 +5166,8 @@
 
 :- pragma foreign_proc("MC++",
 	io__command_line_arguments(Args::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe], "
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
 #ifdef MR_HIGHLEVEL_DATA
 	mercury::runtime::Errors::SORRY(""io__command_line_arguments"");
 #else
@@ -5316,27 +5241,31 @@
 /* io__getenv and io__putenv, from io.m */
 
 :- pragma promise_semipure(io__getenv/2).
-:- pragma foreign_proc("C", io__getenv(Var::in, Value::out),
+:- pragma foreign_proc("C",
+	io__getenv(Var::in, Value::out),
 		[will_not_call_mercury, tabled_for_io],
 "{
 	Value = getenv(Var);
 	SUCCESS_INDICATOR = (Value != 0);
 }").
 
-:- pragma foreign_proc("C", io__putenv(VarAndValue::in),
+:- pragma foreign_proc("C",
+	io__putenv(VarAndValue::in),
 		[will_not_call_mercury, tabled_for_io],
 "
 	SUCCESS_INDICATOR = (putenv(VarAndValue) == 0);
 ").
 
-:- pragma foreign_proc("MC++", io__getenv(Var::in, Value::out),
+:- pragma foreign_proc("MC++",
+	io__getenv(Var::in, Value::out),
 		[will_not_call_mercury, tabled_for_io],
 "{
 	Value = System::Environment::GetEnvironmentVariable(Var);
 	SUCCESS_INDICATOR = (Value != 0);
 }").
 
-:- pragma foreign_proc("MC++", io__putenv(_VarAndValue::in),
+:- pragma foreign_proc("MC++",
+	io__putenv(_VarAndValue::in),
 		[will_not_call_mercury, tabled_for_io],
 "
 	mercury::runtime::Errors::SORRY(
@@ -5460,7 +5389,8 @@
 	} while (fd == -1 && errno == EEXIST &&
 		num_tries < MAX_TEMPNAME_TRIES);
 	if (fd == -1) {
-		ML_maybe_make_err_msg(MR_TRUE, ""error opening temporary file: "",
+		ML_maybe_make_err_msg(MR_TRUE,
+			""error opening temporary file: "",
 			MR_PROC_LABEL, ErrorMessage);
 		Error = -1;
 	}  else {
@@ -5537,8 +5467,7 @@
 :- pragma foreign_proc("C",
 	io__remove_file_2(FileName::in, RetVal::out, RetStr::out,
 		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
 	RetVal = remove(FileName);
 	ML_maybe_make_err_msg(RetVal != 0, ""remove failed: "",
@@ -5550,8 +5479,7 @@
 :- pragma foreign_proc("MC++",
 	io__remove_file_2(FileName::in, RetVal::out, RetStr::out,
 		IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
 	mercury::runtime::Errors::SORRY(""foreign code for this function"");
 	System::IO::File::Delete(FileName);
@@ -5580,8 +5508,7 @@
 :- pragma foreign_proc("C",
 		io__rename_file_2(OldFileName::in, NewFileName::in,
 			RetVal::out, RetStr::out, IO0::di, IO::uo),
-		[will_not_call_mercury, promise_pure, tabled_for_io,
-			thread_safe],
+	[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
 	RetVal = rename(OldFileName, NewFileName);
 	ML_maybe_make_err_msg(RetVal != 0, ""rename failed: "",
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/RESERVED_MACRO_NAMES
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/RESERVED_MACRO_NAMES,v
retrieving revision 1.13
diff -u -d -u -r1.13 RESERVED_MACRO_NAMES
--- runtime/RESERVED_MACRO_NAMES	24 Sep 2002 06:55:26 -0000	1.13
+++ runtime/RESERVED_MACRO_NAMES	25 Sep 2002 10:22:50 -0000
@@ -42,3 +42,8 @@
 # headers, so this doesn't cause any name space polution.
 __GNU_LIBRARY__
 #-----------------------------------------------------------------------------#
+# These are defined by mercury_signal.h. The first is defined only temporarily,
+# and the second eliminates gratuitous differences between Linux versions.
+# Neither really pollutes the namespace.
+__KERNEL__
+sigcontext_struct
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.64
diff -u -d -u -r1.64 mercury.h
--- runtime/mercury.h	12 Sep 2002 10:00:53 -0000	1.64
+++ runtime/mercury.h	25 Sep 2002 10:22:50 -0000
@@ -30,6 +30,7 @@
 #include "mercury_std.h"	/* for the MR_CALL macro (and others) */
 #include "mercury_type_info.h"
 #include "mercury_builtin_types.h" 
+#include "mercury_library_types.h" 
 #include "mercury_ho_call.h"	/* for the `MR_Closure' type */
 #include "mercury_bootstrap.h"
 #include "mercury_memory.h"	/* for memory allocation routines */
@@ -125,7 +126,7 @@
 
 /*
 ** Declare the TypeCtorInfos of the library types that are not already
-** declared in mercury_builtin_types.h
+** declared in mercury_builtin_types.h.
 */
 
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
Index: runtime/mercury_builtin_types.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_builtin_types.c,v
retrieving revision 1.3
diff -u -d -u -r1.3 mercury_builtin_types.c
--- runtime/mercury_builtin_types.c	22 Aug 2002 06:51:18 -0000	1.3
+++ runtime/mercury_builtin_types.c	25 Sep 2002 10:22:50 -0000
@@ -40,6 +40,7 @@
 MR_DEFINE_PROC_STATICS(builtin, pred, 0);
 MR_DEFINE_PROC_STATICS(builtin, func, 0);
 MR_DEFINE_PROC_STATICS(builtin, tuple, 0);
+#ifndef MR_HIGHLEVEL_CODE
 MR_DEFINE_PROC_STATICS(builtin, succip, 0);
 MR_DEFINE_PROC_STATICS(builtin, hp, 0);
 MR_DEFINE_PROC_STATICS(builtin, curfr, 0);
@@ -48,6 +49,7 @@
 MR_DEFINE_PROC_STATICS(builtin, redoip, 0);
 MR_DEFINE_PROC_STATICS(builtin, trailptr, 0);
 MR_DEFINE_PROC_STATICS(builtin, ticket, 0);
+#endif
 MR_DEFINE_PROC_STATICS(private_builtin, heap_pointer, 0);
 MR_DEFINE_PROC_STATICS(private_builtin, type_ctor_info, 1);
 MR_DEFINE_PROC_STATICS(private_builtin, type_info, 1);
Index: runtime/mercury_builtin_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_builtin_types.h,v
retrieving revision 1.2
diff -u -d -u -r1.2 mercury_builtin_types.h
--- runtime/mercury_builtin_types.h	12 Sep 2002 10:00:54 -0000	1.2
+++ runtime/mercury_builtin_types.h	25 Sep 2002 10:22:50 -0000
@@ -42,6 +42,24 @@
 	MR_TYPE_CTOR_INFO_NAME(builtin, func, 0));
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
 	MR_TYPE_CTOR_INFO_NAME(builtin, tuple, 0));
+#ifndef MR_HIGHLEVEL_CODE
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, succip, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, hp, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, curfr, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, maxfr, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, redofr, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, redoip, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, trailptr, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+	MR_TYPE_CTOR_INFO_NAME(builtin, ticket, 0));
+#endif
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
 	MR_TYPE_CTOR_INFO_NAME(private_builtin, heap_pointer, 0));
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
Index: runtime/mercury_file.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_file.c,v
retrieving revision 1.4
diff -u -d -u -r1.4 mercury_file.c
--- runtime/mercury_file.c	13 Feb 2002 09:56:40 -0000	1.4
+++ runtime/mercury_file.c	25 Sep 2002 10:22:50 -0000
@@ -12,113 +12,115 @@
 #include "mercury_file.h"
 #include "mercury_std.h"	/* for MR_assert */
 
-#ifdef MR_NATIVE_GC
-  static int next_id = 0;
-#endif
+static int next_id = 0;
 
 #ifndef MR_NEW_MERCURYFILE_STRUCT
-  void
-  MR_mercuryfile_init(FILE *file, int line_number, MercuryFile *mf)
-  {
-	MR_file(*mf)	    = file;
-	MR_line_number(*mf) = line_number;
-  #ifdef MR_NATIVE_GC
-	mf->id = ++next_id;
-  #endif
-  }
 
-#else /* MR_NEW_MERCURYFILE_STRUCT */
+void
+MR_mercuryfile_init(FILE *fp, const char *name, int line_number,
+	MR_MercuryFilePtr mfp)
+{
+	MR_mf_file(*mfp) = fp;
+	MR_mf_fd(*mfp) = MR_fp_to_fileno(fp);
+	MR_mf_line_number(*mfp) = line_number;
+	MR_mf_id(*mfp) = ++next_id;
+	MR_mf_name(*mfp) = name;
+}
 
-  void
-  MR_mercuryfile_init(FILE *file, int line_number, MercuryFile *mf)
-  {
-	mf->stream_type	= MR_FILE_STREAM;
-	mf->stream_info.file	= file;
-	mf->line_number	= line_number;
+#else /* MR_NEW_MERCURYFILE_STRUCT */
+  
+void
+MR_mercuryfile_init(FILE *fp, const char *name, int line_number,
+	MR_MercuryFilePtr mfp)
+{
+	mfp->MR_mf_stream_type		= MR_FILE_STREAM;
+	mfp->MR_mf_stream_info.MR_si_file	= fp;
+	mfp->MR_mf_fd			= MR_fp_to_fileno(fp);
+	mfp->MR_mf_id			= ++next_id;
+	mfp->MR_mf_line_number		= line_number;
+	mfp->MR_mf_name			= name;
 
-	mf->close		= MR_close;
-	mf->read		= MR_read;
-	mf->write		= MR_write;
+	mfp->MR_mf_close		= MR_close;
+	mfp->MR_mf_read			= MR_read;
+	mfp->MR_mf_write		= MR_write;
 
-	mf->flush		= MR_flush;
-	mf->ungetc		= MR_ungetch;
-	mf->getc		= MR_getch;
-	mf->vprintf		= MR_vfprintf;
-	mf->putc		= MR_putch;
-  #ifdef MR_NATIVE_GC
-	mf->id = ++next_id;
-  #endif
-  }
+	mfp->MR_mf_flush		= MR_flush;
+	mfp->MR_mf_ungetc		= MR_ungetch;
+	mfp->MR_mf_getc			= MR_getch;
+	mfp->MR_mf_vprintf		= MR_vfprintf;
+	mfp->MR_mf_putc			= MR_putch;
+}
 
-  int
-  MR_getch(MR_StreamInfo *info) 
-  {
+int
+MR_getch(MR_StreamInfo *info) 
+{
 	MR_assert(info != NULL);
-	return getc(info->file);	  
-  }
+	return getc(info->MR_si_file);	  
+}
 
-  int
-  MR_ungetch(MR_StreamInfo *info, int ch)
-  {
+int
+MR_ungetch(MR_StreamInfo *info, int ch)
+{
 	MR_assert(info != NULL);		
-	return ungetc(ch, info->file);
-  }
+	return ungetc(ch, info->MR_si_file);
+}
 
-  int
-  MR_putch(MR_StreamInfo *info, int ch)
-  {
+int
+MR_putch(MR_StreamInfo *info, int ch)
+{
 	MR_assert(info != NULL);
-	return putc(ch, info->file);
-  }
+	return putc(ch, info->MR_si_file);
+}
 
-  int
-  MR_close(MR_StreamInfo *info)
-  {
+int
+MR_close(MR_StreamInfo *info)
+{
 	MR_assert(info != NULL);				      
-	return fclose(info->file);
-  }
-  
-  int
-  MR_flush(MR_StreamInfo *info)
-  {
+	return fclose(info->MR_si_file);
+}
+
+int
+MR_flush(MR_StreamInfo *info)
+{
 	MR_assert(info != NULL);				       
-	return fflush(info->file);
-  }
-  
-  int
-  MR_vfprintf(MR_StreamInfo *info, const char *format, va_list ap)
-  {
+	return fflush(info->MR_si_file);
+}
+
+int
+MR_vfprintf(MR_StreamInfo *info, const char *format, va_list ap)
+{
 	MR_assert(info != NULL);
 	MR_assert(format != NULL);
 
-	return vfprintf(info->file, format, ap);
-  }
+	return vfprintf(info->MR_si_file, format, ap);
+}
   
-  int
-  MR_read(MR_StreamInfo *info, void *buffer, size_t size)
-  { 
+int
+MR_read(MR_StreamInfo *info, void *buffer, size_t size)
+{ 
 	int rc;							       
 	MR_assert(info != NULL);				
-	rc = fread(buffer, sizeof(unsigned char), size, info->file);
+	rc = fread(buffer, sizeof(unsigned char), size, info->MR_si_file);
 
 		/* Handle error/eof special cases */
-	if ( (rc < size) &&  feof(info->file) ) {
+	if ( (rc < size) &&  feof(info->MR_si_file) ) {
 		/* nothing to do */;
-	} else if ( ferror(info->file) ) {
+	} else if ( ferror(info->MR_si_file) ) {
 		rc = -1;
 	}
 
 	return rc;
-  }
+}
 
-  int
-  MR_write(MR_StreamInfo *info, const void *buffer, size_t size)
-  {
+int
+MR_write(MR_StreamInfo *info, const void *buffer, size_t size)
+{
 	int rc;							       
 
 	MR_assert(info != NULL);
-	rc = fwrite(buffer, sizeof(unsigned char), size, info->file);
+	rc = fwrite(buffer, sizeof(unsigned char), size, info->MR_si_file);
 
 	return (rc < size ? -1 : rc);
-  }
+}
+
 #endif /* MR_NEW_MERCURYFILE_STRUCT */
Index: runtime/mercury_file.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_file.h,v
retrieving revision 1.1
diff -u -d -u -r1.1 mercury_file.h
--- runtime/mercury_file.h	11 Aug 2000 16:50:21 -0000	1.1
+++ runtime/mercury_file.h	25 Sep 2002 10:22:50 -0000
@@ -9,13 +9,12 @@
 #include "mercury_library_types.h"
 
 /*
-** Initialise a MercuryFile structure to use the C stdlib FILE *type.
+** Initialise a MR_MercuryFile structure to use the C stdlib FILE *type.
 */
-void MR_mercuryfile_init(FILE *file, int line_number, MercuryFile *mf);
+extern	void	MR_mercuryfile_init(FILE *file, const char *name,
+			int line_number, MR_MercuryFilePtr mfp);
 
 #ifdef MR_NEW_MERCURYFILE_STRUCT
-  #define MR_IS_FILE_STREAM(mf)	( (mf).stream_type == MR_FILE_STREAM )
-
   int MR_getch(MR_StreamInfo *info);
   int MR_putch(MR_StreamInfo *info, int);
   int MR_ungetch(MR_StreamInfo *info, int);
Index: runtime/mercury_init.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_init.h,v
retrieving revision 1.39
diff -u -d -u -r1.39 mercury_init.h
--- runtime/mercury_init.h	21 Aug 2002 11:27:42 -0000	1.39
+++ runtime/mercury_init.h	25 Sep 2002 10:22:50 -0000
@@ -86,6 +86,7 @@
 				   etc. */
 #include "mercury_trace_base.h"	/* for MR_trace_port */
 #include "mercury_type_info.h"	/* for MR_TypeCtorInfo_Struct */
+#include "mercury_library_types.h"	/* for MR_MercuryFilePtr */
 
 #ifdef MR_CONSERVATIVE_GC
   #ifdef MR_MPS_GC
@@ -118,11 +119,11 @@
 extern	void	mercury_init_io(void);
 extern	void	ML_io_init_state(void);
 extern	void	ML_io_finalize_state(void);
-extern	void	ML_io_stderr_stream(MR_Word *);
-extern	void	ML_io_stdout_stream(MR_Word *);
-extern	void	ML_io_stdin_stream(MR_Word *);
+extern	void	ML_io_stderr_stream(MR_MercuryFilePtr *);
+extern	void	ML_io_stdout_stream(MR_MercuryFilePtr *);
+extern	void	ML_io_stdin_stream(MR_MercuryFilePtr *);
 
-extern	void	ML_io_print_to_stream(MR_Word, MR_Word, MR_Word);
+extern	void	ML_io_print_to_stream(MR_Word, MR_MercuryFilePtr, MR_Word);
 extern	void	ML_io_print_to_cur_stream(MR_Word, MR_Word);
 
 /* in trace/mercury_trace_internal.h */
@@ -139,11 +140,12 @@
 extern	void	MR_trace_final_external(void);
 
 /* in browser/debugger_interface.h */
-extern	void	ML_DI_output_current_vars(MR_Word, MR_Word, MR_Word);
+extern	void	ML_DI_output_current_vars(MR_Word, MR_Word, MR_MercuryFilePtr);
 		/* output_current_vars/4 */
-extern	void	ML_DI_output_current_nth_var(MR_Word, MR_Word);
+extern	void	ML_DI_output_current_nth_var(MR_Word, MR_MercuryFilePtr);
 		/* output_current_nth_var/3 */
-extern	void	ML_DI_output_current_live_var_names(MR_Word, MR_Word, MR_Word);
+extern	void	ML_DI_output_current_live_var_names(MR_Word, MR_Word,
+			MR_MercuryFilePtr);
 		/* output_current_live_var_names/5 */
 extern	void	ML_DI_output_current_slots(MR_Integer, MR_Integer, MR_Integer,
 			MR_Word, MR_String, MR_String, MR_Integer, MR_Integer,
@@ -153,7 +155,7 @@
 			MR_String, MR_String, MR_Integer, MR_Integer,
 			MR_Integer, MR_Word, MR_String, MR_Word);
 		/* found_match/12 */
-extern	void	ML_DI_read_request_from_socket(MR_Word, MR_Word *,
+extern	void	ML_DI_read_request_from_socket(MR_MercuryFilePtr, MR_Word *,
 			MR_Integer *);
 extern	MR_Integer	ML_DI_get_var_number(MR_Word);
 
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.29
diff -u -d -u -r1.29 mercury_layout_util.c
--- runtime/mercury_layout_util.c	15 May 2002 11:24:15 -0000	1.29
+++ runtime/mercury_layout_util.c	25 Sep 2002 10:22:50 -0000
@@ -701,10 +701,10 @@
 void
 MR_write_variable(MR_TypeInfo type_info, MR_Word value)
 {
-	MR_Word	stdout_stream;
+	MR_MercuryFilePtr	stdout_mfp;
 
-	(*MR_io_stdout_stream)(&stdout_stream);
-	(*MR_io_print_to_stream)((MR_Word) type_info, stdout_stream, value);
+	(*MR_io_stdout_stream)(&stdout_mfp);
+	(*MR_io_print_to_stream)((MR_Word) type_info, stdout_mfp, value);
 }
 
 void
Index: runtime/mercury_library_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_library_types.h,v
retrieving revision 1.9
diff -u -d -u -r1.9 mercury_library_types.h
--- runtime/mercury_library_types.h	4 Jun 2002 14:28:58 -0000	1.9
+++ runtime/mercury_library_types.h	25 Sep 2002 10:22:50 -0000
@@ -17,48 +17,57 @@
 #include "mercury_types.h"	/* for `MR_Word' and `MR_Integer' */
 #include "mercury_std.h"	/* for MR_VARIABLE_SIZED */
 
+#if defined(fileno) || defined(MR_HAVE_FILENO)
+  #define MR_fp_to_fileno(fp) ((fp != NULL) ? fileno(fp) : -1)
+#else
+  #define MR_fp_to_fileno(fp) -1
+#endif
+
 /*
-** The C `MercuryFile' type is used for the Mercury `io__stream' type
-** in library/io.m.
+** The C `MR_MercuryFile' and `MR_MercuryFilePtr' types are used to implement
+** the Mercury `io__stream' type in library/io.m.
 ** Mercury files are not quite the same as C stdio FILEs,
 ** because we keep track of a lot more information.
 */
 #ifndef MR_NEW_MERCURYFILE_STRUCT
   typedef struct mercury_file {
-	FILE *file1;
-	int line_number1;
-  #ifdef MR_NATIVE_GC
-	int id;
-  #endif
-  } MercuryFile;
+	FILE		*MR_mf_file;
+	int		MR_mf_fd;
+	int		MR_mf_line_number;
+	int		MR_mf_id;
+	const char	*MR_mf_name;
+  } MR_MercuryFile;
 
-  #define MR_file(mf)		(mf).file1
-  #define MR_line_number(mf)	(mf).line_number1
+  #define MR_mf_file(mf)	(mf).MR_mf_file
+  #define MR_mf_fd(mf)		(mf).MR_mf_fd
+  #define MR_mf_line_number(mf)	(mf).MR_mf_line_number
+  #define MR_mf_id(mf)		(mf).MR_mf_id
+  #define MR_mf_name(mf)	(mf).MR_mf_name
 
   #define MR_IS_FILE_STREAM(mf)	( MR_TRUE )
 
-  #define MR_MERCURYFILE_INIT(file, line_number)		\
-  		{ (file), (line_number) }
+  #define MR_MERCURYFILE_INIT(file, line_number, id, name)		\
+		{ (file), MR_fp_to_fileno(file), (line_number), (id), (name) }
 
-  #define MR_CLOSE(mf)		fclose(MR_file(mf))
-  #define MR_FLUSH(mf)		fflush(MR_file(mf))
+  #define MR_CLOSE(mf)		fclose(MR_mf_file(mf))
+  #define MR_FLUSH(mf)		fflush(MR_mf_file(mf))
 
   #define MR_READ(mf, ptr, size)	\
-  		fread((ptr), sizeof(unsigned char), (size), MR_file(mf))
+  		fread((ptr), sizeof(unsigned char), (size), MR_mf_file(mf))
   #define MR_WRITE(mf, ptr, size)	\
-  		fwrite((ptr), sizeof(unsigned char), (size), MR_file(mf))
+  		fwrite((ptr), sizeof(unsigned char), (size), MR_mf_file(mf))
 
-  #define MR_UNGETCH(mf, ch)	ungetc((ch), MR_file(mf))
-  #define MR_GETCH(mf)		getc(MR_file(mf))
+  #define MR_UNGETCH(mf, ch)	ungetc((ch), MR_mf_file(mf))
+  #define MR_GETCH(mf)		getc(MR_mf_file(mf))
 
   #define MR_VFPRINTF(mf, fmt, args)	\
-  		vfprintf(MR_file(mf), (fmt), (args))
+  		vfprintf(MR_mf_file(mf), (fmt), (args))
 
-  #define MR_PUTCH(mf, ch)	putc((ch), MR_file(mf))
+  #define MR_PUTCH(mf, ch)	putc((ch), MR_mf_file(mf))
 
 #else /* MR_NEW_MERCURYFILE_STRUCT */
 
-	/* Possible types of a MercuryFile */
+	/* Possible types of an MR_MercuryFile */
   typedef enum {
 	MR_FILE_STREAM		= 1,
 	MR_SOCKET_STREAM	= 2,
@@ -67,11 +76,11 @@
   } MR_StreamType;
 
   /*
-  ** A pointer to the data which can be used to access the MercuryFile.
+  ** A pointer to the data which can be used to access the MR_MercuryFile.
   */
   typedef union {
-	FILE *file;
-	void *data;
+	FILE *MR_si_file;
+	void *MR_si_data;
   } MR_StreamInfo;
 
   typedef int (MR_Stream_close)(MR_StreamInfo *);
@@ -85,7 +94,7 @@
   typedef int (MR_Stream_putc)(MR_StreamInfo *, int);
 
   /*
-  ** The MercuryFile structure records:
+  ** The MR_MercuryFile structure records:
   **	- the type of the stream
   **	- a pointer to the information which describes the stream
   **	- the line number we are up to in the stream
@@ -96,56 +105,66 @@
   **	- pointers to functions which provide the same functionality
   **	  as flush/ungetc/getc/vprintf/putc on stdio files.
   **
-  ** MercuryFiles record all this extra information so that users can use all
+  ** MR_MercuryFiles record all this extra information so that users can use all
   ** the functionality of io.m on their own streams.  For instance see
   ** extras/logged_output.
   */
   typedef struct mercury_file {
-	MR_StreamType	stream_type;
-	MR_StreamInfo	stream_info;
-	int		line_number;
-  #ifdef MR_NATIVE_GC
-	int id;
-  #endif
+	MR_StreamType	MR_mf_stream_type;
+	MR_StreamInfo	MR_mf_stream_info;
+	int		MR_mf_line_number;
+	int		MR_mf_fd;
+	int		MR_mf_id;
+	const char	*MR_mf_name;
 
 		/* UNBUFFERED FUNCTIONS */
-	MR_Stream_close	*close;    
-	MR_Stream_read	*read;
-	MR_Stream_write	*write;
+	MR_Stream_close	*MR_mf_close;    
+	MR_Stream_read	*MR_mf_read;
+	MR_Stream_write	*MR_mf_write;
 
 		/* BUFFERED FUNCTIONS */
-	MR_Stream_flush		*flush;
-	MR_Stream_ungetc	*ungetc;
-	MR_Stream_getc		*getc;
-	MR_Stream_vprintf	*vprintf;
-	MR_Stream_putc		*putc;
-  } MercuryFile;
+	MR_Stream_flush		*MR_mf_flush;
+	MR_Stream_ungetc	*MR_mf_ungetc;
+	MR_Stream_getc		*MR_mf_getc;
+	MR_Stream_vprintf	*MR_mf_vprintf;
+	MR_Stream_putc		*MR_mf_putc;
+  } MR_MercuryFile;
 
   /*
-  ** access the file and line number fields
+  ** access the file, fd, line number, id and name fields
   */
-  #define MR_file(mf)		(mf).stream_info.file
-  #define MR_line_number(mf)	(mf).line_number
+  #define MR_mf_file(mf)	(mf).MR_mf_stream_info.MR_si_file
+  #define MR_mf_fd(mf)		(mf).MR_mf_fd
+  #define MR_mf_line_number(mf)	(mf).MR_mf_line_number
+  #define MR_mf_id(mf)		(mf).MR_mf_id
+  #define MR_mf_name(mf)	(mf).MR_mf_name
+
+  #define MR_IS_FILE_STREAM(mf)	( (mf).MR_mf_stream_type == MR_FILE_STREAM )
 
   /*
-  ** Call the functions associated with the MercuryFile structure
+  ** Call the functions associated with the MR_MercuryFile structure
   */
-  #define MR_CLOSE(mf)	((mf).close)(&((mf).stream_info))
+  #define MR_CLOSE(mf)			\
+		((mf).MR_mf_close)(&((mf).MR_mf_stream_info))
   #define MR_READ(mf, ptr, size)	\
-  		((mf).read)(&((mf).stream_info), (ptr), (size))
+  		((mf).MR_mf_read)(&((mf).MR_mf_stream_info), (ptr), (size))
   #define MR_WRITE(mf, ptr, size)	\
-  		((mf).write)(&((mf).stream_info), (ptr), (size))
+  		((mf).MR_mf_write)(&((mf).MR_mf_stream_info), (ptr), (size))
 
-  #define MR_FLUSH(mf)	((mf).flush)(&((mf).stream_info))
+  #define MR_FLUSH(mf)			\
+		((mf).MR_mf_flush)(&((mf).MR_mf_stream_info))
   #define MR_UNGETCH(mf, ch)	\
-  		((mf).ungetc)(&((mf).stream_info), (ch))
-  #define MR_GETCH(mf)	((mf).getc)(&((mf).stream_info))
+  		((mf).MR_mf_ungetc)(&((mf).MR_mf_stream_info), (ch))
+  #define MR_GETCH(mf)			\
+		((mf).MR_mf_getc)(&((mf).MR_mf_stream_info))
   #define MR_VFPRINTF(mf, fmt, args)	\
-  		((mf).vprintf)(&((mf).stream_info), (fmt), (args))
+  		((mf).MR_mf_vprintf)(&((mf).MR_mf_stream_info), (fmt), (args))
   #define MR_PUTCH(mf, ch)	\
-  		((mf).putc)(&((mf).stream_info), (ch))
+  		((mf).MR_mf_putc)(&((mf).MR_mf_stream_info), (ch))
 
 #endif	/* MR_NEW_MERCURYFILE_STRUCT */
+
+typedef	MR_MercuryFile	*MR_MercuryFilePtr;
 
 /*
 ** Definitions for accessing the representation of the
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.111
diff -u -d -u -r1.111 mercury_wrapper.c
--- runtime/mercury_wrapper.c	25 Sep 2002 07:54:12 -0000	1.111
+++ runtime/mercury_wrapper.c	25 Sep 2002 10:22:50 -0000
@@ -294,11 +294,11 @@
 void	(*MR_library_finalizer)(void);
 		/* normally ML_io_finalize_state (io__finalize_state/2) */
 
-void	(*MR_io_stderr_stream)(MR_Word *);
-void	(*MR_io_stdout_stream)(MR_Word *);
-void	(*MR_io_stdin_stream)(MR_Word *);
+void	(*MR_io_stdin_stream)(MR_MercuryFilePtr *);
+void	(*MR_io_stdout_stream)(MR_MercuryFilePtr *);
+void	(*MR_io_stderr_stream)(MR_MercuryFilePtr *);
 void	(*MR_io_print_to_cur_stream)(MR_Word, MR_Word);
-void	(*MR_io_print_to_stream)(MR_Word, MR_Word, MR_Word);
+void	(*MR_io_print_to_stream)(MR_Word, MR_MercuryFilePtr, MR_Word);
 
 void	(*MR_DI_output_current_ptr)(MR_Integer, MR_Integer, MR_Integer,
 		MR_Word, MR_String, MR_String, MR_Integer, MR_Integer,
@@ -309,15 +309,6 @@
 		MR_Word, MR_String, MR_Word);
 		/* normally ML_DI_found_match (output_current/12) */
 void	(*MR_DI_read_request_from_socket)(MR_Word, MR_Word *, MR_Integer *);
-
-/*
-** This variable has been replaced by MR_io_print_to_*_stream,
-** but the installed mkinit executable may still generate references to it.
-** We must therefore keep it until all obsolete mkinit executables have
-** been retired.
-*/
-
-MR_Code	*MR_library_trace_browser;
 
 MR_Code	*(*volatile MR_trace_func_ptr)(const MR_Label_Layout *);
 
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.55
diff -u -d -u -r1.55 mercury_wrapper.h
--- runtime/mercury_wrapper.h	25 Sep 2002 07:54:13 -0000	1.55
+++ runtime/mercury_wrapper.h	25 Sep 2002 10:22:50 -0000
@@ -19,6 +19,7 @@
 #include "mercury_trace_base.h"		/* for `MR_trace_port' */
 #include "mercury_stacks.h"		/* for `MR_{Cut,Generator}StackFrame' */
 #include "mercury_type_info.h"		/* for `MR_TypeCtorInfo' */
+#include "mercury_library_types.h"	/* for `MR_MercuryFilePtr' */
 #include <stdio.h>			/* for `FILE' */
 
 /*
@@ -79,11 +80,12 @@
 extern	void		(*MR_library_initializer)(void);
 extern	void		(*MR_library_finalizer)(void);
 
-extern	void		(*MR_io_stderr_stream)(MR_Word *);
-extern	void		(*MR_io_stdout_stream)(MR_Word *);
-extern	void		(*MR_io_stdin_stream)(MR_Word *);
+extern	void		(*MR_io_stdin_stream)(MR_MercuryFilePtr *);
+extern	void		(*MR_io_stdout_stream)(MR_MercuryFilePtr *);
+extern	void		(*MR_io_stderr_stream)(MR_MercuryFilePtr *);
 extern	void		(*MR_io_print_to_cur_stream)(MR_Word, MR_Word);
-extern	void		(*MR_io_print_to_stream)(MR_Word, MR_Word, MR_Word);
+extern	void		(*MR_io_print_to_stream)(MR_Word, MR_MercuryFilePtr,
+				MR_Word);
 
 extern	void		(*MR_address_of_mercury_init_io)(void);
 extern	void		(*MR_address_of_init_modules)(void);
@@ -133,16 +135,6 @@
 
 extern	void		(*MR_address_of_trace_init_external)(void);
 extern	void		(*MR_address_of_trace_final_external)(void);
-
-/*
-** XXX This is obsolete too.
-** This variable has been replaced by MR_io_print_to_*_stream,
-** but the installed mkinit executable may still generate references to it.
-** We must therefore keep it until all obsolete mkinit executables have
-** been retired.
-*/
-
-extern	MR_Code		*MR_library_trace_browser;
 
 /*
 ** MR_trace_func_ptr is set to either MR_trace_real (trace/mercury_trace.c),
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
Index: tests/debugger/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mmakefile,v
retrieving revision 1.89
diff -u -d -u -r1.89 Mmakefile
--- tests/debugger/Mmakefile	24 Sep 2002 06:37:56 -0000	1.89
+++ tests/debugger/Mmakefile	25 Sep 2002 10:22:50 -0000
@@ -34,6 +34,7 @@
 	print_goal			\
 	queens_rep			\
 	resume_typeinfos		\
+	stream				\
 	type_desc_test
 
 # This test is currently not useful.
@@ -327,6 +328,9 @@
 
 shallow.out: shallow shallow.inp
 	$(MDB) ./shallow < shallow.inp > shallow.out 2>&1
+
+stream.out: stream stream.inp DATA.in
+	$(MDB_STD) ./stream < stream.inp > stream.out 2>&1
 
 tabled_read.out: tabled_read tabled_read.inp tabled_read.data
 	$(MDB_STD) ./tabled_read < tabled_read.inp > tabled_read.out 2>&1
cvs diff: Diffing tests/debugger/declarative
Index: tests/debugger/declarative/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/Mmakefile,v
retrieving revision 1.42
diff -u -d -u -r1.42 Mmakefile
--- tests/debugger/declarative/Mmakefile	13 Sep 2002 04:17:46 -0000	1.42
+++ tests/debugger/declarative/Mmakefile	25 Sep 2002 10:22:50 -0000
@@ -35,6 +35,7 @@
 	small			\
 	solutions		\
 	special_term_dep	\
+	stream			\
 	tabled_read_decl	\
 	throw
 
@@ -202,6 +203,9 @@
 special_term_dep.out: special_term_dep special_term_dep.inp
 	$(MDB) ./special_term_dep < special_term_dep.inp \
 			> special_term_dep.out 2>&1
+
+stream.out: stream stream.inp
+	$(MDB_STD) ./stream < stream.inp > stream.out 2>&1
 
 tabled_read_decl.out: tabled_read_decl tabled_read_decl.inp
 	$(MDB) ./tabled_read_decl < tabled_read_decl.inp \
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_browse.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
retrieving revision 1.26
diff -u -d -u -r1.26 mercury_trace_browse.c
--- trace/mercury_trace_browse.c	5 Aug 2002 21:46:18 -0000	1.26
+++ trace/mercury_trace_browse.c	25 Sep 2002 10:22:50 -0000
@@ -33,6 +33,7 @@
 #include "mdb.browser_info.mh"
 #include "mdb.interactive_query.mh"
 
+#include "io.mh"
 #include "type_desc.mh"
 
 #include <stdio.h>
@@ -48,26 +49,22 @@
 void
 MR_trace_browse(MR_Word type_info, MR_Word value, MR_Browse_Format format)
 {
-	MercuryFile	mdb_in, mdb_out;
 	MR_Word		maybe_mark;
 
 	MR_trace_browse_ensure_init();
 
-	MR_c_file_to_mercury_file(MR_mdb_in, &mdb_in);
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	if (format != MR_BROWSE_DEFAULT_FORMAT) {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_browse_format(type_info, value,
-				(MR_Word) &mdb_in, (MR_Word) &mdb_out,
+			ML_BROWSE_browse_format_mfp(type_info, value,
+				MR_mdb_in_mfp, MR_mdb_out_mfp,
 				(MR_Word) format,
 				MR_trace_browser_persistent_state,
 				&MR_trace_browser_persistent_state);
 		);
 	} else {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_browse(type_info, value,
-				(MR_Word) &mdb_in, (MR_Word) &mdb_out,
+			ML_BROWSE_browse_mfp(type_info, value,
+				MR_mdb_in_mfp, MR_mdb_out_mfp,
 				&maybe_mark, MR_trace_browser_persistent_state,
 				&MR_trace_browser_persistent_state);
 		);
@@ -81,28 +78,24 @@
 MR_trace_browse_goal(MR_ConstString name, MR_Word arg_list, MR_Word is_func,
 	MR_Browse_Format format)
 {
-	MercuryFile	mdb_in, mdb_out;
 	MR_Word		maybe_mark;
 
 	MR_trace_browse_ensure_init();
 
-	MR_c_file_to_mercury_file(MR_mdb_in, &mdb_in);
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	if (format != MR_BROWSE_DEFAULT_FORMAT) {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_browse_format_synthetic(
+			ML_BROWSE_browse_format_synthetic_mfp(
 				(MR_String) (MR_Word) name, arg_list, is_func,
-				(MR_Word) &mdb_in, (MR_Word) &mdb_out,
+				MR_mdb_in_mfp, MR_mdb_out_mfp,
 				(MR_Word) format,
 				MR_trace_browser_persistent_state,
 				&MR_trace_browser_persistent_state);
 		);
 	} else {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_browse_synthetic(
+			ML_BROWSE_browse_synthetic_mfp(
 				(MR_String) (MR_Word) name, arg_list, is_func,
-				(MR_Word) &mdb_in, (MR_Word) &mdb_out,
+				MR_mdb_in_mfp, MR_mdb_out_mfp,
 				&maybe_mark, MR_trace_browser_persistent_state,
 				&MR_trace_browser_persistent_state);
 		);
@@ -128,9 +121,9 @@
 	MR_trace_browse_ensure_init();
 
 	MR_TRACE_CALL_MERCURY(
-		ML_BROWSE_browse_external(type_info, value,
-			(MR_Word) &MR_debugger_socket_in, 
-			(MR_Word) &MR_debugger_socket_out,
+		ML_BROWSE_browse_external_mfp(type_info, value,
+			&MR_debugger_socket_in_mf, 
+			&MR_debugger_socket_out_mf,
 			MR_trace_browser_persistent_state,
 			&MR_trace_browser_persistent_state);
 	);
@@ -145,23 +138,19 @@
 MR_trace_print(MR_Word type_info, MR_Word value, MR_Browse_Caller_Type caller,
 		MR_Browse_Format format)
 {
-	MercuryFile mdb_out;
-
 	MR_trace_browse_ensure_init();
 
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	if (format != MR_BROWSE_DEFAULT_FORMAT) {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_print_format(type_info, value,
-				(MR_Word) &mdb_out, (MR_Word) caller,
+			ML_BROWSE_print_format_mfp(type_info, value,
+				MR_mdb_out_mfp, (MR_Word) caller,
 				(MR_Word) format,
 				MR_trace_browser_persistent_state);
 		);
 	} else {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_print(type_info, value,
-				(MR_Word) &mdb_out, (MR_Word) caller,
+			ML_BROWSE_print_mfp(type_info, value,
+				MR_mdb_out_mfp, (MR_Word) caller,
 				MR_trace_browser_persistent_state);
 		);
 	}
@@ -171,25 +160,21 @@
 MR_trace_print_goal(MR_ConstString name, MR_Word arg_list, MR_Word is_func,
 	MR_Browse_Caller_Type caller, MR_Browse_Format format)
 {
-	MercuryFile mdb_out;
-
 	MR_trace_browse_ensure_init();
 
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	if (format != MR_BROWSE_DEFAULT_FORMAT) {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_print_format_synthetic(
+			ML_BROWSE_print_format_synthetic_mfp(
 				(MR_String) (MR_Word) name, arg_list, is_func,
-				(MR_Word) &mdb_out, (MR_Word) caller,
+				MR_mdb_out_mfp, (MR_Word) caller,
 				(MR_Word) format,
 				MR_trace_browser_persistent_state);
 		);
 	} else {
 		MR_TRACE_CALL_MERCURY(
-			ML_BROWSE_print_synthetic(
+			ML_BROWSE_print_synthetic_mfp(
 				(MR_String) (MR_Word) name, arg_list, is_func,
-				(MR_Word) &mdb_out, (MR_Word) caller,
+				MR_mdb_out_mfp, (MR_Word) caller,
 				MR_trace_browser_persistent_state);
 		);
 	}
@@ -315,12 +300,8 @@
 {
 	MR_ConstString options_on_heap;
 	MR_Word imports_list;
-	MercuryFile mdb_in, mdb_out;
 	int i;
 
-	MR_c_file_to_mercury_file(MR_mdb_in, &mdb_in);
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	if (options == NULL) options = "";
 
         MR_TRACE_USE_HP(
@@ -336,8 +317,8 @@
 	);
 
 	MR_TRACE_CALL_MERCURY(
-		ML_query(type, imports_list, (MR_String) options_on_heap,
-			(MR_Word) &mdb_in, (MR_Word) &mdb_out);
+		ML_query_mfp(type, imports_list, (MR_String) options_on_heap,
+			MR_mdb_in_mfp, MR_mdb_out_mfp);
 	);
 }
 
@@ -348,9 +329,8 @@
 	MR_Word imports_list)
 {
 	MR_TRACE_CALL_MERCURY(
-		ML_query_external(type, imports_list,  options,
-			(MR_Word) &MR_debugger_socket_in, 
-			(MR_Word) &MR_debugger_socket_out);
+		ML_query_external_mfp(type, imports_list, options,
+			&MR_debugger_socket_in_mf, &MR_debugger_socket_out_mf);
 	);
 }
 
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.56
diff -u -d -u -r1.56 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	5 Aug 2002 21:46:18 -0000	1.56
+++ trace/mercury_trace_declarative.c	25 Sep 2002 10:22:51 -0000
@@ -49,6 +49,7 @@
 #include "mdb.declarative_execution.mh"
 
 #include "std_util.mh"
+#include "io.mh"
 
 #include <errno.h>
 
@@ -157,9 +158,11 @@
 ** which the store should be written when built.  This global is
 ** set in MR_trace_start_decl_debug, and keeps the same value
 ** throughout the declarative debugging session.
+** XXX the last part is not true; it is closed once a trace is saved.
 */
 
 static	FILE		*MR_trace_store_file;
+static	MR_MercuryFile	MR_trace_store_file_mf;
 
 static	MR_Trace_Node	MR_trace_decl_call(MR_Event_Info *event_info,
 				MR_Trace_Node prev);
@@ -1029,26 +1032,19 @@
 MR_trace_decl_ensure_init(void)
 {
 	static MR_bool		done = MR_FALSE;
-	static MercuryFile	mdb_in;
-	static MercuryFile	mdb_out;
-
-	MR_mercuryfile_init(MR_mdb_in, 1, &mdb_in);
-	MR_mercuryfile_init(MR_mdb_out, 1, &mdb_out);
 
 	if (! done) {
 		MR_TRACE_CALL_MERCURY(
 			MR_trace_node_store = 0;
-			MR_DD_decl_diagnosis_state_init(
-					(MR_Word) &mdb_in,
-					(MR_Word) &mdb_out,
-					&MR_trace_front_end_state);
+			MR_DD_decl_diagnosis_state_init(MR_mdb_in_mfp,
+				MR_mdb_out_mfp, &MR_trace_front_end_state);
 		);
 		done = MR_TRUE;
 	}
 }
 
 MR_bool
-MR_trace_start_decl_debug(MR_Trace_Mode trace_mode, const char *outfile,
+MR_trace_start_decl_debug(MR_Trace_Mode trace_mode, char *outfile,
 		MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
 		MR_Event_Details *event_details, MR_Code **jumpaddr)
 {
@@ -1107,6 +1103,9 @@
 		}
 	}
 
+	MR_mercuryfile_init(MR_trace_store_file, "<trace store file>", 1,
+		&MR_trace_store_file_mf);
+
 	MR_trace_decl_mode = trace_mode;
 
 	MR_trace_decl_ensure_init();
@@ -1223,7 +1222,6 @@
 	MR_Unsigned		bug_event;
 	MR_Unsigned		final_event;
 	MR_Unsigned		topmost_seqno;
-	MercuryFile		stream;
 	MR_Integer		use_old_io_map;
 	MR_Unsigned		io_start;
 	MR_Unsigned		io_end;
@@ -1241,10 +1239,8 @@
 	}
 
 	if (MR_trace_decl_mode == MR_TRACE_DECL_DEBUG_DUMP) {
-		MR_mercuryfile_init(MR_trace_store_file, 1, &stream);
-
 		MR_TRACE_CALL_MERCURY(
-			MR_DD_save_trace((MR_Word) &stream,
+			MR_DD_save_trace_mfp(&MR_trace_store_file_mf,
 						MR_trace_node_store, root);
 		);
 
@@ -1476,13 +1472,9 @@
 static	void
 MR_decl_checkpoint_loc(const char *str, MR_Trace_Node node)
 {
-	MercuryFile mdb_out;
-
-	MR_mercuryfile_init(MR_mdb_out, 1, &mdb_out);
-
 	fprintf(MR_mdb_out, "DD %s: %ld ", str, (long) node);
 	MR_TRACE_CALL_MERCURY(
-		MR_DD_print_trace_node((MR_Word) &mdb_out, (MR_Word) node);
+		MR_DD_print_trace_node_mfp(MR_mdb_out_mfp, (MR_Word) node);
 	);
 	fprintf(MR_mdb_out, "\n");
 }
Index: trace/mercury_trace_declarative.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.h,v
retrieving revision 1.14
diff -u -d -u -r1.14 mercury_trace_declarative.h
--- trace/mercury_trace_declarative.h	18 Feb 2002 07:01:29 -0000	1.14
+++ trace/mercury_trace_declarative.h	25 Sep 2002 10:22:51 -0000
@@ -29,7 +29,7 @@
 */
 
 extern	MR_bool	MR_trace_start_decl_debug(MR_Trace_Mode trace_mode,
-			const char *out, MR_Trace_Cmd_Info *cmd,
+			char *out, MR_Trace_Cmd_Info *cmd,
 			MR_Event_Info *event_info,
 			MR_Event_Details *event_details, MR_Code **jumpaddr);
 
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.66
diff -u -d -u -r1.66 mercury_trace_external.c
--- trace/mercury_trace_external.c	5 Aug 2002 21:46:18 -0000	1.66
+++ trace/mercury_trace_external.c	25 Sep 2002 10:22:51 -0000
@@ -32,6 +32,7 @@
 #include "mdb.debugger_interface.mh"
 #include "mdb.collect_lib.mh"
 
+#include "io.mh"
 #include "type_desc.mh"
 
 #include "mercury_deep_copy.h"
@@ -97,8 +98,8 @@
 
 } MR_debugger_request_type;
 
-MercuryFile MR_debugger_socket_in;
-MercuryFile MR_debugger_socket_out;
+MR_MercuryFile	MR_debugger_socket_in_mf;
+MR_MercuryFile	MR_debugger_socket_out_mf;
 
 static MR_String	MR_mmc_options;
 
@@ -141,7 +142,7 @@
 ** debugger.
 */
 
-static	void	(*send_collect_result_ptr)(MR_Word, MR_Word);
+static	void	(*send_collect_result_ptr)(MR_Word, MR_MercuryFilePtr);
 
 /*
 ** Variable generated during the dynamic linking that is needed to close
@@ -409,8 +410,10 @@
 		fprintf(stderr, "Mercury runtime: fdopen(): ok\n");
 	}
 
-	MR_mercuryfile_init(file_in, 1, &MR_debugger_socket_in);
-	MR_mercuryfile_init(file_out, 1, &MR_debugger_socket_out);
+	MR_mercuryfile_init(file_in, "<morphine input socket>", 1,
+		&MR_debugger_socket_in_mf);
+	MR_mercuryfile_init(file_out, "<morphine output socket>", 1,
+		&MR_debugger_socket_out_mf);
 
 	/*
 	** Send hello
@@ -938,7 +941,7 @@
 			layout->MR_sll_entry->MR_sle_detism,
 			(MR_String) (MR_Word) path,
 			lineno,
-			(MR_Word) &MR_debugger_socket_out);
+			&MR_debugger_socket_out_mf);
 		    );
 	} else {
 		MR_TRACE_CALL_MERCURY(
@@ -959,7 +962,7 @@
 			layout->MR_sll_entry->MR_sle_detism,
 			(MR_String) (MR_Word) path,
 			lineno,
-			(MR_Word) &MR_debugger_socket_out);
+			&MR_debugger_socket_out_mf);
 		    );
 	}
 }
@@ -971,7 +974,7 @@
 	ML_DI_output_current_vars(
 		var_list,
 		string_list,
-		(MR_Word) &MR_debugger_socket_out);
+		&MR_debugger_socket_out_mf);
     );
 }
 
@@ -981,7 +984,7 @@
     MR_TRACE_CALL_MERCURY(
 	ML_DI_output_current_nth_var(
 		var,
-		(MR_Word) &MR_debugger_socket_out);
+		&MR_debugger_socket_out_mf);
     );
 }
 
@@ -992,7 +995,7 @@
 	ML_DI_output_current_live_var_names(
 		var_names_list,
 		type_list,
-		(MR_Word) &MR_debugger_socket_out);
+		&MR_debugger_socket_out_mf);
     );
 }
 
@@ -1001,11 +1004,11 @@
 			MR_Word *debugger_request_ptr, 
 			MR_Integer *debugger_request_type_ptr)
 {		
-	fflush(MR_file(MR_debugger_socket_in));
+	fflush(MR_mf_file(MR_debugger_socket_in_mf));
 
     MR_TRACE_CALL_MERCURY(
 	ML_DI_read_request_from_socket(
-		(MR_Word) &MR_debugger_socket_in, 
+		&MR_debugger_socket_in_mf,
 		debugger_request_ptr, 
 		debugger_request_type_ptr);
     );
@@ -1074,18 +1077,18 @@
 	va_list args;
 
 	va_start(args, format);
-	vfprintf(MR_file(MR_debugger_socket_out), format, args);
+	vfprintf(MR_mf_file(MR_debugger_socket_out_mf), format, args);
 	va_end(args);
-	fflush(MR_file(MR_debugger_socket_out));
-	MR_line_number(MR_debugger_socket_out)++;
+	fflush(MR_mf_file(MR_debugger_socket_out_mf));
+	MR_mf_line_number(MR_debugger_socket_out_mf)++;
 }
 
 static void
 MR_send_message_to_socket(const char *message)
 {
-	fprintf(MR_file(MR_debugger_socket_out), "%s.\n", message);
-	fflush(MR_file(MR_debugger_socket_out));
-	MR_line_number(MR_debugger_socket_out)++;
+	fprintf(MR_mf_file(MR_debugger_socket_out_mf), "%s.\n", message);
+	fflush(MR_mf_file(MR_debugger_socket_out_mf));
+	MR_mf_line_number(MR_debugger_socket_out_mf)++;
 }
 
 /*
@@ -1567,10 +1570,11 @@
 
 		(*send_collect_result_ptr)(
 			MR_collected_variable, 
-			(MR_Word) &MR_debugger_socket_out));
+			&MR_debugger_socket_out_mf));
 #if defined(MR_HAVE_DLFCN_H) && defined(MR_HAVE_DLCLOSE)
 	MR_TRACE_CALL_MERCURY(
        		ML_CL_unlink_collect(collect_lib_maybe_handle));
 #endif
 }
+
 #endif /* MR_USE_EXTERNAL_DEBUGGER */
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.12
diff -u -d -u -r1.12 mercury_trace_external.h
--- trace/mercury_trace_external.h	18 Feb 2002 07:01:30 -0000	1.12
+++ trace/mercury_trace_external.h	25 Sep 2002 10:22:51 -0000
@@ -10,7 +10,7 @@
 #include "mercury_trace.h"		/* for MR_Trace_Cmd_Info, etc.  */
 #include "mercury_conf.h"		/* for MR_USE_EXTERNAL_DEBUGGER */
 #include "mercury_types.h"		/* for MR_Code                  */
-#include "mercury_library_types.h"	/* for MercuryFile              */
+#include "mercury_library_types.h"	/* for MR_MercuryFile           */
 
 #ifdef	MR_USE_EXTERNAL_DEBUGGER
 
@@ -31,8 +31,8 @@
 ** External debugger socket streams.
 */
 
-extern MercuryFile MR_debugger_socket_in;
-extern MercuryFile MR_debugger_socket_out;
+extern MR_MercuryFile MR_debugger_socket_in_mf;
+extern MR_MercuryFile MR_debugger_socket_out_mf;
 
 #endif	/* MR_USE_EXTERNAL_DEBUGGER */
 
Index: trace/mercury_trace_help.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_help.c,v
retrieving revision 1.19
diff -u -d -u -r1.19 mercury_trace_help.c
--- trace/mercury_trace_help.c	5 Aug 2002 21:46:19 -0000	1.19
+++ trace/mercury_trace_help.c	25 Sep 2002 10:22:51 -0000
@@ -117,14 +117,10 @@
 void
 MR_trace_help(void)
 {
-	MercuryFile mdb_out;
-
 	MR_trace_help_ensure_init();
 
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
-
 	MR_TRACE_CALL_MERCURY(
-		ML_HELP_help(MR_trace_help_system, (MR_Word) &mdb_out);
+		ML_HELP_help_mfp(MR_trace_help_system, MR_mdb_out_mfp);
 	);
 }
 
@@ -132,7 +128,6 @@
 MR_trace_help_word(const char *word)
 {
 	char	*word_on_heap;
-	MercuryFile mdb_out;
 
 	MR_trace_help_ensure_init();
 
@@ -140,10 +135,9 @@
 		MR_make_aligned_string_copy(word_on_heap, word);
 	);
 
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
 	MR_TRACE_CALL_MERCURY(
-		ML_HELP_name(MR_trace_help_system, word_on_heap,
-			(MR_Word) &mdb_out);
+		ML_HELP_name_mfp(MR_trace_help_system, word_on_heap,
+			MR_mdb_out_mfp);
 	);
 }
 
@@ -156,7 +150,6 @@
 	char	*category_on_heap;
 	char	*item_on_heap;
 	MR_bool	error;
-	MercuryFile mdb_out;
 
 	MR_trace_help_ensure_init();
 
@@ -168,10 +161,9 @@
 		path = MR_list_cons((MR_Word) category_on_heap, path);
 	);
 
-	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
 	MR_TRACE_CALL_MERCURY(
-		ML_HELP_path(MR_trace_help_system, path,
-			(MR_Word) &mdb_out, &result);
+		ML_HELP_path_mfp(MR_trace_help_system, path, MR_mdb_out_mfp,
+			&result);
 		error = ML_HELP_result_is_error(result, &msg);
 	);
 
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.140
diff -u -d -u -r1.140 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	15 Sep 2002 10:06:02 -0000	1.140
+++ trace/mercury_trace_internal.c	25 Sep 2002 10:23:02 -0000
@@ -29,6 +29,7 @@
 #include "mercury_trace_readline.h"
 #include "mercury_trace_source.h"
 
+#include "io.mh"
 #include "mdb.browse.mh"
 #include "mdb.browser_info.mh"
 #include "mdb.program_representation.mh"
@@ -111,6 +112,14 @@
 FILE	*MR_mdb_out;
 FILE	*MR_mdb_err;
 
+MR_MercuryFilePtr	MR_mdb_in_mfp;
+MR_MercuryFilePtr	MR_mdb_out_mfp;
+MR_MercuryFilePtr	MR_mdb_err_mfp;
+
+static MR_MercuryFile	MR_mdb_in_mf;
+static MR_MercuryFile	MR_mdb_out_mf;
+static MR_MercuryFile	MR_mdb_err_mf;
+
 static	MR_Trace_Print_Level	MR_default_print_level = MR_PRINT_LEVEL_SOME;
 
 /*
@@ -677,6 +686,17 @@
 		/* Ensure that MR_mdb_err is not buffered */
 		setvbuf(MR_mdb_err, NULL, _IONBF, 0);
 
+		MR_mercuryfile_init(MR_mdb_in, "<mdb input>", 1,
+			&MR_mdb_in_mf);
+		MR_mercuryfile_init(MR_mdb_out, "<mdb output>", 1,
+			&MR_mdb_out_mf);
+		MR_mercuryfile_init(MR_mdb_err, "<mdb errors>", 1,
+			&MR_mdb_err_mf);
+
+		MR_mdb_in_mfp  = &MR_mdb_in_mf;
+		MR_mdb_out_mfp = &MR_mdb_out_mf;
+		MR_mdb_err_mfp = &MR_mdb_err_mf;
+
 		if (getenv("MERCURY_SUPPRESS_MDB_BANNER") == NULL) {
 			fprintf(MR_mdb_out, MR_trace_banner, MR_VERSION);
 		}
@@ -919,6 +939,11 @@
 		    goto parent_error;
 		}
 
+		/*
+		** MR_mdb_in, MR_mdb_out and MR_mdb_err will be put into
+		** MR_MercuryFile structures by our caller.
+		*/
+
 		MR_have_mdb_window = MR_TRUE;
 		MR_mdb_window_pid = child_pid;
 		return MR_TRUE;
@@ -2162,8 +2187,7 @@
 			sprintf(buf, "\nWhich do you want to put "
 				"a breakpoint on (0-%d or *)? ",
 				matches.match_proc_next - 1);
-			line2 = MR_trace_getline(buf,
-				MR_mdb_in, MR_mdb_out);
+			line2 = MR_trace_getline(buf, MR_mdb_in, MR_mdb_out);
 			if (line2 == NULL) {
 				/* This means the user input EOF. */
 				fprintf(MR_mdb_out, "none of them\n");
@@ -3534,7 +3558,7 @@
 	MR_Code **jumpaddr)
 {
 	MR_Trace_Mode	trace_mode;
-	const char	*filename;
+	char		*filename;
 
 	if (word_count > 2) {
 		fflush(MR_mdb_out);
@@ -3543,10 +3567,10 @@
 	} else {
 		if (word_count == 2) {
 			trace_mode = MR_TRACE_DECL_DEBUG_DUMP;
-			filename = (const char *) words[1];
+			filename = words[1];
 		} else {
 			trace_mode = MR_TRACE_DECL_DEBUG_DEBUG;
-			filename = (const char *) NULL;
+			filename = NULL;
 		}
 
 		if (MR_trace_start_decl_debug(trace_mode, filename,
Index: trace/mercury_trace_internal.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.h,v
retrieving revision 1.16
diff -u -d -u -r1.16 mercury_trace_internal.h
--- trace/mercury_trace_internal.h	6 Mar 2002 14:35:05 -0000	1.16
+++ trace/mercury_trace_internal.h	25 Sep 2002 10:22:51 -0000
@@ -8,7 +8,9 @@
 #define	MERCURY_TRACE_INTERNAL_H
 
 #include "mercury_conf.h"	/* for MR_USE_DECLARATIVE_DEBUGGER */
+#include "mercury_regs.h"		/* must be before most other headers */
 #include "mercury_types.h"	/* for MR_Code */
+#include "mercury_library_types.h"	/* for MR_MercuryFilePtr */
 #include "mercury_trace.h"	/* for MR_Event_Info, etc. */
 #include "mercury_std.h"	/* for MR_bool */
 #include "mercury_trace_completion.h"	/* for MR_Make_Completer */
@@ -55,14 +57,19 @@
 ** Debugger I/O streams.
 ** Replacements for stdin/stdout/stderr respectively.
 **
-** The distinction between MR_mdb_out and MR_mdb_err is analagous to
+** The distinction between MR_mdb_out and MR_mdb_err is analogous to
 ** the distinction between stdout and stderr: ordinary output, including
 ** information messages about conditions which are not errors, should
 ** go to MR_mdb_out, but error messages should go to MR_mdb_err.
 */
+
 extern FILE *MR_mdb_in;
 extern FILE *MR_mdb_out;
 extern FILE *MR_mdb_err;
+
+extern	MR_MercuryFilePtr	MR_mdb_in_mfp;
+extern	MR_MercuryFilePtr	MR_mdb_out_mfp;
+extern	MR_MercuryFilePtr	MR_mdb_err_mfp;
 
 /*
 ** This just prints to MR_mdb_out a message telling the user
Index: trace/mercury_trace_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.c,v
retrieving revision 1.8
diff -u -d -u -r1.8 mercury_trace_util.c
--- trace/mercury_trace_util.c	18 Feb 2002 07:01:32 -0000	1.8
+++ trace/mercury_trace_util.c	25 Sep 2002 10:22:51 -0000
@@ -17,12 +17,6 @@
 
 #include <ctype.h>
 
-void
-MR_c_file_to_mercury_file(FILE *c_file, MercuryFile *mercury_file)
-{
-	MR_mercuryfile_init(c_file, 1, mercury_file);
-}
-
 MR_bool
 MR_trace_is_number(const char *word, int *value)
 {
Index: trace/mercury_trace_util.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.h,v
retrieving revision 1.8
diff -u -d -u -r1.8 mercury_trace_util.h
--- trace/mercury_trace_util.h	22 Jul 2002 07:13:14 -0000	1.8
+++ trace/mercury_trace_util.h	25 Sep 2002 10:22:51 -0000
@@ -17,7 +17,6 @@
 
 #include "mercury_std.h"		/* for MR_bool        */
 #include "mercury_types.h"		/* for MR_Word etc */
-#include "mercury_library_types.h"	/* for MercuryFile */
 #include <stdio.h>			/* for FILE        */
 
 /*
@@ -49,13 +48,6 @@
 		MR_save_transient_registers();				\
 		MR_io_tabling_enabled = saved_io_enabled;		\
 	} while (0)
-
-/*
-** MR_c_file_to_mercury_file is used to convert MR_mdb_in and MR_mdb_out
-** into Mercury streams suitable for use by the browser.
-*/
-extern	void	MR_c_file_to_mercury_file(FILE *c_file,
-			MercuryFile *mercury_file);
 
 /*
 ** MR_trace_is_number checks whether the given word contains a natural number,
Index: trace/mercury_trace_vars.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_vars.c,v
retrieving revision 1.49
diff -u -d -u -r1.49 mercury_trace_vars.c
--- trace/mercury_trace_vars.c	9 Sep 2002 05:52:18 -0000	1.49
+++ trace/mercury_trace_vars.c	25 Sep 2002 10:22:51 -0000
@@ -18,11 +18,13 @@
 #include "mercury_imp.h"
 #include "mercury_array_macros.h"
 #include "mercury_memory.h"
+#include "mercury_builtin_types.h"
 #include "mercury_layout_util.h"
 #include "mercury_deconstruct.h"
 #include "mercury_stack_layout.h"
 #include "mercury_trace_util.h"
 #include "mercury_trace_vars.h"
+#include "io.mh"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -145,67 +147,27 @@
 ** do not export them. The types are a lie, but a safe lie.
 */
 
-#ifndef MR_HIGHLEVEL_CODE
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_private_builtin__type_ctor_info_type_info_1;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_private_builtin__type_ctor_info_type_ctor_info_1;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_private_builtin__type_ctor_info_typeclass_info_1;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_private_builtin__type_ctor_info_base_typeclass_info_1;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_std_util__type_ctor_info_type_desc_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_std_util__type_ctor_info_type_ctor_desc_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_type_desc__type_ctor_info_type_desc_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_type_desc__type_ctor_info_type_ctor_desc_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_func_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_pred_0;
-  extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_void_0;
-
-  #ifdef MR_NATIVE_GC
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_succip_0;
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_hp_0;
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_curfr_0;
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_maxfr_0;
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_redoip_0;
-    extern struct MR_TypeCtorInfo_Struct
-    mercury_data_builtin__type_ctor_info_redofr_0;
-  #endif
-#endif
-
 static  MR_TypeCtorInfo
 MR_trace_always_ignored_type_ctors[] =
 {
-#ifndef MR_HIGHLEVEL_CODE
     /* we ignore these until the browser can handle their varying arity, */
     /* or their definitions are updated. XXX */
-    &mercury_data_private_builtin__type_ctor_info_typeclass_info_1,
-    &mercury_data_private_builtin__type_ctor_info_base_typeclass_info_1,
+    &MR_TYPE_CTOR_INFO_NAME(private_builtin, typeclass_info, 1),
+    &MR_TYPE_CTOR_INFO_NAME(private_builtin, base_typeclass_info, 1),
 
     /* we ignore these because they should never be needed */
-    &mercury_data_builtin__type_ctor_info_void_0,
+    &MR_TYPE_CTOR_INFO_NAME(builtin, void, 0),
 
-  #ifdef MR_NATIVE_GC
+#ifndef MR_HIGHLEVEL_CODE
     /* we ignore these because they are not interesting */
-    &mercury_data_builtin__type_ctor_info_succip_0,
-    &mercury_data_builtin__type_ctor_info_hp_0,
-    &mercury_data_builtin__type_ctor_info_curfr_0,
-    &mercury_data_builtin__type_ctor_info_maxfr_0,
-    &mercury_data_builtin__type_ctor_info_redoip_0,
-    &mercury_data_builtin__type_ctor_info_redofr_0,
-  #endif
+    &MR_TYPE_CTOR_INFO_NAME(builtin, succip, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, hp, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, curfr, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, maxfr, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, redofr, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, redoip, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, trailptr, 0),
+    &MR_TYPE_CTOR_INFO_NAME(builtin, ticket, 0),
 #endif
     /* dummy member */
     NULL
@@ -214,14 +176,12 @@
 static  MR_TypeCtorInfo
 MR_trace_maybe_ignored_type_ctors[] =
 {
-#ifndef MR_HIGHLEVEL_CODE
     /*
     ** We can print values of these types (after a fashion),
     ** but users are usually not interested in their values.
     */
-    &mercury_data_private_builtin__type_ctor_info_type_info_1,
-    &mercury_data_private_builtin__type_ctor_info_type_ctor_info_1,
-#endif
+    &MR_TYPE_CTOR_INFO_NAME(private_builtin, type_info, 1),
+    &MR_TYPE_CTOR_INFO_NAME(private_builtin, type_ctor_info, 1),
     /* dummy member */
     NULL
 };
@@ -306,6 +266,11 @@
     }
 }
 
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(io, input_stream, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(io, output_stream, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(io, stream, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(io, stream_rep, 0));
+
 const char *
 MR_trace_set_level_from_layout(const MR_Label_Layout *level_layout,
     MR_Word *base_sp, MR_Word *base_curfr, int ancestor_level,
@@ -319,6 +284,7 @@
     MR_TypeInfo             *type_params;
     MR_Word                 value;
     MR_TypeInfo             type_info;
+    MR_TypeCtorInfo         type_ctor_info;
     MR_PseudoTypeInfo       pseudo_type_info;
     int                     i;
     int                     slot;
@@ -457,6 +423,26 @@
         {
             /* this value is not a variable */
             continue;
+        }
+
+        type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
+
+        if (type_ctor_info == &MR_TYPE_CTOR_INFO_NAME(io, input_stream, 0)
+        ||  type_ctor_info == &MR_TYPE_CTOR_INFO_NAME(io, output_stream, 0)
+        ||  type_ctor_info == &MR_TYPE_CTOR_INFO_NAME(io, stream, 0))
+        {
+            MR_MercuryFilePtr   mfp;
+            MR_Word             stream_rep;
+            MR_Integer          stream_id;
+            MR_String           stream_name;
+
+            mfp = (MR_MercuryFilePtr) value;
+            stream_id = MR_mf_id(*mfp);
+            MR_make_aligned_string_copy(stream_name, MR_mf_name(*mfp));
+            ML_io_make_stream_rep(stream_id, stream_name, &stream_rep);
+            type_info = (MR_TypeInfo)
+                &MR_TYPE_CTOR_INFO_NAME(io, stream_rep, 0);
+            value = stream_rep;
         }
 
         MR_point.MR_point_vars[slot].MR_var_hlds_number = var_num;
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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