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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/high-ir/high-types.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/high-ir/high-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3475 - (view) (download)

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

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