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

SCM Repository

[diderot] View of /branches/charisee_dev/src/compiler/ein/printer.sml
ViewVC logotype

View of /branches/charisee_dev/src/compiler/ein/printer.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3472 - (download) (annotate)
Tue Dec 1 18:45:25 2015 UTC (3 years, 10 months ago) by cchiw
File size: 5246 byte(s)
adding split to different level
(*printer Function returns String*)
structure Printer = struct

    local

      structure E = Ein

    in 

    fun iTos e=Int.toString e
    fun intList l = String.concatWith "," (List.map iTos l)
    fun handleIndex e= (case e
        of E.C(cx,true)=> String.concat["'",iTos(cx),"'"]
        | E.C(cx,false)=> String.concat["S",iTos(cx),"'"]
        | E.V(ix)=> iTos(ix)
    (*end case*))
    fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
    fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
    fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
    fun printbody b= (case b
        of E.B(E.Const r) => iTos(r)
        | E.B(E.ConstR r) =>RationalEin.toString r
        | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
        | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
        | E.G(E.Delta(ix)) =>  handleBeta ix
        | E.G(E.Epsilon(ix, jx, kx)) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
        | E.G(E.Eps2(ix, jx)) => String.concat["ϵ_",iTos(ix), iTos(jx)]
 
        | E.Field(id, []) =>String.concat[" F",iTos(id)]
        | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
        | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
 
        | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
        | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
 (*
        | E.Conv _ => "F"
 *)
        | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
        | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
 (*
        | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
 *)
         | E.Probe (e1,e2)=> String.concat ["Probe(",printbody(e1),")"]
        | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
        | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[", (String.concatWith "," (List.map printbody pos)),"]"]
        | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
        | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
 
        | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
        | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
 (*
         | E.Sum (sumindex,e1)=>String.concat[" Σ",printbody e1,"⋑"]
 *)
        | E.Op1(E.Neg, e1) => String.concat["-NEG-", printbody e1]
        | E.Op1(E.Sqrt ,e )=> String.concat[ "√(", printbody e ,")"]
        | E.Op1(E.PowInt n1,e) => String.concat[  "(",printbody e ,")^",Int.toString n1]
        | E.Op1(E.PowReal n1,e) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
        | E.Op1(E.PowEmb (sx,n),e)=>String.concat["POW(",printbody e,"^", iTos n,")"]
        | E.Op1(E.Exp, e1)=> String.concat["E^(",printbody e1,")"]
        | E.Op1(t,e)=>(case t
            of  E.Cosine =>  String.concat["Cosine(",printbody e ,")"]
            | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
            | E.Sine  => String.concat["Sine(",printbody e ,")"]
            | E.ArcSine  => String.concat["ArcSine(",printbody e ,")"]
            | E.Tangent  => String.concat["Tangent(",printbody e ,")"]
            | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
            (*end case*))
        | E.Op2(E.Sub,e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
        | E.Op2(E.Div,e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
 (*
        | E.Opn(E.Add, el) => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
        | E.Opn(E.Prod, el) => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]*)
 | E.Opn(E.Add, el) => String.concat["Add(",String.concatWith "+" (List.map printbody el),")"]
 | E.Opn(E.Prod, el) => String.concat["Prod<",String.concatWith "* " (List.map printbody el),">"]
 
        (* end case *))

    (*printerE:EIN ->string*)
    fun printerE (Ein.EIN{params, index, body}) = let
        fun Index (dim::i, count) = String.concat["(", iTos count,
                " DIM:", iTos dim, ")", Index(i,count+1)]
            | Index (_, count) = ""
        fun Param(E.TEN(t,shape)::param, i)=
                String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
            | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
            | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
                        (intList shape),  ">, ",Param(param, i+1)]
            | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
            | Param(_,_)=""
   
        in
           String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
               
        end
                    
    end (* local *)
  end

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