SCM Repository
View of /trunk/src/compiler/high-il/high-il-types.sml
Parent Directory
|
Revision Log
Revision 1640 -
(download)
(annotate)
Wed Nov 16 02:19:51 2011 UTC (9 years, 2 months ago) by jhr
File size: 2516 byte(s)
Wed Nov 16 02:19:51 2011 UTC (9 years, 2 months ago) by jhr
File size: 2516 byte(s)
Merging in changes from pure-cfg branch.
(* high-il-types.sml * * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. *) structure HighILTypes = struct datatype ty = BoolTy | IntTy | StringTy | TensorTy of int list | TupleTy of ty list (* tuples; used for multiple return values *) | SeqTy of ty * int | ImageTy of int | KernelTy | FieldTy | AnyTy (* this is used in checking when we can't figure out the type *) val intTy = IntTy val realTy = TensorTy[] fun vecTy 1 = realTy | vecTy n = TensorTy[n] val vec2Ty = TensorTy[2] val vec3Ty = TensorTy[3] val vec4Ty = TensorTy[4] (* smart constructor for tensor type that prunes out dimensions with size 1 *) fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd) fun same (AnyTy, _) = true | same (_, AnyTy) = true | same (BoolTy, BoolTy) = true | same (IntTy, IntTy) = true | same (StringTy, StringTy) = true | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2) | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2) | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2) | same (ImageTy d1, ImageTy d2) = (d1 = d2) | same (KernelTy, KernelTy) = true | same (FieldTy, FieldTy) = true | same _ = false fun hash BoolTy = 0w1 | hash StringTy = 0w2 | hash IntTy = 0w3 | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w5 dd | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11 | hash (ImageTy d) = 0w13 + 0w3 * Word.fromInt d | hash KernelTy = 0w17 | hash FieldTy = 0w19 | hash AnyTy = raise Fail "hash(AnyTy)" fun toString BoolTy = "bool" | toString StringTy = "string" | toString IntTy = "int" | toString (TensorTy[]) = "real" | toString (TensorTy dd) = String.concat[ "tensor[", String.concatWith "," (List.map Int.toString dd), "]" ] | toString (TupleTy tys) = String.concat[ "(", String.concatWith " * " (List.map toString tys), ")" ] | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"] | toString (ImageTy d) = String.concat["image", Int.toString d, "D"] | toString KernelTy = "kernel" | toString FieldTy = "field" | toString AnyTy = "**any**" end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |