blob: 0838f38bd7e333b585aa25c88def37b49182aa37 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
structure Elab =
struct
fun primop (s : string) : Syntax.primop =
case s of
"exit" => Syntax.PExit
| _ => raise Fail ("invalid op: " ^ s)
fun elaborate (p : Syntax.expr) : Syntax.lexp =
case p of
Syntax.EBuiltin builtin => Syntax.LPrim (primop builtin)
| Syntax.EIdent [i] => raise Fail "only primitive operations for now, no variables"
| Syntax.EInt i => Syntax.LInt i
| Syntax.EStr s => Syntax.LString s
| Syntax.ETuple exprs => Syntax.LRecord (map elaborate exprs)
| Syntax.EApp (f, x) => Syntax.LApp (elaborate f, elaborate x)
| Syntax.ETyped (e, _) => elaborate e
| Syntax.ELet (decls, body) =>
Syntax.LRecord
(map elaborate
(map (fn (Syntax.DVal e) => e) decls @ [body]))
| _ => raise Fail "elaborate: operation not supported"
end
|