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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2605 - (download) (annotate)
Wed Apr 30 01:46:09 2014 UTC (7 years, 3 months ago) by cchiw
File size: 2423 byte(s)
code cleanup
(*Orders Ein Function after substitution*)
structure OrderEin = struct

    local

    structure E = Ein
    structure F = Filter

    in

fun rewriteProd A=(case A
    of [A]=> A
    | A => E.Prod A
    (*end case*))

fun rewriteApply(c,p)= E.Apply(c, rewriteProd p)


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*))


(*Orders the expression correctly.*)
fun orderfn(Ein.EIN{params, index, body})= let
   val changed =ref false
   fun order(body)=(case body
        of E.Const _ => body
        | E.Tensor _=> body
        | E.Field _ => body
        | E.Krn _ => body
        | E.Img _ => body
        | E.Delta _ => body
        | E.Value _ => body
        | E.Epsilon _=>body
        | E.Partial _ => body
        | E.Conv _=>body 
        | E.Sum(c1,E.Sum(c2, e))=>(changed:=true;E.Sum(c1@c2,order e))
            (*   | E.Sum([c1],E.Prod p)=> let
            val _ =print "\n Sum prod"
            val p'=order(E.Prod p)
            val (change,e')= (case p'
                of E.Prod p''=> F.pushSum(c1,p'')
                | _=> (1,E.Sum([c1],p'))
                (*end case *))
            in (case change of 1=>(changed:=true; e') |_=> e')
            end*)
        | E.Sum(c,e)=>(print "\n other sum"; E.Sum(c, order e))
        | E.Lift e => E.Lift(order e)
        | E.Neg e => E.Neg(order e)
        | E.Add es => E.Add (List.map order es)
        | E.Sub(e1,e2) => E.Sub(order e1, order e2)
        | E.Div(e1,e2)=> E.Div(order e1, order e2)
        | E.Apply(e1,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.Prod [e1]=>e1
        | E.Prod e=> let
            val(s,eps,dels,p)= F.filterGreek e
            val p'=List.map order p
            in E.Prod(s@eps@dels@p')
            end
        (*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