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

SCM Repository

[diderot] Diff of /trunk/src/compiler/IL/types.sml
ViewVC logotype

Diff of /trunk/src/compiler/IL/types.sml

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

revision 7, Fri Jan 8 20:44:57 2010 UTC revision 9, Fri Jan 8 22:06:11 2010 UTC
# Line 2  Line 2 
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5     *
6     * This file defines the internal representation of Diderot types.  Most values
7     * have the tensor type, which includes scalars, vectors, etc.  The internal
8     * type system supports polymorphism, which is used to give types to higher-order
9     * operators (e.g., derivatives).
10   *)   *)
11    
12  structure Types : TYPES =  structure Types =
13    sig    struct
14    
15    (* kinds for type variables *)    (* kinds for type variables *)
16      datatype kind      datatype kind
# Line 13  Line 18 
18        | TK_INT          (* ranges over integer types *)        | TK_INT          (* ranges over integer types *)
19        | TK_FLT          (* ranges over floating-point types *)        | TK_FLT          (* ranges over floating-point types *)
20        | TK_RAW          (* ranges over raw (scalar) types *)        | TK_RAW          (* ranges over raw (scalar) types *)
21          | TK_TYPE         (* ranges over types *)
22    (* Question: do we want kinds for tensors of different orders (e.g., TK_TENSOR of word?);
23     * Then TK_RAW would be TK_TENSOR of 0w0.
24     *)
25    
26      (* raw numeric types as supported by NRRD *)
27      datatype raw_ty      datatype raw_ty
28        = Int8 | UInt8        = RT_Int8 | RT_UInt8
29        | Int16 | UInt16        | RT_Int16 | RT_UInt16
30        | Int32 | UInt32        | RT_Int32 | RT_UInt32
31        | Int64 | UInt64        | RT_Int64 | RT_UInt64
32        | Float | Double        | RT_Float | RT_Double
33          | RT_Var of var
34    
35      datatype ty      and ty
36        = T_Var of var        = T_Var of var
37        | T_Bool        | T_Bool
38      (* scalars, vectors, matrices, etc. *)      (* scalars, vectors, matrices, etc. *)
# Line 30  Line 41 
41        | T_Data of {        | T_Data of {
42            dim : dim,            (* 2D or 3D data set *)            dim : dim,            (* 2D or 3D data set *)
43            order : dim list,     (* tensor order/dimension info *)            order : dim list,     (* tensor order/dimension info *)
44            rep_ty : ty           (* representation type of elements (raw kind) *)            repTy : raw_ty        (* representation type of elements (raw kind) *)
45          }          }
46      (* continuous field reconstructed from a data set *)      (* continuous field reconstructed from a data set *)
47        | T_Field of {        | T_Field of {
48            dim : dim,            (* 2D or 3D field *)            dim : dim,            (* 2D or 3D field *)
49            order : dim list,     (* tensor order/dimension info *)            order : dim list,     (* tensor order/dimension info *)
50            rep_ty : ty,          (* representation type of elements (raw kind) *)            repTy : raw_ty,       (* representation type of elements (raw kind) *)
51            ty : ty               (* type of samples (float kind) *)            ty : raw_ty           (* type of samples (float kind) *)
52          }          }
53    
54      and dim = DIM of word | DIMVAR of var      and dim = DIM of word | DIMVAR of var
55    
56    (* type variables *)    (* type variables; the kind field restricts their range *)
57      and var = TV of {      and var = TV of {
58            stamp : Stamp.stamp,            kind : kind,
59            kind : kind            stamp : Stamp.stamp
60          }          }
61    
62    (* given a dataset or field type, return the element type, which will be    (* given a dataset or field type, return the element type, which will be
63     * a tensor type.     * a tensor type.
64     *)     *)
65      fun elemTypeOf (T_Data{order, rep_ty, ...}) = T_Tensor{order=order, ty=rep_ty}      fun elemTypeOf (T_Data{order, repTy, ...}) = T_Tensor{order=order, ty=repTy}
66        | elemTypeOf (T_Field{order, ty, ...}) = T_Tensor{order=order, ty=ty}        | elemTypeOf (T_Field{order, ty, ...}) = T_Tensor{order=order, ty=ty}
67        | elemTypeOf _ = raise Fail "not a dataset/field"        | elemTypeOf _ = raise Fail "not a dataset/field"
68    
69      (* is a type well-formed? *)
70        fun wellFormed ty = let
71            (* is a dimension well-formed? *)
72              fun okDim (DIM w) = (w > 0w0)
73                | okDim (DIMVAR(TV{kind=TK_DIM, ...})) = true
74                | okDim _ = false
75            (* is a raw type well formed *)
76              fun okRawTy (RT_Var(TV{kind=TK_INT, ...})) = true
77                | okRawTy (RT_Var(TV{kind=TK_FLT, ...})) = true
78                | okRawTy (RT_Var(TV{kind=TK_RAW, ...})) = true
79                | okRawTy (RT_Var _) = false
80                | okRawTy _ = true
81            (* is a raw type a floating-point type? *)
82              fun okFloatTy (RT_Var(TV{kind=TK_FLT, ...})) = true
83                | okFloatTy RT_Float = true
84                | okFloatTy RT_Double = true
85                | okFloatTy _ = false
86              fun wellFormed' (T_Var(TV{kind=TK_TYPE, ...})) = true
87                | wellFormed' (T_Var _) = false
88                | wellFormed' (T_Tensor{order, ty}) =
89                    List.all okDim order
90                    andalso okRawTy ty
91                | wellFormed' (T_Data{dim, order, repTy}) =
92                    okDim dim
93                    andalso List.all okDim order
94                    andalso okRawTy repTy
95                | wellFormed' (T_Field{dim, order, repTy, ty}) =
96                    okDim dim
97                    andalso List.all okDim order
98                    andalso okRawTy repTy
99                    andalso okFloatTy repTy
100                | wellFormed' _ = false
101              in
102                wellFormed' ty
103              end
104    
105      (* some common types *)
106        local
107          fun scalarTy rty = T_Tensor{order=[], ty=rty}
108          fun vecTy (d, rty) = T_Tensor{order=[DIM d], ty=rty}
109        in
110        val intTy = scalarTy RT_Int32
111        val int2Ty = vecTy (0w2, RT_Int32)
112        val intT3y = vecTy (0w3, RT_Int32)
113        val intT4y = vecTy (0w4, RT_Int32)
114        val uintTy = scalarTy RT_UInt32
115        val uint2Ty = vecTy (0w2, RT_UInt32)
116        val uintT3y = vecTy (0w3, RT_UInt32)
117        val uintT4y = vecTy (0w4, RT_UInt32)
118        val floatTy = scalarTy RT_Float
119        val float2Ty = vecTy (0w2, RT_Float)
120        val floatT3y = vecTy (0w3, RT_Float)
121        val floatT4y = vecTy (0w4, RT_Float)
122        val doubleTy = scalarTy RT_Double
123        val double2Ty = vecTy (0w2, RT_Double)
124        val double3Ty = vecTy (0w3, RT_Double)
125        val double4Ty = vecTy (0w4, RT_Double)
126        end (* local *)
127    
128      (* new type variables *)
129        fun newVar k = TV{kind=k, stamp=Stamp.new()}
130    
131    end    end

Legend:
Removed from v.7  
changed lines
  Added in v.9

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