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

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