79 |
in |
in |
80 |
fun newEnv () = E{tbl = VT.mkTable (512, Fail "tbl"), locals=[]} |
fun newEnv () = E{tbl = VT.mkTable (512, Fail "tbl"), locals=[]} |
81 |
|
|
|
fun newScope (E{tbl, ...}) = E{tbl=tbl, locals=[]} |
|
|
|
|
82 |
(* use a variable. If it is a pending expression, we remove it from the table *) |
(* use a variable. If it is a pending expression, we remove it from the table *) |
83 |
fun useVar (E{tbl, ...}) x = (case VT.find tbl x |
fun useVar (E{tbl, ...}) x = (case VT.find tbl x |
84 |
of SOME(GLOB x') => T.E_Var x' |
of SOME(GLOB x') => T.E_Var x' |
132 |
(* end case *)) |
(* end case *)) |
133 |
|
|
134 |
(* set the definition of a variable, where the RHS is either a literal constant or a variable *) |
(* set the definition of a variable, where the RHS is either a literal constant or a variable *) |
135 |
fun setDef (env as E{tbl, ...}, lhs, rhs) = ( |
fun bindSimple (env as E{tbl, ...}, lhs, rhs) = ( |
136 |
case peekGlobal (env, lhs) |
case peekGlobal (env, lhs) |
137 |
of SOME x => (env, [T.S_Assign(x, rhs)]) |
of SOME x => (env, [T.S_Assign(x, rhs)]) |
138 |
| NONE => (VT.insert tbl (lhs, DEF rhs); (env, [])) |
| NONE => (VT.insert tbl (lhs, DEF rhs); (env, [])) |
214 |
end |
end |
215 |
in |
in |
216 |
case rhs |
case rhs |
217 |
of IL.VAR x => setDef (env, lhs, useVar env x) |
of IL.VAR x => bindSimple (env, lhs, useVar env x) |
218 |
| IL.LIT lit => setDef (env, lhs, T.E_Lit lit) |
| IL.LIT lit => bindSimple (env, lhs, T.E_Lit lit) |
219 |
| IL.OP(Op.LoadImage info, [a]) => let |
| IL.OP(Op.LoadImage info, [a]) => let |
220 |
val (env, t) = doLHS() |
val (env, t) = doLHS() |
221 |
in |
in |