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 1685 - (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 :     | AddrTy of ImageInfo.info (* voxel address *)
19 : jhr 1116 | ImageTy of ImageInfo.info
20 : jhr 391
21 : jhr 1640 val intTy = IntTy
22 :     fun iVecTy 1 = IntTy
23 :     | iVecTy n = SeqTy(IntTy, n)
24 : jhr 1116 val realTy = TensorTy[]
25 :     fun vecTy 1 = realTy
26 :     | vecTy n = TensorTy[n]
27 : jhr 391
28 : jhr 1116 fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
29 :     of [] => realTy (* 0-order tensors are represented as reals *)
30 :     | dd => TensorTy dd
31 :     (* end case *))
32 : jhr 391
33 : jhr 1116 fun same (BoolTy, BoolTy) = true
34 :     | same (StringTy, StringTy) = true
35 : jhr 1640 | same (IntTy, IntTy) = true
36 : jhr 1116 | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
37 : jhr 1640 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
38 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
39 : jhr 1116 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
40 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
41 :     | same _ = false
42 :    
43 : jhr 391 fun hash BoolTy = 0w1
44 :     | hash StringTy = 0w2
45 : jhr 1640 | hash IntTy = 0w3
46 : jhr 1116 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
47 : jhr 1640 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
48 :     | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
49 : jhr 1116 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
50 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
51 : jhr 391
52 :     fun toString BoolTy = "bool"
53 :     | toString StringTy = "string"
54 : jhr 1640 | toString IntTy = "int"
55 : jhr 1116 | toString (TensorTy[]) = "real"
56 :     | toString (TensorTy[d]) = "real" ^ Int.toString d
57 :     | toString (TensorTy dd) = String.concat[
58 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
59 :     ]
60 : jhr 1640 | toString (TupleTy tys) = String.concat[
61 :     "(", String.concatWith " * " (List.map toString tys), ")"
62 :     ]
63 :     | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
64 : jhr 1116 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
65 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
66 : jhr 391
67 :     end

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