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 79 - (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 79 fun initialize () = (* read $HOME/.smlnjrc, if it exists *)
33 :     let val home = valOf (OS.Process.getEnv "HOME")
34 :     val rcfile = ".smlnjrc"
35 :     val rcpath = OS.Path.joinDirFile {dir=home, file=rcfile}
36 :     val rcin = TextIO.openIn rcpath
37 :     (* when reading the rc file, we use the usual evalloop
38 :     * params, but we substitute a pretty-printer that
39 :     * does nothing, so that we get rid of gross
40 :     * `val it = () : unit' everywhere.
41 :     *)
42 :     val {compManagerHook,
43 :     baseEnvRef,
44 :     localEnvRef,
45 :     transform,
46 :     instrument,
47 :     perform,
48 :     isolate,...} = EvalLoop.stdParams
49 :    
50 :     val params : EvalLoop.interactParams =
51 :     {compManagerHook = compManagerHook,
52 :     baseEnvRef = baseEnvRef,
53 :     localEnvRef = localEnvRef,
54 :     transform = transform,
55 :     instrument = instrument,
56 :     perform = perform,
57 :     isolate = isolate,
58 :     printer = fn _ => fn _ => fn _ => () (* no-op printer *)
59 :     }
60 :     in
61 :     EvalLoop.evalStream params (rcpath, rcin)
62 :     end
63 :     handle Option => ()
64 :     | IO.Io _ => ()
65 :    
66 : monnier 16 fun evalStream (stream: TextIO.instream, baseEnv: SCEnv.Env.environment) :
67 :     SCEnv.Env.environment =
68 :     let val r = ref Environment.emptyEnv
69 :     val localEnvRef = {get=(fn()=> !r),set=(fn x=>r:=x)}
70 :     val b = ref baseEnv
71 : monnier 45 val baseEnvRef =
72 :     {get=(fn()=> !b),set=(fn _ => raise Fail "evalStream")}
73 : monnier 16 in EvalLoop.evalStream
74 :     ({compManagerHook = ref NONE,
75 :     (* ???? should CM get its hands into that? *)
76 :     baseEnvRef = baseEnvRef,
77 :     localEnvRef=localEnvRef,
78 : monnier 45 transform=(fn x => x),
79 :     instrument=(fn _ => fn x => x),
80 : monnier 16 perform=(fn x => x),
81 :     isolate= #isolate EvalLoop.stdParams,
82 :     printer= #printer EvalLoop.stdParams})
83 :     ("<instream>", stream);
84 :     SCEnv.SC (#get localEnvRef ())
85 :     end
86 :    
87 : monnier 45 (* These mUse functions should really be part of the Open Compiler *)
88 :     val mUseFile_hiddenList =
89 :     ref [ [((fn () => (print "--mUseFile not reset!")),"Error!")] ];
90 :    
91 :     fun mUseFile_reset () = (mUseFile_hiddenList := [])
92 :     fun mUseFile_add f = (mUseFile_hiddenList := (f::(!mUseFile_hiddenList)))
93 :     fun mUseFile_list () = (List.rev(!mUseFile_hiddenList))
94 :    
95 :     fun mUseFile (test) (fname: string) =
96 :     let fun repeat test n =
97 :     if (test n) then (useFile fname; repeat test (n+1)) else ()
98 :     in repeat test 0 end
99 :    
100 : monnier 16 end (* functor Interact *)

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