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 2412 - (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 : jhr 2391
14 :     fun printerE (Ein.EIN{params, index, body}) = let
15 :     fun printer2 term = (case term
16 : cchiw 2394 of E.Tensor(id, []) => String.concat[" S",Int.toString(id)]
17 : cchiw 2409 | E.Tensor(id, mx) => String.concat[" T",Int.toString(id),"_",intList(mx)]
18 : cchiw 2394 | E.Const e => Real.toString(e)
19 : cchiw 2407 | E.Field(id, []) => String.concat ["F",Int.toString(id)]
20 : cchiw 2394 | E.Field(id, mx) => String.concat ["F",Int.toString(id),"_",intList(mx)]
21 : cchiw 2409 | E.Add e => String.concat["(",String.concatWith "+" (List.map printer2 e),")"]
22 : cchiw 2394 | E.Sub(a,b) => String.concat ["(",printer2(a),"- ",printer2(b), ")"]
23 :     | E.Div(a,b) => String.concat ["(",printer2(a),"/ ",printer2(b), ")"]
24 :     | E.Prod e => String.concatWith "*" (List.map printer2 e)
25 :     | E.Delta(i,j) => String.concat [" Delta_",Int.toString(i),Int.toString(j)]
26 :     | E.Epsilon(i,j,k)=> String.concat ["E_",Int.toString(i),Int.toString(j),Int.toString(k) ]
27 :     | E.Conv(v,deltas,k,n) => let
28 : jhr 2391 fun imp([])=""
29 : cchiw 2394 | imp([(i,j)])= String.concat [" Delta_",Int.toString(i),Int.toString(j)]
30 :     | imp((i,j)::es)= String.concat[" Delta_",Int.toString(i),Int.toString(j)," ",imp(es)]
31 :     in
32 :     String.concat [v,"*",k,"{",imp(deltas),"}_",Int.toString(n)]
33 :     end
34 : cchiw 2407 | E.Partial e => String.concat ["d^",Int.toString(length(e)),"/dx_",intList(e)]
35 : cchiw 2412 | E.Probe(a,b) => String.concat ["",printer2(a), "","@(", printer2(b),")"]
36 : cchiw 2394 | E.Apply(a,b) => String.concat [ printer2(a)," ", printer2(b)," "]
37 : cchiw 2399 | E.Sum (id,a) => String.concat [" Sigma:", Int.toString(id), " ",printer2(a)]
38 : jhr 2391 | _ =>("newbie")
39 : cchiw 2394 (* end case *))
40 :     fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,
41 :     " DIM:", Int.toString dim, ")", Index(i,count+1)]
42 :     | Index ((E.SX(dim))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),
43 :     " DIM:",Int.toString(dim),")", Index(i,count+1)]
44 : jhr 2391 | Index (_, count) = ""
45 : cchiw 2412 fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]
46 :     | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", intList d," ",Param(param, i+1)]
47 :     | Param(_,_)=""
48 : cchiw 2383 in
49 : cchiw 2412 String.concat ["\n",Param(params, 0),"\n<",printer2(body),">","_{",Index(index,0),"}\n"]
50 : cchiw 2387 end
51 : cchiw 2383
52 : cchiw 2395 (* fun printerApp(R.App(e,l))= printerE(e)
53 :     | printerApp(_)= ""*)
54 : cchiw 2394
55 : jhr 2391 end (* local *)
56 :     end

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