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/branches/primop-branch-3/compiler/ElabData/modules/modules.sml
ViewVC logotype

Annotation of /sml/branches/primop-branch-3/compiler/ElabData/modules/modules.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3376 - (view) (download)

1 : blume 902 (* modules.sml
2 :     *
3 :     * (C) 2001 Lucent Technologies, Bell Labs
4 :     *)
5 :     structure Modules : MODULES =
6 :     struct
7 :    
8 :     local structure S = Symbol
9 :     structure SP = SymPath
10 :     structure IP = InvPath
11 :     structure EP = EntPath
12 :     structure ST = Stamps
13 :     structure T = Types
14 :     structure A = Access
15 :     structure E = Env
16 :     in
17 :    
18 :     (* -------------------- signature-related definitions -------------------- *)
19 :    
20 :     type sharespec = SP.path list (* only internal sharing *)
21 :    
22 :     datatype Signature
23 :     = SIG of sigrec
24 :     | ERRORsig
25 :    
26 :     (*
27 : dbm 3287 * 1. tyc spec tycon should only be GENtyc, with FORMAL or DATATYPE tyckinds, or DEFtyc.
28 : blume 902 * 2. the stamp and the path for the GENtyc or DEFtyc should be meaningless
29 :     * (but the stamps are in fact used for relativization of withtype bodies and
30 :     * the datacon domains of datatype repl specs)
31 :     * 3. if VALspec and CONspec are using typspec instead of T.ty, then
32 :     * the whole thing can be further cleaned up.
33 :     *)
34 :     and spec
35 : dbm 2571 = TYCspec of {entVar : EP.entVar, info: tycSpecInfo}
36 : blume 902 | STRspec of {entVar : EP.entVar, sign : Signature,
37 :     def : (strDef * int) option, slot : int}
38 :     | FCTspec of {entVar : EP.entVar, sign : fctSig, slot : int}
39 :     | VALspec of {spec : T.ty, slot : int}
40 :     | CONspec of {spec : T.datacon, slot : int option}
41 :    
42 : dbm 2571 (* there are two forms of TYCspec. One for regular, explicitly defined signatures,
43 : dbm 3287 * and the other for inferred signatures, where all the type info is found in the
44 : dbm 2571 * realization. But we need some info for printing in the one case where a
45 : dbm 3287 * realization is not available with the signature, namely the inferred result
46 : dbm 2571 * signature for a functor. *)
47 :     and tycSpecInfo
48 :     = RegTycSpec of {spec : T.tycon, repl: bool, scope: int} (* normal signature *)
49 : dbm 3287 (* repl = true for a datatype replication spec
50 :     * scope deals with insertion of type spec via where clause, where rhs type
51 :     * expression is to be interpreted in an outer scope *)
52 : dbm 2571 | InfTycSpec of {name: S.symbol, arity: int} (* inferred signature *)
53 :    
54 : blume 902 and fctSig
55 :     = FSIG of {kind : S.symbol option,
56 :     paramsig : Signature,
57 :     paramvar : EP.entVar,
58 :     paramsym : S.symbol option,
59 :     bodysig : Signature}
60 :     | ERRORfsig
61 :    
62 : dbm 3287 (* rhs of where clauses in signatures *)
63 : blume 902 and extDef
64 :     = TYCdef of
65 : dbm 3287 {path : SymPath.path, (* lhs of the where defn *)
66 :     tyc : T.tycon, (* tycon representing rhs of where defn *)
67 :     relative : bool} (* true when tyc contains entity paths *)
68 : blume 902 | STRdef of SP.path * strDef
69 :    
70 :     and strDef
71 :     = CONSTstrDef of Structure (* constant *)
72 :     | VARstrDef of Signature * EP.entPath (* relative *)
73 :    
74 :     (* ------------------------- structures and functors ---------------------- *)
75 :    
76 : dbm 3287 (* Structure and Functor are the types providing the static (i.e. type) information
77 :     * associated with a structure or functor, respectively. *)
78 :    
79 :     (* There should be a STRvar analagous to a VALvar, where the access property would
80 :     * be associated with the STRvar, and the Structure type would be concerned only
81 :     * with the static specification of the structure, i.e. the signature and
82 :     * realization. (the prim property would presumably belong to the STRvar).
83 :     * Similarly, there should be a FCTvar type that would contain the access and
84 :     * prim attribues of a functor.
85 :     *)
86 :    
87 : blume 902 and Structure
88 : dbm 3287 = STR of strrec (* the normal "static" representation of a structure *)
89 : blume 902 | STRSIG of {sign: Signature, entPath : EP.entPath}
90 : dbm 3287 | ERRORstr (* for ERROR tolerance *)
91 : blume 902
92 :     and Functor
93 :     = FCT of fctrec
94 :     | ERRORfct
95 :    
96 :     (* ----------------------- entity-related definitions -------------------- *)
97 :    
98 : dbm 3287 (* entity: the essential static info defining with types, structures, functors
99 :     * interpreted (in the case of structures and functors) relative to signatures *)
100 : blume 902 and entity (* elements of a entityEnv *)
101 :     = TYCent of tycEntity
102 :     | STRent of strEntity
103 :     | FCTent of fctEntity
104 :     | ERRORent
105 :     (* no entities for val, con, exn, but this may change *)
106 :    
107 : dbm 3287 (* entity expressions
108 :     * These are used to compute new resulting entities during functor applications.
109 :     * They describe how types are propagated and generated by a functor.
110 :     * Evaluation of entity expressions is defined in EvalEntity. *)
111 : blume 902
112 :     and stampExp
113 : dbm 3287 = GETSTAMP of strExp (* evaluate strExp and extract its structure stamp *)
114 : blume 902 | NEW (* generate a new stamp *)
115 :    
116 :     and tycExp (* expression evaluating to a TYCentity *)
117 : dbm 3285 = VARtyc of EP.entPath (* selection from current entityEnv *)
118 : dbm 2561 | CONSTtyc of T.tycon (* actual tycon *)
119 :     | FORMtyc of T.tycon (* formal tycon *)
120 : blume 902
121 : dbm 2561 and strExp
122 : blume 902 = VARstr of EP.entPath (* selection from current entityEnv *)
123 : dbm 3287 | CONSTstr of strEntity (* a constant referece to an existing str entity *)
124 : blume 902 | STRUCTURE of {stamp : stampExp, entDec : entityDec}
125 :     | APPLY of fctExp * strExp
126 : dbm 3287 (* the arg strExp includes coercions to match the fct param sig *)
127 : blume 902 | LETstr of entityDec * strExp
128 :     | ABSstr of Signature * strExp (* shortcut for abstraction matching *)
129 :     | FORMstr of fctSig (* formal functor body structure *)
130 :     | CONSTRAINstr of {boundvar : EP.entVar, raw : strExp, coercion: strExp}
131 :     (* similar to LETstr(M.STRdec(boundvar, strExp), coercion),
132 :     * but with special treatment of rpath propagation to support
133 :     * accurate type names in functor results where the functor has
134 :     * a result signature constraint. *)
135 :    
136 : dbm 3368 (*
137 : dbm 3367 and primary
138 : dbm 3368 = PrimaryTyc of T.tycon * EntPath.entPath
139 : dbm 3367 | PrimaryFct of Stamps.stamp * fctSig * EntPath.entPath
140 : dbm 3368 *)
141 : dbm 3367
142 : dbm 3368 (* primarySig : info used (in conjunction with param instantiation, to compute
143 :     * abstraction kinds for functors *)
144 :     and primarySig
145 :     = PrimaryTyc of int (* tycon arity *)
146 :     | PrimaryFct of fctSig (* formal functor signature *)
147 :    
148 : blume 902 and fctExp
149 : dbm 3287 = VARfct of EP.entPath (* selection from current entityEnv *)
150 :     | CONSTfct of fctEntity (* a constant reference to an existing fct entity *)
151 : dbm 3368 | LAMBDA of {param : EP.entVar, body : strExp}
152 : blume 902 | LETfct of entityDec * fctExp
153 :    
154 :     and entityExp
155 :     = TYCexp of tycExp
156 :     | STRexp of strExp
157 :     | FCTexp of fctExp
158 :     | DUMMYexp
159 :     | ERRORexp
160 :    
161 :     and entityDec
162 :     = TYCdec of EP.entVar * tycExp
163 :     | STRdec of EP.entVar * strExp * S.symbol
164 :     | FCTdec of EP.entVar * fctExp
165 :     | SEQdec of entityDec list
166 :     | LOCALdec of entityDec * entityDec
167 : dbm 3287 | EMPTYdec (* could use SEQdec [] instead? *)
168 : blume 902 | ERRORdec
169 :    
170 : dbm 3287 and fctClosure (* core realization for functors *)
171 :     = CLOSURE of {param : EP.entVar, body : strExp, env : entityEnv}
172 :    
173 :     (* entity environments
174 :     * map from entity variables to entities *)
175 : blume 902 and entityEnv
176 :     = MARKeenv of envrec
177 :     | BINDeenv of entity EP.EvDict.map * entityEnv
178 :     | NILeenv
179 :     | ERReenv
180 :    
181 : dbm 3287 (* modtree: an auxiliary structure used in pickle isolation, appears in stubinfo *)
182 : dbm 2541 and modtree
183 :     = TYCNODE of Types.gtrec
184 : blume 902 | SIGNODE of sigrec
185 :     | STRNODE of strrec
186 :     | FCTNODE of fctrec
187 :     | ENVNODE of envrec
188 :     | BRANCH of modtree list
189 :    
190 :     withtype stubinfo =
191 :     {owner : PersStamps.persstamp,
192 :     lib : bool,
193 :     tree : modtree}
194 :    
195 : dbm 3368 and primary = primarySig * ST.stamp * EP.entPath
196 :    
197 : dbm 2532 and elements = (S.symbol * spec) list
198 :    
199 : blume 902 and sigrec =
200 :     {stamp : ST.stamp,
201 :     name : S.symbol option,
202 :     closed : bool,
203 :     fctflag : bool,
204 : dbm 2532 elements : elements,
205 : blume 902 typsharing : sharespec list,
206 :     strsharing : sharespec list,
207 : dbm 3287 stub : stubinfo option,
208 :     properties : PropList.holder} (* FLINT: (entpath * tkind) list option *)
209 : blume 902
210 : dbm 3290 (* strEntity and fctEntity
211 :     * realizations: the essential static descriptions for structures and functors
212 :     * relative to corresponding signatures. This is the "statically volatile
213 :     * information that varies between different instantiations of the signatures *)
214 :    
215 :     and strEntity =
216 :     {stamp : ST.stamp, (* structure stamp *)
217 :     entities : entityEnv, (* the realizations of the static elements
218 :     * specified in the structure signature *)
219 :     rpath : IP.path, (* reverse symbolic path of structure *)
220 :     stub : stubinfo option, (* for pickling isolation *)
221 :     properties: PropList.holder} (* FLINT: lambdaty memoization *)
222 :    
223 :     and fctEntity =
224 :     {stamp : ST.stamp,
225 : dbm 3368 exp : fctExp, (* INVARIANT: always a LAMBDA *)
226 : dbm 3346 closureEnv : entityEnv,
227 : dbm 3368 primaries : primary list,
228 :     paramEnv : entityEnv, (* entities of parameter instantiation *)
229 : dbm 3346 rpath : IP.path, (* reverse symbolic path name of the functor *)
230 :     stub : stubinfo option, (* for pickling isolation *)
231 : dbm 3290 properties: PropList.holder} (* FLINT: lambdaty memoization *)
232 :    
233 : dbm 3287 (* contents of a STR. named because also used in modtree/STRNODE *)
234 : blume 902 and strrec =
235 :     {sign : Signature,
236 :     rlzn : strEntity,
237 :     access : A.access,
238 : blume 2222 prim : PrimOpId.strPrimInfo}
239 : dbm 3287 (* access and prim belong in a separate STRvar type, since they describe
240 :     * the "dynamic" attributes of a structure *)
241 : blume 902
242 : dbm 3287 (* contents of a FCT. named because also used in modtree/FCTNODE *)
243 : blume 902 and fctrec =
244 :     {sign : fctSig,
245 :     rlzn : fctEntity,
246 :     access : A.access,
247 : blume 2222 prim : PrimOpId.strPrimInfo}
248 : dbm 3287 (* access and prim belong in a separate FCTvar type, since they describe
249 :     * the "dynamic" attributes of a functor *)
250 : blume 902
251 : dbm 3287 (* envrec: chunks of entity evns are marked with a stamp and stubbed for
252 :     * pickling isolation *)
253 :     and envrec =
254 :     {stamp : ST.stamp,
255 :     env : entityEnv,
256 :     stub : stubinfo option}
257 :    
258 :     (* a tycEntity is just a tycon. The stamp and arity of the tycon are critical. *)
259 : blume 902 and tycEntity = T.tycon
260 :    
261 :    
262 : dbm 3287 (* some default/error values *)
263 :    
264 : blume 902 val bogusStrStamp = ST.special "bogusStr"
265 :     val bogusFctStamp = ST.special "bogusFct"
266 :     val bogusSigStamp = ST.special "bogusSig"
267 :     val bogusRpath = IP.IPATH[S.strSymbol "Bogus"]
268 :    
269 :     val bogusStrEntity : strEntity =
270 :     { stamp = bogusStrStamp,
271 :     entities = ERReenv,
272 :     rpath = bogusRpath,
273 : dbm 3299 stub = NONE,
274 :     properties = PropList.newHolder ()}
275 : blume 902
276 :     val bogusSig : Signature =
277 :     SIG {stamp = bogusSigStamp,
278 :     name=NONE, closed=true, fctflag=false,
279 :     elements=[],
280 :     typsharing=[], strsharing=[],
281 : dbm 3299 stub = NONE,
282 :     properties = PropList.newHolder ()}
283 : blume 902
284 :     val bogusFctEntity : fctEntity =
285 :     {stamp = bogusFctStamp,
286 : gkuan 3345 exp = LAMBDA {param=EP.bogusEntVar,
287 :     body=CONSTstr bogusStrEntity},
288 :     closureEnv = NILeenv,
289 : gkuan 3376 primaries=[],
290 :     paramEnv=ERReenv,
291 : blume 902 rpath = bogusRpath,
292 : dbm 3299 stub = NONE,
293 :     properties = PropList.newHolder ()}
294 : blume 902
295 :     end (* local *)
296 :     end (* structure Modules *)

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