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

revision 2499, Mon Nov 4 16:10:36 2013 UTC revision 2867, Tue Feb 10 06:52:58 2015 UTC
# Line 1  Line 1 
   
1  (*printer Function returns String*)  (*printer Function returns String*)
2  structure Printer = struct  structure Printer = struct
3    
# Line 8  Line 7 
7    
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  fun handleIndex e= (case e
13      of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]          of E.C(cx)=> String.concat["'",iTos(cx),"'"]
14      |  E.V(ix)=> Int.toString(ix)          |  E.V(ix)=> iTos(ix)
15  )      (*end case*))
   
16  fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]  fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
17        fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
18        fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",iTos(lb),"-",iTos(ub),"]"]
19    
20        (*printbody:ein_exp ->string*)
 fun handleBeta(a,b)=String.concat["Delta_(",handleIndex a, ",", handleIndex b,")"]  
   
 fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",Int.toString(lb),"-",Int.toString(ub),"]"]  
   
21  fun printbody term = (case term  fun printbody term = (case term
22      of E.Const r => Real.toString(r)          of E.Const r => iTos(r)
23      | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]          | E.Tensor(id, []) =>String.concat[" S",iTos(id)]
24      | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",handleAlpha alpha]          | E.Tensor(id, alpha) =>String.concat[" T",iTos(id),"_",handleAlpha alpha]
25      | E.Field(id, []) =>String.concat[" F",Int.toString(id)]          | E.Field(id, []) =>String.concat[" F",iTos(id)]
26      | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",handleAlpha alpha]          | E.Field(id, alpha) =>String.concat[" F",iTos(id),"_",handleAlpha alpha]
27      | E.Krn(tid,[],pos) =>String.concat["h ",Int.toString(tid),"[",  (printbody pos),"]"]          | E.Krn(tid,[],pos) =>String.concat[" H ",iTos(tid),"[",  (printbody pos),"]"]
28      | E.Krn(tid,betas,pos) => String.concat["h",Int.toString(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]          | E.Krn(tid,betas,pos) => String.concat[" H",iTos(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
29      | E.Delta(ix) =>  handleBeta ix      | E.Delta(ix) =>  handleBeta ix
30      | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]          | E.Value(ix)=> String.concat["_",iTos(ix),"_"]
31      | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]          | E.Epsilon(ix, jx, kx) => String.concat["ϵ_",iTos(ix), iTos(jx), iTos(kx)]
32      | E.Sum (sumindex,e1)=>String.concat["Σ_",String.concatWith ","(List.map handleSumRange sumindex)," (", printbody e1,")"]          | E.Eps2(ix, jx) => String.concat["ϵ_",iTos(ix), iTos(jx)]
33      | E.Neg e1 => String.concat["-", printbody e1]          | E.Sum (sumindex,e1)=>String.concat[" Σ_",String.concatWith ","(List.map handleSumRange sumindex),"⋐" ,printbody e1,"⋑"]
34            | E.Neg e1 => String.concat["-NEG-", printbody e1]
35            | E.Lift e1 => String.concat["LIFT ⊢", printbody e1,"⊣"]
36      | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]      | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
37      | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]      | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
38      | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]      | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]
39      | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]      | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
40      | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]      | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
41      | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]      | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
42      | E.Conv(fid,alpha, tid ,[])=> String.concat["|V",Int.toString(fid),"_{",handleAlpha alpha, "}★h",Int.toString(tid),"|"]          | 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",Int.toString(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",Int.toString(tid),"|"]          | E.Conv(fid,alpha, tid, beta)=> String.concat["|v",iTos(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",iTos(tid),"|"]
44      | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","[", printbody(e2),"]"]          | E.Probe (e1,e2)=> String.concat ["[",printbody(e1), "","[", printbody(e2),"]]"]
45      | E.Img (fid,alpha,pos)=> String.concat ["V", Int.toString(fid),"_",handleAlpha alpha,"[",          | E.Img (fid,alpha,pos)=> String.concat [" V", iTos(fid),"_",handleAlpha alpha,"[",
46                  (String.concatWith "," (List.map printbody pos)),"]"]                  (String.concatWith "," (List.map printbody pos)),"]"]
47            | E.Sqrt e => String.concat[ "√(", printbody e ,")"]
   
   
48              (* end case *))              (* end case *))
49    
50        (*printerE:EIN ->string*)
51          fun printerE (Ein.EIN{params, index, body}) = let          fun printerE (Ein.EIN{params, index, body}) = let
52          fun Index (dim::i, count) = String.concat["(", Int.toString count,          fun Index (dim::i, count) = String.concat["(", iTos count,
53                  " DIM:", Int.toString dim, ")", Index(i,count+1)]                  " DIM:", iTos dim, ")", Index(i,count+1)]
54              | Index (_, count) = ""              | Index (_, count) = ""
55          fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]          fun Param(E.TEN(t,shape)::param, i)=
56              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]                  String.concat[iTos(i), ":TEN "(*, iTos t*),"<", intList shape,">, ",Param(param, i+1)]
57                | Param(E.FLD(d)::param, i)= String.concat[iTos(i), ":FLD(", iTos d,"), ",Param(param, i+1)]
58                | Param(E.IMG(d,shape)::param, i)= String.concat[iTos(i), ":IMG(", iTos d,")< ",
59                            (intList shape),  ">, ",Param(param, i+1)]
60                | Param(E.KRN::param, i)= String.concat[iTos(i), ":KRN ",Param(param, i+1)]
61              | Param(_,_)=""              | Param(_,_)=""
62    
         val str=String.concat ["\n\t" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} \n "]  
63          in          in
64              str              String.concat["-EIN-" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"} "]
65          end          end
66    
        (* fun printerApp(R.App(e,l))= printerE(e)  
             | printerApp(_)= ""*)  
   
67      end (* local *)      end (* local *)
68    end    end

Legend:
Removed from v.2499  
changed lines
  Added in v.2867

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