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 3350 - (download) (annotate)
Tue Oct 27 22:56:49 2015 UTC (3 years, 10 months ago) by cchiw
File size: 4698 byte(s)
look for re in mid-to-low as converting
(*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)=> String.concat["'",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 term = (case term
        of E.Const r => iTos(r)
        | 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.Field(id, []) =>String.concat[" F",iTos(id)]
        | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
        | 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.Delta(ix) =>  handleBeta ix
        | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
        | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
        | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
        | 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.Neg e1 => String.concat["-NEG-", printbody e1]
        | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
        | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
        | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
 | E.Prod el => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]
        | E.Div(e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
        | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
        | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
 
        | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
                | E.Conv(fid,alpha, tid, [b0,b1])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h2(",iTos(tid),")dx_",handleAlpha [b0,b1],"}|"]
        | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
 (*
         | E.Conv(fid,alpha, tid,[])=> String.concat["F_",handleAlpha alpha]
         | E.Conv(fid,alpha, tid, beta)=> String.concat["F_",handleAlpha alpha,"∇",handleAlpha beta]
 *)
        | E.Probe (e1,e2)=> String.concat [printbody(e1)(*,"[", printbody(e2),"]"*)]
        | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[",
                (String.concatWith "," (List.map printbody pos)),"]"]
        | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
        | E.PowInt(e,n1) => String.concat[  "(",printbody e ,")^",iTos n1]
        | E.PowReal(e,n1) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
        | E.Cosine e=>  String.concat["Cosine(",printbody e ,")"]
        | E.ArcCosine e=> String.concat["ArcCosine(",printbody e ,")"]
        | E.Sine e => String.concat["Sine(",printbody e ,")"]
        | E.ArcSine e => String.concat["ArcSine(",printbody e ,")"]
        (* 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