Files
mercury/tests/hard_coded/print_stream.exp
Julien Fischer 2d25acf696 Change the representation of file streams in the io module so that they
Estimated hours taken: 25
Branches: main

Change the representation of file streams in the io module so that they
can be used as typeclass instances.  This is not currently possible because
file streams are defined as equivalence types and making them typeclass
instances results in overlapping instances.

This diff changes the representation by putting notag wrappers around the
various file stream types: io.input_stream, io.output_stream,
io.binary_input_stream, etc.  This avoids the problem with overlapping
instances.  It also improves type-safety; it is now not possible to pass a
binary input stream where a binary output stream is expected and so forth.

This change is complicated by the fact that the io module interacts with both
the runtime and the debugger via the C interface.  In order to preserve the
existing C interface that the io module presents to the runtime (the
alternative being to more or less change all the argument types to MR_Word),
the I/O operations that operate on file streams have been split into two
parts: a "typed" part that is exported from the io module and an "untyped"
part that deals with primitive streams (the io.stream type).

For the debugger the problem is the reverse since there we typically pass
values of type MercuryFilePtr to exported Mercury procedures.  In order
to avoid warnings from gcc we add a set of macros to the runtime that
wrap or unwrap MercuryFilePtrs.  There should be no performance impact
since the macros just expand to casts.

library/io.m:
	Do not define the various I/O streams as equivalence types in order
	to avoid problems with overlapping instances when these types are
	used as typeclass instances.

	Mark io.seek_binary/5 and io.binary_stream_offset/4 as obsolete.
	Add a typeclass io.binary_stream and make both binary file stream
	types instances of it.  This is so that the above predicates will
	continue to work until they are deleted.

	Add new predicates: io.seek_binary_input/5, io.seek_binary_output/5
	io.binary_input_stream_offset/4 and io.binary_input_stream_offset/4
	to replace the above.

	When using io.write to print file streams strip off the wrapper
	before printing the entry from the stream database.  The information
	in the wrapper is redundant - we use that from the stream db since
	that is more detailed.

	Format some section headings to conform with our current coding
	standard.

	Lots of minor formatting changes.

runtime/mercury_init.h:
	s/io.h/io.mh/ in a comment.

runtime/mercury_library_types.h:
	Add macros to wrap (and in one case unwrap) file stream types
	as we pass them across the C interface.  This avoids warnings
	from gcc.

browser/listing.m:
	Upwrap the input stream passed to mercury_stream_to_c_FILE_star
	before trying to extract the underlying C file pointer.

trace/mercury_trace_browse.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Use the new macros in the runtime to wrap streams that we pass back to
	Mercury procedures.

compiler/export.m:
	Unrelated change: s/Word/MR_Word/

NEWS:
	Announce the changes to the io module.

tests/debugger/declarative/io_stream_test.exp2:
	Conform to the changes in the io module.

tests/hard_coded/Mmakefile:
tests/hard_coded/print_stream.{m,exp}:
	Test for io.write and file streams.

tests/invalid/Mmakefile:
tests/invalid/mixed_up_streams.{m,err_exp}:
	Test that it isn't possible to pass binary input streams where
	binary output streams are expected.

tests/valid/Mmakefile:
tests/valid/file_stream_instances.m:
	Add a test case to check that we can use the various file stream
	types as typeclass instances.
2006-10-09 06:40:29 +00:00

6 lines
133 B
Plaintext

stream(0, input, preopen, stdin)
stream(1, output, preopen, stdout)
stream(1, output, preopen, stderr)
unknown_stream
unknown_stream