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 403 - (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 :     val lpcth = EnvConfig.getSet StdConfig.local_pathconfig NONE
160 :     val p = case lpcth () of
161 :     NONE => []
162 :     | SOME f => [f]
163 :     val p = EnvConfig.getSet StdConfig.pathcfgspec NONE :: p
164 :     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 :     symenv = SSV.env,
179 :     keep_going = EnvConfig.getSet StdConfig.keep_going NONE,
180 :     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 :     fun stabilize_runner gp g = true
214 :    
215 :     fun stabilize recursively = run (SOME recursively) stabilize_runner
216 :     val recomp = run NONE recomp_runner
217 :     val make = run NONE make_runner
218 :    
219 :     fun reset () =
220 : blume 399 (Compile.reset ();
221 :     Link.reset ();
222 : blume 375 AutoLoad.reset ();
223 :     Parse.reset ();
224 :     SmlInfo.forgetAllBut SrcPathSet.empty)
225 :    
226 :     fun initTheValues (bootdir, er) = let
227 :     val _ = let
228 :     fun listDir ds = let
229 :     fun loop l =
230 : blume 380 case F.readDir ds of
231 : blume 375 "" => l
232 :     | x => loop (x :: l)
233 :     in
234 :     loop []
235 :     end
236 :     val fileList = SafeIO.perform
237 : blume 380 { openIt = fn () => F.openDir bootdir,
238 :     closeIt = F.closeDir,
239 : blume 375 work = listDir,
240 :     cleanup = fn () => () }
241 : blume 380 fun isDir x = F.isDir x handle _ => false
242 : blume 375 fun subDir x = let
243 : blume 380 val d = P.concat (bootdir, x)
244 : blume 375 in
245 :     if isDir d then SOME (x, d) else NONE
246 :     end
247 :     val pairList = List.mapPartial subDir fileList
248 :     in
249 :     app (fn (x, d) => PathConfig.set (pcmode, x, d)) pairList
250 :     end
251 :     val initgspec =
252 :     SrcPath.standard pcmode { context = SrcPath.cwdContext (),
253 :     spec = BtNames.initgspec }
254 :     val ginfo = { param = { primconf = Primitive.primEnvConf,
255 :     fnpolicy = fnpolicy,
256 :     pcmode = pcmode,
257 :     symenv = SSV.env,
258 :     keep_going = false,
259 :     pervasive = E.emptyEnv,
260 :     corenv = BE.staticPart BE.emptyEnv,
261 :     pervcorepids = PidSet.empty },
262 :     groupreg = GroupReg.new (),
263 :     errcons = EM.defaultConsumer () }
264 :     in
265 :     case BuildInitDG.build ginfo initgspec of
266 :     NONE => raise Fail "CMBoot: BuiltInitDG.build"
267 :     | SOME { rts, core, pervasive, primitives, ... } => let
268 :     (* It is absolutely crucial that we don't finish the
269 :     * recomp traversal until we are done with all
270 :     * nodes of the InitDG. This is because we have
271 :     * been cheating, and if we ever have to try and
272 :     * fetch assembly.sig or core.sml in a separate
273 :     * traversal, it will fail. *)
274 : blume 400 val sbnode = Compile.newSbnodeTraversal ()
275 : blume 375 fun get n = let
276 : blume 399 val { ii, ctxt } = valOf (sbnode ginfo n)
277 :     val { statpid, statenv, symenv, sympid } = ii
278 :     (* We have not implemented the "sbnode" part
279 :     * in the Link module.
280 : blume 375 * But at boot time any relevant value should be
281 : blume 399 * available as a sysval, so there is no problem.
282 :     *
283 :     * WARNING! HACK!
284 :     * We are cheating somewhat by taking advantage
285 :     * of the fact that the staticPid is always
286 :     * the same as the exportPid if the latter exists.
287 :     *)
288 :     val d = case Link.sysval (SOME statpid) of
289 :     SOME d => d
290 :     | NONE => emptydyn
291 :     val env = E.mkenv { static = statenv (),
292 :     symbolic = symenv (),
293 : blume 375 dynamic = d }
294 : blume 399 val pidInfo = { statpid = statpid,
295 :     sympid = sympid,
296 : blume 375 ctxt = ctxt }
297 :     in
298 :     (env, pidInfo)
299 :     end
300 :     fun getPspec (name, n) = let
301 :     val (env, pidInfo) = get n
302 :     in
303 :     { name = name, env = env, pidInfo = pidInfo }
304 :     end
305 :    
306 :     val (core, corePidInfo) = get core
307 :     val corenv = CoerceEnv.es2bs (E.staticPart core)
308 :     val (rts, _) = get rts
309 :     val (pervasive0, pervPidInfo) = get pervasive
310 :     val pspecs = map getPspec primitives
311 :     val core_symdyn =
312 :     E.mkenv { static = E.staticPart E.emptyEnv,
313 :     dynamic = E.dynamicPart core,
314 :     symbolic = E.symbolicPart core }
315 :     val pervasive = E.layerEnv (pervasive0, core_symdyn)
316 :     val pervcorepids =
317 :     PidSet.addList (PidSet.empty,
318 :     [#statpid corePidInfo,
319 :     #statpid pervPidInfo,
320 :     #sympid pervPidInfo])
321 :     in
322 : blume 399 Compile.reset ();
323 :     Link.reset ();
324 : blume 375 #set ER.core corenv;
325 :     #set ER.pervasive pervasive;
326 :     #set ER.topLevel BE.emptyEnv;
327 :     theValues :=
328 :     SOME { primconf = Primitive.configuration pspecs,
329 :     pervasive = pervasive,
330 :     corenv = corenv,
331 :     pervcorepids = pervcorepids };
332 :     case er of
333 :     BARE =>
334 :     (make "basis.cm";
335 :     make "host-compiler.cm";
336 :     system_values := emptydyn)
337 :     | AUTOLOAD =>
338 :     (HostMachDepVC.Interact.installCompManager
339 :     (SOME al_manager');
340 :     autoload "basis.cm";
341 :     autoload "host-cm.cm";
342 :     CmHook.init
343 :     { stabilize = stabilize,
344 :     recomp = recomp,
345 :     make = make,
346 :     autoload = autoload,
347 :     reset = reset,
348 :     verbose =
349 :     EnvConfig.getSet StdConfig.verbose,
350 :     debug =
351 :     EnvConfig.getSet StdConfig.debug,
352 :     keep_going =
353 :     EnvConfig.getSet StdConfig.keep_going,
354 : blume 397 warn_obsolete =
355 :     EnvConfig.getSet StdConfig.warn_obsolete,
356 : blume 375 parse_caching =
357 :     EnvConfig.getSet StdConfig.parse_caching,
358 :     setAnchor = setAnchor,
359 :     cancelAnchor = cancelAnchor,
360 :     resetPathConfig = resetPathConfig,
361 :     synchronize = SrcPath.sync,
362 :     showPending = showPending })
363 :    
364 :     end
365 :     end
366 :     end
367 :     in
368 :     fun init (bootdir, de, er) =
369 :     (system_values := de;
370 :     initTheValues (bootdir, er);
371 :     Cleanup.install initPaths)
372 :     end
373 :     end

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