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

SCM Repository

[diderot] Diff of /trunk/src/compiler/ast/type-util.sml
ViewVC logotype

Diff of /trunk/src/compiler/ast/type-util.sml

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

revision 2355, Sun Apr 7 11:35:08 2013 UTC revision 2356, Sun Apr 7 14:45:25 2013 UTC
# Line 24  Line 24 
24    (* returns true if the type is a value type (bool, int, string, or tensor) *)    (* returns true if the type is a value type (bool, int, string, or tensor) *)
25      val isValueType : Types.ty -> bool      val isValueType : Types.ty -> bool
26    
27      (* return the range (return type) of a function type *)
28        val rngOf : Types.ty -> Types.ty
29    
30    (* prune out instantiated meta variables from a type.  We also normalize    (* prune out instantiated meta variables from a type.  We also normalize
31     * tensor shapes (i.e., remove 1s).     * tensor shapes (i.e., remove 1s).
32     *)     *)
# Line 40  Line 43 
43      val resolveDiff : Types.diff_var -> Types.diff      val resolveDiff : Types.diff_var -> Types.diff
44      val resolveShape : Types.shape_var -> Types.shape      val resolveShape : Types.shape_var -> Types.shape
45      val resolveDim : Types.dim_var -> Types.dim      val resolveDim : Types.dim_var -> Types.dim
46        val resolveVar : Types.meta_var -> Types.var_bind
47    
48    (* equality testing *)    (* equality testing *)
49      val sameDim : Types.dim * Types.dim -> bool      val sameDim : Types.dim * Types.dim -> bool
# Line 50  Line 54 
54      val shapeToString : Types.shape -> string      val shapeToString : Types.shape -> string
55      val dimToString : Types.dim -> string      val dimToString : Types.dim -> string
56    
57      (* convert to fully resolved monomorphic forms *)
58        val monoDim : Types.dim -> int
59        val monoShape : Types.shape -> int list
60        val monoDiff : Types.diff -> int
61    
62    end = struct    end = struct
63    
64      structure Ty = Types      structure Ty = Types
# Line 137  Line 146 
146              | SOME dim => pruneDim dim              | SOME dim => pruneDim dim
147            (* end case *))            (* end case *))
148    
149        fun resolveVar (Ty.TYPE tv) = Ty.TYPE(resolve tv)
150          | resolveVar (Ty.DIFF dv) = Ty.DIFF(resolveDiff dv)
151          | resolveVar (Ty.SHAPE sv) = Ty.SHAPE(resolveShape sv)
152          | resolveVar (Ty.DIM d) = Ty.DIM(resolveDim d)
153    
154    (* prune the head of a type *)    (* prune the head of a type *)
155      fun pruneHead ty = let      fun pruneHead ty = let
156            fun prune' (ty as Ty.T_Var(Ty.TV{bind, ...})) = (case !bind            fun prune' (ty as Ty.T_Var(Ty.TV{bind, ...})) = (case !bind
# Line 232  Line 246 
246                  end                  end
247            (* end case *))            (* end case *))
248    
249      (* return the range (return type) of a function type *)
250        fun rngOf (Ty.T_Fun(_, ty)) = ty
251          | rngOf ty = raise Fail(concat["TypeUtil.rngOf(", toString ty, ")"])
252    
253      fun slice (Ty.T_Tensor(Ty.Shape l), mask) = let      fun slice (Ty.T_Tensor(Ty.Shape l), mask) = let
254            fun f (d, true, dd) = dd            fun f (d, true, dd) = dd
255              | f (d, false, dd) = d::dd              | f (d, false, dd) = d::dd
# Line 240  Line 258 
258            end            end
259        | slice (ty, _) = raise Fail(concat["slice(", toString ty, ", _)"])        | slice (ty, _) = raise Fail(concat["slice(", toString ty, ", _)"])
260    
261      (* convert to fully resolved monomorphic forms *)
262        fun monoDim dim = (case pruneDim dim
263               of Ty.DimConst d => d
264                | dim => raise Fail(concat["dim ", dimToString dim, " is not constant"])
265              (* end case *))
266    
267        fun monoShape shp = (case pruneShape shp
268               of Ty.Shape shp => List.map monoDim shp
269                | shp => raise Fail(concat["shape ", shapeToString shp, " is not constant"])
270              (* end case *))
271    
272        fun monoDiff diff = (case pruneDiff diff
273               of Ty.DiffConst k => k
274                | diff => raise Fail(concat["diff ", diffToString diff, " is not constant"])
275              (* end case *))
276    
277    end    end

Legend:
Removed from v.2355  
changed lines
  Added in v.2356

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