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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3383 - (download) (annotate)
Mon Nov 9 02:39:26 2015 UTC (3 years, 9 months ago) by cchiw
File size: 1964 byte(s)
cut vector fields
(* Expands probe ein
 *
 * 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 einSet = struct

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


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


   structure OprKey =
        struct
        type ord_key =MidIL.var*MidIL.rhs
        val compare = cmp
    end;
    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),")\n"])
        |einSetToString _ =""

    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))= (
        EinSet.find(
            (fn (_,MidIL.EINAPP(ein1,arg1))=>(EqualEin.isEinEqual(ein0,ein1) andalso allEq(arg0,arg1)) | _ =>false
        ))) tbl
        | setFind  _ = NONE

    fun rtnVar (tbl,v,e)=(case setFind(tbl,v,e)
        of NONE     => ((einSetToString("\n\t 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 rtnVarN (tbl,(v,e))=(case setFind(tbl,v,e)
of NONE     => ((einSetToString("\n\t 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))



  end; (* local *)

end (* local *)

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