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 2603 - (download) (annotate)
Thu Apr 24 03:58:37 2014 UTC (7 years, 3 months ago) by cchiw
File size: 2629 byte(s)
Added Lift Constructor
(*Orders Ein Function after substitution*)
structure OrderEin = struct

    local

    structure E = Ein
    structure F = Filter

    in

fun pushApply (del,p)= let
    val _=print "In push Apply"
    val(pre,post)=F.filterField p
    in (case (pre,post)
        of ([],[])    => raise Fail"No Field in Apply expression"
        | ([],[keep]) => (0,E.Apply(del,keep))
        | ([],keep)   => (0,E.Apply(del,E.Prod(keep)))
        | (_,[keep])  => (1,E.Prod(pre@[E.Apply(del,keep)]))
        |  _          => (1,E.Prod(pre@[E.Apply(del,E.Prod(post))]))
        (*end case*))
    end


(*Orders the expression correctly.*)
fun orderfn(Ein.EIN{params, index, body})= let
  (* val _ = print "\n IN ORDER \n"*)
   val changed =ref false
   fun order(body)=(case body
        of E.Const _ => body
        | E.Tensor _=> body
        | E.Field _ => body
        | E.Krn _ => 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,E.Add[e2,e3]) => E.Add[E.Apply(e1,e2),E.Apply(e1,e3)]
        | E.Apply(e1,e2)=> (print "\n Found apply"; E.Apply(e1, order e2))
        | E.Probe(e1,e2)=>  E.Probe(order e1,order e2)
        | E.Img _ => body
        | 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