[MLton-devel] cvs commit: basis library slices

Stephen Weeks sweeks@users.sourceforge.net
Wed, 24 Sep 2003 18:43:27 -0700


sweeks      03/09/24 18:43:27

  Modified:    basis-library/io bin-io.sml bin-or-text-io.fun
                        bin-prim-io.sml buffer-i.fun prim-io.fun
                        prim-io.sig stream-io.fun text-io.sml
                        text-prim-io.sml
               basis-library/libs/basis-1997/posix io-convert.fun
               basis-library/libs/basis-2002/top-level basis-funs.sml
               basis-library/mlton random.sml
               basis-library/posix file-sys.sml io.sig io.sml primitive.sml
                        process.sml
               basis-library/real pack-real.sml
               basis-library/text byte.sig byte.sml
               doc      changelog
               regression bytechar.sml
  Log:
  Tracking the basis library changes to use slices where possible: Byte,
  PRIM_IO, PrimIO, Posix.IO, StreamIO.  I haven't yet done Socket,
  but plan to do so soon.

Revision  Changes    Path
1.10      +5 -3      mlton/basis-library/io/bin-io.sml

Index: bin-io.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/bin-io.sml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- bin-io.sml	9 May 2003 12:48:34 -0000	1.9
+++ bin-io.sml	25 Sep 2003 01:43:25 -0000	1.10
@@ -33,19 +33,21 @@
       structure S = struct
 		      structure PrimIO = BinPrimIO
 		      structure Array = Word8Array
+		      structure ArraySlice = Word8ArraySlice
 		      structure Vector = Word8Vector
+		      structure VectorSlice = Word8VectorSlice
 		      val someElem = (0wx0: Word8.word)
 		      val lineElem = (0wx0: Word8.word)
 		      fun isLine _ = false
 		      structure Cleaner = Cleaner
 		    end
-      structure StreamIO = StreamIOExtraFile(open S)
+      structure StreamIO = StreamIOExtraFile (open S)
       structure SIO = StreamIO
       structure S = struct 
 		      open S 
 		      structure StreamIO = StreamIO
 		    end
-      structure BufferI = BufferIExtraFile(open S)
+      structure BufferI = BufferIExtraFile (open S)
       structure BI = BufferI
       structure S = struct
 		      open S
@@ -55,7 +57,7 @@
 		      val mkReader = Posix.IO.mkBinReader
 		      val mkWriter = Posix.IO.mkBinWriter
 		    end
-      structure FastImperativeIO = FastImperativeIOExtraFile(open S)
+      structure FastImperativeIO = FastImperativeIOExtraFile (open S)
       open FastImperativeIO
    end
 



1.7       +17 -18    mlton/basis-library/io/bin-or-text-io.fun

Index: bin-or-text-io.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/bin-or-text-io.fun,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- bin-or-text-io.fun	9 May 2003 12:48:34 -0000	1.6
+++ bin-or-text-io.fun	25 Sep 2003 01:43:25 -0000	1.7
@@ -84,28 +84,27 @@
 
 fun isFull (Buf {size, ...}) = !size = bufSize
 
+structure AS = Word8ArraySlice
+structure VS = Word8VectorSlice
+   
 (* Write out to fd size bytes of buf starting at index i. *)
 fun flushGen (fd: FS.file_desc,
 	      buf: 'a,
 	      i: int,
 	      size: int,
-	      write: FS.file_desc * {buf: 'a,
-				     i: int,
-				     sz: int option} -> int): unit =
+	      slice: 'a * int * int option -> 'b,
+	      write: FS.file_desc * 'b -> int): unit =
    let
       val max = i + size
       fun loop i =
 	 if i = max
 	    then ()
-	 else
-	    loop (i + write (fd, {buf = buf,
-				  i = i,
-				  sz = SOME (max - i)}))
+	 else loop (i + write (fd, slice (buf, i, SOME (max - i))))
    in loop i
    end
 
 fun flush (fd, Buf {size, array}) =
-   (flushGen (fd, array, 0, !size, PIO.writeArr)
+   (flushGen (fd, array, 0, !size, AS.slice, PIO.writeArr)
     ; size := 0)
    
 datatype bufStyle =
@@ -247,7 +246,8 @@
    else
       let
 	 val v = NativeVector.toWord8Vector s
-	 fun put () = flushGen (fd, v, 0, Vector.length v, PIO.writeVec)
+	 fun put () =
+	    flushGen (fd, v, 0, Vector.length v, VS.slice, PIO.writeVec)
 	 fun doit (b as Buf {size, array}, maybe) =
 	    let
 	       val curSize = !size
@@ -297,7 +297,7 @@
 	    case bufStyle of
 	       Unbuffered =>
 		  (Array.update (buf1, 0, NativeVector.toByte c)
-		   ; flushGen (fd, buf1, 0, 1, PIO.writeArr))
+		   ; flushGen (fd, buf1, 0, 1, AS.slice, PIO.writeArr))
 	     | Line b => doit (b, NativeVector.isLine c)
 	     | Buffered b => doit (b, false)
 	 end handle exn => raise IO.Io {name = outName out,
@@ -385,9 +385,9 @@
 		 orelse
 		 (* need to read *)
 		 let
-		    val bytesRead =
-		       PIO.readArr (fd, {buf = buf, i = 0, sz = NONE})
-		 in if bytesRead = 0
+		    val bytesRead = PIO.readArr (fd, AS.full buf)
+		 in
+		    if bytesRead = 0
 		       then (eof := true; false)
 		    else (first := 0; last := bytesRead; true)
 		 end
@@ -464,9 +464,9 @@
 			else let
 				val bytesRead' =
 				   PIO.readArr
-				   (fd, {buf = dst, i = bytesRead,
-					 sz = SOME (bytesToRead
-						    -? bytesRead)})
+				   (fd,
+				    AS.slice (dst, bytesRead,
+					      SOME (bytesToRead -? bytesRead)))
 			     in if bytesRead' = 0
 				   then (eof := true
 					 ; first := !last
@@ -575,8 +575,7 @@
 		     else
 			let
 			   val buf = Primitive.Array.array bufSize
-			   val n =
-			      PIO.readArr (fd, {buf = buf, i = 0, sz = NONE})
+			   val n = PIO.readArr (fd, AS.full buf)
 			   val buf =
 			      if n < bufSize
 				 then Array.tabulate (n, fn i =>



1.4       +12 -11    mlton/basis-library/io/bin-prim-io.sml

Index: bin-prim-io.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/bin-prim-io.sml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- bin-prim-io.sml	5 Sep 2003 23:01:01 -0000	1.3
+++ bin-prim-io.sml	25 Sep 2003 01:43:25 -0000	1.4
@@ -1,11 +1,12 @@
-
-structure BinPrimIO : PRIM_IO
-                      where type array = Word8Array.array
-		      where type vector = Word8Vector.vector
-		      where type elem = Word8.word
-		      where type pos = Position.int =
-  PrimIOExtra(structure Vector = Word8Vector
-	      structure Array = Word8Array
-	      val someElem = (0wx0: Word8.word)
-	      type pos = Position.int
-	      val compare = Position.compare)
+structure BinPrimIO: PRIM_IO
+                     where type array = Word8Array.array
+		     where type vector = Word8Vector.vector
+		     where type elem = Word8.word
+		     where type pos = Position.int =
+  PrimIO (structure Array = Word8Array
+	  structure ArraySlice = Word8ArraySlice
+	  structure Vector = Word8Vector
+	  structure VectorSlice = Word8VectorSlice
+	  type pos = Position.int
+	  val compare = Position.compare
+	  val someElem = 0wx0: Word8.word)



1.9       +79 -66    mlton/basis-library/io/buffer-i.fun

Index: buffer-i.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/buffer-i.fun,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- buffer-i.fun	24 Sep 2003 17:45:25 -0000	1.8
+++ buffer-i.fun	25 Sep 2003 01:43:25 -0000	1.9
@@ -6,30 +6,38 @@
                           include MONO_ARRAY
 			  val rawArray: int -> array
 		       end
+      structure ArraySlice: MONO_ARRAY_SLICE
       structure Vector: sig 
 	                   include MONO_VECTOR
                            val fromArray: Array.array -> vector
 			end
-      sharing type PrimIO.elem = StreamIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = StreamIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
-      sharing type PrimIO.reader = StreamIO.reader
+      structure VectorSlice: MONO_VECTOR_SLICE
+      sharing type Array.array = ArraySlice.array = PrimIO.array
+      sharing type Array.elem = ArraySlice.elem = PrimIO.elem = StreamIO.elem
+	 = Vector.elem = VectorSlice.elem
+      sharing type Array.vector = ArraySlice.vector = PrimIO.vector
+	 = StreamIO.vector = Vector.vector = VectorSlice.vector
+      sharing type ArraySlice.slice = PrimIO.array_slice
+      sharing type ArraySlice.vector_slice = PrimIO.vector_slice
+	 = VectorSlice.slice
       sharing type PrimIO.pos = StreamIO.pos
-      val someElem: PrimIO.elem
+      sharing type PrimIO.reader = StreamIO.reader
 
-      val lineElem: Vector.elem
       val isLine: Vector.elem -> bool
+      val lineElem: Vector.elem
+      val someElem: PrimIO.elem
    end
 
-functor BufferIExtra
-        (S: BUFFER_I_EXTRA_ARG): BUFFER_I_EXTRA =
+functor BufferIExtra (S: BUFFER_I_EXTRA_ARG): BUFFER_I_EXTRA =
    struct
       open S
 
       structure PIO = PrimIO
       structure SIO = StreamIO
-      structure V = Vector
       structure A = Array
+      structure AS = ArraySlice
+      structure V = Vector
+      structure VS = VectorSlice
 
       type elem = PrimIO.elem
       type vector = PrimIO.vector
@@ -80,7 +88,7 @@
 		   let
 		     fun doit readArr =
 		       let
-			 val i = readArr {buf = buf, i = 0, sz = NONE}
+			 val i = readArr (AS.full buf)
 			         handle exn =>
 				 liftExn (inbufferName ib) function exn
 		       in
@@ -134,7 +142,7 @@
 		let
 		  fun loop read =
 		    let
-		      val i = readArr {buf = buf, i = read, sz = NONE}
+		      val i = readArr (AS.full buf)
 			      handle exn =>
 			      liftExn (inbufferName ib) function exn
 		    in
@@ -251,9 +259,7 @@
 				       else let
 					      val j = 
 						readArr
-						{buf = inp,
-						 i = i,
-						 sz = SOME (n - i)}
+						(AS.slice (inp, i, SOME (n - i)))
 						handle exn => 
 					        liftExn (inbufferName ib) "inputN" exn
 					    in
@@ -446,77 +452,84 @@
 	getInstream' SIO.mkInstream' ib
    end
 
-signature BUFFER_I_ARG = 
-   sig
-      structure PrimIO: PRIM_IO
-      structure StreamIO: STREAM_IO
-      structure Array: MONO_ARRAY
-      structure Vector: MONO_VECTOR
-      sharing type PrimIO.elem = StreamIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = StreamIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
-      sharing type PrimIO.reader = StreamIO.reader
-      sharing type PrimIO.pos = StreamIO.pos
-      val someElem: PrimIO.elem
-   end
-functor BufferI
-        (S: BUFFER_I_ARG): BUFFER_I = 
-  BufferIExtra(open S
-	       structure Array =
-		  struct
-		     open Array
-		     fun rawArray n = Array.array (n, someElem)
-		  end
-	       structure Vector =
-		  struct
-		     open Vector
-		     fun fromArray a = 
-		       tabulate(Array.length a, fn i => Array.sub (a, i))
-		  end
-	       structure StreamIO =
-		  struct
-		     open StreamIO
-		     fun input1' _ = raise (Fail "<input1'>")
-		     fun equalsIn _ = raise (Fail "<equalsIn>")
-		     fun instreamReader _ = raise (Fail "<instreamReader>")
-		     fun mkInstream' _ = raise (Fail "<mkInstream>")
-		     fun equalsOut _ = raise (Fail "<equalsOut>")
-		     fun outstreamWriter _ = raise (Fail "<outstreamWriter>")
-		     fun mkOutstream' _ = raise (Fail "<mkOutstream>")
-		     fun openVector _ = raise (Fail "<openVector>")
-		     fun inputLine _ = raise (Fail "<inputLine>")
-		     fun outputSlice _ = raise (Fail "<outputSlice>")
-		  end
-	       val lineElem = someElem
-	       fun isLine _ = raise (Fail "<isLine>"))
+(* signature BUFFER_I_ARG = 
+ *    sig
+ *       structure PrimIO: PRIM_IO
+ *       structure StreamIO: STREAM_IO
+ *       structure Array: MONO_ARRAY
+ *       structure Vector: MONO_VECTOR
+ *       sharing type PrimIO.elem = StreamIO.elem = Vector.elem = Array.elem
+ *       sharing type PrimIO.vector = StreamIO.vector = Vector.vector = Array.vector
+ *       sharing type PrimIO.array = Array.array
+ *       sharing type PrimIO.reader = StreamIO.reader
+ *       sharing type PrimIO.pos = StreamIO.pos
+ *       val someElem: PrimIO.elem
+ *    end
+ * functor BufferI
+ *         (S: BUFFER_I_ARG): BUFFER_I = 
+ *   BufferIExtra(open S
+ * 	       structure Array =
+ * 		  struct
+ * 		     open Array
+ * 		     fun rawArray n = Array.array (n, someElem)
+ * 		  end
+ * 	       structure Vector =
+ * 		  struct
+ * 		     open Vector
+ * 		     fun fromArray a = 
+ * 		       tabulate(Array.length a, fn i => Array.sub (a, i))
+ * 		  end
+ * 	       structure StreamIO =
+ * 		  struct
+ * 		     open StreamIO
+ * 		     fun input1' _ = raise (Fail "<input1'>")
+ * 		     fun equalsIn _ = raise (Fail "<equalsIn>")
+ * 		     fun instreamReader _ = raise (Fail "<instreamReader>")
+ * 		     fun mkInstream' _ = raise (Fail "<mkInstream>")
+ * 		     fun equalsOut _ = raise (Fail "<equalsOut>")
+ * 		     fun outstreamWriter _ = raise (Fail "<outstreamWriter>")
+ * 		     fun mkOutstream' _ = raise (Fail "<mkOutstream>")
+ * 		     fun openVector _ = raise (Fail "<openVector>")
+ * 		     fun inputLine _ = raise (Fail "<inputLine>")
+ * 		     fun outputSlice _ = raise (Fail "<outputSlice>")
+ * 		  end
+ * 	       val lineElem = someElem
+ * 	       fun isLine _ = raise (Fail "<isLine>"))
+ *)
 
 signature BUFFER_I_EXTRA_FILE_ARG =
    sig
       structure PrimIO: PRIM_IO
       structure StreamIO: STREAM_IO_EXTRA_FILE
       structure Array: sig
-	                  include MONO_ARRAY
+                          include MONO_ARRAY
 			  val rawArray: int -> array
 		       end
+      structure ArraySlice: MONO_ARRAY_SLICE
       structure Vector: sig 
 	                   include MONO_VECTOR
                            val fromArray: Array.array -> vector
 			end
-      sharing type PrimIO.elem = StreamIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = StreamIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
-      sharing type PrimIO.reader = StreamIO.reader
+      structure VectorSlice: MONO_VECTOR_SLICE
+      sharing type Array.array = ArraySlice.array = PrimIO.array
+      sharing type Array.elem = ArraySlice.elem = PrimIO.elem = StreamIO.elem
+	 = Vector.elem = VectorSlice.elem
+      sharing type Array.vector = ArraySlice.vector = PrimIO.vector
+	 = StreamIO.vector = Vector.vector = VectorSlice.vector
+      sharing type ArraySlice.slice = PrimIO.array_slice
+      sharing type ArraySlice.vector_slice = PrimIO.vector_slice
+	 = VectorSlice.slice
       sharing type PrimIO.pos = StreamIO.pos
-      val someElem: PrimIO.elem
+      sharing type PrimIO.reader = StreamIO.reader
 
-      val lineElem: Vector.elem
       val isLine: Vector.elem -> bool
+      val lineElem: Vector.elem
+      val someElem: PrimIO.elem
 
       structure Cleaner: CLEANER
    end
 
-functor BufferIExtraFile
-        (S: BUFFER_I_EXTRA_FILE_ARG): BUFFER_I_EXTRA_FILE =
+functor BufferIExtraFile (S: BUFFER_I_EXTRA_FILE_ARG): BUFFER_I_EXTRA_FILE =
    struct
       open S
 



1.5       +311 -323  mlton/basis-library/io/prim-io.fun

Index: prim-io.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/prim-io.fun,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- prim-io.fun	5 Sep 2003 23:01:01 -0000	1.4
+++ prim-io.fun	25 Sep 2003 01:43:25 -0000	1.5
@@ -1,342 +1,330 @@
-signature PRIM_IO_EXTRA_ARG =
+signature PRIM_IO_ARG =
    sig
-     structure Vector: MONO_VECTOR
-     structure Array: MONO_ARRAY
-     sharing type Vector.elem = Array.elem 
-     sharing type Vector.vector = Array.vector
-     val someElem : Vector.elem
-     eqtype pos
-     val compare : (pos * pos) -> order
+      structure Array: MONO_ARRAY
+      structure ArraySlice: MONO_ARRAY_SLICE
+      structure Vector: MONO_VECTOR
+      structure VectorSlice: MONO_VECTOR_SLICE
+      sharing type Array.array = ArraySlice.array
+      sharing type Array.elem = ArraySlice.elem = Vector.elem = VectorSlice.elem
+      sharing type Array.vector = ArraySlice.vector = Vector.vector
+	 = VectorSlice.vector
+      sharing type ArraySlice.vector_slice = VectorSlice.slice
+	
+      eqtype pos
+
+      val compare: (pos * pos) -> order
+      val someElem: Vector.elem
+   end
+
+functor PrimIO (S: PRIM_IO_ARG): PRIM_IO = 
+struct
+
+open S
+
+structure A = Array
+structure AS = ArraySlice
+structure V = Vector
+structure VS = VectorSlice
+
+type array = A.array
+type array_slice = AS.slice
+type vector = V.vector
+type vector_slice = VS.slice
+type elem = A.elem
+type pos = pos
+val compare = compare
+
+datatype reader =
+   RD of {avail: unit -> int option,
+	  block: (unit -> unit) option,
+	  canInput: (unit -> bool) option,
+	  chunkSize: int,
+	  close: unit -> unit,
+	  endPos: (unit -> pos) option,
+	  getPos: (unit -> pos) option,
+	  ioDesc: OS.IO.iodesc option,
+	  name: string,
+	  readArr: (array_slice -> int) option,
+	  readArrNB: (array_slice -> int option) option,
+	  readVec: (int -> vector) option,
+	  readVecNB: (int -> vector option) option,
+	  setPos: (pos -> unit) option,
+	  verifyPos: (unit -> pos) option}
+
+datatype writer =
+   WR of {block: (unit -> unit) option,
+	  canOutput: (unit -> bool) option,
+	  chunkSize: int,
+	  close: unit -> unit,
+	  endPos: (unit -> pos) option,
+	  getPos: (unit -> pos) option,
+	  ioDesc: OS.IO.iodesc option,
+	  name: string,
+	  setPos: (pos -> unit) option,
+	  verifyPos: (unit -> pos) option,
+	  writeArr: (array_slice -> int) option,
+	  writeArrNB: (array_slice -> int option) option,
+	  writeVec: (vector_slice -> int) option,
+	  writeVecNB: (vector_slice -> int option) option}
+
+
+
+fun liftExn name function cause = raise IO.Io {name = name,
+					       function = function,
+					       cause = cause}
+fun openVector v =
+   let
+      val name = "openVector"
+      val closed = ref false
+      val empty = V.tabulate (0, fn _ => someElem)
+      val pos = ref 0
+      val eofPos = V.length v
+      fun check f = if !closed
+		       then liftExn name f IO.ClosedStream
+		    else ()
+      fun const f c = fn _ => (check f; c)
+      fun function f g = fn x => (check f; g x)
+      fun readVec f i =
+	 let
+	    val _ = check f
+	    val n = Int.min (i, eofPos - !pos)
+	 in
+	    V.tabulate (n, fn i => (V.sub (v, !pos)) before (pos := !pos + 1))
+	 end
+      fun readArr f sl =
+	 let
+	    val _ = check f
+	    val (buf, i, sz) = ArraySlice.base sl
+	    val n = Int.min (sz, eofPos - !pos)
+	    fun loop j = if j >= n
+			    then ()
+			 else (A.update (buf, i + j, V.sub (v, !pos));
+			       pos := !pos + 1;
+			       loop (j + 1))
+	 in
+	    loop 0;
+	    n
+	 end
+   in
+      RD {avail = const "avail" NONE,
+	  block = SOME (const "block" ()),
+	  canInput = SOME (const "canInput" true),
+	  chunkSize = 32,
+	  close = fn () => (closed := true),
+	  endPos = NONE,
+	  getPos = NONE,
+	  ioDesc = NONE,
+	  name = name,
+	  readArr = SOME (readArr "readArr"),
+	  readArrNB = SOME (SOME o (readArr "readVecNB")),
+	  readVec = SOME (readVec "readVec"),
+	  readVecNB = SOME (SOME o (readVec "readVecNB")),
+	  setPos = NONE,
+	  verifyPos = NONE}
+   end
+
+fun nullRd () =
+   let
+      val name = "nullRd"
+      val closed = ref false
+      fun check f = if !closed
+		       then liftExn name f IO.ClosedStream
+		    else ()
+      fun const f c = fn _ => (check f; c)
+      fun function f g = fn x => (check f; g x)
+      val empty = V.fromList []
+   in
+      RD {avail = const "avail" NONE,
+	  block = SOME (const "block" ()),
+	  canInput = SOME (const "canInput" true),
+	  chunkSize = 1,
+	  close = fn () => (closed := true),
+	  endPos = NONE,
+	  getPos = NONE,
+	  ioDesc = NONE,
+	  name = name,
+	  readArr = SOME (const "readArr" 0),
+	  readArrNB = SOME (const "readArrNB" (SOME 0)),
+	  readVec = SOME (const "readVec" empty),
+	  readVecNB = SOME (const "readVecNB" (SOME empty)),
+	  setPos = NONE,
+	  verifyPos = NONE}
    end
 
-functor PrimIOExtra 
-        (S : PRIM_IO_EXTRA_ARG): PRIM_IO_EXTRA = 
-   struct
-      open S
-
-      structure A = Array
-      structure V = Vector
-
-      type array = A.array
-      type vector = V.vector
-      type elem = A.elem
-      type pos = pos
-      val compare = compare
-
-      datatype reader = RD of {name: string,
-			       chunkSize: int,
-			       readVec: (int -> vector) option,
-			       readArr: ({buf: array, 
-					  i: int,
-					  sz: int option} -> int) option,
-			       readVecNB: (int -> vector option) option,
-			       readArrNB: ({buf: array, 
-					    i: int, 
-					    sz: int option} -> int option) option,
-			       block: (unit -> unit) option,
-			       canInput: (unit -> bool) option,
-			       avail: unit -> int option,
-			       getPos: (unit -> pos) option,
-			       setPos: (pos -> unit) option,
-			       endPos: (unit -> pos) option,
-			       verifyPos: (unit -> pos) option,
-			       close: unit -> unit,
-			       ioDesc: OS.IO.iodesc option}
-      datatype writer = WR of {name: string,
-			       chunkSize: int,
-			       writeVec: ({buf: vector, 
-					   i: int, 
-					   sz: int option} -> int) option,
-			       writeArr: ({buf: array, 
-					   i: int, 
-					   sz: int option} -> int) option,
-			       writeVecNB: ({buf: vector, 
-					     i: int, 
-					     sz: int option} -> int option) option,
-			       writeArrNB: ({buf: array, 
-					     i: int, 
-					     sz: int option} -> int option) option,
-			       block: (unit -> unit) option,
-			       canOutput: (unit -> bool) option,
-			       getPos: (unit -> pos) option,
-			       setPos: (pos -> unit) option,
-			       endPos: (unit -> pos) option,
-			       verifyPos: (unit -> pos) option,
-			       close: unit -> unit,
-			       ioDesc: OS.IO.iodesc option}
-
-      fun liftExn name function cause = raise IO.Io {name = name,
-						     function = function,
-						     cause = cause}
-      fun openVector v =
-	let
-	  val name = "openVector"
-	  val closed = ref false
-	  val empty = V.tabulate (0, fn _ => someElem)
-	  val pos = ref 0
-	  val eofPos = V.length v
-	  fun check f = if !closed
-			  then liftExn name f IO.ClosedStream
-			  else ()
-	  fun const f c = fn _ => (check f; c)
-	  fun function f g = fn x => (check f; g x)
-	  fun readVec f i =
-	    let
-	      val _ = check f
-	      val n = Int.min (i, eofPos - !pos)
-	    in
-	      V.tabulate (n, fn i => (V.sub (v, !pos)) before (pos := !pos + 1))
-	    end
-	  fun readArr f {buf, i, sz} =
-	    let
-	      val _ = check f
-	      val n = Int.min (case sz of
-				 SOME sz => sz
-			       | NONE => A.length buf - i, eofPos - !pos)
-	      fun loop j = if j >= n
-			     then ()
-			     else (A.update (buf, i + j, V.sub (v, !pos));
-				   pos := !pos + 1;
-				   loop (j + 1))
-	    in
-	      loop 0;
-	      n
-	    end
-	in
-	  RD {name = name,
-	      chunkSize = 32,
-	      readVec = SOME (readVec "readVec"),
-	      readArr = SOME (readArr "readArr"),
-	      readVecNB = SOME (SOME o (readVec "readVecNB")),
-	      readArrNB = SOME (SOME o (readArr "readVecNB")),
-	      block = SOME (const "block" ()),
-	      canInput = SOME (const "canInput" true),
-	      avail = const "avail" NONE,
-	      getPos = NONE,
-	      setPos = NONE,
-	      endPos = NONE,
-	      verifyPos = NONE,
-	      close = fn () => (closed := true),
-	      ioDesc = NONE}
-	end
-      fun nullRd () =
-	let
-	  val name = "nullRd"
-	  val closed = ref false
-	  fun check f = if !closed
-			  then liftExn name f IO.ClosedStream
-			  else ()
-	  fun const f c = fn _ => (check f; c)
-	  fun function f g = fn x => (check f; g x)
-	  val empty = V.fromList []
-	in
-	  RD {name = name,
-	      chunkSize = 1,
-	      readVec = SOME (const "readVec" empty),
-	      readArr = SOME (const "readArr" 0),
-	      readVecNB = SOME (const "readVecNB" (SOME empty)),
-	      readArrNB = SOME (const "readArrNB" (SOME 0)),
-	      block = SOME (const "block" ()),
-	      canInput = SOME (const "canInput" true),
-	      avail = const "avail" NONE,
-	      getPos = NONE,
-	      setPos = NONE,
-	      endPos = NONE,
-	      verifyPos = NONE,
-	      close = fn () => (closed := true),
-	      ioDesc = NONE}
-	end
-      fun nullWr () =
-	let
-	  val name = "nullWr"
-	  val closed = ref false
-	  fun check f = if !closed
-			  then liftExn name f IO.ClosedStream
-			  else ()
-	  fun const f c = fn _ => (check f; c)
-	  fun function f g = fn x => (check f; g x)
-	  fun sizeS length {buf, i, sz} =
-	    case (length buf, sz) of
-	      (len, NONE) => len - i
-	    | (len, SOME sz) => Int.min (len - i, sz)
-	  val sizeA = sizeS A.length
-	  val sizeV = sizeS V.length
-	in
-	  WR {name = name,
-	      chunkSize = 1,
-	      writeVec = SOME (function "writeVec" sizeV),
-	      writeArr = SOME (function "writeArr" sizeA),
-	      writeVecNB = SOME (function "writeVecNB" (SOME o sizeV)),
-	      writeArrNB = SOME (function "writeArrNB" (SOME o sizeA)),
-	      block = SOME (const "block" ()),
-	      canOutput = SOME (const "canOutput" true),
-	      getPos = NONE,
-	      setPos = NONE,
-	      endPos = NONE,
-	      verifyPos = NONE,
-	      close = fn () => (closed := true),
-	      ioDesc = NONE}
-	end
-
-      fun doBlock (f, block) x = (block (); valOf (f x))
-      fun doCanInput (f, canInput) x = if canInput ()
-					 then SOME (f x)
-					 else NONE
-
-      fun augmentReader (RD {name, chunkSize,
-			     readVec, readArr, readVecNB, readArrNB,
-			     block, canInput, avail,
-			     getPos, setPos, endPos, verifyPos,
-			     close, ioDesc}) =
-	let
-	  fun augmentRead (readVec, readArr) =
-	    case (readVec, readArr) of
-	      (SOME readVec, SOME readArr) => (SOME readVec, SOME readArr)
-	    | (NONE, SOME readArr) =>
-		(SOME (fn i =>
-		       let
+fun nullWr () =
+   let
+      val name = "nullWr"
+      val closed = ref false
+      fun check f = if !closed
+		       then liftExn name f IO.ClosedStream
+		    else ()
+      fun const f c = fn _ => (check f; c)
+      fun function f g = fn x => (check f; g x)
+      fun sizeS (base, length) sl =
+	 let
+	    val (buf, i, sz) = base sl
+	 in
+	    Int.min (length buf - i, sz)
+	 end
+      val sizeA = sizeS (AS.base, A.length)
+      val sizeV = sizeS (VS.base, V.length)
+   in
+      WR {block = SOME (const "block" ()),
+	  canOutput = SOME (const "canOutput" true),
+	  chunkSize = 1,
+	  close = fn () => (closed := true),
+	  endPos = NONE,
+	  getPos = NONE,
+	  ioDesc = NONE,
+	  name = name,
+	  setPos = NONE,
+	  verifyPos = NONE,
+	  writeArr = SOME (function "writeArr" sizeA),
+	  writeArrNB = SOME (function "writeArrNB" (SOME o sizeA)),
+	  writeVec = SOME (function "writeVec" sizeV),
+	  writeVecNB = SOME (function "writeVecNB" (SOME o sizeV))}
+   end
+
+fun doBlock (f, block) x = (block (); valOf (f x))
+fun doCanInput (f, canInput) x = if canInput ()
+				    then SOME (f x)
+				 else NONE
+
+fun augmentReader (RD {name, chunkSize,
+		       readVec, readArr, readVecNB, readArrNB,
+		       block, canInput, avail,
+		       getPos, setPos, endPos, verifyPos,
+		       close, ioDesc}) =
+   let
+      fun augmentRead (readVec, readArr) =
+	 case (readVec, readArr) of
+	    (SOME readVec, SOME readArr) => (SOME readVec, SOME readArr)
+	  | (NONE, SOME readArr) =>
+	       (SOME (fn i =>
+		      let
 			 val buf = A.array (i, someElem)
-			 val k = readArr {buf = buf, i = 0, sz = SOME i}
-		       in
+			 val k = readArr (AS.slice (buf, 0, SOME i))
+		      in
 			 V.tabulate (k, fn i => A.sub (buf, i))
-		       end),
-		 SOME readArr)
-	    | (SOME readVec, NONE) =>
-		(SOME readVec,
-		 SOME (fn {buf, i, sz} =>
-		       let
-			 val v = readVec (case sz of 
-					    SOME sz => sz 
-					  | NONE => A.length buf - i)
-			 val k = V.length v
+		      end),
+		SOME readArr)
+	  | (SOME readVec, NONE) =>
+	       (SOME readVec,
+		SOME (fn sl =>
+		      let
+			 val (buf, i, sz) = AS.base sl
+			 val v = readVec sz
 			 val _ = A.copyVec {src = v, dst = buf, di = i}
-		       in
-			 k
-		       end))
-	    | (NONE, NONE) => (NONE, NONE)
-	  fun augmentReadNB (readVecNB, readArrNB) =
-	    case (readVecNB, readArrNB) of
-	      (SOME readVecNB, SOME readArrNB) => (SOME readVecNB, SOME readArrNB)
-	    | (NONE, SOME readArrNB) => 
-		(SOME (fn i =>
-		       let
+		      in
+			 V.length v
+		      end))
+	  | (NONE, NONE) => (NONE, NONE)
+      fun augmentReadNB (readVecNB, readArrNB) =
+	 case (readVecNB, readArrNB) of
+	    (SOME readVecNB, SOME readArrNB) => (SOME readVecNB, SOME readArrNB)
+	  | (NONE, SOME readArrNB) => 
+	       (SOME (fn i =>
+		      let
 			 val buf = A.array (i, someElem)
-		       in
-			 case readArrNB {buf = buf, i = 0, sz = SOME i} of
-			   NONE => NONE
-			 | SOME k => SOME (V.tabulate (k, fn i => A.sub (buf, i)))
-		       end),
-		 SOME readArrNB)
-	    | (SOME readVecNB, NONE) =>
-		(SOME readVecNB,
-		 SOME (fn {buf, i, sz} =>
-		       case readVecNB (case sz of
-					 SOME sz => sz
-				       | NONE => A.length buf - i) of
-			 NONE => NONE
-		       | SOME v => let
-				     val k = V.length v
-				     val _ = A.copyVec {src = v, dst = buf, di = i}
-				   in
-				     SOME k
-				   end))
-	    | (NONE, NONE) => (NONE, NONE)
-	  fun augmentSeq (readSeq, readSeqNB) =
-	    case (readSeq, readSeqNB) of
-	      (SOME readSeq, SOME readSeqNB) => (SOME readSeq, SOME readSeqNB)
-	    | (NONE, SOME readSeqNB) =>
-		(case block of
+			 fun first j = AS.slice (buf, 0, SOME j)
+		      in
+			 Option.map (AS.vector o first) (readArrNB (first i))
+		      end),
+		SOME readArrNB)
+	  | (SOME readVecNB, NONE) =>
+	       (SOME readVecNB,
+		SOME (fn sl =>
+		      let
+			 val (buf, i, sz) = AS.base sl
+		      in
+			 case readVecNB sz of
+			    NONE => NONE
+			  | SOME v => (A.copyVec {src = v, dst = buf, di = i}
+				       ; SOME (V.length v))
+		      end))
+	  | (NONE, NONE) => (NONE, NONE)
+      fun augmentSeq (readSeq, readSeqNB) =
+	 case (readSeq, readSeqNB) of
+	    (SOME readSeq, SOME readSeqNB) => (SOME readSeq, SOME readSeqNB)
+	  | (NONE, SOME readSeqNB) =>
+	       (case block of
 		   NONE => NONE
 		 | SOME block => SOME (doBlock (readSeqNB, block)),
-		 SOME readSeqNB)
-	    | (SOME readSeq, NONE) =>
-		(SOME readSeq,
-		 case canInput of
+		      SOME readSeqNB)
+	  | (SOME readSeq, NONE) =>
+	       (SOME readSeq,
+		case canInput of
 		   NONE => NONE
 		 | SOME canInput => SOME (doCanInput (readSeq, canInput)))
-	    | (NONE, NONE) => (NONE, NONE)
+	  | (NONE, NONE) => (NONE, NONE)
+
+      val ((readVec,readArr),(readVecNB,readArrNB)) =
+	 (augmentRead (readVec, readArr),
+	  augmentReadNB (readVecNB, readArrNB))
+      val ((readVec,readVecNB),(readArr,readArrNB)) =
+	 (augmentSeq (readVec, readVecNB),
+	  augmentSeq (readArr, readArrNB))
+   in
+      RD {name = name, chunkSize = chunkSize,
+	  readVec = readVec, readArr = readArr, 
+	  readVecNB = readVecNB, readArrNB = readArrNB,
+	  block = block, canInput = canInput, avail = avail,
+	  getPos = getPos, setPos = setPos, 
+	  endPos = endPos, verifyPos = verifyPos,
+	  close = close, ioDesc = ioDesc}
+   end
 
-	  val ((readVec,readArr),(readVecNB,readArrNB)) =
-	    (augmentRead (readVec, readArr),
-	     augmentReadNB (readVecNB, readArrNB))
-	  val ((readVec,readVecNB),(readArr,readArrNB)) =
-	    (augmentSeq (readVec, readVecNB),
-	     augmentSeq (readArr, readArrNB))
-	in
-	  RD {name = name, chunkSize = chunkSize,
-	      readVec = readVec, readArr = readArr, 
-	      readVecNB = readVecNB, readArrNB = readArrNB,
-	      block = block, canInput = canInput, avail = avail,
-	      getPos = getPos, setPos = setPos, 
-	      endPos = endPos, verifyPos = verifyPos,
-	      close = close, ioDesc = ioDesc}
-	end
-
-      fun augmentWriter (WR {name, chunkSize,
-			     writeVec, writeArr, writeVecNB, writeArrNB,
-			     block, canOutput,
-			     getPos, setPos, endPos, verifyPos,
-			     close, ioDesc}) =
-	let
-	  fun augmentWrite (writeVec, writeArr) =
-	    case (writeVec, writeArr) of
-	      (SOME writeVec, SOME writeArr) => (SOME writeVec, SOME writeArr)
-	    | (NONE, SOME writeArr) =>
-		(SOME (fn {buf, i, sz} =>
-		       writeArr {buf = A.tabulate (V.length buf, 
-						   fn i => V.sub (buf, i)),
-				 i = i, sz = sz}),
-		 SOME writeArr)
-	    | (SOME writeVec, NONE) =>
-		(SOME writeVec,
-		 SOME (fn {buf, i, sz} =>
-		       writeVec {buf = A.vector buf, i = i, sz = sz}))
-	    | (NONE, NONE) => (NONE, NONE)
-	  fun augmentSeq (writeSeq, writeSeqNB) =
-	    case (writeSeq, writeSeqNB) of
-	      (SOME writeSeq, SOME writeSeqNB) => (SOME writeSeq, SOME writeSeqNB)
-	    | (NONE, SOME writeSeqNB) =>
-		(case block of
+fun augmentWriter (WR {name, chunkSize,
+		       writeVec, writeArr, writeVecNB, writeArrNB,
+		       block, canOutput,
+		       getPos, setPos, endPos, verifyPos,
+		       close, ioDesc}) =
+   let
+      fun augmentWrite (writeVec, writeArr) =
+	 case (writeVec, writeArr) of
+	    (SOME writeVec, SOME writeArr) => (SOME writeVec, SOME writeArr)
+	  | (NONE, SOME writeArr) =>
+	       (SOME (fn sl =>
+		      writeArr
+		      (AS.full
+		       (A.tabulate (VS.length sl, fn i => VS.sub (sl, i))))),
+		SOME writeArr)
+	  | (SOME writeVec, NONE) =>
+	       (SOME writeVec,
+		SOME (fn sl => writeVec (VS.full (AS.vector sl))))
+	  | (NONE, NONE) => (NONE, NONE)
+      fun augmentSeq (writeSeq, writeSeqNB) =
+	 case (writeSeq, writeSeqNB) of
+	    (SOME writeSeq, SOME writeSeqNB) => (SOME writeSeq, SOME writeSeqNB)
+	  | (NONE, SOME writeSeqNB) =>
+	       (case block of
 		   NONE => NONE
 		 | SOME block => SOME (fn x => (block ();
 						valOf (writeSeqNB x))),
-		 SOME writeSeqNB)
-	    | (SOME writeSeq, NONE) =>
-		(SOME writeSeq,
-		 case canOutput of
+		   SOME writeSeqNB)
+	  | (SOME writeSeq, NONE) =>
+	       (SOME writeSeq,
+		case canOutput of
 		   NONE => NONE
 		 | SOME canOutput => SOME (fn x => (if canOutput ()
-						      then SOME (writeSeq x)
-						      else NONE)))
-	    | (NONE, NONE) => (NONE, NONE)
-
-	  val ((writeVec,writeArr),(writeVecNB,writeArrNB)) =
-	    (augmentWrite (writeVec, writeArr),
-	     augmentWrite (writeVecNB, writeArrNB))
-	  val ((writeVec,writeVecNB),(writeArr,wriveArrNB)) =
-	    (augmentSeq (writeVec, writeVecNB),
-	     augmentSeq (writeArr, writeArrNB))
-	in
-	  WR {name = name, chunkSize = chunkSize,
-	      writeVec = writeVec, writeArr = writeArr, 
-	      writeVecNB = writeVecNB, writeArrNB = writeArrNB,
-	      block = block, canOutput = canOutput,
-	      getPos = getPos, setPos = setPos, 
-	      endPos = endPos, verifyPos = verifyPos,
-	      close = close, ioDesc = ioDesc}
-	end
+						       then SOME (writeSeq x)
+						    else NONE)))
+	  | (NONE, NONE) => (NONE, NONE)
+
+      val ((writeVec,writeArr),(writeVecNB,writeArrNB)) =
+	 (augmentWrite (writeVec, writeArr),
+	  augmentWrite (writeVecNB, writeArrNB))
+      val ((writeVec,writeVecNB),(writeArr,wriveArrNB)) =
+	 (augmentSeq (writeVec, writeVecNB),
+	  augmentSeq (writeArr, writeArrNB))
+   in
+      WR {name = name, chunkSize = chunkSize,
+	  writeVec = writeVec, writeArr = writeArr, 
+	  writeVecNB = writeVecNB, writeArrNB = writeArrNB,
+	  block = block, canOutput = canOutput,
+	  getPos = getPos, setPos = setPos, 
+	  endPos = endPos, verifyPos = verifyPos,
+	  close = close, ioDesc = ioDesc}
    end
 
-signature PRIM_IO_ARG =
-   sig
-     structure Vector: MONO_VECTOR
-     structure Array: MONO_ARRAY
-     sharing type Vector.vector = Array.vector
-     sharing type Vector.elem = Array.elem
-     val someElem : Vector.elem
-     eqtype pos
-     val compare : (pos * pos) -> order
-   end
-functor PrimIO
-        (S: PRIM_IO_ARG): PRIM_IO = 
-  PrimIOExtra(S)
\ No newline at end of file
+end



1.3       +40 -50    mlton/basis-library/io/prim-io.sig

Index: prim-io.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/prim-io.sig,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- prim-io.sig	24 Nov 2002 01:19:36 -0000	1.2
+++ prim-io.sig	25 Sep 2003 01:43:25 -0000	1.3
@@ -1,59 +1,49 @@
 signature PRIM_IO = 
    sig
       type array
-      type vector
+      type array_slice
       type elem
       eqtype pos
+      type vector
+      type vector_slice
+
+      datatype reader =
+	 RD of {avail: unit -> int option,
+		block: (unit -> unit) option,
+		canInput: (unit -> bool) option,
+		chunkSize: int,
+		close: unit -> unit,
+		endPos: (unit -> pos) option,
+		getPos: (unit -> pos) option,
+		ioDesc: OS.IO.iodesc option,
+		name: string,
+		readArr: (array_slice -> int) option,
+		readArrNB: (array_slice -> int option) option,
+		readVec: (int -> vector) option,
+		readVecNB: (int -> vector option) option,
+		setPos: (pos -> unit) option,
+		verifyPos: (unit -> pos) option}
+
+      datatype writer =
+	 WR of {block: (unit -> unit) option,
+		canOutput: (unit -> bool) option,
+		chunkSize: int,
+		close: unit -> unit,
+		endPos: (unit -> pos) option,
+		getPos: (unit -> pos) option,
+		ioDesc: OS.IO.iodesc option,
+		name: string,
+		setPos: (pos -> unit) option,
+		verifyPos: (unit -> pos) option,
+		writeArr: (array_slice -> int) option,
+		writeArrNB: (array_slice -> int option) option,
+		writeVec: (vector_slice -> int) option,
+		writeVecNB: (vector_slice -> int option) option}
+
+      val augmentReader: reader -> reader
+      val augmentWriter: writer -> writer 
       val compare: pos * pos -> order
-      datatype reader = RD of {name: string,
-			       chunkSize: int,
-			       readVec: (int -> vector) option,
-			       readArr: ({buf: array, 
-					  i: int,
-					  sz: int option} -> int) option,
-			       readVecNB: (int -> vector option) option,
-			       readArrNB: ({buf: array, 
-					    i: int, 
-					    sz: int option} -> int option) option,
-			       block: (unit -> unit) option,
-			       canInput: (unit -> bool) option,
-			       avail: unit -> int option,
-			       getPos: (unit -> pos) option,
-			       setPos: (pos -> unit) option,
-			       endPos: (unit -> pos) option,
-			       verifyPos: (unit -> pos) option,
-			       close: unit -> unit,
-			       ioDesc: OS.IO.iodesc option}
-      datatype writer = WR of {name: string,
-			       chunkSize: int,
-			       writeVec: ({buf: vector, 
-					   i: int, 
-					   sz: int option} -> int) option,
-			       writeArr: ({buf: array, 
-					   i: int, 
-					   sz: int option} -> int) option,
-			       writeVecNB: ({buf: vector, 
-					     i: int, 
-					     sz: int option} -> int option) option,
-			       writeArrNB: ({buf: array, 
-					     i: int, 
-					     sz: int option} -> int option) option,
-			       block: (unit -> unit) option,
-			       canOutput: (unit -> bool) option,
-			       getPos: (unit -> pos) option,
-			       setPos: (pos -> unit) option,
-			       endPos: (unit -> pos) option,
-			       verifyPos: (unit -> pos) option,
-			       close: unit -> unit,
-			       ioDesc: OS.IO.iodesc option}
-      val openVector: vector -> reader
       val nullRd: unit -> reader
       val nullWr: unit -> writer
-      val augmentReader: reader -> reader
-      val augmentWriter: writer -> writer
+      val openVector: vector -> reader
    end
-
-signature PRIM_IO_EXTRA = 
-   sig
-      include PRIM_IO
-   end
\ No newline at end of file



1.15      +69 -66    mlton/basis-library/io/stream-io.fun

Index: stream-io.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/stream-io.fun,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- stream-io.fun	24 Sep 2003 17:45:25 -0000	1.14
+++ stream-io.fun	25 Sep 2003 01:43:25 -0000	1.15
@@ -1,31 +1,39 @@
 signature STREAM_IO_EXTRA_ARG = 
    sig
-      structure PrimIO: PRIM_IO_EXTRA where type pos = Position.int
+      structure PrimIO: PRIM_IO where type pos = Position.int
+      structure Array: MONO_ARRAY
+      structure ArraySlice: MONO_ARRAY_SLICE
       structure Vector: sig 
 	                  include MONO_VECTOR
 			  val extract: vector * int * int option -> vector
 			end
-      structure Array: MONO_ARRAY
-      sharing type PrimIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
-      val someElem: PrimIO.elem
+      structure VectorSlice: MONO_VECTOR_SLICE
+      sharing type Array.array = ArraySlice.array = PrimIO.array
+      sharing type Array.elem = ArraySlice.elem = PrimIO.elem = Vector.elem
+	 = VectorSlice.elem
+      sharing type Array.vector = ArraySlice.vector = PrimIO.vector
+	 = Vector.vector = VectorSlice.vector
+      sharing type ArraySlice.slice = PrimIO.array_slice
+      sharing type ArraySlice.vector_slice = PrimIO.vector_slice
+	 = VectorSlice.slice
 
-      val lineElem : Vector.elem
       val isLine : Vector.elem -> bool 
+      val lineElem : Vector.elem
+      val someElem: PrimIO.elem
    end
 
-functor StreamIOExtra 
-        (S: STREAM_IO_EXTRA_ARG): STREAM_IO_EXTRA =
+functor StreamIOExtra (S: STREAM_IO_EXTRA_ARG): STREAM_IO_EXTRA =
    struct
       open S
 
       structure PIO = PrimIO
       structure A = Array
+      structure AS = ArraySlice
       structure V = struct
 		      open Vector
 		      val extract = extract
 		    end
+      structure VS = VectorSlice
 
       type elem = PIO.elem
       type vector = PIO.vector
@@ -73,43 +81,44 @@
       fun writerSel (PIO.WR v, sel) = sel v
       fun outstreamName os = writerSel (outstreamWriter os, #name)
 
-      fun flushGen (writeSeq: {buf: 'a, i: int, sz: int option} -> int,
-		    {buf: 'a, i: int, sz: int}) =
-	let
-	  val max = i + sz
-	  fun loop i =
-	    if i = max
-	      then ()
-	      else let val j = writeSeq {buf = buf, i = i, sz = SOME (max - i)}
-		   in 
-		     if j = 0
-		       then raise (Fail "partial write")
+      fun flushGen (write: 'a -> int,
+		    base: 'a -> ('b * int * int),
+		    slice: ('b * int * int option) -> 'a,
+		    a: 'a) =
+	 let
+	    val (b, i, sz) = base a
+	    val max = i + sz
+	    fun loop i =
+	       if i = max
+		  then ()
+	       else let
+		       val j = write (slice (b, i, SOME (max - i)))
+		    in 
+		       if j = 0
+			  then raise (Fail "partial write")
 		       else loop (i + j)
-		   end
-	in loop i
-	end
+		    end
+	 in
+	    loop i
+	 end
 
       fun flushVec (writer, x) =
-	let val writeVec = writerSel (writer, #writeVec)
-	in
-	  case writeVec of
-	    SOME writeVec => flushGen (writeVec, x)
-	  | NONE => raise IO.BlockingNotSupported
-	end
+	 case writerSel (writer, #writeVec) of
+	    NONE => raise IO.BlockingNotSupported
+	  | SOME writeVec => flushGen (writeVec, VS.base, VS.slice, x)
+     
       fun flushArr (writer, x) =
-	let val writeArr = writerSel (writer, #writeArr)
-	in
-	  case writeArr of
-	    SOME writeArr => flushGen (writeArr, x)
-	  | NONE => raise IO.BlockingNotSupported
-	end
-
+	 case writerSel (writer, #writeArr) of
+	    NONE => raise IO.BlockingNotSupported
+	  | SOME writeArr => flushGen (writeArr, AS.base, AS.slice, x)
+     
       fun flushBuf (writer, Buf {size, array}) =
-	let val size' = !size 
-	in 
-	  size := 0;
-	  flushArr (writer, {buf = array, i = 0, sz = size'})
-	end
+	 let
+	    val size' = !size 
+	 in 
+	    size := 0
+	    ; flushArr (writer, AS.slice (array, 0, SOME size'))
+	 end
 
       fun output (os as Out {augmented_writer, 
 			     state, 
@@ -117,8 +126,7 @@
 	if terminated (!state)
 	  then liftExn (outstreamName os) "output" IO.ClosedStream
 	  else let
-		 fun put () = flushVec (augmented_writer, 
-					{buf = v, i = 0, sz = V.length v})
+		  fun put () = flushVec (augmented_writer, VS.full v)
 		 fun doit (buf as Buf {size, array}, maybe) =
 		   let
 		     val curSize = !size
@@ -163,7 +171,7 @@
 		   case !buffer_mode of
 		     NO_BUF => (A.update (buf1, 0, c);
 				flushArr (augmented_writer,
-					  {buf = buf1, i = 0, sz = 1}))
+					  AS.slice (buf1, 0, SOME 1)))
 		   | LINE_BUF buf => doit (buf, isLine c)
 		   | BLOCK_BUF buf => doit (buf, false)
 		 end
@@ -657,15 +665,23 @@
 signature STREAM_IO_ARG = 
    sig
       structure PrimIO: PRIM_IO where type pos = Position.int
-      structure Vector: MONO_VECTOR
       structure Array: MONO_ARRAY
-      sharing type PrimIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
+      structure ArraySlice: MONO_ARRAY_SLICE
+      structure Vector: MONO_VECTOR
+      structure VectorSlice: MONO_VECTOR_SLICE
+      sharing type Array.array = ArraySlice.array = PrimIO.array
+      sharing type Array.elem = ArraySlice.elem = PrimIO.elem = Vector.elem
+	 = VectorSlice.elem
+      sharing type Array.vector = ArraySlice.vector = PrimIO.vector
+	 = Vector.vector = VectorSlice.vector
+      sharing type ArraySlice.slice = PrimIO.array_slice
+      sharing type ArraySlice.vector_slice = PrimIO.vector_slice
+	 = VectorSlice.slice
+
       val someElem: PrimIO.elem
    end
-functor StreamIO
-        (S: STREAM_IO_ARG): STREAM_IO = 
+
+functor StreamIO (S: STREAM_IO_ARG): STREAM_IO = 
   StreamIOExtra(open S
 		structure Vector =
 		  struct
@@ -689,32 +705,19 @@
 
 signature STREAM_IO_EXTRA_FILE_ARG =
    sig
-      structure PrimIO: PRIM_IO_EXTRA where type pos = Position.int
-      structure Vector: sig 
-	                  include MONO_VECTOR
-			  val extract: vector * int * int option -> vector
-			end
-      structure Array: MONO_ARRAY
-      sharing type PrimIO.elem = Vector.elem = Array.elem
-      sharing type PrimIO.vector = Vector.vector = Array.vector
-      sharing type PrimIO.array = Array.array
-      val someElem: PrimIO.elem
-
-      val lineElem : Vector.elem
-      val isLine : Vector.elem -> bool
+      include STREAM_IO_EXTRA_ARG
 
       structure Cleaner: CLEANER
    end
 
-functor StreamIOExtraFile
-        (S: STREAM_IO_EXTRA_FILE_ARG): STREAM_IO_EXTRA_FILE =
+functor StreamIOExtraFile (S: STREAM_IO_EXTRA_FILE_ARG): STREAM_IO_EXTRA_FILE =
    struct
       open S
 
       structure PIO = PrimIO
       structure V = Vector
 
-      structure StreamIO = StreamIOExtra(open S)
+      structure StreamIO = StreamIOExtra (S)
       open StreamIO
 
       structure PFS = Posix.FileSys



1.17      +2 -0      mlton/basis-library/io/text-io.sml

Index: text-io.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/text-io.sml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- text-io.sml	9 May 2003 12:48:34 -0000	1.16
+++ text-io.sml	25 Sep 2003 01:43:25 -0000	1.17
@@ -170,7 +170,9 @@
       structure S = struct
 		      structure PrimIO = TextPrimIO
 		      structure Array = CharArray
+		      structure ArraySlice = CharArraySlice
 		      structure Vector = CharVector
+		      structure VectorSlice = CharVectorSlice
 		      val someElem = (#"\000": Char.char)
 		      val lineElem = (#"\n": Char.char)
 		      fun isLine c = c = lineElem



1.4       +11 -9     mlton/basis-library/io/text-prim-io.sml

Index: text-prim-io.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/io/text-prim-io.sml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- text-prim-io.sml	5 Sep 2003 23:01:01 -0000	1.3
+++ text-prim-io.sml	25 Sep 2003 01:43:26 -0000	1.4
@@ -1,10 +1,12 @@
+structure TextPrimIO: PRIM_IO
+                      where type array = CharArray.array
+		      where type vector = CharVector.vector
+		      where type elem = Char.char =
+  PrimIO (structure Array = CharArray
+	  structure ArraySlice = CharArraySlice
+	  structure Vector = CharVector
+	  structure VectorSlice = CharVectorSlice
+	  type pos = Position.int
+	  val compare = Position.compare
+	  val someElem = #"\000": Char.char)
 
-structure TextPrimIO : PRIM_IO
-                       where type array = CharArray.array
-		       where type vector = CharVector.vector
-		       where type elem = Char.char =
-  PrimIOExtra(structure Vector = CharVector
-	      structure Array = CharArray
-	      val someElem = (#"\000": Char.char)
-	      type pos = Position.int
-	      val compare = Position.compare)



1.3       +14 -6     mlton/basis-library/libs/basis-1997/posix/io-convert.fun

Index: io-convert.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/libs/basis-1997/posix/io-convert.fun,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- io-convert.fun	24 Nov 2002 01:19:37 -0000	1.2
+++ io-convert.fun	25 Sep 2003 01:43:26 -0000	1.3
@@ -1,19 +1,27 @@
-functor PosixIOConvert
-        (structure IO: POSIX_IO) :
-        POSIX_IO_1997 =
+functor PosixIOConvert (structure IO: POSIX_IO): POSIX_IO_1997 =
   struct
      open IO
+
      structure FD =
         struct
 	   open FD
-	   structure Flags = FlagsConvert(structure Flags = FD)
+	   structure Flags = FlagsConvert (structure Flags = FD)
 	   open Flags
 	end
+     
      structure O =
         struct
 	   open O
-	   structure Flags = FlagsConvert(structure Flags = O)
+	   structure Flags = FlagsConvert (structure Flags = O)
 	   open Flags
 	end
 
-  end
\ No newline at end of file
+     fun readArr (fd, {buf, i, sz}) =
+	IO.readArr (fd, Word8ArraySlice.slice (buf, i, sz))
+
+     fun writeArr (fd, {buf, i, sz}) =
+	IO.writeArr (fd, Word8ArraySlice.slice (buf, i, sz))
+
+     fun writeVec (fd, {buf, i, sz}) =
+	IO.writeVec (fd, Word8VectorSlice.slice (buf, i, sz))
+  end



1.3       +3 -3      mlton/basis-library/libs/basis-2002/top-level/basis-funs.sml

Index: basis-funs.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/libs/basis-2002/top-level/basis-funs.sml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- basis-funs.sml	24 Nov 2002 01:19:38 -0000	1.2
+++ basis-funs.sml	25 Sep 2003 01:43:26 -0000	1.3
@@ -1,6 +1,6 @@
 (* Required functors *)
 
 (* Optional functors *)
-functor PrimIO (S: PRIM_IO_ARG) = PrimIO (S)
-functor StreamIO (S: STREAM_IO_ARG) = StreamIO (S)
-functor ImperativeIO (S: IMPERATIVE_IO_ARG) = ImperativeIO (S)
+functor PrimIO (S: PRIM_IO_ARG): PRIM_IO = PrimIO (S)
+functor StreamIO (S: STREAM_IO_ARG): STREAM_IO = StreamIO (S)
+functor ImperativeIO (S: IMPERATIVE_IO_ARG): IMPERATIVE_IO = ImperativeIO (S)



1.6       +3 -3      mlton/basis-library/mlton/random.sml

Index: random.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/mlton/random.sml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- random.sml	11 Sep 2003 18:30:57 -0000	1.5
+++ random.sml	25 Sep 2003 01:43:26 -0000	1.6
@@ -18,9 +18,9 @@
 		      end
 		   fun loop rem =
 		      let
-			 val n = Posix.IO.readArr (fd, {buf = buf,
-							i = 4 - rem,
-							sz = SOME rem})
+			 val n = Posix.IO.readArr (fd,
+						   Word8ArraySlice.slice
+						   (buf, 4 - rem, SOME rem))
 			 val _ = if n = 0
 				    then (Posix.IO.close fd; raise Fail name)
 				 else ()



1.8       +5 -3      mlton/basis-library/posix/file-sys.sml

Index: file-sys.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/file-sys.sml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- file-sys.sml	6 Sep 2003 21:20:45 -0000	1.7
+++ file-sys.sml	25 Sep 2003 01:43:26 -0000	1.8
@@ -202,9 +202,11 @@
 	 val buf = Word8Array.array (size, 0w0)
       in
 	 fun readlink (path: string): string =
-	    let val len = Prim.readlink (String.nullTerm path, buf, size)
-	    in checkResult len
-	       ; Byte.unpackString (buf, 0, SOME len)
+	    let
+	       val len = Prim.readlink (String.nullTerm path, buf, size)
+	    in
+	       checkResult len
+	       ; Byte.unpackString (Word8ArraySlice.slice (buf, 0, SOME len))
 	    end
       end
 



1.3       +3 -9      mlton/basis-library/posix/io.sig

Index: io.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/io.sig,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- io.sig	24 Nov 2002 01:19:39 -0000	1.2
+++ io.sig	25 Sep 2003 01:43:26 -0000	1.3
@@ -9,15 +9,9 @@
 
       val close: file_desc -> unit 
       val readVec: file_desc * int -> Word8Vector.vector 
-      val readArr: file_desc * {buf: Word8Array.array,
-				i: int,
-				sz: int option} -> int 
-      val writeVec: file_desc * {buf: Word8Vector.vector,
-				 i: int,
-				 sz: int option} -> int 
-      val writeArr: file_desc * {buf: Word8Array.array,
-				 i: int,
-				 sz: int option} -> int 
+      val readArr: file_desc * Word8ArraySlice.slice -> int
+      val writeVec: file_desc * Word8VectorSlice.slice -> int
+      val writeArr: file_desc * Word8ArraySlice.slice -> int
 
       datatype whence = SEEK_SET | SEEK_CUR | SEEK_END
 



1.7       +67 -60    mlton/basis-library/posix/io.sml

Index: io.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/io.sml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- io.sml	6 Sep 2003 19:03:05 -0000	1.6
+++ io.sml	25 Sep 2003 01:43:26 -0000	1.7
@@ -34,42 +34,47 @@
       fun close (FD fd) = checkResult (Prim.close fd)
 
       local
-	fun make {read, write} =
-	  let
-	    fun readArr (FD fd, {buf, i, sz}): int =
-	      let
-		val max = Array.checkSlice (buf, i, sz)
-	      in
-		checkReturnResult (read (fd, buf, i, max -? i))
-	      end
-	    
-	    fun readVec (fd, n) =
-	      let
-		 val _ = if n < 0 then raise Subscript else ()
-		val a = Primitive.Array.array n
-		val bytesRead = readArr (fd, {buf = a, i = 0, sz = SOME n})
-	      in 
-		if n = bytesRead
-		  then Vector.fromArray a
-		  else Array.extract (a, 0, SOME bytesRead)
-	      end
-		
-	    fun writeVec (FD fd, {buf, i, sz}) =
-	      let
-		val max = Vector.checkSlice (buf, i, sz)
-	      in
-		checkReturnResult (write (fd, buf, i, max -? i))
-	      end
-	    
-	    fun writeArr (fd, {buf, i, sz}) =
-	      writeVec (fd, {buf = Vector.fromArray buf, i = i, sz = sz})
-	  in
-	    {readArr = readArr, readVec = readVec,
-	     writeVec = writeVec, writeArr = writeArr}
-	  end
+	 fun make {read, write, writeVec} =
+	    let
+	       fun readArr (FD fd, sl): int =
+		  let
+		     val (buf, i, sz) = ArraySlice.base sl
+		  in
+		     checkReturnResult (read (fd, buf, i, sz))
+		  end
+	       fun readVec (FD fd, n) =
+		  let
+		     val a = Primitive.Array.array n
+		     val bytesRead = checkReturnResult (read (fd, a, 0, n))
+		  in 
+		     if n = bytesRead
+			then Vector.fromArray a
+		     else Array.extract (a, 0, SOME bytesRead)
+		  end
+	       fun writeArr (FD fd, sl) =
+		  let
+		     val (buf, i, sz) = ArraySlice.base sl
+		  in
+		     checkReturnResult (write (fd, buf, i, sz))
+		  end
+	       val writeVec =
+		  fn (FD fd, sl) =>
+		  let
+		     val (buf, i, sz) = VectorSlice.base sl
+		  in
+		     checkReturnResult (writeVec (fd, buf, i, sz))
+		  end
+	    in
+	       {readArr = readArr, readVec = readVec,
+		writeVec = writeVec, writeArr = writeArr}
+	    end
       in
-	val rwChar = make {read = readChar, write = writeChar}
-	val rwWord8 = make {read = readWord8, write = writeWord8}
+	val rwChar = make {read = readChar,
+			   write = writeChar,
+			   writeVec = writeCharVec}
+	val rwWord8 = make {read = readWord8,
+			    write = writeWord8,
+			    writeVec = writeWord8Vec}
       end
       val {readArr, readVec, writeVec, writeArr} = rwWord8
 		      
@@ -233,7 +238,8 @@
 	    fun mkReader {fd, name, initBlkMode} =
 	      let
 		val closed = ref false
-		val {pos, getPos, setPos, endPos, verifyPos} = posFns (closed, fd)
+		val {pos, getPos, setPos, endPos, verifyPos} =
+		   posFns (closed, fd)
 		val blocking = ref initBlkMode
 		fun blockingOn () = 
 		  (setfl(fd, O.flags[]); blocking := true)
@@ -269,26 +275,27 @@
 				    else SOME(Position.-(FS.ST.size(FS.fstat fd), !pos))
 		    else fn () => if !closed then SOME 0 else NONE
 	      in
-		RD {name = name,
-		    chunkSize = Primitive.TextIO.bufSize,
-		    readVec = SOME (blockWrap readVec),
-		    readArr = SOME (blockWrap readArr),
-		    readVecNB = SOME (noBlockWrap readVec),
-		    readArrNB = SOME (noBlockWrap readArr),
+		RD {avail = avail,
 		    block = NONE,
 		    canInput = NONE,
-		    avail = avail,
+		    chunkSize = Primitive.TextIO.bufSize,
+		    close = close,
+		    endPos = endPos,
 		    getPos = getPos,
+		    ioDesc = SOME (FS.fdToIOD fd),
+		    name = name,
+		    readArr = SOME (blockWrap readArr),
+		    readArrNB = SOME (noBlockWrap readArr),
+		    readVec = SOME (blockWrap readVec),
+		    readVecNB = SOME (noBlockWrap readVec),
 		    setPos = setPos,
-		    endPos = endPos,
-		    verifyPos = verifyPos,
-		    close = close,
-		    ioDesc = SOME (FS.fdToIOD fd)}
+		    verifyPos = verifyPos}
 	      end
 	    fun mkWriter {fd, name, initBlkMode, appendMode, chunkSize} =
 	      let
 		val closed = ref false
-		val {pos, getPos, setPos, endPos, verifyPos} = posFns (closed, fd)
+		val {pos, getPos, setPos, endPos, verifyPos} =
+		   posFns (closed, fd)
 		fun incPos k = (pos := Position.+ (!pos, Position.fromInt k); k)
 		val blocking = ref initBlkMode
 		val appendFlgs = O.flags(if appendMode then [O.append] else [])
@@ -304,8 +311,8 @@
 		  if !closed then raise IO.ClosedStream else ()
 		fun ensureBlock x = 
 		  if !blocking then () else (blocking := x; updateStatus ())
-		fun putV x = incPos(writeVec x)
-		fun putA x = incPos(writeArr x)
+		fun putV x = incPos (writeVec x)
+		fun putA x = incPos (writeArr x)
 		fun write (put, block) arg = 
 		  (ensureOpen (); ensureBlock block; put (fd, arg))
 		fun handleBlock writer arg = 
@@ -315,20 +322,20 @@
 		val close = 
 		  fn () => if !closed then () else (closed := true; close fd)
 	      in
-		WR {name = name,
-		    chunkSize = chunkSize,
-		    writeVec = SOME (write (putV, true)),
-		    writeArr = SOME (write (putA, true)),
-		    writeVecNB = SOME (handleBlock (write (putV, false))),
-		    writeArrNB = SOME (handleBlock (write (putA, false))),
-		    block = NONE,
+		WR {block = NONE,
 		    canOutput = NONE,
+		    chunkSize = chunkSize,
+		    close = close,
+		    endPos = endPos,
 		    getPos = getPos,
+		    ioDesc = SOME (FS.fdToIOD fd),
+		    name = name,
 		    setPos = setPos,
-		    endPos = endPos,
 		    verifyPos = verifyPos,
-		    close = close,
-		    ioDesc = SOME (FS.fdToIOD fd)}
+		    writeArr = SOME (write (putA, true)),
+		    writeArrNB = SOME (handleBlock (write (putA, false))),
+		    writeVec = SOME (write (putV, true)),
+		    writeVecNB = SOME (handleBlock (write (putV, false)))}
 	      end
 	  in
 	    {mkReader = mkReader, mkWriter = mkWriter}



1.16      +4 -0      mlton/basis-library/posix/primitive.sml

Index: primitive.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/primitive.sml,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- primitive.sml	19 Jul 2003 01:23:25 -0000	1.15
+++ primitive.sml	25 Sep 2003 01:43:26 -0000	1.16
@@ -524,10 +524,14 @@
 	    val readChar = _import "Posix_IO_read":
 	       fd * char array * int * size -> ssize;
 	    val writeChar = _import "Posix_IO_write":
+	       fd * char array * int * size -> ssize;
+	    val writeCharVec = _import "Posix_IO_write":
 	       fd * char vector * int * size -> ssize;
 	    val readWord8 = _import "Posix_IO_read":
 	       fd * word8 array * int * size -> ssize;
 	    val writeWord8 = _import "Posix_IO_write":
+	       fd * word8 array * int * size -> ssize;
+	    val writeWord8Vec = _import "Posix_IO_write":
 	       fd * word8 vector * int * size -> ssize;
 	 end	       
 



1.14      +3 -3      mlton/basis-library/posix/process.sml

Index: process.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/process.sml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- process.sml	26 Aug 2003 20:36:44 -0000	1.13
+++ process.sml	25 Sep 2003 01:43:26 -0000	1.14
@@ -45,9 +45,9 @@
 		  case fork () of
 		     NONE => 
 			(PosixIO.writeVec (outfd,
-					   {buf = (Word8Vector.tabulate
-						   (1, fn _ => 0w0)),
-					    i = 0, sz = NONE})
+					   Word8VectorSlice.full
+					   (Word8Vector.tabulate
+					    (1, fn _ => 0w0)))
 			 ; NONE)
 		   | SOME n =>
 			let



1.6       +1 -1      mlton/basis-library/real/pack-real.sml

Index: pack-real.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/real/pack-real.sml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- pack-real.sml	29 Aug 2003 00:25:20 -0000	1.5
+++ pack-real.sml	25 Sep 2003 01:43:27 -0000	1.6
@@ -25,7 +25,7 @@
 in
    fun toBytes (r: real): Word8Vector.vector =
       (up (a, 0, r)
-       ; Byte.stringToBytes (Byte.unpackString (a, 0, NONE)))
+       ; Byte.stringToBytes (Byte.unpackString (Word8ArraySlice.full a)))
 end
 
 fun subVec (v, i) =



1.3       +7 -7      mlton/basis-library/text/byte.sig

Index: byte.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/text/byte.sig,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- byte.sig	20 Jul 2003 18:07:58 -0000	1.2
+++ byte.sig	25 Sep 2003 01:43:27 -0000	1.3
@@ -1,10 +1,10 @@
 signature BYTE =
    sig
-      val byteToChar: Word8.word -> char 
-      val bytesToString: Word8Vector.vector -> string 
-      val charToByte: char -> Word8.word 
-      val packString: Word8Array.array * int * substring -> unit 
-      val stringToBytes: string -> Word8Vector.vector 
-      val unpackString: Word8Array.array * int * int option -> string 
-      val unpackStringVec: Word8Vector.vector * int * int option -> string 
+      val byteToChar: Word8.word -> char
+      val bytesToString: Word8Vector.vector -> string
+      val charToByte: char -> Word8.word
+      val packString: Word8Array.array * int * substring -> unit
+      val stringToBytes: string -> Word8Vector.vector
+      val unpackString: Word8ArraySlice.slice -> string
+      val unpackStringVec: Word8VectorSlice.slice -> string
    end



1.4       +8 -3      mlton/basis-library/text/byte.sml

Index: byte.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/text/byte.sml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- byte.sml	20 Jul 2003 18:07:58 -0000	1.3
+++ byte.sml	25 Sep 2003 01:43:27 -0000	1.4
@@ -20,7 +20,12 @@
 
       val stringToBytes = Primitive.String.toWord8Vector
 
-      val unpackString = bytesToString o Word8Array.extract
-
-      val unpackStringVec = bytesToString o Word8Vector.extract
+      local
+	 fun make (length, sub) s =
+	    String.tabulate (length s, fn i => byteToChar (sub (s, i)))
+      in
+	 val unpackString = make (Word8ArraySlice.length, Word8ArraySlice.sub)
+	 val unpackStringVec =
+	    make (Word8VectorSlice.length, Word8VectorSlice.sub)
+      end
    end



1.82      +8 -1      mlton/doc/changelog

Index: changelog
===================================================================
RCS file: /cvsroot/mlton/mlton/doc/changelog,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- changelog	22 Sep 2003 19:16:27 -0000	1.81
+++ changelog	25 Sep 2003 01:43:27 -0000	1.82
@@ -1,9 +1,16 @@
 Here are the changes since version 20030716.
 
+* 2003-0924
+  - Tracking basis library changes:
+    o TextIO.inputLine now returns a string option.
+    o Slices used in Byte, PRIM_IO, PrimIO, Posix.IO, StreamIO
+    o Posix.IO.readVec raises Size, not Subscript, with negative
+      argument. 
+
 * 2003-09-22
   - Fixed Real.toManExp so that the mantissa is in [0.5, 1), 
     not [1, 2).  The spec says that 1.0 <= man * radix < radix, which
-    since radix is 2, implies that the mantiss is in [0.5, 1).
+    since radix is 2, implies that the mantissa is in [0.5, 1).
   - Added Time.{from,to}Nanoseconds.
 
 * 2003-09-11



1.3       +26 -23    mlton/regression/bytechar.sml

Index: bytechar.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/regression/bytechar.sml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- bytechar.sml	24 Nov 2002 01:19:44 -0000	1.2
+++ bytechar.sml	25 Sep 2003 01:43:27 -0000	1.3
@@ -56,51 +56,54 @@
 	  (Byte.bytesToString o Word8Vector.fromList o map Word8.fromInt)
 	   [65, 66, 68, 67]);
 
-val test9 = tst "test9" ("" = Byte.unpackString(Word8Array.fromList [], 0, SOME 0));
+val unpackString = Byte.unpackString o Word8ArraySlice.slice
+   
+val test9 = tst "test9" ("" = unpackString (Word8Array.fromList [], 0, SOME 0))
 
 local 
     val arr = Word8Array.tabulate(10, fn i => Word8.fromInt(i+65))
 in
-val test10a = tst "test10a" ("" = Byte.unpackString(arr, 0, SOME 0));
-val test10b = tst "test10b" ("" = Byte.unpackString(arr, 10, SOME 0) 
-			     andalso "" = Byte.unpackString(arr, 10, NONE));
-val test10c = tst "test10c" ("BCDE" = Byte.unpackString(arr, 1, SOME 4));
-val test10d = tst0 "test10d" ((Byte.unpackString(arr, ~1, SOME 0) seq "WRONG")
+val test10a = tst "test10a" ("" = unpackString(arr, 0, SOME 0));
+val test10b = tst "test10b" ("" = unpackString(arr, 10, SOME 0) 
+			     andalso "" = unpackString(arr, 10, NONE));
+val test10c = tst "test10c" ("BCDE" = unpackString(arr, 1, SOME 4));
+val test10d = tst0 "test10d" ((unpackString(arr, ~1, SOME 0) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10e = tst0 "test10e" ((Byte.unpackString(arr, 11, SOME 0) seq "WRONG")
+val test10e = tst0 "test10e" ((unpackString(arr, 11, SOME 0) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10f = tst0 "test10f" ((Byte.unpackString(arr, 0, SOME ~1) seq "WRONG")
+val test10f = tst0 "test10f" ((unpackString(arr, 0, SOME ~1) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10g = tst0 "test10g" ((Byte.unpackString(arr, 0, SOME 11) seq "WRONG")
+val test10g = tst0 "test10g" ((unpackString(arr, 0, SOME 11) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10h = tst0 "test10h" ((Byte.unpackString(arr, 10, SOME 1) seq "WRONG")
+val test10h = tst0 "test10h" ((unpackString(arr, 10, SOME 1) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10i = tst0 "test10i" ((Byte.unpackString(arr, ~1, NONE) seq "WRONG")
+val test10i = tst0 "test10i" ((unpackString(arr, ~1, NONE) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test10j = tst0 "test10j" ((Byte.unpackString(arr, 11, NONE) seq "WRONG")
+val test10j = tst0 "test10j" ((unpackString(arr, 11, NONE) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
 end
 
+val unpackStringVec = Byte.unpackStringVec o Word8VectorSlice.slice
 local 
     val vec = Word8Vector.tabulate(10, fn i => Word8.fromInt(i+65))
 in
-val test11a = tst "test11a" ("" = Byte.unpackStringVec(vec, 0, SOME 0));
-val test11b = tst "test11b" ("" = Byte.unpackStringVec(vec, 10, SOME 0) 
-			     andalso "" = Byte.unpackStringVec(vec, 10, NONE));
-val test11c = tst "test11c" ("BCDE" = Byte.unpackStringVec(vec, 1, SOME 4));
-val test11d = tst0 "test11d" ((Byte.unpackStringVec(vec, ~1, SOME 0) seq "WRONG")
+val test11a = tst "test11a" ("" = unpackStringVec(vec, 0, SOME 0));
+val test11b = tst "test11b" ("" = unpackStringVec(vec, 10, SOME 0) 
+			     andalso "" = unpackStringVec(vec, 10, NONE));
+val test11c = tst "test11c" ("BCDE" = unpackStringVec(vec, 1, SOME 4));
+val test11d = tst0 "test11d" ((unpackStringVec(vec, ~1, SOME 0) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test11e = tst0 "test11e" ((Byte.unpackStringVec(vec, 11, SOME 0) seq "WRONG")
+val test11e = tst0 "test11e" ((unpackStringVec(vec, 11, SOME 0) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test11f = tst0 "test11f" ((Byte.unpackStringVec(vec, 0, SOME ~1) seq "WRONG")
+val test11f = tst0 "test11f" ((unpackStringVec(vec, 0, SOME ~1) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test11g = tst0 "test11g" ((Byte.unpackStringVec(vec, 0, SOME 11) seq "WRONG")
+val test11g = tst0 "test11g" ((unpackStringVec(vec, 0, SOME 11) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test11h = tst0 "test11h" ((Byte.unpackStringVec(vec, 10, SOME 1) seq "WRONG")
+val test11h = tst0 "test11h" ((unpackStringVec(vec, 10, SOME 1) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
-val test11i = tst0 "test11i" ((Byte.unpackStringVec(vec, ~1, NONE) seq "WRONG")
+val test11i = tst0 "test11i" ((unpackStringVec(vec, ~1, NONE) seq "WRONG")
 			    handle Subscript => "OK" | _ => "WRONG")
-val test11j = tst0 "test11j" ((Byte.unpackStringVec(vec, 11, NONE) seq "WRONG")
+val test11j = tst0 "test11j" ((unpackStringVec(vec, 11, NONE) seq "WRONG")
 			      handle Subscript => "OK" | _ => "WRONG")
 end
 




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel