Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/system/Basis/Implementation/IO/prim-io-fn.sml
ViewVC logotype

Diff of /sml/trunk/src/system/Basis/Implementation/IO/prim-io-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1381, Wed Sep 17 21:28:41 2003 UTC revision 1398, Tue Sep 30 21:09:27 2003 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4   *   *
5   *)   *)
   
6  functor PrimIO (  functor PrimIO (
7    
8      structure Vector : MONO_VECTOR      structure Vector : MONO_VECTOR
# Line 230  Line 229 
229              }              }
230            end            end
231    
232    end (* PrimIO *)      fun openVector v = let
233            val pos = ref 0
234            val closed = ref false
235            fun checkClosed () = if !closed then raise IO.ClosedStream else ()
236            val len = V.length v
237            fun avail () = len - !pos
238            fun readV n = let
239                val p = !pos
240                val m = Int31Imp.min (n, len - p)
241            in
242                checkClosed ();
243                pos := p + m;
244                VS.vector (VS.slice (v, p, SOME m))
245            end
246            fun readA asl = let
247                val p = !pos
248                val (buf, i, n) = AS.base asl
249                val m = Int31Imp.min (n, len - p)
250            in
251                checkClosed ();
252                pos := p + m;
253                AS.copyVec { src = VS.slice (v, p, SOME m), dst = buf, di = i };
254                m
255            end
256            fun checked k () = (checkClosed (); k)
257        in
258            (* random access not supported because pos type is abstract *)
259            RD { name = "<vector>",
260                 chunkSize = len,
261                 readVec = SOME readV,
262                 readArr = SOME readA,
263                 readVecNB = SOME (SOME o readV),
264                 readArrNB = SOME (SOME o readA),
265                 block = SOME checkClosed,
266                 canInput = SOME (checked true),
267                 avail = SOME o avail,
268                 getPos = NONE,
269                 setPos = NONE,
270                 endPos = NONE,
271                 verifyPos = NONE,
272                 close = fn () => closed := true,
273                 ioDesc = NONE }
274        end
275    
276        fun nullRd () = let
277            val closed = ref false
278            fun checkClosed () = if !closed then raise IO.ClosedStream else ()
279            fun checked k _ = (checkClosed (); k)
280        in
281            RD { name = "<null>",
282                 chunkSize = 1,
283                 readVec = SOME (checked (V.fromList [])),
284                 readArr = SOME (checked 0),
285                 readVecNB = SOME (checked (SOME (V.fromList []))),
286                 readArrNB = SOME (checked (SOME 0)),
287                 block = SOME checkClosed,
288                 canInput = SOME (checked true),
289                 avail = fn () => SOME 0,
290                 getPos = NONE,
291                 setPos = NONE,
292                 endPos = NONE,
293                 verifyPos = NONE,
294                 close = fn () => closed := true,
295                 ioDesc = NONE }
296        end
297    
298        fun nullWr () = let
299            val closed = ref false
300            fun checkClosed () = if !closed then raise IO.ClosedStream else ()
301            fun checked k () = k
302            fun writeVec vsl = (checkClosed (); VS.length vsl)
303            fun writeArr asl = (checkClosed (); AS.length asl)
304        in
305            WR { name = "<null>",
306                 chunkSize = 1,
307                 writeVec = SOME writeVec,
308                 writeArr = SOME writeArr,
309                 writeVecNB = SOME (SOME o writeVec),
310                 writeArrNB = SOME (SOME o writeArr),
311                 block = SOME checkClosed,
312                 canOutput = SOME (checked true),
313                 getPos = NONE,
314                 setPos = NONE,
315                 endPos = NONE,
316                 verifyPos = NONE,
317                 close = fn () => closed := true,
318                 ioDesc = NONE }
319        end
320    
321      end (* PrimIO *)

Legend:
Removed from v.1381  
changed lines
  Added in v.1398

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0