SCM Repository
Annotation of /trunk/src/ast/types.sml
Parent Directory
|
Revision Log
Revision 75 - (view) (download)
1 : | jhr | 40 | (* types.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | jhr | 63 | * Internal representation of Diderot types. These are the types produced |
7 : | * by the type checker. | ||
8 : | jhr | 40 | *) |
9 : | |||
10 : | structure Types = | ||
11 : | struct | ||
12 : | |||
13 : | jhr | 74 | (* union type for meta variables and meta-variable bindings *) |
14 : | datatype ('ty, 'diff, 'shape, 'dim) kind | ||
15 : | = TYPE of 'ty (* ranges over types *) | ||
16 : | | DIFF of 'diff (* ranges of differentiation levels (0, 1, ...) *) | ||
17 : | | SHAPE of 'shape (* ranges over tensor shapes *) | ||
18 : | | DIM of 'dim (* ranges over dimensions (1, 2, ...) *) | ||
19 : | jhr | 40 | |
20 : | jhr | 73 | (* |
21 : | jhr | 61 | (* raw numeric types as supported by NRRD *) |
22 : | datatype raw_ty | ||
23 : | = 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 | 73 | *) |
30 : | jhr | 61 | |
31 : | jhr | 73 | datatype ty |
32 : | jhr | 75 | = T_Var of ty_var |
33 : | jhr | 61 | | T_Bool |
34 : | | T_Int | ||
35 : | jhr | 63 | | T_String |
36 : | (* convolution kernel; argument is number of levels of differentiation *) | ||
37 : | jhr | 74 | | T_Kernel of diff |
38 : | jhr | 63 | (* scalars, vectors, matrices, etc.; argument is tensor shape *) |
39 : | | T_Tensor of shape | ||
40 : | jhr | 61 | (* data sets from NRRD *) |
41 : | | T_Image of { | ||
42 : | jhr | 74 | dim : dim, (* 2D or 3D data set *) |
43 : | jhr | 63 | shape : shape (* tensor shape; order is length of list *) |
44 : | jhr | 61 | } |
45 : | (* continuous field reconstructed from a data set *) | ||
46 : | | T_Field of { | ||
47 : | jhr | 74 | diff : diff, (* number of levels of differentiation supported *) |
48 : | dim : dim, (* dimension of domain (2D or 3D field) *) | ||
49 : | jhr | 63 | shape : shape (* shape of tensors in range; order is length of list *) |
50 : | jhr | 61 | } |
51 : | jhr | 63 | | T_Fun of ty list * ty list |
52 : | jhr | 40 | |
53 : | jhr | 74 | (* type variables; the kind field restricts their range *) |
54 : | and ty_var = TV of { | ||
55 : | id : Stamp.stamp, | ||
56 : | bind : ty option ref | ||
57 : | } | ||
58 : | |||
59 : | (* levels of differentiation *) | ||
60 : | and diff | ||
61 : | = DiffConst of int (* i *) | ||
62 : | | DiffVar of (diff_var * int) (* d + i (i >= 0) *) | ||
63 : | |||
64 : | and diff_var = DfV of { | ||
65 : | id : Stamp.stamp, | ||
66 : | bound : int ref, (* lower bound of differentiation *) | ||
67 : | jhr | 75 | bind : diff option ref (* unification binding *) |
68 : | jhr | 74 | } |
69 : | |||
70 : | (* tensor shapes *) | ||
71 : | jhr | 63 | and shape |
72 : | jhr | 74 | = Shape of dim list |
73 : | | ShapeVar of shape_var | ||
74 : | jhr | 75 | | ShapeExt of shape * dim (* extension of shape (i.e., for D operator) *) |
75 : | jhr | 63 | |
76 : | jhr | 74 | and shape_var = SV of { |
77 : | id : Stamp.stamp, | ||
78 : | jhr | 75 | bind : shape option ref (* unification binding *) |
79 : | jhr | 74 | } |
80 : | jhr | 40 | |
81 : | jhr | 74 | (* dimensions *) |
82 : | and dim | ||
83 : | = DimConst of int (* i *) | ||
84 : | | DimVar of dim_var | ||
85 : | |||
86 : | and dim_var = DV of { | ||
87 : | id : Stamp.stamp, | ||
88 : | jhr | 75 | bind : dim option ref (* unification binding *) |
89 : | jhr | 61 | } |
90 : | jhr | 40 | |
91 : | jhr | 74 | type meta_var = (ty_var, diff_var, shape_var, dim_var) kind |
92 : | type var_bind = (ty, diff, shape, dim) kind | ||
93 : | jhr | 63 | |
94 : | jhr | 74 | type scheme = meta_var list * ty |
95 : | |||
96 : | jhr | 61 | (* useful types *) |
97 : | jhr | 63 | val realTy = T_Tensor(Shape[]) |
98 : | jhr | 75 | fun vecTy n = T_Tensor(Shape[DimConst n]) |
99 : | jhr | 70 | val vec2Ty = vecTy 2 |
100 : | val vec3Ty = vecTy 3 | ||
101 : | val vec4Ty = vecTy 4 | ||
102 : | jhr | 40 | |
103 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |