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 2388, Sun Jun 16 17:02:02 2013 UTC revision 2518, Tue Dec 17 00:04:37 2013 UTC
# Line 3  Line 3 
3  structure Printer = struct  structure Printer = struct
4    
5      local      local
6      structure G = GenericEin  
7      structure E = Ein      structure E = Ein
     structure S = Specialize  
     structure R = Rewrite  
8    
9          in          in
10    
11    fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
12    
13      fun intList([])=""  fun handleIndex e= (case e
14          |intList(e::es)= Int.toString(e)^ intList(es)      of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
15        |  E.V(ix)=> Int.toString(ix)
16    )
17    
18    fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
19    
20    
21    fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
22    
23    fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",Int.toString(lb),"-",Int.toString(ub),"]"]
24    
25    fun printbody term = (case term
26        of E.Const r => Real.toString(r)
27        | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
28        | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",handleAlpha alpha]
29        | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
30        | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",handleAlpha alpha]
31        | E.Krn(tid,[],pos) =>String.concat[" h ",Int.toString(tid),"[",  (printbody pos),"]"]
32        | E.Krn(tid,betas,pos) => String.concat[" h",Int.toString(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
33        | E.Delta(ix) =>  handleBeta ix
34        | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]
35        | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
36        | E.Sum (sumindex,e1)=>String.concat["\n Σ_",String.concatWith ","(List.map handleSumRange sumindex)," (", printbody e1,")"]
37        | E.Neg e1 => String.concat["-", printbody e1]
38        | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
39        | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
40        | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]
41        | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
42        | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
43        | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
44        | E.Conv(fid,alpha, tid ,[])=> String.concat["|V",Int.toString(fid),"_{",handleAlpha alpha, "}★h",Int.toString(tid),"|"]
45        | E.Conv(fid,alpha, tid, beta)=> String.concat["|V",Int.toString(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",Int.toString(tid),"|"]
46        | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","[", printbody(e2),"]"]
47        | E.Img (fid,alpha,pos)=> String.concat ["\n V", Int.toString(fid),"_",handleAlpha alpha,"[",
48                    (String.concatWith "," (List.map printbody pos)),"]\n"]
49    
50    
51    
         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))  
52                  (* end case *))                  (* end case *))
53              | E.Const(f)=> ("zero")          fun printerE (Ein.EIN{params, index, body}) = let
54              | E.Field(id, mx) => ( "F"^Int.toString(id)^"_"^intList(mx))          fun Index (dim::i, count) = String.concat["(", Int.toString count,
55              | E.Add(e)=> let                  " DIM:", Int.toString dim, ")", Index(i,count+1)]
56                  fun imp([])=""              | Index (_, count) = ""
57                  | imp([a])=printer2(a)          fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
58                  | imp(a::es)=(printer2(a)^"+"^imp(es))              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]
59                  in ("("^imp(e)^")") end                 | Param(E.IMG(d)::param, i)= String.concat[Int.toString(i), ":IMG-", Int.toString d," ",Param(param, i+1)]
60              | E.Sub(b,c)=>("("^printer2(b)^"- "^printer2(c)^ ")")                 | Param(E.KRN::param, i)= String.concat[Int.toString(i), ":KRN ",Param(param, i+1)]
61                | Param(_,_)=""
62              | E.Prod(e)=>let  
63                  fun imp([])=""          val str=String.concat ["" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"}  "]
                 | 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)=("("^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)= ("")  
64              in              in
65                  ("\n<"^printer2(body)^">"^"_{"^Index(index,0)^"}")              str
66              end              end
67    
68           (* fun printerApp(R.App(e,l))= printerE(e)
69                | printerApp(_)= ""*)
70    
71          fun printerApp(R.App(e,l)) =let      end (* local *)
             fun argList([])=""  
               | argList([e])=e  
               |argList(e::es)= e^","^argList(es)  
             in printerE(e)^"["^argList(l)^"]" end  
         |printerApp(_)=""  
   
   
 end  
72  end  end

Legend:
Removed from v.2388  
changed lines
  Added in v.2518

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