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

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

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