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 3346 - (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 :     and fctExp
137 : dbm 3287 = VARfct of EP.entPath (* selection from current entityEnv *)
138 :     | CONSTfct of fctEntity (* a constant reference to an existing fct entity *)
139 : dbm 3346 | LAMBDA of {param : EP.entVar,
140 :     body : strExp,
141 :     primaries: Types.tycon list * (ST.stamp * fctsig) list}
142 :     (* these become FLINT type variables *)
143 : blume 902 | LETfct of entityDec * fctExp
144 :    
145 :     and entityExp
146 :     = TYCexp of tycExp
147 :     | STRexp of strExp
148 :     | FCTexp of fctExp
149 :     | DUMMYexp
150 :     | ERRORexp
151 :    
152 :     and entityDec
153 :     = TYCdec of EP.entVar * tycExp
154 :     | STRdec of EP.entVar * strExp * S.symbol
155 :     | FCTdec of EP.entVar * fctExp
156 :     | SEQdec of entityDec list
157 :     | LOCALdec of entityDec * entityDec
158 : dbm 3287 | EMPTYdec (* could use SEQdec [] instead? *)
159 : blume 902 | ERRORdec
160 :    
161 : dbm 3287 and fctClosure (* core realization for functors *)
162 :     = CLOSURE of {param : EP.entVar, body : strExp, env : entityEnv}
163 :    
164 :     (* entity environments
165 :     * map from entity variables to entities *)
166 : blume 902 and entityEnv
167 :     = MARKeenv of envrec
168 :     | BINDeenv of entity EP.EvDict.map * entityEnv
169 :     | NILeenv
170 :     | ERReenv
171 :    
172 : dbm 3287 (* modtree: an auxiliary structure used in pickle isolation, appears in stubinfo *)
173 : dbm 2541 and modtree
174 :     = TYCNODE of Types.gtrec
175 : blume 902 | SIGNODE of sigrec
176 :     | STRNODE of strrec
177 :     | FCTNODE of fctrec
178 :     | ENVNODE of envrec
179 :     | BRANCH of modtree list
180 :    
181 :     withtype stubinfo =
182 :     {owner : PersStamps.persstamp,
183 :     lib : bool,
184 :     tree : modtree}
185 :    
186 : dbm 2532 and elements = (S.symbol * spec) list
187 :    
188 : blume 902 and sigrec =
189 :     {stamp : ST.stamp,
190 :     name : S.symbol option,
191 :     closed : bool,
192 :     fctflag : bool,
193 : dbm 2532 elements : elements,
194 : blume 902 typsharing : sharespec list,
195 :     strsharing : sharespec list,
196 : dbm 3287 stub : stubinfo option,
197 :     properties : PropList.holder} (* FLINT: (entpath * tkind) list option *)
198 : blume 902
199 : dbm 3290 (* strEntity and fctEntity
200 :     * realizations: the essential static descriptions for structures and functors
201 :     * relative to corresponding signatures. This is the "statically volatile
202 :     * information that varies between different instantiations of the signatures *)
203 :    
204 :     and strEntity =
205 :     {stamp : ST.stamp, (* structure stamp *)
206 :     entities : entityEnv, (* the realizations of the static elements
207 :     * specified in the structure signature *)
208 :     rpath : IP.path, (* reverse symbolic path of structure *)
209 :     stub : stubinfo option, (* for pickling isolation *)
210 :     properties: PropList.holder} (* FLINT: lambdaty memoization *)
211 :    
212 :     and fctEntity =
213 :     {stamp : ST.stamp,
214 : dbm 3346 exp : fctExp, (* INVARIANT: always a LAMBDA (includes primaries) *)
215 :     closureEnv : entityEnv,
216 :     rpath : IP.path, (* reverse symbolic path name of the functor *)
217 :     stub : stubinfo option, (* for pickling isolation *)
218 : dbm 3290 properties: PropList.holder} (* FLINT: lambdaty memoization *)
219 :    
220 : dbm 3287 (* contents of a STR. named because also used in modtree/STRNODE *)
221 : blume 902 and strrec =
222 :     {sign : Signature,
223 :     rlzn : strEntity,
224 :     access : A.access,
225 : blume 2222 prim : PrimOpId.strPrimInfo}
226 : dbm 3287 (* access and prim belong in a separate STRvar type, since they describe
227 :     * the "dynamic" attributes of a structure *)
228 : blume 902
229 : dbm 3287 (* contents of a FCT. named because also used in modtree/FCTNODE *)
230 : blume 902 and fctrec =
231 :     {sign : fctSig,
232 :     rlzn : fctEntity,
233 :     access : A.access,
234 : blume 2222 prim : PrimOpId.strPrimInfo}
235 : dbm 3287 (* access and prim belong in a separate FCTvar type, since they describe
236 :     * the "dynamic" attributes of a functor *)
237 : blume 902
238 : dbm 3287 (* envrec: chunks of entity evns are marked with a stamp and stubbed for
239 :     * pickling isolation *)
240 :     and envrec =
241 :     {stamp : ST.stamp,
242 :     env : entityEnv,
243 :     stub : stubinfo option}
244 :    
245 :     (* a tycEntity is just a tycon. The stamp and arity of the tycon are critical. *)
246 : blume 902 and tycEntity = T.tycon
247 :    
248 :    
249 : dbm 3287 (* some default/error values *)
250 :    
251 : blume 902 val bogusStrStamp = ST.special "bogusStr"
252 :     val bogusFctStamp = ST.special "bogusFct"
253 :     val bogusSigStamp = ST.special "bogusSig"
254 :     val bogusRpath = IP.IPATH[S.strSymbol "Bogus"]
255 :    
256 :     val bogusStrEntity : strEntity =
257 :     { stamp = bogusStrStamp,
258 :     entities = ERReenv,
259 :     rpath = bogusRpath,
260 : dbm 3299 stub = NONE,
261 :     properties = PropList.newHolder ()}
262 : blume 902
263 :     val bogusSig : Signature =
264 :     SIG {stamp = bogusSigStamp,
265 :     name=NONE, closed=true, fctflag=false,
266 :     elements=[],
267 :     typsharing=[], strsharing=[],
268 : dbm 3299 stub = NONE,
269 :     properties = PropList.newHolder ()}
270 : blume 902
271 :     val bogusFctEntity : fctEntity =
272 :     {stamp = bogusFctStamp,
273 : gkuan 3345 exp = LAMBDA {param=EP.bogusEntVar,
274 :     paramRlzn=bogusStrEntity,
275 :     primaries=[],
276 :     body=CONSTstr bogusStrEntity},
277 :     closureEnv = NILeenv,
278 :     (* closure = CLOSURE{param=EP.bogusEntVar,
279 : blume 902 body= CONSTstr bogusStrEntity,
280 : gkuan 3345 env=NILeenv}, *)
281 : blume 902 rpath = bogusRpath,
282 : dbm 3299 stub = NONE,
283 :     properties = PropList.newHolder ()}
284 : blume 902
285 :     end (* local *)
286 :     end (* structure Modules *)

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