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

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