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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (view) (download)
Original Path: trunk/src/IL/types.sml

1 : jhr 7 (* types.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 : jhr 8 structure Types =
8 :     struct
9 : jhr 7
10 :     (* kinds for type variables *)
11 :     datatype kind
12 :     = TK_DIM (* ranges over dimensions (1, 2, ...) *)
13 :     | TK_INT (* ranges over integer types *)
14 :     | TK_FLT (* ranges over floating-point types *)
15 :     | TK_RAW (* ranges over raw (scalar) types *)
16 : jhr 8 | TK_TYPE (* ranges over types *)
17 :     (* Question: do we want kinds for tensors of different orders (e.g., TK_TENSOR of word?);
18 :     * Then TK_RAW would be TK_TENSOR of 0w0.
19 :     *)
20 : jhr 7
21 : jhr 8 (* raw numeric types as supported by NRRD *)
22 : jhr 7 datatype raw_ty
23 : jhr 8 = RT_Int8 | RT_UInt8
24 :     | RT_Int16 | RT_UInt16
25 :     | RT_Int32 | RT_UInt32
26 :     | RT_Int64 | RT_UInt64
27 :     | RT_Float | RT_Double
28 :     | RT_Var of var
29 : jhr 7
30 : jhr 8 and ty
31 : jhr 7 = T_Var of var
32 :     | T_Bool
33 :     (* scalars, vectors, matrices, etc. *)
34 :     | T_Tensor of {order : dim list, ty : raw_ty}
35 :     (* data sets from NNRD *)
36 :     | T_Data of {
37 :     dim : dim, (* 2D or 3D data set *)
38 :     order : dim list, (* tensor order/dimension info *)
39 : jhr 8 repTy : raw_ty (* representation type of elements (raw kind) *)
40 : jhr 7 }
41 :     (* continuous field reconstructed from a data set *)
42 :     | T_Field of {
43 :     dim : dim, (* 2D or 3D field *)
44 :     order : dim list, (* tensor order/dimension info *)
45 : jhr 8 repTy : raw_ty, (* representation type of elements (raw kind) *)
46 :     ty : raw_ty (* type of samples (float kind) *)
47 : jhr 7 }
48 :    
49 :     and dim = DIM of word | DIMVAR of var
50 :    
51 : jhr 8 (* type variables; the kind field restricts their range *)
52 : jhr 7 and var = TV of {
53 : jhr 8 kind : kind,
54 :     stamp : Stamp.stamp
55 : jhr 7 }
56 :    
57 :     (* given a dataset or field type, return the element type, which will be
58 :     * a tensor type.
59 :     *)
60 : jhr 8 fun elemTypeOf (T_Data{order, repTy, ...}) = T_Tensor{order=order, ty=repTy}
61 : jhr 7 | elemTypeOf (T_Field{order, ty, ...}) = T_Tensor{order=order, ty=ty}
62 :     | elemTypeOf _ = raise Fail "not a dataset/field"
63 :    
64 : jhr 8 (* is a type well-formed? *)
65 :     fun wellFormed ty = let
66 :     (* is a dimension well-formed? *)
67 :     fun okDim (DIM w) = (w > 0w0)
68 :     | okDim (DIMVAR(TV{kind=TK_DIM, ...})) = true
69 :     | okDim _ = false
70 :     (* is a raw type well formed *)
71 :     fun okRawTy (RT_Var(TV{kind=TK_INT, ...})) = true
72 :     | okRawTy (RT_Var(TV{kind=TK_FLT, ...})) = true
73 :     | okRawTy (RT_Var(TV{kind=TK_RAW, ...})) = true
74 :     | okRawTy (RT_Var _) = false
75 :     | okRawTy _ = true
76 :     (* is a raw type a floating-point type? *)
77 :     fun okFloatTy (RT_Var(TV{kind=TK_FLT, ...})) = true
78 :     | okFloatTy RT_Float = true
79 :     | okFloatTy RT_Double = true
80 :     | okFloatTy _ = false
81 :     fun wellFormed' (T_Var(TV{kind=TK_TYPE, ...})) = true
82 :     | wellFormed' (T_Var _) = false
83 :     | wellFormed' (T_Tensor{order, ty}) =
84 :     List.all okDim order
85 :     andalso okRawTy ty
86 :     | wellFormed' (T_Data{dim, order, repTy}) =
87 :     okDim dim
88 :     andalso List.all okDim order
89 :     andalso okRawTy repTy
90 :     | wellFormed' (T_Field{dim, order, repTy, ty}) =
91 :     okDim dim
92 :     andalso List.all okDim order
93 :     andalso okRawTy repTy
94 :     andalso okFloatTy repTy
95 :     | wellFormed' _ = false
96 :     in
97 :     wellFormed' ty
98 :     end
99 :    
100 : jhr 7 end

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