Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/ein/printer.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/ein/printer.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2426 - (view) (download)

1 : cchiw 2383
2 : cchiw 2387 (*printer Function returns String*)
3 : cchiw 2383 structure Printer = struct
4 :    
5 :     local
6 : jhr 2391 structure G = GenericEin
7 :     structure E = Ein
8 :     structure S = Specialize
9 : cchiw 2395 (* structure R = Rewrite*)
10 : jhr 2391 in
11 : cchiw 2383
12 : cchiw 2407 fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
13 : cchiw 2426
14 :     fun printIndex e= (case e
15 :     of E.c(cx)=> String.concat["c-",Int.toString(cx)]
16 :     | E.m([ix])=> Int.toString(ix)
17 :     | E.m(mx)=> intList(mx)
18 :     )
19 :     fun imp([])=""
20 :     | imp([(i,j)])= String.concat [" Delta_",printIndex(i),printIndex(j)]
21 :     | imp((i,j)::es)= String.concat[" Delta_",printIndex(i),printIndex(j)," ",imp(es)]
22 :    
23 :    
24 :     fun printerE (Ein.EIN{params, index, body}) = let
25 : jhr 2391 fun printer2 term = (case term
26 : cchiw 2424 of E.Value(id)=> String.concat[" CI-",Int.toString(id)]
27 : cchiw 2426 | E.Tensor(id, E.m([])) =>String.concat[" S",Int.toString(id)]
28 :     | E.Tensor(id, ix) =>String.concat[" T",Int.toString(id),"_",printIndex ix]
29 : cchiw 2424 | E.Pair e => String.concat["(",String.concatWith "," (List.map printer2 e),")"]
30 : cchiw 2394 | E.Const e => Real.toString(e)
31 : cchiw 2426 | E.Field(id, E.m [],E.m []) => String.concat ["F",Int.toString(id)]
32 :     | E.Field(id, mx,dx) => String.concat ["F",Int.toString(id),"_",printIndex(mx),",",printIndex(dx)]
33 : cchiw 2424
34 : cchiw 2409 | E.Add e => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]
35 : cchiw 2424 | E.Sub(a,b) => String.concat ["(",printer2(a),"-",printer2(b), ")"]
36 : cchiw 2394 | E.Div(a,b) => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]
37 : cchiw 2424 | E.Prod [e1,e2,e3] => String.concatWith "*" (List.map printer2 [e1,e2,e3])
38 :     | E.Prod e => String.concatWith "^^" (List.map printer2 e)
39 : cchiw 2426 | E.Delta(dels) => imp(dels)
40 : cchiw 2394 | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]
41 : cchiw 2426 | E.Conv(k,[]) => String.concat ["V (*)",printer2(k)]
42 :     | E.Conv(k,[E.Delta(dels)]) => let
43 :     val n= length(dels)
44 :     in
45 :     String.concat ["V (*)",printer2(k),"^",Int.toString(n),"{",imp(dels),"}"]
46 :     end
47 :     | E.Conv(k,_) => "Incorrect convolution argument"
48 :     | E.Partial(E.c(ix)) => String.concat ["d^1","/dx_",Int.toString(ix)]
49 :     | E.Partial(E.m(mx)) => String.concat ["d^",Int.toString(length(mx)),"/dx_",intList(mx)]
50 : cchiw 2424 | E.Probe(a,b) => String.concat ["",printer2(a), "","@", printer2(b)]
51 : cchiw 2394 | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]
52 : cchiw 2399 | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]
53 : jhr 2391 | _ =>("newbie")
54 : cchiw 2394 (* end case *))
55 :     fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
56 :     " DIM:", Int.toString dim, ")", Index(i,count+1)]
57 : cchiw 2424 | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
58 :     " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]
59 : jhr 2391 | Index (_, count) = ""
60 : cchiw 2412 fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
61 :     | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]
62 :     | Param(_,_)=""
63 : cchiw 2424
64 :     val str=String.concat [Param(params, 0)," \n<",printer2(body),">","\n _{",Index(index,0),"} \n "]
65 :     in
66 :     print str
67 :     end
68 : cchiw 2383
69 : cchiw 2395 (* fun printerApp(R.App(e,l))= printerE(e)
70 :     | printerApp(_)= ""*)
71 : cchiw 2394
72 : jhr 2391 end (* local *)
73 :     end

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