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 507 - (view) (download)

1 : blume 375 (*
2 :     * This is the module that actually puts together the contents of the
3 : blume 483 * structure CM that people find at the top-level. A "minimal" structure
4 : blume 375 * CM is defined in CmHook, but it needs to be initialized at bootstrap
5 : blume 495 * time.
6 : blume 375 *
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 : blume 380 structure P = OS.Path
30 :     structure F = OS.FileSys
31 : blume 451 structure DG = DependencyGraph
32 : blume 375
33 :     val os = SMLofNJ.SysInfo.getOSKind ()
34 : blume 464 val my_archos =
35 :     concat [HostMachDepVC.architecture, "-", FilenamePolicy.kind2name os]
36 : blume 375
37 :     structure SSV =
38 :     SpecificSymValFn (structure MachDepVC = HostMachDepVC
39 :     val os = os)
40 :    
41 :     val emptydyn = E.dynamicPart E.emptyEnv
42 :     val system_values = ref emptydyn
43 :    
44 : blume 400 structure Compile =
45 : blume 448 CompileFn (structure MachDepVC = HostMachDepVC
46 : blume 464 val compile_there = Servers.compile o SrcPath.descr)
47 : blume 400
48 : blume 399 structure Link =
49 :     LinkFn (structure MachDepVC = HostMachDepVC
50 :     val system_values = system_values)
51 : blume 375
52 : blume 403 structure BFC =
53 :     BfcFn (structure MachDepVC = HostMachDepVC)
54 :    
55 : blume 375 structure AutoLoad = AutoLoadFn
56 : blume 399 (structure C = Compile
57 : blume 403 structure L = Link
58 :     structure BFC = BFC)
59 : blume 375
60 : blume 456 fun init_servers (GroupGraph.GROUP { grouppath, ... }) =
61 : blume 464 Servers.cm { archos = my_archos, project = SrcPath.descr grouppath }
62 : blume 456
63 : blume 399 fun recomp_runner gp g = let
64 : blume 456 val _ = init_servers g
65 : blume 403 fun store _ = ()
66 :     val { group, ... } = Compile.newTraversal (Link.evict, store, g)
67 : blume 399 in
68 : blume 450 isSome (Servers.withServers (fn () => group gp))
69 :     before Link.cleanup gp
70 : blume 399 end
71 : blume 375
72 :     (* This function combines the actions of "recompile" and "exec".
73 :     * When successful, it combines the results (thus forming a full
74 :     * environment) and adds it to the toplevel environment. *)
75 : blume 399 fun make_runner gp g = let
76 : blume 403 val { store, get } = BFC.new ()
77 : blume 456 val _ = init_servers g
78 : blume 403 val { group = c_group, ... } =
79 :     Compile.newTraversal (Link.evict, store, g)
80 :     val { group = l_group, ... } = Link.newTraversal (g, get)
81 : blume 399 val GroupGraph.GROUP { required = rq, ... } = g
82 :     in
83 : blume 450 case Servers.withServers (fn () => c_group gp) of
84 : blume 375 NONE => false
85 :     | SOME { stat, sym} =>
86 : blume 399 (* Before executing the code, we announce the priviliges
87 :     * that are being invoked. (For the time being, we assume
88 :     * that everybody has every conceivable privilege, but at
89 :     * the very least we announce which ones are being made
90 :     * use of.) *)
91 : blume 400 (Link.cleanup gp;
92 : blume 399 if StringSet.isEmpty rq then ()
93 :     else Say.say ("$Execute: required privileges are:\n" ::
94 :     map (fn s => (" " ^ s ^ "\n")) (StringSet.listItems rq));
95 :     case l_group gp of
96 : blume 375 NONE => false
97 :     | SOME dyn => let
98 :     val delta = E.mkenv { static = stat, symbolic = sym,
99 :     dynamic = dyn }
100 :     val base = #get ER.topLevel ()
101 :     val new = BE.concatEnv (CoerceEnv.e2b delta, base)
102 :     in
103 :     #set ER.topLevel new;
104 :     Say.vsay ["[New bindings added.]\n"];
105 :     true
106 :     end)
107 : blume 399 end
108 : blume 375
109 :     val al_greg = GroupReg.new ()
110 :    
111 :     (* Instantiate the stabilization mechanism. *)
112 :     structure Stabilize =
113 : blume 403 StabilizeFn (structure MachDepVC = HostMachDepVC
114 :     fun recomp gp g = let
115 :     val { store, get } = BFC.new ()
116 : blume 456 val _ = init_servers g
117 : blume 403 val { group, ... } =
118 :     Compile.newTraversal (Link.evict, store, g)
119 :     in
120 : blume 450 case Servers.withServers (fn () => group gp) of
121 : blume 403 NONE => NONE
122 :     | SOME _ => SOME get
123 :     end
124 :     fun destroy_state gp i =
125 : blume 451 (Compile.evict i;
126 :     Link.evict gp i)
127 : blume 403 val getII = Compile.getII)
128 : blume 375
129 :     (* Access to the stabilization mechanism is integrated into the
130 :     * parser. I'm not sure if this is the cleanest way, but it works
131 :     * well enough. *)
132 :     structure Parse = ParseFn (structure Stabilize = Stabilize
133 :     val pending = AutoLoad.getPending)
134 :    
135 :     local
136 :     type kernelValues =
137 :     { primconf : Primitive.configuration,
138 :     pervasive : E.environment,
139 :     corenv : BE.staticEnv,
140 :     pervcorepids : PidSet.set }
141 :    
142 :     val fnpolicy = FilenamePolicy.colocate
143 :     { os = os, arch = HostMachDepVC.architecture }
144 :    
145 :     val pcmode = PathConfig.new ()
146 :    
147 :     val theValues = ref (NONE: kernelValues option)
148 :    
149 :     in
150 : blume 479 fun setAnchor { anchor = a, path = s } =
151 : blume 377 (PathConfig.set (pcmode, a, s); SrcPath.sync ())
152 :     (* cancelling anchors cannot affect the order of existing paths
153 :     * (it may invalidate some paths; but all other ones stay as
154 :     * they are) *)
155 : blume 375 fun cancelAnchor a = PathConfig.cancel (pcmode, a)
156 : blume 377 (* same goes for reset because it just cancels all anchors... *)
157 : blume 375 fun resetPathConfig () = PathConfig.reset pcmode
158 :    
159 : blume 479 fun getPending () = let
160 : blume 375 fun one (s, _) = let
161 :     val nss = Symbol.nameSpaceToString (Symbol.nameSpace s)
162 :     val n = Symbol.name s
163 :     in
164 : blume 479 concat [" ", nss, " ", n, "\n"]
165 : blume 375 end
166 :     in
167 : blume 479 map one (SymbolMap.listItemsi (AutoLoad.getPending ()))
168 : blume 375 end
169 :    
170 :     fun initPaths () = let
171 : blume 433 val lpcth = #get StdConfig.local_pathconfig ()
172 : blume 375 val p = case lpcth () of
173 :     NONE => []
174 :     | SOME f => [f]
175 : blume 433 val p = #get StdConfig.pathcfgspec () :: p
176 : blume 375 fun processOne f = PathConfig.processSpecFile (pcmode, f)
177 :     handle _ => ()
178 :     in
179 :     app processOne p
180 :     end
181 :    
182 :     fun param () = let
183 :     val v = valOf (!theValues)
184 :     handle Option =>
185 :     raise Fail "CMBoot: theParam not initialized"
186 :     in
187 :     { primconf = #primconf v,
188 :     fnpolicy = fnpolicy,
189 :     pcmode = pcmode,
190 : blume 433 symval = SSV.symval,
191 :     keep_going = #get StdConfig.keep_going (),
192 : blume 375 pervasive = #pervasive v,
193 :     corenv = #corenv v,
194 :     pervcorepids = #pervcorepids v }
195 :     end
196 :    
197 : blume 507 fun dropPickles () =
198 :     if #get StdConfig.conserve_memory () then
199 :     Parse.dropPickles ()
200 :     else ()
201 :    
202 : blume 375 fun autoload s = let
203 :     val c = SrcPath.cwdContext ()
204 :     val p = SrcPath.standard pcmode { context = c, spec = s }
205 :     in
206 : blume 505 (case Parse.parse (SOME al_greg) (param ()) NONE p of
207 :     NONE => false
208 :     | SOME (g, _) =>
209 :     (AutoLoad.register (GenericVC.EnvRef.topLevel, g);
210 :     true))
211 : blume 507 before dropPickles ()
212 : blume 375 end
213 :    
214 :     fun al_ginfo () = { param = param (),
215 :     groupreg = al_greg,
216 :     errcons = EM.defaultConsumer () }
217 :    
218 : blume 505 val al_manager =
219 :     AutoLoad.mkManager { get_ginfo = al_ginfo,
220 : blume 507 dropPickles = dropPickles }
221 : blume 375
222 :     fun al_manager' (ast, _, ter) = al_manager (ast, ter)
223 :    
224 :     fun run sflag f s = let
225 :     val c = SrcPath.cwdContext ()
226 :     val p = SrcPath.standard pcmode { context = c, spec = s }
227 :     in
228 : blume 505 (case Parse.parse NONE (param ()) sflag p of
229 :     NONE => false
230 :     | SOME (g, gp) => f gp g)
231 : blume 507 before dropPickles ()
232 : blume 375 end
233 :    
234 : blume 449 fun stabilize_runner gp g = true
235 :    
236 :     fun stabilize recursively = run (SOME recursively) stabilize_runner
237 :     val recomp = run NONE recomp_runner
238 :     val make = run NONE make_runner
239 :    
240 : blume 480 fun slave () =
241 :     Slave.slave { pcmode = pcmode,
242 :     parse = fn p => Parse.parse NONE (param ()) NONE p,
243 :     my_archos = my_archos,
244 :     sbtrav = Compile.newSbnodeTraversal,
245 :     make = make }
246 : blume 456
247 : blume 375 fun reset () =
248 : blume 399 (Compile.reset ();
249 :     Link.reset ();
250 : blume 375 AutoLoad.reset ();
251 :     Parse.reset ();
252 : blume 487 SmlInfo.reset ())
253 : blume 375
254 : blume 495 fun initTheValues (bootdir, er, autoload_postprocess) = let
255 : blume 375 val _ = let
256 :     fun listDir ds = let
257 :     fun loop l =
258 : blume 380 case F.readDir ds of
259 : blume 375 "" => l
260 :     | x => loop (x :: l)
261 :     in
262 :     loop []
263 :     end
264 :     val fileList = SafeIO.perform
265 : blume 380 { openIt = fn () => F.openDir bootdir,
266 :     closeIt = F.closeDir,
267 : blume 375 work = listDir,
268 : blume 459 cleanup = fn _ => () }
269 : blume 380 fun isDir x = F.isDir x handle _ => false
270 : blume 375 fun subDir x = let
271 : blume 380 val d = P.concat (bootdir, x)
272 : blume 375 in
273 :     if isDir d then SOME (x, d) else NONE
274 :     end
275 :     val pairList = List.mapPartial subDir fileList
276 :     in
277 :     app (fn (x, d) => PathConfig.set (pcmode, x, d)) pairList
278 :     end
279 :     val initgspec =
280 :     SrcPath.standard pcmode { context = SrcPath.cwdContext (),
281 :     spec = BtNames.initgspec }
282 :     val ginfo = { param = { primconf = Primitive.primEnvConf,
283 :     fnpolicy = fnpolicy,
284 :     pcmode = pcmode,
285 : blume 433 symval = SSV.symval,
286 : blume 375 keep_going = false,
287 :     pervasive = E.emptyEnv,
288 :     corenv = BE.staticPart BE.emptyEnv,
289 :     pervcorepids = PidSet.empty },
290 :     groupreg = GroupReg.new (),
291 :     errcons = EM.defaultConsumer () }
292 :     in
293 :     case BuildInitDG.build ginfo initgspec of
294 :     NONE => raise Fail "CMBoot: BuiltInitDG.build"
295 :     | SOME { rts, core, pervasive, primitives, ... } => let
296 :     (* It is absolutely crucial that we don't finish the
297 :     * recomp traversal until we are done with all
298 :     * nodes of the InitDG. This is because we have
299 :     * been cheating, and if we ever have to try and
300 :     * fetch assembly.sig or core.sml in a separate
301 :     * traversal, it will fail. *)
302 : blume 400 val sbnode = Compile.newSbnodeTraversal ()
303 : blume 375 fun get n = let
304 : blume 460 val { statpid, statenv, symenv, sympid } =
305 :     valOf (sbnode ginfo n)
306 : blume 399 (* We have not implemented the "sbnode" part
307 :     * in the Link module.
308 : blume 375 * But at boot time any relevant value should be
309 : blume 399 * available as a sysval, so there is no problem.
310 :     *
311 :     * WARNING! HACK!
312 :     * We are cheating somewhat by taking advantage
313 :     * of the fact that the staticPid is always
314 :     * the same as the exportPid if the latter exists.
315 :     *)
316 :     val d = case Link.sysval (SOME statpid) of
317 :     SOME d => d
318 :     | NONE => emptydyn
319 : blume 461 val { env = static, ctxt } = statenv ()
320 :     val env = E.mkenv { static = static,
321 : blume 399 symbolic = symenv (),
322 : blume 375 dynamic = d }
323 : blume 461 val pidInfo =
324 :     { statpid = statpid, sympid = sympid,
325 :     ctxt = ctxt }
326 : blume 375 in
327 :     (env, pidInfo)
328 :     end
329 :     fun getPspec (name, n) = let
330 :     val (env, pidInfo) = get n
331 :     in
332 :     { name = name, env = env, pidInfo = pidInfo }
333 :     end
334 :    
335 :     val (core, corePidInfo) = get core
336 :     val corenv = CoerceEnv.es2bs (E.staticPart core)
337 :     val (rts, _) = get rts
338 :     val (pervasive0, pervPidInfo) = get pervasive
339 :     val pspecs = map getPspec primitives
340 :     val core_symdyn =
341 :     E.mkenv { static = E.staticPart E.emptyEnv,
342 :     dynamic = E.dynamicPart core,
343 :     symbolic = E.symbolicPart core }
344 :     val pervasive = E.layerEnv (pervasive0, core_symdyn)
345 :     val pervcorepids =
346 :     PidSet.addList (PidSet.empty,
347 :     [#statpid corePidInfo,
348 :     #statpid pervPidInfo,
349 :     #sympid pervPidInfo])
350 : blume 495 fun bare_autoload x =
351 :     (Say.say
352 :     ["!* ", x,
353 :     ": \"autoload\" not available, using \"make\"\n"];
354 :     make x)
355 :     val bare_preload =
356 :     Preload.preload { make = make,
357 :     autoload = bare_autoload }
358 :     val standard_preload =
359 :     Preload.preload { make = make, autoload = autoload }
360 : blume 375 in
361 : blume 399 Compile.reset ();
362 :     Link.reset ();
363 : blume 375 #set ER.core corenv;
364 :     #set ER.pervasive pervasive;
365 :     #set ER.topLevel BE.emptyEnv;
366 :     theValues :=
367 :     SOME { primconf = Primitive.configuration pspecs,
368 :     pervasive = pervasive,
369 :     corenv = corenv,
370 :     pervcorepids = pervcorepids };
371 :     case er of
372 :     BARE =>
373 : blume 495 (bare_preload BtNames.bare_preloads;
374 :     system_values := emptydyn;
375 :     NONE)
376 : blume 375 | AUTOLOAD =>
377 :     (HostMachDepVC.Interact.installCompManager
378 :     (SOME al_manager');
379 : blume 495 standard_preload BtNames.standard_preloads;
380 : blume 375 CmHook.init
381 :     { stabilize = stabilize,
382 :     recomp = recomp,
383 :     make = make,
384 : blume 495 autoload = autoload };
385 : blume 507 (* unconditionally drop all library pickles *)
386 :     Parse.dropPickles ();
387 : blume 495 SOME (autoload_postprocess ()))
388 : blume 375 end
389 :     end
390 :     end
391 :     in
392 : blume 495 fun init (bootdir, de, er) = let
393 :     fun procCmdLine () = let
394 :     val autoload = ignore o autoload
395 :     val make = ignore o make
396 :     fun p (f, ("sml" | "sig"), mk) = HostMachDepVC.Interact.useFile f
397 :     | p (f, "cm", mk) = mk f
398 :     | p (f, e, mk) = Say.say ["!* unable to process `", f,
399 :     "' (unknown extension `", e, "')\n"]
400 :     fun arg ("-a", _) = autoload
401 :     | arg ("-m", _) = make
402 :     | arg (f, mk) =
403 :     (p (f,
404 :     String.map Char.toLower (getOpt (OS.Path.ext f, "<none>")),
405 :     mk);
406 :     mk)
407 :     in
408 :     case SMLofNJ.getArgs () of
409 :     ["@CMslave"] => (#set StdConfig.verbose false; slave ())
410 :     | l => ignore (foldl arg autoload l)
411 :     end
412 : blume 448 in
413 : blume 495 system_values := de;
414 :     initTheValues (bootdir, er, fn () => (Cleanup.install initPaths;
415 :     procCmdLine))
416 : blume 448 end
417 : blume 479
418 :     structure CM :> CM = struct
419 :     type 'a controller = { get : unit -> 'a, set : 'a -> unit }
420 :    
421 :     structure Anchor = struct
422 :     val set = setAnchor
423 :     val cancel = cancelAnchor
424 :     val reset = resetPathConfig
425 :     end
426 :    
427 :     structure Control = struct
428 :     val keep_going = StdConfig.keep_going
429 :     val verbose = StdConfig.verbose
430 :     val parse_caching = StdConfig.parse_caching
431 :     val warn_obsolete = StdConfig.warn_obsolete
432 :     val debug = StdConfig.debug
433 : blume 505 val conserve_memory = StdConfig.conserve_memory
434 : blume 479 end
435 :    
436 :     structure Library = struct
437 :     type lib = SrcPath.t
438 :     val known = Parse.listLibs
439 :     val descr = SrcPath.descr
440 :     val osstring = SrcPath.osstring
441 :     val dismiss = Parse.dismissLib
442 :     end
443 :    
444 :     structure State = struct
445 :     val synchronize = SrcPath.sync
446 :     val reset = reset
447 :     val pending = getPending
448 :     end
449 :    
450 :     structure Server = struct
451 :     type server = Servers.server
452 :     fun start x = Servers.start x before SrcPath.invalidateCwd ()
453 :     val stop = Servers.stop
454 :     val kill = Servers.kill
455 :     val name = Servers.name
456 :     end
457 :    
458 :     val autoload = autoload
459 :     val make = make
460 :     val recomp = recomp
461 :     val stabilize = stabilize
462 :    
463 :     val symval = SSV.symval
464 :     end
465 : blume 375 end
466 :     end

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