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

SCM Repository

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

Diff of /trunk/src/compiler/simplify/inliner.sml

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

revision 2488, Mon Oct 21 19:20:12 2013 UTC revision 2489, Mon Oct 21 19:43:32 2013 UTC
# Line 13  Line 13 
13    end = struct    end = struct
14    
15      structure S = Simple      structure S = Simple
16      structure V = SimpleVar      structure V = Var
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 SimpleVar.isGlobal x                    | NONE => if Var.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, xs, ty) => S.E_Apply(f, List.map (rename env) xs, ty)                    | S.E_Apply(f, tys, xs, ty) =>
65                    | S.E_Prim(f, tys, xs, ty) =>                        S.E_Apply(f, tys, List.map (rename env) xs, ty)
                       S.E_Prim(f, tys, List.map (rename env) xs, ty)  
66                    | S.E_Cons xs => S.E_Cons(List.map (rename env) xs)                    | S.E_Cons xs => S.E_Cons(List.map (rename env) xs)
67                    | S.E_Slice(x, xs, ty) =>                    | S.E_Slice(x, xs, ty) =>
68                        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)
69                    | S.E_Coerce{srcTy, dstTy, x} =>                    | S.E_Coerce{srcTy, dstTy, x} =>
70                        S.E_Coerce{srcTy=srcTy, dstTy=dstTy, x=rename env x}                        S.E_Coerce{srcTy=srcTy, dstTy=dstTy, x=rename env x}
                   | S.E_Input(_, _, _, NONE) => exp  
                   | S.E_Input(ty, name, desc, SOME x) =>  
                       S.E_Input(ty, name, desc, SOME(rename env x))  
71                    | S.E_LoadImage _ => exp                    | S.E_LoadImage _ => exp
72                  (* end case *))                  (* end case *))
73          (* build the initial environment by mapping parameters to arguments *)          (* build the initial environment by mapping parameters to arguments *)
# Line 88  Line 84 
84            fun expandBlk (S.Block stms) =            fun expandBlk (S.Block stms) =
85                  S.Block(List.foldr expandStm [] stms)                  S.Block(List.foldr expandStm [] stms)
86            and expandStm (stm, stms') = (case stm            and expandStm (stm, stms') = (case stm
87                   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
88                         of NONE => stm :: stms'                         of NONE => stm :: stms'
89                          | SOME func => let                          | SOME func => let
90                              val S.Block stms = beta(x, func, xs)                              val S.Block stms = beta(x, func, xs)

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

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