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 2391 - (download) (annotate)
Sun Jun 16 19:14:08 2013 UTC (6 years, 3 months ago) by jhr
Original Path: branches/charisee/src/compiler/ein/printer.sml
File size: 3026 byte(s)
  style edits
(*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.concatWith "," (List.map Int.toString l)
	
    fun printerE (Ein.EIN{params, index, body}) = let            
          fun printer2 term = (case term
                 of E.Tensor(id, mx) => (
                     case mx
                     of [] => ( " S"^Int.toString(id))
                     | [a] => ( " V"^Int.toString(id)^ "_"^Int.toString(a))
                     | [a,b]=> ("M"^Int.toString(id)^ "_"^ intList(mx))
                     | _ =>  ("T"^Int.toString(id)^ "_"^intList(mx))
                     (* end case *))
                  | E.Const(f)=> ("zero")
                  | E.Field(id, mx) => ( "F"^Int.toString(id)^"_"^intList(mx))
                  | E.Add(e)=> let 
                      fun imp([])=""
                      | imp([a])=printer2(a)
                      | imp(a::es)=(printer2(a)^"+"^imp(es))
                      in ("("^imp(e)^")") end
                  | E.Sub(b,c)=>("("^printer2(b)^"- "^printer2(c)^ ")")

                  | E.Prod(e)=>let
                      fun imp [] = ""
                        | imp [a] = printer2(a)
                        | imp (a::es) = printer2(a) ^ " "^ imp(es)
                      in "("^imp(e)^")" end
                  | E.Delta(i,j)=> (" Delta_"^Int.toString(i)^Int.toString(j))
                  | E.Epsilon(i,j,k) =>(" E_"^Int.toString(i)^Int.toString(j)^Int.toString(k) )
                  | E.Conv(i,j,k,l) => let
                      fun imp([])=""
                      | imp([(a,b)])=(" Delta_"^Int.toString(a)^Int.toString(b))
                      | imp((a,b)::es)=(" Delta_"^Int.toString(a)^Int.toString(b))^" "^imp(es)
                      in i^"*"^k^"^{"^imp(j)^"}_"^Int.toString(l) end
                  | E.Partial(e)=> ("d"^ Int.toString(length(e))^"/dx_"^intList(e))
                  | E.Probe(a,b)=> ( "("^printer2(a)^ ")"^"@"^"T"^Int.toString(b))
                  | E.Apply(a, b)=> (printer2(a)^ " " ^printer2(b) ^ " " )
                  | E.Sum (id,a)=> ( " 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)=("} {Summation:("^Int.toString(count) ^
                " DIM:"^Int.toString(dim)^")"^ Index(i,count+1))
            | Index (_, count) = ""
            in
                ("\n<"^printer2(body)^">"^"_{"^Index(index,0)^"}")
            end


        fun printerApp(R.App(e,l)) =let 
            fun argList([])=""
              | argList([e])=e
              |argList(e::es)= e^","^argList(es)
            in printerE(e)^"["^argList(l)^"]" end
        |printerApp(_)=""


    end (* local *)
  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0