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/cm/main/cm-boot.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/main/cm-boot.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 379 - (view) (download)

1 : blume 375 (*
2 :     * This is the module that actually puts together the contents of the
3 :     * structure CM that people find at the top-level. The "real" structure
4 :     * CM is defined in CmHook, but it needs to be initialized at bootstrap
5 :     * time -- and _that_ is what's done here.
6 :     *
7 :     * Copyright (c) 1999 by Lucent Bell Laboratories
8 :     *
9 :     * author: Matthias Blume (blume@cs.princeton.edu)
10 :     *)
11 :     functor LinkCM (structure HostMachDepVC : MACHDEP_VC) = struct
12 :    
13 :     datatype envrequest = AUTOLOAD | BARE
14 :    
15 :     local
16 :     structure YaccTool = YaccTool
17 :     structure LexTool = LexTool
18 :     structure BurgTool = BurgTool
19 :    
20 :     structure E = GenericVC.Environment
21 :     structure SE = GenericVC.StaticEnv
22 :     structure ER = GenericVC.EnvRef
23 :     structure BE = GenericVC.BareEnvironment
24 :     structure CMSE = GenericVC.CMStaticEnv
25 :     structure S = GenericVC.Symbol
26 :     structure CoerceEnv = GenericVC.CoerceEnv
27 :     structure EM = GenericVC.ErrorMsg
28 :     structure BF = HostMachDepVC.Binfile
29 :    
30 :     val os = SMLofNJ.SysInfo.getOSKind ()
31 :    
32 :     structure SSV =
33 :     SpecificSymValFn (structure MachDepVC = HostMachDepVC
34 :     val os = os)
35 :    
36 :     val emptydyn = E.dynamicPart E.emptyEnv
37 :     val system_values = ref emptydyn
38 :    
39 :     (* Instantiate the persistent state functor; this includes
40 :     * the binfile cache and the dynamic value cache *)
41 :     structure FullPersstate =
42 :     FullPersstateFn (structure MachDepVC = HostMachDepVC
43 :     val system_values = system_values)
44 :    
45 :     (* Building "Exec" will automatically also build "Recomp" and
46 :     * "RecompTraversal"... *)
47 :     local
48 :     structure E = ExecFn (structure PS = FullPersstate)
49 :     in
50 :     structure Recomp = E.Recomp
51 :     structure RT = E.RecompTraversal
52 :     structure Exec = E.Exec
53 :     end
54 :    
55 :     structure ET = CompileGenericFn (structure CT = Exec)
56 :    
57 :     structure AutoLoad = AutoLoadFn
58 :     (structure RT = RT
59 :     structure ET = ET)
60 :    
61 :     (* The StabilizeFn functor needs a way of converting bnodes to
62 :     * dependency-analysis environments. This can be achieved quite
63 :     * conveniently by a "recompile" traversal for bnodes. *)
64 :     fun bn2statenv gp i = #1 (#stat (valOf (RT.bnode' gp i)))
65 :     handle Option => raise Fail "bn2statenv"
66 :    
67 :     (* exec_group is basically the same as ET.group with
68 : blume 379 * one additional actions to be taken:
69 :     * Before executing the code, we announce the priviliges
70 : blume 375 * that are being invoked. (For the time being, we assume
71 :     * that everybody has every conceivable privilege, but at the
72 : blume 379 * very least we announce which ones are being made use of.) *)
73 : blume 375 fun exec_group gp (g as GroupGraph.GROUP { required = rq, ... }) =
74 :     (if StringSet.isEmpty rq then ()
75 :     else Say.say ("$Execute: required privileges are:\n" ::
76 :     map (fn s => (" " ^ s ^ "\n")) (StringSet.listItems rq));
77 :     ET.group gp g)
78 :    
79 :     fun recomp_runner gp g = isSome (RT.group gp g)
80 :    
81 :     (* This function combines the actions of "recompile" and "exec".
82 :     * When successful, it combines the results (thus forming a full
83 :     * environment) and adds it to the toplevel environment. *)
84 :     fun make_runner gp g =
85 :     case RT.group gp g of
86 :     NONE => false
87 :     | SOME { stat, sym} =>
88 :     (case exec_group gp g of
89 :     NONE => false
90 :     | SOME dyn => let
91 :     val delta = E.mkenv { static = stat, symbolic = sym,
92 :     dynamic = dyn }
93 :     val base = #get ER.topLevel ()
94 :     val new = BE.concatEnv (CoerceEnv.e2b delta, base)
95 :     in
96 :     #set ER.topLevel new;
97 :     Say.vsay ["[New bindings added.]\n"];
98 :     true
99 :     end)
100 :    
101 :     val al_greg = GroupReg.new ()
102 :    
103 :     (* Instantiate the stabilization mechanism. *)
104 :     structure Stabilize =
105 :     StabilizeFn (val bn2statenv = bn2statenv
106 :     val recomp = recomp_runner
107 :     val transfer_state = FullPersstate.transfer_state)
108 :    
109 :     (* Access to the stabilization mechanism is integrated into the
110 :     * parser. I'm not sure if this is the cleanest way, but it works
111 :     * well enough. *)
112 :     structure Parse = ParseFn (structure Stabilize = Stabilize
113 :     val pending = AutoLoad.getPending)
114 :    
115 :     local
116 :     type kernelValues =
117 :     { primconf : Primitive.configuration,
118 :     pervasive : E.environment,
119 :     corenv : BE.staticEnv,
120 :     pervcorepids : PidSet.set }
121 :    
122 :     val fnpolicy = FilenamePolicy.colocate
123 :     { os = os, arch = HostMachDepVC.architecture }
124 :    
125 :     val pcmode = PathConfig.new ()
126 :    
127 :     val theValues = ref (NONE: kernelValues option)
128 :    
129 :     in
130 : blume 377 fun setAnchor (a, s) =
131 :     (PathConfig.set (pcmode, a, s); SrcPath.sync ())
132 :     (* cancelling anchors cannot affect the order of existing paths
133 :     * (it may invalidate some paths; but all other ones stay as
134 :     * they are) *)
135 : blume 375 fun cancelAnchor a = PathConfig.cancel (pcmode, a)
136 : blume 377 (* same goes for reset because it just cancels all anchors... *)
137 : blume 375 fun resetPathConfig () = PathConfig.reset pcmode
138 :    
139 :     fun showPending () = let
140 :     fun one (s, _) = let
141 :     val nss = Symbol.nameSpaceToString (Symbol.nameSpace s)
142 :     val n = Symbol.name s
143 :     in
144 :     Say.say [" ", nss, " ", n, "\n"]
145 :     end
146 :     in
147 :     SymbolMap.appi one (AutoLoad.getPending ())
148 :     end
149 :    
150 :     fun initPaths () = let
151 :     val lpcth = EnvConfig.getSet StdConfig.local_pathconfig NONE
152 :     val p = case lpcth () of
153 :     NONE => []
154 :     | SOME f => [f]
155 :     val p = EnvConfig.getSet StdConfig.pathcfgspec NONE :: p
156 :     fun processOne f = PathConfig.processSpecFile (pcmode, f)
157 :     handle _ => ()
158 :     in
159 :     app processOne p
160 :     end
161 :    
162 :     fun param () = let
163 :     val v = valOf (!theValues)
164 :     handle Option =>
165 :     raise Fail "CMBoot: theParam not initialized"
166 :     in
167 :     { primconf = #primconf v,
168 :     fnpolicy = fnpolicy,
169 :     pcmode = pcmode,
170 :     symenv = SSV.env,
171 :     keep_going = EnvConfig.getSet StdConfig.keep_going NONE,
172 :     pervasive = #pervasive v,
173 :     corenv = #corenv v,
174 :     pervcorepids = #pervcorepids v }
175 :     end
176 :    
177 :     fun autoload s = let
178 :     val c = SrcPath.cwdContext ()
179 :     val p = SrcPath.standard pcmode { context = c, spec = s }
180 :     in
181 :     case Parse.parse (SOME al_greg) (param ()) NONE p of
182 :     NONE => false
183 :     | SOME (g, _) =>
184 :     (AutoLoad.register (GenericVC.EnvRef.topLevel, g);
185 :     true)
186 :     end
187 :    
188 :     fun al_ginfo () = { param = param (),
189 :     groupreg = al_greg,
190 :     errcons = EM.defaultConsumer () }
191 :    
192 :     val al_manager = AutoLoad.mkManager al_ginfo
193 :    
194 :     fun al_manager' (ast, _, ter) = al_manager (ast, ter)
195 :    
196 :     fun run sflag f s = let
197 :     val c = SrcPath.cwdContext ()
198 :     val p = SrcPath.standard pcmode { context = c, spec = s }
199 :     in
200 :     case Parse.parse NONE (param ()) sflag p of
201 :     NONE => false
202 :     | SOME (g, gp) => f gp g
203 :     end
204 :    
205 :     fun stabilize_runner gp g = true
206 :    
207 :     fun stabilize recursively = run (SOME recursively) stabilize_runner
208 :     val recomp = run NONE recomp_runner
209 :     val make = run NONE make_runner
210 :    
211 :     fun reset () =
212 :     (FullPersstate.reset ();
213 :     RT.reset ();
214 :     ET.reset ();
215 :     Recomp.reset ();
216 :     Exec.reset ();
217 :     AutoLoad.reset ();
218 :     Parse.reset ();
219 :     SmlInfo.forgetAllBut SrcPathSet.empty)
220 :    
221 :     fun initTheValues (bootdir, er) = let
222 :     val _ = let
223 :     fun listDir ds = let
224 :     fun loop l =
225 :     case OS.FileSys.readDir ds of
226 :     "" => l
227 :     | x => loop (x :: l)
228 :     in
229 :     loop []
230 :     end
231 :     val fileList = SafeIO.perform
232 :     { openIt = fn () => OS.FileSys.openDir bootdir,
233 :     closeIt = OS.FileSys.closeDir,
234 :     work = listDir,
235 :     cleanup = fn () => () }
236 :     fun isDir x =
237 :     OS.FileSys.isDir x handle _ => false
238 :     fun subDir x = let
239 :     val d = OS.Path.concat (bootdir, x)
240 :     in
241 :     if isDir d then SOME (x, d) else NONE
242 :     end
243 :     val pairList = List.mapPartial subDir fileList
244 :     in
245 :     app (fn (x, d) => PathConfig.set (pcmode, x, d)) pairList
246 :     end
247 :     val initgspec =
248 :     SrcPath.standard pcmode { context = SrcPath.cwdContext (),
249 :     spec = BtNames.initgspec }
250 :     val ginfo = { param = { primconf = Primitive.primEnvConf,
251 :     fnpolicy = fnpolicy,
252 :     pcmode = pcmode,
253 :     symenv = SSV.env,
254 :     keep_going = false,
255 :     pervasive = E.emptyEnv,
256 :     corenv = BE.staticPart BE.emptyEnv,
257 :     pervcorepids = PidSet.empty },
258 :     groupreg = GroupReg.new (),
259 :     errcons = EM.defaultConsumer () }
260 :     in
261 :     case BuildInitDG.build ginfo initgspec of
262 :     NONE => raise Fail "CMBoot: BuiltInitDG.build"
263 :     | SOME { rts, core, pervasive, primitives, ... } => let
264 :     (* It is absolutely crucial that we don't finish the
265 :     * recomp traversal until we are done with all
266 :     * nodes of the InitDG. This is because we have
267 :     * been cheating, and if we ever have to try and
268 :     * fetch assembly.sig or core.sml in a separate
269 :     * traversal, it will fail. *)
270 :     val rtts = RT.start ()
271 :     fun get n = let
272 :     val { stat = (s, sp), sym = (sy, syp), ctxt, bfc } =
273 :     valOf (RT.sbnode rtts ginfo n)
274 :     (* Since we cannot start another recomp traversal,
275 :     * we must also avoid exec traversals (because they
276 :     * would internally trigger recomp traversals).
277 :     * But at boot time any relevant value should be
278 :     * available as a sysval, so there is no problem. *)
279 :     val d =
280 :     case Option.map (FullPersstate.sysval o
281 :     BF.exportPidOf) bfc of
282 :     SOME (SOME d) => d
283 :     | _ => emptydyn
284 :     val env = E.mkenv { static = s, symbolic = sy,
285 :     dynamic = d }
286 :     val pidInfo = { statpid = sp, sympid = syp,
287 :     ctxt = ctxt }
288 :     in
289 :     (env, pidInfo)
290 :     end
291 :     fun getPspec (name, n) = let
292 :     val (env, pidInfo) = get n
293 :     in
294 :     { name = name, env = env, pidInfo = pidInfo }
295 :     end
296 :    
297 :     val (core, corePidInfo) = get core
298 :     val corenv = CoerceEnv.es2bs (E.staticPart core)
299 :     val (rts, _) = get rts
300 :     val (pervasive0, pervPidInfo) = get pervasive
301 :     val pspecs = map getPspec primitives
302 :     val core_symdyn =
303 :     E.mkenv { static = E.staticPart E.emptyEnv,
304 :     dynamic = E.dynamicPart core,
305 :     symbolic = E.symbolicPart core }
306 :     val pervasive = E.layerEnv (pervasive0, core_symdyn)
307 :     val pervcorepids =
308 :     PidSet.addList (PidSet.empty,
309 :     [#statpid corePidInfo,
310 :     #statpid pervPidInfo,
311 :     #sympid pervPidInfo])
312 :     in
313 :     (* Nobody is going to try and share this state --
314 :     * or, rather, this state is shared via access
315 :     * to "primitives". Therefore, we don't call
316 :     * RT.finish and ET.finish and reset the state. *)
317 :     FullPersstate.reset ();
318 :     #set ER.core corenv;
319 :     #set ER.pervasive pervasive;
320 :     #set ER.topLevel BE.emptyEnv;
321 :     theValues :=
322 :     SOME { primconf = Primitive.configuration pspecs,
323 :     pervasive = pervasive,
324 :     corenv = corenv,
325 :     pervcorepids = pervcorepids };
326 :     case er of
327 :     BARE =>
328 :     (make "basis.cm";
329 :     make "host-compiler.cm";
330 :     system_values := emptydyn)
331 :     | AUTOLOAD =>
332 :     (HostMachDepVC.Interact.installCompManager
333 :     (SOME al_manager');
334 :     autoload "basis.cm";
335 :     autoload "host-cm.cm";
336 :     CmHook.init
337 :     { stabilize = stabilize,
338 :     recomp = recomp,
339 :     make = make,
340 :     autoload = autoload,
341 :     reset = reset,
342 :     verbose =
343 :     EnvConfig.getSet StdConfig.verbose,
344 :     debug =
345 :     EnvConfig.getSet StdConfig.debug,
346 :     keep_going =
347 :     EnvConfig.getSet StdConfig.keep_going,
348 :     parse_caching =
349 :     EnvConfig.getSet StdConfig.parse_caching,
350 :     setAnchor = setAnchor,
351 :     cancelAnchor = cancelAnchor,
352 :     resetPathConfig = resetPathConfig,
353 :     synchronize = SrcPath.sync,
354 :     showPending = showPending })
355 :    
356 :     end
357 :     end
358 :     end
359 :     in
360 :     fun init (bootdir, de, er) =
361 :     (system_values := de;
362 :     initTheValues (bootdir, er);
363 :     Cleanup.install initPaths)
364 :     end
365 :     end

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