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

SCM Repository

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

Diff of /branches/vis15/src/compiler/simplify/inliner.sml

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

revision 4033, Thu Jun 23 14:09:17 2016 UTC revision 4034, Thu Jun 23 14:40:24 2016 UTC
# Line 33  Line 33 
33            end            end
34    
35    (* beta reduce the application "lhs = f(args)" by creating a fresh copy of f's body    (* beta reduce the application "lhs = f(args)" by creating a fresh copy of f's body
36     * while mapping the parameters to arguments.     * while mapping the parameters to arguments.  The `isDcl` flag is true if `lhs'` is
37       * being declared at this point.
38     *)     *)
39      fun beta (lhs', S.Func{f, params, body}, args) = let      fun beta (isDcl, lhs', S.Func{f, params, body}, args) = let
40          (* if the fucntion body has a deep return, then we need to predeclare the lhs.  Futhermore,          (* if the fucntion body has a deep return, then we need to predeclare the lhs.  Futhermore,
41           * if the lhs is a global or state variable and the body has a deep return, then we need to           * if the lhs is a global or state variable and the body has a deep return, then we need to
42           * use a local temporary to hold the result.           * use a local temporary to hold the result.
# Line 43  Line 44 
44            val (lhs, preCode, postCode) = let            val (lhs, preCode, postCode) = let
45                  fun withTmp () = let                  fun withTmp () = let
46                        val tmp = V.new(V.nameOf lhs', V.LocalVar, V.typeOf lhs')                        val tmp = V.new(V.nameOf lhs', V.LocalVar, V.typeOf lhs')
47                          val tmpDcl = [S.S_Var(tmp, NONE)]
48                        in                        in
49                          (tmp, [S.S_Var(lhs', NONE)], [S.S_Assign(lhs', S.E_Var tmp)])                          if isDcl
50                              then (tmp, tmpDcl, [S.S_Var(lhs', SOME(S.E_Var tmp))])
51                              else (tmp, tmpDcl, [S.S_Assign(lhs', S.E_Var tmp)])
52                        end                        end
53                    fun withLHS () = if isDcl
54                          then (lhs', [S.S_Var(lhs', NONE)], [])
55                          else (lhs', [], [])
56                  in                  in
57                    if hasDeepReturn body                    if hasDeepReturn body
58                      then (case V.kindOf lhs'                      then (case V.kindOf lhs'
59                         of V.GlobalVar => withTmp ()                         of V.GlobalVar => withTmp ()
60                          | V.StrandStateVar => withTmp ()                          | V.StrandStateVar => withTmp ()
61                          | V.StrandOutputVar => withTmp ()                          | V.StrandOutputVar => withTmp ()
62                          | _ => (lhs', [S.S_Var(lhs', NONE)], [])                          | _ => withLHS ()
63                        (* end case *))                        (* end case *))
64                      else (lhs', [], [])                      else withLHS ()
65                  end                  end
66            fun rename env x = (case V.Map.find(env, x)            fun rename env x = (case V.Map.find(env, x)
67                   of SOME x' => x'                   of SOME x' => x'
# Line 125  Line 132 
132            and expandStm (stm, stms') = (case stm            and expandStm (stm, stms') = (case stm
133                   of S.S_Var(x, SOME(S.E_Apply(f, xs, _))) => (case findFunc f                   of S.S_Var(x, SOME(S.E_Apply(f, xs, _))) => (case findFunc f
134                         of NONE => stm :: stms'                         of NONE => stm :: stms'
135                          | SOME func => beta(x, func, xs) @ stms'                          | SOME func => beta(true, x, func, xs) @ stms'
136                         (* end case *))                         (* end case *))
137                    | S.S_Assign(x, S.E_Apply(f, xs, _)) => (case findFunc f                    | S.S_Assign(x, S.E_Apply(f, xs, _)) => (case findFunc f
138                         of NONE => stm :: stms'                         of NONE => stm :: stms'
139                          | SOME func => beta(x, func, xs) @ stms'                          | SOME func => beta(false, x, func, xs) @ stms'
140                        (* end case *))                        (* end case *))
141                    | S.S_IfThenElse(x, b1, b2) =>                    | S.S_IfThenElse(x, b1, b2) =>
142                        S.S_IfThenElse(x, expandBlk b1, expandBlk b2) :: stms'                        S.S_IfThenElse(x, expandBlk b1, expandBlk b2) :: stms'

Legend:
Removed from v.4033  
changed lines
  Added in v.4034

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