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

SCM Repository

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

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

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

revision 2489, Mon Oct 21 19:43:32 2013 UTC revision 2490, Mon Oct 21 21:17:25 2013 UTC
# Line 13  Line 13 
13    end = struct    end = struct
14    
15      structure S = Simple      structure S = Simple
16      structure V = Var      structure V = SimpleVar
17    
18    (* 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
19     * while mapping the parameters to arguments.     * while mapping the parameters to arguments.
# Line 21  Line 21 
21      fun beta (lhs, S.Func{f, params, body}, args) = let      fun beta (lhs, S.Func{f, params, body}, args) = let
22            fun rename env x = (case V.Map.find(env, x)            fun rename env x = (case V.Map.find(env, x)
23                   of SOME x' => x'                   of SOME x' => x'
24                    | NONE => if Var.isGlobal x                    | NONE => if SimpleVar.isGlobal x
25                        then x                        then x
26                        else raise Fail("unknown variable " ^ V.uniqueNameOf x)                        else raise Fail("unknown variable " ^ V.uniqueNameOf x)
27                  (* end case *))                  (* end case *))
# Line 61  Line 61 
61                   of S.E_Var x => S.E_Var(rename env x)                   of S.E_Var x => S.E_Var(rename env x)
62                    | S.E_Lit _ => exp                    | S.E_Lit _ => exp
63                    | S.E_Tuple xs => S.E_Tuple(List.map (rename env) xs)                    | S.E_Tuple xs => S.E_Tuple(List.map (rename env) xs)
64                    | S.E_Apply(f, tys, xs, ty) =>                    | S.E_Apply(f, xs, ty) => S.E_Apply(f, List.map (rename env) xs, ty)
65                        S.E_Apply(f, tys, List.map (rename env) xs, ty)                    | S.E_Prim(f, tys, xs, ty) =>
66                          S.E_Prim(f, tys, List.map (rename env) xs, ty)
67                    | S.E_Cons xs => S.E_Cons(List.map (rename env) xs)                    | S.E_Cons xs => S.E_Cons(List.map (rename env) xs)
68                    | S.E_Slice(x, xs, ty) =>                    | S.E_Slice(x, xs, ty) =>
69                        S.E_Slice(rename env x, List.map (Option.map (rename env)) xs, ty)                        S.E_Slice(rename env x, List.map (Option.map (rename env)) xs, ty)
70                    | S.E_Coerce{srcTy, dstTy, x} =>                    | S.E_Coerce{srcTy, dstTy, x} =>
71                        S.E_Coerce{srcTy=srcTy, dstTy=dstTy, x=rename env x}                        S.E_Coerce{srcTy=srcTy, dstTy=dstTy, x=rename env x}
72                      | S.E_Input(_, _, _, NONE) => exp
73                      | S.E_Input(ty, name, desc, SOME x) =>
74                          S.E_Input(ty, name, desc, SOME(rename env x))
75                    | S.E_LoadImage _ => exp                    | S.E_LoadImage _ => exp
76                  (* end case *))                  (* end case *))
77          (* build the initial environment by mapping parameters to arguments *)          (* build the initial environment by mapping parameters to arguments *)
# Line 84  Line 88 
88            fun expandBlk (S.Block stms) =            fun expandBlk (S.Block stms) =
89                  S.Block(List.foldr expandStm [] stms)                  S.Block(List.foldr expandStm [] stms)
90            and expandStm (stm, stms') = (case stm            and expandStm (stm, stms') = (case stm
91                   of S.S_Assign(x, S.E_Apply(f, [], xs, _)) => (case findFunc f                   of S.S_Assign(x, S.E_Apply(f, xs, _)) => (case findFunc f
92                         of NONE => stm :: stms'                         of NONE => stm :: stms'
93                          | SOME func => let                          | SOME func => let
94                              val S.Block stms = beta(x, func, xs)                              val S.Block stms = beta(x, func, xs)

Legend:
Removed from v.2489  
changed lines
  Added in v.2490

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