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

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