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/semant/semant.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/semant/semant.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 537 - (view) (download)

1 : blume 267 (*
2 :     * semantic actions to go with the grammar for CM description files
3 :     *
4 :     * (C) 1999 Lucent Technologies, Bell Laboratories
5 :     *
6 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7 :     *)
8 : blume 265 signature CM_SEMANT = sig
9 :    
10 : blume 354 type context = SrcPath.context
11 :     type pathname = SrcPath.t
12 : blume 297 type region = GenericVC.SourceMap.region
13 : blume 265 type ml_symbol
14 :     type cm_symbol
15 : blume 380 type cm_class
16 : blume 265
17 : blume 294 type group = GroupGraph.group
18 : blume 265
19 : blume 305 type privilegespec
20 : blume 265 type aexp
21 :     type exp
22 :     type members (* still conditional *)
23 :     type exports (* still conditional *)
24 :    
25 : blume 266 type complainer = string -> unit
26 :    
27 : blume 267 (* getting elements of primitive types (pathnames and symbols) *)
28 : blume 270 val file_native : string * context -> pathname
29 : blume 318 val file_standard : GeneralParams.info -> string * context -> pathname
30 : blume 265 val cm_symbol : string -> cm_symbol
31 :     val ml_structure : string -> ml_symbol
32 :     val ml_signature : string -> ml_symbol
33 :     val ml_functor : string -> ml_symbol
34 :     val ml_funsig : string -> ml_symbol
35 : blume 380 val class : cm_symbol -> cm_class
36 : blume 265
37 : blume 270 (* getting the full analysis for a group/library *)
38 : blume 283 val emptyGroup : pathname -> group
39 :     val group :
40 : blume 364 pathname * privilegespec * exports option * members *
41 : blume 537 GeneralParams.info * pathname option * pathname option * complainer *
42 :     GroupGraph.group (* init group *)
43 : blume 283 -> group
44 :     val library :
45 : blume 364 pathname * privilegespec * exports * members *
46 : blume 537 GeneralParams.info *
47 :     GroupGraph.group (* init group *)
48 : blume 283 -> group
49 : blume 265
50 : blume 283 (* assembling privilege lists *)
51 :     val initialPrivilegeSpec : privilegespec
52 :     val require : privilegespec * cm_symbol * complainer -> privilegespec
53 : blume 348 val wrap : privilegespec * cm_symbol * complainer -> privilegespec
54 : blume 265
55 : blume 267 (* constructing member collections *)
56 : blume 265 val emptyMembers : members
57 : blume 297 val member :
58 : blume 518 GeneralParams.info * (pathname option -> pathname -> group) *
59 :     (string -> bool)
60 : blume 493 -> { name: string, mkpath: string -> pathname,
61 :     group: pathname * region, class: cm_class option,
62 :     context: SrcPath.context }
63 : blume 270 -> members
64 : blume 265 val members : members * members -> members
65 : blume 443 val guarded_members :
66 :     exp * (members * members) * (string -> unit) -> members
67 : blume 275 val error_member : (unit -> unit) -> members
68 : blume 265
69 : blume 267 (* constructing export lists *)
70 : blume 265 val emptyExports : exports
71 : blume 356 val export : ml_symbol * complainer -> exports
72 : blume 265 val exports : exports * exports -> exports
73 : blume 275 val guarded_exports :
74 :     exp * (exports * exports) * (string -> unit) -> exports
75 :     val error_export : (unit -> unit) -> exports
76 : blume 265
77 : blume 267 (* arithmetic (number-valued) expression *)
78 : blume 265 val number : int -> aexp
79 : blume 336 val variable : GeneralParams.info -> cm_symbol -> aexp
80 : blume 265 val plus : aexp * aexp -> aexp
81 :     val minus : aexp * aexp -> aexp
82 :     val times : aexp * aexp -> aexp
83 :     val divide : aexp * aexp -> aexp
84 :     val modulus : aexp * aexp -> aexp
85 :     val negate : aexp -> aexp
86 :    
87 : blume 267 (* (bool-valued) expressions *)
88 : blume 265 val ml_defined : ml_symbol -> exp
89 : blume 336 val cm_defined : GeneralParams.info -> cm_symbol -> exp
90 : blume 265 val conj : exp * exp -> exp
91 :     val disj : exp * exp -> exp
92 :     val beq : exp * exp -> exp
93 :     val bne : exp * exp -> exp
94 :     val not : exp -> exp
95 :     val lt : aexp * aexp -> exp
96 :     val le : aexp * aexp -> exp
97 :     val gt : aexp * aexp -> exp
98 :     val ge : aexp * aexp -> exp
99 :     val eq : aexp * aexp -> exp
100 :     val ne : aexp * aexp -> exp
101 :     end
102 :    
103 :     structure CMSemant :> CM_SEMANT = struct
104 :    
105 : blume 267 structure SymPath = GenericVC.SymPath
106 : blume 294 structure EM = GenericVC.ErrorMsg
107 :     structure GG = GroupGraph
108 : blume 267
109 : blume 354 type pathname = SrcPath.t
110 :     type context = SrcPath.context
111 : blume 297 type region = GenericVC.SourceMap.region
112 : blume 267 type ml_symbol = Symbol.symbol
113 : blume 265 type cm_symbol = string
114 : blume 380 type cm_class = string
115 : blume 265
116 : blume 294 type group = GG.group
117 : blume 348 type privilegespec = { required: GG.privileges, wrapped: GG.privileges }
118 : blume 265
119 : blume 268 type environment = MemberCollection.collection
120 : blume 265
121 :     type aexp = environment -> int
122 :     type exp = environment -> bool
123 : blume 367 type members = environment * pathname option -> MemberCollection.collection
124 : blume 267 type exports = environment -> SymbolSet.set
125 : blume 265
126 : blume 266 type complainer = string -> unit
127 :    
128 : blume 275 fun saveEval (exp, env, error) =
129 : blume 267 exp env
130 :     handle exn =>
131 : blume 275 (error ("expression raises exception: " ^ General.exnMessage exn);
132 :     false)
133 : blume 267
134 : blume 354 fun file_native (s, d) = SrcPath.native { context = d, spec = s }
135 : blume 318 fun file_standard (gp: GeneralParams.info) (s, d) =
136 : blume 354 SrcPath.standard (#pcmode (#param gp)) { context = d, spec = s }
137 : blume 265 fun cm_symbol s = s
138 : blume 267 val ml_structure = Symbol.strSymbol
139 :     val ml_signature = Symbol.sigSymbol
140 :     val ml_functor = Symbol.fctSymbol
141 :     val ml_funsig = Symbol.fsigSymbol
142 : blume 265
143 : blume 380 fun class s = String.map Char.toLower s
144 :    
145 : blume 282 fun applyTo mc e = e mc
146 :    
147 : blume 283 fun emptyGroup path =
148 : blume 294 GG.GROUP { exports = SymbolMap.empty,
149 : blume 537 kind = GG.NOLIB [],
150 : blume 305 required = StringSet.empty,
151 : blume 294 grouppath = path,
152 : blume 348 sublibs = [] }
153 : blume 282
154 : blume 340 fun sgl2sll subgroups = let
155 : blume 444 fun sameSL (p, g) (p', g') = SrcPath.compare (p, p') = EQUAL
156 : blume 340 fun add (x, l) =
157 :     if List.exists (sameSL x) l then l else x :: l
158 : blume 444 fun oneSG (x as (_, GG.GROUP { kind, sublibs, ... }), l) =
159 : blume 348 case kind of
160 : blume 537 GG.NOLIB _ => foldl add l sublibs
161 : blume 348 | _ => add (x, l)
162 : blume 340 in
163 :     foldl oneSG [] subgroups
164 :     end
165 :    
166 : blume 537 fun grouplib (islib, g, p, e, m, gp, curlib, init_group) = let
167 :     val mc = applyTo (MemberCollection.implicit init_group, curlib) m
168 : blume 283 val filter = Option.map (applyTo mc) e
169 : blume 537 val pfsbn = let
170 :     val GroupGraph.GROUP { exports, ... } = init_group
171 :     in
172 :     #1 (valOf (SymbolMap.find (exports, PervCoreAccess.pervStrSym)))
173 :     end
174 :     val (exports, rp) = MemberCollection.build (mc, filter, gp, pfsbn)
175 : blume 294 val subgroups = MemberCollection.subgroups mc
176 : blume 348 val { required = rp', wrapped = wr } = p
177 :     val rp'' = StringSet.union (rp', StringSet.union (rp, wr))
178 : blume 280 in
179 : blume 348 GG.GROUP { exports = exports,
180 : blume 537 kind = if islib then GG.LIB (wr, subgroups)
181 : blume 348 else (if StringSet.isEmpty wr then ()
182 :     else EM.impossible
183 :     "group with wrapped privilege";
184 : blume 537 GG.NOLIB subgroups),
185 : blume 348 required = rp'',
186 : blume 305 grouppath = g,
187 : blume 348 sublibs = sgl2sll subgroups }
188 : blume 280 end
189 :    
190 : blume 537 fun group (g, p, e, m, gp, curlib, owner, error, init_group) = let
191 : blume 367 fun libname NONE = "<toplevel>"
192 :     | libname (SOME p) = SrcPath.descr p
193 :     fun eq (NONE, NONE) = true
194 :     | eq (SOME p, SOME p') = SrcPath.compare (p, p') = EQUAL
195 :     | eq _ = false
196 :     fun checkowner () =
197 :     if eq (curlib, owner) then ()
198 :     else error (concat ["owner specified as ",
199 :     libname owner, " but found to be ",
200 :     libname curlib])
201 :     in
202 :     checkowner ();
203 : blume 537 grouplib (false, g, p, e, m, gp, curlib, init_group)
204 : blume 367 end
205 : blume 537 fun library (g, p, e, m, gp, init_group) =
206 :     grouplib (true, g, p, SOME e, m, gp, SOME g, init_group)
207 : blume 265
208 : blume 266 local
209 : blume 267 val isMember = StringSet.member
210 : blume 348 fun sanity ({ required, wrapped }, s, error) =
211 :     if isMember (required, s) orelse isMember (wrapped, s) then
212 : blume 283 error ("duplicate privilege name: " ^ s)
213 : blume 266 else ()
214 :     in
215 : blume 283 val initialPrivilegeSpec = { required = StringSet.empty,
216 : blume 348 wrapped = StringSet.empty }
217 :     fun require (a as ({ required, wrapped }, s, _)) =
218 : blume 266 (sanity a;
219 : blume 348 { required = StringSet.add (required, s), wrapped = wrapped })
220 :     fun wrap (a as ({ required, wrapped }, s, _)) =
221 : blume 266 (sanity a;
222 : blume 348 { required = required, wrapped = StringSet.add (wrapped, s) })
223 : blume 266 end
224 : blume 265
225 : blume 367 fun emptyMembers (env, _) = env
226 : blume 518 fun member (gp, rparse, ldpi) arg (env, curlib) = let
227 :     val coll = MemberCollection.expandOne (gp, rparse curlib, ldpi) arg
228 : blume 297 val group = #group arg
229 : blume 299 val error = GroupReg.error (#groupreg gp) group
230 : blume 294 fun e0 s = error EM.COMPLAIN s EM.nullErrorBody
231 : blume 270 in
232 : blume 277 MemberCollection.sequential (env, coll, e0)
233 : blume 270 end
234 : blume 367 fun members (m1, m2) (env, curlib) = m2 (m1 (env, curlib), curlib)
235 :     fun guarded_members (c, (m1, m2), error) (env, curlib) =
236 :     if saveEval (c, env, error) then m1 (env, curlib) else m2 (env, curlib)
237 :     fun error_member thunk (env, _) = (thunk (); env)
238 : blume 265
239 : blume 267 fun emptyExports env = SymbolSet.empty
240 : blume 356 fun export (s, error) env =
241 :     if MemberCollection.ml_look env s then SymbolSet.singleton s
242 :     else (error (concat ["exported ",
243 :     Symbol.nameSpaceToString (Symbol.nameSpace s),
244 :     " not defined: ", Symbol.name s]);
245 :     SymbolSet.empty)
246 : blume 267 fun exports (e1, e2) env = SymbolSet.union (e1 env, e2 env)
247 : blume 275 fun guarded_exports (c, (e1, e2), error) env =
248 :     if saveEval (c, env, error) then e1 env else e2 env
249 :     fun error_export thunk env = (thunk (); SymbolSet.empty)
250 : blume 265
251 :     fun number i _ = i
252 : blume 336 fun variable gp v e = MemberCollection.num_look gp e v
253 : blume 265 fun plus (e1, e2) e = e1 e + e2 e
254 :     fun minus (e1, e2) e = e1 e - e2 e
255 :     fun times (e1, e2) e = e1 e * e2 e
256 :     fun divide (e1, e2) e = e1 e div e2 e
257 :     fun modulus (e1, e2) e = e1 e mod e2 e
258 :     fun negate ex e = ~(ex e)
259 :    
260 : blume 267 fun ml_defined s e = MemberCollection.ml_look e s
261 : blume 336 fun cm_defined gp s e = MemberCollection.cm_look gp e s
262 : blume 265 fun conj (e1, e2) e = e1 e andalso e2 e
263 :     fun disj (e1, e2) e = e1 e orelse e2 e
264 :     fun beq (e1: exp, e2) e = e1 e = e2 e
265 :     fun bne (e1: exp, e2) e = e1 e <> e2 e
266 :     fun not ex e = Bool.not (ex e)
267 :     fun lt (e1, e2) e = e1 e < e2 e
268 :     fun le (e1, e2) e = e1 e <= e2 e
269 :     fun gt (e1, e2) e = e1 e > e2 e
270 :     fun ge (e1, e2) e = e1 e >= e2 e
271 :     fun eq (e1: aexp, e2) e = e1 e = e2 e
272 :     fun ne (e1: aexp, e2) e = e1 e <> e2 e
273 :     end

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