-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathremove-open.sml
71 lines (61 loc) · 1.98 KB
/
remove-open.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
structure RemoveOpen = struct
open Expr
open ExprVisitor
open Util
infixr 0 $
infixr 0 !!
fun remove_DOpen_expr_visitor_vtable cast () : ('this, unit) expr_visitor_vtable =
let
val vtable =
default_expr_visitor_vtable
cast
extend_noop
extend_noop
extend_noop
extend_noop
visit_noop
visit_noop
(visit_imposs "remove_DOpen/visit_mod_id")
visit_noop
visit_noop
visit_noop
visit_noop
visit_noop
visit_noop
fun visit_DOpen this env (Outer m, octx) =
let
val (sctx, kctx, cctx, tctx) = octx !! (fn () => raise Impossible "remove_DOpen: octx must be SOME")
val decls = []
fun V i = QID (m, (i, dummy))
val decls = mapi (fn (i, name) => DIdxDef (name, Outer NONE, Outer $ VarI $ V i)) sctx @ decls
val decls = mapi (fn (i, name) => DTypeDef (name, Outer $ MtVar $ V i)) kctx @ decls
val decls = mapi (fn (i, name) => DConstrDef (name, Outer $ V i)) cctx @ decls
val decls = mapi (fn (i, name) => MakeDVal (unBinderName name, [], EVar (V i, true), dummy)) tctx @ decls
val decls = rev decls
in
decls
end
val vtable = override_visit_DOpen vtable visit_DOpen
in
vtable
end
fun new_remove_DOpen_expr_visitor params = new_expr_visitor remove_DOpen_expr_visitor_vtable params
fun remove_DOpen_e e =
let
val visitor as (ExprVisitor vtable) = new_remove_DOpen_expr_visitor ()
in
#visit_expr vtable visitor () e
end
fun remove_DOpen_decls a = DerivedTrans.for_decls remove_DOpen_e a
fun remove_DOpen_m m =
let
val visitor = new_remove_DOpen_expr_visitor ()
in
fst $ visit_mod_acc visitor (m, ())
end
fun remove_DOpen_top_bind b =
case b of
TopModBind m => TopModBind $ remove_DOpen_m m
| _ => raise Unimpl "remove_DOpen_top_bind"
fun remove_DOpen_prog p = map (mapSnd remove_DOpen_top_bind) p
end