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 2428, Wed Sep 18 18:04:04 2013 UTC revision 2436, Sat Sep 21 15:57:18 2013 UTC
# Line 12  Line 12 
12      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
13    
14      fun printIndex e= (case e      fun printIndex e= (case e
15          of E.C(cx)=> String.concat["c{",intList(cx),"}"]          of E.C(cx)=> Int.toString(cx)
16          |  E.V([ix])=> Int.toString(ix)          |  E.V(ix)=> Int.toString(ix)
         |  E.V(mx)=> intList(mx)  
17      )      )
18      fun imp([])=""  
19      | imp([(i,j)])=  String.concat [" Delta_",printIndex(i),printIndex(j)]      fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]
20      | imp((i,j)::es)= String.concat[" Delta_",printIndex(i),printIndex(j)," ",imp(es)]  
21    
22        fun handleBeta(a,b)=String.concat[printIndex a, ",", printIndex b]
23    
24    
25    
26      fun printerE (Ein.EIN{params, index, body}) = let      fun printerE (Ein.EIN{params, index, body}) = let
27            fun printer2 term = (case term            fun printbody term = (case term
28                   of E.Value(id)=> String.concat[" CI-",Int.toString(id)]              of E.Const r => Real.toString(r)
29                    | E.Tensor(id, E.V([])) =>String.concat[" S",Int.toString(id)]              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
30                    | E.Tensor(id, ix) =>String.concat[" T",Int.toString(id),"_",printIndex ix]              | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]
31                    | E.Pair e => String.concat["(",String.concatWith "," (List.map printer2 e),")"]              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
32                    | E.Const e => Real.toString(e)              | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]
33                    | E.Field(id, E.V [],E.V []) => String.concat ["F",Int.toString(id)]              | E.Kernel([]) =>String.concat["h"]
34                    | E.Field(id, mx,dx) => String.concat ["F",Int.toString(id),"_",printIndex(mx),",",printIndex(dx)]              | E.Kernel(betas) =>String.concat["h^",String.concat(List.map handleBeta betas)]
35                | E.Delta(ix) => String.concat["Delta_", handleBeta ix]
36                    | E.Add e        => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]              | E.Value(ix)=> String.concat["c-",Int.toString(ix)]
37                    | E.Sub(a,b)      => String.concat ["(",printer2(a),"- ",printer2(b), ")"]              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
38                    | E.Div(a,b)      => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]              | E.Sum (count,e1)=> String.concat["Sigma:", Int.toString(count), printbody e1]
39                    | E.Prod e       => String.concatWith "*" (List.map printer2 e)              | E.Neg e1 => String.concat["-", printbody e1]
40                    | E.Kernel [] =>  "h"              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
41                    | E.Kernel dels=> String.concat["h^",imp(dels)]              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
42                    | E.Delta dels  => imp(dels)              | E.Prod el => String.concatWith "*" (List.map printbody el)
43                    | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
44                    | E.Conv(k,[]) => String.concat ["V (*)",printer2(k)]              | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]
45                    | E.Conv(k,[E.V(mx)]) =>let              | E.Apply(e1, e2)=> String.concat [ printbody(e1)," ", printbody(e2)," "]
46                          val n= length(mx)              | E.Conv(e1, [])=> String.concat[printbody(e1), "(*)h"]
47                          val ind= intList(mx)              | E.Conv(e1, alpha)=> String.concat[printbody(e1), "(*)h^",printAlpha alpha]
48                | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","@", printbody(e2)]
49                | E.Image(e1::es)=> let
50                        val position=  String.concatWith "," (List.map printbody es)
51                          in                          in
52                              String.concat ["V (*)",printer2(k),"^",Int.toString(n),"{",ind,"}"]                      String.concat ["",printbody(e1),"[", position,"]"]
53                          end                          end
                   | E.Conv(k,_) => "Incorrect convolution argument"  
                   | E.Partial(E.C(ix)) => String.concat ["d^1","/dx_",intList(ix)]  
                   | E.Partial(E.V(mx))  => String.concat ["d^",Int.toString(length(mx)),"/dx_",intList(mx)]  
                   | E.Probe(a,b) => String.concat ["",printer2(a), "","@", printer2(b)]  
                   | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]  
                   | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]  
                   | _ =>("newbie")  
54                  (* end case *))                  (* end case *))
55    
56            fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,            fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
57                  " DIM:", Int.toString dim, ")", Index(i,count+1)]                  " DIM:", Int.toString dim, ")", Index(i,count+1)]
58              | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),              | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
# Line 63  Line 62 
62              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]
63              | Param(_,_)=""              | Param(_,_)=""
64    
65          val str=String.concat [Param(params, 0)," \n<",printer2(body),">","\n _{",Index(index,0),"} \n \n \n "]          val str=String.concat [Param(params, 0)," \n<",printbody(body),">","\n _{",Index(index,0),"} \n \n \n "]
66          in          in
67              print str; str              print str; str
68          end          end

Legend:
Removed from v.2428  
changed lines
  Added in v.2436

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