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

SCM Repository

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

Annotation of /branches/lamont/src/compiler/high-il/high-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1687 - (view) (download)
Original Path: branches/vis12/src/compiler/high-il/high-il-types.sml

1 : jhr 393 (* high-il-types.sml
2 :     *
3 : jhr 1640 * COPYRIGHT (c) 2011 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 : jhr 1640 = BoolTy | IntTy | StringTy
12 : jhr 394 | TensorTy of int list
13 : jhr 1640 | TupleTy of ty list (* tuples; used for multiple return values *)
14 :     | SeqTy of ty * int
15 : jhr 1687 | DynSeqTy of ty
16 : jhr 1116 | ImageTy of int
17 :     | KernelTy
18 :     | FieldTy
19 :     | AnyTy (* this is used in checking when we can't figure out the type *)
20 : jhr 393
21 : jhr 417 val intTy = IntTy
22 : jhr 403 val realTy = TensorTy[]
23 : jhr 1640 fun vecTy 1 = realTy
24 :     | vecTy n = TensorTy[n]
25 :     val vec2Ty = TensorTy[2]
26 : jhr 403 val vec3Ty = TensorTy[3]
27 : jhr 1640 val vec4Ty = TensorTy[4]
28 : jhr 403
29 : jhr 426 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
30 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
31 :    
32 : jhr 1116 fun same (AnyTy, _) = true
33 :     | same (_, AnyTy) = true
34 :     | same (BoolTy, BoolTy) = true
35 : jhr 1640 | same (IntTy, IntTy) = true
36 : jhr 1116 | same (StringTy, StringTy) = true
37 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
38 : jhr 1640 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
39 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
40 : jhr 1687 | same (DynSeqTy ty1, DynSeqTy ty2) = 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 1687 | hash (DynSeqTy ty) = hash ty + 0w13
53 :     | hash (ImageTy d) = 0w17 + 0w3 * Word.fromInt d
54 :     | hash KernelTy = 0w19
55 :     | hash FieldTy = 0w23
56 : jhr 1116 | hash AnyTy = raise Fail "hash(AnyTy)"
57 : jhr 393
58 :     fun toString BoolTy = "bool"
59 :     | toString StringTy = "string"
60 :     | toString IntTy = "int"
61 :     | toString (TensorTy[]) = "real"
62 :     | toString (TensorTy dd) = String.concat[
63 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
64 :     ]
65 : jhr 1640 | toString (TupleTy tys) = String.concat[
66 :     "(", String.concatWith " * " (List.map toString tys), ")"
67 :     ]
68 :     | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
69 : jhr 1687 | toString (DynSeqTy ty) = toString ty ^ "{}"
70 : jhr 1116 | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]
71 : jhr 395 | toString KernelTy = "kernel"
72 :     | toString FieldTy = "field"
73 : jhr 1116 | toString AnyTy = "**any**"
74 : jhr 393
75 :     end

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