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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/simple/simple-var.sml
ViewVC logotype

View of /branches/vis15/src/compiler/simple/simple-var.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3506 - (download) (annotate)
Fri Dec 18 04:03:54 2015 UTC (3 years, 9 months ago) by jhr
File size: 3827 byte(s)
working on merge
(* simple-var.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.
 *)

structure SimpleVar : sig

    type t

    datatype kind = datatype Var.kind

  (* define a new variable *)
    val new : string * kind * SimpleTypes.ty -> t

  (* make a copy of a variable (same name and type) *)
    val copy : t * kind -> t

  (* return the variable's name (as it appears in the source) *)
    val nameOf : t -> string

  (* return the variable's type scheme *)
    val typeOf : t -> SimpleTypes.ty

  (* return the variable's kind *)
    val kindOf : t -> kind

  (* return a unique string representation of the variable *)
    val uniqueNameOf : t -> string

  (* return true if the variable has global scope *)
    val hasGlobalScope : t -> bool

  (* define a property for variables *)
    val newProp : (t -> 'a) -> {
	    clrFn  : t -> unit,
	    getFn  : t -> 'a,
	    peekFn : t -> 'a option,
	    setFn  : t * 'a -> unit
	  }
  (* define a boolean property for variables *)
    val newFlag : unit -> { getFn : t -> bool, setFn : t * bool -> unit }

  (* are two variables the same? *)
    val same : t * t -> bool

  (* compare two variables *)
    val compare : t * t -> order

  (* return a hash code for a variable *)
    val hash : t -> word

  (* return the string representation of the variable's kind *)
    val kindToString : kind -> string

    structure Map : ORD_MAP where type Key.ord_key = t
    structure Set : ORD_SET where type Key.ord_key = t
    structure Tbl : MONO_HASH_TABLE where type Key.hash_key = t

  end = struct

    datatype kind = datatype Var.kind

    datatype t = V of {
        name : string,          (* print name of variable *)
        id : Stamp.stamp,       (* unique ID *)
        kind : kind,        	(* variable kind *)
        ty : SimpleTypes.ty,    (* type *)
        props : PropList.holder (* property list *)
      }

    fun nameOf (V{name, ...}) = name
    fun typeOf (V{ty, ...}) = ty
    fun kindOf (V{kind, ...}) = kind
    fun uniqueNameOf (V{name, id, ...}) = name ^ Stamp.toString id

    fun new (name, kind, ty) = let
          val id = Stamp.new()
          in
            V{name=name, id=id, kind=kind, ty=ty, props=PropList.newHolder()}
          end

    fun copy (V{name, ty, ...}, kind) = new (name, kind, ty)

  (* return true if variable has global scope *)
    fun hasGlobalScope (V{kind, ...}) = (case kind
           of BasisVar => true
	    | ConstVar => true
            | InputVar => true
            | GlobalVar => true
            | FunVar => true
            | _ => false
          (* end case *))

    fun newProp initFn = PropList.newProp (fn (V{props, ...}) => props, initFn)
    fun newFlag () = PropList.newFlag (fn (V{props, ...}) => props)

    fun compare (V{id=a, ...}, V{id=b, ...}) = Stamp.compare(a, b)
    fun same (V{id=a, ...}, V{id=b, ...}) = Stamp.same(a, b)
    fun hash (V{id, ...}) = Stamp.hash id

    fun kindToString kind = (case kind
	  of BasisVar => "basis variable"
	   | ConstVar => "constant"
	   | InputVar => "input variable"
	   | GlobalVar => "global variable"
	   | FunVar => "function"
	   | FunParam => "function parameter"
	   | StrandParam => "strand parameter"
	   | StrandStateVar => "state variable"
	   | StrandOutputVar => "strand output variable"
	   | LocalVar => "local variable"
	   | IterVar => "iteration variable"
	  (* end case *))

    local
      structure V =
        struct
          type ord_key = t
          val compare = compare
        end
    in
    structure Map = RedBlackMapFn (V)
    structure Set = RedBlackSetFn (V)
    end

    structure Tbl = HashTableFn (
      struct
        type hash_key = t
        val hashVal = hash
        val sameKey = same
      end)

  end

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