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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2383 - (view) (download)

1 : cchiw 2383
2 :    
3 :     structure Printer = struct
4 :    
5 :     local
6 :     structure G = GenericEin
7 :     structure E = Ein
8 :     structure S = Specialize
9 :     structure R = Rewrite
10 :    
11 :     in
12 :    
13 :     fun printPairs([])= print ""
14 :     | printPairs([e]) =( let
15 :     val (a,b)=e in (print" Delta_";print(Int.toString(a));print(Int.toString(b))) end )
16 :     | printPairs(e1::en)= ( printPairs([e1]); (let val q = (List.app (fn x=> printPairs([x])) en) in q end)
17 :     )
18 :    
19 :    
20 :     fun printInt(l)= print(Int.toString(l))
21 :    
22 :     fun printerG(GenericEin.EIN{params, index, body})=
23 :     let
24 :    
25 :     fun printer2 term = (case term
26 :     of G.Tensor(id, mx) => (
27 :     case mx
28 :     of [] => (print "S"; print(Int.toString id))
29 :     | [a] => (print "T"; print(Int.toString id); print "_"; print(Int.toString a))
30 :     | _ => (print "T"; print(Int.toString id); print "_"; List.app printInt mx; print "")
31 :     (* end case *))
32 :     | G.Field(id, mx) => (print "F";print(Int.toString(id)))
33 :     | G.Add([b,c])=>(print("(");printer2(b); print("+");printer2(c); print(")"))
34 :     | G.Add([b,c,d])=> (print("(");printer2(b);print("+"); printer2(c); print("+"); printer2(d); print(")"))
35 :     | G.Add(_)=>(print("Need to add more terms in the Add"))
36 :     | G.Sub(b,c)=>(printer2(b); print("-");printer2(c))
37 :     | G.Prod([b,c])=>(print "(";printer2(b); print("*");printer2(c);print(")"))
38 :     | G.Prod([b,c,d])=> (print"(";printer2(b);print("*"); printer2(c); print("*"); printer2(d);print (")"))
39 :     | G.Prod(_)=>(print("Need to add more terms in the product"))
40 :     | G.Delta(i,j)=> ( printPairs([(i,j)]))
41 :     | G.Epsilon(i,j,k) =>( print "E_";print(Int.toString(i)); print(Int.toString(j));print(Int.toString(k)))
42 :     | G.Conv(i,j,k,l) => (case length(j)
43 :     of 0=>( print i; print " * "; print k; print "_"; print(Int.toString(l)))
44 :     | _=> (print i; print " * "; print k; print "_";print(Int.toString(l));print("^(");printPairs(j);print ")" )
45 :     (* end case *))
46 :     | G.Partial([])=> (print "Error no list here")
47 :     | G.Partial([a])=>(print "d/dx_" ; print(Int.toString(a)))
48 :     | G.Partial(mx)=>(print "d^"; print(Int.toString(length(mx))) ;print "/dx_" ;List.map printInt mx;print(""))
49 :     | G.Probe(a,b)=> ( print "("; printer2(a); print ")"; print("@"); print("T"); print(Int.toString(b)))
50 :     | G.Apply(a, b)=> ( print "Apply "; printer2(a); print " to " ; printer2(b) ; print ")" )
51 :     | G.Sum(id, e)=> (print"Sigma "; print(Int.toString(id)); printer2(e))
52 :     |_=>print("newbie")
53 :     (*end case*))
54 :     in
55 :     (print"\n<";printer2(body);print">"; index)
56 :     end
57 :    
58 :     fun printerE(Ein.EIN{params, index, body})=
59 :     let
60 :    
61 :    
62 :     fun printer2 term = (case term
63 :     of E.Tensor(id, mx) => (
64 :     case mx
65 :     of [] => (print " S"; print(Int.toString id))
66 :     | [a] => (print " V"; print(Int.toString id); print "_"; print(Int.toString a))
67 :     | [a,b]=> (print " M";print(Int.toString id); print "_"; List.app printInt mx)
68 :     | _ => (print " T"; print(Int.toString id); print "_"; List.app printInt mx; print "")
69 :     (* end case *))
70 :     | E.Const(f)=> print("zero")
71 :     | E.Field(id, mx) => (print "F";print(Int.toString(id));print("_"); List.app printInt mx )
72 :     | E.Add([b,c])=>(print("(");printer2(b); print("+");printer2(c); print(")"))
73 :     | E.Add([b,c,d])=> (print("(");printer2(b);print("+\n"); printer2(c); print("+\n"); printer2(d); print(")"))
74 :     | E.Add(_)=>(print("Need to add more terms in the Add"))
75 :     | E.Sub(b,c)=>(print"(";printer2(b); print(")\n -( ");printer2(c); print ")")
76 :     | E.Prod([a])=> printer2(a)
77 :     | E.Prod([E.Partial(a), E.Partial(b)]) =>(printer2(E.Partial(a));print(" "); printer2(E.Partial(b)))
78 :     | E.Prod([E.Partial(a), E.Partial(b), c])=> (printer2(E.Partial(a));print(" "); printer2(E.Partial(b)); print(" "); printer2(c))
79 :     | E.Prod(e)=>(print "("; List.map printer2(e); print")")
80 :     | E.Delta(i,j)=> ( printPairs([(i,j)]))
81 :     | E.Epsilon(i,j,k) =>( print " E_";print(Int.toString(i)); print(Int.toString(j));print(Int.toString(k));print" " )
82 :     | E.Conv(i,j,k,l) => (case length(j)
83 :     of 0=>( print i; print " * "; print k; print "_"; print(Int.toString(l)))
84 :     | _=> (print i; print " * "; print k; print "_";print(Int.toString(l));print("^(");printPairs(j);print ")" )
85 :     (* end case *))
86 :     | E.Partial([])=> (print "Error no list here")
87 :     | E.Partial([a])=>(print "d/dx_" ; print(Int.toString(a)))
88 :     | E.Partial(mx)=>(print "d^"; print(Int.toString(length(mx))) ;print "/dx_" ;List.map printInt mx;print(""))
89 :     | E.Probe(a,b)=> ( print "("; printer2(a); print ")"; print("@"); print("T"); print(Int.toString(b)))
90 :     | E.Apply(a, b)=> ( print " "; printer2(a); print " " ; printer2(b) ;print " " )
91 :     | E.Sum (id,a)=> (print " Sigma:"; print(Int.toString(id));printer2 a )
92 :     |_=>print("newbie")
93 :     (*end case *))
94 :    
95 :     fun printIndex ((E.IX(dim))::i, count)=(print("(");
96 :     print(Int.toString(count));
97 :     print(" DIM:");print(Int.toString(dim));print(") ");printIndex(i,count+1))
98 :     |printIndex ((E.SX(dim))::i, count)=
99 :     (print("} {Summation:(");print(Int.toString(count));
100 :     print(" DIM:");print(Int.toString(dim)); print(")");
101 :     printIndex(i,count+1))
102 :     | printIndex(_, count)= print(" ")
103 :     in
104 :     (print"\n<";printer2(body);print">"; print("_{");printIndex(index,0);print("}"); index)
105 :    
106 :     end
107 :    
108 :    
109 :     fun re e2 = (case e2
110 :     of R.App(e, l) => printerE(e)
111 :     )
112 :    
113 :    
114 :     end
115 :     end

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