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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/charisee/src/compiler/ein/printer.sml revision 2387, Sun Jun 16 00:18:49 2013 UTC branches/charisee_dev/src/compiler/ein/printer.sml revision 3440, Mon Nov 16 19:16:54 2015 UTC
# Line 1  Line 1 
   
1  (*printer Function returns String*)  (*printer Function returns String*)
2  structure Printer = struct  structure Printer = struct
3    
4      local      local
5      structure G = GenericEin  
6      structure E = Ein      structure E = Ein
     structure S = Specialize  
     structure R = Rewrite  
7    
8          in          in
9    
10        fun iTos e=Int.toString e
11      fun intList([])=""      fun intList l = String.concatWith "," (List.map iTos l)
12          |intList(e::es)= Int.toString(e)^ intList(es)      fun handleIndex e= (case e
13            of E.C(cx)=> String.concat["'",iTos(cx),"'"]
14            |  E.V(ix)=> iTos(ix)
   
         fun printerE(Ein.EIN{params, index, body})= let  
         fun printer2 term = (case term  
             of E.Tensor(id, mx) => (  
                 case mx  
                 of [] => ( " S"^Int.toString(id))  
                 | [a] => ( " V"^Int.toString(id)^ "_"^Int.toString(a))  
                 | [a,b]=> ("M"^Int.toString(id)^ "_"^ intList(mx))  
                 | _ =>  ("T"^Int.toString(id)^ "_"^intList(mx))  
15                  (* end case *))                  (* end case *))
16              | E.Const(f)=> ("zero")      fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
17              | E.Field(id, mx) => ( "F"^Int.toString(id)^"_"^intList(mx))      fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
18              | E.Add(e)=> let      fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
19                  fun imp([])=""      fun printbody b= (case b
20                  | imp([a])=printer2(a)          of E.Const r => iTos(r)
21                  | imp(a::es)=(printer2(a)^"+"^imp(es))          | E.ConstR r =>RationalEin.toString r
22                  in ("("^imp(e)^")") end          | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
23              | E.Sub(b,c)=>("("^printer2(b)^")\n -( "^printer2(c)^ ")")          | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
24            | E.Field(id, []) =>String.concat[" F",iTos(id)]
25              | E.Prod(e)=>let          | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
26                  fun imp([])=""          | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
27                  | imp([a])=printer2(a)          | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
28                  | imp(a::es)=printer2(a)^" "^imp(es)          | E.Delta(ix) =>  handleBeta ix
29                  in "("^imp(e)^")" end          | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
30              | E.Delta(i,j)=> (" Delta_"^Int.toString(i)^Int.toString(j))          | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
31              | E.Epsilon(i,j,k) =>(" E_"^Int.toString(i)^Int.toString(j)^Int.toString(k) )          | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
32              | E.Conv(i,j,k,l) => let          | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
33                  fun imp([])=""          | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
34                  | imp([(a,b)])=(" Delta_"^Int.toString(a)^Int.toString(b))          | E.Neg e1 => String.concat["-NEG-", printbody e1]
35                  | imp((a,b)::es)=(" Delta_"^Int.toString(a)^Int.toString(b))^" "^imp(es)          | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
36                  in i^"*"^k^"^{"^imp(j)^"}_"^Int.toString(l) end          | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
37              | E.Partial(e)=> ("d"^ Int.toString(length(e))^"/dx_"^intList(e))          | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
38              | E.Probe(a,b)=> ( "("^printer2(a)^ ")"^"@"^"T"^Int.toString(b))          | E.Prod el => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]
39              | E.Apply(a, b)=> (printer2(a)^ " " ^printer2(b) ^ " " )          | E.Div(e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
40              | E.Sum (id,a)=> ( " Sigma:"^Int.toString(id)^ printer2(a) )          | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
41              |_=>("newbie")          | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
42            | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
43            | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
44            | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
45            | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[",
46                (String.concatWith "," (List.map printbody pos)),"]"]
47            | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
48            | E.PowInt(e,n1) => String.concat[  "(",printbody e ,")^",Int.toString n1]
49            | E.PowReal(e,n1) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
50            | E.PowEmb (e,sx,n)=>String.concat["POW(",printbody e,"^", iTos n,")"]
51            | E.Trig(t,e)=>(case t
52                of  E.Cosine =>  String.concat["Cosine(",printbody e ,")"]
53                | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
54                | E.Sine  => String.concat["Sine(",printbody e ,")"]
55                | E.ArcSine  => String.concat["ArcSine(",printbody e ,")"]
56                | E.Tangent  => String.concat["Tangent(",printbody e ,")"]
57                | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
58                (*end case*))
59            | E.Exp e1=> String.concat["E^(",printbody e1,")"]
60              (*end case *))              (*end case *))
             fun Index ((E.IX(dim))::i, count)=("("^Int.toString(count)^  
                     " DIM:"^Int.toString(dim)^")"^ Index(i,count+1))  
                 |Index ((E.SX(dim))::i, count)=("} {Summation:("^Int.toString(count) ^  
                     " DIM:"^Int.toString(dim)^")"^ Index(i,count+1))  
                 | Index(_, count)= ("")  
             in  
                 ("\n<"^printer2(body)^">"^"_{"^Index(index,0)^"}")  
             end  
   
61    
62          fun printerApp(R.App(e,l)) =let      (*printerE:EIN ->string*)
63              fun argList([])=""      fun printerE (Ein.EIN{params, index, body}) = let
64                | argList([e])=e          fun Index (dim::i, count) = String.concat["(", iTos count,
65                |argList(e::es)= e^","^argList(es)                  " DIM:", iTos dim, ")", Index(i,count+1)]
66              in printerE(e)^"["^argList(l)^"]" end              | Index (_, count) = ""
67          |printerApp(_)=""          fun Param(E.TEN(t,shape)::param, i)=
68                    String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
69                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
70                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
71                            (intList shape),  ">, ",Param(param, i+1)]
72                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
73                | Param(_,_)=""
74    
75            in
76               String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
77    
78  end  end
79    
80        end (* local *)
81  end  end

Legend:
Removed from v.2387  
changed lines
  Added in v.3440

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