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

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