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

SCM Repository

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

Annotation of /trunk/src/compiler/mid-il/mid-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 391 (* mid-il-types.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 391 * All rights reserved.
7 :     *
8 :     * Types for the MidIL.
9 :     *)
10 :    
11 :     structure MidILTypes =
12 :     struct
13 :    
14 : jhr 1640 (* FIXME: perhaps we should replage TensorTy wity SeqTy at this stage? *)
15 : jhr 391 datatype ty
16 : jhr 1640 = BoolTy | StringTy | IntTy
17 :     | TensorTy of int list (* tensor types, which include reals, sequences of reals, etc. *)
18 :     | TupleTy of ty list (* tuples; used for multiple return values *)
19 :     | SeqTy of ty * int
20 :     | AddrTy of ImageInfo.info (* voxel address *)
21 : jhr 1116 | ImageTy of ImageInfo.info
22 : jhr 391
23 : jhr 1640 val intTy = IntTy
24 :     fun iVecTy 1 = IntTy
25 :     | iVecTy n = SeqTy(IntTy, n)
26 : jhr 1116 val realTy = TensorTy[]
27 :     fun vecTy 1 = realTy
28 :     | vecTy n = TensorTy[n]
29 : jhr 391
30 : jhr 1116 fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
31 :     of [] => realTy (* 0-order tensors are represented as reals *)
32 :     | dd => TensorTy dd
33 :     (* end case *))
34 : jhr 391
35 : jhr 1116 fun same (BoolTy, BoolTy) = true
36 :     | same (StringTy, StringTy) = true
37 : jhr 1640 | same (IntTy, IntTy) = true
38 : jhr 1116 | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
39 : jhr 1640 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
40 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso 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 1116 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
52 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
53 : jhr 391
54 :     fun toString BoolTy = "bool"
55 :     | toString StringTy = "string"
56 : jhr 1640 | toString IntTy = "int"
57 : jhr 1116 | toString (TensorTy[]) = "real"
58 :     | toString (TensorTy[d]) = "real" ^ Int.toString d
59 :     | toString (TensorTy dd) = String.concat[
60 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
61 :     ]
62 : jhr 1640 | toString (TupleTy tys) = String.concat[
63 :     "(", String.concatWith " * " (List.map toString tys), ")"
64 :     ]
65 :     | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
66 : jhr 1116 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
67 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
68 : jhr 391
69 :     end

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