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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/simplify/simple-types.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/simplify/simple-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2513 - (view) (download)

1 : jhr 2481 (* simple-types.sml
2 :     *
3 :     * COPYRIGHT (c) 2013 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Internal representation of Diderot types after simplification. This is essentially
7 :     * the Types representations with the meta variables stripped out.
8 :     *)
9 :    
10 :     structure SimpleTypes =
11 :     struct
12 :    
13 :     datatype ty
14 :     = T_Bool
15 :     | T_Int
16 :     | T_String
17 :     | T_Sequence of ty * dim (* fixed-sized sequence of values *)
18 :     | T_DynSequence of ty (* dynamically sized sequence of values *)
19 :     (* convolution kernel; argument is number of levels of differentiation *)
20 :     | T_Kernel of diff
21 :     (* scalars, vectors, matrices, etc.; argument is tensor shape *)
22 :     | T_Tensor of shape
23 :     (* data sets from NRRD *)
24 :     | T_Image of {
25 :     dim : dim, (* 2D or 3D data set *)
26 :     shape : shape (* tensor shape; order is length of list *)
27 :     }
28 :     (* continuous field reconstructed from a data set *)
29 :     | T_Field of {
30 :     diff : diff, (* number of levels of differentiation supported *)
31 :     dim : dim, (* dimension of domain (2D or 3D field) *)
32 :     shape : shape (* shape of tensors in range; order is length of list *)
33 :     }
34 :     | T_Fun of ty list * ty
35 :    
36 :     withtype diff = int
37 :     and shape = int list
38 :     and dim = int
39 :    
40 :     (* instantiated meta variable values *)
41 :     datatype meta_arg
42 :     = TY of ty
43 :     | DIFF of diff
44 :     | SHAPE of shape
45 :     | DIM of dim
46 :    
47 :     local
48 :     fun listToString fmt sep items = String.concatWith sep (List.map fmt items)
49 :     val shapeToString = listToString Int.toString ","
50 :     in
51 :     fun toString ty = (case ty
52 :     of T_Bool => "bool"
53 :     | T_Int => "int"
54 :     | T_String => "string"
55 :     | T_Sequence(ty, dim) => concat[toString ty, "{", Int.toString dim, "}"]
56 : jhr 2512 | T_DynSequence ty => toString ty ^ "{}"
57 : jhr 2481 | T_Kernel n => "kernel#" ^ Int.toString n
58 :     | T_Tensor[] => "real"
59 :     | T_Tensor[2] => "vec2"
60 :     | T_Tensor[3] => "vec3"
61 :     | T_Tensor[4] => "vec4"
62 :     | T_Tensor shape => concat["tensor[", shapeToString shape, "]"]
63 :     | T_Image{dim, shape} => concat[
64 :     "image(", Int.toString dim, ")[", shapeToString shape, "]"
65 :     ]
66 :     | T_Field{diff, dim, shape} => concat[
67 :     "field#", Int.toString diff, "(", Int.toString dim,
68 :     ")[", shapeToString shape, "]"
69 :     ]
70 :     | T_Fun(tys1, ty2) => let
71 :     fun tysToString [] = "()"
72 :     | tysToString [ty] = toString ty
73 :     | tysToString tys = String.concat[
74 :     "(", listToString toString " * " tys, ")"
75 :     ]
76 :     in
77 :     String.concat[tysToString tys1, " -> ", toString ty2]
78 :     end
79 :     (* end case *))
80 :     end (* local *)
81 :    
82 :     (* return the range (return type) of a function type *)
83 :     fun rngOf (T_Fun(_, ty)) = ty
84 :     | rngOf ty = raise Fail(concat["SimpleTypes.rngOf(", toString ty, ")"])
85 :    
86 :     local
87 :     structure Ty = Types
88 :     structure TU = TypeUtil
89 :     (* convert to fully resolved monomorphic forms *)
90 :     in
91 :     (* convert a Types.ty to a SimpleTypes.ty *)
92 :     fun simplify ty = (case ty
93 :     of Ty.T_Var(Ty.TV{bind, ...}) => (case !bind
94 :     of NONE => raise Fail "unresolved type variable"
95 :     | SOME ty => simplify ty
96 :     (* end case *))
97 :     | Ty.T_Bool => T_Bool
98 :     | Ty.T_Int => T_Int
99 :     | Ty.T_String => T_String
100 :     | Ty.T_Sequence(ty, dim) => T_Sequence(simplify ty, TU.monoDim dim)
101 : jhr 2513 | Ty.T_DynSequence ty => T_DynSequence(simplify ty)
102 : jhr 2481 | Ty.T_Kernel n => T_Kernel(TU.monoDiff n)
103 :     | Ty.T_Tensor shape => T_Tensor(TU.monoShape shape)
104 :     | Ty.T_Image{dim, shape} => T_Image{
105 :     dim = TU.monoDim dim,
106 :     shape = TU.monoShape shape
107 :     }
108 :     | Ty.T_Field{diff, dim, shape} => T_Field{
109 :     diff = TU.monoDiff diff,
110 :     dim = TU.monoDim dim,
111 :     shape = TU.monoShape shape
112 :     }
113 :     | Ty.T_Fun(tys1, ty2) => T_Fun(List.map simplify tys1, simplify ty2)
114 :     (* end case *))
115 :     end
116 :    
117 :     end

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