Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/typechecker/util.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/typechecker/util.sml

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

revision 1970, Sun Jul 15 14:20:23 2012 UTC revision 1971, Sun Jul 15 16:24:43 2012 UTC
# Line 21  Line 21 
21    
22      val matchType : Types.ty * Types.ty -> match      val matchType : Types.ty * Types.ty -> match
23    
24        val tryMatchType : Types.ty * Types.ty -> match
25    
26      val equalType : Types.ty * Types.ty -> bool      val equalType : Types.ty * Types.ty -> bool
27      val equalTypes : Types.ty list * Types.ty list -> bool      val equalTypes : Types.ty list * Types.ty list -> bool
28    
29      val tryMatchType : Types.ty * Types.ty -> bool      val tryEqualType : Types.ty * Types.ty -> bool
30      val tryMatchTypes : Types.ty list * Types.ty list -> bool      val tryEqualTypes : Types.ty list * Types.ty list -> bool
31    
32      val instantiate : Types.scheme -> (Types.meta_var list * Types.ty)      val instantiate : Types.scheme -> (Types.meta_var list * Types.ty)
33    
# Line 161  Line 163 
163              match (TU.pruneHead ty1, TU.pruneHead ty2)              match (TU.pruneHead ty1, TU.pruneHead ty2)
164            end            end
165    
166      fun equalTypes (tys1, tys2) = let      fun unifyTypeWithCoercion (pl, ty1, ty2) = (case (TU.pruneHead ty1, TU.pruneHead ty2)
           val pl = ref[]  
           in  
             ListPair.allEq (fn (ty1, ty2) => unifyType(pl, ty1, ty2)) (tys1, tys2)  
           end  
   
     fun equalType (ty1, ty2) = unifyType (ref[], ty1, ty2)  
   
 (* TODO: add removal of differentiation *)  
     fun matchType (ty1, ty2) = (case (TU.pruneHead ty1, TU.pruneHead ty2)  
167             of (Ty.T_Tensor(Ty.Shape[]), Ty.T_Int) => COERCE             of (Ty.T_Tensor(Ty.Shape[]), Ty.T_Int) => COERCE
168              | (Ty.T_DynSequence ty1, Ty.T_Sequence(ty2, _)) =>              | (Ty.T_DynSequence ty1, Ty.T_Sequence(ty2, _)) =>
169                  if equalType(ty1, ty2) then COERCE else FAIL                  if unifyType(pl, ty1, ty2) then COERCE else FAIL
170              | (Ty.T_Field{diff=k1, dim=d1, shape=s1}, Ty.T_Field{diff=k2, dim=d2, shape=s2}) =>              | (Ty.T_Field{diff=k1, dim=d1, shape=s1}, Ty.T_Field{diff=k2, dim=d2, shape=s2}) =>
171                  if equalType (ty1, ty2)                  if unifyType(pl, ty1, ty2)
172                    then EQ                    then EQ
173                  else if matchDiff (k1, k2) andalso equalDim(ref[], d1, d2)                  else if matchDiff (k1, k2) andalso equalDim(pl, d1, d2)
174                  andalso equalShape(ref[], s1, s2)                  andalso equalShape(pl, s1, s2)
175                    then COERCE                    then COERCE
176                    else FAIL                    else FAIL
177              | (ty1, ty2) => if equalType(ty1, ty2) then EQ else FAIL              | (ty1, ty2) => if unifyType(pl, ty1, ty2) then EQ else FAIL
178            (* end case *))            (* end case *))
179    
180        fun equalTypes (tys1, tys2) = let
181              val pl = ref[]
182              in
183                ListPair.allEq (fn (ty1, ty2) => unifyType(pl, ty1, ty2)) (tys1, tys2)
184              end
185    
186        fun equalType (ty1, ty2) = unifyType (ref[], ty1, ty2)
187    
188    (* try to match types; if we fail, all meta-variable bindings are undone *)    (* try to match types; if we fail, all meta-variable bindings are undone *)
189      fun tryMatchType (ty1, ty2) = let      fun tryEqualType (ty1, ty2) = let
190            val pl = ref[]            val pl = ref[]
191            in            in
192              unifyType(pl, ty1, ty2) orelse (undo pl; false)              unifyType(pl, ty1, ty2) orelse (undo pl; false)
193            end            end
194    
195    (* try to match types; if we fail, all meta-variable bindings are undone *)    (* try to unify two types to equality; if we fail, all meta-variable bindings are undone *)
196      fun tryMatchTypes (tys1, tys2) = let      fun tryEqualTypes (tys1, tys2) = let
197            val pl = ref[]            val pl = ref[]
198            in            in
199              ListPair.allEq (fn (ty1, ty2) => unifyType(pl, ty1, ty2)) (tys1, tys2)              ListPair.allEq (fn (ty1, ty2) => unifyType(pl, ty1, ty2)) (tys1, tys2)
200              orelse (undo pl; false)              orelse (undo pl; false)
201            end            end
202    
203        fun matchType (ty1, ty2) = unifyTypeWithCoercion (ref[], ty1, ty2)
204    
205      (* try to unify two type lists to equality; if we fail, all meta-variable bindings are undone *)
206        fun tryMatchType (ty1, ty2) = let
207              val pl = ref[]
208              in
209                case unifyTypeWithCoercion (pl, ty1, ty2)
210                 of FAIL => (undo pl; FAIL)
211                  | result => result
212                (* end case *)
213              end
214    
215    (* rebind equalDim without patch-list argument *)    (* rebind equalDim without patch-list argument *)
216      val equalDim = fn (d1, d2) => equalDim(ref [], d1, d2)      val equalDim = fn (d1, d2) => equalDim(ref [], d1, d2)
217    

Legend:
Removed from v.1970  
changed lines
  Added in v.1971

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