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 2426 - (download) (annotate)
Mon Sep 16 20:16:19 2013 UTC (6 years, 1 month ago) by cchiw
Original Path: branches/charisee/src/compiler/ein/printer.sml
File size: 3775 byte(s)
added deltas
(*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["c-",Int.toString(cx)]
        |  E.m([ix])=> Int.toString(ix)
        |  E.m(mx)=> intList(mx)
    )
    fun imp([])=""
    | imp([(i,j)])=  String.concat [" Delta_",printIndex(i),printIndex(j)]
    | imp((i,j)::es)= String.concat[" Delta_",printIndex(i),printIndex(j)," ",imp(es)]


    fun printerE (Ein.EIN{params, index, body}) = let
          fun printer2 term = (case term
                 of E.Value(id)=> String.concat[" CI-",Int.toString(id)]
                  | E.Tensor(id, E.m([])) =>String.concat[" S",Int.toString(id)]
                  | E.Tensor(id, ix) =>String.concat[" T",Int.toString(id),"_",printIndex ix]
                  | E.Pair e => String.concat["(",String.concatWith "," (List.map printer2 e),")"]
                  | E.Const e => Real.toString(e)
                  | E.Field(id, E.m [],E.m []) => String.concat ["F",Int.toString(id)]
                  | E.Field(id, mx,dx) => String.concat ["F",Int.toString(id),"_",printIndex(mx),",",printIndex(dx)]

                  | E.Add e        => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]
                  | E.Sub(a,b)      => String.concat ["(",printer2(a),"-",printer2(b), ")"]
                  | E.Div(a,b)      => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]
                  | E.Prod [e1,e2,e3]       => String.concatWith "*" (List.map printer2 [e1,e2,e3])
                  | E.Prod e       => String.concatWith "^^" (List.map printer2 e)
                  | E.Delta(dels)  => imp(dels) 
                  | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]
                  | E.Conv(k,[]) => String.concat ["V (*)",printer2(k)]
                  | E.Conv(k,[E.Delta(dels)]) => let
                       val n= length(dels)
                    in
                        String.concat ["V (*)",printer2(k),"^",Int.toString(n),"{",imp(dels),"}"]
                    end
                  | E.Conv(k,_) => "Incorrect convolution argument"
                  | E.Partial(E.c(ix)) => String.concat ["d^1","/dx_",Int.toString(ix)]
                  | E.Partial(E.m(mx))  => String.concat ["d^",Int.toString(length(mx)),"/dx_",intList(mx)]
                  | E.Probe(a,b) => String.concat ["",printer2(a), "","@", printer2(b)]
                  | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]
                  | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]
                  | _ =>("newbie")
                (* 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<",printer2(body),">","\n _{",Index(index,0),"} \n "]
        in
            print 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