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

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