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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-il/order-ein.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-il/order-ein.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3448 - (download) (annotate)
Fri Nov 20 20:33:38 2015 UTC (4 years ago) by cchiw
File size: 2678 byte(s)
merge over dev branch
(*Orders Ein Function after substitution
*Could be moved to High-IL
*)
structure OrderEin = struct

    local

    structure E = Ein
    structure F = Filter

    in

    (*rewriteProd:ein_exp list ->ein_exp*)
    fun rewriteProd A=(case A
        of [A]=> A
        | A => E.Opn(E.Prod, A)
        (*end case*))

    (*rewriteProd:ein_exp * ein_exp list ->ein_exp*)
    fun rewriteApply(c,p)= E.Apply(c, rewriteProd p)

    (*pushApply:ein_exp * ein_exp list ->int* ein_exp
    *Moves non-field expression outside of apply
    *)
    fun pushApply (del,p)=(case F.filterField p
        of ([],[])    => raise Fail"No Field in Apply expression"
        | ([],post) => (0,rewriteApply(del,post))
        | (pre,post)=> (1,rewriteProd(pre@[rewriteApply(del,post)]))
        (*end case*))

    (*orderfn:EIN->EIN
     Does some smple ordering
    Scalars*Epsilons*deltas*else
    *)
    fun orderfn(Ein.EIN{params, index, body})= let
       val changed =ref false
       fun order b = (case b
            of E.B  _                   => b
            | E.Tensor _                => b
            | E.G _                     => b
            | E.Field _                 => b
            | E.Lift e1                 => E.Lift(order e1)
            | E.Conv _                  => b
            | E.Partial _               => b
            | E.Apply(e1,E.Opn(E.Prod, e2))     => let
                val(change,e')=pushApply (e1,e2)
                in (case change of 1=>(changed:=true; e') |_=> e')
                end
            | E.Apply(e1,e2)            => E.Apply(e1, order e2)
            | E.Probe(e1,e2)            => E.Probe(order e1,order e2)
            | E.Value _                 => b
            | E.Img _                   => b
            | E.Krn _                   => b
            | E.Sum(c1,E.Sum(c2, e))    => (changed:=true;E.Sum(c1@c2,order e))
            | E.Sum(c,e1)               => E.Sum(c, order e1)
            | E.Op1(op1, e1)            => E.Op1(op1,order e1)
            | E.Op2(op2, e1,e2)         => E.Op2(op2,order e1,order e2)
            | E.Opn(E.Prod, es)=> let
                val(s,eps,dels,p)= F.filterGreek es
                val p'=List.map order p
                in E.Opn(E.Prod,s@eps@dels@p') end
            | E.Opn(opn, es)            => E.Opn(opn,List.map order es)
            (*end case*))
        fun loop body = let
        val body' = order body
            in
                if !changed
                    then (changed := false; loop body')
                else body'
            end
            val b = loop body
            val b'=order b
       in (Ein.EIN{params=params, index=index, body=b'}) end

end (* local *)

end 

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