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

SCM Repository

[diderot] View of /trunk/src/ast/meta-var.sml
ViewVC logotype

View of /trunk/src/ast/meta-var.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (download) (annotate)
Wed May 26 17:28:54 2010 UTC (9 years, 1 month ago) by jhr
File size: 2043 byte(s)
  Working on typechecker
(* meta-var.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * The Diderot typechecker uses four kinds of meta variables:
 *
 *	type variables
 *	differentiation variables
 *	shape variables
 *	dimension variables
 *)

structure MetaVar =
  struct

    datatype ty_var = datatype Types.ty_var
    datatype diff_var = datatype Types.diff_var
    datatype shape_var = datatype Types.shape_var
    datatype dim_var = datatype Types.dim_var
    datatype kind = datatype Types.kind


  (***** Type variables ****)

    fun newTyVar () = TV{
	    id = Stamp.new(),
	    bind = ref NONE
	  }

    fun tyVarToString (TV{id, ...}) = "'ty" ^ Stamp.toString id


  (***** Differentiation variables ****)

    fun newDiffVar bnd = DfV{
	    id = Stamp.new(),
	    bound = ref bnd,
	    bind = ref NONE
	  }

    fun diffVarToString (DfV{id, ...}) = "'diff" ^ Stamp.toString id


  (***** Shape variables ****)

    fun newShapeVar () = SV{
	    id = Stamp.new(),
	    bind = ref NONE
	  }

    fun shapeVarToString (SV{id, ...}) = "'shp" ^ Stamp.toString id


  (***** Dimension variables ****)

    fun newDimVar () = DV{
	    id = Stamp.new(),
	    bind = ref NONE
	  }

    fun dimVarToString (DV{id, ...}) = "'dim" ^ Stamp.toString id


  (***** Meta variables ****)

    fun metaToString (TYPE tv) = tyVarToString tv
      | metaToString (DIFF dv) = diffVarToString dv
      | metaToString (SHAPE sv) = shapeVarToString sv
      | metaToString (DIM dv) = dimVarToString dv

    fun stamp (TYPE(TV{id, ...})) = id
      | stamp (DIFF(DfV{id, ...})) = id
      | stamp (SHAPE(SV{id, ...})) = id
      | stamp (DIM(DV{id, ...})) = id

    fun copy (TYPE _) = TYPE(newTyVar())
      | copy (DIFF(k as DfV{bound, ...})) = DIFF(newDiffVar(!bound))
      | copy (SHAPE _) = SHAPE(newShapeVar())
      | copy (DIM _) = DIM(newDimVar())

    structure Map = RedBlackMapFn (
      struct
	type ord_key = Types.meta_var
	fun compare (mv1, mv2) = Stamp.compare(stamp mv1, stamp mv2)
      end)

  end

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