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 3321, Sun Oct 18 10:35:17 2015 UTC revision 3322, Mon Oct 19 19:39:09 2015 UTC
# Line 343  Line 343 
343                  end                  end
344            (* end case *))            (* end case *))
345    
346      and simplifyExp (env, exp, stms) = (      and simplifyExp (env, exp, stms) = let
347            case exp            fun doApply (f, tyArgs, args, ty) = let
            of AST.E_Var x => (case Var.kindOf x  
                  of Var.BasisVar => let  
                       val ty = cvtTy(Var.monoTypeOf x)  
                       val x' = newTemp ty  
                       val stm = S.S_Assign(x', S.E_Prim(x, [], [], ty))  
                       in  
                         (stm::stms, S.E_Var x')  
                       end  
                   | _ => (stms, S.E_Var(lookupVar(env, x)))  
                 (* end case *))  
             | AST.E_Lit lit => (stms, S.E_Lit lit)  
             | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"  
             | AST.E_Apply(f, tyArgs, args, ty) => let  
348                  val (stms, xs) = simplifyExpsToVars (env, args, stms)                  val (stms, xs) = simplifyExpsToVars (env, args, stms)
349                  in                  in
350                    case Var.kindOf f                    case Var.kindOf f
# Line 374  Line 361 
361                      | _ => raise Fail "bogus application"                      | _ => raise Fail "bogus application"
362                    (* end case *)                    (* end case *)
363                  end                  end
364              in
365                case exp
366                 of AST.E_Var x => (case Var.kindOf x
367                       of Var.BasisVar => let
368                            val ty = cvtTy(Var.monoTypeOf x)
369                            val x' = newTemp ty
370                            val stm = S.S_Assign(x', S.E_Prim(x, [], [], ty))
371                            in
372                              (stm::stms, S.E_Var x')
373                            end
374                        | _ => (stms, S.E_Var(lookupVar(env, x)))
375                      (* end case *))
376                  | AST.E_Lit lit => (stms, S.E_Lit lit)
377                  | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"
378                  | AST.E_Apply(rator, tyArgs, args as [AST.E_Lit(Literal.Int n)], ty) =>
379                    (* constant-fold negation of integer literals *)
380                      if Var.same(BasisVars.neg_i, rator)
381                        then (stms, S.E_Lit(Literal.Int(~n)))
382                        else doApply (rator, tyArgs, args, ty)
383                  | AST.E_Apply(rator, tyArgs, args as [AST.E_Lit(Literal.Float f)], ty as Types.T_Tensor sh) =>
384                    (* constant-fold negation of real literals *)
385                      if Var.same(BasisVars.neg_i, rator) andalso List.null(TU.monoShape sh)
386                        then (stms, S.E_Lit(Literal.Float(FloatLit.negate f)))
387                        else doApply (rator, tyArgs, args, ty)
388                  | AST.E_Apply(f, tyArgs, args, ty) => doApply (f, tyArgs, args, ty)
389              | AST.E_Cons es => let              | AST.E_Cons es => let
390                  val (stms, xs) = simplifyExpsToVars (env, es, stms)                  val (stms, xs) = simplifyExpsToVars (env, es, stms)
391                  in                  in
# Line 430  Line 442 
442                  in                  in
443                    (S.S_Assign(result, rhs)::stms, S.E_Var result)                    (S.S_Assign(result, rhs)::stms, S.E_Var result)
444                  end                  end
445            (* end case *))              (* end case *)
446              end
447    
448      and simplifyExpToVar (env, exp, stms) = let      and simplifyExpToVar (env, exp, stms) = let
449            val (stms, e) = simplifyExp (env, exp, stms)            val (stms, e) = simplifyExp (env, exp, stms)

Legend:
Removed from v.3321  
changed lines
  Added in v.3322

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