SCM Repository
View of /branches/charisee/src/compiler/ein/printer.sml
Parent Directory
|
Revision Log
Revision 2584 -
(download)
(annotate)
Tue Apr 15 03:22:58 2014 UTC (6 years, 10 months ago) by cchiw
File size: 3800 byte(s)
Tue Apr 15 03:22:58 2014 UTC (6 years, 10 months ago) by cchiw
File size: 3800 byte(s)
Multiply Fields
(*printer Function returns String*) structure Printer = struct local structure E = Ein in fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)] fun handleIndex e= (case e of E.C(cx)=> String.concat["'",Int.toString(cx),"'"] | E.V(ix)=> Int.toString(ix) ) 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),"[",Int.toString(lb),"-",Int.toString(ub),"]"] fun printbody term = (case term of E.Const r => Int.toString(r) | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)] | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",handleAlpha alpha] | E.Field(id, []) =>String.concat[" F",Int.toString(id)] | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",handleAlpha alpha] | E.Krn(tid,[],pos) =>String.concat[" H ",Int.toString(tid),"[", (printbody pos),"]"] | E.Krn(tid,betas,pos) => String.concat[" H",Int.toString(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"] | E.Delta(ix) => handleBeta ix | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"] | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)] | E.Sum (sumindex,e1)=>String.concat[" Σ_",String.concatWith ","(List.map handleSumRange sumindex),"~" ,printbody e1,"~"] | E.Neg e1 => String.concat["-NEG-", 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",Int.toString(fid),"_{",handleAlpha alpha, "}★h",Int.toString(tid),"|"] | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",Int.toString(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",Int.toString(tid),"|"] | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","[", printbody(e2),"]"] | E.Img (fid,alpha,pos)=> String.concat [" V", Int.toString(fid),"_",handleAlpha alpha,"[", (String.concatWith "," (List.map printbody pos)),"]"] (* end case *)) fun printerE (Ein.EIN{params, index, body}) = let fun Index (dim::i, count) = String.concat["(", Int.toString count, " DIM:", Int.toString dim, ")", Index(i,count+1)] | Index (_, count) = "" fun Param(E.TEN(t,shape)::param, i)=let val shape'=List.map(fn e1=>Int.toString(e1)) shape in String.concat[Int.toString(i), ":TEN", Int.toString t," ", String.concatWith"," shape'," --",Param(param, i+1)] end | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)] | Param(E.IMG(d)::param, i)= String.concat[Int.toString(i), ":IMG-", Int.toString d," ",Param(param, i+1)] | Param(E.KRN::param, i)= String.concat[Int.toString(i), ":KRN ",Param(param, i+1)] | Param(_,_)="" val str=String.concat ["\n" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} \n "] in str end (* fun printerApp(R.App(e,l))= printerE(e) | printerApp(_)= ""*) end (* local *) end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |