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

SCM Repository

[diderot] Diff of /trunk/src/compiler/codegen/codegen-fn.sml
ViewVC logotype

Diff of /trunk/src/compiler/codegen/codegen-fn.sml

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

revision 1639, Wed Nov 16 01:48:07 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 23  Line 23 
23    
24      structure IL = TreeIL      structure IL = TreeIL
25    
26      structure LowToTree = LowToTreeFn(T)      val targetSupportsPrinting = ref T.supportsPrinting
27    
28        local
29          structure TargetInfo =
30            struct
31              fun supportsPrinting () = !targetSupportsPrinting
32              val inlineCons = T.inlineCons
33              val inlineMatrixExp = T.inlineMatrixExp
34            end
35        in
36        structure LowToTree = LowToTreeFn(TargetInfo)
37        end
38    
39      fun trMethod (strand, stateVars, env) = let      fun trMethod (strand, stateVars, env) = let
           val varyingStateVars = List.mapPartial  
                 (fn (IL.SV{varying = true, var, ...}) => SOME var | _ => NONE)  
                   stateVars  
           val env = T.Env.scopeMethod (env, varyingStateVars)  
40            fun tr (IL.Method{name, body}) = let            fun tr (IL.Method{name, body}) = let
41                    val env = T.Env.scopeMethod (env, name)
42                  val body = T.Tr.block (env, body)                  val body = T.Tr.block (env, body)
43                  in                  in
44                    T.Strand.method (strand, name, body)                    T.Strand.method (strand, name, body)
# Line 40  Line 48 
48            end            end
49    
50      fun trStrand (prog, env) (IL.Strand{name, params, state, stateInit, methods}) = let      fun trStrand (prog, env) (IL.Strand{name, params, state, stateInit, methods}) = let
51            val strand = T.Strand.define(prog, name)            val strand = T.Strand.define(prog, name, state)
52            val env = T.Env.scopeStrand (env, List.map (fn (IL.SV{var, ...}) => var) state)            val env = T.Env.scopeStrand env
         (* the output state variable *)  
           val outputVar = ref NONE  
         (* map the state variables to target state variables and extend the environment *)  
           val env = let  
                 fun cvtSVar (IL.SV{output, var=x, ...}, env) = let  
                       val x' = T.Var.state(strand, x)  
                       in  
                         case (output, !outputVar)  
                          of (true, NONE) => outputVar := SOME(IL.Var.ty x, x')  
                           | (false, _) => ()  
                           | _ => raise Fail("multiple outputs in " ^ Atom.toString name)  
                         (* end case *);  
                         T.Env.bind(env, x, x')  
                       end  
                 in  
                 (* note that we fold right-to-left to get the order of state variables in the  
                  * target strand in the right order.  
                  *)  
                   List.foldr cvtSVar env state  
                 end  
53          (* define the parameters and add them to the environment *)          (* define the parameters and add them to the environment *)
54            val params' = List.map T.Var.param params            val params' = List.map T.Var.param params
55            val env = ListPair.foldlEq (fn (x, y, env) => T.Env.bind(env, x, y)) env (params, params')            val env = ListPair.foldlEq (fn (x, y, env) => T.Env.bind(env, x, y)) env (params, params')
56            in            in
57              T.Strand.init (strand, params', T.Tr.block (env, stateInit));              T.Strand.init (strand, params', T.Tr.block (env, stateInit));
             case !outputVar  
              of NONE => raise Fail("no output specified for strand " ^ Atom.toString name)  
               | SOME(ty, x) => T.Strand.output (strand, ty, x)  
             (* end case *);  
58              List.app (trMethod (strand, state, env)) methods              List.app (trMethod (strand, state, env)) methods
59            end            end
60    
# Line 99  Line 83 
83            end            end
84    
85      fun generate {basename, double, parallel, debug, prog=srcProg} = let      fun generate {basename, double, parallel, debug, prog=srcProg} = let
86              val _ = if parallel then targetSupportsPrinting := false else ()
87            val treeProg as TreeIL.Program{props, globals, inputInit, globalInit, strands, initially} =            val treeProg as TreeIL.Program{props, globals, inputInit, globalInit, strands, initially} =
88                  PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate srcProg                  PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate srcProg
89  val _ = (  val _ = (

Legend:
Removed from v.1639  
changed lines
  Added in v.1640

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