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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2436 - (view) (download)
Original Path: branches/charisee/src/compiler/ein/printer.sml

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 : cchiw 2436 of E.C(cx)=> Int.toString(cx)
16 :     | E.V(ix)=> Int.toString(ix)
17 : cchiw 2426 )
18 :    
19 : cchiw 2436 fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]
20 : cchiw 2426
21 : cchiw 2436
22 :     fun handleBeta(a,b)=String.concat[printIndex a, ",", printIndex b]
23 :    
24 :    
25 :    
26 : cchiw 2426 fun printerE (Ein.EIN{params, index, body}) = let
27 : cchiw 2436 fun printbody term = (case term
28 :     of E.Const r => Real.toString(r)
29 :     | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
30 :     | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]
31 :     | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
32 :     | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]
33 :     | E.Kernel([]) =>String.concat["h"]
34 :     | E.Kernel(betas) =>String.concat["h^",String.concat(List.map handleBeta betas)]
35 :     | E.Delta(ix) => String.concat["Delta_", handleBeta ix]
36 :     | E.Value(ix)=> String.concat["c-",Int.toString(ix)]
37 :     | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
38 :     | E.Sum (count,e1)=> String.concat["Sigma:", Int.toString(count), printbody e1]
39 :     | E.Neg e1 => String.concat["-", printbody e1]
40 :     | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
41 :     | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
42 :     | E.Prod el => String.concatWith "*" (List.map printbody el)
43 :     | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
44 :     | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]
45 :     | E.Apply(e1, e2)=> String.concat [ printbody(e1)," ", printbody(e2)," "]
46 :     | E.Conv(e1, [])=> String.concat[printbody(e1), "(*)h"]
47 :     | 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
52 :     String.concat ["",printbody(e1),"[", position,"]"]
53 :     end
54 :     (* end case *))
55 : cchiw 2424
56 : cchiw 2436 fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
57 : cchiw 2394 " DIM:", Int.toString dim, ")", Index(i,count+1)]
58 : cchiw 2424 | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
59 :     " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]
60 : jhr 2391 | Index (_, count) = ""
61 : cchiw 2412 fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
62 :     | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]
63 :     | Param(_,_)=""
64 : cchiw 2424
65 : cchiw 2436 val str=String.concat [Param(params, 0)," \n<",printbody(body),">","\n _{",Index(index,0),"} \n \n \n "]
66 : cchiw 2424 in
67 : cchiw 2427 print str; str
68 : cchiw 2424 end
69 : cchiw 2383
70 : cchiw 2395 (* fun printerApp(R.App(e,l))= printerE(e)
71 :     | printerApp(_)= ""*)
72 : cchiw 2394
73 : jhr 2391 end (* local *)
74 :     end

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