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/step2.sml
ViewVC logotype

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

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

revision 2844, Tue Dec 9 18:05:29 2014 UTC revision 2845, Fri Dec 12 06:46:23 2014 UTC
# Line 8  Line 8 
8      structure E = Ein      structure E = Ein
9      structure S3=step3      structure S3=step3
10      structure genKrn=genKrn      structure genKrn=genKrn
11      structure tS= toS      structure LowToS= LowToString
12    
13      in      in
14    
# Line 16  Line 16 
16  fun insert (key, value) d =fn s =>  fun insert (key, value) d =fn s =>
17  if s = key then SOME value  if s = key then SOME value
18  else d s  else d s
   
19  fun lookup k d = d k  fun lookup k d = d k
20  val empty =fn key =>NONE  val empty =fn key =>NONE
   
21  fun err _=raise Fail("Invalid Field Here")  fun err _=raise Fail("Invalid Field Here")
22  fun errS str=raise Fail(str)  fun errS str=raise Fail(str)
   
23  (*Helpers for scalars*)  (*Helpers for scalars*)
   
 fun mkCons(shape, rest)=let  
     val ty=DstTy.TensorTy shape  
     val a=DstIL.Var.new("Cons" ,ty)  
     val code=DstIL.ASSGN (a,DstIL.CONS(ty ,rest))  
     (*val _=print("###"^tS.toStringAll(ty,code))*)  
     in (a, [code])  
     end  
   
   
24  val Sca=DstTy.TensorTy([])  val Sca=DstTy.TensorTy([])
25  val addR=DstOp.addSca  val addR=DstOp.addSca
   
   
26  fun mkProdSca(lhs,rest)=S3.aaV(DstOp.prodSca,rest,lhs^"prodSca",Sca)  fun mkProdSca(lhs,rest)=S3.aaV(DstOp.prodSca,rest,lhs^"prodSca",Sca)
27  fun mkSubSca(lhs,rest)= S3.aaV(DstOp.subSca,rest,lhs^"subSca",Sca)  fun mkSubSca(lhs,rest)= S3.aaV(DstOp.subSca,rest,lhs^"subSca",Sca)
28  fun mkDivSca(lhs,rest)= S3.aaV(DstOp.divSca,rest,lhs^"divSca",Sca)  fun mkDivSca(lhs,rest)= S3.aaV(DstOp.divSca,rest,lhs^"divSca",Sca)
29  fun mkMultipleSca(info,ids,rator)=S3.mkMultiple(info,ids,rator,Sca)  fun mkMultipleSca(info,ids,rator)=S3.mkMultiple(info,ids,rator,Sca)
30  fun mkReal n=S3.mkReal n  fun mkReal n=S3.mkReal n
31        fun mkCons(shape, rest)=let
32            val ty=DstTy.TensorTy shape
33            val a=DstIL.Var.new("Cons" ,ty)
34            val code=DstIL.ASSGN (a,DstIL.CONS(ty ,rest))
35            (*val _=print("###"^LowToS.toStringAll(ty,code))*)
36            in
37                (a, [code])
38            end
39    
40  fun prodIter(origIndex,index,nextfn,args)=(let  fun prodIter(origIndex,index,nextfn,args)=(let
41      val index'=List.map (fn (e)=>(e-1)) index      val index'=List.map (fn (e)=>(e-1)) index
   
42      fun get(n,m,mapp)=let      fun get(n,m,mapp)=let
43          val mapp =insert(n, m) mapp          val mapp =insert(n, m) mapp
44          in          in
45              nextfn(mapp,args)              nextfn(mapp,args)
46          end          end
   
47      fun Iter(mapp,[],rest,code,shape,_)=let      fun Iter(mapp,[],rest,code,shape,_)=let
48          val (vF,code')=nextfn(mapp,args)          val (vF,code')=nextfn(mapp,args)
49          in (vF, code'@code)          in (vF, code'@code)
# Line 123  Line 110 
110          in (vD,A@B@D) end          in (vD,A@B@D) end
111      (*end case*))      (*end case*))
112    
   
113  fun SubcheckO(lhs,(vA,A),(vB,B))=(case((skeleton A),(skeleton B))  fun SubcheckO(lhs,(vA,A),(vB,B))=(case((skeleton A),(skeleton B))
114      of (0,0)=> mkReal 0      of (0,0)=> mkReal 0
115      |(0,_)=> let      |(0,_)=> let
# Line 136  Line 122 
122          in (vD, A@B@D) end          in (vD, A@B@D) end
123      (*end case*))      (*end case*))
124    
   
   
125  (* general expressions-removes zeros*)  (* general expressions-removes zeros*)
126  fun generalfn(dict,(body,origargs,info as (lhs,_,_,_)))=let  fun generalfn(dict,(body,origargs,info as (lhs,_,_,_)))=let
127      val mapp=ref dict      val mapp=ref dict
128    
   
   
129      fun gen body=let      fun gen body=let
130          fun AddcheckO ([],[],[])=let val (vA,A)=mkReal 0 in ([vA],A) end          fun AddcheckO ([],[],[])=let val (vA,A)=mkReal 0 in ([vA],A) end
131            | AddcheckO([],ids,code)=(ids,code)            | AddcheckO([],ids,code)=(ids,code)
# Line 253  Line 235 
235              in              in
236                  genKrn.evalField(!mapp,(body,(v,imgargnew),h,info))                  genKrn.evalField(!mapp,(body,(v,imgargnew),h,info))
237              end              end
   
238          | E.Sum(sumx, e)=>iterList(Sumcheck(sumx,e),addR)          | E.Sum(sumx, e)=>iterList(Sumcheck(sumx,e),addR)
239          (*end case*))          (*end case*))
240          end          end

Legend:
Removed from v.2844  
changed lines
  Added in v.2845

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