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/branches/rt-transition/system/Basis/Implementation/IO/text-io.sml
ViewVC logotype

Diff of /sml/branches/rt-transition/system/Basis/Implementation/IO/text-io.sml

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

revision 2848, Thu Nov 8 21:59:14 2007 UTC revision 2849, Thu Nov 8 23:17:09 2007 UTC
# Line 1  Line 1 
1  (* text-io-fn.sml  (* text-io.sml
2   *   *
3   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4     * COPYRIGHT (c) 2007 Fellowship of SML/NJ
5   *   *
6   * QUESTION: what operations should raise exceptions when the stream is   * QUESTION: what operations should raise exceptions when the stream is
7   * closed?   * closed?
# Line 11  Line 12 
12      structure Int = IntImp      structure Int = IntImp
13      structure OS = OSImp      structure OS = OSImp
14  in  in
15  functor TextIOFn (  structure TextIO : TEXT_IO = struct
16    
17      structure OSPrimIO : sig      structure PIO = TextPrimIO
         include OS_PRIM_IO  
         val stdIn   : unit -> PrimIO.reader  
         val stdOut  : unit -> PrimIO.writer  
         val stdErr  : unit -> PrimIO.writer  
         val strReader : string -> PrimIO.reader  
       end  
       where PrimIO = TextPrimIO  
   
   ) : TEXT_IO = struct  
   
     structure PIO = OSPrimIO.PrimIO  
18      structure A = CharArray      structure A = CharArray
19      structure V = CharVector      structure V = CharVector
20      structure AS = CharArraySlice      structure AS = CharArraySlice
# Line 779  Line 769 
769    
770    (** Open files **)    (** Open files **)
771      fun openIn fname =      fun openIn fname =
772            mkInstream(StreamIO.mkInstream(OSPrimIO.openRd fname, empty))            mkInstream(StreamIO.mkInstream(PIO.openRd fname, empty))
773              handle ex => raise IO.Io{function="openIn", name=fname, cause=ex}              handle ex => raise IO.Io{function="openIn", name=fname, cause=ex}
774      fun openOut fname = let      fun openOut fname = let
775            val wr = OSPrimIO.openWr fname            val wr = PIO.openWr fname
776            in            in
777              mkOutstream (StreamIO.mkOutstream (wr, bufferMode wr))              mkOutstream (StreamIO.mkOutstream (wr, bufferMode wr))
778            end            end
779              handle ex => raise IO.Io{function="openOut", name=fname, cause=ex}              handle ex => raise IO.Io{function="openOut", name=fname, cause=ex}
780      fun openAppend fname =      fun openAppend fname =
781            mkOutstream(StreamIO.mkOutstream(OSPrimIO.openApp fname, IO.NO_BUF))            mkOutstream(StreamIO.mkOutstream(PIO.openApp fname, IO.NO_BUF))
782              handle ex => raise IO.Io{function="openAppend", name=fname, cause=ex}              handle ex => raise IO.Io{function="openAppend", name=fname, cause=ex}
783    
784    (** Text stream specific operations **)    (** Text stream specific operations **)
# Line 796  Line 786 
786          Option.map (fn (v, s) => (strm := s; v)) (StreamIO.inputLine (!strm))          Option.map (fn (v, s) => (strm := s; v)) (StreamIO.inputLine (!strm))
787      fun outputSubstr (strm, ss) = StreamIO.outputSubstr (!strm, ss)      fun outputSubstr (strm, ss) = StreamIO.outputSubstr (!strm, ss)
788      fun openString src =      fun openString src =
789            mkInstream(StreamIO.mkInstream(OSPrimIO.strReader src, empty))            mkInstream(StreamIO.mkInstream(PIO.strReader src, empty))
790              handle ex => raise IO.Io{function="openIn", name="<string>", cause=ex}              handle ex => raise IO.Io{function="openIn", name="<string>", cause=ex}
791    
792    (* the standard streams *)    (* the standard streams *)
# Line 804  Line 794 
794        structure SIO = StreamIO        structure SIO = StreamIO
795        fun mkStdIn () = let        fun mkStdIn () = let
796              val (strm as SIO.ISTRM(SIO.IBUF{info=SIO.INFO{cleanTag, ...}, ...}, _)) =              val (strm as SIO.ISTRM(SIO.IBUF{info=SIO.INFO{cleanTag, ...}, ...}, _)) =
797                    SIO.mkInstream(OSPrimIO.stdIn(), empty)                    SIO.mkInstream(PIO.stdIn(), empty)
798              in              in
799                CleanIO.rebindCleaner (cleanTag, {                CleanIO.rebindCleaner (cleanTag, {
800                    init = fn () => (),                    init = fn () => (),
# Line 814  Line 804 
804                strm                strm
805              end              end
806        fun mkStdOut () = let        fun mkStdOut () = let
807              val wr = OSPrimIO.stdOut()              val wr = PIO.stdOut()
808              val (strm as SIO.OSTRM{cleanTag, ...}) =              val (strm as SIO.OSTRM{cleanTag, ...}) =
809                    SIO.mkOutstream(wr, bufferMode wr)                    SIO.mkOutstream(wr, bufferMode wr)
810              in              in
# Line 827  Line 817 
817              end              end
818        fun mkStdErr () = let        fun mkStdErr () = let
819              val (strm as SIO.OSTRM{cleanTag, ...}) =              val (strm as SIO.OSTRM{cleanTag, ...}) =
820                    SIO.mkOutstream(OSPrimIO.stdErr(), IO.NO_BUF)                    SIO.mkOutstream(PIO.stdErr(), IO.NO_BUF)
821              in              in
822                CleanIO.rebindCleaner (cleanTag, {                CleanIO.rebindCleaner (cleanTag, {
823                   init = fn () => (),                   init = fn () => (),
# Line 866  Line 856 
856              doit              doit
857            end            end
858    
859    end (* TextIOFn *)    end (* TextIO *)
860  end  end
861    

Legend:
Removed from v.2848  
changed lines
  Added in v.2849

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