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

SCM Repository

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

View of /trunk/src/compiler/high-il/high-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1116 - (download) (annotate)
Thu May 5 04:49:02 2011 UTC (8 years, 6 months ago) by jhr
File size: 1782 byte(s)
  more merging of pure-cfg changes back into trunk
(* 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 | StringTy | IntTy
      | TensorTy of int list
      | 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 (StringTy, StringTy) = true
      | same (IntTy, IntTy) = true
      | 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 (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd
      | hash (ImageTy d) = 0w5 + 0w3 * Word.fromInt d
      | hash KernelTy = 0w6
      | hash FieldTy = 0w7
      | 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 (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