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

SCM Repository

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

Annotation of /branches/vis12/src/compiler/mid-il/mid-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1689 - (view) (download)

1 : jhr 391 (* mid-il-types.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 391 * All rights reserved.
5 :     *
6 :     * Types for the MidIL.
7 :     *)
8 :    
9 :     structure MidILTypes =
10 :     struct
11 :    
12 : jhr 1640 (* FIXME: perhaps we should replage TensorTy wity SeqTy at this stage? *)
13 : jhr 391 datatype ty
14 : jhr 1640 = BoolTy | StringTy | IntTy
15 :     | TensorTy of int list (* tensor types, which include reals, sequences of reals, etc. *)
16 :     | TupleTy of ty list (* tuples; used for multiple return values *)
17 :     | SeqTy of ty * int
18 : jhr 1689 | DynSeqTy of ty
19 : jhr 1640 | AddrTy of ImageInfo.info (* voxel address *)
20 : jhr 1116 | ImageTy of ImageInfo.info
21 : jhr 391
22 : jhr 1640 val intTy = IntTy
23 :     fun iVecTy 1 = IntTy
24 :     | iVecTy n = SeqTy(IntTy, n)
25 : jhr 1116 val realTy = TensorTy[]
26 :     fun vecTy 1 = realTy
27 :     | vecTy n = TensorTy[n]
28 : jhr 391
29 : jhr 1116 fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
30 :     of [] => realTy (* 0-order tensors are represented as reals *)
31 :     | dd => TensorTy dd
32 :     (* end case *))
33 : jhr 391
34 : jhr 1116 fun same (BoolTy, BoolTy) = true
35 :     | same (StringTy, StringTy) = true
36 : jhr 1640 | same (IntTy, IntTy) = true
37 : jhr 1116 | 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 1689 | same (DynSeqTy ty1, DynSeqTy ty2) = same(ty1, ty2)
41 : jhr 1116 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
42 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
43 :     | same _ = false
44 :    
45 : jhr 391 fun hash BoolTy = 0w1
46 :     | hash StringTy = 0w2
47 : jhr 1640 | hash IntTy = 0w3
48 : jhr 1116 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
49 : jhr 1640 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
50 :     | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
51 : jhr 1689 | hash (DynSeqTy ty) = hash ty + 0w13
52 :     | hash (AddrTy info) = 0w17 + ImageInfo.hash info
53 :     | hash (ImageTy info) = 0w19 * ImageInfo.hash info + 0w6
54 : jhr 391
55 :     fun toString BoolTy = "bool"
56 :     | toString StringTy = "string"
57 : jhr 1640 | toString IntTy = "int"
58 : jhr 1116 | toString (TensorTy[]) = "real"
59 :     | toString (TensorTy[d]) = "real" ^ Int.toString d
60 :     | toString (TensorTy dd) = String.concat[
61 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
62 :     ]
63 : jhr 1640 | toString (TupleTy tys) = String.concat[
64 :     "(", String.concatWith " * " (List.map toString tys), ")"
65 :     ]
66 :     | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
67 : jhr 1689 | toString (DynSeqTy ty) = toString ty ^ "{}"
68 : jhr 1116 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
69 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
70 : jhr 391
71 :     end

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