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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 517 - (view) (download)

1 : jhr 393 (* high-il-types.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 393 * All rights reserved.
5 :     *)
6 :    
7 :     structure HighILTypes =
8 :     struct
9 :    
10 : jhr 394 datatype ty
11 :     = BoolTy | StringTy | IntTy
12 :     | TensorTy of int list
13 : jhr 517 | ImageTy of int (* parameter is dimension *)
14 :     | KernelTy
15 :     | FieldTy
16 : jhr 393
17 : jhr 417 val intTy = IntTy
18 : jhr 403 val realTy = TensorTy[]
19 :     val vec3Ty = TensorTy[3]
20 :    
21 : jhr 426 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
22 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
23 :    
24 : jhr 393 fun same (ty1 : ty, ty2) = (ty1 = ty2)
25 :    
26 :     fun hash BoolTy = 0w1
27 :     | hash StringTy = 0w2
28 :     | hash IntTy = 0w3
29 :     | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd
30 : jhr 517 | hash (ImageTy d) = 0w5 + 0w3 * Word.fromInt d
31 :     | hash KernelTy = 0w6
32 : jhr 395 | hash FieldTy = 0w7
33 : jhr 393
34 :     fun toString BoolTy = "bool"
35 :     | toString StringTy = "string"
36 :     | toString IntTy = "int"
37 :     | toString (TensorTy[]) = "real"
38 :     | toString (TensorTy dd) = String.concat[
39 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
40 :     ]
41 : jhr 517 | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]
42 : jhr 395 | toString KernelTy = "kernel"
43 :     | toString FieldTy = "field"
44 : jhr 393
45 :     end

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