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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3624 - (download) (annotate)
Fri Jan 29 17:49:01 2016 UTC (3 years, 11 months ago) by jhr
File size: 2507 byte(s)
adding header comments in prep for merge
(* iter.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) 
 *
 * COPYRIGHT (c)  2015 The University of Chicago
 * All rights reserved.
 *) 

structure Iter =  struct
    local

    structure H = Helper
    structure IMap = IntRedBlackMap
    in

    fun mkCons e = H.assgnCons e
    fun insert  (k, v) d =  IMap.insert (d, k, v)
    val empty = IMap.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 (avail, origIndex, index, nextfn, args) = 
        let
        val index' = List.map (fn (e) => (e-1) )  index
        fun get (avail, n, m, mapp) = nextfn (avail, insert (n, m)  mapp, args)
        fun Iter(avail, mapp, x, y, rest, shape, n, str)= case (x,y)
            of ([],[]) => nextfn (avail, mapp, args)
            | ([i],[]) => let
                val (avail, vF) =  get (avail, n, i, mapp)
                in
                    mkCons (avail, str, shape, rest@[vF])
                end
            | ( i::es, []) => let
                val (avail, vE) = get (avail, n, i, mapp)
                in
                    Iter (avail, mapp, es, [], rest@[vE], shape, n, str)
                end
            | ([], [b]) =>
                Iter (avail, mapp, List.tabulate (b+1, fn e => e), [], rest, shape, n, str)
            | ([], b::c) => let
                val s::shape=shape
                val n' = n+1
                fun S (avail, [i], rest) = let
                    val mapp = insert (n, i)  mapp
                    val str = str^ (Int.toString i)
                    val (avail, v') = Iter (avail, mapp, [], c, [], shape, n', str)
                    in
                        mkCons (avail, "", s::shape, rest@[v'])
                    end
                | S (avail, i::es,rest) =  let
                    val mapp = insert (n, i)  mapp
                    val str = str^ (Int.toString i)
                    val (avail, v') = Iter (avail, mapp, [], c, [],shape, n', str)
                    in
                        S (avail, es, rest@[v'])
                    end
                in
                    S (avail, List.tabulate (b+1, fn e => e), [])
                end
            | _ => raise Fail"index' is larger than origIndex"
        val n = (List.length (index)) -1
        in
            Iter (avail, empty, [], index', [], origIndex, 0, "")
        end


end (* local *) 

end

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