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/cm-boot.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/cm-boot.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 362 - (view) (download)

1 : blume 360 functor LinkCM (structure HostMachDepVC : MACHDEP_VC) = struct
2 :    
3 : blume 362 datatype envrequest = AUTOLOAD | BARE
4 :    
5 : blume 360 local
6 :     structure YaccTool = YaccTool
7 :     structure LexTool = LexTool
8 :     structure BurgTool = BurgTool
9 :    
10 :     structure E = GenericVC.Environment
11 :     structure SE = GenericVC.StaticEnv
12 :     structure ER = GenericVC.EnvRef
13 :     structure BE = GenericVC.BareEnvironment
14 :     structure CMSE = GenericVC.CMStaticEnv
15 :     structure S = GenericVC.Symbol
16 :     structure CoerceEnv = GenericVC.CoerceEnv
17 :     structure EM = GenericVC.ErrorMsg
18 :    
19 :     val os = SMLofNJ.SysInfo.getOSKind ()
20 :    
21 :     structure SSV =
22 :     SpecificSymValFn (structure MachDepVC = HostMachDepVC
23 :     val os = os)
24 :    
25 : blume 362 val emptydyn = E.dynamicPart E.emptyEnv
26 :     val system_values = ref emptydyn
27 : blume 360
28 :     (* Instantiate the persistent state functor; this includes
29 :     * the binfile cache and the dynamic value cache *)
30 :     structure FullPersstate =
31 :     FullPersstateFn (structure MachDepVC = HostMachDepVC
32 : blume 362 val system_values = system_values)
33 : blume 360
34 :     (* Create two arguments appropriate for being passed to
35 :     * CompileGenericFn. One instantiation of that functor
36 :     * is responsible for "recompile" traversals, the other one
37 :     * does "link" traversals. Notice how the two share the same
38 :     * underlying state. *)
39 :     structure Recomp = RecompFn (structure PS = FullPersstate)
40 :     structure Exec = ExecFn (structure PS = FullPersstate)
41 :    
42 :     (* make the two traversals *)
43 :     structure RT = CompileGenericFn (structure CT = Recomp)
44 :     structure ET = CompileGenericFn (structure CT = Exec)
45 :    
46 :     (* The StabilizeFn functor needs a way of converting bnodes to
47 :     * dependency-analysis environments. This can be achieved quite
48 :     * conveniently by a "recompile" traversal for bnodes. *)
49 :     fun bn2statenv gp i = #1 (#stat (valOf (RT.bnode gp i)))
50 :     handle Option => raise Fail "bn2statenv"
51 :    
52 :     (* exec_group is basically the same as ET.group with
53 :     * two additional actions to be taken:
54 :     * 1. Before executing the code, we announce the priviliges
55 :     * that are being invoked. (For the time being, we assume
56 :     * that everybody has every conceivable privilege, but at the
57 :     * very least we announce which ones are being made use of.)
58 :     * 2. After we are done we must make the values of "shared"
59 :     * compilation units permanent. *)
60 :     fun exec_group gp (g as GroupGraph.GROUP { required = rq, ... }) =
61 :     (if StringSet.isEmpty rq then ()
62 :     else Say.say ("$Execute: required privileges are:\n" ::
63 :     map (fn s => (" " ^ s ^ "\n")) (StringSet.listItems rq));
64 :     ET.group gp g
65 :     before FullPersstate.rememberShared ())
66 :    
67 :     fun recomp_runner gp g = isSome (RT.group gp g)
68 :    
69 :     (* This function combines the actions of "recompile" and "exec".
70 :     * When successful, it combines the results (thus forming a full
71 :     * environment) and adds it to the toplevel environment. *)
72 :     fun make_runner gp g =
73 :     case RT.group gp g of
74 :     NONE => false
75 :     | SOME { stat, sym} =>
76 :     (case exec_group gp g of
77 :     NONE => false
78 :     | SOME dyn => let
79 :     val delta = E.mkenv { static = stat, symbolic = sym,
80 :     dynamic = dyn }
81 :     val base = #get ER.topLevel ()
82 :     val new = BE.concatEnv (CoerceEnv.e2b delta, base)
83 :     in
84 :     #set ER.topLevel new;
85 :     Say.vsay ["[New bindings added.]\n"];
86 :     true
87 :     end)
88 :    
89 :     fun al_loadit gp m =
90 :     case RT.impexpmap gp m of
91 :     NONE => NONE
92 :     | SOME { stat, sym } => let
93 :     fun exec () =
94 :     ET.impexpmap gp m
95 :     before FullPersstate.rememberShared ()
96 :     in
97 :     case exec () of
98 :     NONE => NONE
99 :     | SOME dyn => let
100 :     val e = E.mkenv { static = stat, symbolic = sym,
101 :     dynamic =dyn }
102 :     val be = GenericVC.CoerceEnv.e2b e
103 :     in
104 :     SOME be
105 :     end
106 :     end
107 :    
108 :     val al_greg = GroupReg.new ()
109 :    
110 :     (* Instantiate the stabilization mechanism. *)
111 :     structure Stabilize =
112 :     StabilizeFn (val bn2statenv = bn2statenv
113 :     val getPid = FullPersstate.pid_fetch_sml
114 :     val recomp = recomp_runner)
115 :    
116 :     (* Access to the stabilization mechanism is integrated into the
117 :     * parser. I'm not sure if this is the cleanest way, but it works
118 :     * well enough. *)
119 : blume 362 structure Parse = ParseFn (structure Stabilize = Stabilize
120 :     val pending = AutoLoad.getPending)
121 : blume 360
122 :     local
123 :     type kernelValues =
124 :     { primconf : Primitive.configuration,
125 :     pervasive : E.environment,
126 :     corenv : BE.staticEnv,
127 :     pervcorepids : PidSet.set }
128 :    
129 :     val fnpolicy = FilenamePolicy.colocate
130 :     { os = os, arch = HostMachDepVC.architecture }
131 :    
132 : blume 361 val pcmode = PathConfig.new ()
133 : blume 360
134 :     val theValues = ref (NONE: kernelValues option)
135 :    
136 :     in
137 : blume 361 fun initPaths () = let
138 :     val p =
139 :     case OS.Process.getEnv "HOME" of
140 :     NONE => []
141 :     | SOME h => [OS.Path.concat (h, ".smlnj-pathconfig")]
142 :     val p = EnvConfig.getSet StdConfig.pathcfgspec NONE :: p
143 :     fun processOne f = PathConfig.processSpecFile (pcmode, f)
144 :     handle _ => ()
145 :     in
146 :     app processOne p
147 :     end
148 :    
149 : blume 360 fun param () = let
150 :     val v = valOf (!theValues)
151 :     handle Option =>
152 :     raise Fail "CMBoot: theParam not initialized"
153 :     in
154 :     { primconf = #primconf v,
155 :     fnpolicy = fnpolicy,
156 : blume 361 pcmode = pcmode,
157 : blume 360 symenv = SSV.env,
158 :     keep_going = EnvConfig.getSet StdConfig.keep_going NONE,
159 :     pervasive = #pervasive v,
160 :     corenv = #corenv v,
161 :     pervcorepids = #pervcorepids v }
162 :     end
163 :    
164 :     fun autoload s = let
165 :     val c = SrcPath.cwdContext ()
166 :     val p = SrcPath.standard pcmode { context = c, spec = s }
167 :     in
168 :     case Parse.parse (SOME al_greg) (param ()) NONE p of
169 :     NONE => false
170 :     | SOME (g, _) =>
171 :     (AutoLoad.register (GenericVC.EnvRef.topLevel, g);
172 :     true)
173 :     end
174 :    
175 :     fun al_ginfo () = { param = param (),
176 :     groupreg = al_greg,
177 :     errcons = EM.defaultConsumer () }
178 :    
179 :     val al_manager =
180 :     AutoLoad.mkManager (fn m => al_loadit (al_ginfo ()) m)
181 :    
182 :     fun al_manager' (ast, _, ter) = al_manager (ast, ter)
183 :    
184 : blume 362 fun run sflag f s = let
185 :     val c = SrcPath.cwdContext ()
186 :     val p = SrcPath.standard pcmode { context = c, spec = s }
187 :     in
188 :     case Parse.parse NONE (param ()) sflag p of
189 :     NONE => false
190 :     | SOME (g, gp) => f gp g
191 :     end
192 :    
193 :     fun stabilize_runner gp g = true
194 :    
195 :     fun stabilize recursively = run (SOME recursively) stabilize_runner
196 :     val recomp = run NONE recomp_runner
197 :     val make = run NONE make_runner
198 :    
199 :     fun reset () =
200 :     (FullPersstate.reset ();
201 :     RT.resetAll ();
202 :     ET.resetAll ();
203 :     Recomp.reset ();
204 :     Exec.reset ();
205 :     AutoLoad.reset ();
206 :     SmlInfo.forgetAllBut SrcPathSet.empty)
207 :    
208 :     fun initTheValues (bootdir, er) = let
209 : blume 361 val _ = let
210 :     fun listDir ds = let
211 :     fun loop l =
212 :     case OS.FileSys.readDir ds of
213 :     "" => l
214 :     | x => loop (x :: l)
215 :     in
216 :     loop []
217 :     end
218 :     val fileList = SafeIO.perform
219 :     { openIt = fn () => OS.FileSys.openDir bootdir,
220 :     closeIt = OS.FileSys.closeDir,
221 :     work = listDir,
222 :     cleanup = fn () => () }
223 :     fun isDir x =
224 :     OS.FileSys.isDir x handle _ => false
225 :     fun subDir x = let
226 :     val d = OS.Path.concat (bootdir, x)
227 :     in
228 :     if isDir d then SOME (x, d) else NONE
229 :     end
230 :     val pairList = List.mapPartial subDir fileList
231 :     in
232 :     app (fn (x, d) => PathConfig.set (pcmode, x, d)) pairList
233 :     end
234 : blume 360 val initgspec =
235 :     SrcPath.standard pcmode { context = SrcPath.cwdContext (),
236 :     spec = BtNames.initgspec }
237 :     val ginfo = { param = { primconf = Primitive.primEnvConf,
238 :     fnpolicy = fnpolicy,
239 :     pcmode = pcmode,
240 :     symenv = SSV.env,
241 :     keep_going = false,
242 :     pervasive = E.emptyEnv,
243 :     corenv = BE.staticPart BE.emptyEnv,
244 :     pervcorepids = PidSet.empty },
245 :     groupreg = GroupReg.new (),
246 :     errcons = EM.defaultConsumer () }
247 :     in
248 :     case BuildInitDG.build ginfo initgspec of
249 :     NONE => raise Fail "CMBoot: BuiltInitDG.build"
250 :     | SOME { rts, core, pervasive, primitives, ... } => let
251 :     fun get n = let
252 :     val { stat = (s, sp), sym = (sy, syp), ctxt } =
253 :     valOf (RT.sbnode ginfo n)
254 :     val d = Exec.env2result (valOf (ET.sbnode ginfo n))
255 :     val env = E.mkenv { static = s, symbolic = sy,
256 :     dynamic = d }
257 :     val pidInfo = { statpid = sp, sympid = syp,
258 :     ctxt = ctxt }
259 :     in
260 :     (env, pidInfo)
261 :     end
262 :     fun getPspec (name, n) = let
263 :     val (env, pidInfo) = get n
264 :     in
265 :     { name = name, env = env, pidInfo = pidInfo }
266 :     end
267 :    
268 :     val (core, corePidInfo) = get core
269 :     val corenv = CoerceEnv.es2bs (E.staticPart core)
270 :     val (rts, _) = get rts
271 :     val (pervasive0, pervPidInfo) = get pervasive
272 :     val pspecs = map getPspec primitives
273 :     val core_symdyn =
274 :     E.mkenv { static = E.staticPart E.emptyEnv,
275 :     dynamic = E.dynamicPart core,
276 :     symbolic = E.symbolicPart core }
277 :     val pervasive = E.layerEnv (pervasive0, core_symdyn)
278 :     val pervcorepids =
279 :     PidSet.addList (PidSet.empty,
280 :     [#statpid corePidInfo,
281 :     #statpid pervPidInfo,
282 :     #sympid pervPidInfo])
283 :     in
284 :     #set ER.core corenv;
285 :     #set ER.pervasive pervasive;
286 :     #set ER.topLevel BE.emptyEnv;
287 :     theValues :=
288 :     SOME { primconf = Primitive.configuration pspecs,
289 :     pervasive = pervasive,
290 :     corenv = corenv,
291 :     pervcorepids = pervcorepids };
292 : blume 362 case er of
293 :     BARE =>
294 :     (make "basis.cm";
295 :     make "host-compiler.cm";
296 :     system_values := emptydyn)
297 :     | AUTOLOAD =>
298 :     (HostMachDepVC.Interact.installCompManager
299 :     (SOME al_manager');
300 :     autoload "basis.cm";
301 :     AutoLoadHook.autoloadHook := autoload)
302 : blume 360 end
303 :     end
304 :     end
305 :     in
306 :     structure CM = struct
307 : blume 362 val stabilize = stabilize
308 :     val recomp = recomp
309 :     val make = make
310 : blume 360 val autoload = autoload
311 : blume 362 val reset = reset
312 : blume 360 end
313 :    
314 : blume 362 fun init (bootdir, de, er) =
315 :     (system_values := de;
316 :     initTheValues (bootdir, er);
317 : blume 361 Cleanup.install initPaths)
318 : blume 360 end
319 :     end

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