Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/cm/semant/semant.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 265, Fri May 7 08:42:54 1999 UTC revision 274, Fri May 14 05:23:02 1999 UTC
# Line 1  Line 1 
1    (*
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  signature CM_SEMANT = sig  signature CM_SEMANT = sig
9    
10      type pathname      exception ExplicitError of string
11        exception ExpressionError of exn
12    
13        type context = AbsPath.context
14        type pathname = AbsPath.t
15      type ml_symbol      type ml_symbol
16      type cm_symbol      type cm_symbol
17    
18      type group      type group
19    
20      type perm      type perms
21      type aexp      type aexp
22      type exp      type exp
23      type members                        (* still conditional *)      type members                        (* still conditional *)
24      type exports                        (* still conditional *)      type exports                        (* still conditional *)
25    
26      val file_native : string * pathname -> pathname      type complainer = string -> unit
27      val file_standard : string * pathname -> pathname  
28        (* getting elements of primitive types (pathnames and symbols) *)
29        val file_native : string * context -> pathname
30        val file_standard : string * context -> pathname
31      val cm_symbol : string -> cm_symbol      val cm_symbol : string -> cm_symbol
32      val ml_structure : string -> ml_symbol      val ml_structure : string -> ml_symbol
33      val ml_signature : string -> ml_symbol      val ml_signature : string -> ml_symbol
34      val ml_functor : string -> ml_symbol      val ml_functor : string -> ml_symbol
35      val ml_funsig : string -> ml_symbol      val ml_funsig : string -> ml_symbol
36    
37      val alias : pathname -> group      (* getting the full analysis for a group/library *)
38      val group : perm list * exports * members -> group      val emptyGroup : group
39      val library : perm list * exports * members -> group      val group : perms * exports * members -> group
40        val library : perms * exports * members -> group
41      val require : cm_symbol -> perm  
42      val grant : cm_symbol -> perm      (* assembling permission lists *)
43        val initialPerms : perms
44        val require : perms * cm_symbol * complainer -> perms
45        val grant : perms * cm_symbol * complainer -> perms
46    
47        (* constructing member collections *)
48      val emptyMembers : members      val emptyMembers : members
49      val member : pathname * cm_symbol option -> members      val member : (pathname -> group)
50            -> { sourcepath: pathname, group: pathname, class: cm_symbol option }
51            -> members
52      val members : members * members -> members      val members : members * members -> members
53      val guarded_members : exp * (members * members) -> members      val guarded_members : exp * (members * members) -> members
54        val error_member : string -> members
55    
56        (* constructing export lists *)
57      val emptyExports : exports      val emptyExports : exports
58      val export : ml_symbol -> exports      val export : ml_symbol -> exports
59      val exports : exports * exports -> exports      val exports : exports * exports -> exports
60      val guarded_exports : exp * (exports * exports) -> exports      val guarded_exports : exp * (exports * exports) -> exports
61        val error_export : string -> exports
62    
63        (* arithmetic (number-valued) expression *)
64      val number : int -> aexp      val number : int -> aexp
65      val variable : cm_symbol -> aexp      val variable : cm_symbol -> aexp
66      val plus : aexp * aexp -> aexp      val plus : aexp * aexp -> aexp
# Line 46  Line 70 
70      val modulus : aexp * aexp -> aexp      val modulus : aexp * aexp -> aexp
71      val negate : aexp -> aexp      val negate : aexp -> aexp
72    
73        (* (bool-valued) expressions *)
74      val ml_defined : ml_symbol -> exp      val ml_defined : ml_symbol -> exp
75      val cm_defined : cm_symbol -> exp      val cm_defined : cm_symbol -> exp
76      val conj : exp * exp -> exp      val conj : exp * exp -> exp
# Line 59  Line 84 
84      val ge : aexp * aexp -> exp      val ge : aexp * aexp -> exp
85      val eq : aexp * aexp -> exp      val eq : aexp * aexp -> exp
86      val ne : aexp * aexp -> exp      val ne : aexp * aexp -> exp
   
87  end  end
88    
89  structure CMSemant :> CM_SEMANT = struct  structure CMSemant :> CM_SEMANT = struct
90    
91        exception ExplicitError of string
92        exception ExpressionError of exn
93    
94        structure Symbol = GenericVC.Symbol
95        structure SymPath = GenericVC.SymPath
96    
97      type pathname = AbsPath.t      type pathname = AbsPath.t
98      type ml_symbol = unit      type context = AbsPath.context
99        type ml_symbol = Symbol.symbol
100      type cm_symbol = string      type cm_symbol = string
101    
102      type group = unit      type group = Dummy.t
103    
104      type environment = unit      type environment = MemberCollection.collection
105      fun num_look () _ = 0  
106      fun ml_look () _ = false      type perms = { required : StringSet.set, granted : StringSet.set }
     fun cm_look () _ = false  
   
     datatype perm =  
         REQUIRE of cm_symbol  
       | GRANT of cm_symbol  
107    
108      type aexp = environment -> int      type aexp = environment -> int
109      type exp = environment -> bool      type exp = environment -> bool
110      type members = unit      type members = environment -> MemberCollection.collection
111      type exports = unit      type exports = environment -> SymbolSet.set
112    
113        type complainer = string -> unit
114    
115        fun saveEval (exp, env) =
116            exp env
117            handle exn =>
118                raise ExpressionError exn
119    
120      fun file_native (s, d) = AbsPath.native { context = d, spec = s }      fun file_native (s, d) = AbsPath.native { context = d, spec = s }
121      fun file_standard (s, d) = AbsPath.standard { context = d, spec = s }      fun file_standard (s, d) = AbsPath.standard { context = d, spec = s }
122      fun cm_symbol s = s      fun cm_symbol s = s
123      fun ml_structure (s: string) = ()      val ml_structure = Symbol.strSymbol
124      fun ml_signature (s: string) = ()      val ml_signature = Symbol.sigSymbol
125      fun ml_functor (s: string) = ()      val ml_functor = Symbol.fctSymbol
126      fun ml_funsig (s: string) = ()      val ml_funsig = Symbol.fsigSymbol
127    
128      fun alias (f: pathname) = ()      val emptyGroup = Dummy.v
129      fun group (p: perm list, e: exports, m: members) = ()      fun group (p: perms, e: exports, m: members) =
130      fun library (p: perm list, e: exports, m: members) = ()          (ignore (m MemberCollection.empty);
131             Dummy.v)
132      val require = REQUIRE      fun library (p: perms, e: exports, m: members) =
133      val grant = GRANT          (ignore (m MemberCollection.empty);
134             Dummy.v)
135      val emptyMembers = ()  
136      fun member (f: pathname, c: cm_symbol option) = ()      local
137      fun members (m1: members, m2: members) = ()          val isMember = StringSet.member
138      fun guarded_members (c: exp, (m1: members, m2: members)) = ()          fun sanity ({ required, granted }, s, error) =
139                if isMember (required, s) orelse isMember (granted, s) then
140      val emptyExports = ()                  error ("duplicate permission name: " ^ s)
141      fun export (s: ml_symbol) = ()              else ()
142      fun exports (e1: exports, e2: exports) = ()      in
143      fun guarded_exports (c: exp, (e1: exports, e2: exports)) = ()          val initialPerms = { required = StringSet.empty,
144                                 granted = StringSet.empty }
145            fun require (a as ({ required, granted }, s, _)) =
146                (sanity a;
147                 { required = StringSet.add (required, s), granted = granted })
148            fun grant (a as ({ required, granted }, s, _)) =
149                (sanity a;
150                 { required = required, granted = StringSet.add (granted, s) })
151        end
152    
153        (* get the export map from a group *)
154        fun getExports (g: group) = (ignore Dummy.v; SymbolMap.empty)
155    
156        fun emptyMembers env = env
157        fun member rparse arg env = let
158            val coll = MemberCollection.expandOne (getExports o rparse) arg
159        in
160            MemberCollection.sequential (env, coll)
161        end
162        fun members (m1, m2) env = m2 (m1 env)
163        fun guarded_members (c, (m1, m2)) env =
164            if saveEval (c, env) then m1 env else m2 env
165        fun error_member m env =
166            (print (m ^ "\n");
167             raise ExplicitError m)
168    
169        fun emptyExports env = SymbolSet.empty
170        fun export s env = SymbolSet.singleton s
171        fun exports (e1, e2) env = SymbolSet.union (e1 env, e2 env)
172        fun guarded_exports (c, (e1, e2)) env =
173            if saveEval (c, env) then e1 env else e2 env
174        fun error_export m env = raise ExplicitError m
175    
176      fun number i _ = i      fun number i _ = i
177      fun variable v e = num_look e v      fun variable v e = MemberCollection.num_look e v
178      fun plus (e1, e2) e = e1 e + e2 e      fun plus (e1, e2) e = e1 e + e2 e
179      fun minus (e1, e2) e = e1 e - e2 e      fun minus (e1, e2) e = e1 e - e2 e
180      fun times (e1, e2) e = e1 e * e2 e      fun times (e1, e2) e = e1 e * e2 e
# Line 118  Line 182 
182      fun modulus (e1, e2) e = e1 e mod e2 e      fun modulus (e1, e2) e = e1 e mod e2 e
183      fun negate ex e = ~(ex e)      fun negate ex e = ~(ex e)
184    
185      fun ml_defined s e = ml_look e s      fun ml_defined s e = MemberCollection.ml_look e s
186      fun cm_defined s e = cm_look e s      fun cm_defined s e = MemberCollection.cm_look e s
187      fun conj (e1, e2) e = e1 e andalso e2 e      fun conj (e1, e2) e = e1 e andalso e2 e
188      fun disj (e1, e2) e = e1 e orelse e2 e      fun disj (e1, e2) e = e1 e orelse e2 e
189      fun beq (e1: exp, e2) e = e1 e = e2 e      fun beq (e1: exp, e2) e = e1 e = e2 e

Legend:
Removed from v.265  
changed lines
  Added in v.274

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