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 349 - (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 310
17 :     type statenvgetter = GP.info -> DG.bnode -> E.staticEnv
18 : blume 314 type recomp = GP.info -> GG.group -> bool
19 : blume 309 in
20 : blume 304
21 : blume 309 signature STABILIZE = sig
22 :    
23 :     val loadStable :
24 : blume 310 GP.info * (AbsPath.t -> GG.group option) * bool ref ->
25 :     AbsPath.t -> GG.group option
26 : blume 309
27 :     val stabilize :
28 : blume 311 GP.info -> { group: GG.group, anyerrors: bool ref } ->
29 : blume 310 GG.group option
30 : blume 309 end
31 :    
32 : blume 311 functor StabilizeFn (val bn2statenv : statenvgetter
33 :     val recomp: recomp) :> STABILIZE = struct
34 : blume 309
35 : blume 307 datatype pitem =
36 :     PSS of SymbolSet.set
37 :     | PS of Symbol.symbol
38 :     | PSN of DG.snode
39 : blume 304
40 : blume 307 datatype uitem =
41 :     USS of SymbolSet.set
42 :     | US of Symbol.symbol
43 :     | UBN of DG.bnode
44 : blume 304
45 : blume 307 fun compare (PS s, PS s') = SymbolOrdKey.compare (s, s')
46 :     | compare (PS _, _) = GREATER
47 :     | compare (_, PS _) = LESS
48 :     | compare (PSS s, PSS s') = SymbolSet.compare (s, s')
49 :     | compare (PSS _, _) = GREATER
50 :     | compare (_, PSS _) = LESS
51 :     | compare (PSN (DG.SNODE n), PSN (DG.SNODE n')) =
52 :     SmlInfo.compare (#smlinfo n, #smlinfo n')
53 :    
54 : blume 304 structure Map =
55 :     BinaryMapFn (struct
56 : blume 307 type ord_key = pitem
57 : blume 304 val compare = compare
58 :     end)
59 :    
60 : blume 308 fun genStableInfoMap (exports, group) = let
61 :     (* find all the exported bnodes that are in the same group: *)
62 :     fun add (((_, DG.SB_BNODE (n as DG.BNODE b)), _), m) = let
63 :     val i = #bininfo b
64 :     in
65 :     if AbsPath.compare (BinInfo.group i, group) = EQUAL then
66 :     IntBinaryMap.insert (m, BinInfo.offset i, n)
67 :     else m
68 :     end
69 :     | add (_, m) = m
70 :     in
71 :     SymbolMap.foldl add IntBinaryMap.empty exports
72 :     end
73 :    
74 : blume 311 fun stabilize gp { group = g as GG.GROUP grec, anyerrors } = let
75 : blume 304
76 : blume 323 val primconf = #primconf (#param gp)
77 :     val policy = #fnpolicy (#param gp)
78 :    
79 : blume 340 val grouppath = #grouppath grec
80 :     val groupdir = AbsPath.dir grouppath
81 :    
82 : blume 348 fun doit wrapped = let
83 : blume 312
84 : blume 314 val _ =
85 : blume 348 if StringSet.isEmpty wrapped then ()
86 : blume 314 else
87 :     Say.say ("$Stabilize: wrapping the following privileges:\n"
88 : blume 312 :: map (fn s => (" " ^ s ^ "\n"))
89 : blume 348 (StringSet.listItems wrapped))
90 : blume 312
91 : blume 311 val bname = AbsPath.name o SmlInfo.binpath
92 :     val bsz = OS.FileSys.fileSize o bname
93 : blume 345
94 : blume 311 fun cpb s i = let
95 : blume 345 fun copy ins = let
96 :     fun cp () =
97 :     if BinIO.endOfStream ins then ()
98 :     else (BinIO.output (s, BinIO.input ins); cp ())
99 :     in
100 :     cp ()
101 :     end
102 : blume 311 in
103 : blume 345 SafeIO.perform { openIt = fn () => BinIO.openIn (bname i),
104 :     closeIt = BinIO.closeIn,
105 :     work = copy,
106 :     cleanup = fn () => () }
107 : blume 311 end
108 : blume 310
109 : blume 311 val grpSrcInfo = (#errcons gp, anyerrors)
110 : blume 308
111 : blume 311 val exports = #exports grec
112 : blume 348 val required = StringSet.difference (#required grec, wrapped)
113 : blume 340 val sublibs = #sublibs grec
114 : blume 304
115 : blume 311 (* The format of a stable archive is the following:
116 :     * - It starts with the size s of the pickled dependency
117 :     * graph. This size itself is written as four-byte string.
118 :     * - The pickled dependency graph. This graph contains
119 :     * integer offsets of the binfiles for the individual ML
120 :     * members. These offsets need to be adjusted by adding
121 :     * s + 4. The pickled dependency graph also contains integer
122 :     * offsets relative to other stable groups. These offsets
123 :     * need no further adjustment.
124 :     * - Individual binfile contents (concatenated).
125 :     *)
126 : blume 304
127 : blume 340 (* Here we build a mapping that maps each BNODE to a number
128 :     * representing the sub-library that it came from and a
129 :     * representative symbol that can be used to find the BNODE
130 :     * within the exports of that library *)
131 :     fun oneB i (sy, ((_, DG.SB_BNODE (DG.BNODE n)), _), m) =
132 :     StableMap.insert (m, #bininfo n, (i, sy))
133 :     | oneB i (_, _, m) = m
134 :     fun oneSL ((_, g as GG.GROUP { exports, ... }), (m, i)) =
135 :     (SymbolMap.foldli (oneB i) m exports, i + 1)
136 :     val inverseMap = #1 (foldl oneSL (StableMap.empty, 0) sublibs)
137 : blume 330
138 : blume 311 val members = ref []
139 :     val (registerOffset, getOffset) = let
140 :     val dict = ref SmlInfoMap.empty
141 :     val cur = ref 0
142 :     fun reg (i, sz) = let
143 :     val os = !cur
144 : blume 306 in
145 : blume 311 cur := os + sz;
146 :     dict := SmlInfoMap.insert (!dict, i, os);
147 :     members := i :: (!members);
148 :     os
149 : blume 306 end
150 : blume 311 fun get i = valOf (SmlInfoMap.find (!dict, i))
151 :     in
152 :     (reg, get)
153 :     end
154 : blume 304
155 : blume 311 fun w_list w_item [] k m =
156 :     "0" :: k m
157 :     | w_list w_item [a] k m =
158 :     "1" :: w_item a k m
159 :     | w_list w_item [a, b] k m =
160 :     "2" :: w_item a (w_item b k) m
161 :     | w_list w_item [a, b, c] k m =
162 :     "3" :: w_item a (w_item b (w_item c k)) m
163 :     | w_list w_item [a, b, c, d] k m =
164 :     "4" :: w_item a (w_item b (w_item c (w_item d k))) m
165 :     | w_list w_item (a :: b :: c :: d :: e :: r) k m =
166 :     "5" :: w_item a (w_item b (w_item c (w_item d (w_item e
167 :     (w_list w_item r k))))) m
168 : blume 304
169 : blume 311 fun w_option w_item NONE k m = "n" :: k m
170 :     | w_option w_item (SOME i) k m = "s" :: w_item i k m
171 : blume 304
172 : blume 311 fun int_encode i = let
173 :     (* this is the same mechanism that's also used in
174 :     * TopLevel/batch/binfile.sml (maybe we should share it) *)
175 :     val n = Word32.fromInt i
176 :     val // = LargeWord.div
177 :     val %% = LargeWord.mod
178 :     val !! = LargeWord.orb
179 :     infix // %% !!
180 :     val toW8 = Word8.fromLargeWord
181 :     fun r (0w0, l) = Word8Vector.fromList l
182 :     | r (n, l) =
183 :     r (n // 0w128, toW8 ((n %% 0w128) !! 0w128) :: l)
184 :     in
185 :     Byte.bytesToString (r (n // 0w128, [toW8 (n %% 0w128)]))
186 :     end
187 : blume 304
188 : blume 311 fun w_int i k m = int_encode i :: k m
189 : blume 304
190 : blume 311 fun w_share w C v k (i, m) =
191 :     case Map.find (m, C v) of
192 :     SOME i' => "o" :: w_int i' k (i, m)
193 :     | NONE => "n" :: w v k (i + 1, Map.insert (m, C v, i))
194 : blume 304
195 : blume 311 fun w_symbol_raw s k m = let
196 :     val ns = case Symbol.nameSpace s of
197 :     Symbol.SIGspace => "'"
198 :     | Symbol.FCTspace => "("
199 :     | Symbol.FSIGspace => ")"
200 :     | Symbol.STRspace => ""
201 :     | _ => GenericVC.ErrorMsg.impossible "stabilize:w_symbol"
202 :     in
203 :     ns :: Symbol.name s :: "." :: k m
204 :     end
205 : blume 304
206 : blume 311 val w_symbol = w_share w_symbol_raw PS
207 : blume 304
208 : blume 311 val w_ss = w_share (w_list w_symbol o SymbolSet.listItems) PSS
209 : blume 306
210 : blume 311 val w_filter = w_option w_ss
211 : blume 306
212 : blume 311 fun w_string s k m = let
213 :     fun esc #"\\" = "\\\\"
214 :     | esc #"\"" = "\\\""
215 :     | esc c = String.str c
216 :     in
217 :     String.translate esc s :: "\"" :: k m
218 :     end
219 : blume 306
220 : blume 311 fun w_sharing NONE k m = "n" :: k m
221 :     | w_sharing (SOME true) k m = "t" :: k m
222 :     | w_sharing (SOME false) k m = "f" :: k m
223 : blume 306
224 : blume 311 fun w_si i k = let
225 : blume 340 (* FIXME: this is not a technical flaw, but perhaps one
226 :     * that deserves fixing anyway: If we only look at spec,
227 :     * then we are losing information about sub-grouping
228 :     * within libraries. However, the spec in BinInfo.info
229 :     * is only used for diagnostics and has no impact on the
230 :     * operation of CM itself. *)
231 : blume 311 val spec = AbsPath.spec (SmlInfo.sourcepath i)
232 :     val locs = SmlInfo.errorLocation gp i
233 :     val offset = registerOffset (i, bsz i)
234 :     in
235 :     w_string spec
236 :     (w_string locs
237 :     (w_int offset
238 :     (w_sharing (SmlInfo.share i) k)))
239 :     end
240 : blume 306
241 : blume 323 fun w_primitive p k m =
242 :     String.str (Primitive.toIdent primconf p) :: k m
243 : blume 306
244 : blume 340 fun warn_relabs p abs = let
245 :     val relabs = if abs then "absolute" else "relative"
246 : blume 330 fun ppb pps =
247 :     (PP.add_newline pps;
248 : blume 340 PP.add_string pps (AbsPath.name p);
249 : blume 330 PP.add_newline pps;
250 :     PP.add_string pps
251 :     "(This means that in order to be able to use the result of stabilization";
252 :     PP.add_newline pps;
253 : blume 340 PP.add_string pps "the library must be in the same ";
254 : blume 330 PP.add_string pps relabs;
255 :     PP.add_string pps " location as it is now.)";
256 :     PP.add_newline pps)
257 :     in
258 :     EM.errorNoFile (#errcons gp, anyerrors) SM.nullRegion
259 :     EM.WARN
260 : blume 340 (concat [AbsPath.name grouppath,
261 :     ": library referred to by ", relabs,
262 :     " pathname:"])
263 : blume 330 ppb
264 :     end
265 : blume 306
266 : blume 330 fun w_abspath p k m =
267 : blume 340 w_list w_string (AbsPath.pickle (warn_relabs p) (p, groupdir))
268 :     k m
269 : blume 306
270 : blume 311 fun w_bn (DG.PNODE p) k m = "p" :: w_primitive p k m
271 : blume 340 | w_bn (DG.BNODE { bininfo = i, ... }) k m = let
272 :     val (n, sy) = valOf (StableMap.find (inverseMap, i))
273 :     in
274 :     "b" :: w_int n (w_symbol sy k) m
275 :     end
276 : blume 306
277 : blume 311 fun w_sn_raw (DG.SNODE n) k =
278 :     w_si (#smlinfo n)
279 :     (w_list w_sn (#localimports n)
280 :     (w_list w_fsbn (#globalimports n) k))
281 : blume 306
282 : blume 311 and w_sn n = w_share w_sn_raw PSN n
283 : blume 307
284 : blume 311 and w_sbn (DG.SB_BNODE n) k m = "b" :: w_bn n k m
285 :     | w_sbn (DG.SB_SNODE n) k m = "s" :: w_sn n k m
286 : blume 306
287 : blume 311 and w_fsbn (f, n) k = w_filter f (w_sbn n k)
288 : blume 306
289 : blume 311 fun w_impexp (s, (n, _)) k = w_symbol s (w_fsbn n k)
290 : blume 306
291 : blume 311 fun w_exports e = w_list w_impexp (SymbolMap.listItemsi e)
292 : blume 306
293 : blume 311 fun w_bool true k m = "t" :: k m
294 :     | w_bool false k m = "f" :: k m
295 : blume 306
296 : blume 311 fun w_privileges p = w_list w_string (StringSet.listItems p)
297 : blume 306
298 : blume 311 fun pickle_group () = let
299 : blume 330 fun w_sg (p, _) = w_abspath p
300 : blume 311 fun k0 m = []
301 :     val m0 = (0, Map.empty)
302 :     in
303 : blume 340 (* Pickle the sublibs first because we need to already
304 : blume 330 * have them back when we unpickle BNODEs. *)
305 : blume 340 concat (w_list w_sg sublibs
306 : blume 330 (w_exports exports
307 : blume 348 (w_privileges required k0)) m0)
308 : blume 311 end
309 : blume 308
310 : blume 311 val pickle = pickle_group ()
311 :     val sz = size pickle
312 :     val offset_adjustment = sz + 4
313 : blume 308
314 : blume 329 fun mkStableGroup spath = let
315 : blume 311 val m = ref SmlInfoMap.empty
316 :     fun sn (DG.SNODE (n as { smlinfo, ... })) =
317 :     case SmlInfoMap.find (!m, smlinfo) of
318 :     SOME n => n
319 :     | NONE => let
320 :     val li = map sn (#localimports n)
321 :     val gi = map fsbn (#globalimports n)
322 :     val sourcepath = SmlInfo.sourcepath smlinfo
323 : blume 340 (* FIXME: see the comment near the other
324 :     * occurence of AbsPath.spec... *)
325 : blume 311 val spec = AbsPath.spec sourcepath
326 :     val offset =
327 :     getOffset smlinfo + offset_adjustment
328 :     val share = SmlInfo.share smlinfo
329 :     val locs = SmlInfo.errorLocation gp smlinfo
330 :     val error = EM.errorNoSource grpSrcInfo locs
331 :     val i = BinInfo.new { group = grouppath,
332 : blume 329 stablepath = spath,
333 : blume 311 spec = spec,
334 :     offset = offset,
335 :     share = share,
336 :     error = error }
337 :     val n = DG.BNODE { bininfo = i,
338 :     localimports = li,
339 :     globalimports = gi }
340 :     in
341 :     m := SmlInfoMap.insert (!m, smlinfo, n);
342 :     n
343 :     end
344 : blume 308
345 : blume 311 and sbn (DG.SB_SNODE n) = sn n
346 :     | sbn (DG.SB_BNODE n) = n
347 : blume 308
348 : blume 311 and fsbn (f, n) = (f, sbn n)
349 : blume 308
350 : blume 311 fun impexp ((f, n), e) = ((f, DG.SB_BNODE (sbn n)), e)
351 : blume 308
352 : blume 311 val exports = SymbolMap.map impexp (#exports grec)
353 :     val simap = genStableInfoMap (exports, grouppath)
354 :     in
355 :     GG.GROUP { exports = exports,
356 : blume 348 kind = GG.STABLELIB simap,
357 : blume 311 required = required,
358 :     grouppath = grouppath,
359 : blume 348 sublibs = sublibs }
360 : blume 311 end
361 : blume 308
362 : blume 311 fun writeInt32 (s, i) = let
363 :     val a = Word8Array.array (4, 0w0)
364 :     val _ = Pack32Big.update (a, 0, LargeWord.fromInt i)
365 :     in
366 :     BinIO.output (s, Word8Array.extract (a, 0, NONE))
367 :     end
368 :     val memberlist = rev (!members)
369 :    
370 :     val gpath = #grouppath grec
371 :     val spath = FilenamePolicy.mkStablePath policy gpath
372 : blume 345 fun work outs =
373 : blume 311 (Say.vsay ["[stabilizing ", AbsPath.name gpath, "]\n"];
374 :     writeInt32 (outs, sz);
375 :     BinIO.output (outs, Byte.stringToBytes pickle);
376 :     app (cpb outs) memberlist;
377 : blume 345 mkStableGroup spath)
378 : blume 311 in
379 : blume 345 SOME (SafeIO.perform { openIt = fn () => AbsPath.openBinOut spath,
380 :     closeIt = BinIO.closeOut,
381 :     work = work,
382 : blume 349 cleanup = fn () => AbsPath.delete spath })
383 : blume 345 handle exn => NONE
384 : blume 311 end
385 :     in
386 : blume 348 case #kind grec of
387 :     GG.STABLELIB _ => SOME g
388 :     | GG.NOLIB => EM.impossible "stabilize: no library"
389 :     | GG.LIB wrapped =>
390 : blume 314 if not (recomp gp g) then
391 : blume 311 (anyerrors := true; NONE)
392 :     else let
393 : blume 348 fun notStable (_, GG.GROUP { kind, ... }) =
394 :     case kind of GG.STABLELIB _ => true | _ => false
395 : blume 308 in
396 : blume 340 case List.filter notStable (#sublibs grec) of
397 : blume 348 [] => doit wrapped
398 : blume 311 | l => let
399 :     val grammar = case l of [_] => " is" | _ => "s are"
400 :     fun ppb pps = let
401 :     fun loop [] = ()
402 : blume 330 | loop ((p, GG.GROUP { grouppath, ... })
403 :     :: t) =
404 : blume 311 (PP.add_string pps
405 :     (AbsPath.name grouppath);
406 : blume 330 PP.add_string pps " (";
407 :     PP.add_string pps (AbsPath.name p);
408 :     PP.add_string pps ")";
409 : blume 311 PP.add_newline pps;
410 :     loop t)
411 :     in
412 :     PP.add_newline pps;
413 :     PP.add_string pps
414 :     (concat ["because the following sub-group",
415 :     grammar, " not stable:"]);
416 :     PP.add_newline pps;
417 :     loop l
418 :     end
419 :     val errcons = #errcons gp
420 :     val gname = AbsPath.name (#grouppath grec)
421 :     in
422 :     EM.errorNoFile (errcons, anyerrors) SM.nullRegion
423 :     EM.COMPLAIN
424 :     (gname ^ " cannot be stabilized")
425 :     ppb;
426 :     NONE
427 :     end
428 : blume 308 end
429 : blume 311 end
430 : blume 310
431 :     fun loadStable (gp, getGroup, anyerrors) group = let
432 : blume 306
433 : blume 340 val groupdir = AbsPath.dir group
434 : blume 310 fun bn2env n = Statenv2DAEnv.cvtMemo (fn () => bn2statenv gp n)
435 : blume 308
436 : blume 311 val errcons = #errcons gp
437 :     val grpSrcInfo = (errcons, anyerrors)
438 :     val gname = AbsPath.name group
439 :     fun error l = EM.errorNoFile (errcons, anyerrors) SM.nullRegion
440 :     EM.COMPLAIN (concat (gname :: ": " :: l)) EM.nullErrorBody
441 : blume 309
442 : blume 306 exception Format
443 :    
444 : blume 318 val pcmode = #pcmode (#param gp)
445 : blume 310 val policy = #fnpolicy (#param gp)
446 : blume 323 val primconf = #primconf (#param gp)
447 : blume 310 val spath = FilenamePolicy.mkStablePath policy group
448 : blume 311 val _ = Say.vsay ["[checking stable ", gname, "]\n"]
449 : blume 310
450 : blume 345 fun work s = let
451 : blume 310
452 : blume 345 fun getGroup' p =
453 :     case getGroup p of
454 :     SOME g => g
455 :     | NONE => (error ["unable to find ", AbsPath.name p];
456 :     raise Format)
457 : blume 306
458 : blume 345 (* for getting sharing right... *)
459 :     val m = ref IntBinaryMap.empty
460 :     val next = ref 0
461 : blume 304
462 : blume 345 fun bytesIn n = let
463 :     val bv = BinIO.inputN (s, n)
464 :     in
465 :     if n = Word8Vector.length bv then bv
466 :     else raise Format
467 :     end
468 : blume 304
469 : blume 345 val sz = LargeWord.toIntX (Pack32Big.subVec (bytesIn 4, 0))
470 :     val pickle = bytesIn sz
471 :     val offset_adjustment = sz + 4
472 :    
473 :     val rd = let
474 :     val pos = ref 0
475 :     fun rd () = let
476 :     val p = !pos
477 :     in
478 :     pos := p + 1;
479 :     Byte.byteToChar (Word8Vector.sub (pickle, p))
480 :     handle _ => raise Format
481 :     end
482 : blume 306 in
483 : blume 345 rd
484 : blume 306 end
485 : blume 304
486 : blume 345 fun r_list r () =
487 :     case rd () of
488 :     #"0" => []
489 :     | #"1" => [r ()]
490 :     | #"2" => [r (), r ()]
491 :     | #"3" => [r (), r (), r ()]
492 :     | #"4" => [r (), r (), r (), r ()]
493 :     | #"5" => r () :: r () :: r () :: r () :: r () :: r_list r ()
494 :     | _ => raise Format
495 : blume 304
496 : blume 345 fun r_bool () =
497 :     case rd () of
498 :     #"t" => true
499 :     | #"f" => false
500 :     | _ => raise Format
501 : blume 304
502 : blume 345 fun r_option r_item () =
503 :     case rd () of
504 :     #"n" => NONE
505 :     | #"s" => SOME (r_item ())
506 :     | _ => raise Format
507 : blume 304
508 : blume 345 fun r_int () = let
509 :     fun loop n = let
510 :     val w8 = Byte.charToByte (rd ())
511 :     val n' =
512 :     n * 0w128 + Word8.toLargeWord (Word8.andb (w8, 0w127))
513 :     in
514 :     if Word8.andb (w8, 0w128) = 0w0 then n' else loop n'
515 :     end
516 : blume 306 in
517 : blume 345 LargeWord.toIntX (loop 0w0)
518 : blume 306 end
519 : blume 304
520 : blume 345 fun r_share r_raw C unC () =
521 : blume 306 case rd () of
522 : blume 345 #"o" => (case IntBinaryMap.find (!m, r_int ()) of
523 :     SOME x => unC x
524 :     | NONE => raise Format)
525 :     | #"n" => let
526 :     val i = !next
527 :     val _ = next := i + 1
528 :     val v = r_raw ()
529 :     in
530 :     m := IntBinaryMap.insert (!m, i, C v);
531 :     v
532 :     end
533 :     | _ => raise Format
534 : blume 304
535 : blume 345 fun r_string () = let
536 :     fun loop l =
537 : blume 306 case rd () of
538 : blume 345 #"\"" => String.implode (rev l)
539 :     | #"\\" => loop (rd () :: l)
540 :     | c => loop (c :: l)
541 : blume 306 in
542 : blume 345 loop []
543 : blume 306 end
544 : blume 304
545 : blume 345 fun r_abspath () =
546 :     case AbsPath.unpickle pcmode (r_list r_string (), groupdir) of
547 :     SOME p => p
548 :     | NONE => raise Format
549 : blume 304
550 : blume 345 val r_symbol = let
551 :     fun r_symbol_raw () = let
552 :     val (ns, first) =
553 :     case rd () of
554 :     #"`" => (Symbol.sigSymbol, rd ())
555 :     | #"(" => (Symbol.fctSymbol, rd ())
556 :     | #")" => (Symbol.fsigSymbol, rd ())
557 :     | c => (Symbol.strSymbol, c)
558 :     fun loop (#".", l) = String.implode (rev l)
559 :     | loop (c, l) = loop (rd (), c :: l)
560 :     in
561 :     ns (loop (first, []))
562 :     end
563 :     fun unUS (US x) = x
564 :     | unUS _ = raise Format
565 :     in
566 :     r_share r_symbol_raw US unUS
567 :     end
568 : blume 305
569 : blume 345 val r_ss = let
570 :     fun r_ss_raw () =
571 :     SymbolSet.addList (SymbolSet.empty, r_list r_symbol ())
572 :     fun unUSS (USS s) = s
573 :     | unUSS _ = raise Format
574 :     in
575 :     r_share r_ss_raw USS unUSS
576 :     end
577 : blume 305
578 : blume 345 val r_filter = r_option r_ss
579 : blume 305
580 : blume 345 fun r_primitive () =
581 :     case Primitive.fromIdent primconf (rd ()) of
582 :     NONE => raise Format
583 :     | SOME p => p
584 : blume 305
585 : blume 345 fun r_sharing () =
586 :     case rd () of
587 :     #"n" => NONE
588 :     | #"t" => SOME true
589 :     | #"f" => SOME false
590 :     | _ => raise Format
591 : blume 306
592 : blume 345 fun r_si () = let
593 :     val spec = r_string ()
594 :     val locs = r_string ()
595 :     val offset = r_int () + offset_adjustment
596 :     val share = r_sharing ()
597 :     val error = EM.errorNoSource grpSrcInfo locs
598 :     in
599 :     BinInfo.new { group = group,
600 :     stablepath = spath,
601 :     error = error,
602 :     spec = spec,
603 :     offset = offset,
604 :     share = share }
605 :     end
606 : blume 306
607 : blume 345 fun r_sg () = let
608 :     val p = r_abspath ()
609 :     in
610 :     (p, getGroup' p)
611 :     end
612 :    
613 : blume 340 val sublibs = r_list r_sg ()
614 : blume 307
615 : blume 330 fun r_bn () =
616 :     case rd () of
617 :     #"p" => DG.PNODE (r_primitive ())
618 :     | #"b" => let
619 : blume 340 val n = r_int ()
620 : blume 330 val sy = r_symbol ()
621 : blume 340 val (_, GG.GROUP { exports = slexp, ... }) =
622 :     List.nth (sublibs, n) handle _ => raise Format
623 : blume 330 in
624 : blume 340 case SymbolMap.find (slexp, sy) of
625 : blume 330 SOME ((_, DG.SB_BNODE (n as DG.BNODE _)), _) => n
626 :     | _ => raise Format
627 :     end
628 :     | _ => raise Format
629 : blume 306
630 : blume 330 (* this is the place where what used to be an
631 :     * SNODE changes to a BNODE! *)
632 :     fun r_sn_raw () =
633 :     DG.BNODE { bininfo = r_si (),
634 :     localimports = r_list r_sn (),
635 :     globalimports = r_list r_fsbn () }
636 : blume 306
637 : blume 330 and r_sn () =
638 :     r_share r_sn_raw UBN (fn (UBN n) => n | _ => raise Format) ()
639 : blume 306
640 : blume 330 (* this one changes from farsbnode to plain farbnode *)
641 :     and r_sbn () =
642 :     case rd () of
643 :     #"b" => r_bn ()
644 :     | #"s" => r_sn ()
645 :     | _ => raise Format
646 : blume 306
647 : blume 330 and r_fsbn () = (r_filter (), r_sbn ())
648 : blume 306
649 : blume 330 fun r_impexp () = let
650 :     val sy = r_symbol ()
651 :     val (f, n) = r_fsbn () (* really reads farbnodes! *)
652 :     val e = bn2env n
653 :     (* put a filter in front to avoid having the FCTENV being
654 :     * queried needlessly (this avoids spurious module loadings) *)
655 :     val e' = DAEnv.FILTER (SymbolSet.singleton sy, e)
656 :     in
657 :     (sy, ((f, DG.SB_BNODE n), e')) (* coerce to farsbnodes *)
658 :     end
659 :    
660 :     fun r_exports () =
661 :     foldl SymbolMap.insert' SymbolMap.empty (r_list r_impexp ())
662 :    
663 :     fun r_privileges () =
664 :     StringSet.addList (StringSet.empty, r_list r_string ())
665 :    
666 : blume 306 val exports = r_exports ()
667 :     val required = r_privileges ()
668 : blume 308 val simap = genStableInfoMap (exports, group)
669 : blume 306 in
670 :     GG.GROUP { exports = exports,
671 : blume 348 kind = GG.STABLELIB simap,
672 : blume 306 required = required,
673 : blume 308 grouppath = group,
674 : blume 348 sublibs = sublibs }
675 : blume 306 end
676 : blume 304 in
677 : blume 345 SOME (SafeIO.perform { openIt = fn () => AbsPath.openBinIn spath,
678 :     closeIt = BinIO.closeIn,
679 :     work = work,
680 :     cleanup = fn () => () })
681 :     handle Format => NONE
682 : blume 346 | IO.Io _ => NONE
683 : blume 345 end
684 : blume 304 end
685 : blume 309
686 :     end (* local *)

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