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/stable/stabilize.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/stable/stabilize.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 505 - (view) (download)

1 : blume 309 (*
2 :     * Reading, generating, and writing stable groups.
3 :     *
4 :     * (C) 1999 Lucent Technologies, Bell Laboratories
5 :     *
6 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7 :     *)
8 :     local
9 : blume 304 structure DG = DependencyGraph
10 : blume 306 structure GG = GroupGraph
11 :     structure EM = GenericVC.ErrorMsg
12 : blume 311 structure PP = PrettyPrint
13 :     structure SM = GenericVC.SourceMap
14 : blume 309 structure GP = GeneralParams
15 :     structure E = GenericVC.Environment
16 : blume 357 structure Pid = GenericVC.PersStamps
17 : blume 398 structure P = PickMod
18 :     structure UP = UnpickMod
19 :     structure E = GenericVC.Environment
20 : blume 309 in
21 : blume 304
22 : blume 309 signature STABILIZE = sig
23 :    
24 :     val loadStable :
25 : blume 398 GP.info -> { getGroup: SrcPath.t -> GG.group option,
26 :     anyerrors: bool ref }
27 :     -> SrcPath.t -> GG.group option
28 : blume 309
29 :     val stabilize :
30 : blume 398 GP.info -> { group: GG.group, anyerrors: bool ref } -> GG.group option
31 : blume 309 end
32 :    
33 : blume 403 functor StabilizeFn (val destroy_state : GP.info -> SmlInfo.info -> unit
34 :     structure MachDepVC : MACHDEP_VC
35 :     val recomp : GP.info -> GG.group ->
36 :     (SmlInfo.info -> MachDepVC.Binfile.bfContent) option
37 :     val getII : SmlInfo.info -> IInfo.info) :> STABILIZE =
38 :     struct
39 : blume 309
40 : blume 403 structure BF = MachDepVC.Binfile
41 :    
42 : blume 447 structure SSMap = MapFn
43 : blume 385 (struct
44 :     type ord_key = SymbolSet.set
45 :     val compare = SymbolSet.compare
46 :     end)
47 :    
48 : blume 447 structure SNMap = MapFn
49 : blume 384 (struct
50 :     type ord_key = DG.snode
51 :     fun compare (DG.SNODE n, DG.SNODE n') =
52 :     SmlInfo.compare (#smlinfo n, #smlinfo n')
53 : blume 304 end)
54 :    
55 : blume 398 structure PU = PickleUtil
56 :     structure UU = UnpickleUtil
57 : blume 384
58 : blume 398 type map = { ss: PU.id SSMap.map, sn: PU.id SNMap.map, pm: P.map }
59 : blume 393
60 : blume 398 val emptyMap = { ss = SSMap.empty, sn = SNMap.empty, pm = P.emptyMap }
61 : blume 393
62 : blume 398 val lifter =
63 :     { extract = fn (m: map) => #pm m,
64 :     patchback = fn (m: map, pm) => { ss = #ss m, sn = #sn m, pm = pm } }
65 :    
66 : blume 393 infix 3 $
67 :     infixr 4 &
68 :     val op & = PU.&
69 :     val % = PU.%
70 :    
71 :     (* type info *)
72 :     val (BN, SN, SBN, SS, SI, FSBN, IMPEXP, SHM) = (1, 2, 3, 4, 5, 6, 7, 8)
73 :    
74 : blume 398 val SSs =
75 :     { find = fn (m: map, k) => SSMap.find (#ss m, k),
76 :     insert = fn ({ ss, sn, pm }, k, v) =>
77 :     { sn = sn, ss = SSMap.insert (ss, k, v), pm = pm } }
78 :     val SNs =
79 :     { find = fn (m: map, k) => SNMap.find (#sn m, k),
80 :     insert = fn ({ ss, sn, pm }, k, v) =>
81 :     { ss = ss, sn = SNMap.insert (sn, k, v), pm = pm } }
82 : blume 385
83 : blume 505 fun fetch_pickle s = let
84 :     fun bytesIn n = let
85 :     val bv = BinIO.inputN (s, n)
86 :     in
87 :     if n = Word8Vector.length bv then bv
88 :     else raise UU.Format
89 :     end
90 :    
91 :     val dg_sz = LargeWord.toIntX (Pack32Big.subVec (bytesIn 4, 0))
92 :     val dg_pickle = Byte.bytesToString (bytesIn dg_sz)
93 :     in
94 :     { size = dg_sz, pickle = dg_pickle }
95 :     end
96 :    
97 :     fun mkPickleFetcher mksname () =
98 :     SafeIO.perform { openIt = BinIO.openIn o mksname,
99 :     closeIt = BinIO.closeIn,
100 :     work = #pickle o fetch_pickle,
101 :     cleanup = fn _ => () }
102 :    
103 : blume 311 fun stabilize gp { group = g as GG.GROUP grec, anyerrors } = let
104 : blume 304
105 : blume 323 val primconf = #primconf (#param gp)
106 :     val policy = #fnpolicy (#param gp)
107 : blume 398 val pervasive = #pervasive (#param gp)
108 : blume 323
109 : blume 340 val grouppath = #grouppath grec
110 :    
111 : blume 403 fun doit (wrapped, getBFC) = let
112 : blume 312
113 : blume 403 fun writeBFC s i = BF.write { stream = s,
114 :     content = getBFC i,
115 :     nopickle = true }
116 :     fun sizeBFC i = BF.size { content = getBFC i, nopickle = true }
117 :    
118 : blume 314 val _ =
119 : blume 403 Say.vsay ["[stabilizing ", SrcPath.descr grouppath, "]\n"]
120 :    
121 :     val _ =
122 : blume 348 if StringSet.isEmpty wrapped then ()
123 : blume 314 else
124 :     Say.say ("$Stabilize: wrapping the following privileges:\n"
125 : blume 312 :: map (fn s => (" " ^ s ^ "\n"))
126 : blume 348 (StringSet.listItems wrapped))
127 : blume 312
128 : blume 311 val grpSrcInfo = (#errcons gp, anyerrors)
129 : blume 308
130 : blume 311 val exports = #exports grec
131 : blume 348 val required = StringSet.difference (#required grec, wrapped)
132 : blume 340 val sublibs = #sublibs grec
133 : blume 304
134 : blume 311 (* The format of a stable archive is the following:
135 :     * - It starts with the size s of the pickled dependency
136 :     * graph. This size itself is written as four-byte string.
137 : blume 398 * - The size t of the pickled environment for the entire
138 :     * library (using the pickleEnvN interface of the pickler)
139 :     * in the same format as s.
140 : blume 311 * - The pickled dependency graph. This graph contains
141 :     * integer offsets of the binfiles for the individual ML
142 :     * members. These offsets need to be adjusted by adding
143 : blume 398 * s + t + 8. The pickled dependency graph also contains integer
144 : blume 311 * offsets relative to other stable groups. These offsets
145 :     * need no further adjustment.
146 : blume 398 * - Individual binfile contents (concatenated) but without
147 :     * their static environments.
148 : blume 311 *)
149 : blume 304
150 : blume 340 (* Here we build a mapping that maps each BNODE to a number
151 :     * representing the sub-library that it came from and a
152 :     * representative symbol that can be used to find the BNODE
153 :     * within the exports of that library *)
154 : blume 398 fun oneB i (sy, ((_, DG.SB_BNODE (DG.BNODE n, _)), _), m) =
155 : blume 340 StableMap.insert (m, #bininfo n, (i, sy))
156 :     | oneB i (_, _, m) = m
157 : blume 444 fun oneSL ((_, g as GG.GROUP { exports, ... }), (m, i)) =
158 : blume 340 (SymbolMap.foldli (oneB i) m exports, i + 1)
159 :     val inverseMap = #1 (foldl oneSL (StableMap.empty, 0) sublibs)
160 : blume 330
161 : blume 311 val members = ref []
162 :     val (registerOffset, getOffset) = let
163 :     val dict = ref SmlInfoMap.empty
164 :     val cur = ref 0
165 :     fun reg (i, sz) = let
166 :     val os = !cur
167 : blume 306 in
168 : blume 311 cur := os + sz;
169 :     dict := SmlInfoMap.insert (!dict, i, os);
170 :     members := i :: (!members);
171 :     os
172 : blume 306 end
173 : blume 311 fun get i = valOf (SmlInfoMap.find (!dict, i))
174 :     in
175 :     (reg, get)
176 :     end
177 : blume 304
178 : blume 398 (* Collect all BNODEs and PNODEs that we see and build
179 :     * a context suitable for P.envPickler. *)
180 :     fun mkContext () = let
181 :     fun lst f [] k s = k s
182 :     | lst f (h :: t) k s = f h (lst f t k) s
183 :    
184 :     fun sbn n k (s as (prims, bnodes, snodes)) =
185 :     case n of
186 :     DG.SB_BNODE (DG.PNODE p, { statenv, ... }) => let
187 :     val str = String.str (Primitive.toIdent primconf p)
188 : blume 461 val prims' =
189 :     StringMap.insert (prims, str, #env o statenv)
190 : blume 398 in
191 :     k (prims', bnodes, snodes)
192 :     end
193 :     | DG.SB_BNODE (DG.BNODE { bininfo = i, ... }, ii) => let
194 :     val { statenv, ... } = ii
195 :     val nsy = valOf (StableMap.find (inverseMap, i))
196 :     val bnodes' =
197 : blume 461 StableMap.insert (bnodes, i,
198 :     (nsy, #env o statenv))
199 : blume 398 in
200 :     k (prims, bnodes', snodes)
201 :     end
202 :     | DG.SB_SNODE n => sn n k s
203 :    
204 :     and sn (DG.SNODE n) k (prims, bnodes, snodes) = let
205 :     val i = #smlinfo n
206 :     val li = #localimports n
207 :     val gi = #globalimports n
208 :     in
209 :     if SmlInfoSet.member (snodes, i) then
210 :     k (prims, bnodes, snodes)
211 :     else let
212 :     val snodes' = SmlInfoSet.add (snodes, i)
213 :     in
214 :     lst sn li (lst fsbn gi k) (prims, bnodes, snodes')
215 :     end
216 :     end
217 :    
218 :     and fsbn (_, n) k s = sbn n k s
219 :    
220 :     fun impexp (n, _) k s = fsbn n k s
221 :    
222 :     val (prims, bnodes) =
223 :     lst impexp (SymbolMap.listItems exports)
224 :     (fn (prims, bnodes, _) => (prims, bnodes))
225 :     (StringMap.empty, StableMap.empty, SmlInfoSet.empty)
226 :    
227 :     val priml = StringMap.listItemsi prims
228 :     val bnodel = StableMap.listItems bnodes
229 :    
230 :     fun cvt lk id = let
231 :     fun nloop [] = NONE
232 :     | nloop ((k, ge) :: t) =
233 :     (case lk (ge ()) id of
234 :     SOME _ => SOME (P.NodeKey k)
235 :     | NONE => nloop t)
236 :     fun ploop [] = nloop bnodel
237 :     | ploop ((k, ge) :: t) =
238 :     (case lk (ge ()) id of
239 :     SOME _ => SOME (P.PrimKey k)
240 :     | NONE => ploop t)
241 :     in
242 :     case lk (E.staticPart pervasive) id of
243 :     NONE => ploop priml
244 :     | SOME _ => SOME (P.PrimKey "pv")
245 :     end
246 :     in
247 :     { lookSTR = cvt GenericVC.CMStaticEnv.lookSTR,
248 :     lookSIG = cvt GenericVC.CMStaticEnv.lookSIG,
249 :     lookFCT = cvt GenericVC.CMStaticEnv.lookFCT,
250 :     lookFSIG = cvt GenericVC.CMStaticEnv.lookFSIG,
251 :     lookTYC = cvt GenericVC.CMStaticEnv.lookTYC,
252 :     lookEENV = cvt GenericVC.CMStaticEnv.lookEENV }
253 :     end
254 :    
255 :     (* make the picklers for static and symbolic environments;
256 :     * lift them so we can use them here... *)
257 :     val envContext = mkContext ()
258 : blume 403
259 : blume 398 val env_orig = P.envPickler envContext
260 :     val env = PU.lift_pickler lifter env_orig
261 :     val symenv_orig = P.symenvPickler
262 :     val symenv = PU.lift_pickler lifter symenv_orig
263 :     val lazy_env = PU.w_lazy env
264 :     val lazy_symenv = PU.w_lazy symenv
265 :    
266 : blume 384 val int = PU.w_int
267 : blume 398 val symbol = PickleSymPid.w_symbol
268 :     val pid = PickleSymPid.w_pid
269 : blume 384 val share = PU.ah_share
270 :     val option = PU.w_option
271 :     val list = PU.w_list
272 :     val string = PU.w_string
273 :     val bool = PU.w_bool
274 :     val int = PU.w_int
275 : blume 304
276 : blume 385 fun symbolset ss = let
277 :     val op $ = PU.$ SS
278 :     fun raw_ss ss = "s" $ list symbol (SymbolSet.listItems ss)
279 :     in
280 :     share SSs raw_ss ss
281 :     end
282 : blume 304
283 : blume 384 val filter = option symbolset
284 : blume 304
285 : blume 387 fun shm (Sharing.SHARE true) = %SHM "a"
286 :     | shm (Sharing.SHARE false) = %SHM "b"
287 :     | shm Sharing.DONTSHARE = %SHM "c"
288 : blume 304
289 : blume 384 fun si i = let
290 : blume 340 (* FIXME: this is not a technical flaw, but perhaps one
291 :     * that deserves fixing anyway: If we only look at spec,
292 :     * then we are losing information about sub-grouping
293 :     * within libraries. However, the spec in BinInfo.info
294 :     * is only used for diagnostics and has no impact on the
295 :     * operation of CM itself. *)
296 : blume 354 val spec = SrcPath.specOf (SmlInfo.sourcepath i)
297 : blume 311 val locs = SmlInfo.errorLocation gp i
298 : blume 398 val offset = registerOffset (i, sizeBFC i)
299 : blume 387 val sh_mode = SmlInfo.sh_mode i
300 : blume 385 val op $ = PU.$ SI
301 : blume 311 in
302 : blume 387 "s" $ string spec & string locs & int offset & shm sh_mode
303 : blume 311 end
304 : blume 306
305 : blume 384 fun primitive p =
306 :     string (String.str (Primitive.toIdent primconf p))
307 : blume 306
308 : blume 340 fun warn_relabs p abs = let
309 :     val relabs = if abs then "absolute" else "relative"
310 : blume 330 fun ppb pps =
311 :     (PP.add_newline pps;
312 : blume 354 PP.add_string pps (SrcPath.descr p);
313 : blume 330 PP.add_newline pps;
314 :     PP.add_string pps
315 :     "(This means that in order to be able to use the result of stabilization";
316 :     PP.add_newline pps;
317 : blume 340 PP.add_string pps "the library must be in the same ";
318 : blume 330 PP.add_string pps relabs;
319 :     PP.add_string pps " location as it is now.)";
320 :     PP.add_newline pps)
321 :     in
322 :     EM.errorNoFile (#errcons gp, anyerrors) SM.nullRegion
323 :     EM.WARN
324 : blume 354 (concat [SrcPath.descr grouppath,
325 : blume 340 ": library referred to by ", relabs,
326 :     " pathname:"])
327 : blume 330 ppb
328 :     end
329 : blume 306
330 : blume 384 fun abspath p = let
331 :     val pp = SrcPath.pickle (warn_relabs p) (p, grouppath)
332 :     in
333 :     list string pp
334 :     end
335 : blume 306
336 : blume 385 fun sn n = let
337 : blume 398 val op $ = PU.$ SN
338 : blume 385 fun raw_sn (DG.SNODE n) =
339 :     "a" $ si (#smlinfo n) & list sn (#localimports n) &
340 :     list fsbn (#globalimports n)
341 : blume 384 in
342 : blume 385 share SNs raw_sn n
343 :     end
344 : blume 306
345 : blume 398 (* Here we ignore the interface info because we will not
346 :     * need it anymore when we unpickle. *)
347 : blume 385 and sbn x = let
348 :     val op $ = PU.$ SBN
349 :     in
350 :     case x of
351 : blume 398 DG.SB_BNODE (DG.PNODE p, { statenv = getE, ... }) =>
352 :     "1" $ primitive p
353 :     | DG.SB_BNODE (DG.BNODE { bininfo = i, ... }, _) => let
354 :     val (n, sy) = valOf (StableMap.find (inverseMap, i))
355 :     in
356 :     "2" $ int n & symbol sy
357 :     end
358 :     | DG.SB_SNODE n => "3" $ sn n
359 : blume 385 end
360 :    
361 :     and fsbn (f, n) = let
362 :     val op $ = PU.$ FSBN
363 :     in
364 :     "f" $ filter f & sbn n
365 :     end
366 : blume 370
367 : blume 398 (* Here is the place where we need to write interface info. *)
368 : blume 385 fun impexp (s, (n, _)) = let
369 :     val op $ = PU.$ IMPEXP
370 : blume 398 val { statenv, symenv, statpid, sympid } =
371 :     case n of
372 :     (_, DG.SB_BNODE (_, ii)) => ii
373 :     | (_, DG.SB_SNODE (DG.SNODE { smlinfo, ... })) =>
374 :     getII smlinfo
375 : blume 461 fun es2bs { env, ctxt } =
376 :     { env = GenericVC.CoerceEnv.es2bs env, ctxt = ctxt }
377 : blume 385 in
378 : blume 398 "i" $ symbol s & fsbn n &
379 : blume 461 lazy_env (es2bs o statenv) &
380 : blume 398 lazy_symenv symenv &
381 :     pid statpid &
382 :     pid sympid
383 : blume 384 end
384 : blume 307
385 : blume 384 fun w_exports e = list impexp (SymbolMap.listItemsi e)
386 : blume 306
387 : blume 384 fun privileges p = list string (StringSet.listItems p)
388 : blume 306
389 : blume 384 fun group () = let
390 : blume 444 fun sg (p, g) = abspath p
391 : blume 311 in
392 : blume 340 (* Pickle the sublibs first because we need to already
393 : blume 330 * have them back when we unpickle BNODEs. *)
394 : blume 384 list sg sublibs & w_exports exports & privileges required
395 : blume 311 end
396 : blume 308
397 : blume 398 val dg_pickle =
398 :     Byte.stringToBytes (PU.pickle emptyMap (group ()))
399 : blume 403
400 : blume 398 val dg_sz = Word8Vector.length dg_pickle
401 : blume 308
402 : blume 398 val offset_adjustment = dg_sz + 4
403 :    
404 : blume 361 fun mkStableGroup mksname = let
405 : blume 311 val m = ref SmlInfoMap.empty
406 :     fun sn (DG.SNODE (n as { smlinfo, ... })) =
407 :     case SmlInfoMap.find (!m, smlinfo) of
408 :     SOME n => n
409 :     | NONE => let
410 : blume 371 val li = map sn (#localimports n)
411 :     val gi = map fsbn (#globalimports n)
412 : blume 311 val sourcepath = SmlInfo.sourcepath smlinfo
413 : blume 340 (* FIXME: see the comment near the other
414 : blume 354 * occurence of SrcPath.spec... *)
415 :     val spec = SrcPath.specOf sourcepath
416 : blume 311 val offset =
417 :     getOffset smlinfo + offset_adjustment
418 : blume 387 val sh_mode = SmlInfo.sh_mode smlinfo
419 : blume 311 val locs = SmlInfo.errorLocation gp smlinfo
420 :     val error = EM.errorNoSource grpSrcInfo locs
421 :     val i = BinInfo.new { group = grouppath,
422 : blume 361 mkStablename = mksname,
423 : blume 311 spec = spec,
424 :     offset = offset,
425 : blume 387 sh_mode = sh_mode,
426 : blume 311 error = error }
427 :     val n = DG.BNODE { bininfo = i,
428 :     localimports = li,
429 :     globalimports = gi }
430 :     in
431 :     m := SmlInfoMap.insert (!m, smlinfo, n);
432 :     n
433 :     end
434 : blume 308
435 : blume 398 and sbn (DG.SB_SNODE (n as DG.SNODE { smlinfo = i, ... })) =
436 :     let val ii = getII i
437 :     in
438 :     (sn n, ii)
439 :     end
440 :     | sbn (DG.SB_BNODE (n, ii)) = (n, ii)
441 : blume 308
442 : blume 398 and fsbn (f, n) = (f, #1 (sbn n))
443 : blume 308
444 : blume 311 fun impexp ((f, n), e) = ((f, DG.SB_BNODE (sbn n)), e)
445 : blume 308
446 : blume 311 val exports = SymbolMap.map impexp (#exports grec)
447 :     in
448 : blume 426 SmlInfoMap.appi (fn (i, _) => destroy_state gp i) (!m);
449 : blume 311 GG.GROUP { exports = exports,
450 : blume 505 kind = GG.STABLELIB (fn () => ()),
451 : blume 311 required = required,
452 :     grouppath = grouppath,
453 : blume 348 sublibs = sublibs }
454 : blume 311 end
455 : blume 308
456 : blume 311 fun writeInt32 (s, i) = let
457 :     val a = Word8Array.array (4, 0w0)
458 :     val _ = Pack32Big.update (a, 0, LargeWord.fromInt i)
459 :     in
460 :     BinIO.output (s, Word8Array.extract (a, 0, NONE))
461 :     end
462 :     val memberlist = rev (!members)
463 :    
464 : blume 403 fun mksname () = FilenamePolicy.mkStableName policy grouppath
465 : blume 345 fun work outs =
466 : blume 403 (writeInt32 (outs, dg_sz);
467 : blume 398 BinIO.output (outs, dg_pickle);
468 :     app (writeBFC outs) memberlist;
469 : blume 361 mkStableGroup mksname)
470 : blume 311 in
471 : blume 361 SOME (SafeIO.perform { openIt = AutoDir.openBinOut o mksname,
472 : blume 345 closeIt = BinIO.closeOut,
473 :     work = work,
474 : blume 459 cleanup = fn _ =>
475 : blume 361 (OS.FileSys.remove (mksname ())
476 :     handle _ => ()) })
477 : blume 426 handle exn =>
478 :     (EM.errorNoFile (#errcons gp, anyerrors) SM.nullRegion
479 :     EM.COMPLAIN
480 :     (concat ["Exception raised while stabilizing ",
481 :     SrcPath.descr grouppath])
482 :     EM.nullErrorBody;
483 :     NONE)
484 : blume 311 end
485 :     in
486 : blume 348 case #kind grec of
487 : blume 505 GG.STABLELIB _ => SOME g
488 : blume 348 | GG.NOLIB => EM.impossible "stabilize: no library"
489 :     | GG.LIB wrapped =>
490 : blume 403 (case recomp gp g of
491 :     NONE => (anyerrors := true; NONE)
492 :     | SOME bfc_acc => let
493 : blume 444 fun notStable (_, GG.GROUP { kind, ... }) =
494 : blume 505 case kind of GG.STABLELIB _ => false | _ => true
495 : blume 403 in
496 : blume 340 case List.filter notStable (#sublibs grec) of
497 : blume 403 [] => doit (wrapped, bfc_acc)
498 : blume 311 | l => let
499 :     val grammar = case l of [_] => " is" | _ => "s are"
500 :     fun ppb pps = let
501 :     fun loop [] = ()
502 : blume 444 | loop ((p, _) :: t) =
503 :     (PP.add_string pps (SrcPath.descr p);
504 : blume 311 PP.add_newline pps;
505 :     loop t)
506 :     in
507 :     PP.add_newline pps;
508 :     PP.add_string pps
509 :     (concat ["because the following sub-group",
510 :     grammar, " not stable:"]);
511 :     PP.add_newline pps;
512 :     loop l
513 :     end
514 :     val errcons = #errcons gp
515 : blume 354 val gdescr = SrcPath.descr (#grouppath grec)
516 : blume 311 in
517 :     EM.errorNoFile (errcons, anyerrors) SM.nullRegion
518 :     EM.COMPLAIN
519 : blume 354 (gdescr ^ " cannot be stabilized")
520 : blume 311 ppb;
521 :     NONE
522 :     end
523 : blume 403 end)
524 : blume 311 end
525 : blume 310
526 : blume 398 fun loadStable gp { getGroup, anyerrors } group = let
527 : blume 306
528 : blume 398 val errcons = #errcons (gp: GeneralParams.info)
529 : blume 311 val grpSrcInfo = (errcons, anyerrors)
530 : blume 354 val gdescr = SrcPath.descr group
531 : blume 311 fun error l = EM.errorNoFile (errcons, anyerrors) SM.nullRegion
532 : blume 367 EM.COMPLAIN (concat ("(stable) " :: gdescr :: ": " :: l))
533 :     EM.nullErrorBody
534 : blume 309
535 : blume 384 exception Format = UU.Format
536 : blume 306
537 : blume 318 val pcmode = #pcmode (#param gp)
538 : blume 310 val policy = #fnpolicy (#param gp)
539 : blume 323 val primconf = #primconf (#param gp)
540 : blume 398 val pervasive = #pervasive (#param gp)
541 :    
542 : blume 361 fun mksname () = FilenamePolicy.mkStableName policy group
543 : blume 310
544 : blume 345 fun work s = let
545 : blume 310
546 : blume 345 fun getGroup' p =
547 :     case getGroup p of
548 :     SOME g => g
549 : blume 354 | NONE => (error ["unable to find ", SrcPath.descr p];
550 : blume 345 raise Format)
551 : blume 306
552 : blume 505 val { size = dg_sz, pickle = dg_pickle } = fetch_pickle s
553 : blume 398 val offset_adjustment = dg_sz + 4
554 : blume 505 val { getter, dropper } =
555 :     UU.stringGetter' (SOME dg_pickle, mkPickleFetcher mksname)
556 :     val session = UU.mkSession getter
557 : blume 345
558 : blume 398 fun list m r = UU.r_list session m r
559 :     val string = UU.r_string session
560 :     val stringListM = UU.mkMap ()
561 :     val stringlist = list stringListM string
562 : blume 304
563 : blume 398 fun abspath () =
564 :     SrcPath.unpickle pcmode (stringlist (), group)
565 :     handle SrcPath.Format => raise Format
566 :     | SrcPath.BadAnchor a =>
567 :     (error ["configuration anchor \"", a, "\" undefined"];
568 :     raise Format)
569 :    
570 : blume 444 fun sg () = let
571 :     val p = abspath ()
572 :     in
573 :     (p, getGroup' p)
574 :     end
575 : blume 398 val sgListM = UU.mkMap ()
576 :     val sublibs = list sgListM sg ()
577 :    
578 :     (* Now that we have the list of sublibs, we can build the
579 :     * environment for unpickling the environment list.
580 :     * We will need the environment list when unpickling the
581 :     * export list (making SB_BNODES). *)
582 :     fun prim_context "pv" = SOME (E.staticPart pervasive)
583 :     | prim_context s =
584 :     SOME (E.staticPart (Primitive.env primconf
585 :     (valOf (Primitive.fromIdent primconf
586 :     (String.sub (s, 0))))))
587 :     handle _ => NONE
588 :     fun node_context (n, sy) = let
589 : blume 444 val (_, GG.GROUP { exports = slexp, ... }) =
590 :     List.nth (sublibs, n)
591 : blume 398 in
592 :     case SymbolMap.find (slexp, sy) of
593 :     SOME ((_, DG.SB_BNODE (_, { statenv = ge, ... })), _) =>
594 : blume 461 SOME (#env (ge ()))
595 : blume 398 | _ => NONE
596 :     end handle _ => NONE
597 :    
598 :     val { symenv, env, symbol, symbollist } =
599 :     UP.mkUnpicklers session
600 :     { prim_context = prim_context,
601 :     node_context = node_context }
602 :    
603 :     val lazy_symenv = UU.r_lazy session symenv
604 :     val lazy_env = UU.r_lazy session env
605 :    
606 : blume 384 fun option m r = UU.r_option session m r
607 :     val int = UU.r_int session
608 :     fun share m r = UU.share session m r
609 : blume 387 fun nonshare r = UU.nonshare session r
610 : blume 384 val bool = UU.r_bool session
611 : blume 398 val pid = UnpickleSymPid.r_pid string
612 : blume 304
613 : blume 384 val stringListM = UU.mkMap ()
614 : blume 385 val ssM = UU.mkMap ()
615 : blume 384 val ssoM = UU.mkMap ()
616 :     val boolOptionM = UU.mkMap ()
617 : blume 385 val siM = UU.mkMap ()
618 : blume 384 val snM = UU.mkMap ()
619 :     val snListM = UU.mkMap ()
620 :     val sbnM = UU.mkMap ()
621 : blume 385 val fsbnM = UU.mkMap ()
622 : blume 384 val fsbnListM = UU.mkMap ()
623 : blume 385 val impexpM = UU.mkMap ()
624 : blume 384 val impexpListM = UU.mkMap ()
625 : blume 304
626 : blume 385 fun symbolset () = let
627 :     fun s #"s" = SymbolSet.addList (SymbolSet.empty, symbollist ())
628 :     | s _ = raise Format
629 :     in
630 :     share ssM s
631 :     end
632 : blume 305
633 : blume 384 val filter = option ssoM symbolset
634 : blume 305
635 : blume 384 fun primitive () =
636 :     valOf (Primitive.fromIdent primconf
637 :     (String.sub (string (), 0)))
638 :     handle _ => raise Format
639 : blume 305
640 : blume 387 fun shm () = let
641 :     fun s #"a" = Sharing.SHARE true
642 :     | s #"b" = Sharing.SHARE false
643 :     | s #"c" = Sharing.DONTSHARE
644 :     | s _ = raise Format
645 :     in
646 :     nonshare s
647 :     end
648 : blume 305
649 : blume 384 fun si () = let
650 : blume 385 fun s #"s" =
651 :     let val spec = string ()
652 :     val locs = string ()
653 :     val offset = int () + offset_adjustment
654 : blume 387 val sh_mode = shm ()
655 : blume 385 val error = EM.errorNoSource grpSrcInfo locs
656 :     in
657 :     BinInfo.new { group = group,
658 :     mkStablename = mksname,
659 :     error = error,
660 :     spec = spec,
661 :     offset = offset,
662 : blume 387 sh_mode = sh_mode }
663 : blume 385 end
664 :     | s _ = raise Format
665 : blume 345 in
666 : blume 385 share siM s
667 : blume 345 end
668 : blume 306
669 : blume 330 (* this is the place where what used to be an
670 :     * SNODE changes to a BNODE! *)
671 : blume 384 fun sn () = let
672 :     fun sn' #"a" =
673 :     DG.BNODE { bininfo = si (),
674 :     localimports = snlist (),
675 :     globalimports = fsbnlist () }
676 :     | sn' _ = raise Format
677 :     in
678 :     share snM sn'
679 :     end
680 : blume 306
681 : blume 384 and snlist () = list snListM sn ()
682 : blume 306
683 : blume 330 (* this one changes from farsbnode to plain farbnode *)
684 : blume 384 and sbn () = let
685 : blume 398 fun sbn' #"1" = DG.PNODE (primitive ())
686 :     | sbn' #"2" = let
687 :     val n = int ()
688 :     val sy = symbol ()
689 : blume 444 val (_, GG.GROUP { exports = slexp, ... }) =
690 : blume 398 List.nth (sublibs, n) handle _ => raise Format
691 :     in
692 :     case SymbolMap.find (slexp, sy) of
693 :     SOME ((_, DG.SB_BNODE (n as DG.BNODE _, _)), _) =>
694 :     n
695 :     | _ => raise Format
696 :     end
697 :     | sbn' #"3" = sn ()
698 : blume 384 | sbn' _ = raise Format
699 :     in
700 :     share sbnM sbn'
701 :     end
702 : blume 306
703 : blume 385 and fsbn () = let
704 :     fun f #"f" = (filter (), sbn ())
705 :     | f _ = raise Format
706 :     in
707 :     share fsbnM f
708 :     end
709 : blume 306
710 : blume 384 and fsbnlist () = list fsbnListM fsbn ()
711 :    
712 :     fun impexp () = let
713 : blume 385 fun ie #"i" =
714 :     let val sy = symbol ()
715 :     val (f, n) = fsbn () (* really reads farbnodes! *)
716 : blume 398 val ge = lazy_env ()
717 : blume 461 fun bs2es { env, ctxt } =
718 :     { env = GenericVC.CoerceEnv.bs2es env,
719 :     ctxt = ctxt }
720 :     val ge' = bs2es o ge
721 : blume 494 val ii = { statenv = Memoize.memoize ge',
722 : blume 398 symenv = lazy_symenv (),
723 :     statpid = pid (),
724 :     sympid = pid () }
725 : blume 461 val e = Statenv2DAEnv.cvtMemo (#env o ge)
726 : blume 385 (* put a filter in front to avoid having the FCTENV
727 :     * being queried needlessly (this avoids spurious
728 :     * module loadings) *)
729 :     val e' = DAEnv.FILTER (SymbolSet.singleton sy, e)
730 :     in
731 : blume 398 (sy, ((f, DG.SB_BNODE (n, ii)), e'))
732 : blume 385 end
733 :     | ie _ = raise Format
734 : blume 330 in
735 : blume 385 share impexpM ie
736 : blume 330 end
737 :    
738 : blume 384 val impexplist = list impexpListM impexp
739 :    
740 : blume 398 fun r_exports () = let
741 :     val iel = impexplist ()
742 :     in
743 :     foldl SymbolMap.insert' SymbolMap.empty iel
744 :     end
745 : blume 330
746 : blume 384 val stringlist = list stringListM string
747 : blume 330
748 : blume 384 fun privileges () =
749 :     StringSet.addList (StringSet.empty, stringlist ())
750 :    
751 : blume 306 val exports = r_exports ()
752 : blume 384 val required = privileges ()
753 : blume 306 in
754 :     GG.GROUP { exports = exports,
755 : blume 505 kind = GG.STABLELIB dropper,
756 : blume 306 required = required,
757 : blume 308 grouppath = group,
758 : blume 348 sublibs = sublibs }
759 : blume 306 end
760 : blume 304 in
761 : blume 361 SOME (SafeIO.perform { openIt = BinIO.openIn o mksname,
762 : blume 345 closeIt = BinIO.closeIn,
763 :     work = work,
764 : blume 459 cleanup = fn _ => () })
765 : blume 402 handle Format => (error ["file is corrupted (old version?)"];
766 :     NONE)
767 : blume 346 | IO.Io _ => NONE
768 : blume 345 end
769 : blume 304 end
770 : blume 309
771 :     end (* local *)

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