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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/codegen/codegen-fn.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/codegen/codegen-fn.sml

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

revision 535, Tue Feb 15 17:17:20 2011 UTC revision 544, Wed Feb 16 23:14:14 2011 UTC
# Line 31  Line 31 
31              | Ty.ImageTy => T.boolTy (* FIXME *)              | Ty.ImageTy => T.boolTy (* FIXME *)
32            (* end case *))            (* end case *))
33    
34        fun addBindings (env, xs, ys) =
35              ListPair.foldlEq (fn (x, y, env) => V.Map.insert(env, x, y)) env (xs, ys)
36    
37      fun lookup (env, x) = (case V.Map.find (env, x)      fun lookup (env, x) = (case V.Map.find (env, x)
38             of SOME x' => x'             of SOME x' => x'
39              | NONE => raise Fail(concat["lookup(_, ", V.name x, ")"])              | NONE => raise Fail(concat["lookup(_, ", V.name x, ")"])
# Line 102  Line 105 
105  (* FIXME: special case for when x is a strand-state variable *)  (* FIXME: special case for when x is a strand-state variable *)
106              | IL.S_Assign(x, exp) => (case V.kind x              | IL.S_Assign(x, exp) => (case V.kind x
107                   of IL.VK_Global => [T.Stmt.assign(lookup(env, x), trExp(env, exp))]                   of IL.VK_Global => [T.Stmt.assign(lookup(env, x), trExp(env, exp))]
108                    | IL.VK_State strand => raise Fail "FIXME: state var"                    | IL.VK_State strand =>
109                          [T.Stmt.assignState(lookup(env, x), trExp(env, exp))]
110                    | IL.VK_Local => [T.Stmt.assign(lookup(env, x), trExp(env, exp))]                    | IL.VK_Local => [T.Stmt.assign(lookup(env, x), trExp(env, exp))]
111                  (* end case *))                  (* end case *))
112              | IL.S_Cons(lhs, args) =>              | IL.S_Cons(lhs, args) =>
# Line 121  Line 125 
125              | IL.S_Stabilize => [T.Stmt.stabilize()]              | IL.S_Stabilize => [T.Stmt.stabilize()]
126            (* end case *))            (* end case *))
127    
128      and trBlock (env, IL.Block{locals, body}) = (      and trBlock (env, IL.Block{locals, body}) = let
129  (* what about the locals?? *)            val env = List.foldl
130            T.Stmt.block(List.foldr (fn (stm, stms) => trStmt(env, stm)@stms) [] body))                  (fn (x, env) => V.Map.insert(env, x, T.Var.var(cvtTy(V.ty x), V.name x)))
131                      env locals
132              in
133                T.Stmt.block(List.foldr (fn (stm, stms) => trStmt(env, stm)@stms) [] body)
134              end
135    
136        fun trStrand (prog, env) (IL.Strand{name, params, state, stateInit, methods}) = let
137              val strand = T.Strand.define(prog, Atom.toString name)
138              val state' =
139                    List.map (fn x => T.Var.state(strand, cvtTy(V.ty x), V.name x)) state
140              val env = addBindings (env, state, state')
141            (* define the parameters and add them to the environment *)
142              val params' = List.map (fn x => T.Var.param(cvtTy(V.ty x), V.name x)) params
143              val env = addBindings (env, params, params')
144              in
145                T.Strand.init (strand, params', trBlock (env, stateInit));
146                ()
147              end
148    
149      fun generate (fileStem, srcProg) = let      fun generate (fileStem, srcProg) = let
150            val treeProg as TreeIL.Program{globals, globalInit, strands} = LowToTree.translate srcProg            val treeProg as TreeIL.Program{globals, globalInit, strands} = LowToTree.translate srcProg
# Line 141  Line 162 
162            in            in
163            (* global initialization *)            (* global initialization *)
164              T.globalInit (prog, trBlock (env, globalInit));              T.globalInit (prog, trBlock (env, globalInit));
165              (* translate strands *)
166                List.app (trStrand (prog, env)) strands;
167            (* output the program *)            (* output the program *)
168              T.generate (fileStem, prog)              T.generate (fileStem, prog)
169            end            end

Legend:
Removed from v.535  
changed lines
  Added in v.544

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