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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2497 - (download) (annotate)
Wed Oct 30 17:29:20 2013 UTC (8 years ago) by cchiw
File size: 3773 byte(s)
 
(*printer Function returns String*)
structure Printer = struct

    local
      structure G = GenericEin
      structure E = Ein
      structure S = Specialize
     (* structure R = Rewrite*)
    in 

    fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]

    fun printIndex e= (case e
        of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
        |  E.V(ix)=> Int.toString(ix)
    )

    fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]

    
    fun handleBeta(a,b)=String.concat["Delta_(",printIndex a, ",", printIndex b,")"]
  
    
          fun printbody term = (case term
            of E.Const r => Real.toString(r)
            | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
            | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]
            | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
            | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha 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 (alpha,e1)=> String.concat["Σ_", printAlpha alpha," (", printbody e1,")"]
            | E.Neg e1 => String.concat["-", 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_",printAlpha alpha]
            | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]

            | E.Conv(fid,alpha, tid ,[])=> String.concat["|V",Int.toString(fid),"_{",printAlpha alpha, "}★h",Int.toString(tid),"|"]
            | E.Conv(fid,alpha, tid, beta)=> String.concat["|V",Int.toString(fid),"_{",printAlpha alpha, "}★d/dx_{",printAlpha 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),"_",printAlpha alpha,"[",
                (String.concatWith "," (List.map printbody pos)),"]"]
     

           
            (* end case *))
        fun printerE (Ein.EIN{params, index, body}) = let
        fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
                " DIM:", Int.toString dim, ")", Index(i,count+1)]
            | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Sum:(",Int.toString(count),
                " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]
            | Index (_, count) = ""
        fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
            | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]
            | Param(_,_)=""
   
        val str=String.concat ["\n\t" ,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