3 |
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) |
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) |
4 |
* All rights reserved. |
* All rights reserved. |
5 |
* |
* |
6 |
* Translate AST code into the IL representation. |
* Translate Simple-AST code into the IL representation. |
7 |
*) |
*) |
8 |
|
|
9 |
structure Translate : sig |
structure Translate : sig |
10 |
|
|
11 |
val translate : AST.program -> ?? |
val translate : Simple.program -> HighIL.program |
12 |
|
|
13 |
end = struct |
end = struct |
14 |
|
|
15 |
|
structure S = Simple |
16 |
structure VMap = Var.Map |
structure VMap = Var.Map |
17 |
structure IL = HighIL |
structure IL = HighIL |
18 |
|
|
19 |
|
fun lookup env x = (case VMap.find x |
20 |
|
of SOME x' => x' |
21 |
|
| NONE => raise Fail(concat[ |
22 |
|
"no binding for ", Var.toString x, " in environment" |
23 |
|
]) |
24 |
|
(* end case *)) |
25 |
|
|
26 |
(* expression translation *) |
(* expression translation *) |
27 |
fun cvtExpr (env, exp, kont) = let |
fun cvtExpr (env, exp) = (case exp |
28 |
fun cvt e = (case e |
of S.E_Var x => IL.VAR(lookup env x) |
29 |
of AST.E_Var(x, tyArgs, ty) => |
| S.E_Lit lit => IL.LIT lit |
30 |
| AST.E_Lit lit => |
| S.E_Tuple xs => raise Fail "E_Tuple not implemeted" |
31 |
| AST.E_Tuple es => |
| S.E_Apply(f, tyArgs, args, ty) => |
32 |
| AST.E_Apply(f, tyArgs, args, ty) => |
| S.E_Cons args => IL.CONS(List.map (lookup env) args) |
|
| AST.E_Cons of expr list |
|
|
| AST.E_Cond(e1, e2, e3) => |
|
33 |
(* end case *)) |
(* end case *)) |
|
in |
|
|
end |
|
34 |
|
|
35 |
and cvtStmt (env, stm) = (case stm |
and cvtStmt (env, stm) = (case stm |
36 |
of AST.S_Block of stmt list |
of S.S_Block stms => |
37 |
| AST.S_Decl of var_decl |
| S.S_Assign(x, e) => |
38 |
| AST.S_IfThenElse of expr * stmt * stmt |
| S.S_IfThenElse(x, s1, s2) => |
39 |
| AST.S_Assign of var * expr |
| S.S_New(name, xs) => |
40 |
| AST.S_New of Atom.atom * expr list |
| S.S_Die => |
41 |
| AST.S_Die |
| S.S_Stabilize => |
|
| AST.S_Stabilize |
|
42 |
(* end case *)) |
(* end case *)) |
43 |
|
|
44 |
|
fun translate (S.Program{globals, globaInit, actors}) = ?? |
45 |
|
|
46 |
end |
end |