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

SCM Repository

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

Annotation of /trunk/src/compiler/high-il/high-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 393 (* high-il-types.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 393 * All rights reserved.
7 :     *)
8 :    
9 :     structure HighILTypes =
10 :     struct
11 :    
12 : jhr 394 datatype ty
13 : jhr 1640 = BoolTy | IntTy | StringTy
14 : jhr 394 | TensorTy of int list
15 : jhr 1640 | TupleTy of ty list (* tuples; used for multiple return values *)
16 :     | SeqTy of ty * int
17 : jhr 1116 | ImageTy of int
18 :     | KernelTy
19 :     | FieldTy
20 :     | AnyTy (* this is used in checking when we can't figure out the type *)
21 : jhr 393
22 : jhr 417 val intTy = IntTy
23 : jhr 403 val realTy = TensorTy[]
24 : jhr 1640 fun vecTy 1 = realTy
25 :     | vecTy n = TensorTy[n]
26 :     val vec2Ty = TensorTy[2]
27 : jhr 403 val vec3Ty = TensorTy[3]
28 : jhr 1640 val vec4Ty = TensorTy[4]
29 : jhr 403
30 : jhr 426 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
31 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
32 :    
33 : jhr 1116 fun same (AnyTy, _) = true
34 :     | same (_, AnyTy) = true
35 :     | same (BoolTy, BoolTy) = true
36 : jhr 1640 | same (IntTy, IntTy) = true
37 : jhr 1116 | same (StringTy, StringTy) = true
38 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
39 : jhr 1640 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
40 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
41 : jhr 1116 | same (ImageTy d1, ImageTy d2) = (d1 = d2)
42 :     | same (KernelTy, KernelTy) = true
43 :     | same (FieldTy, FieldTy) = true
44 :     | same _ = false
45 : jhr 393
46 :     fun hash BoolTy = 0w1
47 :     | hash StringTy = 0w2
48 :     | hash IntTy = 0w3
49 : jhr 1640 | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w5 dd
50 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
51 :     | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
52 : jhr 2636 | hash (ImageTy d) = 0w17 + 0w3 * Word.fromInt d
53 :     | hash KernelTy = 0w19
54 :     | hash FieldTy = 0w23
55 : jhr 1116 | hash AnyTy = raise Fail "hash(AnyTy)"
56 : jhr 393
57 :     fun toString BoolTy = "bool"
58 :     | toString StringTy = "string"
59 :     | toString IntTy = "int"
60 :     | toString (TensorTy[]) = "real"
61 :     | toString (TensorTy dd) = String.concat[
62 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
63 :     ]
64 : jhr 1640 | toString (TupleTy tys) = String.concat[
65 :     "(", String.concatWith " * " (List.map toString tys), ")"
66 :     ]
67 :     | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
68 : jhr 1116 | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]
69 : jhr 395 | toString KernelTy = "kernel"
70 :     | toString FieldTy = "field"
71 : jhr 1116 | toString AnyTy = "**any**"
72 : jhr 393
73 :     end

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