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 505 - (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 :     fun autoload s = let
198 :     val c = SrcPath.cwdContext ()
199 :     val p = SrcPath.standard pcmode { context = c, spec = s }
200 :     in
201 : blume 505 (case Parse.parse (SOME al_greg) (param ()) NONE p of
202 :     NONE => false
203 :     | SOME (g, _) =>
204 :     (AutoLoad.register (GenericVC.EnvRef.topLevel, g);
205 :     true))
206 :     before Parse.dropPickles ()
207 : blume 375 end
208 :    
209 :     fun al_ginfo () = { param = param (),
210 :     groupreg = al_greg,
211 :     errcons = EM.defaultConsumer () }
212 :    
213 : blume 505 val al_manager =
214 :     AutoLoad.mkManager { get_ginfo = al_ginfo,
215 :     dropPickles = Parse.dropPickles }
216 : blume 375
217 :     fun al_manager' (ast, _, ter) = al_manager (ast, ter)
218 :    
219 :     fun run sflag f s = let
220 :     val c = SrcPath.cwdContext ()
221 :     val p = SrcPath.standard pcmode { context = c, spec = s }
222 :     in
223 : blume 505 (case Parse.parse NONE (param ()) sflag p of
224 :     NONE => false
225 :     | SOME (g, gp) => f gp g)
226 :     before Parse.dropPickles ()
227 : blume 375 end
228 :    
229 : blume 449 fun stabilize_runner gp g = true
230 :    
231 :     fun stabilize recursively = run (SOME recursively) stabilize_runner
232 :     val recomp = run NONE recomp_runner
233 :     val make = run NONE make_runner
234 :    
235 : blume 480 fun slave () =
236 :     Slave.slave { pcmode = pcmode,
237 :     parse = fn p => Parse.parse NONE (param ()) NONE p,
238 :     my_archos = my_archos,
239 :     sbtrav = Compile.newSbnodeTraversal,
240 :     make = make }
241 : blume 456
242 : blume 375 fun reset () =
243 : blume 399 (Compile.reset ();
244 :     Link.reset ();
245 : blume 375 AutoLoad.reset ();
246 :     Parse.reset ();
247 : blume 487 SmlInfo.reset ())
248 : blume 375
249 : blume 495 fun initTheValues (bootdir, er, autoload_postprocess) = let
250 : blume 375 val _ = let
251 :     fun listDir ds = let
252 :     fun loop l =
253 : blume 380 case F.readDir ds of
254 : blume 375 "" => l
255 :     | x => loop (x :: l)
256 :     in
257 :     loop []
258 :     end
259 :     val fileList = SafeIO.perform
260 : blume 380 { openIt = fn () => F.openDir bootdir,
261 :     closeIt = F.closeDir,
262 : blume 375 work = listDir,
263 : blume 459 cleanup = fn _ => () }
264 : blume 380 fun isDir x = F.isDir x handle _ => false
265 : blume 375 fun subDir x = let
266 : blume 380 val d = P.concat (bootdir, x)
267 : blume 375 in
268 :     if isDir d then SOME (x, d) else NONE
269 :     end
270 :     val pairList = List.mapPartial subDir fileList
271 :     in
272 :     app (fn (x, d) => PathConfig.set (pcmode, x, d)) pairList
273 :     end
274 :     val initgspec =
275 :     SrcPath.standard pcmode { context = SrcPath.cwdContext (),
276 :     spec = BtNames.initgspec }
277 :     val ginfo = { param = { primconf = Primitive.primEnvConf,
278 :     fnpolicy = fnpolicy,
279 :     pcmode = pcmode,
280 : blume 433 symval = SSV.symval,
281 : blume 375 keep_going = false,
282 :     pervasive = E.emptyEnv,
283 :     corenv = BE.staticPart BE.emptyEnv,
284 :     pervcorepids = PidSet.empty },
285 :     groupreg = GroupReg.new (),
286 :     errcons = EM.defaultConsumer () }
287 :     in
288 :     case BuildInitDG.build ginfo initgspec of
289 :     NONE => raise Fail "CMBoot: BuiltInitDG.build"
290 :     | SOME { rts, core, pervasive, primitives, ... } => let
291 :     (* It is absolutely crucial that we don't finish the
292 :     * recomp traversal until we are done with all
293 :     * nodes of the InitDG. This is because we have
294 :     * been cheating, and if we ever have to try and
295 :     * fetch assembly.sig or core.sml in a separate
296 :     * traversal, it will fail. *)
297 : blume 400 val sbnode = Compile.newSbnodeTraversal ()
298 : blume 375 fun get n = let
299 : blume 460 val { statpid, statenv, symenv, sympid } =
300 :     valOf (sbnode ginfo n)
301 : blume 399 (* We have not implemented the "sbnode" part
302 :     * in the Link module.
303 : blume 375 * But at boot time any relevant value should be
304 : blume 399 * available as a sysval, so there is no problem.
305 :     *
306 :     * WARNING! HACK!
307 :     * We are cheating somewhat by taking advantage
308 :     * of the fact that the staticPid is always
309 :     * the same as the exportPid if the latter exists.
310 :     *)
311 :     val d = case Link.sysval (SOME statpid) of
312 :     SOME d => d
313 :     | NONE => emptydyn
314 : blume 461 val { env = static, ctxt } = statenv ()
315 :     val env = E.mkenv { static = static,
316 : blume 399 symbolic = symenv (),
317 : blume 375 dynamic = d }
318 : blume 461 val pidInfo =
319 :     { statpid = statpid, sympid = sympid,
320 :     ctxt = ctxt }
321 : blume 375 in
322 :     (env, pidInfo)
323 :     end
324 :     fun getPspec (name, n) = let
325 :     val (env, pidInfo) = get n
326 :     in
327 :     { name = name, env = env, pidInfo = pidInfo }
328 :     end
329 :    
330 :     val (core, corePidInfo) = get core
331 :     val corenv = CoerceEnv.es2bs (E.staticPart core)
332 :     val (rts, _) = get rts
333 :     val (pervasive0, pervPidInfo) = get pervasive
334 :     val pspecs = map getPspec primitives
335 :     val core_symdyn =
336 :     E.mkenv { static = E.staticPart E.emptyEnv,
337 :     dynamic = E.dynamicPart core,
338 :     symbolic = E.symbolicPart core }
339 :     val pervasive = E.layerEnv (pervasive0, core_symdyn)
340 :     val pervcorepids =
341 :     PidSet.addList (PidSet.empty,
342 :     [#statpid corePidInfo,
343 :     #statpid pervPidInfo,
344 :     #sympid pervPidInfo])
345 : blume 495 fun bare_autoload x =
346 :     (Say.say
347 :     ["!* ", x,
348 :     ": \"autoload\" not available, using \"make\"\n"];
349 :     make x)
350 :     val bare_preload =
351 :     Preload.preload { make = make,
352 :     autoload = bare_autoload }
353 :     val standard_preload =
354 :     Preload.preload { make = make, autoload = autoload }
355 : blume 375 in
356 : blume 399 Compile.reset ();
357 :     Link.reset ();
358 : blume 375 #set ER.core corenv;
359 :     #set ER.pervasive pervasive;
360 :     #set ER.topLevel BE.emptyEnv;
361 :     theValues :=
362 :     SOME { primconf = Primitive.configuration pspecs,
363 :     pervasive = pervasive,
364 :     corenv = corenv,
365 :     pervcorepids = pervcorepids };
366 :     case er of
367 :     BARE =>
368 : blume 495 (bare_preload BtNames.bare_preloads;
369 :     system_values := emptydyn;
370 :     NONE)
371 : blume 375 | AUTOLOAD =>
372 :     (HostMachDepVC.Interact.installCompManager
373 :     (SOME al_manager');
374 : blume 495 standard_preload BtNames.standard_preloads;
375 : blume 375 CmHook.init
376 :     { stabilize = stabilize,
377 :     recomp = recomp,
378 :     make = make,
379 : blume 495 autoload = autoload };
380 :     SOME (autoload_postprocess ()))
381 : blume 375 end
382 :     end
383 :     end
384 :     in
385 : blume 495 fun init (bootdir, de, er) = let
386 :     fun procCmdLine () = let
387 :     val autoload = ignore o autoload
388 :     val make = ignore o make
389 :     fun p (f, ("sml" | "sig"), mk) = HostMachDepVC.Interact.useFile f
390 :     | p (f, "cm", mk) = mk f
391 :     | p (f, e, mk) = Say.say ["!* unable to process `", f,
392 :     "' (unknown extension `", e, "')\n"]
393 :     fun arg ("-a", _) = autoload
394 :     | arg ("-m", _) = make
395 :     | arg (f, mk) =
396 :     (p (f,
397 :     String.map Char.toLower (getOpt (OS.Path.ext f, "<none>")),
398 :     mk);
399 :     mk)
400 :     in
401 :     case SMLofNJ.getArgs () of
402 :     ["@CMslave"] => (#set StdConfig.verbose false; slave ())
403 :     | l => ignore (foldl arg autoload l)
404 :     end
405 : blume 448 in
406 : blume 495 system_values := de;
407 :     initTheValues (bootdir, er, fn () => (Cleanup.install initPaths;
408 :     procCmdLine))
409 : blume 448 end
410 : blume 479
411 :     structure CM :> CM = struct
412 :     type 'a controller = { get : unit -> 'a, set : 'a -> unit }
413 :    
414 :     structure Anchor = struct
415 :     val set = setAnchor
416 :     val cancel = cancelAnchor
417 :     val reset = resetPathConfig
418 :     end
419 :    
420 :     structure Control = struct
421 :     val keep_going = StdConfig.keep_going
422 :     val verbose = StdConfig.verbose
423 :     val parse_caching = StdConfig.parse_caching
424 :     val warn_obsolete = StdConfig.warn_obsolete
425 :     val debug = StdConfig.debug
426 : blume 505 val conserve_memory = StdConfig.conserve_memory
427 : blume 479 end
428 :    
429 :     structure Library = struct
430 :     type lib = SrcPath.t
431 :     val known = Parse.listLibs
432 :     val descr = SrcPath.descr
433 :     val osstring = SrcPath.osstring
434 :     val dismiss = Parse.dismissLib
435 :     end
436 :    
437 :     structure State = struct
438 :     val synchronize = SrcPath.sync
439 :     val reset = reset
440 :     val pending = getPending
441 :     end
442 :    
443 :     structure Server = struct
444 :     type server = Servers.server
445 :     fun start x = Servers.start x before SrcPath.invalidateCwd ()
446 :     val stop = Servers.stop
447 :     val kill = Servers.kill
448 :     val name = Servers.name
449 :     end
450 :    
451 :     val autoload = autoload
452 :     val make = make
453 :     val recomp = recomp
454 :     val stabilize = stabilize
455 :    
456 :     val symval = SSV.symval
457 :     end
458 : blume 375 end
459 :     end

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