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 3441 - (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 : cchiw 3440 fun printbody b= (case b
20 : cchiw 3441 of E.B(E.Const r) => iTos(r)
21 :     | E.B(E.ConstR r) =>RationalEin.toString r
22 : cchiw 2844 | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
23 :     | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
24 : cchiw 3441 | E.G(E.Delta(ix)) => handleBeta ix
25 :     | E.G(E.Epsilon(ix, jx, kx)) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
26 :     | E.G(E.Eps2(ix, jx)) => String.concat["ϵ_",iTos(ix), iTos(jx)]
27 :    
28 : cchiw 2844 | E.Field(id, []) =>String.concat[" F",iTos(id)]
29 :     | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
30 : cchiw 2605 | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
31 : cchiw 3441 (*
32 :     | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
33 :     | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
34 :     *)
35 :     | E.Conv _ => "F"
36 : cchiw 2605 | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
37 :     | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
38 : cchiw 3441 (*
39 : cchiw 3415 | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
40 : cchiw 3441 *)
41 :     | E.Probe (e1,e2)=> String.concat ["Probe(",printbody(e1),")"]
42 :     | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
43 :     | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[", (String.concatWith "," (List.map printbody pos)),"]"]
44 :     | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[", (printbody pos),"]"]
45 :     | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
46 :     (*
47 :     | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
48 :     | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]*)
49 :     | E.Sum (sumindex,e1)=>String.concat[" Σ",printbody e1,"⋑"]
50 :     | E.Op1(E.Neg, e1) => String.concat["-NEG-", printbody e1]
51 :     | E.Op1(E.Sqrt ,e )=> String.concat[ "√(", printbody e ,")"]
52 :     | E.Op1(E.PowInt n1,e) => String.concat[ "(",printbody e ,")^",Int.toString n1]
53 :     | E.Op1(E.PowReal n1,e) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
54 :     | E.Op1(E.PowEmb (sx,n),e)=>String.concat["POW(",printbody e,"^", iTos n,")"]
55 :     | E.Op1(E.Exp, e1)=> String.concat["E^(",printbody e1,")"]
56 :     | E.Op1(t,e)=>(case t
57 : cchiw 3440 of E.Cosine => String.concat["Cosine(",printbody e ,")"]
58 :     | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
59 :     | E.Sine => String.concat["Sine(",printbody e ,")"]
60 :     | E.ArcSine => String.concat["ArcSine(",printbody e ,")"]
61 :     | E.Tangent => String.concat["Tangent(",printbody e ,")"]
62 :     | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
63 :     (*end case*))
64 : cchiw 3441 | E.Op2(E.Sub,e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
65 :     | E.Op2(E.Div,e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
66 :     (*
67 :     | E.Opn(E.Add, el) => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
68 :     | E.Opn(E.Prod, el) => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]*)
69 :     | E.Opn(E.Add, el) => String.concat["Add(",String.concatWith "+" (List.map printbody el),")"]
70 :     | E.Opn(E.Prod, el) => String.concat["Prod<",String.concatWith "* " (List.map printbody el),">"]
71 :    
72 : cchiw 2845 (* end case *))
73 : cchiw 3276
74 : cchiw 2844 (*printerE:EIN ->string*)
75 : cchiw 2605 fun printerE (Ein.EIN{params, index, body}) = let
76 : cchiw 2844 fun Index (dim::i, count) = String.concat["(", iTos count,
77 :     " DIM:", iTos dim, ")", Index(i,count+1)]
78 : jhr 2391 | Index (_, count) = ""
79 : cchiw 2844 fun Param(E.TEN(t,shape)::param, i)=
80 : cchiw 2845 String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
81 :     | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
82 :     | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
83 :     (intList shape), ">, ",Param(param, i+1)]
84 : cchiw 2844 | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
85 : cchiw 2412 | Param(_,_)=""
86 : cchiw 2424
87 :     in
88 : cchiw 3383 String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
89 : cchiw 3276
90 : cchiw 2424 end
91 : cchiw 2394
92 : jhr 2391 end (* local *)
93 :     end

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