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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/ast/types.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/ast/types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 691 - (view) (download)

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

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