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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3846 - (view) (download)

1 : jhr 3480 (* low-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 : jhr 3779 * Types for the LowIR.
9 : jhr 3480 *)
10 :    
11 : jhr 3779 structure LowTypes =
12 :     struct
13 : jhr 3628
14 : jhr 3779 datatype ty
15 :     = BoolTy | StringTy | IntTy
16 :     | TensorTy of int list (* tensor types, which include reals, vectors, etc. *)
17 :     | TupleTy of ty list (* tuples; used for multiple return values *)
18 :     | SeqTy of ty * int option
19 :     | ImageTy of ImageInfo.info
20 : jhr 3846 | StrandTy of Atom.atom
21 : jhr 3779
22 :     val intTy = IntTy
23 :     val realTy = TensorTy[]
24 :     fun vecTy 1 = realTy
25 :     | vecTy n = TensorTy[n]
26 :     fun iVecTy 1 = IntTy
27 :     | iVecTy n = SeqTy(IntTy, SOME n)
28 :    
29 : jhr 3802 fun tensorShape (TensorTy dd) = dd
30 :     | tensorShape _ = raise Fail "expected TensorTy"
31 :    
32 : jhr 3779 (* 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 :     fun same (BoolTy, BoolTy) = true
36 :     | same (StringTy, StringTy) = true
37 :     | 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 3779 | same _ = false
45 :    
46 :     fun hash BoolTy = 0w1
47 :     | hash StringTy = 0w2
48 :     | hash IntTy = 0w3
49 :     | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
50 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
51 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w11
52 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w13
53 : jhr 3804 | hash (ImageTy info) = 0w5 * ImageInfo.hash info + 0w17
54 : jhr 3846 | hash (StrandTy n) = Atom.hash n
55 : jhr 3779
56 :     fun toString BoolTy = "bool"
57 :     | toString StringTy = "string"
58 :     | toString IntTy = "int"
59 :     | toString (TensorTy[]) = "real"
60 :     | toString (TensorTy dd) = String.concat[
61 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
62 :     ]
63 :     | toString (TupleTy tys) = String.concat[
64 :     "(", String.concatWithMap " * " toString tys, ")"
65 :     ]
66 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
67 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
68 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
69 : jhr 3846 | toString (StrandTy n) = Atom.toString n
70 : jhr 3779
71 :     end
72 :    

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