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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1115, Thu May 5 04:42:18 2011 UTC revision 1116, Thu May 5 04:49:02 2011 UTC
# Line 11  Line 11 
11    
12      datatype ty      datatype ty
13        = BoolTy | StringTy        = BoolTy | StringTy
14        | IVecTy of int           (* integers; both scalars and vectors *)        | IVecTy of int           (* integers; both scalars and sequences *)
15        | VecTy of int            (* reals; both scalars and vectors *)        | TensorTy of int list    (* tensor types, which include reals, sequences of reals, etc. *)
16        | AddrTy                  (* voxel address *)        | AddrTy of ImageInfo.info (* voxel address *)
17        | ImageTy        | ImageTy of ImageInfo.info
18    
19      val intTy = IVecTy 1      val intTy = IVecTy 1
20      val realTy = VecTy 1      val realTy = TensorTy[]
21        fun vecTy 1 = realTy
22      fun same (ty1 : ty, ty2) = (ty1 = ty2)        | vecTy n = TensorTy[n]
23    
24        fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
25               of [] => realTy (* 0-order tensors are represented as reals *)
26                | dd => TensorTy dd
27              (* end case *))
28    
29        fun same (BoolTy, BoolTy) = true
30          | same (StringTy, StringTy) = true
31          | same (IVecTy n1, IVecTy n2) = (n1 = n2)
32          | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
33          | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
34          | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
35          | same _ = false
36    
37      fun hash BoolTy = 0w1      fun hash BoolTy = 0w1
38        | hash StringTy = 0w2        | hash StringTy = 0w2
39        | hash (IVecTy d) = 0w7 * Word.fromInt d + 0w3        | hash (IVecTy d) = 0w7 * Word.fromInt d + 0w3
40        | hash (VecTy d) = 0w11 * Word.fromInt d + 0w4        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
41        | hash AddrTy = 0w5        | hash (AddrTy info) = 0w5 + ImageInfo.hash info
42        | hash ImageTy = 0w6        | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
43    
44      fun toString BoolTy = "bool"      fun toString BoolTy = "bool"
45        | toString StringTy = "string"        | toString StringTy = "string"
46        | toString (IVecTy 1) = "int"        | toString (IVecTy 1) = "int"
47        | toString (IVecTy d) = "int" ^ Int.toString d        | toString (IVecTy d) = "int" ^ Int.toString d
48        | toString (VecTy 1) = "real"        | toString (TensorTy[]) = "real"
49        | toString (VecTy d) = "real" ^ Int.toString d        | toString (TensorTy[d]) = "real" ^ Int.toString d
50        | toString AddrTy = "addr"        | toString (TensorTy dd) = String.concat[
51        | toString ImageTy = "image"              "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
52              ]
53          | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
54          | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
55    
56    end    end

Legend:
Removed from v.1115  
changed lines
  Added in v.1116

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