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

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