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

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