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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-to-mid/einSet.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-to-mid/einSet.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3174 - (download) (annotate)
Mon Mar 30 11:46:58 2015 UTC (4 years, 1 month ago) by cchiw
File size: 2276 byte(s)
(* Expands probe ein
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.

structure einSet = struct

    structure E = Ein
    structure DstIL = MidIL
    structure DstOp = MidOps
    structure P=Printer
    structure T=TransformEin
    structure MidToS=MidToString
    structure DstV  = DstIL.Var

   fun cmp((_,MidIL.EINAPP(e1,_)),(_,MidIL.EINAPP(e2,_)))=(Word.compare(HashEin.hashfn e1, HashEin.hashfn e2))

   structure OprKey =
        type ord_key =MidIL.var*MidIL.rhs
            (*(Ein.ein * MidIL.var)*) 
        val compare = cmp
    structure  EinSet= RedBlackSetFn(OprKey);

    fun einSetToString(str,v,MidIL.EINAPP(e,args))=(String.concat["\n",str,DstV.toString v,"=",
                P.printerE e,"(",String.concatWith","(List.map DstV.toString args),")"])

    fun allEq([], []) = true
      | allEq(x::xs, y::ys) = DstIL.Var.same(x,y) andalso allEq (xs,ys)
      | allEq _ = false

    fun setFind (tbl,_,MidIL.EINAPP(ein0,arg0))= (
            (fn (_,MidIL.EINAPP(ein1,arg1))=>(EqualEin.isEinEqual(ein0,ein1) andalso allEq(arg0,arg1)))
        )) tbl

    fun rtnVar (tbl,v,e)=(case setFind(tbl,v,e)
        of NONE     => (einSetToString("\n\n inserting: ",v,e);(EinSet.add(tbl,(v,e)), NONE))
        | SOME(v1,e1) => ((einSetToString("\n\nfound: ",v,e));(einSetToString("\n with: ",v1,e1));(tbl,SOME v1))
        (*end case*))

    fun setToString tbl=List.map (fn (e1,e2)=> einSetToString("\n",e1,e2)) (EinSet.listItems (tbl))

    val tbl1= EinSet.empty
    val x0=(DstV.new ("Y", MidILTypes.realTy),MidIL.EINAPP(MkOperators.cross2TT,[]))
    val x1=(DstV.new ("Y", MidILTypes.realTy),MidIL.EINAPP(MkOperators.cross2FF,[]))
    val tbl2=EinSet.add(tbl1,x0)
    val tbl2=EinSet.add(tbl2,x1)
    val tbl4= setFind (tbl2,MidIL.EINAPP(MkOperators.cross3TT,[]))
    val tbl3= setFind(tbl2,MidIL.EINAPP(MkOperators.cross2TT,[]))
    val _=rtnVar(tbl2,MidIL.EINAPP(MkOperators.cross2FF,[]))
    val _=rtnVar(tbl2,MidIL.EINAPP(MkOperators.cross2TT,[]))
    val _ =setToString tbl2*)

val hash_fn : Ein.ein->word = HashEin.hashfn e1
fun cmp_fn =cmp
val initial_size : int = 101

  end; (* local *)

end (* local *)

ViewVC Help
Powered by ViewVC 1.0.0