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

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