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 2414 - (download) (annotate)
Mon Aug 19 05:02:14 2013 UTC (6 years ago) by cchiw
Original Path: branches/charisee/src/compiler/ein/printer.sml
File size: 3138 byte(s)
changes
(*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 printerE (Ein.EIN{params, index, body}) = let            
          fun printer2 term = (case term
                 of E.Tensor(id, [])  => String.concat[" S",Int.toString(id)]
                  | E.Tensor(id, mx) =>  String.concat[" T",Int.toString(id),"_",intList(mx)]
                  | E.Const e => Real.toString(e)
                  | E.Field(id, []) => String.concat ["F",Int.toString(id)]
                  | E.Field(id, mx) => String.concat ["F",Int.toString(id),"_",intList(mx)]
                  | 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 e       => String.concatWith "*" (List.map printer2 e)
                  | E.Delta(i,j)    => String.concat [" Delta_",Int.toString(i),Int.toString(j)]
                  | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]
                  | E.Conv(k,deltas) => let
                      val n= length(deltas)
                      fun imp([])=""
                      | imp([(i,j)])=  String.concat [" Delta_",Int.toString(i),Int.toString(j)]
                      | imp((i,j)::es)= String.concat[" Delta_",Int.toString(i),Int.toString(j)," ",imp(es)]
                      in
                        String.concat ["V (*)",printer2(k),"{",imp(deltas),"}_",Int.toString(n)]
                      end
                  | E.Partial e  => String.concat ["d^",Int.toString(length(e)),"/dx_",intList(e)]
                  | 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(dim))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
                " DIM:",Int.toString(dim),")", 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(_,_)=""
            in
                String.concat ["\n",Param(params, 0),"\n<",printer2(body),">","_{",Index(index,0),"}\n"]
            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