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

SCM Repository

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

View of /branches/charisee/src/compiler/mid-to-low/iter.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2924 - (download) (annotate)
Tue Mar 3 21:41:05 2015 UTC (4 years, 4 months ago) by jhr
File size: 2175 byte(s)
  use IntRedBlackMap for index maps
(* iter.sml
 *
 * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Iter = struct
    local
    structure H=Helper

    in

    fun iTos e=H.iTos e 
    fun mkCons e=H.assgnCons e
    fun insert e=H.insert e

    val empty = H.empty

    (*prodIter:int list*int list* function* function args-> Var*LowIL.Assgn
    * Iters over the shape of the EIN operator
    * creates mapp
    * binds each outer index
    *)
    fun prodIter(origIndex,index,nextfn,args)=(let
        val index'=List.map (fn (e)=>(e-1)) index
        fun get(n,m,mapp)=let
            val mapp =insert(n, m) mapp
            in
                nextfn(mapp,args)
            end
        fun Iter(mapp,[],rest,code,shape,_,_)=let
            val (vF,code')=nextfn(mapp,args)
            in (vF, code'@code)
            end
        | Iter(mapp,[0], rest, code,shape,n,str)=let
            val (vF,code')= get(n,0,mapp)
            val(vE,E)=mkCons(str,shape,[vF]@rest)
            in
                (vE, code'@code@E)
            end
        | Iter(mapp,[c],rest,code,shape,n,str)=let
            val (vE,E)=get(n,c,mapp)
            in
                Iter(mapp, [c-1], [vE]@rest,E@code,shape,n,str)
            end
        | Iter(mapp,b::c,rest,ccode,s::shape,n,str0)=let
            val n'=n+1
            fun S(0, rest,code)=let
                val mapp =insert(n, 0) mapp
                val str=str0^("0")
                val (v',code')=Iter(mapp,c,[],[],shape,n',str)
                val(vA,A)=mkCons("",s::shape,[v']@rest)
                in
                    (vA, code'@code@A)
                end
            | S(i, rest, code)= let
                val mapp =insert(n, i) mapp
                val str=str0^(iTos i)
                val (v',code')=Iter(mapp,c,[],[],shape,n',str)
                in
                    S(i-1,[v']@rest,code'@code)
                end
            val (vA,code')=S(b, [],[])
            in
                (vA,code'@ccode)
            end
        | Iter _=raise Fail"index' is larger than origIndex"
        in
            Iter(empty,index',[],[],origIndex,0,"")
        end)
end (* local *)

end

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