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/cml/src/IO/bin-io-fn.sml
ViewVC logotype

Diff of /sml/trunk/src/cml/src/IO/bin-io-fn.sml

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

revision 843, Tue Jun 19 21:53:04 2001 UTC revision 844, Wed Jun 20 20:39:15 2001 UTC
# Line 323  Line 323 
323                          else (SV.mPut(more, next); false)                          else (SV.mPut(more, next); false)
324                      end                      end
325                (* end case *))                (* end case *))
326          fun mkInstream (reader, data) = let          fun mkInstream (reader, optData) = let
327                val PIO.RD{readVec, readVecEvt, getPos, setPos, ...} = reader                val PIO.RD{readVec, readVecEvt, getPos, setPos, ...} = reader
328                val getPos = (case (getPos, setPos)                val getPos = (case (getPos, setPos)
329                       of (SOME f, SOME _) => (fn () => SOME(f()))                       of (SOME f, SOME _) => (fn () => SOME(f()))
# Line 336  Line 336 
336                        closed = ref false, getPos = getPos,                        closed = ref false, getPos = getPos,
337                        tail = SV.mVarInit more, cleanTag = tag                        tail = SV.mVarInit more, cleanTag = tag
338                      }                      }
339  (** What should we do about the position when there is initial data?? **)                val buf = (case optData
340                         of NONE => IBUF{
341                                basePos = getPos(), data=empty,
342                                info=info, more=more
343                              }
344    (** What should we do about the position in this case ?? **)
345  (** Suggestion: When building a stream with supplied initial data,  (** Suggestion: When building a stream with supplied initial data,
346   ** nothing can be said about the positions inside that initial   ** nothing can be said about the positions inside that initial
347   ** data (who knows where that data even came from!).   ** data (who knows where that data even came from!).
348   **)   **)
349                val basePos = if (V.length data = 0)                        | (SOME v) => IBUF{
350                      then getPos()                              basePos = NONE, data=v,
351                      else NONE                              info=info, more=more}
352                val buf = IBUF{                      (* end case *))
                       basePos = basePos, data = data, info = info, more = more  
                     }  
353                val strm = ISTRM(buf, 0)                val strm = ISTRM(buf, 0)
354                in                in
355                  CleanIO.rebindCleaner (tag, fn () => closeIn strm);                  CleanIO.rebindCleaner (tag, fn () => closeIn strm);
# Line 368  Line 371 
371                    else (reader, V.concat(getData more))                    else (reader, V.concat(getData more))
372                end                end
373    
374          fun filePosIn (ISTRM(buf, pos)) = (case buf        (** Position operations on instreams **)
375            datatype in_pos = INP of {
376                base : pos,
377                offset : int,
378                info : info
379              }
380    
381            fun getPosIn (ISTRM(buf, pos)) = (case buf
382                 of IBUF{basePos=NONE, info, ...} =>                 of IBUF{basePos=NONE, info, ...} =>
383                      inputExn (info, "filePosIn", IO.RandomAccessNotSupported)                      inputExn (info, "getPosIn", IO.RandomAccessNotSupported)
384                  | IBUF{basePos=SOME base, info, ...} =>                  | IBUF{basePos=SOME p, info, ...} => INP{
385                      Position.+(base, Position.fromInt pos)                        base = p, offset = pos, info = info
386                        }
387                (* end case *))                (* end case *))
388            fun filePosIn (INP{base, offset, ...}) =
389                  Position.+(base, Position.fromInt offset)
390            fun setPosIn (pos as INP{info as INFO{reader, ...}, ...}) = let
391                  val fpos = filePosIn pos
392                  val (PIO.RD rd) = reader
393                  in
394                    terminate info;
395                    valOf (#setPos rd) fpos;
396                    mkInstream (PIO.RD rd, NONE)
397                  end
398    
399    
400        (*** Output streams ***)        (*** Output streams ***)
# Line 658  Line 679 
679              SV.mPut(strm, StreamIO.findEOS buf)              SV.mPut(strm, StreamIO.findEOS buf)
680            end            end
681      fun endOfStream strm = StreamIO.endOfStream(SV.mGet strm)      fun endOfStream strm = StreamIO.endOfStream(SV.mGet strm)
682        fun getPosIn strm = StreamIO.getPosIn(SV.mGet strm)
683        fun setPosIn (strm, p) = mUpdate(strm, StreamIO.setPosIn p)
684    
685    (** Output operations **)    (** Output operations **)
686      fun output (strm, v) = StreamIO.output(SV.mGet strm, v)      fun output (strm, v) = StreamIO.output(SV.mGet strm, v)
# Line 678  Line 701 
701    
702    (** Open files **)    (** Open files **)
703      fun openIn fname =      fun openIn fname =
704            mkInstream(StreamIO.mkInstream(OSPrimIO.openRd fname, empty))            mkInstream(StreamIO.mkInstream(OSPrimIO.openRd fname, NONE))
705              handle ex => raise IO.Io{function="openIn", name=fname, cause=ex}              handle ex => raise IO.Io{function="openIn", name=fname, cause=ex}
706      fun openOut fname =      fun openOut fname =
707            mkOutstream(StreamIO.mkOutstream(OSPrimIO.openWr fname, IO.BLOCK_BUF))            mkOutstream(StreamIO.mkOutstream(OSPrimIO.openWr fname, IO.BLOCK_BUF))

Legend:
Removed from v.843  
changed lines
  Added in v.844

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