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 548 - (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 548 | ImageTy of int
14 : jhr 517 | KernelTy
15 :     | FieldTy
16 : jhr 548 | AnyTy (* this is used in checking when we can't figure out the type *)
17 : jhr 393
18 : jhr 417 val intTy = IntTy
19 : jhr 403 val realTy = TensorTy[]
20 :     val vec3Ty = TensorTy[3]
21 :    
22 : jhr 426 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
23 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
24 :    
25 : jhr 548 fun same (AnyTy, _) = true
26 :     | same (_, AnyTy) = true
27 :     | same (BoolTy, BoolTy) = true
28 :     | same (StringTy, StringTy) = true
29 :     | same (IntTy, IntTy) = true
30 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
31 :     | same (ImageTy d1, ImageTy d2) = (d1 = d2)
32 :     | same (KernelTy, KernelTy) = true
33 :     | same (FieldTy, FieldTy) = true
34 :     | same _ = false
35 : jhr 393
36 :     fun hash BoolTy = 0w1
37 :     | hash StringTy = 0w2
38 :     | hash IntTy = 0w3
39 :     | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd
40 : jhr 517 | hash (ImageTy d) = 0w5 + 0w3 * Word.fromInt d
41 :     | hash KernelTy = 0w6
42 : jhr 395 | hash FieldTy = 0w7
43 : jhr 548 | hash AnyTy = raise Fail "hash(AnyTy)"
44 : jhr 393
45 :     fun toString BoolTy = "bool"
46 :     | toString StringTy = "string"
47 :     | toString IntTy = "int"
48 :     | toString (TensorTy[]) = "real"
49 :     | toString (TensorTy dd) = String.concat[
50 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
51 :     ]
52 : jhr 517 | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]
53 : jhr 395 | toString KernelTy = "kernel"
54 :     | toString FieldTy = "field"
55 : jhr 548 | toString AnyTy = "**any**"
56 : jhr 393
57 :     end

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