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 2437, Mon Sep 23 22:28:42 2013 UTC branches/charisee_dev/src/compiler/ein/printer.sml revision 3440, Mon Nov 16 19:16:54 2015 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
       structure G = GenericEin  
       structure E = Ein  
       structure S = Specialize  
      (* structure R = Rewrite*)  
     in  
   
     fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]  
   
     fun printIndex e= (case e  
         of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]  
         |  E.V(ix)=> Int.toString(ix)  
     )  
   
     fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]  
5    
6          structure E = Ein
7    
8      fun handleBeta(a,b)=String.concat["Delta_(",printIndex a, ",", printIndex b,")"]      in
9    
10      fun printerE (Ein.EIN{params, index, body}) = let      fun iTos e=Int.toString e
11            fun printbody term = (case term      fun intList l = String.concatWith "," (List.map iTos l)
12              of E.Const r => Real.toString(r)      fun handleIndex e= (case e
13              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]          of E.C(cx)=> String.concat["'",iTos(cx),"'"]
14              | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]          |  E.V(ix)=> iTos(ix)
15              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]      (*end case*))
16              | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]      fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
17              | E.Kernel([]) =>String.concat["h"]      fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
18              | E.Kernel(betas) =>String.concat["h^{",String.concat(List.map handleBeta betas),"}"]      fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
19        fun printbody b= (case b
20            of E.Const r => iTos(r)
21            | E.ConstR r =>RationalEin.toString r
22            | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
23            | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
24            | E.Field(id, []) =>String.concat[" F",iTos(id)]
25            | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
26            | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
27            | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
28              | E.Delta(ix) =>  handleBeta ix              | E.Delta(ix) =>  handleBeta ix
29              | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]          | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
30              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]          | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
31              | E.Sum (count,e1)=> String.concat["Sigma:", Int.toString(count)," ", printbody e1]          | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
32              | E.Neg e1 => String.concat["-", printbody e1]          | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
33            | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
34            | E.Neg e1 => String.concat["-NEG-", printbody e1]
35            | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
36              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
37              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]          | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
38              | E.Prod el => String.concatWith "* " (List.map printbody el)          | E.Prod el => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]
39              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]          | E.Div(e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
40              | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]          | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
41              | E.Apply(e1, e2)=> String.concat [ printbody(e1)," ", printbody(e2)," "]          | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
42              | E.Conv(e1, [])=> String.concat[printbody(e1), "(*)h"]          | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
43              | E.Conv(e1, alpha)=> String.concat[printbody(e1), "(*) d/dx_{",printAlpha alpha,"}h"]          | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
44              | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","@", printbody(e2)]          | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
45              | E.Image(e1::es)=> let          | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[",
46                      val position=  String.concatWith "," (List.map printbody es)              (String.concatWith "," (List.map printbody pos)),"]"]
47                  in          | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
48                      String.concat [printbody(e1),"[", position,"]"]          | E.PowInt(e,n1) => String.concat[  "(",printbody e ,")^",Int.toString n1]
49                  end          | E.PowReal(e,n1) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
50            | E.PowEmb (e,sx,n)=>String.concat["POW(",printbody e,"^", iTos n,")"]
51            | E.Trig(t,e)=>(case t
52                of  E.Cosine =>  String.concat["Cosine(",printbody e ,")"]
53                | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
54                | E.Sine  => String.concat["Sine(",printbody e ,")"]
55                | E.ArcSine  => String.concat["ArcSine(",printbody e ,")"]
56                | E.Tangent  => String.concat["Tangent(",printbody e ,")"]
57                | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
58                (*end case*))
59            | E.Exp e1=> String.concat["E^(",printbody e1,")"]
60              (* end case *))              (* end case *))
61    
62          fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,      (*printerE:EIN ->string*)
63                  " DIM:", Int.toString dim, ")", Index(i,count+1)]      fun printerE (Ein.EIN{params, index, body}) = let
64              | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),          fun Index (dim::i, count) = String.concat["(", iTos count,
65                  " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]                  " DIM:", iTos dim, ")", Index(i,count+1)]
66              | Index (_, count) = ""              | Index (_, count) = ""
67          fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]          fun Param(E.TEN(t,shape)::param, i)=
68              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]                  String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
69                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
70                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
71                            (intList shape),  ">, ",Param(param, i+1)]
72                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
73              | Param(_,_)=""              | Param(_,_)=""
74    
         val str=String.concat ["\n\t" ,Param(params, 0)," \n \t <",printbody(body),">","\n \t _{",Index(index,0),"} \n "]  
75          in          in
76              print str; str             String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
         end  
77    
78         (* fun printerApp(R.App(e,l))= printerE(e)          end
             | printerApp(_)= ""*)  
79    
80      end (* local *)      end (* local *)
81    end    end

Legend:
Removed from v.2437  
changed lines
  Added in v.3440

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