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 2436 - (download) (annotate)
Sat Sep 21 15:57:18 2013 UTC (6 years, 1 month ago) by cchiw
Original Path: branches/charisee/src/compiler/ein/printer.sml
File size: 3482 byte(s)
changed mu to alpha
(*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)=> 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[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) => String.concat["Delta_", handleBeta ix]
            | E.Value(ix)=> String.concat["c-",Int.toString(ix)]
            | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
            | E.Sum (count,e1)=> String.concat["Sigma:", Int.toString(count), 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), "(*)h^",printAlpha alpha]
            | 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-", intList d," ",Param(param, i+1)]
            | Param(_,_)=""
   
        val str=String.concat [Param(params, 0)," \n<",printbody(body),">","\n _{",Index(index,0),"} \n \n \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