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

SCM Repository

[diderot] Diff of /branches/charisee_dev/src/compiler/ein/printer.sml
ViewVC logotype

Diff of /branches/charisee_dev/src/compiler/ein/printer.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2383, Thu Jun 13 01:57:34 2013 UTC revision 2449, Thu Oct 3 20:15:16 2013 UTC
# Line 1  Line 1 
1    
2    (*printer Function returns String*)
3  structure Printer = struct  structure Printer = struct
4    
5      local      local
6      structure G = GenericEin      structure G = GenericEin
7      structure E = Ein      structure E = Ein
8      structure S = Specialize      structure S = Specialize
9      structure R = Rewrite       (* structure R = Rewrite*)
   
10          in          in
11    
12          fun printPairs([])=   print ""      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
13          | printPairs([e]) =(   let  
14                          val (a,b)=e in (print" Delta_";print(Int.toString(a));print(Int.toString(b))) end )      fun printIndex e= (case e
15                   | printPairs(e1::en)= ( printPairs([e1]);  (let val q = (List.app (fn x=>  printPairs([x])) en) in q end)          of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
16            |  E.V(ix)=> Int.toString(ix)
17                   )                   )
18    
19        fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]
20    
     fun printInt(l)=        print(Int.toString(l))  
21    
22     fun printerG(GenericEin.EIN{params, index, body})=      fun handleBeta(a,b)=String.concat["Delta_(",printIndex a, ",", printIndex b,")"]
    let  
23    
24          fun printer2 term = (case term  
25                 of G.Tensor(id, mx) => (            fun printbody term = (case term
26                      case mx              of E.Const r => Real.toString(r)
27                       of [] => (print "S"; print(Int.toString id))              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
28                        | [a] => (print "T"; print(Int.toString id); print "_"; print(Int.toString a))              | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]
29                        | _ => (print "T"; print(Int.toString id); print "_"; List.app printInt mx; print "")              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
30                      (* end case *))              | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]
31                  | G.Field(id, mx) => (print "F";print(Int.toString(id)))              | E.Kernel([]) =>String.concat["h"]
32                  | G.Add([b,c])=>(print("(");printer2(b); print("+");printer2(c); print(")"))              | E.Kernel(betas) =>String.concat["h^{",String.concat(List.map handleBeta betas),"}"]
33                  | G.Add([b,c,d])=> (print("(");printer2(b);print("+"); printer2(c); print("+"); printer2(d); print(")"))              | E.Delta(ix) =>  handleBeta ix
34                  | G.Add(_)=>(print("Need to add more terms in the Add"))              | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]
35                  | G.Sub(b,c)=>(printer2(b); print("-");printer2(c))              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
36                  | G.Prod([b,c])=>(print "(";printer2(b); print("*");printer2(c);print(")"))              | E.Sum (alpha,e1)=> String.concat["Sigma:", printAlpha alpha," (", printbody e1,")"]
37                  | G.Prod([b,c,d])=> (print"(";printer2(b);print("*"); printer2(c); print("*"); printer2(d);print (")"))              | E.Neg e1 => String.concat["-", printbody e1]
38                  | G.Prod(_)=>(print("Need to add more terms in the product"))              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
39                  | G.Delta(i,j)=> ( printPairs([(i,j)]))              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
40                  | G.Epsilon(i,j,k) =>( print "E_";print(Int.toString(i)); print(Int.toString(j));print(Int.toString(k)))              | E.Prod el => String.concatWith "* " (List.map printbody el)
41                  | G.Conv(i,j,k,l) => (case length(j)              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
42                          of 0=>( print i; print " * "; print k; print "_"; print(Int.toString(l)))              | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]
43                          | _=> (print i; print " * "; print k; print "_";print(Int.toString(l));print("^(");printPairs(j);print ")"  )              | E.Apply(e1, e2)=> String.concat [ printbody(e1)," ", printbody(e2)," "]
44                          (* end case *))              | E.Conv(e1, [])=> String.concat[printbody(e1), "(*)h"]
45                  | G.Partial([])=> (print "Error no list here")              | E.Conv(e1, alpha)=> String.concat[printbody(e1), "(*) d/dx_{",printAlpha alpha,"}h"]
46                  | G.Partial([a])=>(print "d/dx_" ; print(Int.toString(a)))              | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","@", printbody(e2)]
47                  | G.Partial(mx)=>(print "d^"; print(Int.toString(length(mx)))  ;print "/dx_" ;List.map printInt mx;print(""))              | E.Image(e1::es)=> let
48                  | G.Probe(a,b)=> ( print "("; printer2(a); print ")"; print("@"); print("T"); print(Int.toString(b)))                      val position=  String.concatWith "," (List.map printbody es)
                 | 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*))  
49                  in                  in
50                  (print"\n<";printer2(body);print">"; index)                      String.concat [printbody(e1),"[", position,"]"]
51                  end                  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")  
52                  (*end case *))                  (*end case *))
53            fun printerE (Ein.EIN{params, index, body}) = let
54            fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
55                    " DIM:", Int.toString dim, ")", Index(i,count+1)]
56                | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
57                    " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]
58                | Index (_, count) = ""
59            fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
60                | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]
61                | Param(_,_)=""
62    
63              fun printIndex ((E.IX(dim))::i, count)=(print("(");          val str=String.concat ["\n\t" ,Param(params, 0)," \n \t <",printbody(body),">","\n \t _{",Index(index,0),"} \n "]
                     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(" ")  
64              in              in
65              (print"\n<";printer2(body);print">"; print("_{");printIndex(index,0);print("}"); index)              print str; str
   
66  end  end
67    
68           (* fun printerApp(R.App(e,l))= printerE(e)
69                | printerApp(_)= ""*)
70    
71  fun re e2 = (case e2      end (* local *)
   of R.App(e, l) => printerE(e)  
   )  
   
   
 end  
72  end  end

Legend:
Removed from v.2383  
changed lines
  Added in v.2449

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