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

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