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

branches/charisee/src/compiler/ein/printer.sml revision 2391, Sun Jun 16 19:14:08 2013 UTC branches/charisee_dev/src/compiler/ein/printer.sml revision 3557, Fri Jan 8 19:54:58 2016 UTC
# Line 1  Line 1 
   
1  (*printer Function returns String*)  (*printer Function returns String*)
2  structure Printer = struct  structure Printer = struct
3    
4      local      local
5        structure G = GenericEin  
6        structure E = Ein        structure E = Ein
       structure S = Specialize  
       structure R = Rewrite  
     in  
7    
8      fun intList l = String.concatWith "," (List.map Int.toString l)      in
9    
10      fun printerE (Ein.EIN{params, index, body}) = let      fun iTos e=Int.toString e
11            fun printer2 term = (case term      fun intList l = String.concatWith "," (List.map iTos l)
12                   of E.Tensor(id, mx) => (      fun handleIndex e= (case e
13                       case mx          of E.C(cx,true)=> String.concat["C(",iTos(cx),")"]
14                       of [] => ( " S"^Int.toString(id))          | E.C(cx,false)=> String.concat["S(",iTos(cx),")"]
15                       | [a] => ( " V"^Int.toString(id)^ "_"^Int.toString(a))          | E.V(ix)=> iTos(ix)
                      | [a,b]=> ("M"^Int.toString(id)^ "_"^ intList(mx))  
                      | _ =>  ("T"^Int.toString(id)^ "_"^intList(mx))  
16                       (* end case *))                       (* end case *))
17                    | E.Const(f)=> ("zero")      fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
18                    | E.Field(id, mx) => ( "F"^Int.toString(id)^"_"^intList(mx))      fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
19                    | E.Add(e)=> let      fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
20                        fun imp([])=""      fun printbody b= let
21                        | imp([a])=printer2(a)            val _ ="\nstart printer"
22                        | imp(a::es)=(printer2(a)^"+"^imp(es))   (*
23                        in ("("^imp(e)^")") end          val str=(case b
24                    | E.Sub(b,c)=>("("^printer2(b)^"- "^printer2(c)^ ")")          of E.B(E.Const r) => iTos(r)
25            | E.B(E.ConstR r) =>RationalEin.toString r
26                    | E.Prod(e)=>let          | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
27                        fun imp [] = ""          | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
28                          | imp [a] = printer2(a)          | E.G(E.Delta(ix)) =>  handleBeta ix
29                          | imp (a::es) = printer2(a) ^ " "^ imp(es)          | E.G(E.Epsilon(ix, jx, kx)) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
30                        in "("^imp(e)^")" end          | E.G(E.Eps2(ix, jx)) => String.concat["ϵ_",iTos(ix), iTos(jx)]
31                    | E.Delta(i,j)=> (" Delta_"^Int.toString(i)^Int.toString(j))  
32                    | E.Epsilon(i,j,k) =>(" E_"^Int.toString(i)^Int.toString(j)^Int.toString(k) )          | E.Field(id, []) =>String.concat[" F",iTos(id)]
33                    | E.Conv(i,j,k,l) => let          | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
34                        fun imp([])=""          | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
35                        | imp([(a,b)])=(" Delta_"^Int.toString(a)^Int.toString(b))  
36                        | imp((a,b)::es)=(" Delta_"^Int.toString(a)^Int.toString(b))^" "^imp(es)          | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
37                        in i^"*"^k^"^{"^imp(j)^"}_"^Int.toString(l) end          | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
38                    | E.Partial(e)=> ("d"^ Int.toString(length(e))^"/dx_"^intList(e))   (*
39                    | E.Probe(a,b)=> ( "("^printer2(a)^ ")"^"@"^"T"^Int.toString(b))          | E.Conv _ => "F"
40                    | E.Apply(a, b)=> (printer2(a)^ " " ^printer2(b) ^ " " )   *)
41                    | E.Sum (id,a)=> ( " Sigma:"^Int.toString(id)^ printer2(a) )          | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
42                    | _ =>("newbie")          | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
43     (*
44            | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
45     *)
46            | E.Probe (e1,e2)=> String.concat ["Probe(",printbody(e1),",",printbody(e2),")"]
47            | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
48            | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[", (String.concatWith "," (List.map printbody pos)),"]"]
49            | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
50            | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
51            | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
52            | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
53     (*
54             | E.Sum (sumindex,e1)=>String.concat[" Σ",printbody e1,"⋑"]
55     *)
56            | E.Op1(E.Neg, e1) => String.concat["-NEG-", printbody e1]
57            | E.Op1(E.Sqrt ,e )=> String.concat[ "√(", printbody e ,")"]
58            | E.Op1(E.PowInt n1,e) => String.concat[  "(",printbody e ,")^",Int.toString n1]
59            | E.Op1(E.PowReal n1,e) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
60            | E.Op1(E.PowEmb (sx,n),e)=>String.concat["POW(",printbody e,"^", iTos n,")"]
61            | E.Op1(E.Exp, e1)=> String.concat["E^(",printbody e1,")"]
62            | E.Op1(t,e)=>(case t
63                of  E.Cosine =>  String.concat["Cosine(",printbody e ,")"]
64                | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
65                | E.Sine  => String.concat["Sine(",printbody e ,")"]
66                | E.ArcSine  => String.concat["ArcSine(",printbody e ,")"]
67                | E.Tangent  => String.concat["Tangent(",printbody e ,")"]
68                | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
69                  (* end case *))                  (* end case *))
70            fun Index ((E.IX(dim))::i, count) = String.concat[          | E.Op2(E.Sub,e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
71                    "(", Int.toString count, " DIM:", Int.toString dim, ")",          | E.Op2(E.Div,e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
72                    Index(i,count+1)   (*
73                  ]          | E.Opn(E.Add, el) => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
74              | Index ((E.SX(dim))::i, count)=("} {Summation:("^Int.toString(count) ^          | E.Opn(E.Prod, el) => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]*)
75                  " DIM:"^Int.toString(dim)^")"^ Index(i,count+1))          | E.Opn(E.Add, el) => String.concat["Add(",String.concatWith "+" (List.map printbody el),")"]
76              | Index (_, count) = ""          | E.Opn(E.Prod, el) => String.concat["Prod<",String.concatWith "* " (List.map printbody el),">"]
77              in          | E.Holder n1=> String.concat["Holder(",Int.toString(n1),")"]
78                  ("\n<"^printer2(body)^">"^"_{"^Index(index,0)^"}")          | E.EvalKrn  del=>String.concat["Krn1pos ",iTos(del)]
79              end          | E.BuildPos(e1,e2)=>String.concat["Buildpos ",printbody e2]
80            (* end case *))
81            val _ ="\nrtn printer"
82            *)
83            val str=""
84            in str end
85    
86        (*printerE:EIN ->string*)
87        fun printerE (Ein.EIN{params, index, body}) = let
88            fun Index (dim::i, count) = String.concat["(", iTos count,
89                    " DIM:", iTos dim, ")", Index(i,count+1)]
90                | Index (_, count) = ""
91            fun Param(E.TEN(t,shape)::param, i)=
92                    String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
93                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
94                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
95                            (intList shape),  ">, ",Param(param, i+1)]
96                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
97                | Param(_,_)=""
98    
99          fun printerApp(R.App(e,l)) =let          in
100              fun argList([])=""             String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
               | argList([e])=e  
               |argList(e::es)= e^","^argList(es)  
             in printerE(e)^"["^argList(l)^"]" end  
         |printerApp(_)=""  
101    
102            end
103    
104      end (* local *)      end (* local *)
105    end    end

Legend:
Removed from v.2391  
changed lines
  Added in v.3557

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