Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/common/log.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/common/log.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 477 - (view) (download)

1 : jhr 237 (* log.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 237 * All rights reserved.
5 :     *)
6 :    
7 :     structure Log : sig
8 :    
9 : jhr 340 val enabled : unit -> bool
10 :    
11 : jhr 237 val init : string -> unit
12 :    
13 :     val logFile : unit -> TextIO.outstream
14 :    
15 :     val msg : string -> unit
16 :    
17 :     end = struct
18 :    
19 : jhr 340 val enabledFlg = ref false
20 : jhr 237 val logStrm : TextIO.outstream option ref = ref NONE
21 :    
22 : jhr 340 fun enabled () = !enabledFlg
23 :    
24 : jhr 237 fun init file = (case !logStrm
25 :     of NONE => let
26 :     val outS = TextIO.openOut file
27 :     in
28 : jhr 340 enabledFlg := true;
29 : jhr 237 (* turn off buffering *)
30 :     TextIO.StreamIO.setBufferMode (TextIO.getOutstream outS, IO.NO_BUF);
31 :     logStrm := SOME outS
32 :     end
33 :     | SOME strm => raise Fail "multiple initialization of log file"
34 :     (* end case *))
35 :    
36 :     fun logFile () = (case !logStrm
37 : jhr 340 of NONE => (init "/dev/null"; enabledFlg := false; logFile())
38 : jhr 237 | SOME outS => outS
39 :     (* end case *))
40 :    
41 : jhr 340 fun msg s = if !enabledFlg then TextIO.output(logFile(), s) else ();
42 : jhr 237
43 :     end
44 : jhr 340

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