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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/high-il/high-il-types.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/high-il/high-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1508 - (download) (annotate)
Wed Sep 21 21:23:18 2011 UTC (7 years, 11 months ago) by jhr
File size: 2033 byte(s)
  Working on adding IL support for sequences and eigenvectors
(* high-il-types.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure HighILTypes =
  struct

    datatype ty
      = BoolTy | IntTy | StringTy
      | TensorTy of int list
      | 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[]
    val vec3Ty = TensorTy[3]

  (* 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 (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
      | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
      | 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 (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w5
      | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w7 dd
      | hash (ImageTy d) = 0w11 + 0w3 * Word.fromInt d
      | hash KernelTy = 0w13
      | hash FieldTy = 0w17
      | hash AnyTy = raise Fail "hash(AnyTy)"

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
      | toString (TensorTy[]) = "real"
      | toString (TensorTy dd) = String.concat[
	    "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
	  ]
      | 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