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 2449, Thu Oct 3 20:15:16 2013 UTC
# Line 6  Line 6 
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 intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
13    
14      fun intList([])=""      fun printIndex e= (case e
15          |intList(e::es)= Int.toString(e)^ intList(es)          of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
16            |  E.V(ix)=> Int.toString(ix)
17        )
18    
19          fun printerE(Ein.EIN{params, index, body})= let      fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]
20          fun printer2 term = (case term  
21              of E.Tensor(id, mx) => (  
22                  case mx      fun handleBeta(a,b)=String.concat["Delta_(",printIndex a, ",", printIndex b,")"]
23                  of [] => ( " S"^Int.toString(id))  
24                  | [a] => ( " V"^Int.toString(id)^ "_"^Int.toString(a))  
25                  | [a,b]=> ("M"^Int.toString(id)^ "_"^ intList(mx))            fun printbody term = (case term
26                  | _ =>  ("T"^Int.toString(id)^ "_"^intList(mx))              of E.Const r => Real.toString(r)
27                  (* end case *))              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
28              | E.Const(f)=> ("zero")              | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]
29              | E.Field(id, mx) => ( "F"^Int.toString(id)^"_"^intList(mx))              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
30              | E.Add(e)=> let              | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]
31                  fun imp([])=""              | E.Kernel([]) =>String.concat["h"]
32                  | imp([a])=printer2(a)              | E.Kernel(betas) =>String.concat["h^{",String.concat(List.map handleBeta betas),"}"]
33                  | imp(a::es)=(printer2(a)^"+"^imp(es))              | E.Delta(ix) =>  handleBeta ix
34                  in ("("^imp(e)^")") end              | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]
35              | E.Sub(b,c)=>("("^printer2(b)^"- "^printer2(c)^ ")")              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
36                | E.Sum (alpha,e1)=> String.concat["Sigma:", printAlpha alpha," (", printbody e1,")"]
37              | E.Prod(e)=>let              | E.Neg e1 => String.concat["-", printbody e1]
38                  fun imp([])=""              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
39                  | imp([a])=printer2(a)              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
40                  | imp(a::es)=printer2(a)^" "^imp(es)              | E.Prod el => String.concatWith "* " (List.map printbody el)
41                  in "("^imp(e)^")" end              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
42              | E.Delta(i,j)=> (" Delta_"^Int.toString(i)^Int.toString(j))              | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]
43              | E.Epsilon(i,j,k) =>(" E_"^Int.toString(i)^Int.toString(j)^Int.toString(k) )              | E.Apply(e1, e2)=> String.concat [ printbody(e1)," ", printbody(e2)," "]
44              | E.Conv(i,j,k,l) => let              | E.Conv(e1, [])=> String.concat[printbody(e1), "(*)h"]
45                  fun imp([])=""              | E.Conv(e1, alpha)=> String.concat[printbody(e1), "(*) d/dx_{",printAlpha alpha,"}h"]
46                  | imp([(a,b)])=(" Delta_"^Int.toString(a)^Int.toString(b))              | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","@", printbody(e2)]
47                  | imp((a,b)::es)=(" Delta_"^Int.toString(a)^Int.toString(b))^" "^imp(es)              | E.Image(e1::es)=> let
48                  in i^"*"^k^"^{"^imp(j)^"}_"^Int.toString(l) end                      val position=  String.concatWith "," (List.map printbody es)
             | 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)= ("")  
49              in              in
50                  ("\n<"^printer2(body)^">"^"_{"^Index(index,0)^"}")                      String.concat [printbody(e1),"[", position,"]"]
51              end              end
52                (* 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            val str=String.concat ["\n\t" ,Param(params, 0)," \n \t <",printbody(body),">","\n \t _{",Index(index,0),"} \n "]
64            in
65                print str; str
66            end
67    
68          fun printerApp(R.App(e,l)) =let         (* fun printerApp(R.App(e,l))= printerE(e)
69              fun argList([])=""              | printerApp(_)= ""*)
               | argList([e])=e  
               |argList(e::es)= e^","^argList(es)  
             in printerE(e)^"["^argList(l)^"]" end  
         |printerApp(_)=""  
   
70    
71  end      end (* local *)
72  end  end

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

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