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

SCM Repository

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

View of /branches/lamont/src/compiler/mid-il/mid-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (download) (annotate)
Fri Mar 15 22:18:22 2013 UTC (6 years, 6 months ago) by jhr
File size: 3199 byte(s)
  Merging in changes from vis12 branch.
(* mid-il-types.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Types for the MidIL.
 *)

structure MidILTypes =
  struct

(* FIXME: perhaps we should replage TensorTy wity SeqTy at this stage? *)
    datatype ty
      = BoolTy | StringTy | IntTy
      | StrandSeqTy of Atom.atom  
      | TensorTy of int list	        (* tensor types, which include reals, sequences of reals, etc. *)
      | TupleTy of ty list              (* tuples; used for multiple return values *)
      | SeqTy of ty * int
      | DynSeqTy of ty
      | AddrTy of ImageInfo.info        (* voxel address *)
      | ImageTy of ImageInfo.info
      | AnyTy				(* this is used in checking when we can't figure out the type *)

    val intTy = IntTy
    fun iVecTy 1 = IntTy
      | iVecTy n = SeqTy(IntTy, n)
    val realTy = TensorTy[]
    fun vecTy 1 = realTy
      | vecTy n = TensorTy[n]

    fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
	   of [] => realTy (* 0-order tensors are represented as reals *)
	    | dd => TensorTy dd
	  (* end case *))

    fun same (AnyTy, _) = true
      | same (_, AnyTy) = true
      | same (BoolTy, BoolTy) = true
      | same (StringTy, StringTy) = true
      | same (IntTy, IntTy) = true
      | same (StrandSeqTy n1, StrandSeqTy n2) = Atom.same(n1,n2)
      | 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 (DynSeqTy ty1, DynSeqTy ty2) = same(ty1, ty2)
      | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
      | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
      | same _ = false

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | hash (StrandSeqTy n) = 0w05
      | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 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 (DynSeqTy ty) = hash ty + 0w13
      | hash (AddrTy info) = 0w17 + ImageInfo.hash info
      | hash (ImageTy info) = 0w19 * ImageInfo.hash info + 0w6
      | hash AnyTy = raise Fail "hash(AnyTy)"

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString (TensorTy[]) = "real"
      | toString (StrandSeqTy n) = Atom.toString(n) 
      | toString (TensorTy[d]) = "real" ^ Int.toString d
      | 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 (DynSeqTy ty) = toString ty ^ "{}"
      | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
      | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
      | toString AnyTy = "**any**"

  end

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