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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/low-to-tree/env.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/low-to-tree/env.sml

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

revision 3843, Tue May 10 15:10:58 2016 UTC revision 3848, Thu May 12 14:30:19 2016 UTC
# Line 33  Line 33 
33    (* set the definition of a variable, where the RHS is either a literal constant or a variable *)    (* set the definition of a variable, where the RHS is either a literal constant or a variable *)
34      val bindSimple : t * LowIR.var * TreeIR.exp -> unit      val bindSimple : t * LowIR.var * TreeIR.exp -> unit
35    
   (* record a local variable *)  
     val addLocal : t * TreeVar.t -> t  
   
36    (* at the end of a block, we need to assign any pending expressions to locals.  The    (* at the end of a block, we need to assign any pending expressions to locals.  The
37     * blkStms list and the resulting statement list are in reverse order.     * blkStms list and the resulting statement list are in reverse order.
38     *)     *)
39      val flushPending : t * TreeIR.stm list -> t * TreeIR.stm list      val flushPending : t * TreeIR.stm list -> t * TreeIR.stm list
40    
   (* close off a scope by turning the stms and locals into a TreeIR block *)  
     val endScope : t * TreeIR.stm list -> TreeIR.block  
   
41    end = struct    end = struct
42    
43      structure VT = LowIR.Var.Tbl      structure VT = LowIR.Var.Tbl
# Line 54  Line 48 
48    
49      datatype t = E of {      datatype t = E of {
50          tbl : (bool * binding) VT.hash_table,          tbl : (bool * binding) VT.hash_table,
51          layout : int -> TreeTypes.vec_layout,          layout : int -> TreeTypes.vec_layout
         locals : TreeVar.t list  
52        }        }
53    
54      fun decCount (LowIR.V{useCnt, ...}) = let      fun decCount (LowIR.V{useCnt, ...}) = let
# Line 66  Line 59 
59    
60      fun new layout = E{      fun new layout = E{
61              tbl = VT.mkTable (256, Fail "tbl"),              tbl = VT.mkTable (256, Fail "tbl"),
62              layout = layout,              layout = layout
             locals=[]  
63            }            }
64    
65      fun layoutVec (E{layout, ...}) wid = layout wid      fun layoutVec (E{layout, ...}) wid = layout wid
# Line 99  Line 91 
91    
92      fun bindSimple (E{tbl, ...}, x, b) = VT.insert tbl (x, (true, TREE b))      fun bindSimple (E{tbl, ...}, x, b) = VT.insert tbl (x, (true, TREE b))
93    
94      fun addLocal (E{tbl, layout, locals}, x) = E{tbl=tbl, layout=layout, locals=x::locals}      fun flushPending (E{tbl, layout}, blkStms) = let
95              fun doVar (x, (false, TREE e), stms) = let
     fun flushPending (E{tbl, layout, locals}, blkStms) = let  
           fun doVar (x, (false, TREE e), (locals, stms)) = let  
96                  val t = Util.newLocalVar x                  val t = Util.newLocalVar x
97                  in                  in
98                    VT.insert tbl (x, (true, TREE(TreeIR.E_Var t)));                    VT.insert tbl (x, (true, TREE(TreeIR.E_Var t)));
99                    (t::locals, TreeIR.S_Assign(t, e)::stms)                    TreeIR.S_Assign(t, e)::stms
100                  end                  end
101              | doVar (x, (false, VEC(layout, es)), (locals, stms)) = raise Fail "FIXME"              | doVar (x, (false, VEC(layout, es)), stms) = raise Fail "FIXME"
102              | doVar (_, _, acc) = acc              | doVar (_, _, acc) = acc
103            val (locals, stms) = VT.foldi doVar (locals, blkStms) tbl            val stms = VT.foldi doVar blkStms tbl
104            in            in
105              (E{tbl=tbl, layout=layout, locals=locals}, stms)              (E{tbl=tbl, layout=layout}, stms)
106            end            end
107    
     fun endScope (E{locals, ...}, stms) = TreeIR.Block{  
             locals = List.rev locals,  
             body = stms  
           }  
   
108    end    end

Legend:
Removed from v.3843  
changed lines
  Added in v.3848

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