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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (download) (annotate)
Wed Oct 14 21:25:00 2015 UTC (5 years, 9 months ago) by jhr
File size: 2886 byte(s)
code is copyright University of Chicago
(* mid-il-types.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * 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
      | 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

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

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | 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

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString (TensorTy[]) = "real"
      | 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, ")"]

  end

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