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 2424, Mon Sep 16 14:57:35 2013 UTC branches/charisee_dev/src/compiler/ein/printer.sml revision 3541, Mon Jan 4 18:03:27 2016 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
7        structure S = Specialize  
      (* structure R = Rewrite*)  
8      in      in
9    
10      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]      fun iTos e=Int.toString e
11        fun intList l = String.concatWith "," (List.map iTos l)
12        fun handleIndex e= (case e
13            of E.C(cx,true)=> String.concat["C(",iTos(cx),")"]
14            | E.C(cx,false)=> String.concat["S(",iTos(cx),")"]
15            | E.V(ix)=> iTos(ix)
16        (*end case*))
17        fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
18        fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
19        fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
20        fun printbody b= (case b
21            of E.B(E.Const r) => iTos(r)
22            | E.B(E.ConstR r) =>RationalEin.toString r
23            | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
24            | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
25            | E.G(E.Delta(ix)) =>  handleBeta ix
26            | E.G(E.Epsilon(ix, jx, kx)) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
27            | E.G(E.Eps2(ix, jx)) => String.concat["ϵ_",iTos(ix), iTos(jx)]
28    
29            | E.Field(id, []) =>String.concat[" F",iTos(id)]
30            | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
31            | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
32    
33            | E.Conv(fid,alpha, tid ,[])=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")|"]
34            | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★h(",iTos(tid),")dx_",handleAlpha beta,"}|"]
35     (*
36            | E.Conv _ => "F"
37     *)
38            | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
39            | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
40     (*
41            | E.Probe (e1,e2)=> String.concat [printbody(e1),"[", printbody(e2),"]"]
42     *)
43            | E.Probe (e1,e2)=> String.concat ["Probe(",printbody(e1),",",printbody(e2),")"]
44            | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
45            | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[", (String.concatWith "," (List.map printbody pos)),"]"]
46            | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
47            | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
48            | E.Sum ([(v,_,_)],e1)=>String.concat[" Σ_",handleIndex v,"⋐" ,printbody e1,"⋑",handleIndex v]
49            | E.Sum (sumindex,e1)=>String.concat[" Σ_", String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
50     (*
51             | E.Sum (sumindex,e1)=>String.concat[" Σ",printbody e1,"⋑"]
52     *)
53            | E.Op1(E.Neg, e1) => String.concat["-NEG-", printbody e1]
54            | E.Op1(E.Sqrt ,e )=> String.concat[ "√(", printbody e ,")"]
55            | E.Op1(E.PowInt n1,e) => String.concat[  "(",printbody e ,")^",Int.toString n1]
56            | E.Op1(E.PowReal n1,e) => String.concat[ "(", printbody e ,")^",RationalEin.toString n1]
57            | E.Op1(E.PowEmb (sx,n),e)=>String.concat["POW(",printbody e,"^", iTos n,")"]
58            | E.Op1(E.Exp, e1)=> String.concat["E^(",printbody e1,")"]
59            | E.Op1(t,e)=>(case t
60                of  E.Cosine =>  String.concat["Cosine(",printbody e ,")"]
61                | E.ArcCosine => String.concat["ArcCosine(",printbody e ,")"]
62                | E.Sine  => String.concat["Sine(",printbody e ,")"]
63                | E.ArcSine  => String.concat["ArcSine(",printbody e ,")"]
64                | E.Tangent  => String.concat["Tangent(",printbody e ,")"]
65                | E.ArcTangent => String.concat["ArcTangent(",printbody e ,")"]
66                (*end case*))
67            | E.Op2(E.Sub,e1, e2) => String.concat ["(",printbody(e1),"---- ",printbody(e2)]
68            | E.Op2(E.Div,e1,e2) => String.concat ["(",printbody(e1),")/( ",printbody (e2),")"]
69     (*
70            | E.Opn(E.Add, el) => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
71            | E.Opn(E.Prod, el) => String.concat["{*{",String.concatWith "* " (List.map printbody el),"}*}"]*)
72            | E.Opn(E.Add, el) => String.concat["Add(",String.concatWith "+" (List.map printbody el),")"]
73            | E.Opn(E.Prod, el) => String.concat["Prod<",String.concatWith "* " (List.map printbody el),">"]
74            | E.Holder n1=> String.concat["Holder(",Int.toString(n1),")"]
75            | E.EvalKrn  del=>String.concat["Krn1pos ",iTos(del)]
76            | E.BuildPos(e1,e2)=>String.concat["Buildpos ",printbody e2]
77            (* end case *))
78    
79        (*printerE:EIN ->string*)
80      fun printerE (Ein.EIN{params, index, body}) = let      fun printerE (Ein.EIN{params, index, body}) = let
81            fun printer2 term = (case term          fun Index (dim::i, count) = String.concat["(", iTos count,
82                   of E.Value(id)=> String.concat[" CI-",Int.toString(id)]                  " DIM:", iTos dim, ")", Index(i,count+1)]
   
                   | E.Tensor(id, E.c mx) =>  String.concat[" T",Int.toString(id),"_",Int.toString(mx)]  
                   | E.Tensor(id, E.m [])  => String.concat[" S",Int.toString(id)]  
                   | E.Tensor(id, E.m mx) =>  String.concat[" T",Int.toString(id),"_",intList(mx)]  
                   | E.Pair e => String.concat["(",String.concatWith "," (List.map printer2 e),")"]  
                   | E.Const e => Real.toString(e)  
                   | E.Field(id, [],[]) => String.concat ["F",Int.toString(id)]  
                   | E.Field(id, mx,[]) => String.concat ["F",Int.toString(id),"_",intList(mx)]  
                   | E.Field(id, [],dx) => String.concat ["F,",Int.toString(id),",",intList(dx)]  
                   | E.Field(id, mx,dx) => String.concat ["F",Int.toString(id),"_",intList(mx),",",intList(dx)]  
   
                   | E.Add e        => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]  
                   | E.Sub(a,b)      => String.concat ["(",printer2(a),"-",printer2(b), ")"]  
                   | E.Div(a,b)      => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]  
                   | E.Prod [e1,e2,e3]       => String.concatWith "*" (List.map printer2 [e1,e2,e3])  
                   | E.Prod e       => String.concatWith "^^" (List.map printer2 e)  
                   | E.Delta(i,j)    => String.concat [" Delta_",Int.toString(i),Int.toString(j)]  
                   | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]  
                   | E.Conv(k,deltas) => let  
                       val n= length(deltas)  
                       fun imp([])=""  
                       | imp([(i,j)])=  String.concat [" Delta_",Int.toString(i),Int.toString(j)]  
                       | imp((i,j)::es)= String.concat[" Delta_",Int.toString(i),Int.toString(j)," ",imp(es)]  
                       in  
                         String.concat ["V (*)",printer2(k),"{",imp(deltas),"}_",Int.toString(n)]  
                       end  
                   | E.Partial e  => String.concat ["d^",Int.toString(length(e)),"/dx_",intList(e)]  
                   | E.Probe(a,b) => String.concat ["",printer2(a), "","@", printer2(b)]  
                   | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]  
                   | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]  
                   | _ =>("newbie")  
                 (* end case *))  
           fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,  
                 " DIM:", Int.toString dim, ")", Index(i,count+1)]  
             | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),  
                 " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]  
83              | Index (_, count) = ""              | Index (_, count) = ""
84          fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]          fun Param(E.TEN(t,shape)::param, i)=
85              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]                  String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
86                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
87                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
88                            (intList shape),  ">, ",Param(param, i+1)]
89                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
90              | Param(_,_)=""              | Param(_,_)=""
91    
         val str=String.concat [Param(params, 0)," \n<",printer2(body),">","\n _{",Index(index,0),"} \n "]  
92          in          in
93              print str             String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
         end  
94    
95         (* fun printerApp(R.App(e,l))= printerE(e)          end
             | printerApp(_)= ""*)  
96    
97      end (* local *)      end (* local *)
98    end    end

Legend:
Removed from v.2424  
changed lines
  Added in v.3541

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