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 286 - (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 270 type context = AbsPath.context
11 : blume 268 type pathname = AbsPath.t
12 : blume 265 type ml_symbol
13 :     type cm_symbol
14 :    
15 :     type group
16 :    
17 : blume 283 type privileges
18 :     type privilegespec
19 : blume 265 type aexp
20 :     type exp
21 :     type members (* still conditional *)
22 :     type exports (* still conditional *)
23 :    
24 : blume 266 type complainer = string -> unit
25 :    
26 : blume 267 (* getting elements of primitive types (pathnames and symbols) *)
27 : blume 270 val file_native : string * context -> pathname
28 :     val file_standard : string * context -> pathname
29 : blume 265 val cm_symbol : string -> cm_symbol
30 :     val ml_structure : string -> ml_symbol
31 :     val ml_signature : string -> ml_symbol
32 :     val ml_functor : string -> ml_symbol
33 :     val ml_funsig : string -> ml_symbol
34 :    
35 : blume 270 (* getting the full analysis for a group/library *)
36 : blume 283 val emptyGroup : pathname -> group
37 :     val group :
38 :     pathname * privilegespec * exports option * members * complainer
39 :     -> group
40 :     val library :
41 :     pathname * privilegespec * exports * members * complainer
42 :     -> group
43 : blume 265
44 : blume 283 (* assembling privilege lists *)
45 :     val initialPrivilegeSpec : privilegespec
46 :     val require : privilegespec * cm_symbol * complainer -> privilegespec
47 :     val grant : privilegespec * cm_symbol * complainer -> privilegespec
48 : blume 265
49 : blume 267 (* constructing member collections *)
50 : blume 265 val emptyMembers : members
51 : blume 286 val member : GeneralParams.params * (pathname -> group)
52 : blume 275 -> { sourcepath: pathname, group: pathname, class: cm_symbol option,
53 : blume 277 error: string -> (PrettyPrint.ppstream -> unit) -> unit }
54 : blume 270 -> members
55 : blume 265 val members : members * members -> members
56 : blume 275 val guarded_members :
57 :     exp * (members * members) * (string -> unit) -> members
58 :     val error_member : (unit -> unit) -> members
59 : blume 265
60 : blume 267 (* constructing export lists *)
61 : blume 265 val emptyExports : exports
62 :     val export : ml_symbol -> exports
63 :     val exports : exports * exports -> exports
64 : blume 275 val guarded_exports :
65 :     exp * (exports * exports) * (string -> unit) -> exports
66 :     val error_export : (unit -> unit) -> exports
67 : blume 265
68 : blume 267 (* arithmetic (number-valued) expression *)
69 : blume 265 val number : int -> aexp
70 :     val variable : cm_symbol -> aexp
71 :     val plus : aexp * aexp -> aexp
72 :     val minus : aexp * aexp -> aexp
73 :     val times : aexp * aexp -> aexp
74 :     val divide : aexp * aexp -> aexp
75 :     val modulus : aexp * aexp -> aexp
76 :     val negate : aexp -> aexp
77 :    
78 : blume 267 (* (bool-valued) expressions *)
79 : blume 265 val ml_defined : ml_symbol -> exp
80 :     val cm_defined : cm_symbol -> exp
81 :     val conj : exp * exp -> exp
82 :     val disj : exp * exp -> exp
83 :     val beq : exp * exp -> exp
84 :     val bne : exp * exp -> exp
85 :     val not : exp -> exp
86 :     val lt : aexp * aexp -> exp
87 :     val le : aexp * aexp -> exp
88 :     val gt : aexp * aexp -> exp
89 :     val ge : aexp * aexp -> exp
90 :     val eq : aexp * aexp -> exp
91 :     val ne : aexp * aexp -> exp
92 :     end
93 :    
94 :     structure CMSemant :> CM_SEMANT = struct
95 :    
96 : blume 267 structure SymPath = GenericVC.SymPath
97 :    
98 : blume 265 type pathname = AbsPath.t
99 : blume 270 type context = AbsPath.context
100 : blume 267 type ml_symbol = Symbol.symbol
101 : blume 265 type cm_symbol = string
102 :    
103 : blume 283 type privileges = StringSet.set
104 :     type privilegespec = { required : privileges, granted : privileges }
105 : blume 265
106 : blume 283 datatype group =
107 :     GROUP of { exports: DependencyGraph.impexp SymbolMap.map,
108 :     islib: bool,
109 :     privileges: privilegespec,
110 :     grouppath: AbsPath.t }
111 :    
112 : blume 268 type environment = MemberCollection.collection
113 : blume 265
114 :     type aexp = environment -> int
115 :     type exp = environment -> bool
116 : blume 267 type members = environment -> MemberCollection.collection
117 :     type exports = environment -> SymbolSet.set
118 : blume 265
119 : blume 266 type complainer = string -> unit
120 :    
121 : blume 275 fun saveEval (exp, env, error) =
122 : blume 267 exp env
123 :     handle exn =>
124 : blume 275 (error ("expression raises exception: " ^ General.exnMessage exn);
125 :     false)
126 : blume 267
127 : blume 265 fun file_native (s, d) = AbsPath.native { context = d, spec = s }
128 :     fun file_standard (s, d) = AbsPath.standard { context = d, spec = s }
129 :     fun cm_symbol s = s
130 : blume 267 val ml_structure = Symbol.strSymbol
131 :     val ml_signature = Symbol.sigSymbol
132 :     val ml_functor = Symbol.fctSymbol
133 :     val ml_funsig = Symbol.fsigSymbol
134 : blume 265
135 : blume 282 fun applyTo mc e = e mc
136 :    
137 : blume 283 fun emptyGroup path =
138 :     GROUP { exports = SymbolMap.empty,
139 :     islib = false,
140 :     privileges = { required = StringSet.empty,
141 :     granted = StringSet.empty },
142 :     grouppath = path }
143 :    
144 : blume 282
145 : blume 283 fun group (g, p, e, m, error) = let
146 : blume 282 val mc = applyTo MemberCollection.empty m
147 : blume 283 val filter = Option.map (applyTo mc) e
148 :     val exports = MemberCollection.build (mc, filter, error)
149 : blume 280 in
150 : blume 283 GROUP { exports = exports, islib = false,
151 :     privileges = p, grouppath = g }
152 : blume 280 end
153 :    
154 : blume 283 fun library (g, p, e, m, error) = let
155 : blume 282 val mc = applyTo MemberCollection.empty m
156 : blume 283 val filter = applyTo mc e
157 :     val exports = MemberCollection.build (mc, SOME filter, error)
158 : blume 282 in
159 : blume 283 GROUP { exports = exports, islib = true,
160 :     privileges = p, grouppath = g }
161 : blume 282 end
162 : blume 265
163 : blume 266 local
164 : blume 267 val isMember = StringSet.member
165 : blume 266 fun sanity ({ required, granted }, s, error) =
166 : blume 267 if isMember (required, s) orelse isMember (granted, s) then
167 : blume 283 error ("duplicate privilege name: " ^ s)
168 : blume 266 else ()
169 :     in
170 : blume 283 val initialPrivilegeSpec = { required = StringSet.empty,
171 :     granted = StringSet.empty }
172 : blume 266 fun require (a as ({ required, granted }, s, _)) =
173 :     (sanity a;
174 :     { required = StringSet.add (required, s), granted = granted })
175 :     fun grant (a as ({ required, granted }, s, _)) =
176 :     (sanity a;
177 :     { required = required, granted = StringSet.add (granted, s) })
178 :     end
179 : blume 265
180 : blume 270 (* get the export map from a group *)
181 : blume 283 fun getExports (GROUP { exports, islib, ... }) =
182 :     { imports = exports,
183 :     gimports = if islib then SymbolMap.empty else exports }
184 : blume 270
185 : blume 268 fun emptyMembers env = env
186 : blume 286 fun member (params, rparse) arg env = let
187 :     val coll = MemberCollection.expandOne (params, getExports o rparse) arg
188 : blume 275 val error = #error arg
189 : blume 277 fun e0 s = error s GenericVC.ErrorMsg.nullErrorBody
190 : blume 270 in
191 : blume 277 MemberCollection.sequential (env, coll, e0)
192 : blume 270 end
193 : blume 268 fun members (m1, m2) env = m2 (m1 env)
194 : blume 275 fun guarded_members (c, (m1, m2), error) env =
195 :     if saveEval (c, env, error) then m1 env else m2 env
196 :     fun error_member thunk env = (thunk (); env)
197 : blume 265
198 : blume 267 fun emptyExports env = SymbolSet.empty
199 :     fun export s env = SymbolSet.singleton s
200 :     fun exports (e1, e2) env = SymbolSet.union (e1 env, e2 env)
201 : blume 275 fun guarded_exports (c, (e1, e2), error) env =
202 :     if saveEval (c, env, error) then e1 env else e2 env
203 :     fun error_export thunk env = (thunk (); SymbolSet.empty)
204 : blume 265
205 :     fun number i _ = i
206 : blume 267 fun variable v e = MemberCollection.num_look e v
207 : blume 265 fun plus (e1, e2) e = e1 e + e2 e
208 :     fun minus (e1, e2) e = e1 e - e2 e
209 :     fun times (e1, e2) e = e1 e * e2 e
210 :     fun divide (e1, e2) e = e1 e div e2 e
211 :     fun modulus (e1, e2) e = e1 e mod e2 e
212 :     fun negate ex e = ~(ex e)
213 :    
214 : blume 267 fun ml_defined s e = MemberCollection.ml_look e s
215 :     fun cm_defined s e = MemberCollection.cm_look e s
216 : blume 265 fun conj (e1, e2) e = e1 e andalso e2 e
217 :     fun disj (e1, e2) e = e1 e orelse e2 e
218 :     fun beq (e1: exp, e2) e = e1 e = e2 e
219 :     fun bne (e1: exp, e2) e = e1 e <> e2 e
220 :     fun not ex e = Bool.not (ex e)
221 :     fun lt (e1, e2) e = e1 e < e2 e
222 :     fun le (e1, e2) e = e1 e <= e2 e
223 :     fun gt (e1, e2) e = e1 e > e2 e
224 :     fun ge (e1, e2) e = e1 e >= e2 e
225 :     fun eq (e1: aexp, e2) e = e1 e = e2 e
226 :     fun ne (e1: aexp, e2) e = e1 e <> e2 e
227 :     end

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