Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/charisee/src/compiler/ein/printer.sml
ViewVC logotype

View of /branches/charisee/src/compiler/ein/printer.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2383 - (download) (annotate)
Thu Jun 13 01:57:34 2013 UTC (8 years ago) by cchiw
File size: 6092 byte(s)
added ein

structure Printer = struct

    local
    structure G = GenericEin
    structure E = Ein
    structure S = Specialize
    structure R = Rewrite

	in 

	fun printPairs([])=   print ""
    	| printPairs([e]) =(   let 
			val (a,b)=e in (print" Delta_";print(Int.toString(a));print(Int.toString(b))) end )
		 | printPairs(e1::en)= ( printPairs([e1]);  (let val q = (List.app (fn x=>  printPairs([x])) en) in q end)
		 )


    fun printInt(l)=        print(Int.toString(l))

   fun printerG(GenericEin.EIN{params, index, body})=
   let

        fun printer2 term = (case term
               of G.Tensor(id, mx) => (
                    case mx
                     of [] => (print "S"; print(Int.toString id))
                      | [a] => (print "T"; print(Int.toString id); print "_"; print(Int.toString a))
                      | _ => (print "T"; print(Int.toString id); print "_"; List.app printInt mx; print "")
                    (* end case *))
                | G.Field(id, mx) => (print "F";print(Int.toString(id)))
                | G.Add([b,c])=>(print("(");printer2(b); print("+");printer2(c); print(")"))
                | G.Add([b,c,d])=> (print("(");printer2(b);print("+"); printer2(c); print("+"); printer2(d); print(")"))
                | G.Add(_)=>(print("Need to add more terms in the Add"))
                | G.Sub(b,c)=>(printer2(b); print("-");printer2(c))
                | G.Prod([b,c])=>(print "(";printer2(b); print("*");printer2(c);print(")"))
                | G.Prod([b,c,d])=> (print"(";printer2(b);print("*"); printer2(c); print("*"); printer2(d);print (")"))
                | G.Prod(_)=>(print("Need to add more terms in the product"))
                | G.Delta(i,j)=> ( printPairs([(i,j)]))
                | G.Epsilon(i,j,k) =>( print "E_";print(Int.toString(i)); print(Int.toString(j));print(Int.toString(k)))
                | G.Conv(i,j,k,l) => (case length(j)
                        of 0=>( print i; print " * "; print k; print "_"; print(Int.toString(l)))
                        | _=> (print i; print " * "; print k; print "_";print(Int.toString(l));print("^(");printPairs(j);print ")"  )
                        (* end case *))
                | G.Partial([])=> (print "Error no list here")
                | G.Partial([a])=>(print "d/dx_" ; print(Int.toString(a)))
                | G.Partial(mx)=>(print "d^"; print(Int.toString(length(mx)))  ;print "/dx_" ;List.map printInt mx;print(""))
                | G.Probe(a,b)=> ( print "("; printer2(a); print ")"; print("@"); print("T"); print(Int.toString(b)))
                | G.Apply(a, b)=> ( print "Apply "; printer2(a); print " to " ; printer2(b) ; print ")" )
                | G.Sum(id, e)=> (print"Sigma "; print(Int.toString(id)); printer2(e))
                |_=>print("newbie")
                (*end case*))
		in
		(print"\n<";printer2(body);print">"; index)
		end
		
	fun printerE(Ein.EIN{params, index, body})=
   let
                  
            
        fun printer2 term = (case term
            of E.Tensor(id, mx) => (
                case mx
                of [] => (print " S"; print(Int.toString id))
                | [a] => (print " V"; print(Int.toString id); print "_"; print(Int.toString a))
                | [a,b]=> (print " M";print(Int.toString id); print "_"; List.app printInt mx)
                | _ => (print " T"; print(Int.toString id); print "_"; List.app printInt mx; print "")
                (* end case *))
            | E.Const(f)=> print("zero")
            | E.Field(id, mx) => (print "F";print(Int.toString(id));print("_"); List.app printInt mx )
            | E.Add([b,c])=>(print("(");printer2(b); print("+");printer2(c); print(")"))
            | E.Add([b,c,d])=> (print("(");printer2(b);print("+\n"); printer2(c); print("+\n"); printer2(d); print(")"))
            | E.Add(_)=>(print("Need to add more terms in the Add"))
            | E.Sub(b,c)=>(print"(";printer2(b); print(")\n -( ");printer2(c); print ")")
			| E.Prod([a])=> printer2(a)
            | E.Prod([E.Partial(a), E.Partial(b)]) =>(printer2(E.Partial(a));print(" "); printer2(E.Partial(b)))
            | E.Prod([E.Partial(a), E.Partial(b), c])=> (printer2(E.Partial(a));print(" ");  printer2(E.Partial(b)); print(" ");  printer2(c))
            | E.Prod(e)=>(print "("; List.map printer2(e);   print")")
            | E.Delta(i,j)=> ( printPairs([(i,j)]))
            | E.Epsilon(i,j,k) =>( print " E_";print(Int.toString(i)); print(Int.toString(j));print(Int.toString(k));print" " )
            | E.Conv(i,j,k,l) => (case length(j)
                of 0=>( print i; print " * "; print k; print "_"; print(Int.toString(l)))
                | _=> (print i; print " * "; print k; print "_";print(Int.toString(l));print("^(");printPairs(j);print ")"  )
                (* end case *))
            | E.Partial([])=> (print "Error no list here")
            | E.Partial([a])=>(print "d/dx_" ; print(Int.toString(a)))
            | E.Partial(mx)=>(print "d^"; print(Int.toString(length(mx)))  ;print "/dx_" ;List.map printInt mx;print(""))
            | E.Probe(a,b)=> ( print "("; printer2(a); print ")"; print("@"); print("T"); print(Int.toString(b)))
            | E.Apply(a, b)=> ( print "  "; printer2(a); print " " ; printer2(b) ;print " " )
            | E.Sum (id,a)=> (print " Sigma:"; print(Int.toString(id));printer2 a )
            |_=>print("newbie")
                (*end case *))
		
            fun printIndex ((E.IX(dim))::i, count)=(print("(");
                    print(Int.toString(count));
                    print(" DIM:");print(Int.toString(dim));print(") ");printIndex(i,count+1))
                |printIndex ((E.SX(dim))::i, count)=
            (print("} {Summation:(");print(Int.toString(count));
                        print(" DIM:");print(Int.toString(dim)); print(")");
                        printIndex(i,count+1))
                | printIndex(_, count)= print(" ")
            in
            (print"\n<";printer2(body);print">"; print("_{");printIndex(index,0);print("}"); index)

end


fun re e2 = (case e2
  of R.App(e, l) => printerE(e)
  )


end
end

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