[m-rev.] diff: fixes for extras/streams

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 22 22:03:56 AEDT 2001


Estimated hours taken: 0.5
Branches: main

extras/stream/Mmakefile:
	Copy the files needed from ../concurrency automatically,
	rather than requiring the user to do it manually.
	Also make `libstream' in the rule for `mmake check'.

extras/stream/README:
	Mention that the copying will be done automatically.

extras/stream/impure.m:
extras/stream/lowlevel.m:
extras/stream/stream.m:
	Fix some software rot: s/mutvar/mvar/g

Workspace: /home/earth/fjh/ws-earth3/mercury
Index: extras/stream/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/stream/Mmakefile,v
retrieving revision 1.1
diff -u -d -r1.1 Mmakefile
--- extras/stream/Mmakefile	22 Nov 2000 14:01:51 -0000	1.1
+++ extras/stream/Mmakefile	22 Nov 2001 10:58:19 -0000
@@ -4,6 +4,21 @@
 # Public License - see the file COPYING.LIB in the Mercury distribution.
 #-----------------------------------------------------------------------------#
 
+-include ../Mmake.params
+
 MAIN_TARGET=libstream
 
 depend: stream.depend
+
+stream stream.depend: mvar.m semaphore.m
+
+mvar.m: ../concurrency/mvar.m
+	cp ../concurrency/mvar.m .
+semaphore.m: ../concurrency/semaphore.m
+	cp ../concurrency/semaphore.m .
+
+realclean:
+	rm -f mvar.m semaphore.m
+
+check: libstream
+	true
Index: extras/stream/README
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/stream/README,v
retrieving revision 1.1
diff -u -d -r1.1 README
--- extras/stream/README	22 Nov 2000 14:01:52 -0000	1.1
+++ extras/stream/README	22 Nov 2001 11:00:47 -0000
@@ -3,8 +3,9 @@
 own stream types and can write generic code that will work on any
 appropriate stream.
 
-To build this library you need mutvar.m and semaphore.m from the
-extras/concurrency directory.
+To build this library you need mvar.m and semaphore.m from the
+extras/concurrency directory.  (The Mmakefile rules should copy these
+here automatically.)
 
 The following files implement the stream interfaces at various levels
 
Index: extras/stream/impure.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/stream/impure.m,v
retrieving revision 1.1
diff -u -d -r1.1 impure.m
--- extras/stream/impure.m	22 Nov 2000 14:01:52 -0000	1.1
+++ extras/stream/impure.m	22 Nov 2001 10:54:50 -0000
@@ -32,6 +32,7 @@
 
 :- import_module stream.
 :- import_module char.
+:- import_module io.
 
 	% A handle on the impure stream.
 :- type impure(S).
@@ -82,24 +83,24 @@
 
 :- implementation.
 
-:- import_module mutvar.
+:- import_module mvar.
 :- import_module exception, std_util.
 
 :- type impure(S)
 	--->	impure(
 			S,		% Handle
-			mutvar(unit)	% Mutvar used as a semaphore to
+			mvar(unit)	% Mvar used as a semaphore to
 					% ensure the atomicity of
 					% operations.
 		).
 
 impure_init(S, impure(S, MVar)) -->
-	mutvar__init(MVar),
-	mutvar__put(MVar, unit).
+	mvar__init(MVar),
+	mvar__put(MVar, unit).
 
 :- pragma promise_pure(pure_read_char/4).
 pure_read_char(impure(Stream, MVar), Result, IO0, IO) :-
-	mutvar__take(MVar, Unit, IO0, IO1),
+	mvar__take(MVar, Unit, IO0, IO1),
 	( impure impure__read_char(Stream, Chr) ->
 		Result = ok(Chr)
 	;
@@ -112,22 +113,22 @@
 			Result = error(Error)
 		)
 	),
-	mutvar__put(MVar, Unit, IO1, IO).
+	mvar__put(MVar, Unit, IO1, IO).
 
 %-----------------------------------------------------------------------------%
 
 :- pragma promise_pure(pure_write_char/4).
 pure_write_char(impure(Stream, MVar), Chr, IO0, IO) :-
-	mutvar__take(MVar, Unit, IO0, IO1),
+	mvar__take(MVar, Unit, IO0, IO1),
 	( impure impure__write_char(Stream, Chr) ->
-		mutvar__put(MVar, Unit, IO1, IO)
+		mvar__put(MVar, Unit, IO1, IO)
 	;
 		( impure impure__get_error(Stream, Err0) ->
 			Err = Err0
 		;
 			Err = "write char failed but there is no error message"
 		),
-		mutvar__put(MVar, Unit, IO1, IO),
+		mvar__put(MVar, Unit, IO1, IO),
 		throw(stream_error(Err))
 	).
 
Index: extras/stream/lowlevel.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/stream/lowlevel.m,v
retrieving revision 1.1
diff -u -d -r1.1 lowlevel.m
--- extras/stream/lowlevel.m	22 Nov 2000 14:01:52 -0000	1.1
+++ extras/stream/lowlevel.m	22 Nov 2001 10:55:12 -0000
@@ -28,7 +28,7 @@
 :- interface.
 
 :- import_module stream.
-:- import_module bool, char.
+:- import_module bool, char, io.
 
 	% A handle on the lowlevel stream.
 :- type lowlevel(S).
@@ -89,23 +89,23 @@
 
 :- implementation.
 
-:- import_module mutvar.
+:- import_module mvar.
 :- import_module exception, std_util.
 
 :- type lowlevel(S)
 	--->	lowlevel(
 			S,		% Handle
-			mutvar(unit)	% Mutvar used as a semaphore to
+			mvar(unit)	% Mvar used as a semaphore to
 					% ensure the atomicity of
 					% operations.
 		).
 
 init(S, lowlevel(S, MVar)) -->
-	mutvar__init(MVar),
-	mutvar__put(MVar, unit).
+	mvar__init(MVar),
+	mvar__put(MVar, unit).
 
 low_read_char(lowlevel(Stream, MVar), Result) -->
-	mutvar__take(MVar, Unit),
+	mvar__take(MVar, Unit),
 	read_char(Stream, Chr, ReadBool), 
 	( { ReadBool = yes } ->
 		{ Result = ok(Chr) }
@@ -123,15 +123,15 @@
 			)
 		)
 	),
-	mutvar__put(MVar, Unit).
+	mvar__put(MVar, Unit).
 
 %-----------------------------------------------------------------------------%
 
 low_write_char(lowlevel(Stream, MVar), Chr) -->
-	mutvar__take(MVar, Unit),
+	mvar__take(MVar, Unit),
 	write_char(Stream, Chr, WriteBool),
 	( { WriteBool = yes } ->
-		mutvar__put(MVar, Unit)
+		mvar__put(MVar, Unit)
 	;
 		get_error(Stream, Err0, ErrorBool),
 		{ ErrorBool = yes ->
@@ -139,7 +139,7 @@
 		;
 			Err = "write char failed but there is no error message"
 		},
-		mutvar__put(MVar, Unit),
+		mvar__put(MVar, Unit),
 		{ throw(stream_error(Err)) }
 	).
 
Index: extras/stream/stream.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/stream/stream.m,v
retrieving revision 1.1
diff -u -d -r1.1 stream.m
--- extras/stream/stream.m	22 Nov 2000 14:01:53 -0000	1.1
+++ extras/stream/stream.m	22 Nov 2001 10:58:58 -0000
@@ -200,13 +200,13 @@
 	% library.
 :- import_module (impure), lowlevel.
 
-:- import_module mutvar.
+:- import_module mvar.
 :- import_module int, string.
 
 :- type putback(S)
 	--->	pb(
 			S,
-			mutvar(list(char))
+			mvar(list(char))
 		).
 
 :- instance stream(putback(S)) <= stream(S) where [
@@ -222,8 +222,8 @@
 ].
 
 putback_stream(Stream, pb(Stream, MPutbackChars)) -->
-	mutvar__init(MPutbackChars),
-	mutvar__put(MPutbackChars, []).
+	mvar__init(MPutbackChars),
+	mvar__put(MPutbackChars, []).
 
 putback_base_stream(pb(Stream, _)) = Stream.
 
@@ -231,7 +231,7 @@
 		io__state::di, io__state::uo) is det <= stream__input(S).
 
 putback_read_char(pb(Stream, MPutbackChars), Result) -->
-	mutvar__take(MPutbackChars, PutbackChars),
+	mvar__take(MPutbackChars, PutbackChars),
 	(
 		{ PutbackChars = [] },
 		{ NewPutbackChars = PutbackChars },
@@ -240,21 +240,21 @@
 		{ PutbackChars = [Char | NewPutbackChars] },
 		{ Result = ok(Char) }
 	),
-	mutvar__put(MPutbackChars, NewPutbackChars).
+	mvar__put(MPutbackChars, NewPutbackChars).
 
 :- pred putback_putback_char(putback(S)::in, char::in,
 		io__state::di, io__state::uo) is det <= stream__input(S).
 
 putback_putback_char(pb(_Stream, MPutbackChars), Char) -->
-	mutvar__take(MPutbackChars, PutbackChars),
-	mutvar__put(MPutbackChars, [Char | PutbackChars]).
+	mvar__take(MPutbackChars, PutbackChars),
+	mvar__put(MPutbackChars, [Char | PutbackChars]).
 
 %-----------------------------------------------------------------------------%
 
 :- type linenumber(S)
 	--->	line(
 			S,		% stream
-			mutvar(int)	% line number
+			mvar(int)	% line number
 		).
 
 :- instance stream(linenumber(S)) <= stream(S) where [
@@ -275,8 +275,8 @@
 ].
 
 linenumber_stream(S, line(S, MLine)) -->
-	mutvar__init(MLine),
-	mutvar__put(MLine, 0).
+	mvar__init(MLine),
+	mvar__put(MLine, 0).
 
 linenumber_base_stream(line(Stream, _)) = Stream.
 
@@ -286,8 +286,8 @@
 linenumber_read_char(line(Stream, MLine), Result) -->
 	stream__read_char(Stream, Result),
 	( { Result = ok('\n') } ->
-		mutvar__take(MLine, Line),
-		mutvar__put(MLine, Line + 1)
+		mvar__take(MLine, Line),
+		mvar__put(MLine, Line + 1)
 	;
 		[]
 	).
@@ -298,8 +298,8 @@
 linenumber_putback_char(line(Stream, MLine), Char) -->
 	stream__putback_char(Stream, Char),
 	( { Char = '\n' } ->
-		mutvar__take(MLine, Line),
-		mutvar__put(MLine, Line - 1)
+		mvar__take(MLine, Line),
+		mvar__put(MLine, Line - 1)
 	;
 		[]
 	).
@@ -308,15 +308,15 @@
 		io__state::di, io__state::uo) is det.
 
 linenumber(line(_, MLine), Line) -->
-	mutvar__take(MLine, Line),
-	mutvar__put(MLine, Line).
+	mvar__take(MLine, Line),
+	mvar__put(MLine, Line).
 
 :- pred set_linenumber(linenumber(S)::in, int::in,
 		io__state::di, io__state::uo) is det.
 
 set_linenumber(line(_, MLine), Line) -->
-	mutvar__take(MLine, _OldLine),
-	mutvar__put(MLine, Line).
+	mvar__take(MLine, _OldLine),
+	mvar__put(MLine, Line).
 
 %-----------------------------------------------------------------------------%
 

-- 
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