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 2428 - (view) (download)
Original Path: branches/charisee/src/compiler/ein/printer.sml

1 : cchiw 2383
2 : cchiw 2387 (*printer Function returns String*)
3 : cchiw 2383 structure Printer = struct
4 :    
5 :     local
6 : jhr 2391 structure G = GenericEin
7 :     structure E = Ein
8 :     structure S = Specialize
9 : cchiw 2395 (* structure R = Rewrite*)
10 : jhr 2391 in
11 : cchiw 2383
12 : cchiw 2407 fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
13 : cchiw 2426
14 :     fun printIndex e= (case e
15 : cchiw 2427 of E.C(cx)=> String.concat["c{",intList(cx),"}"]
16 :     | E.V([ix])=> Int.toString(ix)
17 :     | E.V(mx)=> intList(mx)
18 : cchiw 2426 )
19 :     fun imp([])=""
20 :     | imp([(i,j)])= String.concat [" Delta_",printIndex(i),printIndex(j)]
21 :     | imp((i,j)::es)= String.concat[" Delta_",printIndex(i),printIndex(j)," ",imp(es)]
22 :    
23 :    
24 :     fun printerE (Ein.EIN{params, index, body}) = let
25 : jhr 2391 fun printer2 term = (case term
26 : cchiw 2424 of E.Value(id)=> String.concat[" CI-",Int.toString(id)]
27 : cchiw 2427 | E.Tensor(id, E.V([])) =>String.concat[" S",Int.toString(id)]
28 : cchiw 2426 | E.Tensor(id, ix) =>String.concat[" T",Int.toString(id),"_",printIndex ix]
29 : cchiw 2424 | E.Pair e => String.concat["(",String.concatWith "," (List.map printer2 e),")"]
30 : cchiw 2394 | E.Const e => Real.toString(e)
31 : cchiw 2427 | E.Field(id, E.V [],E.V []) => String.concat ["F",Int.toString(id)]
32 : cchiw 2426 | E.Field(id, mx,dx) => String.concat ["F",Int.toString(id),"_",printIndex(mx),",",printIndex(dx)]
33 : cchiw 2424
34 : cchiw 2409 | E.Add e => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]
35 : cchiw 2427 | E.Sub(a,b) => String.concat ["(",printer2(a),"- ",printer2(b), ")"]
36 : cchiw 2394 | E.Div(a,b) => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]
37 : cchiw 2428 | E.Prod e => String.concatWith "*" (List.map printer2 e)
38 : cchiw 2427 | E.Kernel [] => "h"
39 :     | E.Kernel dels=> String.concat["h^",imp(dels)]
40 :     | E.Delta dels => imp(dels)
41 : cchiw 2394 | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]
42 : cchiw 2426 | E.Conv(k,[]) => String.concat ["V (*)",printer2(k)]
43 : cchiw 2427 | E.Conv(k,[E.V(mx)]) =>let
44 :     val n= length(mx)
45 :     val ind= intList(mx)
46 :     in
47 :     String.concat ["V (*)",printer2(k),"^",Int.toString(n),"{",ind,"}"]
48 :     end
49 : cchiw 2426 | E.Conv(k,_) => "Incorrect convolution argument"
50 : cchiw 2427 | E.Partial(E.C(ix)) => String.concat ["d^1","/dx_",intList(ix)]
51 :     | E.Partial(E.V(mx)) => String.concat ["d^",Int.toString(length(mx)),"/dx_",intList(mx)]
52 : cchiw 2424 | E.Probe(a,b) => String.concat ["",printer2(a), "","@", printer2(b)]
53 : cchiw 2394 | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]
54 : cchiw 2399 | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]
55 : jhr 2391 | _ =>("newbie")
56 : cchiw 2394 (* end case *))
57 :     fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
58 :     " DIM:", Int.toString dim, ")", Index(i,count+1)]
59 : cchiw 2424 | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
60 :     " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]
61 : jhr 2391 | Index (_, count) = ""
62 : cchiw 2412 fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
63 :     | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]
64 :     | Param(_,_)=""
65 : cchiw 2424
66 : cchiw 2427 val str=String.concat [Param(params, 0)," \n<",printer2(body),">","\n _{",Index(index,0),"} \n \n \n "]
67 : cchiw 2424 in
68 : cchiw 2427 print str; str
69 : cchiw 2424 end
70 : cchiw 2383
71 : cchiw 2395 (* fun printerApp(R.App(e,l))= printerE(e)
72 :     | printerApp(_)= ""*)
73 : cchiw 2394
74 : jhr 2391 end (* local *)
75 :     end

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