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

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