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