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 2448 - (download) (annotate)
Tue Oct 1 00:57:08 2013 UTC (6 years ago) by cchiw
Original Path: branches/charisee/src/compiler/ein/printer.sml
File size: 3529 byte(s)
Change Sum term
(*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 printerE (Ein.EIN{params, index, body}) = let
          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.Kernel([]) =>String.concat["h"]
            | E.Kernel(betas) =>String.concat["h^{",String.concat(List.map handleBeta betas),"}"]
            | 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["Sigma:", 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.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(e1, [])=> String.concat[printbody(e1), "(*)h"]
            | E.Conv(e1, alpha)=> String.concat[printbody(e1), "(*) d/dx_{",printAlpha alpha,"}h"]
            | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","@", printbody(e2)]
            | E.Image(e1::es)=> let
                    val position=  String.concatWith "," (List.map printbody es)
                in
                    String.concat [printbody(e1),"[", position,"]"]
                end
            (* end case *))

        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[ "} {Summation:(",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)," \n \t <",printbody(body),">","\n \t _{",Index(index,0),"} \n "]
        in
            print str; 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