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

SCM Repository

[diderot] View of /branches/ein16/src/compiler/ast/var.sml
ViewVC logotype

View of /branches/ein16/src/compiler/ast/var.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3682 - (download) (annotate)
Thu Feb 18 20:13:18 2016 UTC (4 years, 5 months ago) by cchiw
File size: 2157 byte(s)
creating stable branch that represents ein ir
(* 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 Var =
  struct

    datatype var = datatype AST.var

    datatype var_kind = datatype AST.var_kind

    fun nameOf (V{name, ...}) = name
    fun typeOf (V{ty, ...}) = ty
    fun monoTypeOf (V{ty=([], ty), ...}) = ty
      | monoTypeOf (V{name, ...}) = raise Fail(name ^ " is not monomrphic")
    fun kindOf (V{kind, ...}) = kind
    fun uniqueNameOf (V{name, id, ...}) = name ^ Stamp.toString id

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

    fun new (name, kind, ty) = newPoly (name, kind, ([], ty))

    fun copy (V{name, kind, ty, ...}) =
	  V{name=name, id=Stamp.new(), kind=kind, ty=ty, props=PropList.newHolder()}

  (* return true if variable has global scope *)
    fun isGlobal (V{kind, ...}) = (case kind
	   of BasisVar => 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 (V{kind, ...}) = (case kind
	  of BasisVar => "basis variable"
	   | InputVar => "input variable"
	   | GlobalVar => "global variable"
	   | FunVar => "function"
	   | StrandParam => "strand parameter"
	   | StrandStateVar => "state variable"
	   | StrandOutputVar => "strand output variable"
	   | LocalVar => "variable"
	  (* end case *))

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

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

  end

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