File: patsolve_z3_solving_sort.dats

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (233 lines) | stat: -rw-r--r-- 3,480 bytes parent folder | download | duplicates (4)
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
(*
##
## ATS-extsolve-z3:
## Solving ATS-constraints with Z3
##
*)

(* ****** ****** *)
//
#ifdef
PATSOLVE_Z3_SOLVING
#then
#else
#include "./myheader.hats"
#endif // ifdef(PATSOLVE_Z3_SOLVING)
//
(* ****** ****** *)
//
#staload
UN = "prelude/SATS/unsafe.sats"
//
#staload "./patsolve_z3_solving_ctx.dats"
//
(* ****** ****** *)

assume sort_vtype = Z3_sort

(* ****** ****** *)

implement
sort_decref
  (ty) = () where
{
  val (fpf | ctx) =
    the_Z3_context_vget()
  // end of [val]
  val () = Z3_sort_dec_ref(ctx, ty)
  prval ((*void*)) = fpf(ctx)
}

(* ****** ****** *)

implement
sort_incref
  (ty) = ty2 where
{
//
val (fpf | ctx) =
  the_Z3_context_vget()
// end of [val]
val ty2 =
  Z3_sort_inc_ref(ctx, ty)
//
prval ((*void*)) = fpf(ctx)
//
} (* end of [sort_incref] *)

(* ****** ****** *)
//
implement 
sort_int () = res where
{
//
(*
val () =
  println! ("sort_int")
*)
//
val (fpf | ctx) = 
  the_Z3_context_vget()
// end of [val]
val res =
  Z3_mk_int_sort (ctx)
//
prval ((*void*)) = fpf (ctx)
//
} (* end of [sort_int] *)
//
(* ****** ****** *)
//
implement 
sort_bool () = res where
{
//
(*
val () =
  println! ("sort_bool")
*)
//
val (fpf | ctx) = 
  the_Z3_context_vget()
// end of [val]
val res =
  Z3_mk_bool_sort (ctx)
prval ((*void*)) = fpf (ctx)
//
} (* end of [sort_bool] *)
//
(* ****** ****** *)
//
implement 
sort_real () = res where
{
//
(*
val () =
  println! ("sort_real")
*)
//
val (fpf | ctx) = 
  the_Z3_context_vget()
// end of [val]
val res =
  Z3_mk_real_sort (ctx)
//
prval ((*void*)) = fpf (ctx)
//
} (* end of [sort_real] *)
//
(* ****** ****** *)

implement
sort_mk_cls () = sort_mk_abstract("cls")
implement
sort_mk_eff () = sort_mk_abstract("eff")

(* ****** ****** *)
//
implement
sort_mk_type () = sort_mk_abstract("type")
implement
sort_mk_vtype () = sort_mk_abstract("type")
//
implement
sort_mk_t0ype () = sort_mk_abstract("type")
implement
sort_mk_vt0ype () = sort_mk_abstract("type")
//
implement
sort_mk_prop () = sort_bool()
implement
sort_mk_view () = sort_bool()
//
implement
sort_mk_tkind () = sort_mk_abstract("tkind")
//
(* ****** ****** *)
//
(*
implement
sort_mk_abstract(name) = sort_int()
*)
//
implement
sort_mk_abstract
  (name) = res where
{
//
val (fpf | ctx) = 
  the_Z3_context_vget()
// end of [val]
val sym =
  Z3_mk_string_symbol (ctx, name)
val res =
  Z3_mk_uninterpreted_sort (ctx, sym)
prval ((*void*)) = fpf (ctx)
//
} (* end of [sort_mk_abstract] *)
//
(* ****** ****** *)

implement
sort_error
  (s2t0) = res where
{
//
val () =
prerrln!
  ("sort_error: s2t0 = ", s2t0)
//
val () = assertloc(false)
val res = sort_error(s2t0)
//
} (* end of [sort_error] *)

(* ****** ****** *)

implement
sort_make_s2rt(s2t0) = let
//
(*
val () =
println! ("sort_make: s2t0 = ", s2t0)
*)
//
in
//
case+ s2t0 of
//
| S2RTint() => sort_int()
| S2RTaddr() => sort_int()
| S2RTbool() => sort_bool()
//
| S2RTreal() => sort_real()
(*
| S2RTfloat() => sort_float()
| S2RTstring() => sort_string()
*)
//
| S2RTcls() => sort_mk_cls()
| S2RTeff() => sort_mk_eff()
//
| S2RTtype() => sort_mk_type()
| S2RTvtype() => sort_mk_vtype()
| S2RTt0ype() => sort_mk_t0ype()
| S2RTvt0ype() => sort_mk_vt0ype()
//
| S2RTprop() => sort_mk_prop()
| S2RTview() => sort_mk_view()
//
| S2RTtkind() => sort_mk_tkind()
//
| S2RTnamed(sym) =>
    sort_mk_abstract(sym.name())
  // end of [S2RTnamed]
//
| _(*rest-of-S2RT*) => sort_error(s2t0)
//
end (* end of [sort_make_s2rt] *)

(* ****** ****** *)

(* end of [patsolve_z3_solving_sort.dats] *)