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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/mid-to-low/genH.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/mid-to-low/genH.sml

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

revision 2604, Fri Apr 25 18:23:44 2014 UTC revision 2605, Wed Apr 30 01:46:09 2014 UTC
# Line 20  Line 20 
20    
21      in      in
22    
23    val testing=1
24    
25    
26  fun insert (key, value) d =fn s =>  fun insert (key, value) d =fn s =>
# Line 44  Line 45 
45    
46  val bV= ref 0  val bV= ref 0
47    
48  fun printgetRHS x  =  fun toStringRHS x  = (case DstIL.Var.binding x
   
     (case DstIL.Var.binding x  
49      of vb => String.concat[      of vb => String.concat[
50          "\n Found ", DstIL.vbToString vb,"\n"]          "\n Found ", DstIL.vbToString vb,"\n"]
   
51      (* end case *))      (* end case *))
52    
53    
# Line 70  Line 68 
68    
69    
70    
71  fun printX(DstIL.ASSGN (x, DstIL.OP(opss,args)))= let  fun toStringAssgn(DstIL.ASSGN (x, DstIL.OP(opss,args)))=let
72            val A=[(Var.toString x),"==",DstOp.toString opss," : ",(String.concatWith "," (List.map Var.toString args))]
73          val a= print(String.concat([Var.toString  x,"==",DstOp.toString opss," : "]))          in String.concat A
74              in print (String.concatWith "," (List.map Var.toString args)) end          end
75      | printX(DstIL.ASSGN(x,DstIL.LIT _))= print(String.concat[Var.toString  x,"==...Lit"])      | toStringAssgn(DstIL.ASSGN(x,DstIL.LIT _))= String.concat[Var.toString  x,"==...Lit"]
76      | printX(DstIL.ASSGN(x,DstIL.CONS (_, varl)))= let      | toStringAssgn(DstIL.ASSGN(x,DstIL.CONS (_, varl)))= let
77               val y= List.map (fn e1=> Var.toString e1) varl               val y= List.map (fn e1=> Var.toString e1) varl
78              in print(String.concat[(Var.toString  x),"==",(String.concatWith "," y)]) end              in String.concat[(Var.toString  x),"==",(String.concatWith "," y)] end
79      | printX(DstIL.ASSGN (x, _))=print(String.concat[Var.toString  x,"==","CONS",printgetRHS x])      | toStringAssgn(DstIL.ASSGN (x, _))=String.concat[Var.toString  x,"==","CONS",toStringRHS x]
80    
81    
82    
83  fun  printTy(DstTy.IntTy )= "int "  fun toStringTy(DstTy.IntTy )= "int "
84      | printTy(DstTy.TensorTy [])= "Real "      | toStringTy(DstTy.TensorTy [])= "Real "
85      |printTy(DstTy.TensorTy(dd))=String.concat[      | toStringTy(DstTy.TensorTy(dd))=String.concat[
86      "TensorTy[", String.concatWith "," (List.map Int.toString dd), "] "]      "TensorTy[", String.concatWith "," (List.map Int.toString dd), "] "]
87    
88    
89  fun aaV(opss,args,pre,ty)=let  fun aaV(opss,args,pre,ty)=let
   
     (*problem here forces variable binding *)  
90      val a=DstIL.Var.new(pre ,ty)      val a=DstIL.Var.new(pre ,ty)
    (* val m=printTy ty  
     val z=print(String.concat["\n", m] )*)  
91      val code=DstIL.ASSGN (a,DstIL.OP(opss,args))      val code=DstIL.ASSGN (a,DstIL.OP(opss,args))
92     val g=printX code      val _ =(case testing
93            of 0=> 1
94            | _ => (String.concat([toStringTy ty,"\n", toStringAssgn code] );1)
95            (* end case *))
96      in      in
97          (a,[code])          (a,[code])
98      end      end
# Line 127  Line 124 
124      | E.C c=> c      | E.C c=> c
125      (*end case*))      (*end case*))
126    
127    (*
128  fun printIndexXX(n,mapp)=let  fun printIndexXX(n,mapp)=let
129      val a=lookup n mapp      val a=lookup n mapp
130      in (case a      in (case a
# Line 134  Line 132 
132          |SOME (s) => ((*print(String.concat[Int.toString(n), "==>",Int.toString(s)]);*)printIndexXX(n+1,mapp))          |SOME (s) => ((*print(String.concat[Int.toString(n), "==>",Int.toString(s)]);*)printIndexXX(n+1,mapp))
133          (*end case*))          (*end case*))
134      end      end
135    *)
136    
137    
138  fun getShape(params, id)=(case List.nth(params,id)  fun getShape(params, id)=(case List.nth(params,id)
# Line 154  Line 153 
153    
154  fun mkVec(mapp,(id,ix1,last,(args,params)))= let  fun mkVec(mapp,(id,ix1,last,(args,params)))= let
155      val g="New Vec"      val g="New Vec"
156      val gg=printIndexXX(0, mapp)  
157      val ix1'=List.map (fn (e1)=> mapIndex(e1,mapp)) ix1      val ix1'=List.map (fn (e1)=> mapIndex(e1,mapp)) ix1
158      val nU=List.nth(args,id)      val nU=List.nth(args,id)
159      val i=DstTy.indexTy(ix1')      val i=DstTy.indexTy(ix1')
# Line 163  Line 162 
162    
163  (*Helper functions for addition *)  (*Helper functions for addition *)
164  fun handleAddVec(mapp,(es,index,last,args))=let  fun handleAddVec(mapp,(es,index,last,args))=let
165      val m=print "made it to handleAdd vec"  
166      fun add([],rest,code)=(rest,code)      fun add([],rest,code)=(rest,code)
167     (* | add((id1,[])::es,rest,code)=let     (* | add((id1,[])::es,rest,code)=let
168          val (vA,A)= mkVec(mapp,(id1,index,args))          val (vA,A)= mkVec(mapp,(id1,index,args))
# Line 192  Line 191 
191    
192  (*subtract Vectors*)  (*subtract Vectors*)
193  fun mksubVec(mapp,([(id1,ix1),(id2,ix2)],[],last,args))= let  fun mksubVec(mapp,([(id1,ix1),(id2,ix2)],[],last,args))= let
194       val mm= printIndexXX(0,mapp)  
195      val (vA,A)= mkVec(mapp,(id1,ix1,last,args))      val (vA,A)= mkVec(mapp,(id1,ix1,last,args))
196      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))
197      val (vD, D)=aaV(DstOp.subVec(last),[vA, vB],"subVec",DstTy.TensorTy([last]))      val (vD, D)=aaV(DstOp.subVec(last),[vA, vB],"subVec",DstTy.TensorTy([last]))
# Line 223  Line 222 
222    
223  (*product of 1 scalars and 1 projection*)  (*product of 1 scalars and 1 projection*)
224  fun mkprodScaV(mapp,([(id1,ix1),(id2,ix2)],[],last,args))=let  fun mkprodScaV(mapp,([(id1,ix1),(id2,ix2)],[],last,args))=let
225       val mm= printIndexXX(0,mapp)  
226      val (vA,A)=mkSca(mapp,(id1,ix1,args))      val (vA,A)=mkSca(mapp,(id1,ix1,args))
227      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))
         val q=print(String.concat["Puppy-In prodScaV",Int.toString(last)])  
228    
229      val (vD, D)=aaV(DstOp.prodScaV(last),[vA, vB],"prodScaV",DstTy.TensorTy([last]))      val (vD, D)=aaV(DstOp.prodScaV(last),[vA, vB],"prodScaV",DstTy.TensorTy([last]))
230      in (vD,A@B@D) end      in (vD,A@B@D) end
231    
232  (*product of 2 projections*)  (*product of 2 projections*)
233  fun mkprodVec(mapp,([(id1,ix1),(id2,ix2)],[],last,args))= let  fun mkprodVec(mapp,([(id1,ix1),(id2,ix2)],[],last,args))= let
234      val rr=print "\n mkprodVec"  
235      val (vA,A)= mkVec(mapp,(id1,ix1,last,args))      val (vA,A)= mkVec(mapp,(id1,ix1,last,args))
236      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))      val (vB, B)= mkVec(mapp,(id2,ix2,last,args))
237      val (vD, D)=aaV(DstOp.prodVec(last),[vA, vB],"prodV",DstTy.TensorTy([last]))      val (vD, D)=aaV(DstOp.prodVec(last),[vA, vB],"prodV",DstTy.TensorTy([last]))
# Line 242  Line 240 
240  (*error here *)  (*error here *)
241  (*summation over product of 2 projections*)  (*summation over product of 2 projections*)
242  fun mkprodSumVec(mapp,(m,[],i,args))= let  fun mkprodSumVec(mapp,(m,[],i,args))= let
243      val rr=print "\n In prod sum vec"  
244      val i'=i+1      val i'=i+1
245      val (vD,D)=mkprodVec(mapp,(m,[],i',args))      val (vD,D)=mkprodVec(mapp,(m,[],i',args))
246      val (vE, E)=aaV(DstOp.sumVec(i'),[vD],"sumVec",DstTy.realTy)      val (vE, E)=aaV(DstOp.sumVec(i'),[vD],"sumVec",DstTy.realTy)
# Line 251  Line 249 
249    
250  (*product of -1 and 1 projection*)  (*product of -1 and 1 projection*)
251  fun mkNegV(mapp,((vA,id,ix),[],last,args))=let  fun mkNegV(mapp,((vA,id,ix),[],last,args))=let
     val aaa=print "\n pre mkVec"  
252      val (vB, B)= mkVec(mapp,(id,ix,last,args))      val (vB, B)= mkVec(mapp,(id,ix,last,args))
     val b= print "\n post mkVec"  
253      val (vD, D)=aaV(DstOp.prodScaV(last),[vA, vB],"prodScaV",DstTy.TensorTy([last]))      val (vD, D)=aaV(DstOp.prodScaV(last),[vA, vB],"prodScaV",DstTy.TensorTy([last]))
254      in (vD,B@D) end      in (vD,B@D) end
255    
# Line 282  Line 278 
278    
279  (*Can do multiple summations *)  (*Can do multiple summations *)
280  fun sum(a, ( m,sx,args))=let  fun sum(a, ( m,sx,args))=let
281      val mss=print "\n IN SUM"  
282      fun sumI1(left,(v,0,lb1),[],rest,code)=let      fun sumI1(left,(v,0,lb1),[],rest,code)=let
283              (*val mapp=a@left@[lb1]*)              (*val mapp=a@left@[lb1]*)
284              val mapp =insert(v, lb1) left              val mapp =insert(v, lb1) left
# Line 310  Line 306 
306    
307  fun mkC n= let  fun mkC n= let
308      val (vB,B)=aaV(DstOp.C(n),[],"Const",DstTy.TensorTy([]))      val (vB,B)=aaV(DstOp.C(n),[],"Const",DstTy.TensorTy([]))
     val m=print"postmkC"  
309      in (vB,B) end      in (vB,B) end
310    
311    

Legend:
Removed from v.2604  
changed lines
  Added in v.2605

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