-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty-print.sml
205 lines (179 loc) · 6.61 KB
/
pretty-print.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
functor PrettyPrintFn (structure Expr : IDX_TYPE_EXPR where type Idx.base_sort = BaseSorts.base_sort
and type Type.base_type = BaseTypes.base_type
and type Idx.region = Region.region
and type Idx.name = string * Region.region
and type Type.name = string * Region.region
and type Type.region = Region.region
and type mod_id = string * Region.region
structure CanToString : CAN_TO_STRING
sharing type Expr.Type.basic_sort = Expr.Idx.basic_sort
sharing type CanToString.var = Expr.var
sharing type CanToString.idx = Expr.Idx.idx
sharing type CanToString.uvar_bs = Expr.Idx.uvar_bs
sharing type CanToString.uvar_i = Expr.Idx.uvar_i
sharing type CanToString.uvar_s = Expr.Idx.uvar_s
sharing type CanToString.uvar_mt = Expr.Type.uvar_mt
val str_ptrn_constr_tag : Expr.ptrn_constr_tag -> string
) = struct
open CanToString
open Expr
open Idx
open Type
open Gctx
open List
open Util
open BaseSorts
open BaseTypes
open Operators
open Pattern
open Region
structure IdxUtil = IdxUtilFn (Idx)
open IdxUtil
structure TypeUtil = TypeUtilFn (Type)
open TypeUtil
structure ExprUtil = ExprUtilFn (Expr)
open ExprUtil
open Bind
infixr 0 $
(* structure StringUVar = struct *)
(* type 'a uvar_bs = string *)
(* type ('a, 'b) uvar_i = string *)
(* type ('a, 'b) uvar_s = string *)
(* type ('a, 'b, 'c) uvar_mt = string *)
(* end *)
structure StringUVar = struct
type 'a uvar_bs = 'a uvar_bs
type ('a, 'b) uvar_i = ('a, 'b) uvar_i
type ('a, 'b) uvar_s = ('a, 'b) uvar_s
type ('a, 'b, 'c) uvar_mt = ('a, 'b, 'c) uvar_mt
end
structure NamefulIdx = IdxFn (structure UVarI = StringUVar
type base_sort = base_sort
type var = string
type name = name
type region = region
type 'idx exists_anno = unit
)
(* open NamefulIdx *)
(* structure T = NamefulIdx *)
structure NamefulType = TypeFn (structure Idx = NamefulIdx
structure UVarT = StringUVar
type base_type = base_type
)
structure NamefulTypeUtil = TypeUtilFn (NamefulType)
structure NamefulExpr = ExprFn (
type var = string
type cvar = string
type mod_id = string
type idx = NamefulIdx.idx
type sort = NamefulIdx.sort
type mtype = NamefulType.mtype
val get_constr_names = NamefulTypeUtil.get_constr_names
type ptrn_constr_tag = ptrn_constr_tag
type ty = NamefulType.ty
type kind = NamefulType.kind
)
structure ToStringNameful = ToStringNamefulFn (structure Expr = struct
structure Idx = NamefulIdx
structure Type = NamefulType
open NamefulExpr
end
open CanToString
)
structure SN = ToStringNameful
structure PPNameful = PPNamefulFn (structure Expr = struct
structure Idx = NamefulIdx
structure Type = NamefulType
open NamefulExpr
end
open CanToString
val str_var = id
val str_cvar = id
val str_mod_id = id
val str_ptrn_constr_tag = str_ptrn_constr_tag
)
structure PPN = PPNameful
structure ExportIdx = ExportIdxFn (structure Params = struct
structure S = Idx
structure T = NamefulIdx
end
open CanToString
)
open ExportIdx
fun str_bs b =
let
val b = export_bs b
in
SN.strn_bs b
end
fun str_i gctx ctx b =
let
val b = export_i gctx ctx b
in
SN.strn_i b
end
fun str_s gctx ctx b =
let
val b = export_s gctx ctx b
in
SN.strn_s b
end
fun str_p gctx ctx b =
let
val b = export_p gctx ctx b
in
SN.strn_p b
end
structure ExportType = ExportTypeFn (structure Params = struct
structure S = Type
structure T = NamefulType
end
open CanToString
open ExportIdx
)
open ExportType
fun str_k a = SN.strn_k $ export_k a
val pp_t_params = (SN.strn_bs, SN.strn_i, SN.strn_s, SN.strn_k)
fun pp_t_to_string gctx ctx b =
let
val b = export_mt gctx ctx b
in
PPN.pp_t_to_string_fn pp_t_params b
end
structure ExportExpr = ExportExprFn (structure Params = struct
structure S = Expr
structure T = NamefulExpr
end
open CanToString
open ExportIdx
open ExportType
)
open ExportExpr
fun pp_t_to a = PPN.pp_t pp_t_params a
fun pp_pn_to a = PPN.pp_pn pp_t_to a
val pp_e_params = (SN.strn_i, SN.strn_s, pp_t_to, pp_pn_to)
fun pp_e_to_string gctx ctx b =
let
val b = export_e gctx ctx b
in
PPN.pp_e_to_string_fn pp_e_params b
end
fun pp_d_to_string gctx ctx b =
let
val (b, ctx) = export_decl gctx ctx b
in
(PPN.pp_d_to_string_fn pp_e_params b, ctx)
end
fun pp_decls_to_string gctx ctx b =
let
val (b, ctx) = export_decls gctx ctx b
in
(PPN.pp_decls_to_string_fn pp_e_params b, ctx)
end
(* fun pp_prog_to_string gctx b = *)
(* let *)
(* val (b, gctxd, gctx) = export_prog gctx b *)
(* in *)
(* ((* PPN.pp_prog_to_string_fn pp_e_params *) b, gctxd, gctx) *)
(* end *)
end