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

SCM Repository

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

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

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

revision 1116, Thu May 5 04:49:02 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 1  Line 1 
1  (* high-il-types.sml  (* high-il-types.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *)   *)
6    
# Line 8  Line 8 
8    struct    struct
9    
10      datatype ty      datatype ty
11        = BoolTy | StringTy | IntTy        = BoolTy | IntTy | StringTy
12        | TensorTy of int list        | TensorTy of int list
13          | TupleTy of ty list              (* tuples; used for multiple return values *)
14          | SeqTy of ty * int
15        | ImageTy of int        | ImageTy of int
16        | KernelTy        | KernelTy
17        | FieldTy        | FieldTy
# Line 17  Line 19 
19    
20      val intTy = IntTy      val intTy = IntTy
21      val realTy = TensorTy[]      val realTy = TensorTy[]
22        fun vecTy 1 = realTy
23          | vecTy n = TensorTy[n]
24        val vec2Ty = TensorTy[2]
25      val vec3Ty = TensorTy[3]      val vec3Ty = TensorTy[3]
26        val vec4Ty = TensorTy[4]
27    
28    (* smart constructor for tensor type that prunes out dimensions with size 1 *)    (* smart constructor for tensor type that prunes out dimensions with size 1 *)
29      fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)      fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
# Line 25  Line 31 
31      fun same (AnyTy, _) = true      fun same (AnyTy, _) = true
32        | same (_, AnyTy) = true        | same (_, AnyTy) = true
33        | same (BoolTy, BoolTy) = true        | same (BoolTy, BoolTy) = true
       | same (StringTy, StringTy) = true  
34        | same (IntTy, IntTy) = true        | same (IntTy, IntTy) = true
35          | same (StringTy, StringTy) = true
36        | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)        | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
37          | 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        | same (ImageTy d1, ImageTy d2) = (d1 = d2)        | same (ImageTy d1, ImageTy d2) = (d1 = d2)
40        | same (KernelTy, KernelTy) = true        | same (KernelTy, KernelTy) = true
41        | same (FieldTy, FieldTy) = true        | same (FieldTy, FieldTy) = true
# Line 36  Line 44 
44      fun hash BoolTy = 0w1      fun hash BoolTy = 0w1
45        | hash StringTy = 0w2        | hash StringTy = 0w2
46        | hash IntTy = 0w3        | hash IntTy = 0w3
47        | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd        | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w5 dd
48        | hash (ImageTy d) = 0w5 + 0w3 * Word.fromInt d        | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
49        | hash KernelTy = 0w6        | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
50        | hash FieldTy = 0w7        | hash (ImageTy d) = 0w13 + 0w3 * Word.fromInt d
51          | hash KernelTy = 0w17
52          | hash FieldTy = 0w19
53        | hash AnyTy = raise Fail "hash(AnyTy)"        | hash AnyTy = raise Fail "hash(AnyTy)"
54    
55      fun toString BoolTy = "bool"      fun toString BoolTy = "bool"
# Line 49  Line 59 
59        | toString (TensorTy dd) = String.concat[        | toString (TensorTy dd) = String.concat[
60              "tensor[", String.concatWith "," (List.map Int.toString dd), "]"              "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
61            ]            ]
62          | 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        | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]        | toString (ImageTy d) = String.concat["image", Int.toString d, "D"]
67        | toString KernelTy = "kernel"        | toString KernelTy = "kernel"
68        | toString FieldTy = "field"        | toString FieldTy = "field"

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

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