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 2603 - (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 : cchiw 2499
7 : jhr 2391 structure E = Ein
8 : cchiw 2499
9 : jhr 2391 in
10 : cchiw 2383
11 : cchiw 2499 fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
12 : cchiw 2426
13 : cchiw 2499 fun handleIndex e= (case e
14 :     of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
15 :     | E.V(ix)=> Int.toString(ix)
16 :     )
17 : cchiw 2426
18 : cchiw 2499 fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
19 : cchiw 2426
20 : cchiw 2485
21 : cchiw 2518 fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
22 : cchiw 2499
23 :     fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",Int.toString(lb),"-",Int.toString(ub),"]"]
24 : cchiw 2449
25 : cchiw 2499 fun printbody term = (case term
26 : cchiw 2553 of E.Const r => Int.toString(r)
27 : cchiw 2499 | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
28 :     | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",handleAlpha alpha]
29 :     | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
30 :     | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",handleAlpha alpha]
31 : cchiw 2584 | E.Krn(tid,[],pos) =>String.concat[" H ",Int.toString(tid),"[", (printbody pos),"]"]
32 :     | E.Krn(tid,betas,pos) => String.concat[" H",Int.toString(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
33 : cchiw 2499 | E.Delta(ix) => handleBeta ix
34 :     | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]
35 :     | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
36 : cchiw 2603 | E.Sum (sumindex,e1)=>String.concat[" Σ_",String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
37 : cchiw 2525 | E.Neg e1 => String.concat["-NEG-", printbody e1]
38 : cchiw 2603 | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
39 : cchiw 2499 | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
40 :     | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
41 :     | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]
42 :     | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
43 :     | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
44 :     | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
45 : cchiw 2584 | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",Int.toString(fid),"_{",handleAlpha alpha, "}★h",Int.toString(tid),"|"]
46 :     | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",Int.toString(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",Int.toString(tid),"|"]
47 : cchiw 2587 | E.Probe (e1,e2)=> String.concat ["[",printbody(e1), "","[", printbody(e2),"]]"]
48 : cchiw 2522 | E.Img (fid,alpha,pos)=> String.concat [" V", Int.toString(fid),"_",handleAlpha alpha,"[",
49 :     (String.concatWith "," (List.map printbody pos)),"]"]
50 : cchiw 2496
51 : cchiw 2485
52 :    
53 : cchiw 2436 (* end case *))
54 : cchiw 2449 fun printerE (Ein.EIN{params, index, body}) = let
55 : cchiw 2499 fun Index (dim::i, count) = String.concat["(", Int.toString count,
56 : cchiw 2394 " DIM:", Int.toString dim, ")", Index(i,count+1)]
57 : jhr 2391 | Index (_, count) = ""
58 : cchiw 2525 fun Param(E.TEN(t,shape)::param, i)=let
59 :     val shape'=List.map(fn e1=>Int.toString(e1)) shape
60 :     in String.concat[Int.toString(i), ":TEN", Int.toString t," ", String.concatWith"," shape'," --",Param(param, i+1)]
61 :     end
62 : cchiw 2437 | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]
63 : cchiw 2510 | Param(E.IMG(d)::param, i)= String.concat[Int.toString(i), ":IMG-", Int.toString d," ",Param(param, i+1)]
64 :     | Param(E.KRN::param, i)= String.concat[Int.toString(i), ":KRN ",Param(param, i+1)]
65 : cchiw 2412 | Param(_,_)=""
66 : cchiw 2424
67 : cchiw 2584 val str=String.concat ["\n" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} \n "]
68 : cchiw 2424 in
69 : cchiw 2496 str
70 : cchiw 2424 end
71 : cchiw 2383
72 : cchiw 2395 (* fun printerApp(R.App(e,l))= printerE(e)
73 :     | printerApp(_)= ""*)
74 : cchiw 2394
75 : jhr 2391 end (* local *)
76 :     end

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