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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 169 - (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 datatype ty
21 : jhr 75 = T_Var of ty_var
22 : jhr 61 | T_Bool
23 :     | T_Int
24 : jhr 63 | T_String
25 :     (* convolution kernel; argument is number of levels of differentiation *)
26 : jhr 74 | T_Kernel of diff
27 : jhr 63 (* scalars, vectors, matrices, etc.; argument is tensor shape *)
28 :     | T_Tensor of shape
29 : jhr 61 (* data sets from NRRD *)
30 :     | T_Image of {
31 : jhr 74 dim : dim, (* 2D or 3D data set *)
32 : jhr 63 shape : shape (* tensor shape; order is length of list *)
33 : jhr 61 }
34 :     (* continuous field reconstructed from a data set *)
35 :     | T_Field of {
36 : jhr 74 diff : diff, (* number of levels of differentiation supported *)
37 :     dim : dim, (* dimension of domain (2D or 3D field) *)
38 : jhr 63 shape : shape (* shape of tensors in range; order is length of list *)
39 : jhr 61 }
40 : jhr 81 | T_Fun of ty list * ty
41 : jhr 40
42 : jhr 74 (* type variables; the kind field restricts their range *)
43 :     and ty_var = TV of {
44 :     id : Stamp.stamp,
45 :     bind : ty option ref
46 :     }
47 :    
48 :     (* levels of differentiation *)
49 :     and diff
50 : jhr 110 = DiffConst of int (* i (i >= 0) *)
51 :     | DiffVar of (diff_var * int) (* d + i *)
52 : jhr 74
53 :     and diff_var = DfV of {
54 :     id : Stamp.stamp,
55 :     bound : int ref, (* lower bound of differentiation *)
56 : jhr 75 bind : diff option ref (* unification binding *)
57 : jhr 74 }
58 :    
59 :     (* tensor shapes *)
60 : jhr 63 and shape
61 : jhr 74 = Shape of dim list
62 :     | ShapeVar of shape_var
63 : jhr 75 | ShapeExt of shape * dim (* extension of shape (i.e., for D operator) *)
64 : jhr 63
65 : jhr 74 and shape_var = SV of {
66 :     id : Stamp.stamp,
67 : jhr 75 bind : shape option ref (* unification binding *)
68 : jhr 74 }
69 : jhr 40
70 : jhr 74 (* dimensions *)
71 :     and dim
72 :     = DimConst of int (* i *)
73 :     | DimVar of dim_var
74 :    
75 :     and dim_var = DV of {
76 :     id : Stamp.stamp,
77 : jhr 75 bind : dim option ref (* unification binding *)
78 : jhr 61 }
79 : jhr 40
80 : jhr 74 type meta_var = (ty_var, diff_var, shape_var, dim_var) kind
81 :     type var_bind = (ty, diff, shape, dim) kind
82 : jhr 63
83 : jhr 74 type scheme = meta_var list * ty
84 :    
85 : jhr 61 (* useful types *)
86 : jhr 63 val realTy = T_Tensor(Shape[])
87 : jhr 75 fun vecTy n = T_Tensor(Shape[DimConst n])
88 : jhr 70 val vec2Ty = vecTy 2
89 :     val vec3Ty = vecTy 3
90 :     val vec4Ty = vecTy 4
91 : jhr 40
92 : jhr 81 (* smart constructors for building normalized forms *)
93 :     fun shapeExt (Shape dd, d) = Shape(dd @ [d])
94 :     | shapeExt (shape, d) = ShapeExt(shape, d)
95 :    
96 : jhr 40 end

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