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

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