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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/simplify/simplify.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/simplify/simplify.sml

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

revision 185, Wed Jul 28 17:11:09 2010 UTC revision 240, Fri Aug 6 04:59:16 2010 UTC
# Line 22  Line 22 
22      end      end
23    
24    (* make a block out of a list of statements that are in reverse order *)    (* make a block out of a list of statements that are in reverse order *)
25      fun mkBlock stms = let      fun mkBlock stms = S.Block(List.rev stms)
           fun flatten [] = []  
             | flatten (S.S_Block stms :: r) = stms @ flatten r  
             | flatten (stm :: r) = stm :: flatten r  
           in  
             S.S_Block(flatten (List.rev stms))  
           end  
26    
27      fun transform (AST.Program dcls) = let      fun simplifyProgram (AST.Program dcls) = let
28            val globals = ref []            val globals = ref []
29            val globalInit = ref []            val globalInit = ref []
30            val actors = ref []            val actors = ref []
31            fun simplifyDecl dcl = (case dcl            fun simplifyDecl dcl = (case dcl
32                   of AST.D_Input(x, NONE) => let                   of AST.D_Input(x, NONE) => let
33                        val t = newTemp Ty.T_String                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, NONE)
                       val stm = S.S_Assign(t, S.E_Lit(Literal.String(Var.nameOf x)))  
                       val ty = Var.monoTypeOf x  
                       val e' = S.E_Apply(BasisVars.input,  
                               [Ty.TYPE(MetaVar.newFromType ty)], [t], ty)  
34                        in                        in
35                          globals := x :: !globals;                          globals := x :: !globals;
36                          globalInit := S.S_Assign(x, e') :: stm :: !globalInit                          globalInit := S.S_Assign(x, e') :: !globalInit
37                        end                        end
38                    | AST.D_Input(x, SOME e) => let                    | AST.D_Input(x, SOME e) => let
39                        val (stms, x') = simplifyExpToVar (e, [])                        val (stms, x') = simplifyExpToVar (e, [])
40                        val t = newTemp Ty.T_String                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, SOME x')
                       val stm = S.S_Assign(t, S.E_Lit(Literal.String(Var.nameOf x)))  
                       val ty = Var.monoTypeOf x  
                       val e' = S.E_Apply(BasisVars.optInput,  
                               [Ty.TYPE(MetaVar.newFromType ty)], [t, x'], ty)  
41                        in                        in
42                          globals := x :: !globals;                          globals := x :: !globals;
43                          globalInit := S.S_Assign(x, e') :: stm :: (stms @ !globalInit)                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)
44                        end                        end
45                    | AST.D_Var(AST.VD_Decl(x, e)) => let                    | AST.D_Var(AST.VD_Decl(x, e)) => let
46                        val (stms, e') = simplifyExp (e, [])                        val (stms, e') = simplifyExp (e, [])
# Line 93  Line 79 
79            end            end
80    
81      and simplifyMethod (AST.M_Method(name, body)) =      and simplifyMethod (AST.M_Method(name, body)) =
82            S.M_Method(name, simplifyBlock body)            S.Method(name, simplifyBlock body)
83    
84    (* simplify a statement into a single statement (i.e., a block if it expands into more    (* simplify a statement into a single statement (i.e., a block if it expands into more
85     * than one new statement.     * than one new statement.
# Line 135  Line 121 
121    
122      and simplifyExp (exp, stms) = (      and simplifyExp (exp, stms) = (
123            case exp            case exp
124             of AST.E_Var x => (stms, S.E_Var x)             of AST.E_Var x => (case Var.kindOf x
125                     of Var.BasisVar => let
126                          val ty = Var.monoTypeOf x
127                          val x' = newTemp ty
128                          val stm = S.S_Assign(x', S.E_Apply(x, [], [], ty))
129                          in
130                            (stm::stms, S.E_Var x')
131                          end
132                      | _ => (stms, S.E_Var x)
133                    (* end case *))
134              | AST.E_Lit lit => (stms, S.E_Lit lit)              | AST.E_Lit lit => (stms, S.E_Lit lit)
135              | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"              | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"
136              | AST.E_Apply(f, tyArgs, args, ty) => let              | AST.E_Apply(f, tyArgs, args, ty) => let
# Line 188  Line 183 
183              f (exps, [], stms)              f (exps, [], stms)
184            end            end
185    
186        fun transform ast = let
187              val simple = simplifyProgram ast
188              val _ = SimplePP.output (Log.logFile(), simple)       (* DEBUG *)
189              val simple = Lift.transform simple
190              in
191                simple
192              end
193    
194    end    end

Legend:
Removed from v.185  
changed lines
  Added in v.240

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