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 2407, Wed Jul 31 04:52:25 2013 UTC branches/charisee_dev/src/compiler/ein/printer.sml revision 3271, Fri Oct 9 18:12:58 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
5        structure G = GenericEin  
6        structure E = Ein        structure E = Ein
7        structure S = Specialize  
      (* structure R = Rewrite*)  
8      in      in
9    
10      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]      fun iTos e=Int.toString e
11        fun intList l = String.concatWith "," (List.map iTos l)
12        fun handleIndex e= (case e
13            of E.C(cx)=> String.concat["'",iTos(cx),"'"]
14            |  E.V(ix)=> iTos(ix)
15        (*end case*))
16        fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
17        fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
18        fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
19    
20        (*printbody:ein_exp ->string*)
21     fun printbody term = (case term
22     of E.Const r => iTos(r)
23     | E.ConstR r =>RationalEin.toString r
24     | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
25     | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
26     | E.Field(id, []) =>String.concat[" F",iTos(id)]
27     | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
28     | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
29     | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas)(*,"} [",(printbody pos),"]"*)]
30     | E.Delta(ix) =>  handleBeta ix
31     | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
32     | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
33     | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
34     | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐","⋑",handleIndex v]
35     | E.Sum (sumindex,e1)=>String.concat[" Σ_",(* String.concatWith ","(List.map handleSumRange sumindex),*)"⋐" ,"⋑"]
36     | E.Neg e1 => String.concat["-NEG-"]
37     | E.Lift e1 => String.concat["LIFT ⊢","⊣"]
38     | E.Add el => String.concat["(+",")"]
39     | E.Sub(e1, e2) => String.concat ["---- "]
40     | E.Prod el => String.concat["(","*)"]
41     | E.Div(e1,e2) => String.concat ["(",")/( ",")"]
42     | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
43     | E.Apply(e1, e2)=> String.concat [ "@{","} "]
44     | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
45     | E.Conv(fid,alpha, tid, [b0,b1])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h2(",iTos(tid),")dx_",handleAlpha [b0,b1],"}|"]
46     | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
47     | E.Probe (e1,e2)=> String.concat ["[", "","@[","]]"]
48     | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"["(*,
49     (String.concatWith "," (List.map printbody pos)),"]"*)]
50     | E.Sqrt e => String.concat[ "√(",")"]
51     | E.PowInt(e,n1) => String.concat[  "(",")^",iTos n1]
52     | E.PowReal(e,n1) => String.concat[ "(", ")^",RationalEin.toString n1]
53     | E.Cosine e=>  String.concat["Cosine(",")"]
54     | E.ArcCosine e=> String.concat["ArcCosine(",")"]
55     | E.Sine e => String.concat["Sine(" ,")"]
56     | E.ArcSine e =>String.concat["ArcSine(" ,")"]
57     (* end case *))
58    
59      fun printerE (Ein.EIN{params, index, body}) = let   (*
60            fun printer2 term = (case term      fun printbody term = (case term
61                   of E.Tensor(id, [])  => String.concat[" S",Int.toString(id)]          of E.Const r => iTos(r)
62                    | E.Tensor(id, mx) =>  String.concat[" T",Int.toString(id),intList(mx)]          | E.ConstR r =>RationalEin.toString r
63                    | E.Const e => Real.toString(e)          | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
64                    | E.Field(id, []) => String.concat ["F",Int.toString(id)]          | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
65                    | E.Field(id, mx) => String.concat ["F",Int.toString(id),"_",intList(mx)]          | E.Field(id, []) =>String.concat[" F",iTos(id)]
66                    | E.Add e        => String.concatWith "+" (List.map printer2 e)          | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
67                    | E.Sub(a,b)      => String.concat ["(",printer2(a),"- ",printer2(b), ")"]          | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
68                    | E.Div(a,b)      => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]          | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas)(*,"} [",(printbody pos),"]"*)]
69                    | E.Prod e       => String.concatWith "*" (List.map printer2 e)          | E.Delta(ix) =>  handleBeta ix
70                    | E.Delta(i,j)    => String.concat [" Delta_",Int.toString(i),Int.toString(j)]          | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
71                    | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]          | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
72                    | E.Conv(v,deltas,k,n) => let          | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
73                        fun imp([])=""          | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
74                        | imp([(i,j)])=  String.concat [" Delta_",Int.toString(i),Int.toString(j)]          | E.Sum (sumindex,e1)=>String.concat[" Σ_",(* String.concatWith ","(List.map handleSumRange sumindex),*)"⋐" ,printbody e1,"⋑"]
75                        | imp((i,j)::es)= String.concat[" Delta_",Int.toString(i),Int.toString(j)," ",imp(es)]          | E.Neg e1 => String.concat["-NEG-", printbody e1]
76                        in          | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
77                          String.concat [v,"*",k,"{",imp(deltas),"}_",Int.toString(n)]          | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
78                        end          | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
79                    | E.Partial e  => String.concat ["d^",Int.toString(length(e)),"/dx_",intList(e)]          | E.Prod el => String.concat["(",String.concatWith "* " (List.map printbody el),")"]
80                    | E.Probe(a,b) => String.concat ["(",printer2(a), ")","@","T",Int.toString(b)]          | E.Div(e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
81                    | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]          | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
82                    | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]          | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
83                    | _ =>("newbie")          | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
84                    | E.Conv(fid,alpha, tid, [b0,b1])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h2(",iTos(tid),")dx_",handleAlpha [b0,b1],"}|"]
85            | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
86            | E.Probe (e1,e2)=> String.concat ["[",printbody(e1), "","[", printbody(e2),"]]"]
87            | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"["(*,
88                    (String.concatWith "," (List.map printbody pos)),"]"*)]
89            | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
90            | E.PowInt(e,n1) => String.concat[  "(",printbody e ,")^",iTos n1]
91            | E.PowReal(e,n1) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
92            | E.Cosine e=>  String.concat["Cosine(",printbody e ,")"]
93            | E.ArcCosine e=> String.concat["ArcCosine(",printbody e ,")"]
94            | E.Sine e => String.concat["Sine(",printbody e ,")"]
95            | E.ArcSine e => String.concat["ArcSine(",printbody e ,")"]
96                  (* end case *))                  (* end case *))
97            fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,  *)
98                  " DIM:", Int.toString dim, ")", Index(i,count+1)]      (*printerE:EIN ->string*)
99              | Index ((E.SX(dim))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),      fun printerE (Ein.EIN{params, index, body}) = let
100                  " DIM:",Int.toString(dim),")", Index(i,count+1)]          fun Index (dim::i, count) = String.concat["(", iTos count,
101                    " DIM:", iTos dim, ")", Index(i,count+1)]
102              | Index (_, count) = ""              | Index (_, count) = ""
103            fun Param(E.TEN(t,shape)::param, i)=
104                    String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
105                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
106                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
107                            (intList shape),  ">, ",Param(param, i+1)]
108                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
109                | Param(_,_)=""
110    
111              in              in
112                  String.concat ["\n<",printer2(body),">","_{",Index(index,0),"}"]             (* String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]*)
113                    printbody body
114              end              end
115    
        (* fun printerApp(R.App(e,l))= printerE(e)  
             | printerApp(_)= ""*)  
   
116      end (* local *)      end (* local *)
117    end    end

Legend:
Removed from v.2407  
changed lines
  Added in v.3271

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