Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/cm/main/autoload.sml
ViewVC logotype

Diff of /sml/trunk/src/cm/main/autoload.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 398, Wed Aug 25 15:36:43 1999 UTC revision 399, Thu Aug 26 09:55:09 1999 UTC
# Line 6  Line 6 
6   * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)   * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7   *)   *)
8  local  local
9        structure GP = GeneralParams
10      structure DG = DependencyGraph      structure DG = DependencyGraph
11      structure BE = GenericVC.BareEnvironment      structure BE = GenericVC.BareEnvironment
12      structure ER = GenericVC.EnvRef      structure ER = GenericVC.EnvRef
13      structure GG = GroupGraph      structure GG = GroupGraph
14      structure E = GenericVC.Environment      structure E = GenericVC.Environment
15        structure EM = GenericVC.ErrorMsg
16  in  in
17  signature AUTOLOAD = sig  signature AUTOLOAD = sig
18    
19      val register : ER.envref * GG.group -> unit      val register : ER.envref * GG.group -> unit
20    
21      val mkManager : (unit -> GeneralParams.info) ->      val mkManager : (unit -> GP.info) -> GenericVC.Ast.dec * ER.envref -> unit
         GenericVC.Ast.dec * ER.envref -> unit  
22    
23      val getPending : unit -> DG.impexp SymbolMap.map      val getPending : unit -> DG.impexp SymbolMap.map
24    
25      val reset : unit -> unit      val reset : unit -> unit
26  end  end
27    
28  functor AutoLoadFn (structure RT : TRAVERSAL  functor AutoLoadFn (structure C : COMPILE
29                          where type result =                      structure L : LINK) :> AUTOLOAD = struct
                           { stat: E.staticEnv, sym: E.symenv }  
                     structure ET : TRAVERSAL  
                         where type result = E.dynenv):> AUTOLOAD = struct  
30    
31      structure SE = GenericVC.StaticEnv      structure SE = GenericVC.StaticEnv
32    
33        type traversal = GP.info -> E.environment option
34      (* We let the topLevel env *logically* sit atop the pending      (* We let the topLevel env *logically* sit atop the pending
35       * autoload bindings.  This way we do not have to intercept every       * autoload bindings.  This way we do not have to intercept every
36       * change to the topLevel env.  However, it means that any addition       * change to the topLevel env.  However, it means that any addition
37       * to "pending" must be subtracted from the topLevel env. *)       * to "pending" must be subtracted from the topLevel env. *)
38      val pending =      val pending = ref (SymbolMap.empty: (DG.impexp * traversal) SymbolMap.map)
         ref (SymbolMap.empty: (DG.impexp * RT.ts * ET.ts) SymbolMap.map)  
39    
40      fun reset () = pending := SymbolMap.empty      fun reset () = pending := SymbolMap.empty
41    
42      fun register (ter: ER.envref, GG.GROUP { exports, ... }) = let      fun register (ter: ER.envref, g as GG.GROUP { exports, ... }) = let
43          val te = #get ter ()          val te = #get ter ()
44          (* toplevel bindings (symbol set) ... *)          (* toplevel bindings (symbol set) ... *)
45          val tss = foldl SymbolSet.add' SymbolSet.empty          val tss = foldl SymbolSet.add' SymbolSet.empty
# Line 54  Line 52 
52          (* getting rid of unneeded bindings... *)          (* getting rid of unneeded bindings... *)
53          val te' = BE.filterEnv (te, SymbolSet.listItems rss)          val te' = BE.filterEnv (te, SymbolSet.listItems rss)
54          (* make traversal states *)          (* make traversal states *)
55          val rts = RT.start ()          val { exports = cTrav, ... } = C.newTraversal (L.evict, g)
56          val ets = ET.start ()          val { exports = lTrav, ... } = L.newTraversal g
57          fun addState n = (n, rts, ets)          fun combine (ss, d) gp =
58                case ss gp of
59                    SOME { stat, sym } =>
60                        (case d gp of
61                             SOME dyn => SOME (E.mkenv { static = stat,
62                                                         symbolic = sym,
63                                                         dynamic = dyn })
64                           | NONE => NONE)
65                  | NONE => NONE
66            fun mkNode (sy, ie) =
67                (ie, combine (valOf (SymbolMap.find (cTrav, sy)),
68                              valOf (SymbolMap.find (lTrav, sy))))
69            val newNodes = SymbolMap.mapi mkNode exports
70      in      in
71          #set ter te';          #set ter te';
72          pending :=          pending := SymbolMap.unionWith #1 (newNodes, !pending)
            SymbolMap.unionWith #1 (SymbolMap.map addState exports, !pending)  
73      end      end
74    
75      fun mkManager get_ginfo (ast, ter: ER.envref) = let      fun mkManager get_ginfo (ast, ter: ER.envref) = let
76    
77          val gp = get_ginfo ()          val gp = get_ginfo ()
78    
79          fun loadit m =          fun loadit m = let
80              case RT.resume (fn ((n, _), rts, ets) => (n, rts)) gp m of              fun one ((_, tr), NONE) = NONE
81                  | one ((_, tr), SOME e) =
82                    (case tr gp of
83                  NONE => NONE                  NONE => NONE
84                | SOME { stat, sym } => let                     | SOME e' => let
85                      fun exec () =                           val be = GenericVC.CoerceEnv.e2b e'
                         ET.resume (fn ((n, _), rts, ets) => (n, ets)) gp m  
86                  in                  in
87                      case exec () of                           SOME (BE.concatEnv (be, e))
88                          NONE => NONE                       end)
                       | SOME dyn => let  
                             val e = E.mkenv { static = stat, symbolic = sym,  
                                               dynamic =dyn }  
                             val be = GenericVC.CoerceEnv.e2b e  
89                          in                          in
90                              SOME be              (* make sure that there are no stale value around... *)
91                          end              L.cleanup ();
92                SymbolMap.foldl one (SOME BE.emptyEnv) m
93                  end                  end
94    
95          val { skeleton, ... } =          val { skeleton, ... } =
# Line 98  Line 105 
105          val _ = pending := pend          val _ = pending := pend
106          val (dae, _) = Statenv2DAEnv.cvt ste          val (dae, _) = Statenv2DAEnv.cvt ste
107          val load = ref SymbolMap.empty          val load = ref SymbolMap.empty
108          fun lookpend sy =          fun lookpend sy = let
109                fun otherwise _ = EM.impossible "Autoload:lookpend"
110            in
111              case SymbolMap.find (pend, sy) of              case SymbolMap.find (pend, sy) of
112                  SOME (x as ((_, e), _, _)) =>                  SOME (x as ((_, e), _)) =>
113                      (load := SymbolMap.insert (!load, sy, x);                      (load := SymbolMap.insert (!load, sy, x);
114                       e)                       BuildDepend.look otherwise e sy)
115                | NONE => DAEnv.EMPTY                | NONE => DAEnv.EMPTY
116            end
117          val lookimport = BuildDepend.look lookpend dae          val lookimport = BuildDepend.look lookpend dae
118          val _ = BuildDepend.processOneSkeleton lookimport skeleton          val _ = BuildDepend.processOneSkeleton lookimport skeleton
119    
# Line 116  Line 126 
126           * their corresponding node has been picked.  So we first build           * their corresponding node has been picked.  So we first build
127           * three sets: sml- and stable-infos of picked nodes as well           * three sets: sml- and stable-infos of picked nodes as well
128           * as the set of PNODEs: *)           * as the set of PNODEs: *)
129          fun add ((((_, DG.SB_SNODE (DG.SNODE { smlinfo, ... })), _), _, _),          fun add ((((_, DG.SB_SNODE (DG.SNODE { smlinfo, ... })), _), _),
130                   (ss, bs, ps)) =                   (ss, bs, ps)) =
131              (SmlInfoSet.add (ss, smlinfo), bs, ps)              (SmlInfoSet.add (ss, smlinfo), bs, ps)
132            | add ((((_, DG.SB_BNODE (DG.BNODE { bininfo, ... })), _), _, _),            | add ((((_, DG.SB_BNODE (DG.BNODE { bininfo, ... }, _)), _), _),
133                   (ss, bs, ps)) =                   (ss, bs, ps)) =
134              (ss, StableSet.add (bs, bininfo), ps)              (ss, StableSet.add (bs, bininfo), ps)
135            | add ((((_, DG.SB_BNODE (DG.PNODE p)), _), _, _), (ss, bs, ps)) =            | add ((((_, DG.SB_BNODE (DG.PNODE p, _)), _), _), (ss, bs, ps)) =
136              (ss, bs, StringSet.add (ps, Primitive.toString p))              (ss, bs, StringSet.add (ps, Primitive.toString p))
137    
138          val (smlinfos, stableinfos, prims) =          val (smlinfos, stableinfos, prims) =
# Line 131  Line 141 
141                    loadmap0                    loadmap0
142    
143          (* now we can easily find out whether a node has been picked... *)          (* now we can easily find out whether a node has been picked... *)
144          fun isPicked (((_, DG.SB_SNODE (DG.SNODE n)), _), _, _) =          fun isPicked (((_, DG.SB_SNODE (DG.SNODE n)), _), _) =
145              SmlInfoSet.member (smlinfos, #smlinfo n)              SmlInfoSet.member (smlinfos, #smlinfo n)
146            | isPicked (((_, DG.SB_BNODE (DG.BNODE n)), _), _, _) =            | isPicked (((_, DG.SB_BNODE (DG.BNODE n, _)), _), _) =
147              StableSet.member (stableinfos, #bininfo n)              StableSet.member (stableinfos, #bininfo n)
148            | isPicked (((_, DG.SB_BNODE (DG.PNODE p)), _), _, _) =            | isPicked (((_, DG.SB_BNODE (DG.PNODE p, _)), _), _) =
149              StringSet.member (prims, Primitive.toString p)              StringSet.member (prims, Primitive.toString p)
150    
151          val loadmap = SymbolMap.filter isPicked pend          val loadmap = SymbolMap.filter isPicked pend

Legend:
Removed from v.398  
changed lines
  Added in v.399

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