SCM Repository
[diderot] Diff of /trunk/src/compiler/simplify/lift.sml
Diff of /trunk/src/compiler/simplify/lift.sml
Parent Directory
|
Revision Log
|
Patch
114 |
staticBlock |
staticBlock |
115 |
end |
end |
116 |
|
|
117 |
fun transform (prog as S.Program{globals, staticInit, globalInit, actors}) = let |
(* given values for the static variables; reduce the static initialization code *) |
118 |
|
fun reduce (env, blk) = let |
119 |
|
fun doBlock (S.Block stms) = |
120 |
|
List.foldr (fn (stm, stms) => doStmt stm @ stms) [] stms |
121 |
|
and doStmt stm = (case stm |
122 |
|
of S.S_Assign(x, e) => (case Var.Map.find(env, x) |
123 |
|
of SOME v => let |
124 |
|
val rhs = (case v |
125 |
|
of (Eval.BV b) => S.E_Lit(Literal.Bool b) |
126 |
|
| (Eval.SV s) => S.E_Lit(Literal.String s) |
127 |
|
| (Eval.IV i) => S.E_Lit(Literal.Int i) |
128 |
|
| (Eval.TV _) => e |
129 |
|
| (Eval.FV fld) => S.E_Field fld |
130 |
|
| (Eval.Img info) => S.E_LoadImage info |
131 |
|
| (Eval.KV h) => e |
132 |
|
(* end case *)) |
133 |
|
in |
134 |
|
[S.S_Assign(x, rhs)] |
135 |
|
end |
136 |
|
| NONE => [stm] |
137 |
|
(* end case *)) |
138 |
|
| S.S_IfThenElse(x, b1, b2) => (case Var.Map.find(env, x) |
139 |
|
of SOME(Eval.BV b) => if b then doBlock b1 else doBlock b2 |
140 |
|
| NONE => [stm] |
141 |
|
(* end case *)) |
142 |
|
| _ => [stm] |
143 |
|
(* end case *)) |
144 |
|
in |
145 |
|
S.Block(doBlock blk) |
146 |
|
end |
147 |
|
|
148 |
|
fun transform (prog as S.Program{globals, globalInit, actors}) = let |
149 |
val staticInit = liftLoads globalInit |
val staticInit = liftLoads globalInit |
150 |
|
val staticEnv = Eval.evalStatics staticInit |
151 |
|
val globalInit = reduce (staticEnv, globalInit) |
152 |
in |
in |
153 |
S.Program{ |
S.Program{ |
154 |
globals = globals, |
globals = globals, |
|
staticInit = staticInit, |
|
155 |
globalInit = globalInit, |
globalInit = globalInit, |
156 |
actors = actors |
actors = actors |
157 |
} |
} |
|
Legend:
Removed from v.239 |
|
changed lines |
|
Added in v.240 |
|
|