leanfran 0.0.0-stage → 0.6.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +667 -2
- package/dist/arbitrary-B7Frjn9q.js +131 -0
- package/dist/block-CU7YIXdj.js +37 -0
- package/dist/check-DROT5twE.js +2931 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +134 -0
- package/dist/embed-BlX4FUDH.js +200 -0
- package/dist/index-DPF21ftq.d.ts +210 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +1 -0
- package/dist/io-CmMW8KGX.d.ts +66 -0
- package/dist/marshal-DhKsxhRw.js +2012 -0
- package/dist/node-B3DpEsaq.js +46 -0
- package/dist/object-G1zwZFrv.d.ts +93 -0
- package/dist/runtime/node.d.ts +2 -0
- package/dist/runtime/node.js +1 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1020 -0
- package/dist/schema-CvTyc8wa.js +308 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +4 -0
- package/dist/verify.d.ts +27 -0
- package/dist/verify.js +215 -0
- package/package.json +69 -4
- package/src/lean/LeanTsLib/Ts.lean +78 -0
|
@@ -0,0 +1,2012 @@
|
|
|
1
|
+
import { t as blockRegistry } from "./block-CU7YIXdj.js";
|
|
2
|
+
// src/runtime/uint.ts
|
|
3
|
+
const WORD_BITS = 64;
|
|
4
|
+
function um(bits, x) {
|
|
5
|
+
const mod = 2 ** bits;
|
|
6
|
+
let r = x % mod;
|
|
7
|
+
if (r < 0) r += mod;
|
|
8
|
+
return r;
|
|
9
|
+
}
|
|
10
|
+
function bm(bits, x) {
|
|
11
|
+
return BigInt.asUintN(bits, x);
|
|
12
|
+
}
|
|
13
|
+
function lean_uint8_of_nat(n) {
|
|
14
|
+
return um(8, Number(BigInt.asUintN(8, asNat(n))));
|
|
15
|
+
}
|
|
16
|
+
function lean_uint8_add(a, b) {
|
|
17
|
+
return um(8, a + b);
|
|
18
|
+
}
|
|
19
|
+
function lean_uint8_sub(a, b) {
|
|
20
|
+
return um(8, a - b);
|
|
21
|
+
}
|
|
22
|
+
function lean_uint8_mul(a, b) {
|
|
23
|
+
return um(8, Number(BigInt(um(8, a)) * BigInt(um(8, b)) % BigInt(256)));
|
|
24
|
+
}
|
|
25
|
+
function lean_uint8_div(a, b) {
|
|
26
|
+
return b === 0 ? 0 : um(8, Math.trunc(um(8, a) / um(8, b)));
|
|
27
|
+
}
|
|
28
|
+
function lean_uint8_mod(a, b) {
|
|
29
|
+
return b === 0 ? um(8, a) : um(8, um(8, a) % um(8, b));
|
|
30
|
+
}
|
|
31
|
+
function lean_uint8_land(a, b) {
|
|
32
|
+
return um(8, Number(BigInt(um(8, a)) & BigInt(um(8, b))));
|
|
33
|
+
}
|
|
34
|
+
function lean_uint8_lor(a, b) {
|
|
35
|
+
return um(8, Number(BigInt(um(8, a)) | BigInt(um(8, b))));
|
|
36
|
+
}
|
|
37
|
+
function lean_uint8_xor(a, b) {
|
|
38
|
+
return um(8, Number(BigInt(um(8, a)) ^ BigInt(um(8, b))));
|
|
39
|
+
}
|
|
40
|
+
function lean_uint8_complement(a) {
|
|
41
|
+
return um(8, 255 - um(8, a));
|
|
42
|
+
}
|
|
43
|
+
function lean_uint8_neg(a) {
|
|
44
|
+
return um(8, -um(8, a));
|
|
45
|
+
}
|
|
46
|
+
function lean_uint8_shift_left(a, b) {
|
|
47
|
+
return um(8, Number(BigInt(um(8, a)) << BigInt(b % 8)));
|
|
48
|
+
}
|
|
49
|
+
function lean_uint8_shift_right(a, b) {
|
|
50
|
+
return um(8, Number(BigInt(um(8, a)) >> BigInt(b % 8)));
|
|
51
|
+
}
|
|
52
|
+
function lean_uint8_dec_eq(a, b) {
|
|
53
|
+
return lean_bool(um(8, a) === um(8, b));
|
|
54
|
+
}
|
|
55
|
+
function lean_uint8_dec_lt(a, b) {
|
|
56
|
+
return lean_bool(um(8, a) < um(8, b));
|
|
57
|
+
}
|
|
58
|
+
function lean_uint8_dec_le(a, b) {
|
|
59
|
+
return lean_bool(um(8, a) <= um(8, b));
|
|
60
|
+
}
|
|
61
|
+
function lean_uint8_to_nat(a) {
|
|
62
|
+
return BigInt(um(8, a));
|
|
63
|
+
}
|
|
64
|
+
function lean_uint16_of_nat(n) {
|
|
65
|
+
return um(16, Number(BigInt.asUintN(16, asNat(n))));
|
|
66
|
+
}
|
|
67
|
+
function lean_uint16_add(a, b) {
|
|
68
|
+
return um(16, a + b);
|
|
69
|
+
}
|
|
70
|
+
function lean_uint16_sub(a, b) {
|
|
71
|
+
return um(16, a - b);
|
|
72
|
+
}
|
|
73
|
+
function lean_uint16_mul(a, b) {
|
|
74
|
+
return um(16, Number(BigInt(um(16, a)) * BigInt(um(16, b)) % BigInt(2 ** 16)));
|
|
75
|
+
}
|
|
76
|
+
function lean_uint16_div(a, b) {
|
|
77
|
+
return b === 0 ? 0 : um(16, Math.trunc(um(16, a) / um(16, b)));
|
|
78
|
+
}
|
|
79
|
+
function lean_uint16_mod(a, b) {
|
|
80
|
+
return b === 0 ? um(16, a) : um(16, um(16, a) % um(16, b));
|
|
81
|
+
}
|
|
82
|
+
function lean_uint16_land(a, b) {
|
|
83
|
+
return um(16, Number(BigInt(um(16, a)) & BigInt(um(16, b))));
|
|
84
|
+
}
|
|
85
|
+
function lean_uint16_lor(a, b) {
|
|
86
|
+
return um(16, Number(BigInt(um(16, a)) | BigInt(um(16, b))));
|
|
87
|
+
}
|
|
88
|
+
function lean_uint16_xor(a, b) {
|
|
89
|
+
return um(16, Number(BigInt(um(16, a)) ^ BigInt(um(16, b))));
|
|
90
|
+
}
|
|
91
|
+
function lean_uint16_complement(a) {
|
|
92
|
+
return um(16, 2 ** 16 - 1 - um(16, a));
|
|
93
|
+
}
|
|
94
|
+
function lean_uint16_neg(a) {
|
|
95
|
+
return um(16, -um(16, a));
|
|
96
|
+
}
|
|
97
|
+
function lean_uint16_shift_left(a, b) {
|
|
98
|
+
return um(16, Number(BigInt(um(16, a)) << BigInt(b % 16)));
|
|
99
|
+
}
|
|
100
|
+
function lean_uint16_shift_right(a, b) {
|
|
101
|
+
return um(16, Number(BigInt(um(16, a)) >> BigInt(b % 16)));
|
|
102
|
+
}
|
|
103
|
+
function lean_uint16_dec_eq(a, b) {
|
|
104
|
+
return lean_bool(um(16, a) === um(16, b));
|
|
105
|
+
}
|
|
106
|
+
function lean_uint16_dec_lt(a, b) {
|
|
107
|
+
return lean_bool(um(16, a) < um(16, b));
|
|
108
|
+
}
|
|
109
|
+
function lean_uint16_dec_le(a, b) {
|
|
110
|
+
return lean_bool(um(16, a) <= um(16, b));
|
|
111
|
+
}
|
|
112
|
+
function lean_uint16_to_nat(a) {
|
|
113
|
+
return BigInt(um(16, a));
|
|
114
|
+
}
|
|
115
|
+
function lean_uint32_add(a, b) {
|
|
116
|
+
return um(32, a + b);
|
|
117
|
+
}
|
|
118
|
+
function lean_uint32_sub(a, b) {
|
|
119
|
+
return um(32, a - b);
|
|
120
|
+
}
|
|
121
|
+
function lean_uint32_mul(a, b) {
|
|
122
|
+
return um(32, Number(BigInt(um(32, a)) * BigInt(um(32, b)) % BigInt(2 ** 32)));
|
|
123
|
+
}
|
|
124
|
+
function lean_uint32_div(a, b) {
|
|
125
|
+
return b === 0 ? 0 : um(32, Math.trunc(um(32, a) / um(32, b)));
|
|
126
|
+
}
|
|
127
|
+
function lean_uint32_mod(a, b) {
|
|
128
|
+
return b === 0 ? um(32, a) : um(32, um(32, a) % um(32, b));
|
|
129
|
+
}
|
|
130
|
+
function lean_uint32_land(a, b) {
|
|
131
|
+
return um(32, Number(BigInt(um(32, a)) & BigInt(um(32, b))));
|
|
132
|
+
}
|
|
133
|
+
function lean_uint32_lor(a, b) {
|
|
134
|
+
return um(32, Number(BigInt(um(32, a)) | BigInt(um(32, b))));
|
|
135
|
+
}
|
|
136
|
+
function lean_uint32_xor(a, b) {
|
|
137
|
+
return um(32, Number(BigInt(um(32, a)) ^ BigInt(um(32, b))));
|
|
138
|
+
}
|
|
139
|
+
function lean_uint32_complement(a) {
|
|
140
|
+
return um(32, 2 ** 32 - 1 - um(32, a));
|
|
141
|
+
}
|
|
142
|
+
function lean_uint32_neg(a) {
|
|
143
|
+
return um(32, -um(32, a));
|
|
144
|
+
}
|
|
145
|
+
function lean_uint32_shift_left(a, b) {
|
|
146
|
+
return um(32, Number(BigInt(um(32, a)) << BigInt(b % 32)));
|
|
147
|
+
}
|
|
148
|
+
function lean_uint32_shift_right(a, b) {
|
|
149
|
+
return um(32, Number(BigInt(um(32, a)) >> BigInt(b % 32)));
|
|
150
|
+
}
|
|
151
|
+
function lean_uint32_dec_eq(a, b) {
|
|
152
|
+
return lean_bool(um(32, a) === um(32, b));
|
|
153
|
+
}
|
|
154
|
+
function lean_uint32_dec_lt(a, b) {
|
|
155
|
+
return lean_bool(um(32, a) < um(32, b));
|
|
156
|
+
}
|
|
157
|
+
function lean_uint32_dec_le(a, b) {
|
|
158
|
+
return lean_bool(um(32, a) <= um(32, b));
|
|
159
|
+
}
|
|
160
|
+
function lean_uint32_to_nat(a) {
|
|
161
|
+
return BigInt(um(32, a));
|
|
162
|
+
}
|
|
163
|
+
function lean_uint64_of_nat(n) {
|
|
164
|
+
return bm(64, asNat(n));
|
|
165
|
+
}
|
|
166
|
+
function lean_uint64_of_nat_mk(n) {
|
|
167
|
+
return bm(64, asNat(n));
|
|
168
|
+
}
|
|
169
|
+
function lean_uint64_add(a, b) {
|
|
170
|
+
return bm(64, a + b);
|
|
171
|
+
}
|
|
172
|
+
function lean_uint64_sub(a, b) {
|
|
173
|
+
return bm(64, a - b);
|
|
174
|
+
}
|
|
175
|
+
function lean_uint64_mul(a, b) {
|
|
176
|
+
return bm(64, a * b);
|
|
177
|
+
}
|
|
178
|
+
function lean_uint64_div(a, b) {
|
|
179
|
+
return b === 0n ? 0n : bm(64, a / b);
|
|
180
|
+
}
|
|
181
|
+
function lean_uint64_mod(a, b) {
|
|
182
|
+
return b === 0n ? bm(64, a) : bm(64, a % b);
|
|
183
|
+
}
|
|
184
|
+
function lean_uint64_land(a, b) {
|
|
185
|
+
return bm(64, a & b);
|
|
186
|
+
}
|
|
187
|
+
function lean_uint64_lor(a, b) {
|
|
188
|
+
return bm(64, a | b);
|
|
189
|
+
}
|
|
190
|
+
function lean_uint64_xor(a, b) {
|
|
191
|
+
return bm(64, a ^ b);
|
|
192
|
+
}
|
|
193
|
+
function lean_uint64_complement(a) {
|
|
194
|
+
return bm(64, ~a);
|
|
195
|
+
}
|
|
196
|
+
function lean_uint64_neg(a) {
|
|
197
|
+
return bm(64, -a);
|
|
198
|
+
}
|
|
199
|
+
function lean_uint64_shift_left(a, b) {
|
|
200
|
+
return bm(64, a << b % BigInt(64));
|
|
201
|
+
}
|
|
202
|
+
function lean_uint64_shift_right(a, b) {
|
|
203
|
+
return bm(64, a) >> b % BigInt(64);
|
|
204
|
+
}
|
|
205
|
+
function lean_uint64_dec_eq(a, b) {
|
|
206
|
+
return lean_bool(bm(64, a) === bm(64, b));
|
|
207
|
+
}
|
|
208
|
+
function lean_uint64_dec_lt(a, b) {
|
|
209
|
+
return lean_bool(bm(64, a) < bm(64, b));
|
|
210
|
+
}
|
|
211
|
+
function lean_uint64_dec_le(a, b) {
|
|
212
|
+
return lean_bool(bm(64, a) <= bm(64, b));
|
|
213
|
+
}
|
|
214
|
+
function lean_uint64_to_nat(a) {
|
|
215
|
+
return bm(64, a);
|
|
216
|
+
}
|
|
217
|
+
function lean_usize_of_nat(n) {
|
|
218
|
+
return bm(64, asNat(n));
|
|
219
|
+
}
|
|
220
|
+
function lean_usize_add(a, b) {
|
|
221
|
+
return bm(64, a + b);
|
|
222
|
+
}
|
|
223
|
+
function lean_usize_sub(a, b) {
|
|
224
|
+
return bm(64, a - b);
|
|
225
|
+
}
|
|
226
|
+
function lean_usize_mul(a, b) {
|
|
227
|
+
return bm(64, a * b);
|
|
228
|
+
}
|
|
229
|
+
function lean_usize_div(a, b) {
|
|
230
|
+
return b === 0n ? 0n : bm(64, a / b);
|
|
231
|
+
}
|
|
232
|
+
function lean_usize_mod(a, b) {
|
|
233
|
+
return b === 0n ? bm(64, a) : bm(64, a % b);
|
|
234
|
+
}
|
|
235
|
+
function lean_usize_land(a, b) {
|
|
236
|
+
return bm(64, a & b);
|
|
237
|
+
}
|
|
238
|
+
function lean_usize_lor(a, b) {
|
|
239
|
+
return bm(64, a | b);
|
|
240
|
+
}
|
|
241
|
+
function lean_usize_xor(a, b) {
|
|
242
|
+
return bm(64, a ^ b);
|
|
243
|
+
}
|
|
244
|
+
function lean_usize_complement(a) {
|
|
245
|
+
return bm(64, ~a);
|
|
246
|
+
}
|
|
247
|
+
function lean_usize_neg(a) {
|
|
248
|
+
return bm(64, -a);
|
|
249
|
+
}
|
|
250
|
+
function lean_usize_shift_left(a, b) {
|
|
251
|
+
return bm(64, a << b % BigInt(64));
|
|
252
|
+
}
|
|
253
|
+
function lean_usize_shift_right(a, b) {
|
|
254
|
+
return bm(64, a) >> b % BigInt(64);
|
|
255
|
+
}
|
|
256
|
+
function lean_usize_dec_eq(a, b) {
|
|
257
|
+
return lean_bool(bm(64, a) === bm(64, b));
|
|
258
|
+
}
|
|
259
|
+
function lean_usize_dec_lt(a, b) {
|
|
260
|
+
return lean_bool(bm(64, a) < bm(64, b));
|
|
261
|
+
}
|
|
262
|
+
function lean_usize_dec_le(a, b) {
|
|
263
|
+
return lean_bool(bm(64, a) <= bm(64, b));
|
|
264
|
+
}
|
|
265
|
+
function lean_usize_to_nat(a) {
|
|
266
|
+
return bm(64, a);
|
|
267
|
+
}
|
|
268
|
+
function lean_uint64_to_usize(x) {
|
|
269
|
+
return BigInt.asUintN(64, x);
|
|
270
|
+
}
|
|
271
|
+
function lean_uint32_of_nat(n) {
|
|
272
|
+
return Number(asNat(n) & 4294967295n);
|
|
273
|
+
}
|
|
274
|
+
function lean_uint32_of_nat2(n) {
|
|
275
|
+
return Number(BigInt.asUintN(32, asNat(n)));
|
|
276
|
+
}
|
|
277
|
+
function lean_system_platform_nbits(_unit) {
|
|
278
|
+
return BigInt(64);
|
|
279
|
+
}
|
|
280
|
+
function lean_uint32_of_nat_mk(n) {
|
|
281
|
+
return lean_uint32_of_nat(n);
|
|
282
|
+
}
|
|
283
|
+
function lean_uint8_to_uint64(a) {
|
|
284
|
+
return BigInt(a);
|
|
285
|
+
}
|
|
286
|
+
function lean_uint16_to_uint64(a) {
|
|
287
|
+
return BigInt(a);
|
|
288
|
+
}
|
|
289
|
+
function lean_uint32_to_uint64(a) {
|
|
290
|
+
return BigInt(a);
|
|
291
|
+
}
|
|
292
|
+
function lean_usize_to_uint64(a) {
|
|
293
|
+
return a;
|
|
294
|
+
}
|
|
295
|
+
// src/runtime/object.ts
|
|
296
|
+
function fail(what, x) {
|
|
297
|
+
throw new TypeError(`leanfran runtime: expected ${what}, got ${typeof x}`);
|
|
298
|
+
}
|
|
299
|
+
function lean_bool(b) {
|
|
300
|
+
return b ? 1 : 0;
|
|
301
|
+
}
|
|
302
|
+
function asCtor(x) {
|
|
303
|
+
if (typeof x === "object" && x !== null && "tag" in x) return x;
|
|
304
|
+
return fail("a constructor object", x);
|
|
305
|
+
}
|
|
306
|
+
function asClosure(x) {
|
|
307
|
+
if (typeof x === "object" && x !== null && "arity" in x) return x;
|
|
308
|
+
return fail("a closure", x);
|
|
309
|
+
}
|
|
310
|
+
function asRef(x) {
|
|
311
|
+
if (typeof x === "object" && x !== null && "value" in x) return x;
|
|
312
|
+
return fail("a reference", x);
|
|
313
|
+
}
|
|
314
|
+
function asHandle(x) {
|
|
315
|
+
if (typeof x === "object" && x !== null && "fd" in x) return x;
|
|
316
|
+
return fail("a file handle", x);
|
|
317
|
+
}
|
|
318
|
+
function asNat(x) {
|
|
319
|
+
if (typeof x === "bigint") return x;
|
|
320
|
+
return fail("a bigint", x);
|
|
321
|
+
}
|
|
322
|
+
function asString(x) {
|
|
323
|
+
if (typeof x === "string") return x;
|
|
324
|
+
return fail("a string", x);
|
|
325
|
+
}
|
|
326
|
+
function asArray(x) {
|
|
327
|
+
if (Array.isArray(x)) return x;
|
|
328
|
+
return fail("an array", x);
|
|
329
|
+
}
|
|
330
|
+
function asBytes(x) {
|
|
331
|
+
if (x instanceof Uint8Array) return x;
|
|
332
|
+
return fail("a Uint8Array", x);
|
|
333
|
+
}
|
|
334
|
+
function asFloats(x) {
|
|
335
|
+
if (x instanceof Float64Array) return x;
|
|
336
|
+
return fail("a Float64Array", x);
|
|
337
|
+
}
|
|
338
|
+
function lean_unbox(x) {
|
|
339
|
+
if (typeof x === "number") return x;
|
|
340
|
+
return fail("a number", x);
|
|
341
|
+
}
|
|
342
|
+
function lean_unbox_uint64(x) {
|
|
343
|
+
return asNat(x);
|
|
344
|
+
}
|
|
345
|
+
function lean_tag(x) {
|
|
346
|
+
return typeof x === "number" ? x : asCtor(x).tag;
|
|
347
|
+
}
|
|
348
|
+
function counted(x) {
|
|
349
|
+
return typeof x === "object" && x !== null && "rc" in x && typeof x.rc === "number" && x.rc > 0;
|
|
350
|
+
}
|
|
351
|
+
function lean_inc(x) {
|
|
352
|
+
if (counted(x)) x.rc = (x.rc ?? 0) + 1;
|
|
353
|
+
}
|
|
354
|
+
function lean_inc_n(x, n) {
|
|
355
|
+
if (counted(x)) x.rc = (x.rc ?? 0) + n;
|
|
356
|
+
}
|
|
357
|
+
function lean_dec(x) {
|
|
358
|
+
if (!counted(x)) return;
|
|
359
|
+
if (x.rc !== 1) {
|
|
360
|
+
x.rc = (x.rc ?? 0) - 1;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const stack = [x];
|
|
364
|
+
for (let o = stack.pop(); o !== void 0; o = stack.pop()) {
|
|
365
|
+
o.rc = 0;
|
|
366
|
+
const children = Array.isArray(o) ? o : "fields" in o ? o.fields : null;
|
|
367
|
+
if (children === null) continue;
|
|
368
|
+
for (const c of children) {
|
|
369
|
+
if (!counted(c)) continue;
|
|
370
|
+
if (c.rc === 1) stack.push(c);
|
|
371
|
+
else c.rc = (c.rc ?? 0) - 1;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function lean_is_exclusive(x) {
|
|
376
|
+
return counted(x) && x.rc === 1;
|
|
377
|
+
}
|
|
378
|
+
function lean_is_shared(x) {
|
|
379
|
+
return lean_is_exclusive(x) ? 0 : 1;
|
|
380
|
+
}
|
|
381
|
+
function lean_mark_persistent(x) {
|
|
382
|
+
if (counted(x)) x.rc = 0;
|
|
383
|
+
return x;
|
|
384
|
+
}
|
|
385
|
+
function lean_reset(x, n) {
|
|
386
|
+
if (lean_is_exclusive(x)) {
|
|
387
|
+
const c = asCtor(x);
|
|
388
|
+
for (let i = 0; i < n; i++) {
|
|
389
|
+
lean_dec(c.fields[i]);
|
|
390
|
+
c.fields[i] = 0;
|
|
391
|
+
}
|
|
392
|
+
return c;
|
|
393
|
+
}
|
|
394
|
+
lean_dec(x);
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
function lean_reuse(token, tag, size, usize, ssize, ...objs) {
|
|
398
|
+
if (token === null) return lean_ctor(tag, size, usize, ssize, ...objs);
|
|
399
|
+
const c = asCtor(token);
|
|
400
|
+
c.tag = tag;
|
|
401
|
+
for (let i = 0; i < objs.length; i++) c.fields[i] = objs[i];
|
|
402
|
+
return c;
|
|
403
|
+
}
|
|
404
|
+
function lean_alloc_ctor(tag, size, usize, ssize) {
|
|
405
|
+
return {
|
|
406
|
+
tag,
|
|
407
|
+
fields: Array.from({ length: size + usize }),
|
|
408
|
+
sdata: ssize > 0 ? new DataView(new ArrayBuffer(ssize)) : null,
|
|
409
|
+
rc: 1
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function lean_ctor(tag, size, usize, ssize, ...objs) {
|
|
413
|
+
const c = lean_alloc_ctor(tag, size, usize, ssize);
|
|
414
|
+
for (let i = 0; i < objs.length; i++) c.fields[i] = objs[i];
|
|
415
|
+
return c;
|
|
416
|
+
}
|
|
417
|
+
function lean_ctor_get(x, i) {
|
|
418
|
+
return asCtor(x).fields[i];
|
|
419
|
+
}
|
|
420
|
+
function lean_ctor_set(x, i, v) {
|
|
421
|
+
asCtor(x).fields[i] = v;
|
|
422
|
+
}
|
|
423
|
+
function lean_ctor_set_tag(x, tag) {
|
|
424
|
+
asCtor(x).tag = tag;
|
|
425
|
+
}
|
|
426
|
+
function lean_ctor_uget(x, i) {
|
|
427
|
+
return asNat(asCtor(x).fields[i]);
|
|
428
|
+
}
|
|
429
|
+
function lean_ctor_uset(x, i, v) {
|
|
430
|
+
asCtor(x).fields[i] = v;
|
|
431
|
+
}
|
|
432
|
+
function sdata(x) {
|
|
433
|
+
const d = asCtor(x).sdata;
|
|
434
|
+
if (d === null) return fail("a constructor with scalar fields", x);
|
|
435
|
+
return d;
|
|
436
|
+
}
|
|
437
|
+
function lean_ctor_get_u8(x, o) {
|
|
438
|
+
return sdata(x).getUint8(o);
|
|
439
|
+
}
|
|
440
|
+
function lean_ctor_get_u16(x, o) {
|
|
441
|
+
return sdata(x).getUint16(o, true);
|
|
442
|
+
}
|
|
443
|
+
function lean_ctor_get_u32(x, o) {
|
|
444
|
+
return sdata(x).getUint32(o, true);
|
|
445
|
+
}
|
|
446
|
+
function lean_ctor_get_u64(x, o) {
|
|
447
|
+
return sdata(x).getBigUint64(o, true);
|
|
448
|
+
}
|
|
449
|
+
function lean_ctor_get_f64(x, o) {
|
|
450
|
+
return sdata(x).getFloat64(o, true);
|
|
451
|
+
}
|
|
452
|
+
function lean_ctor_get_f32(x, o) {
|
|
453
|
+
return sdata(x).getFloat32(o, true);
|
|
454
|
+
}
|
|
455
|
+
function lean_ctor_set_u8(x, o, v) {
|
|
456
|
+
sdata(x).setUint8(o, v & 255);
|
|
457
|
+
}
|
|
458
|
+
function lean_ctor_set_u16(x, o, v) {
|
|
459
|
+
sdata(x).setUint16(o, v & 65535, true);
|
|
460
|
+
}
|
|
461
|
+
function lean_ctor_set_u32(x, o, v) {
|
|
462
|
+
sdata(x).setUint32(o, v >>> 0, true);
|
|
463
|
+
}
|
|
464
|
+
function lean_ctor_set_u64(x, o, v) {
|
|
465
|
+
sdata(x).setBigUint64(o, BigInt.asUintN(64, v), true);
|
|
466
|
+
}
|
|
467
|
+
function lean_ctor_set_f64(x, o, v) {
|
|
468
|
+
sdata(x).setFloat64(o, v, true);
|
|
469
|
+
}
|
|
470
|
+
function lean_ctor_set_f32(x, o, v) {
|
|
471
|
+
sdata(x).setFloat32(o, Math.fround(v), true);
|
|
472
|
+
}
|
|
473
|
+
function lean_ctor_get_usize(x, o) {
|
|
474
|
+
return sdata(x).getBigUint64(o, true);
|
|
475
|
+
}
|
|
476
|
+
function lean_ctor_set_usize(x, o, v) {
|
|
477
|
+
sdata(x).setBigUint64(o, BigInt.asUintN(64, v), true);
|
|
478
|
+
}
|
|
479
|
+
function isBounce(x) {
|
|
480
|
+
return typeof x === "object" && x !== null && "tc" in x;
|
|
481
|
+
}
|
|
482
|
+
function lean_trampoline(t) {
|
|
483
|
+
let cur = t;
|
|
484
|
+
while (isBounce(cur)) cur = cur.tc === 1 ? Reflect.apply(cur.f, void 0, cur.a) : lean_apply(cur.clo, cur.a);
|
|
485
|
+
return cur;
|
|
486
|
+
}
|
|
487
|
+
function lean_closure(fn, arity, args) {
|
|
488
|
+
return {
|
|
489
|
+
fn,
|
|
490
|
+
arity,
|
|
491
|
+
args
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function lean_apply(clo, more) {
|
|
495
|
+
if (typeof clo === "function") return {
|
|
496
|
+
tc: 1,
|
|
497
|
+
f: clo,
|
|
498
|
+
a: more
|
|
499
|
+
};
|
|
500
|
+
let cur = asClosure(clo);
|
|
501
|
+
for (const a of cur.args) lean_inc(a);
|
|
502
|
+
if (cur.arity < 0) return {
|
|
503
|
+
tc: 1,
|
|
504
|
+
f: cur.fn,
|
|
505
|
+
a: cur.args.concat(more)
|
|
506
|
+
};
|
|
507
|
+
let i = 0;
|
|
508
|
+
while (i < more.length) {
|
|
509
|
+
const need = cur.arity - cur.args.length;
|
|
510
|
+
if (more.length - i < need) return lean_closure(cur.fn, cur.arity, cur.args.concat(more.slice(i)));
|
|
511
|
+
const callArgs = cur.args.concat(more.slice(i, i + need));
|
|
512
|
+
i += need;
|
|
513
|
+
if (i === more.length) return {
|
|
514
|
+
tc: 1,
|
|
515
|
+
f: cur.fn,
|
|
516
|
+
a: callArgs
|
|
517
|
+
};
|
|
518
|
+
const res = lean_trampoline({
|
|
519
|
+
tc: 1,
|
|
520
|
+
f: cur.fn,
|
|
521
|
+
a: callArgs
|
|
522
|
+
});
|
|
523
|
+
if (typeof res === "function") return {
|
|
524
|
+
tc: 1,
|
|
525
|
+
f: res,
|
|
526
|
+
a: more.slice(i)
|
|
527
|
+
};
|
|
528
|
+
const next = asClosure(res);
|
|
529
|
+
for (const a of next.args) lean_inc(a);
|
|
530
|
+
if (next.arity < 0) return {
|
|
531
|
+
tc: 1,
|
|
532
|
+
f: next.fn,
|
|
533
|
+
a: next.args.concat(more.slice(i))
|
|
534
|
+
};
|
|
535
|
+
cur = next;
|
|
536
|
+
}
|
|
537
|
+
return cur;
|
|
538
|
+
}
|
|
539
|
+
function asThunk(x) {
|
|
540
|
+
if (typeof x === "object" && x !== null && "forced" in x) return x;
|
|
541
|
+
return fail("a thunk", x);
|
|
542
|
+
}
|
|
543
|
+
function lean_mk_thunk(c) {
|
|
544
|
+
return {
|
|
545
|
+
closure: c,
|
|
546
|
+
forced: false,
|
|
547
|
+
result: void 0
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function lean_thunk_pure(v) {
|
|
551
|
+
return {
|
|
552
|
+
closure: null,
|
|
553
|
+
forced: true,
|
|
554
|
+
result: v
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function lean_thunk_get(x) {
|
|
558
|
+
const t = asThunk(x);
|
|
559
|
+
if (t.forced) return t.result;
|
|
560
|
+
const c = t.closure;
|
|
561
|
+
if (c === null) throw new TypeError("leanfran runtime: a thunk forced itself");
|
|
562
|
+
t.closure = null;
|
|
563
|
+
t.result = lean_trampoline(lean_apply(c, [0]));
|
|
564
|
+
t.forced = true;
|
|
565
|
+
return t.result;
|
|
566
|
+
}
|
|
567
|
+
function lean_thunk_get_own(x) {
|
|
568
|
+
const v = lean_thunk_get(x);
|
|
569
|
+
lean_inc(v);
|
|
570
|
+
return v;
|
|
571
|
+
}
|
|
572
|
+
// src/runtime/string.ts
|
|
573
|
+
const utf8enc = new TextEncoder();
|
|
574
|
+
const utf8dec = new TextDecoder("utf-8", { fatal: false });
|
|
575
|
+
function encodeUtf8(s) {
|
|
576
|
+
return utf8enc.encode(s);
|
|
577
|
+
}
|
|
578
|
+
function decodeUtf8(b) {
|
|
579
|
+
return utf8dec.decode(b);
|
|
580
|
+
}
|
|
581
|
+
function lean_char_to_nat(c) {
|
|
582
|
+
return BigInt(c);
|
|
583
|
+
}
|
|
584
|
+
function lean_string_length(s) {
|
|
585
|
+
let n = 0;
|
|
586
|
+
for (const _ of asString(s)) n++;
|
|
587
|
+
return BigInt(n);
|
|
588
|
+
}
|
|
589
|
+
function lean_string_append(a, b) {
|
|
590
|
+
return asString(a) + asString(b);
|
|
591
|
+
}
|
|
592
|
+
function lean_string_push(s, c) {
|
|
593
|
+
return asString(s) + String.fromCodePoint(c);
|
|
594
|
+
}
|
|
595
|
+
function lean_string_dec_eq(a, b) {
|
|
596
|
+
return lean_bool(a === b);
|
|
597
|
+
}
|
|
598
|
+
function lean_string_isempty(s) {
|
|
599
|
+
return lean_bool(asString(s).length === 0);
|
|
600
|
+
}
|
|
601
|
+
const MURMUR_M = 14313749767032793493n;
|
|
602
|
+
const MURMUR_R = 47n;
|
|
603
|
+
function wrap64(x) {
|
|
604
|
+
return BigInt.asUintN(64, x);
|
|
605
|
+
}
|
|
606
|
+
function lean_uint64_mix_hash(h0, k0) {
|
|
607
|
+
let k = wrap64(k0 * MURMUR_M);
|
|
608
|
+
k ^= k >> MURMUR_R;
|
|
609
|
+
k ^= MURMUR_M;
|
|
610
|
+
let h = h0 ^ k;
|
|
611
|
+
h = wrap64(h * MURMUR_M);
|
|
612
|
+
return wrap64(h);
|
|
613
|
+
}
|
|
614
|
+
function lean_string_hash(s) {
|
|
615
|
+
const b = utf8enc.encode(asString(s));
|
|
616
|
+
const len = b.length;
|
|
617
|
+
const m = MURMUR_M;
|
|
618
|
+
const r = MURMUR_R;
|
|
619
|
+
const at = (i) => BigInt(b[i] ?? 0);
|
|
620
|
+
let h = wrap64(11n ^ wrap64(BigInt(len) * m));
|
|
621
|
+
const nblocks = len / 8 | 0;
|
|
622
|
+
for (let i = 0; i < nblocks; i++) {
|
|
623
|
+
let k = 0n;
|
|
624
|
+
for (let j = 0; j < 8; j++) k |= at(i * 8 + j) << BigInt(8 * j);
|
|
625
|
+
k = wrap64(k * m);
|
|
626
|
+
k ^= k >> r;
|
|
627
|
+
k = wrap64(k * m);
|
|
628
|
+
h ^= k;
|
|
629
|
+
h = wrap64(h * m);
|
|
630
|
+
}
|
|
631
|
+
const t = nblocks * 8;
|
|
632
|
+
const rem = len & 7;
|
|
633
|
+
if (rem >= 7) h ^= at(t + 6) << 48n;
|
|
634
|
+
if (rem >= 6) h ^= at(t + 5) << 40n;
|
|
635
|
+
if (rem >= 5) h ^= at(t + 4) << 32n;
|
|
636
|
+
if (rem >= 4) h ^= at(t + 3) << 24n;
|
|
637
|
+
if (rem >= 3) h ^= at(t + 2) << 16n;
|
|
638
|
+
if (rem >= 2) h ^= at(t + 1) << 8n;
|
|
639
|
+
if (rem >= 1) {
|
|
640
|
+
h ^= at(t);
|
|
641
|
+
h = wrap64(h * m);
|
|
642
|
+
}
|
|
643
|
+
h ^= h >> r;
|
|
644
|
+
h = wrap64(h * m);
|
|
645
|
+
h ^= h >> r;
|
|
646
|
+
return wrap64(h);
|
|
647
|
+
}
|
|
648
|
+
function lean_string_data(s) {
|
|
649
|
+
return Array.from(asString(s)).reduceRight((tl, ch) => lean_ctor(1, 2, 0, 0, ch.codePointAt(0), tl), 0);
|
|
650
|
+
}
|
|
651
|
+
function lean_string_mk(lst) {
|
|
652
|
+
let out = "";
|
|
653
|
+
let cur = lst;
|
|
654
|
+
while (typeof cur !== "number" && asCtor(cur).tag === 1) {
|
|
655
|
+
const c = asCtor(cur);
|
|
656
|
+
out += String.fromCodePoint(lean_unbox(c.fields[0]));
|
|
657
|
+
cur = c.fields[1];
|
|
658
|
+
}
|
|
659
|
+
return out;
|
|
660
|
+
}
|
|
661
|
+
function charUtf8Size(c) {
|
|
662
|
+
return c <= 127 ? 1n : c <= 2047 ? 2n : c <= 65535 ? 3n : 4n;
|
|
663
|
+
}
|
|
664
|
+
function isFirstByte(b) {
|
|
665
|
+
return (b & 192) !== 128;
|
|
666
|
+
}
|
|
667
|
+
function decodeAt(bytes, i) {
|
|
668
|
+
const at = (k) => bytes[k] ?? 0;
|
|
669
|
+
const c0 = at(i);
|
|
670
|
+
if (c0 < 128) return [c0, 1];
|
|
671
|
+
if (c0 < 224) return [(c0 & 31) << 6 | at(i + 1) & 63, 2];
|
|
672
|
+
if (c0 < 240) return [(c0 & 15) << 12 | (at(i + 1) & 63) << 6 | at(i + 2) & 63, 3];
|
|
673
|
+
return [(c0 & 7) << 18 | (at(i + 1) & 63) << 12 | (at(i + 2) & 63) << 6 | at(i + 3) & 63, 4];
|
|
674
|
+
}
|
|
675
|
+
function validPos(b, i) {
|
|
676
|
+
return i >= 0 && i < b.length && isFirstByte(b[i] ?? 0);
|
|
677
|
+
}
|
|
678
|
+
function lean_string_utf8_byte_size(s) {
|
|
679
|
+
return BigInt(utf8enc.encode(asString(s)).length);
|
|
680
|
+
}
|
|
681
|
+
function lean_string_utf8_get(s, p) {
|
|
682
|
+
const b = utf8enc.encode(asString(s));
|
|
683
|
+
const i = Number(asNat(p));
|
|
684
|
+
if (!validPos(b, i)) return 65;
|
|
685
|
+
return decodeAt(b, i)[0];
|
|
686
|
+
}
|
|
687
|
+
function lean_string_utf8_get_bang(s, p) {
|
|
688
|
+
return lean_string_utf8_get(s, p);
|
|
689
|
+
}
|
|
690
|
+
function lean_string_utf8_get_opt(s, p) {
|
|
691
|
+
const b = utf8enc.encode(asString(s));
|
|
692
|
+
const i = Number(asNat(p));
|
|
693
|
+
if (!validPos(b, i)) return 0;
|
|
694
|
+
return lean_ctor(1, 1, 0, 0, decodeAt(b, i)[0]);
|
|
695
|
+
}
|
|
696
|
+
function lean_string_utf8_next(s, p) {
|
|
697
|
+
return asNat(p) + charUtf8Size(lean_string_utf8_get(s, p));
|
|
698
|
+
}
|
|
699
|
+
function lean_string_utf8_prev(s, p) {
|
|
700
|
+
const b = utf8enc.encode(asString(s));
|
|
701
|
+
let i = Number(asNat(p));
|
|
702
|
+
if (i <= 0) return 0n;
|
|
703
|
+
if (i > b.length) return BigInt(i - 1);
|
|
704
|
+
i -= 1;
|
|
705
|
+
while (i > 0 && !isFirstByte(b[i] ?? 0)) i -= 1;
|
|
706
|
+
return BigInt(i);
|
|
707
|
+
}
|
|
708
|
+
function lean_string_utf8_at_end(s, p) {
|
|
709
|
+
return lean_bool(Number(asNat(p)) >= utf8enc.encode(asString(s)).length);
|
|
710
|
+
}
|
|
711
|
+
function lean_string_utf8_extract(s, lo, hi) {
|
|
712
|
+
const bytes = utf8enc.encode(asString(s));
|
|
713
|
+
let a = Number(asNat(lo));
|
|
714
|
+
let z = Number(asNat(hi));
|
|
715
|
+
if (a >= z) return "";
|
|
716
|
+
if (z > bytes.length) z = bytes.length;
|
|
717
|
+
if (a > z) a = z;
|
|
718
|
+
return utf8dec.decode(bytes.slice(a, z));
|
|
719
|
+
}
|
|
720
|
+
function lean_string_utf8_extract_fast(s, lo, hi) {
|
|
721
|
+
return lean_string_utf8_extract(s, lo, hi);
|
|
722
|
+
}
|
|
723
|
+
function lean_string_utf8_set(s, p, c) {
|
|
724
|
+
const str = asString(s);
|
|
725
|
+
const b = utf8enc.encode(str);
|
|
726
|
+
const i = Number(asNat(p));
|
|
727
|
+
if (!validPos(b, i)) return str;
|
|
728
|
+
const n = decodeAt(b, i)[1];
|
|
729
|
+
return utf8dec.decode(b.slice(0, i)) + String.fromCodePoint(c) + utf8dec.decode(b.slice(i + n));
|
|
730
|
+
}
|
|
731
|
+
function lean_string_utf8_pos_of(s, c) {
|
|
732
|
+
const b = utf8enc.encode(asString(s));
|
|
733
|
+
for (let i = 0; i < b.length;) {
|
|
734
|
+
const [cp, n] = decodeAt(b, i);
|
|
735
|
+
if (cp === c) return BigInt(i);
|
|
736
|
+
i += n;
|
|
737
|
+
}
|
|
738
|
+
return BigInt(b.length);
|
|
739
|
+
}
|
|
740
|
+
function lean_string_contains(s, c) {
|
|
741
|
+
return lean_bool(Number(lean_string_utf8_pos_of(s, c)) !== utf8enc.encode(asString(s)).length);
|
|
742
|
+
}
|
|
743
|
+
function lean_string_get_byte_fast(s, p) {
|
|
744
|
+
return utf8enc.encode(asString(s))[Number(asNat(p))] ?? 0;
|
|
745
|
+
}
|
|
746
|
+
function lean_string_utf8_get_fast(s, p) {
|
|
747
|
+
return lean_string_utf8_get(s, p);
|
|
748
|
+
}
|
|
749
|
+
function lean_string_isprefixof(p, s) {
|
|
750
|
+
return lean_bool(asString(s).startsWith(asString(p)));
|
|
751
|
+
}
|
|
752
|
+
function lean_string_any(s, p) {
|
|
753
|
+
for (const ch of asString(s)) if (lean_trampoline(lean_apply(p, [ch.codePointAt(0)]))) return 1;
|
|
754
|
+
return 0;
|
|
755
|
+
}
|
|
756
|
+
function lean_string_of_usize(a) {
|
|
757
|
+
return a.toString();
|
|
758
|
+
}
|
|
759
|
+
function lean_string_to_utf8(s) {
|
|
760
|
+
return utf8enc.encode(asString(s));
|
|
761
|
+
}
|
|
762
|
+
function lean_string_from_utf8_unchecked(b) {
|
|
763
|
+
return utf8dec.decode(asBytes(b));
|
|
764
|
+
}
|
|
765
|
+
function lean_string_validate_utf8(b) {
|
|
766
|
+
try {
|
|
767
|
+
new TextDecoder("utf-8", { fatal: true }).decode(asBytes(b));
|
|
768
|
+
return 1;
|
|
769
|
+
} catch {
|
|
770
|
+
return 0;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function lean_string_utf8_next_fast(s, p) {
|
|
774
|
+
return lean_string_utf8_next(s, p);
|
|
775
|
+
}
|
|
776
|
+
function lean_string_memcmp(lhs, rhs, lstart, rstart, len) {
|
|
777
|
+
const a = utf8enc.encode(asString(lhs));
|
|
778
|
+
const b = utf8enc.encode(asString(rhs));
|
|
779
|
+
const l = Number(asNat(lstart));
|
|
780
|
+
const r = Number(asNat(rstart));
|
|
781
|
+
const n = Number(asNat(len));
|
|
782
|
+
for (let i = 0; i < n; i++) if (a[l + i] !== b[r + i]) return 0;
|
|
783
|
+
return 1;
|
|
784
|
+
}
|
|
785
|
+
function lean_string_lt(a, b) {
|
|
786
|
+
const x = utf8enc.encode(asString(a));
|
|
787
|
+
const y = utf8enc.encode(asString(b));
|
|
788
|
+
const n = Math.min(x.length, y.length);
|
|
789
|
+
for (let i = 0; i < n; i++) {
|
|
790
|
+
const p = x[i] ?? 0;
|
|
791
|
+
const q = y[i] ?? 0;
|
|
792
|
+
if (p !== q) return lean_bool(p < q);
|
|
793
|
+
}
|
|
794
|
+
return lean_bool(x.length < y.length);
|
|
795
|
+
}
|
|
796
|
+
function lean_string_dec_lt(a, b) {
|
|
797
|
+
return lean_string_lt(a, b);
|
|
798
|
+
}
|
|
799
|
+
// src/runtime/io.ts
|
|
800
|
+
function consoleWriter(log) {
|
|
801
|
+
let pending = "";
|
|
802
|
+
return (data) => {
|
|
803
|
+
pending += typeof data === "string" ? data : decodeUtf8(data);
|
|
804
|
+
const nl = pending.lastIndexOf("\n");
|
|
805
|
+
if (nl >= 0) {
|
|
806
|
+
log(pending.slice(0, nl));
|
|
807
|
+
pending = pending.slice(nl + 1);
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
function unsupported(op) {
|
|
812
|
+
const e = /* @__PURE__ */ new Error(`${op} is not supported on ${platform.target}`);
|
|
813
|
+
e.name = "UnsupportedOperation";
|
|
814
|
+
throw e;
|
|
815
|
+
}
|
|
816
|
+
const browserPlatform = {
|
|
817
|
+
target: "browser",
|
|
818
|
+
writeStdout: consoleWriter((s) => console.log(s)),
|
|
819
|
+
writeStderr: consoleWriter((s) => console.error(s)),
|
|
820
|
+
readFd: () => unsupported("reading a file descriptor"),
|
|
821
|
+
writeFd: () => unsupported("writing a file descriptor"),
|
|
822
|
+
openFile: () => unsupported("opening a file"),
|
|
823
|
+
isTty: () => false,
|
|
824
|
+
getenv: () => void 0,
|
|
825
|
+
argv: () => [],
|
|
826
|
+
exit: () => unsupported("exiting the process"),
|
|
827
|
+
setExitCode: () => {}
|
|
828
|
+
};
|
|
829
|
+
let platform = browserPlatform;
|
|
830
|
+
function setPlatform(p) {
|
|
831
|
+
platform = p;
|
|
832
|
+
}
|
|
833
|
+
function getPlatform() {
|
|
834
|
+
return platform;
|
|
835
|
+
}
|
|
836
|
+
let panicMessages = true;
|
|
837
|
+
let exitOnPanic = false;
|
|
838
|
+
function lean_set_panic_messages(b) {
|
|
839
|
+
panicMessages = b !== 0;
|
|
840
|
+
}
|
|
841
|
+
function lean_set_exit_on_panic(b) {
|
|
842
|
+
exitOnPanic = b !== 0;
|
|
843
|
+
}
|
|
844
|
+
function lean_panic_fn(defaultVal, msg) {
|
|
845
|
+
if (panicMessages) platform.writeStderr(asString(msg) + "\n");
|
|
846
|
+
if (exitOnPanic) platform.exit(1);
|
|
847
|
+
return defaultVal;
|
|
848
|
+
}
|
|
849
|
+
function lean_panic_fn_borrowed(defaultVal, msg) {
|
|
850
|
+
return lean_panic_fn(defaultVal, msg);
|
|
851
|
+
}
|
|
852
|
+
function lean_internal_panic(msg) {
|
|
853
|
+
platform.writeStderr("INTERNAL PANIC: " + msg + "\n");
|
|
854
|
+
return platform.exit(1);
|
|
855
|
+
}
|
|
856
|
+
function lean_internal_panic_unreachable() {
|
|
857
|
+
return lean_internal_panic("unreachable code has been reached");
|
|
858
|
+
}
|
|
859
|
+
function lean_io_result_mk_ok(a) {
|
|
860
|
+
return lean_ctor(0, 1, 0, 0, a);
|
|
861
|
+
}
|
|
862
|
+
function lean_io_result_mk_error(e) {
|
|
863
|
+
return lean_ctor(1, 1, 0, 0, e);
|
|
864
|
+
}
|
|
865
|
+
function lean_io_result_is_ok(r) {
|
|
866
|
+
return lean_tag(r) === 0;
|
|
867
|
+
}
|
|
868
|
+
function lean_io_result_get_value(r) {
|
|
869
|
+
return asCtor(r).fields[0];
|
|
870
|
+
}
|
|
871
|
+
function lean_io_result_get_error(r) {
|
|
872
|
+
return asCtor(r).fields[0];
|
|
873
|
+
}
|
|
874
|
+
const IO_ERROR_ALREADY_EXISTS = 0;
|
|
875
|
+
const IO_ERROR_OTHER = 1;
|
|
876
|
+
const IO_ERROR_RESOURCE_BUSY = 2;
|
|
877
|
+
const IO_ERROR_RESOURCE_VANISHED = 3;
|
|
878
|
+
const IO_ERROR_UNSUPPORTED_OPERATION = 4;
|
|
879
|
+
const IO_ERROR_HARDWARE_FAULT = 5;
|
|
880
|
+
const IO_ERROR_UNSATISFIED_CONSTRAINTS = 6;
|
|
881
|
+
const IO_ERROR_ILLEGAL_OPERATION = 7;
|
|
882
|
+
const IO_ERROR_PROTOCOL = 8;
|
|
883
|
+
const IO_ERROR_TIME_EXPIRED = 9;
|
|
884
|
+
const IO_ERROR_INTERRUPTED = 10;
|
|
885
|
+
const IO_ERROR_NO_FILE_OR_DIRECTORY = 11;
|
|
886
|
+
const IO_ERROR_INVALID_ARGUMENT = 12;
|
|
887
|
+
const IO_ERROR_PERMISSION_DENIED = 13;
|
|
888
|
+
const IO_ERROR_RESOURCE_EXHAUSTED = 14;
|
|
889
|
+
const IO_ERROR_INAPPROPRIATE_TYPE = 15;
|
|
890
|
+
const IO_ERROR_NO_SUCH_THING = 16;
|
|
891
|
+
const IO_ERROR_USER = 18;
|
|
892
|
+
function lean_mk_io_user_error(msg) {
|
|
893
|
+
return lean_ctor(IO_ERROR_USER, 1, 0, 0, msg);
|
|
894
|
+
}
|
|
895
|
+
function mkIoError(tag, fname, code, details) {
|
|
896
|
+
const e = !(tag === IO_ERROR_ALREADY_EXISTS || tag >= IO_ERROR_INTERRUPTED && tag <= IO_ERROR_NO_SUCH_THING) ? lean_ctor(tag, 1, 0, 4, details) : tag === IO_ERROR_INTERRUPTED || tag === IO_ERROR_NO_FILE_OR_DIRECTORY ? lean_ctor(tag, 2, 0, 4, fname ?? "", details) : lean_ctor(tag, 2, 0, 4, fname === null ? 0 : lean_ctor(1, 1, 0, 0, fname), details);
|
|
897
|
+
e.sdata?.setUint32(0, code, true);
|
|
898
|
+
return e;
|
|
899
|
+
}
|
|
900
|
+
function lean_mk_io_error_unsupported_operation(details) {
|
|
901
|
+
return mkIoError(IO_ERROR_UNSUPPORTED_OPERATION, null, 0, details);
|
|
902
|
+
}
|
|
903
|
+
const UV_ERRORS = {
|
|
904
|
+
E2BIG: [IO_ERROR_RESOURCE_EXHAUSTED, "argument list too long"],
|
|
905
|
+
EACCES: [IO_ERROR_PERMISSION_DENIED, "permission denied"],
|
|
906
|
+
EADDRINUSE: [IO_ERROR_RESOURCE_BUSY, "address already in use"],
|
|
907
|
+
EADDRNOTAVAIL: [IO_ERROR_UNSUPPORTED_OPERATION, "address not available"],
|
|
908
|
+
EAFNOSUPPORT: [IO_ERROR_UNSUPPORTED_OPERATION, "address family not supported"],
|
|
909
|
+
EAGAIN: [IO_ERROR_RESOURCE_EXHAUSTED, "resource temporarily unavailable"],
|
|
910
|
+
EBADF: [IO_ERROR_INVALID_ARGUMENT, "bad file descriptor"],
|
|
911
|
+
EBUSY: [IO_ERROR_RESOURCE_BUSY, "resource busy or locked"],
|
|
912
|
+
ECONNABORTED: [IO_ERROR_PERMISSION_DENIED, "software caused connection abort"],
|
|
913
|
+
ECONNREFUSED: [IO_ERROR_NO_SUCH_THING, "connection refused"],
|
|
914
|
+
ECONNRESET: [IO_ERROR_RESOURCE_VANISHED, "connection reset by peer"],
|
|
915
|
+
EDESTADDRREQ: [IO_ERROR_INVALID_ARGUMENT, "destination address required"],
|
|
916
|
+
EEXIST: [IO_ERROR_ALREADY_EXISTS, "file already exists"],
|
|
917
|
+
EFAULT: [IO_ERROR_OTHER, "bad address in system call argument"],
|
|
918
|
+
EFBIG: [IO_ERROR_PERMISSION_DENIED, "file too large"],
|
|
919
|
+
EHOSTUNREACH: [IO_ERROR_NO_SUCH_THING, "host is unreachable"],
|
|
920
|
+
EILSEQ: [IO_ERROR_INVALID_ARGUMENT, "illegal byte sequence"],
|
|
921
|
+
EINTR: [IO_ERROR_INTERRUPTED, "interrupted system call"],
|
|
922
|
+
EINVAL: [IO_ERROR_INVALID_ARGUMENT, "invalid argument"],
|
|
923
|
+
EIO: [IO_ERROR_HARDWARE_FAULT, "i/o error"],
|
|
924
|
+
EISCONN: [IO_ERROR_ALREADY_EXISTS, "socket is already connected"],
|
|
925
|
+
EISDIR: [IO_ERROR_INAPPROPRIATE_TYPE, "illegal operation on a directory"],
|
|
926
|
+
ELOOP: [IO_ERROR_INVALID_ARGUMENT, "too many symbolic links encountered"],
|
|
927
|
+
EMFILE: [IO_ERROR_RESOURCE_EXHAUSTED, "too many open files"],
|
|
928
|
+
EMLINK: [IO_ERROR_RESOURCE_EXHAUSTED, "too many links"],
|
|
929
|
+
EMSGSIZE: [IO_ERROR_RESOURCE_EXHAUSTED, "message too long"],
|
|
930
|
+
ENAMETOOLONG: [IO_ERROR_INVALID_ARGUMENT, "name too long"],
|
|
931
|
+
ENETDOWN: [IO_ERROR_RESOURCE_VANISHED, "network is down"],
|
|
932
|
+
ENETUNREACH: [IO_ERROR_NO_SUCH_THING, "network is unreachable"],
|
|
933
|
+
ENFILE: [IO_ERROR_RESOURCE_EXHAUSTED, "file table overflow"],
|
|
934
|
+
ENOBUFS: [IO_ERROR_RESOURCE_EXHAUSTED, "no buffer space available"],
|
|
935
|
+
ENODEV: [IO_ERROR_UNSUPPORTED_OPERATION, "no such device"],
|
|
936
|
+
ENOENT: [IO_ERROR_NO_FILE_OR_DIRECTORY, "no such file or directory"],
|
|
937
|
+
ENOMEM: [IO_ERROR_RESOURCE_EXHAUSTED, "not enough memory"],
|
|
938
|
+
ENOPROTOOPT: [IO_ERROR_UNSUPPORTED_OPERATION, "protocol not available"],
|
|
939
|
+
ENOSPC: [IO_ERROR_RESOURCE_EXHAUSTED, "no space left on device"],
|
|
940
|
+
ENOSYS: [IO_ERROR_UNSUPPORTED_OPERATION, "function not implemented"],
|
|
941
|
+
ENOTCONN: [IO_ERROR_INVALID_ARGUMENT, "socket is not connected"],
|
|
942
|
+
ENOTDIR: [IO_ERROR_INAPPROPRIATE_TYPE, "not a directory"],
|
|
943
|
+
ENOTEMPTY: [IO_ERROR_UNSATISFIED_CONSTRAINTS, "directory not empty"],
|
|
944
|
+
ENOTSOCK: [IO_ERROR_INVALID_ARGUMENT, "socket operation on non-socket"],
|
|
945
|
+
ENOTTY: [IO_ERROR_ILLEGAL_OPERATION, "inappropriate ioctl for device"],
|
|
946
|
+
ENXIO: [IO_ERROR_NO_SUCH_THING, "no such device or address"],
|
|
947
|
+
EOPNOTSUPP: [IO_ERROR_UNSUPPORTED_OPERATION, "operation not supported on socket"],
|
|
948
|
+
EPERM: [IO_ERROR_PERMISSION_DENIED, "operation not permitted"],
|
|
949
|
+
EPIPE: [IO_ERROR_RESOURCE_VANISHED, "broken pipe"],
|
|
950
|
+
EPROTO: [IO_ERROR_PROTOCOL, "protocol error"],
|
|
951
|
+
EPROTONOSUPPORT: [IO_ERROR_PROTOCOL, "protocol not supported"],
|
|
952
|
+
EPROTOTYPE: [IO_ERROR_PROTOCOL, "protocol wrong type for socket"],
|
|
953
|
+
ERANGE: [IO_ERROR_UNSUPPORTED_OPERATION, "result too large"],
|
|
954
|
+
EROFS: [IO_ERROR_PERMISSION_DENIED, "read-only file system"],
|
|
955
|
+
ESPIPE: [IO_ERROR_UNSUPPORTED_OPERATION, "invalid seek"],
|
|
956
|
+
ESRCH: [IO_ERROR_NO_SUCH_THING, "no such process"],
|
|
957
|
+
ETIMEDOUT: [IO_ERROR_TIME_EXPIRED, "connection timed out"],
|
|
958
|
+
ETXTBSY: [IO_ERROR_RESOURCE_BUSY, "text file is busy"],
|
|
959
|
+
EXDEV: [IO_ERROR_UNSUPPORTED_OPERATION, "cross-device link not permitted"],
|
|
960
|
+
ENODATA: [IO_ERROR_NO_SUCH_THING, "no data available"]
|
|
961
|
+
};
|
|
962
|
+
function systemError(e) {
|
|
963
|
+
if (!(e instanceof Error)) return null;
|
|
964
|
+
const code = Reflect.get(e, "code");
|
|
965
|
+
const errno = Reflect.get(e, "errno");
|
|
966
|
+
return typeof code === "string" && typeof errno === "number" ? {
|
|
967
|
+
code,
|
|
968
|
+
errno
|
|
969
|
+
} : null;
|
|
970
|
+
}
|
|
971
|
+
function ioErrorOf(e, fname) {
|
|
972
|
+
if (e instanceof Error && e.name === "UnsupportedOperation") return lean_mk_io_error_unsupported_operation(e.message);
|
|
973
|
+
const sys = systemError(e);
|
|
974
|
+
if (sys !== null) {
|
|
975
|
+
const [tag, details] = UV_ERRORS[sys.code] ?? [IO_ERROR_OTHER, `Unknown system error ${sys.errno}`];
|
|
976
|
+
return mkIoError(tag, fname, -sys.errno, details);
|
|
977
|
+
}
|
|
978
|
+
return lean_mk_io_user_error(String(e instanceof Error ? e.message : e));
|
|
979
|
+
}
|
|
980
|
+
function decap(t) {
|
|
981
|
+
return t.length === 0 ? t : t.charAt(0).toLowerCase() + t.slice(1);
|
|
982
|
+
}
|
|
983
|
+
function osCode(e) {
|
|
984
|
+
const data = asCtor(e).sdata;
|
|
985
|
+
if (data === null) throw new TypeError("leanfran runtime: IO.Error without an osCode");
|
|
986
|
+
return data.getUint32(0, true);
|
|
987
|
+
}
|
|
988
|
+
function detailsOf(e) {
|
|
989
|
+
const fields = asCtor(e).fields;
|
|
990
|
+
return asString(fields[fields.length - 1]);
|
|
991
|
+
}
|
|
992
|
+
function optFn(e) {
|
|
993
|
+
const o = asCtor(e).fields[0];
|
|
994
|
+
return lean_tag(o) === 0 ? null : asString(asCtor(o).fields[0]);
|
|
995
|
+
}
|
|
996
|
+
function ioDetails(code, d) {
|
|
997
|
+
return " (error code: " + String(code) + (d !== null ? ", " + decap(d) : "") + ")";
|
|
998
|
+
}
|
|
999
|
+
function ioFopen(gist, fn, code, d) {
|
|
1000
|
+
return decap(gist) + ioDetails(code, d) + "\n file: " + fn;
|
|
1001
|
+
}
|
|
1002
|
+
function ioOther(gist, code, d) {
|
|
1003
|
+
return decap(gist) + ioDetails(code, d);
|
|
1004
|
+
}
|
|
1005
|
+
function withFile(gist, e) {
|
|
1006
|
+
const fn = optFn(e);
|
|
1007
|
+
return fn !== null ? ioFopen(gist, fn, osCode(e), detailsOf(e)) : ioOther(gist, osCode(e), detailsOf(e));
|
|
1008
|
+
}
|
|
1009
|
+
function lean_io_error_to_string(e) {
|
|
1010
|
+
switch (lean_tag(e)) {
|
|
1011
|
+
case IO_ERROR_ALREADY_EXISTS: return withFile("already exists", e);
|
|
1012
|
+
case IO_ERROR_OTHER: return ioOther(detailsOf(e), osCode(e), null);
|
|
1013
|
+
case IO_ERROR_RESOURCE_BUSY: return ioOther("resource busy", osCode(e), detailsOf(e));
|
|
1014
|
+
case IO_ERROR_RESOURCE_VANISHED: return ioOther("resource vanished", osCode(e), detailsOf(e));
|
|
1015
|
+
case IO_ERROR_UNSUPPORTED_OPERATION: return ioOther("unsupported operation", osCode(e), detailsOf(e));
|
|
1016
|
+
case IO_ERROR_HARDWARE_FAULT: return ioOther("hardware fault", osCode(e), null);
|
|
1017
|
+
case IO_ERROR_UNSATISFIED_CONSTRAINTS: return ioOther("directory not empty", osCode(e), null);
|
|
1018
|
+
case IO_ERROR_ILLEGAL_OPERATION: return ioOther("illegal operation", osCode(e), detailsOf(e));
|
|
1019
|
+
case IO_ERROR_PROTOCOL: return ioOther("protocol error", osCode(e), detailsOf(e));
|
|
1020
|
+
case IO_ERROR_TIME_EXPIRED: return ioOther("time expired", osCode(e), detailsOf(e));
|
|
1021
|
+
case IO_ERROR_INTERRUPTED: return ioFopen("interrupted system call", asString(asCtor(e).fields[0]), osCode(e), detailsOf(e));
|
|
1022
|
+
case IO_ERROR_NO_FILE_OR_DIRECTORY: return ioFopen("no such file or directory", asString(asCtor(e).fields[0]), osCode(e), null);
|
|
1023
|
+
case IO_ERROR_INVALID_ARGUMENT: return withFile("invalid argument", e);
|
|
1024
|
+
case IO_ERROR_PERMISSION_DENIED: {
|
|
1025
|
+
const fn = optFn(e);
|
|
1026
|
+
return fn !== null ? ioFopen(detailsOf(e), fn, osCode(e), null) : ioOther(detailsOf(e), osCode(e), null);
|
|
1027
|
+
}
|
|
1028
|
+
case IO_ERROR_RESOURCE_EXHAUSTED: return withFile("resource exhausted", e);
|
|
1029
|
+
case IO_ERROR_INAPPROPRIATE_TYPE: return withFile("inappropriate type", e);
|
|
1030
|
+
case IO_ERROR_NO_SUCH_THING: return withFile("no such thing", e);
|
|
1031
|
+
case 17: return "end of file";
|
|
1032
|
+
case IO_ERROR_USER: return asString(asCtor(e).fields[0]);
|
|
1033
|
+
default: throw new TypeError(`leanfran runtime: IO.Error has no constructor ${lean_tag(e)}`);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
function mkStream(fields) {
|
|
1037
|
+
return lean_ctor(0, 6, 0, 0, ...fields);
|
|
1038
|
+
}
|
|
1039
|
+
function mkWriteStream(fd, write) {
|
|
1040
|
+
return mkStream([
|
|
1041
|
+
() => lean_io_result_mk_ok(0),
|
|
1042
|
+
(_n) => lean_io_result_mk_ok(/* @__PURE__ */ new Uint8Array(0)),
|
|
1043
|
+
(buf) => {
|
|
1044
|
+
write(asBytes(buf));
|
|
1045
|
+
return lean_io_result_mk_ok(0);
|
|
1046
|
+
},
|
|
1047
|
+
() => lean_io_result_mk_ok(""),
|
|
1048
|
+
(s) => {
|
|
1049
|
+
write(asString(s));
|
|
1050
|
+
return lean_io_result_mk_ok(0);
|
|
1051
|
+
},
|
|
1052
|
+
() => lean_bool(platform.isTty(fd))
|
|
1053
|
+
]);
|
|
1054
|
+
}
|
|
1055
|
+
function readLine(fd) {
|
|
1056
|
+
const bytes = [];
|
|
1057
|
+
const one = /* @__PURE__ */ new Uint8Array(1);
|
|
1058
|
+
for (;;) {
|
|
1059
|
+
if (platform.readFd(fd, one) === 0) break;
|
|
1060
|
+
const c = one[0] ?? 0;
|
|
1061
|
+
bytes.push(c);
|
|
1062
|
+
if (c === 10) break;
|
|
1063
|
+
}
|
|
1064
|
+
return decodeUtf8(Uint8Array.from(bytes));
|
|
1065
|
+
}
|
|
1066
|
+
function readBytes(fd, n) {
|
|
1067
|
+
const buf = new Uint8Array(n);
|
|
1068
|
+
const got = platform.readFd(fd, buf);
|
|
1069
|
+
return buf.slice(0, got);
|
|
1070
|
+
}
|
|
1071
|
+
function ioAction(act, fname = null) {
|
|
1072
|
+
try {
|
|
1073
|
+
return lean_io_result_mk_ok(act());
|
|
1074
|
+
} catch (e) {
|
|
1075
|
+
return lean_io_result_mk_error(ioErrorOf(e, fname));
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
function mkStdinStream() {
|
|
1079
|
+
return mkStream([
|
|
1080
|
+
() => lean_io_result_mk_ok(0),
|
|
1081
|
+
(n) => ioAction(() => readBytes(0, Number(n))),
|
|
1082
|
+
(_b) => lean_io_result_mk_ok(0),
|
|
1083
|
+
() => ioAction(() => readLine(0)),
|
|
1084
|
+
(_s) => lean_io_result_mk_ok(0),
|
|
1085
|
+
() => lean_bool(platform.isTty(0))
|
|
1086
|
+
]);
|
|
1087
|
+
}
|
|
1088
|
+
let stdoutStream = mkWriteStream(1, (x) => platform.writeStdout(x));
|
|
1089
|
+
let stderrStream = mkWriteStream(2, (x) => platform.writeStderr(x));
|
|
1090
|
+
let stdinStream = mkStdinStream();
|
|
1091
|
+
function lean_get_stdout() {
|
|
1092
|
+
lean_inc(stdoutStream);
|
|
1093
|
+
return stdoutStream;
|
|
1094
|
+
}
|
|
1095
|
+
function lean_get_stderr() {
|
|
1096
|
+
lean_inc(stderrStream);
|
|
1097
|
+
return stderrStream;
|
|
1098
|
+
}
|
|
1099
|
+
function lean_get_stdin() {
|
|
1100
|
+
lean_inc(stdinStream);
|
|
1101
|
+
return stdinStream;
|
|
1102
|
+
}
|
|
1103
|
+
function lean_get_set_stdout(s) {
|
|
1104
|
+
const p = stdoutStream;
|
|
1105
|
+
stdoutStream = s;
|
|
1106
|
+
return p;
|
|
1107
|
+
}
|
|
1108
|
+
function lean_get_set_stderr(s) {
|
|
1109
|
+
const p = stderrStream;
|
|
1110
|
+
stderrStream = s;
|
|
1111
|
+
return p;
|
|
1112
|
+
}
|
|
1113
|
+
function lean_get_set_stdin(s) {
|
|
1114
|
+
const p = stdinStream;
|
|
1115
|
+
stdinStream = s;
|
|
1116
|
+
return p;
|
|
1117
|
+
}
|
|
1118
|
+
function lean_io_eprint(s) {
|
|
1119
|
+
platform.writeStderr(asString(s));
|
|
1120
|
+
return lean_io_result_mk_ok(0);
|
|
1121
|
+
}
|
|
1122
|
+
function lean_io_eprintln(s) {
|
|
1123
|
+
platform.writeStderr(asString(s) + "\n");
|
|
1124
|
+
return lean_io_result_mk_ok(0);
|
|
1125
|
+
}
|
|
1126
|
+
function lean_st_mk_ref(a) {
|
|
1127
|
+
return { value: a };
|
|
1128
|
+
}
|
|
1129
|
+
function lean_st_ref_get(r) {
|
|
1130
|
+
const v = asRef(r).value;
|
|
1131
|
+
lean_inc(v);
|
|
1132
|
+
return v;
|
|
1133
|
+
}
|
|
1134
|
+
function lean_st_ref_set(r, a) {
|
|
1135
|
+
lean_dec(asRef(r).value);
|
|
1136
|
+
asRef(r).value = a;
|
|
1137
|
+
return 0;
|
|
1138
|
+
}
|
|
1139
|
+
function lean_st_ref_swap(r, a) {
|
|
1140
|
+
const o = asRef(r).value;
|
|
1141
|
+
asRef(r).value = a;
|
|
1142
|
+
return o;
|
|
1143
|
+
}
|
|
1144
|
+
function lean_st_ref_take(r) {
|
|
1145
|
+
const o = asRef(r).value;
|
|
1146
|
+
asRef(r).value = void 0;
|
|
1147
|
+
return o;
|
|
1148
|
+
}
|
|
1149
|
+
function lean_st_ref_put(r, a) {
|
|
1150
|
+
return lean_st_ref_set(r, a);
|
|
1151
|
+
}
|
|
1152
|
+
function lean_st_ref_ptr_eq(r1, r2) {
|
|
1153
|
+
return r1 === r2 ? 1 : 0;
|
|
1154
|
+
}
|
|
1155
|
+
function lean_io_getenv(name) {
|
|
1156
|
+
const v = platform.getenv(asString(name));
|
|
1157
|
+
return v === void 0 ? 0 : lean_ctor(1, 1, 0, 0, v);
|
|
1158
|
+
}
|
|
1159
|
+
function lean_io_exit(code) {
|
|
1160
|
+
return platform.exit(code & 255);
|
|
1161
|
+
}
|
|
1162
|
+
function lean_io_force_exit(code) {
|
|
1163
|
+
return platform.exit(code & 255);
|
|
1164
|
+
}
|
|
1165
|
+
const MODE_FLAG = [
|
|
1166
|
+
"r",
|
|
1167
|
+
"w",
|
|
1168
|
+
"wx",
|
|
1169
|
+
"r+",
|
|
1170
|
+
"a"
|
|
1171
|
+
];
|
|
1172
|
+
function lean_io_prim_handle_mk(path, mode) {
|
|
1173
|
+
const p = asString(path);
|
|
1174
|
+
return ioAction(() => ({ fd: platform.openFile(p, MODE_FLAG[mode] ?? "r") }), p);
|
|
1175
|
+
}
|
|
1176
|
+
function lean_io_prim_handle_put_str(h, s) {
|
|
1177
|
+
return ioAction(() => {
|
|
1178
|
+
platform.writeFd(asHandle(h).fd, encodeUtf8(asString(s)));
|
|
1179
|
+
return 0;
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
function lean_io_prim_handle_write(h, buf) {
|
|
1183
|
+
return ioAction(() => {
|
|
1184
|
+
platform.writeFd(asHandle(h).fd, asBytes(buf));
|
|
1185
|
+
return 0;
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
function lean_io_prim_handle_read(h, n) {
|
|
1189
|
+
return ioAction(() => readBytes(asHandle(h).fd, Number(n)));
|
|
1190
|
+
}
|
|
1191
|
+
function lean_io_prim_handle_flush(_h) {
|
|
1192
|
+
return lean_io_result_mk_ok(0);
|
|
1193
|
+
}
|
|
1194
|
+
function lean_io_prim_handle_is_tty(h) {
|
|
1195
|
+
return lean_bool(platform.isTty(asHandle(h).fd));
|
|
1196
|
+
}
|
|
1197
|
+
function lean_io_prim_handle_get_line(h) {
|
|
1198
|
+
return ioAction(() => readLine(asHandle(h).fd));
|
|
1199
|
+
}
|
|
1200
|
+
function lean_io_result_show_error(res) {
|
|
1201
|
+
platform.writeStderr("uncaught exception: " + lean_io_error_to_string(lean_io_result_get_error(res)) + "\n");
|
|
1202
|
+
}
|
|
1203
|
+
function lean_dbg_trace(s, fn) {
|
|
1204
|
+
platform.writeStderr(asString(s) + "\n");
|
|
1205
|
+
return lean_trampoline(lean_apply(fn, [0]));
|
|
1206
|
+
}
|
|
1207
|
+
function lean_dbg_trace_if_shared(s, a) {
|
|
1208
|
+
if (typeof a === "object" && a !== null && "rc" in a && typeof a.rc === "number" && a.rc > 1) platform.writeStderr(`shared RC ${asString(s)}\n`);
|
|
1209
|
+
return a;
|
|
1210
|
+
}
|
|
1211
|
+
function lean_dbg_sleep(_ms, fn) {
|
|
1212
|
+
return lean_trampoline(lean_apply(fn, [0]));
|
|
1213
|
+
}
|
|
1214
|
+
function lean_ptr_addr(_a) {
|
|
1215
|
+
return 0n;
|
|
1216
|
+
}
|
|
1217
|
+
function lean_is_exclusive_obj(a) {
|
|
1218
|
+
return lean_is_exclusive(a) ? 1 : 0;
|
|
1219
|
+
}
|
|
1220
|
+
const initThunks = [];
|
|
1221
|
+
let initialized = false;
|
|
1222
|
+
function lean_register_init(thunk) {
|
|
1223
|
+
initThunks.push(thunk);
|
|
1224
|
+
}
|
|
1225
|
+
function lean_run_init() {
|
|
1226
|
+
if (initialized) return lean_io_result_mk_ok(0);
|
|
1227
|
+
initialized = true;
|
|
1228
|
+
for (const t of initThunks) {
|
|
1229
|
+
const res = t();
|
|
1230
|
+
if (!lean_io_result_is_ok(res)) return res;
|
|
1231
|
+
}
|
|
1232
|
+
return lean_io_result_mk_ok(0);
|
|
1233
|
+
}
|
|
1234
|
+
function lean_run_main(mainFn, hasArgs, retIsU32) {
|
|
1235
|
+
let res = lean_run_init();
|
|
1236
|
+
if (lean_io_result_is_ok(res)) {
|
|
1237
|
+
if (hasArgs) {
|
|
1238
|
+
const args = platform.argv().reduceRight((tl, s) => lean_ctor(1, 2, 0, 0, s, tl), 0);
|
|
1239
|
+
res = Reflect.apply(mainFn, void 0, [args]);
|
|
1240
|
+
} else res = Reflect.apply(mainFn, void 0, []);
|
|
1241
|
+
}
|
|
1242
|
+
if (lean_io_result_is_ok(res)) {
|
|
1243
|
+
const v = lean_io_result_get_value(res);
|
|
1244
|
+
platform.setExitCode(retIsU32 ? Number(v) & 255 : 0);
|
|
1245
|
+
} else {
|
|
1246
|
+
lean_io_result_show_error(res);
|
|
1247
|
+
platform.setExitCode(1);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
// src/runtime/marshal.ts
|
|
1251
|
+
const natDesc = { kind: "nat" };
|
|
1252
|
+
const intDesc = { kind: "int" };
|
|
1253
|
+
const boolDesc = { kind: "bool" };
|
|
1254
|
+
const charDesc = { kind: "char" };
|
|
1255
|
+
const stringDesc = { kind: "string" };
|
|
1256
|
+
const floatDesc = { kind: "float" };
|
|
1257
|
+
const float32Desc = { kind: "float32" };
|
|
1258
|
+
const unitDesc = { kind: "unit" };
|
|
1259
|
+
const usizeDesc = { kind: "usize" };
|
|
1260
|
+
const isizeDesc = { kind: "isize" };
|
|
1261
|
+
function uintDesc(bits) {
|
|
1262
|
+
return {
|
|
1263
|
+
kind: "uint",
|
|
1264
|
+
bits
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
function sintDesc(bits) {
|
|
1268
|
+
return {
|
|
1269
|
+
kind: "sint",
|
|
1270
|
+
bits
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
function listDesc(item) {
|
|
1274
|
+
return {
|
|
1275
|
+
kind: "list",
|
|
1276
|
+
item
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
function arrayDesc(item) {
|
|
1280
|
+
return {
|
|
1281
|
+
kind: "array",
|
|
1282
|
+
item
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
function optionDesc(item, absent) {
|
|
1286
|
+
return {
|
|
1287
|
+
kind: "option",
|
|
1288
|
+
item,
|
|
1289
|
+
absent
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
function prodDesc(fst, snd) {
|
|
1293
|
+
return {
|
|
1294
|
+
kind: "prod",
|
|
1295
|
+
fst,
|
|
1296
|
+
snd
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
function exceptDesc(error, value) {
|
|
1300
|
+
return {
|
|
1301
|
+
kind: "except",
|
|
1302
|
+
error,
|
|
1303
|
+
value
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function finDesc(bound) {
|
|
1307
|
+
return {
|
|
1308
|
+
kind: "fin",
|
|
1309
|
+
bound
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
function refDesc(get) {
|
|
1313
|
+
return {
|
|
1314
|
+
kind: "ref",
|
|
1315
|
+
get
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function typeDesc(node) {
|
|
1319
|
+
return node;
|
|
1320
|
+
}
|
|
1321
|
+
function modelDesc(key, name, struct) {
|
|
1322
|
+
return {
|
|
1323
|
+
kind: "model",
|
|
1324
|
+
key,
|
|
1325
|
+
name,
|
|
1326
|
+
struct
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
var LeanValidationError = class extends Error {
|
|
1330
|
+
issues;
|
|
1331
|
+
constructor(issues) {
|
|
1332
|
+
super(issues.map((i) => `${i.path.map(String).join(".")}: ${i.message}`).join("\n"));
|
|
1333
|
+
this.name = "LeanValidationError";
|
|
1334
|
+
this.issues = issues;
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const IO_ERROR_CTORS = [
|
|
1338
|
+
"alreadyExists",
|
|
1339
|
+
"otherError",
|
|
1340
|
+
"resourceBusy",
|
|
1341
|
+
"resourceVanished",
|
|
1342
|
+
"unsupportedOperation",
|
|
1343
|
+
"hardwareFault",
|
|
1344
|
+
"unsatisfiedConstraints",
|
|
1345
|
+
"illegalOperation",
|
|
1346
|
+
"protocolError",
|
|
1347
|
+
"timeExpired",
|
|
1348
|
+
"interrupted",
|
|
1349
|
+
"noFileOrDirectory",
|
|
1350
|
+
"invalidArgument",
|
|
1351
|
+
"permissionDenied",
|
|
1352
|
+
"resourceExhausted",
|
|
1353
|
+
"inappropriateType",
|
|
1354
|
+
"noSuchThing",
|
|
1355
|
+
"unexpectedEof",
|
|
1356
|
+
"userError"
|
|
1357
|
+
];
|
|
1358
|
+
function ioErrorCtor(tag) {
|
|
1359
|
+
const name = IO_ERROR_CTORS[tag];
|
|
1360
|
+
if (name === void 0) throw new TypeError(`leanfran runtime: IO.Error has no constructor ${tag}`);
|
|
1361
|
+
return name;
|
|
1362
|
+
}
|
|
1363
|
+
var LeanIOError = class extends Error {
|
|
1364
|
+
code;
|
|
1365
|
+
constructor(error) {
|
|
1366
|
+
super(lean_io_error_to_string(error));
|
|
1367
|
+
this.name = "LeanIOError";
|
|
1368
|
+
this.code = ioErrorCtor(lean_tag(error));
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
const LONE_SURROGATE = /[\uD800-\uDFFF]/u;
|
|
1372
|
+
const DECIMAL = /^-?(?:0|[1-9][0-9]*)$/u;
|
|
1373
|
+
function unreachable(d) {
|
|
1374
|
+
throw new TypeError(`leanfran runtime: unknown type descriptor ${JSON.stringify(d)}`);
|
|
1375
|
+
}
|
|
1376
|
+
function resolve(d) {
|
|
1377
|
+
let cur = d;
|
|
1378
|
+
while (cur.kind === "ref") cur = cur.get();
|
|
1379
|
+
return cur;
|
|
1380
|
+
}
|
|
1381
|
+
function expected(d) {
|
|
1382
|
+
switch (d.kind) {
|
|
1383
|
+
case "nat": return "a natural number (a non-negative bigint or safe integer)";
|
|
1384
|
+
case "int": return "an integer (a bigint or safe integer)";
|
|
1385
|
+
case "uint": return d.bits === 64 ? "a UInt64 (a bigint)" : `a UInt${d.bits} (an integer number)`;
|
|
1386
|
+
case "sint": return d.bits === 64 ? "an Int64 (a bigint)" : `an Int${d.bits} (an integer number)`;
|
|
1387
|
+
case "usize": return "a USize (a bigint)";
|
|
1388
|
+
case "isize": return "an ISize (a bigint)";
|
|
1389
|
+
case "bool": return "a boolean";
|
|
1390
|
+
case "char": return "a Char (a string of one Unicode scalar value)";
|
|
1391
|
+
case "string": return "a string without lone surrogates";
|
|
1392
|
+
case "float":
|
|
1393
|
+
case "float32": return "a number";
|
|
1394
|
+
case "unit": return "undefined";
|
|
1395
|
+
case "list":
|
|
1396
|
+
case "array": return "an array";
|
|
1397
|
+
case "option": return d.absent === "null" ? "a value or null" : "a value or undefined";
|
|
1398
|
+
case "prod": return "an array of two elements";
|
|
1399
|
+
case "except": return "an object { ok: true, value } or { ok: false, error }";
|
|
1400
|
+
case "fin": return `a natural number below ${d.bound}`;
|
|
1401
|
+
case "struct": return `an object ${d.name}`;
|
|
1402
|
+
case "enum": return `one of ${d.ctors.map((c) => JSON.stringify(c)).join(", ")}`;
|
|
1403
|
+
case "inductive": return `a ${d.name} (an object with a constructor name in ${JSON.stringify(d.tagKey)}, or its JSON form)`;
|
|
1404
|
+
case "subtype": return expected(d.base);
|
|
1405
|
+
case "model": return `a ${d.name}`;
|
|
1406
|
+
case "ref": return expected(d.get());
|
|
1407
|
+
}
|
|
1408
|
+
return unreachable(d);
|
|
1409
|
+
}
|
|
1410
|
+
function integer(v, json) {
|
|
1411
|
+
if (typeof v === "bigint") return v;
|
|
1412
|
+
if (typeof v === "number" && Number.isSafeInteger(v)) return BigInt(v);
|
|
1413
|
+
if (json && typeof v === "string" && DECIMAL.test(v)) return BigInt(v);
|
|
1414
|
+
return null;
|
|
1415
|
+
}
|
|
1416
|
+
function inRange(v, bits, signed, big, json) {
|
|
1417
|
+
const i = big || json ? integer(v, json) : typeof v === "number" && Number.isInteger(v) ? BigInt(v) : null;
|
|
1418
|
+
if (i === null || big && !json && typeof v !== "bigint") return null;
|
|
1419
|
+
const n = BigInt(bits);
|
|
1420
|
+
const lo = signed ? -(1n << n - 1n) : 0n;
|
|
1421
|
+
const hi = signed ? 1n << n - 1n : 1n << n;
|
|
1422
|
+
return i >= lo && i < hi ? i : null;
|
|
1423
|
+
}
|
|
1424
|
+
function isObject(v) {
|
|
1425
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1426
|
+
}
|
|
1427
|
+
function record(v, key) {
|
|
1428
|
+
if (typeof v !== "object" || v === null || !Object.hasOwn(v, key)) return {
|
|
1429
|
+
found: false,
|
|
1430
|
+
value: void 0
|
|
1431
|
+
};
|
|
1432
|
+
return {
|
|
1433
|
+
found: true,
|
|
1434
|
+
value: Reflect.get(v, key)
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
function charCode(v) {
|
|
1438
|
+
if (typeof v !== "string") return null;
|
|
1439
|
+
const cp = v.codePointAt(0);
|
|
1440
|
+
if (cp === void 0 || String.fromCodePoint(cp) !== v || cp >= 55296 && cp <= 57343) return null;
|
|
1441
|
+
return cp;
|
|
1442
|
+
}
|
|
1443
|
+
function floatValue(v, json) {
|
|
1444
|
+
if (typeof v === "number") return v;
|
|
1445
|
+
if (!json) return null;
|
|
1446
|
+
if (typeof v === "bigint") return Number(v);
|
|
1447
|
+
if (v === "NaN") return NaN;
|
|
1448
|
+
if (v === "Infinity") return Number.POSITIVE_INFINITY;
|
|
1449
|
+
if (v === "-Infinity") return Number.NEGATIVE_INFINITY;
|
|
1450
|
+
return null;
|
|
1451
|
+
}
|
|
1452
|
+
function isUnit(v, json) {
|
|
1453
|
+
return v === void 0 || json && isObject(v) && Object.keys(v).length === 0;
|
|
1454
|
+
}
|
|
1455
|
+
function isAbsent(v, absent, json) {
|
|
1456
|
+
if (json) return v === null || v === void 0;
|
|
1457
|
+
return absent === "null" ? v === null : v === void 0;
|
|
1458
|
+
}
|
|
1459
|
+
function objectInputs(variant, v, path) {
|
|
1460
|
+
return variant.fields.map((f) => f.flat ? {
|
|
1461
|
+
value: v,
|
|
1462
|
+
path
|
|
1463
|
+
} : {
|
|
1464
|
+
value: record(v, f.key).value,
|
|
1465
|
+
path: [...path, f.key]
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
function jsonInputs(variant, payload, path) {
|
|
1469
|
+
const at = [...path, variant.name];
|
|
1470
|
+
if (!variant.positional) return isObject(payload) ? objectInputs(variant, payload, at) : null;
|
|
1471
|
+
if (variant.fields.length === 1) return [{
|
|
1472
|
+
value: payload,
|
|
1473
|
+
path: at
|
|
1474
|
+
}];
|
|
1475
|
+
if (!Array.isArray(payload) || payload.length !== variant.fields.length) return null;
|
|
1476
|
+
return payload.map((value, i) => ({
|
|
1477
|
+
value,
|
|
1478
|
+
path: [...at, i]
|
|
1479
|
+
}));
|
|
1480
|
+
}
|
|
1481
|
+
function pick(d, v, path, json) {
|
|
1482
|
+
const tag = record(v, d.tagKey);
|
|
1483
|
+
if (isObject(v) && typeof tag.value === "string") {
|
|
1484
|
+
const variant = d.variants.find((x) => x.name === tag.value);
|
|
1485
|
+
if (variant !== void 0) return {
|
|
1486
|
+
variant,
|
|
1487
|
+
inputs: objectInputs(variant, v, path)
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
if (!json) return null;
|
|
1491
|
+
if (typeof v === "string") {
|
|
1492
|
+
const variant = d.variants.find((x) => x.name === v && x.fields.length === 0);
|
|
1493
|
+
return variant === void 0 ? null : {
|
|
1494
|
+
variant,
|
|
1495
|
+
inputs: []
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
if (!isObject(v)) return null;
|
|
1499
|
+
const keys = Object.keys(v);
|
|
1500
|
+
const only = keys[0];
|
|
1501
|
+
if (keys.length !== 1 || only === void 0) return null;
|
|
1502
|
+
const variant = d.variants.find((x) => x.name === only && x.fields.length !== 0);
|
|
1503
|
+
if (variant === void 0) return null;
|
|
1504
|
+
const inputs = jsonInputs(variant, Reflect.get(v, only), path);
|
|
1505
|
+
return inputs === null ? null : {
|
|
1506
|
+
variant,
|
|
1507
|
+
inputs
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
function store(c, f, x) {
|
|
1511
|
+
switch (f.slot) {
|
|
1512
|
+
case "obj":
|
|
1513
|
+
c.fields[f.at] = x;
|
|
1514
|
+
return;
|
|
1515
|
+
case "usize":
|
|
1516
|
+
lean_ctor_uset(c, f.at, asNat(x));
|
|
1517
|
+
return;
|
|
1518
|
+
case "u8":
|
|
1519
|
+
lean_ctor_set_u8(c, f.at, lean_unbox(x));
|
|
1520
|
+
return;
|
|
1521
|
+
case "u16":
|
|
1522
|
+
lean_ctor_set_u16(c, f.at, lean_unbox(x));
|
|
1523
|
+
return;
|
|
1524
|
+
case "u32":
|
|
1525
|
+
lean_ctor_set_u32(c, f.at, lean_unbox(x));
|
|
1526
|
+
return;
|
|
1527
|
+
case "u64":
|
|
1528
|
+
lean_ctor_set_u64(c, f.at, asNat(x));
|
|
1529
|
+
return;
|
|
1530
|
+
case "f64":
|
|
1531
|
+
lean_ctor_set_f64(c, f.at, lean_unbox(x));
|
|
1532
|
+
return;
|
|
1533
|
+
case "f32":
|
|
1534
|
+
lean_ctor_set_f32(c, f.at, lean_unbox(x));
|
|
1535
|
+
return;
|
|
1536
|
+
case "none": return;
|
|
1537
|
+
}
|
|
1538
|
+
unreachable(f.slot);
|
|
1539
|
+
}
|
|
1540
|
+
function load(x, f) {
|
|
1541
|
+
switch (f.slot) {
|
|
1542
|
+
case "obj": return lean_ctor_get(x, f.at);
|
|
1543
|
+
case "usize": return lean_ctor_uget(x, f.at);
|
|
1544
|
+
case "u8": return lean_ctor_get_u8(x, f.at);
|
|
1545
|
+
case "u16": return lean_ctor_get_u16(x, f.at);
|
|
1546
|
+
case "u32": return lean_ctor_get_u32(x, f.at);
|
|
1547
|
+
case "u64": return lean_ctor_get_u64(x, f.at);
|
|
1548
|
+
case "f64": return lean_ctor_get_f64(x, f.at);
|
|
1549
|
+
case "f32": return lean_ctor_get_f32(x, f.at);
|
|
1550
|
+
case "none": return 0;
|
|
1551
|
+
}
|
|
1552
|
+
return unreachable(f.slot);
|
|
1553
|
+
}
|
|
1554
|
+
function build(variant, values) {
|
|
1555
|
+
if (variant.size === 0 && variant.usize === 0 && variant.ssize === 0) return variant.cidx;
|
|
1556
|
+
const c = lean_alloc_ctor(variant.cidx, variant.size, variant.usize, variant.ssize);
|
|
1557
|
+
variant.fields.forEach((f, i) => store(c, f, values[i]));
|
|
1558
|
+
return c;
|
|
1559
|
+
}
|
|
1560
|
+
function checkInvariants(owner, variant, values, path, issues) {
|
|
1561
|
+
for (const inv of variant.invariants) if (!inv.decide(...inv.args.map((i) => shared(values[i])))) issues.push({
|
|
1562
|
+
message: `${owner}.${inv.field}: ${inv.prop}`,
|
|
1563
|
+
path
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
function ownerName(d, v) {
|
|
1567
|
+
return d.kind === "struct" ? d.name : `${d.name}.${v.name}`;
|
|
1568
|
+
}
|
|
1569
|
+
function segment(p) {
|
|
1570
|
+
if (typeof p === "string" || typeof p === "number" || typeof p === "symbol") return p;
|
|
1571
|
+
const key = record(p, "key").value;
|
|
1572
|
+
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") return key;
|
|
1573
|
+
return String(key);
|
|
1574
|
+
}
|
|
1575
|
+
function standardValidate(schema, value) {
|
|
1576
|
+
const std = record(schema, "~standard").value;
|
|
1577
|
+
const validate = record(std, "validate").value;
|
|
1578
|
+
if (typeof validate !== "function") throw new TypeError("leanfran runtime: the model is not a Standard Schema");
|
|
1579
|
+
const r = Reflect.apply(validate, std, [value]);
|
|
1580
|
+
if (r instanceof Promise) throw new TypeError("leanfran runtime: the model's ~standard.validate returned a Promise");
|
|
1581
|
+
const issues = record(r, "issues").value;
|
|
1582
|
+
if (Array.isArray(issues)) return {
|
|
1583
|
+
value: void 0,
|
|
1584
|
+
issues: issues.map((i) => {
|
|
1585
|
+
const p = record(i, "path").value;
|
|
1586
|
+
const segments = Array.isArray(p) ? p : [];
|
|
1587
|
+
return {
|
|
1588
|
+
message: String(record(i, "message").value),
|
|
1589
|
+
path: segments.map(segment)
|
|
1590
|
+
};
|
|
1591
|
+
})
|
|
1592
|
+
};
|
|
1593
|
+
return {
|
|
1594
|
+
value: record(r, "value").value,
|
|
1595
|
+
issues: null
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function modelSchema(d) {
|
|
1599
|
+
const s = blockRegistry().models.get(d.key);
|
|
1600
|
+
if (s === void 0) throw new TypeError(`leanfran runtime: the model ${d.name} (${d.key}) is not registered; the lean(...) block that declares it has not run`);
|
|
1601
|
+
return s;
|
|
1602
|
+
}
|
|
1603
|
+
function runModel(d, v, path, issues) {
|
|
1604
|
+
const r = standardValidate(modelSchema(d), v);
|
|
1605
|
+
if (r.issues !== null) {
|
|
1606
|
+
for (const i of r.issues) issues.push({
|
|
1607
|
+
message: i.message,
|
|
1608
|
+
path: [...path, ...i.path]
|
|
1609
|
+
});
|
|
1610
|
+
return {
|
|
1611
|
+
ok: false,
|
|
1612
|
+
value: void 0
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
return {
|
|
1616
|
+
ok: true,
|
|
1617
|
+
value: r.value
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
function shared(x) {
|
|
1621
|
+
lean_inc(x);
|
|
1622
|
+
return x;
|
|
1623
|
+
}
|
|
1624
|
+
function encode(d, v, path, cx) {
|
|
1625
|
+
const bad = () => {
|
|
1626
|
+
cx.issues.push({
|
|
1627
|
+
message: `expected ${expected(d)}`,
|
|
1628
|
+
path
|
|
1629
|
+
});
|
|
1630
|
+
};
|
|
1631
|
+
switch (d.kind) {
|
|
1632
|
+
case "nat": {
|
|
1633
|
+
const i = integer(v, cx.json);
|
|
1634
|
+
return i !== null && i >= 0n ? i : bad();
|
|
1635
|
+
}
|
|
1636
|
+
case "int": return integer(v, cx.json) ?? bad();
|
|
1637
|
+
case "uint":
|
|
1638
|
+
case "sint": {
|
|
1639
|
+
const i = inRange(v, d.bits, d.kind === "sint", d.bits === 64, cx.json);
|
|
1640
|
+
if (i === null) return bad();
|
|
1641
|
+
return d.bits === 64 ? i : Number(BigInt.asUintN(d.bits, i));
|
|
1642
|
+
}
|
|
1643
|
+
case "usize": return inRange(v, 64, false, true, cx.json) ?? bad();
|
|
1644
|
+
case "isize": return inRange(v, 64, true, true, cx.json) ?? bad();
|
|
1645
|
+
case "bool": return typeof v === "boolean" ? v ? 1 : 0 : bad();
|
|
1646
|
+
case "char": return charCode(v) ?? bad();
|
|
1647
|
+
case "string": return typeof v === "string" && !LONE_SURROGATE.test(v) ? v : bad();
|
|
1648
|
+
case "float": return floatValue(v, cx.json) ?? bad();
|
|
1649
|
+
case "float32": {
|
|
1650
|
+
const f = floatValue(v, cx.json);
|
|
1651
|
+
return f === null ? bad() : Math.fround(f);
|
|
1652
|
+
}
|
|
1653
|
+
case "unit": return isUnit(v, cx.json) ? 0 : bad();
|
|
1654
|
+
case "list": {
|
|
1655
|
+
if (!Array.isArray(v)) return bad();
|
|
1656
|
+
const encoded = v.map((x, i) => encode(d.item, x, [...path, i], cx));
|
|
1657
|
+
let out = 0;
|
|
1658
|
+
for (let i = encoded.length - 1; i >= 0; i--) out = lean_ctor(1, 2, 0, 0, encoded[i], out);
|
|
1659
|
+
return out;
|
|
1660
|
+
}
|
|
1661
|
+
case "array":
|
|
1662
|
+
if (!Array.isArray(v)) return bad();
|
|
1663
|
+
return v.map((x, i) => encode(d.item, x, [...path, i], cx));
|
|
1664
|
+
case "option": return isAbsent(v, d.absent, cx.json) ? 0 : lean_ctor(1, 1, 0, 0, encode(d.item, v, path, cx));
|
|
1665
|
+
case "prod": {
|
|
1666
|
+
if (!Array.isArray(v) || v.length !== 2) return bad();
|
|
1667
|
+
const pair = v;
|
|
1668
|
+
return lean_ctor(0, 2, 0, 0, encode(d.fst, pair[0], [...path, 0], cx), encode(d.snd, pair[1], [...path, 1], cx));
|
|
1669
|
+
}
|
|
1670
|
+
case "except": {
|
|
1671
|
+
const ok = record(v, "ok");
|
|
1672
|
+
const value = record(v, "value");
|
|
1673
|
+
const error = record(v, "error");
|
|
1674
|
+
if (ok.value === true && value.found) return lean_ctor(1, 1, 0, 0, encode(d.value, value.value, [...path, "value"], cx));
|
|
1675
|
+
if (ok.value === false && error.found) return lean_ctor(0, 1, 0, 0, encode(d.error, error.value, [...path, "error"], cx));
|
|
1676
|
+
if (cx.json && isObject(v) && Object.keys(v).length === 1) {
|
|
1677
|
+
if (ok.found) return lean_ctor(1, 1, 0, 0, encode(d.value, ok.value, [...path, "ok"], cx));
|
|
1678
|
+
if (error.found) return lean_ctor(0, 1, 0, 0, encode(d.error, error.value, [...path, "error"], cx));
|
|
1679
|
+
}
|
|
1680
|
+
return bad();
|
|
1681
|
+
}
|
|
1682
|
+
case "fin": {
|
|
1683
|
+
const i = integer(v, cx.json);
|
|
1684
|
+
return i !== null && i >= 0n && i < d.bound ? i : bad();
|
|
1685
|
+
}
|
|
1686
|
+
case "struct":
|
|
1687
|
+
if (!isObject(v)) return bad();
|
|
1688
|
+
return encodeVariant(d, d.variant, objectInputs(d.variant, v, path), d.trivial, path, cx);
|
|
1689
|
+
case "enum": {
|
|
1690
|
+
const i = typeof v === "string" ? d.ctors.indexOf(v) : -1;
|
|
1691
|
+
return i >= 0 ? i : bad();
|
|
1692
|
+
}
|
|
1693
|
+
case "inductive": {
|
|
1694
|
+
const p = pick(d, v, path, cx.json);
|
|
1695
|
+
if (p === null) return bad();
|
|
1696
|
+
return encodeVariant(d, p.variant, p.inputs, null, path, cx);
|
|
1697
|
+
}
|
|
1698
|
+
case "subtype": {
|
|
1699
|
+
const before = cx.issues.length;
|
|
1700
|
+
const x = encode(d.base, v, path, cx);
|
|
1701
|
+
if (cx.issues.length === before && !d.invariant.decide(shared(x))) cx.issues.push({
|
|
1702
|
+
message: `${d.name}.${d.invariant.field}: ${d.invariant.prop}`,
|
|
1703
|
+
path
|
|
1704
|
+
});
|
|
1705
|
+
return x;
|
|
1706
|
+
}
|
|
1707
|
+
case "model": {
|
|
1708
|
+
const r = runModel(d, v, path, cx.issues);
|
|
1709
|
+
return r.ok ? encode(d.struct, r.value, path, {
|
|
1710
|
+
json: true,
|
|
1711
|
+
issues: cx.issues
|
|
1712
|
+
}) : void 0;
|
|
1713
|
+
}
|
|
1714
|
+
case "ref": return encode(d.get(), v, path, cx);
|
|
1715
|
+
}
|
|
1716
|
+
return unreachable(d);
|
|
1717
|
+
}
|
|
1718
|
+
function encodeVariant(d, variant, inputs, trivial, path, cx) {
|
|
1719
|
+
const before = cx.issues.length;
|
|
1720
|
+
const values = variant.fields.map((f, i) => {
|
|
1721
|
+
const input = inputs[i];
|
|
1722
|
+
return encode(f.desc, input?.value, input?.path ?? path, cx);
|
|
1723
|
+
});
|
|
1724
|
+
if (cx.issues.length === before) checkInvariants(ownerName(d, variant), variant, values, path, cx.issues);
|
|
1725
|
+
if (trivial !== null) return values[trivial];
|
|
1726
|
+
return build(variant, values);
|
|
1727
|
+
}
|
|
1728
|
+
function check(d, v, path, issues) {
|
|
1729
|
+
const bad = () => {
|
|
1730
|
+
issues.push({
|
|
1731
|
+
message: `expected ${expected(d)}`,
|
|
1732
|
+
path
|
|
1733
|
+
});
|
|
1734
|
+
};
|
|
1735
|
+
switch (d.kind) {
|
|
1736
|
+
case "nat":
|
|
1737
|
+
case "int":
|
|
1738
|
+
case "usize":
|
|
1739
|
+
case "isize":
|
|
1740
|
+
case "fin": {
|
|
1741
|
+
const before = issues.length;
|
|
1742
|
+
const x = encode(d, v, path, {
|
|
1743
|
+
json: true,
|
|
1744
|
+
issues
|
|
1745
|
+
});
|
|
1746
|
+
if (issues.length !== before) return void 0;
|
|
1747
|
+
if (d.kind === "fin" && d.bound <= 1n << 32n) return Number(asNat(x));
|
|
1748
|
+
return x;
|
|
1749
|
+
}
|
|
1750
|
+
case "uint":
|
|
1751
|
+
case "sint": {
|
|
1752
|
+
const i = inRange(v, d.bits, d.kind === "sint", d.bits === 64, true);
|
|
1753
|
+
if (i === null) return bad();
|
|
1754
|
+
return d.bits === 64 ? i : Number(i);
|
|
1755
|
+
}
|
|
1756
|
+
case "bool": return typeof v === "boolean" ? v : bad();
|
|
1757
|
+
case "char": return charCode(v) === null ? bad() : v;
|
|
1758
|
+
case "string": return typeof v === "string" && !LONE_SURROGATE.test(v) ? v : bad();
|
|
1759
|
+
case "float": return floatValue(v, true) ?? bad();
|
|
1760
|
+
case "float32": {
|
|
1761
|
+
const f = floatValue(v, true);
|
|
1762
|
+
return f === null ? bad() : Math.fround(f);
|
|
1763
|
+
}
|
|
1764
|
+
case "unit": return isUnit(v, true) ? void 0 : bad();
|
|
1765
|
+
case "list":
|
|
1766
|
+
case "array":
|
|
1767
|
+
if (!Array.isArray(v)) return bad();
|
|
1768
|
+
return v.map((x, i) => check(d.item, x, [...path, i], issues));
|
|
1769
|
+
case "option":
|
|
1770
|
+
if (isAbsent(v, d.absent, true)) return d.absent === "null" ? null : void 0;
|
|
1771
|
+
return check(d.item, v, path, issues);
|
|
1772
|
+
case "prod": {
|
|
1773
|
+
if (!Array.isArray(v) || v.length !== 2) return bad();
|
|
1774
|
+
const pair = v;
|
|
1775
|
+
return [check(d.fst, pair[0], [...path, 0], issues), check(d.snd, pair[1], [...path, 1], issues)];
|
|
1776
|
+
}
|
|
1777
|
+
case "except": {
|
|
1778
|
+
const ok = record(v, "ok");
|
|
1779
|
+
const value = record(v, "value");
|
|
1780
|
+
const error = record(v, "error");
|
|
1781
|
+
if (ok.value === true && value.found) return {
|
|
1782
|
+
ok: true,
|
|
1783
|
+
value: check(d.value, value.value, [...path, "value"], issues)
|
|
1784
|
+
};
|
|
1785
|
+
if (ok.value === false && error.found) return {
|
|
1786
|
+
ok: false,
|
|
1787
|
+
error: check(d.error, error.value, [...path, "error"], issues)
|
|
1788
|
+
};
|
|
1789
|
+
if (isObject(v) && Object.keys(v).length === 1) {
|
|
1790
|
+
if (ok.found) return {
|
|
1791
|
+
ok: true,
|
|
1792
|
+
value: check(d.value, ok.value, [...path, "ok"], issues)
|
|
1793
|
+
};
|
|
1794
|
+
if (error.found) return {
|
|
1795
|
+
ok: false,
|
|
1796
|
+
error: check(d.error, error.value, [...path, "error"], issues)
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
return bad();
|
|
1800
|
+
}
|
|
1801
|
+
case "struct":
|
|
1802
|
+
if (!isObject(v)) return bad();
|
|
1803
|
+
return checkVariant(d, d.variant, objectInputs(d.variant, v, path), path, issues, {});
|
|
1804
|
+
case "enum": return typeof v === "string" && d.ctors.includes(v) ? v : bad();
|
|
1805
|
+
case "inductive": {
|
|
1806
|
+
const p = pick(d, v, path, true);
|
|
1807
|
+
if (p === null) return bad();
|
|
1808
|
+
return checkVariant(d, p.variant, p.inputs, path, issues, { [d.tagKey]: p.variant.name });
|
|
1809
|
+
}
|
|
1810
|
+
case "subtype": {
|
|
1811
|
+
const before = issues.length;
|
|
1812
|
+
const x = check(d.base, v, path, issues);
|
|
1813
|
+
if (issues.length === before) {
|
|
1814
|
+
const lean = encode(d.base, x, path, {
|
|
1815
|
+
json: false,
|
|
1816
|
+
issues
|
|
1817
|
+
});
|
|
1818
|
+
if (issues.length === before && !d.invariant.decide(shared(lean))) issues.push({
|
|
1819
|
+
message: `${d.name}.${d.invariant.field}: ${d.invariant.prop}`,
|
|
1820
|
+
path
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
return x;
|
|
1824
|
+
}
|
|
1825
|
+
case "model": return runModel(d, v, path, issues).value;
|
|
1826
|
+
case "ref": return check(d.get(), v, path, issues);
|
|
1827
|
+
}
|
|
1828
|
+
return unreachable(d);
|
|
1829
|
+
}
|
|
1830
|
+
function checkVariant(d, variant, inputs, path, issues, head) {
|
|
1831
|
+
const before = issues.length;
|
|
1832
|
+
const outputs = variant.fields.map((f, i) => {
|
|
1833
|
+
const input = inputs[i];
|
|
1834
|
+
return check(f.desc, input?.value, input?.path ?? path, issues);
|
|
1835
|
+
});
|
|
1836
|
+
if (issues.length !== before) return void 0;
|
|
1837
|
+
if (variant.invariants.length !== 0) {
|
|
1838
|
+
const values = variant.fields.map((f, i) => encode(f.desc, outputs[i], path, {
|
|
1839
|
+
json: false,
|
|
1840
|
+
issues
|
|
1841
|
+
}));
|
|
1842
|
+
if (issues.length !== before) return void 0;
|
|
1843
|
+
checkInvariants(ownerName(d, variant), variant, values, path, issues);
|
|
1844
|
+
}
|
|
1845
|
+
return assemble(variant, outputs, head);
|
|
1846
|
+
}
|
|
1847
|
+
function assemble(variant, outputs, head) {
|
|
1848
|
+
const out = { ...head };
|
|
1849
|
+
variant.fields.forEach((f, i) => {
|
|
1850
|
+
const x = outputs[i];
|
|
1851
|
+
if (f.flat) Object.assign(out, x);
|
|
1852
|
+
else if (x !== void 0 || resolve(f.desc).kind !== "option") out[f.key] = x;
|
|
1853
|
+
});
|
|
1854
|
+
return out;
|
|
1855
|
+
}
|
|
1856
|
+
function decodeVariant(variant, x, trivial, head) {
|
|
1857
|
+
return assemble(variant, variant.fields.map((f, i) => decode(f.desc, trivial === null ? load(x, f) : i === trivial ? x : 0)), head);
|
|
1858
|
+
}
|
|
1859
|
+
function decode(d, x) {
|
|
1860
|
+
switch (d.kind) {
|
|
1861
|
+
case "nat":
|
|
1862
|
+
case "int":
|
|
1863
|
+
case "usize": return asNat(x);
|
|
1864
|
+
case "uint": return d.bits === 64 ? asNat(x) : lean_unbox(x);
|
|
1865
|
+
case "sint": return d.bits === 64 ? BigInt.asIntN(64, asNat(x)) : Number(BigInt.asIntN(d.bits, BigInt(lean_unbox(x))));
|
|
1866
|
+
case "isize": return BigInt.asIntN(64, asNat(x));
|
|
1867
|
+
case "bool": return lean_unbox(x) !== 0;
|
|
1868
|
+
case "char": return String.fromCodePoint(lean_unbox(x));
|
|
1869
|
+
case "string": return asString(x);
|
|
1870
|
+
case "float":
|
|
1871
|
+
case "float32": return lean_unbox(x);
|
|
1872
|
+
case "unit": return;
|
|
1873
|
+
case "list": {
|
|
1874
|
+
const out = [];
|
|
1875
|
+
let cur = x;
|
|
1876
|
+
while (lean_tag(cur) === 1) {
|
|
1877
|
+
const cell = asCtor(cur);
|
|
1878
|
+
out.push(decode(d.item, cell.fields[0]));
|
|
1879
|
+
cur = cell.fields[1];
|
|
1880
|
+
}
|
|
1881
|
+
return out;
|
|
1882
|
+
}
|
|
1883
|
+
case "array": return asArray(x).map((e) => decode(d.item, e));
|
|
1884
|
+
case "option":
|
|
1885
|
+
if (lean_tag(x) === 0) return d.absent === "null" ? null : void 0;
|
|
1886
|
+
return decode(d.item, asCtor(x).fields[0]);
|
|
1887
|
+
case "prod": {
|
|
1888
|
+
const c = asCtor(x);
|
|
1889
|
+
return [decode(d.fst, c.fields[0]), decode(d.snd, c.fields[1])];
|
|
1890
|
+
}
|
|
1891
|
+
case "except": {
|
|
1892
|
+
const c = asCtor(x);
|
|
1893
|
+
return c.tag === 1 ? {
|
|
1894
|
+
ok: true,
|
|
1895
|
+
value: decode(d.value, c.fields[0])
|
|
1896
|
+
} : {
|
|
1897
|
+
ok: false,
|
|
1898
|
+
error: decode(d.error, c.fields[0])
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
case "fin": return d.bound <= 1n << 32n ? Number(asNat(x)) : asNat(x);
|
|
1902
|
+
case "struct": return decodeVariant(d.variant, x, d.trivial, {});
|
|
1903
|
+
case "enum": {
|
|
1904
|
+
const cidx = lean_unbox(x);
|
|
1905
|
+
const name = d.ctors[cidx];
|
|
1906
|
+
if (name === void 0) throw new TypeError(`leanfran runtime: ${d.name} has no constructor ${cidx}`);
|
|
1907
|
+
return name;
|
|
1908
|
+
}
|
|
1909
|
+
case "inductive": {
|
|
1910
|
+
const tag = lean_tag(x);
|
|
1911
|
+
const variant = d.variants.find((v) => v.cidx === tag);
|
|
1912
|
+
if (variant === void 0) throw new TypeError(`leanfran runtime: ${d.name} has no constructor ${tag}`);
|
|
1913
|
+
return decodeVariant(variant, x, null, { [d.tagKey]: variant.name });
|
|
1914
|
+
}
|
|
1915
|
+
case "subtype": return decode(d.base, x);
|
|
1916
|
+
case "model": return jsonValue(d.struct, decode(d.struct, x), false);
|
|
1917
|
+
case "ref": return decode(d.get(), x);
|
|
1918
|
+
}
|
|
1919
|
+
return unreachable(d);
|
|
1920
|
+
}
|
|
1921
|
+
function bigJson(v, big) {
|
|
1922
|
+
if (typeof v !== "bigint" || big) return v;
|
|
1923
|
+
return Number.isSafeInteger(Number(v)) ? Number(v) : v.toString();
|
|
1924
|
+
}
|
|
1925
|
+
function floatJson(v) {
|
|
1926
|
+
if (typeof v !== "number" || Number.isFinite(v)) return v;
|
|
1927
|
+
if (Number.isNaN(v)) return "NaN";
|
|
1928
|
+
return v > 0 ? "Infinity" : "-Infinity";
|
|
1929
|
+
}
|
|
1930
|
+
function variantJson(variant, v, big) {
|
|
1931
|
+
const out = {};
|
|
1932
|
+
for (const f of variant.fields) {
|
|
1933
|
+
if (f.flat) {
|
|
1934
|
+
Object.assign(out, jsonValue(f.desc, v, big));
|
|
1935
|
+
continue;
|
|
1936
|
+
}
|
|
1937
|
+
const x = record(v, f.key).value;
|
|
1938
|
+
if (resolve(f.desc).kind === "option" && (x === null || x === void 0) && f.omitNone) continue;
|
|
1939
|
+
out[f.key] = jsonValue(f.desc, x, big);
|
|
1940
|
+
}
|
|
1941
|
+
return out;
|
|
1942
|
+
}
|
|
1943
|
+
function jsonValue(d, v, big) {
|
|
1944
|
+
switch (d.kind) {
|
|
1945
|
+
case "nat":
|
|
1946
|
+
case "int":
|
|
1947
|
+
case "isize":
|
|
1948
|
+
case "fin": return bigJson(v, big);
|
|
1949
|
+
case "sint": return d.bits === 64 ? bigJson(v, big) : v;
|
|
1950
|
+
case "uint": return d.bits === 64 && typeof v === "bigint" ? v.toString() : v;
|
|
1951
|
+
case "usize": return typeof v === "bigint" ? v.toString() : v;
|
|
1952
|
+
case "bool":
|
|
1953
|
+
case "char":
|
|
1954
|
+
case "string":
|
|
1955
|
+
case "enum": return v;
|
|
1956
|
+
case "float":
|
|
1957
|
+
case "float32": return floatJson(v);
|
|
1958
|
+
case "unit": return {};
|
|
1959
|
+
case "list":
|
|
1960
|
+
case "array": return Array.isArray(v) ? v.map((x) => jsonValue(d.item, x, big)) : v;
|
|
1961
|
+
case "option": return v === null || v === void 0 ? null : jsonValue(d.item, v, big);
|
|
1962
|
+
case "prod": return Array.isArray(v) ? [jsonValue(d.fst, v[0], big), jsonValue(d.snd, v[1], big)] : v;
|
|
1963
|
+
case "except": return record(v, "ok").value === true ? { ok: jsonValue(d.value, record(v, "value").value, big) } : { error: jsonValue(d.error, record(v, "error").value, big) };
|
|
1964
|
+
case "struct": return variantJson(d.variant, v, big);
|
|
1965
|
+
case "inductive": {
|
|
1966
|
+
const tag = record(v, d.tagKey).value;
|
|
1967
|
+
const variant = d.variants.find((x) => x.name === tag);
|
|
1968
|
+
if (variant === void 0) return v;
|
|
1969
|
+
if (variant.fields.length === 0) return variant.name;
|
|
1970
|
+
if (!variant.positional) return { [variant.name]: variantJson(variant, v, big) };
|
|
1971
|
+
const items = variant.fields.map((f) => jsonValue(f.desc, record(v, f.key).value, big));
|
|
1972
|
+
return { [variant.name]: items.length === 1 ? items[0] : items };
|
|
1973
|
+
}
|
|
1974
|
+
case "subtype": return jsonValue(d.base, v, big);
|
|
1975
|
+
case "model": return jsonValue(d.struct, v, big);
|
|
1976
|
+
case "ref": return jsonValue(d.get(), v, big);
|
|
1977
|
+
}
|
|
1978
|
+
return unreachable(d);
|
|
1979
|
+
}
|
|
1980
|
+
function checkValue(d, v) {
|
|
1981
|
+
const issues = [];
|
|
1982
|
+
const value = check(d, v, [], issues);
|
|
1983
|
+
return issues.length === 0 ? { value } : { issues };
|
|
1984
|
+
}
|
|
1985
|
+
function toLean(d, v, name) {
|
|
1986
|
+
const issues = [];
|
|
1987
|
+
const out = encode(d, v, [name], {
|
|
1988
|
+
json: false,
|
|
1989
|
+
issues
|
|
1990
|
+
});
|
|
1991
|
+
if (issues.length > 0) throw new LeanValidationError(issues);
|
|
1992
|
+
return out;
|
|
1993
|
+
}
|
|
1994
|
+
function toTs(d, x) {
|
|
1995
|
+
return decode(d, x);
|
|
1996
|
+
}
|
|
1997
|
+
function ioResult(d, r) {
|
|
1998
|
+
if (!lean_io_result_is_ok(r)) throw new LeanIOError(lean_io_result_get_error(r));
|
|
1999
|
+
return decode(d, lean_io_result_get_value(r));
|
|
2000
|
+
}
|
|
2001
|
+
function lazy(f) {
|
|
2002
|
+
let done = false;
|
|
2003
|
+
let value;
|
|
2004
|
+
return () => {
|
|
2005
|
+
if (!done) {
|
|
2006
|
+
value = lean_mark_persistent(f());
|
|
2007
|
+
done = true;
|
|
2008
|
+
}
|
|
2009
|
+
return value;
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
2012
|
+
export { lean_io_prim_handle_is_tty as $, lean_reuse as $n, lean_uint64_land as $r, lean_string_utf8_extract_fast as $t, unitDesc as A, lean_usize_add as Ai, lean_ctor_get_u32 as An, lean_uint32_dec_le as Ar, encodeUtf8 as At, lean_get_stderr as B, lean_usize_neg as Bi, lean_ctor_set_u64 as Bn, lean_uint32_of_nat_mk as Br, lean_string_hash as Bt, sintDesc as C, lean_uint8_of_nat as Ci, lean_bool as Cn, lean_uint16_sub as Cr, lean_st_ref_ptr_eq as Ct, toTs as D, lean_uint8_to_nat as Di, lean_ctor_get_f32 as Dn, lean_uint32_add as Dr, lean_st_ref_take as Dt, toLean as E, lean_uint8_sub as Ei, lean_ctor_get as En, lean_uint16_xor as Er, lean_st_ref_swap as Et, lean_dbg_trace as F, lean_usize_div as Fi, lean_ctor_set_f32 as Fn, lean_uint32_mod as Fr, lean_string_data as Ft, lean_io_eprint as G, lean_usize_to_nat as Gi, lean_dec as Gn, lean_uint32_to_uint64 as Gr, lean_string_memcmp as Gt, lean_get_stdout as H, lean_usize_shift_left as Hi, lean_ctor_set_usize as Hn, lean_uint32_shift_right as Hr, lean_string_isprefixof as Ht, lean_dbg_trace_if_shared as I, lean_usize_land as Ii, lean_ctor_set_f64 as In, lean_uint32_mul as Ir, lean_string_dec_eq as It, lean_io_exit as J, lean_is_exclusive as Jn, lean_uint64_complement as Jr, lean_string_push as Jt, lean_io_eprintln as K, lean_usize_to_uint64 as Ki, lean_inc as Kn, lean_uint32_xor as Kr, lean_string_mk as Kt, lean_get_set_stderr as L, lean_usize_lor as Li, lean_ctor_set_tag as Ln, lean_uint32_neg as Lr, lean_string_dec_lt as Lt, browserPlatform as M, lean_usize_dec_eq as Mi, lean_ctor_get_u8 as Mn, lean_uint32_div as Mr, lean_string_any as Mt, getPlatform as N, lean_usize_dec_le as Ni, lean_ctor_get_usize as Nn, lean_uint32_land as Nr, lean_string_append as Nt, typeDesc as O, lean_uint8_to_uint64 as Oi, lean_ctor_get_f64 as On, lean_uint32_complement as Or, setPlatform as Ot, lean_dbg_sleep as P, lean_usize_dec_lt as Pi, lean_ctor_set as Pn, lean_uint32_lor as Pr, lean_string_contains as Pt, lean_io_prim_handle_get_line as Q, lean_reset as Qn, lean_uint64_div as Qr, lean_string_utf8_extract as Qt, lean_get_set_stdin as R, lean_usize_mod as Ri, lean_ctor_set_u16 as Rn, lean_uint32_of_nat as Rr, lean_string_from_utf8_unchecked as Rt, resolve as S, lean_uint8_neg as Si, lean_apply as Sn, lean_uint16_shift_right as Sr, lean_st_ref_get as St, stringDesc as T, lean_uint8_shift_right as Ti, lean_ctor as Tn, lean_uint16_to_uint64 as Tr, lean_st_ref_set as Tt, lean_internal_panic as U, lean_usize_shift_right as Ui, lean_ctor_uget as Un, lean_uint32_sub as Ur, lean_string_length as Ut, lean_get_stdin as V, lean_usize_of_nat as Vi, lean_ctor_set_u8 as Vn, lean_uint32_shift_left as Vr, lean_string_isempty as Vt, lean_internal_panic_unreachable as W, lean_usize_sub as Wi, lean_ctor_uset as Wn, lean_uint32_to_nat as Wr, lean_string_lt as Wt, lean_io_getenv as X, lean_mark_persistent as Xn, lean_uint64_dec_le as Xr, lean_string_utf8_at_end as Xt, lean_io_force_exit as Y, lean_is_shared as Yn, lean_uint64_dec_eq as Yr, lean_string_to_utf8 as Yt, lean_io_prim_handle_flush as Z, lean_mk_thunk as Zn, lean_uint64_dec_lt as Zr, lean_string_utf8_byte_size as Zt, modelDesc as _, lean_uint8_div as _i, asNat as _n, lean_uint16_mod as _r, lean_run_init as _t, charDesc as a, lean_uint64_of_nat_mk as ai, lean_string_utf8_next_fast as an, lean_unbox as ar, lean_io_result_get_value as at, prodDesc as b, lean_uint8_mod as bi, asThunk as bn, lean_uint16_of_nat as br, lean_set_panic_messages as bt, finDesc as c, lean_uint64_sub as ci, lean_string_utf8_set as cn, lean_system_platform_nbits as cr, lean_io_result_mk_ok as ct, intDesc as d, lean_uint64_xor as di, asArray as dn, lean_uint16_dec_eq as dr, lean_mk_io_error_unsupported_operation as dt, lean_uint64_lor as ei, lean_string_utf8_get as en, lean_tag as er, lean_io_prim_handle_mk as et, ioResult as f, lean_uint8_add as fi, asBytes as fn, lean_uint16_dec_le as fr, lean_mk_io_user_error as ft, listDesc as g, lean_uint8_dec_lt as gi, asHandle as gn, lean_uint16_lor as gr, lean_register_init as gt, lazy as h, lean_uint8_dec_le as hi, asFloats as hn, lean_uint16_land as hr, lean_ptr_addr as ht, boolDesc as i, lean_uint64_of_nat as ii, lean_string_utf8_next as in, lean_trampoline as ir, lean_io_result_get_error as it, usizeDesc as j, lean_usize_complement as ji, lean_ctor_get_u64 as jn, lean_uint32_dec_lt as jr, lean_char_to_nat as jt, uintDesc as k, lean_uint8_xor as ki, lean_ctor_get_u16 as kn, lean_uint32_dec_eq as kr, decodeUtf8 as kt, float32Desc as l, lean_uint64_to_nat as li, lean_string_validate_utf8 as ln, lean_uint16_add as lr, lean_io_result_show_error as lt, jsonValue as m, lean_uint8_dec_eq as mi, asCtor as mn, lean_uint16_div as mr, lean_panic_fn_borrowed as mt, LeanValidationError as n, lean_uint64_mul as ni, lean_string_utf8_get_fast as nn, lean_thunk_get_own as nr, lean_io_prim_handle_read as nt, checkValue as o, lean_uint64_shift_left as oi, lean_string_utf8_pos_of as on, lean_unbox_uint64 as or, lean_io_result_is_ok as ot, isizeDesc as p, lean_uint8_complement as pi, asClosure as pn, lean_uint16_dec_lt as pr, lean_panic_fn as pt, lean_io_error_to_string as q, lean_usize_xor as qi, lean_inc_n as qn, lean_uint64_add as qr, lean_string_of_usize as qt, arrayDesc as r, lean_uint64_neg as ri, lean_string_utf8_get_opt as rn, lean_thunk_pure as rr, lean_io_prim_handle_write as rt, exceptDesc as s, lean_uint64_shift_right as si, lean_string_utf8_prev as sn, WORD_BITS as sr, lean_io_result_mk_error as st, LeanIOError as t, lean_uint64_mod as ti, lean_string_utf8_get_bang as tn, lean_thunk_get as tr, lean_io_prim_handle_put_str as tt, floatDesc as u, lean_uint64_to_usize as ui, lean_uint64_mix_hash as un, lean_uint16_complement as ur, lean_is_exclusive_obj as ut, natDesc as v, lean_uint8_land as vi, asRef as vn, lean_uint16_mul as vr, lean_run_main as vt, standardValidate as w, lean_uint8_shift_left as wi, lean_closure as wn, lean_uint16_to_nat as wr, lean_st_ref_put as wt, refDesc as x, lean_uint8_mul as xi, lean_alloc_ctor as xn, lean_uint16_shift_left as xr, lean_st_mk_ref as xt, optionDesc as y, lean_uint8_lor as yi, asString as yn, lean_uint16_neg as yr, lean_set_exit_on_panic as yt, lean_get_set_stdout as z, lean_usize_mul as zi, lean_ctor_set_u32 as zn, lean_uint32_of_nat2 as zr, lean_string_get_byte_fast as zt };
|