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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/TopLevel/interact/interact.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/TopLevel/interact/interact.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 118 - (view) (download)

1 : monnier 16 (* COPYRIGHT (c) 1996 Bell Laboratories. *)
2 :     (* interact.sml *)
3 :    
4 :     functor Interact(EvalLoop : EVALLOOP) : INTERACT =
5 :     struct
6 :     exception Interrupt = EvalLoop.Interrupt
7 :    
8 : monnier 45 (* This is where CM can install itelf into. Added for the purpose of
9 : monnier 16 * autoloading. (blume)
10 :     *)
11 :     type envref = EnvRef.envref
12 :    
13 :     fun installCompManager m = (#compManagerHook EvalLoop.stdParams) := m
14 :    
15 :     fun interact() = (
16 :     EvalLoop.interact EvalLoop.stdParams;
17 :     OS.Process.exit OS.Process.success)
18 :    
19 :     fun useFile (fname: string) =
20 :     (app Control.Print.say ["[opening ",fname,"]\n"];
21 :     EvalLoop.evalStream EvalLoop.stdParams
22 :     (fname,(TextIO.openIn fname
23 :     handle e as IO.Io _ =>
24 :     (app Control.Print.say["[use failed: ",
25 :     General.exnMessage e,
26 :     "]\n"];
27 :     raise ErrorMsg.Error))))
28 :    
29 :     fun useStream (stream: TextIO.instream) =
30 : monnier 45 EvalLoop.evalStream EvalLoop.stdParams ("<instream>", stream)
31 : monnier 16
32 : league 83 fun useStreamSilently (name, stream) =
33 :     let (* use the usual evalloop params, but substitute a
34 :     * pretty-printer that does nothing.
35 : league 79 *)
36 :     val {compManagerHook,
37 :     baseEnvRef,
38 :     localEnvRef,
39 :     transform,
40 :     instrument,
41 :     perform,
42 :     isolate,...} = EvalLoop.stdParams
43 :    
44 :     val params : EvalLoop.interactParams =
45 :     {compManagerHook = compManagerHook,
46 :     baseEnvRef = baseEnvRef,
47 :     localEnvRef = localEnvRef,
48 :     transform = transform,
49 :     instrument = instrument,
50 :     perform = perform,
51 :     isolate = isolate,
52 :     printer = fn _ => fn _ => fn _ => () (* no-op printer *)
53 :     }
54 :     in
55 : league 83 EvalLoop.evalStream params (name, stream)
56 : league 79 end
57 :    
58 : monnier 95 fun evalStream (stream: TextIO.instream, baseEnv: CMEnv.Env.environment) :
59 :     CMEnv.Env.environment =
60 : monnier 16 let val r = ref Environment.emptyEnv
61 :     val localEnvRef = {get=(fn()=> !r),set=(fn x=>r:=x)}
62 :     val b = ref baseEnv
63 : monnier 45 val baseEnvRef =
64 :     {get=(fn()=> !b),set=(fn _ => raise Fail "evalStream")}
65 : monnier 16 in EvalLoop.evalStream
66 :     ({compManagerHook = ref NONE,
67 :     (* ???? should CM get its hands into that? *)
68 :     baseEnvRef = baseEnvRef,
69 :     localEnvRef=localEnvRef,
70 : monnier 45 transform=(fn x => x),
71 :     instrument=(fn _ => fn x => x),
72 : monnier 16 perform=(fn x => x),
73 :     isolate= #isolate EvalLoop.stdParams,
74 :     printer= #printer EvalLoop.stdParams})
75 :     ("<instream>", stream);
76 : monnier 95 CMEnv.CM (#get localEnvRef ())
77 : monnier 16 end
78 :    
79 : monnier 45 (* These mUse functions should really be part of the Open Compiler *)
80 :     val mUseFile_hiddenList =
81 :     ref [ [((fn () => (print "--mUseFile not reset!")),"Error!")] ];
82 :    
83 :     fun mUseFile_reset () = (mUseFile_hiddenList := [])
84 :     fun mUseFile_add f = (mUseFile_hiddenList := (f::(!mUseFile_hiddenList)))
85 :     fun mUseFile_list () = (List.rev(!mUseFile_hiddenList))
86 :    
87 :     fun mUseFile (test) (fname: string) =
88 :     let fun repeat test n =
89 :     if (test n) then (useFile fname; repeat test (n+1)) else ()
90 :     in repeat test 0 end
91 :    
92 : monnier 16 end (* functor Interact *)
93 : monnier 95
94 :     (*
95 : monnier 118 * $Log$
96 : monnier 95 *)

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