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 3325 - (view) (download)

1 : cchiw 2387 (*printer Function returns String*)
2 : cchiw 2383 structure Printer = struct
3 :    
4 :     local
5 : cchiw 2499
6 : jhr 2391 structure E = Ein
7 : cchiw 2499
8 : jhr 2391 in
9 : cchiw 2383
10 : cchiw 2844 fun iTos e=Int.toString e
11 :     fun intList l = String.concatWith "," (List.map iTos l)
12 : cchiw 2605 fun handleIndex e= (case e
13 : cchiw 2844 of E.C(cx)=> String.concat["'",iTos(cx),"'"]
14 :     | E.V(ix)=> iTos(ix)
15 :     (*end case*))
16 : cchiw 2605 fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
17 :     fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
18 : cchiw 2844 fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
19 :    
20 : cchiw 3276
21 : cchiw 2605 fun printbody term = (case term
22 : cchiw 2844 of E.Const r => iTos(r)
23 : cchiw 2870 | E.ConstR r =>RationalEin.toString r
24 : cchiw 2844 | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
25 :     | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
26 :     | E.Field(id, []) =>String.concat[" F",iTos(id)]
27 :     | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
28 : cchiw 3276 | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid)(*,"[", (printbody pos),"]"*)]
29 : cchiw 3260 | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas)(*,"} [",(printbody pos),"]"*)]
30 : cchiw 2605 | E.Delta(ix) => handleBeta ix
31 : cchiw 2844 | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
32 :     | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
33 :     | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
34 : cchiw 3017 | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
35 : cchiw 3324 | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
36 : cchiw 2605 | E.Neg e1 => String.concat["-NEG-", printbody e1]
37 :     | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
38 :     | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
39 : cchiw 2870 | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
40 : cchiw 3324 | E.Prod el => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]
41 : cchiw 2870 | E.Div(e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
42 : cchiw 2605 | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
43 :     | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
44 : cchiw 3325
45 : cchiw 3174 | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
46 : cchiw 3189 | E.Conv(fid,alpha, tid, [b0,b1])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h2(",iTos(tid),")dx_",handleAlpha [b0,b1],"}|"]
47 : cchiw 3174 | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
48 : cchiw 3325 (*
49 : cchiw 3276 | E.Conv(fid,alpha, tid,[])=> String.concat["F_",handleAlpha alpha]
50 :     | E.Conv(fid,alpha, tid, beta)=> String.concat["F_",handleAlpha alpha,"∇",handleAlpha beta]
51 : cchiw 3325 *)
52 : cchiw 3276 | E.Probe (e1,e2)=> String.concat [printbody(e1)(*,"[", printbody(e2),"]"*)]
53 : cchiw 3260 | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"["(*,
54 :     (String.concatWith "," (List.map printbody pos)),"]"*)]
55 : cchiw 3138 | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
56 : cchiw 2870 | E.PowInt(e,n1) => String.concat[ "(",printbody e ,")^",iTos n1]
57 :     | E.PowReal(e,n1) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
58 : cchiw 3138 | E.Cosine e=> String.concat["Cosine(",printbody e ,")"]
59 :     | E.ArcCosine e=> String.concat["ArcCosine(",printbody e ,")"]
60 :     | E.Sine e => String.concat["Sine(",printbody e ,")"]
61 :     | E.ArcSine e => String.concat["ArcSine(",printbody e ,")"]
62 : cchiw 2845 (* end case *))
63 : cchiw 3276
64 : cchiw 2844 (*printerE:EIN ->string*)
65 : cchiw 2605 fun printerE (Ein.EIN{params, index, body}) = let
66 : cchiw 2844 fun Index (dim::i, count) = String.concat["(", iTos count,
67 :     " DIM:", iTos dim, ")", Index(i,count+1)]
68 : jhr 2391 | Index (_, count) = ""
69 : cchiw 2844 fun Param(E.TEN(t,shape)::param, i)=
70 : cchiw 2845 String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
71 :     | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
72 :     | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
73 :     (intList shape), ">, ",Param(param, i+1)]
74 : cchiw 2844 | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
75 : cchiw 2412 | Param(_,_)=""
76 : cchiw 2424
77 :     in
78 : cchiw 3276 String.concat["-EIN-" (*,Param(params, 0)*)," <",printbody(body),">"," _{",Index(index,0),"} "]
79 :    
80 : cchiw 2424 end
81 : cchiw 2394
82 : jhr 2391 end (* local *)
83 :     end

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