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 4432 - (view) (download)

1 : jhr 3474 (* high-types.sml
2 :     *
3 : jhr 3532 * Types for the HighIR.
4 :     *
5 : jhr 3474 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2015 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure HighTypes =
12 :     struct
13 :    
14 :     datatype ty
15 : jhr 3532 = BoolTy | StringTy | IntTy
16 :     | TensorTy of int list (* tensor types, which include reals, vectors, etc. *)
17 : jhr 3474 | TupleTy of ty list (* tuples; used for multiple return values *)
18 : jhr 3475 | SeqTy of ty * int option
19 : jhr 4432 | ImageTy of ImageInfo.t
20 : jhr 3846 | StrandTy of Atom.atom
21 : jhr 3474 | KernelTy
22 :     | FieldTy
23 :    
24 :     val intTy = IntTy
25 :     val realTy = TensorTy[]
26 :     fun vecTy 1 = realTy
27 :     | vecTy n = TensorTy[n]
28 :     val vec2Ty = TensorTy[2]
29 :     val vec3Ty = TensorTy[3]
30 :     val vec4Ty = TensorTy[4]
31 :    
32 :     (* smart constructor for tensor type that prunes out dimensions with size 1 *)
33 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
34 :    
35 : jhr 3846 fun same (BoolTy, BoolTy) = true
36 : jhr 3532 | same (StringTy, StringTy) = true
37 : jhr 3474 | same (IntTy, IntTy) = 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 : jhr 3846 | same (StrandTy n1, StrandTy n2) = Atom.same(n1, n2)
44 : jhr 3474 | same (KernelTy, KernelTy) = true
45 :     | same (FieldTy, FieldTy) = true
46 :     | same _ = false
47 :    
48 :     fun hash BoolTy = 0w1
49 :     | hash StringTy = 0w2
50 :     | hash IntTy = 0w3
51 : jhr 3532 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
52 : jhr 3474 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
53 : jhr 3475 | hash (SeqTy(ty, NONE)) = hash ty + 0w11
54 : jhr 3474 | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w13
55 :     | hash (ImageTy info) = 0w17 + 0w3 * ImageInfo.hash info
56 :     | hash KernelTy = 0w19
57 :     | hash FieldTy = 0w23
58 : jhr 3846 | hash (StrandTy n) = Atom.hash n
59 : jhr 3474
60 :     fun toString BoolTy = "bool"
61 :     | toString StringTy = "string"
62 :     | toString IntTy = "int"
63 :     | toString (TensorTy[]) = "real"
64 :     | toString (TensorTy dd) = String.concat[
65 : jhr 3532 "tensor[", String.concatWithMap "," Int.toString dd, "]"
66 : jhr 3474 ]
67 :     | toString (TupleTy tys) = String.concat[
68 : jhr 3532 "(", String.concatWithMap " * " toString tys, ")"
69 : jhr 3474 ]
70 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
71 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
72 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
73 : jhr 3846 | toString (StrandTy n) = Atom.toString n
74 : jhr 3474 | toString KernelTy = "kernel"
75 :     | toString FieldTy = "field"
76 :    
77 :     end

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