@loro-dev/flock-sqlite 0.1.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 +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +27 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +175 -0
- package/dist/index.d.ts +175 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
- package/src/digest.ts +259 -0
- package/src/index.ts +1040 -0
- package/src/key-encoding.ts +106 -0
- package/src/memcomparable.d.ts +5 -0
- package/src/memcomparable.ts +1852 -0
- package/src/moonbit.d.ts +57 -0
- package/src/types.ts +128 -0
|
@@ -0,0 +1,1852 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// NOTE: generated from moon/memcomparable; intentionally skips type checking.
|
|
3
|
+
const $9221120237041090561L = { hi: 2146959360, lo: 1 };
|
|
4
|
+
class $PanicError extends Error {}
|
|
5
|
+
function $panic() {
|
|
6
|
+
throw new $PanicError();
|
|
7
|
+
}
|
|
8
|
+
const moonbitlang$core$bigint$$BigInt$compare = (x, y) => x < y ? -1 : x > y ? 1 : 0;
|
|
9
|
+
const moonbitlang$core$bigint$$BigInt$equal = (x, y) => x === y;
|
|
10
|
+
const moonbitlang$core$bigint$$BigInt$from_int64 = (x) => BigInt(x.hi) * 0x100000000n + BigInt(x.lo >>> 0);
|
|
11
|
+
const moonbitlang$core$bigint$$BigInt$op_neg_ffi = (x) => -x;
|
|
12
|
+
const moonbitlang$core$bigint$$BigInt$op_add_ffi = (x, y) => x + y;
|
|
13
|
+
const moonbitlang$core$bigint$$BigInt$op_mul_ffi = (x, y) => x * y;
|
|
14
|
+
const moonbitlang$core$bigint$$BigInt$op_div_ffi = (x, y) => x / y;
|
|
15
|
+
const moonbitlang$core$bigint$$BigInt$op_mod_ffi = (x, y) => x % y;
|
|
16
|
+
const moonbitlang$core$bigint$$BigInt$js_shr = (x, y) => x >> BigInt(y);
|
|
17
|
+
const moonbitlang$core$bigint$$BigInt$to_uint = (x) => Number(BigInt.asUintN(32, x)) | 0;
|
|
18
|
+
const moonbitlang$core$bigint$$BigInt$to_int = (x) => Number(BigInt.asIntN(32, x));
|
|
19
|
+
function $bound_check(arr, index) {
|
|
20
|
+
if (index < 0 || index >= arr.length) throw new Error("Index out of bounds");
|
|
21
|
+
}
|
|
22
|
+
const moonbitlang$core$builtin$$int_to_string_js = (x, radix) => {
|
|
23
|
+
return x.toString(radix);
|
|
24
|
+
};
|
|
25
|
+
function $makebytes(a, b) {
|
|
26
|
+
const arr = new Uint8Array(a);
|
|
27
|
+
if (b !== 0) {
|
|
28
|
+
arr.fill(b);
|
|
29
|
+
}
|
|
30
|
+
return arr;
|
|
31
|
+
}
|
|
32
|
+
const moonbitlang$core$builtin$$JSArray$push = (arr, val) => { arr.push(val); };
|
|
33
|
+
const $64$moonbitlang$47$core$47$builtin$46$ForeachResult$Continue$0$ = { $tag: 0 };
|
|
34
|
+
function $64$moonbitlang$47$core$47$builtin$46$ForeachResult$Break$0$(param0) {
|
|
35
|
+
this._0 = param0;
|
|
36
|
+
}
|
|
37
|
+
$64$moonbitlang$47$core$47$builtin$46$ForeachResult$Break$0$.prototype.$tag = 1;
|
|
38
|
+
function $64$moonbitlang$47$core$47$builtin$46$ForeachResult$Return$0$(param0) {
|
|
39
|
+
this._0 = param0;
|
|
40
|
+
}
|
|
41
|
+
$64$moonbitlang$47$core$47$builtin$46$ForeachResult$Return$0$.prototype.$tag = 2;
|
|
42
|
+
function $64$moonbitlang$47$core$47$builtin$46$ForeachResult$Error$0$(param0) {
|
|
43
|
+
this._0 = param0;
|
|
44
|
+
}
|
|
45
|
+
$64$moonbitlang$47$core$47$builtin$46$ForeachResult$Error$0$.prototype.$tag = 3;
|
|
46
|
+
function $64$moonbitlang$47$core$47$builtin$46$ForeachResult$JumpOuter$0$(param0) {
|
|
47
|
+
this._0 = param0;
|
|
48
|
+
}
|
|
49
|
+
$64$moonbitlang$47$core$47$builtin$46$ForeachResult$JumpOuter$0$.prototype.$tag = 4;
|
|
50
|
+
const moonbitlang$core$builtin$$MyInt64$reinterpret_as_double = function f(a) {
|
|
51
|
+
let view = f._view;
|
|
52
|
+
if (view === undefined) {
|
|
53
|
+
view = f._view = new DataView(new ArrayBuffer(8));
|
|
54
|
+
}
|
|
55
|
+
view.setUint32(0, a.hi);
|
|
56
|
+
view.setUint32(4, a.lo);
|
|
57
|
+
return view.getFloat64(0);
|
|
58
|
+
};
|
|
59
|
+
const moonbitlang$core$builtin$$MyInt64$reinterpret_double = function f(a) {
|
|
60
|
+
let view = f._view;
|
|
61
|
+
if (view === undefined) {
|
|
62
|
+
view = f._view = new DataView(new ArrayBuffer(8));
|
|
63
|
+
}
|
|
64
|
+
view.setFloat64(0, a);
|
|
65
|
+
const hi = view.getInt32(0);
|
|
66
|
+
const lo = view.getInt32(4);
|
|
67
|
+
return { hi, lo };
|
|
68
|
+
};
|
|
69
|
+
const moonbitlang$core$builtin$$MyInt64$convert_to_double = (a) => a.hi * 4294967296.0 + (a.lo >>> 0);
|
|
70
|
+
const moonbitlang$core$builtin$$MyInt64$from_double = (a) => {
|
|
71
|
+
if (isNaN(a)) {
|
|
72
|
+
return { hi: 0, lo: 0 };
|
|
73
|
+
}
|
|
74
|
+
if (a >= 9223372036854775807) {
|
|
75
|
+
return { hi: 0x7fffffff, lo: 0xffffffff };
|
|
76
|
+
}
|
|
77
|
+
if (a <= -9223372036854775808) {
|
|
78
|
+
return { hi: -2147483648, lo: 0 };
|
|
79
|
+
}
|
|
80
|
+
let neg = false;
|
|
81
|
+
if (a < 0) {
|
|
82
|
+
neg = true;
|
|
83
|
+
a = -a;
|
|
84
|
+
}
|
|
85
|
+
let hi = (a * (1 / 0x100000000)) | 0;
|
|
86
|
+
let lo = a >>> 0;
|
|
87
|
+
if (neg) {
|
|
88
|
+
if (lo === 0) {
|
|
89
|
+
hi = ~hi + 1;
|
|
90
|
+
} else {
|
|
91
|
+
hi = ~hi;
|
|
92
|
+
lo = ~lo + 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { hi, lo };
|
|
96
|
+
};
|
|
97
|
+
const $bytes_literal$0 = new Uint8Array();
|
|
98
|
+
const $255L = { hi: 0, lo: 255 };
|
|
99
|
+
const $0L = { hi: 0, lo: 0 };
|
|
100
|
+
const $_1L = { hi: -1, lo: -1 };
|
|
101
|
+
const $_9223372036854775808L = { hi: -2147483648, lo: 0 };
|
|
102
|
+
function Result$Err$1$(param0) {
|
|
103
|
+
this._0 = param0;
|
|
104
|
+
}
|
|
105
|
+
Result$Err$1$.prototype.$tag = 0;
|
|
106
|
+
function Result$Ok$1$(param0) {
|
|
107
|
+
this._0 = param0;
|
|
108
|
+
}
|
|
109
|
+
Result$Ok$1$.prototype.$tag = 1;
|
|
110
|
+
function Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidTag(param0) {
|
|
111
|
+
this._0 = param0;
|
|
112
|
+
}
|
|
113
|
+
Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidTag.prototype.$tag = 2;
|
|
114
|
+
const Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF = { $tag: 1 };
|
|
115
|
+
const Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidUTF8 = { $tag: 0 };
|
|
116
|
+
const $1L = { hi: 0, lo: 1 };
|
|
117
|
+
const $256L = { hi: 0, lo: 256 };
|
|
118
|
+
function Result$Err$2$(param0) {
|
|
119
|
+
this._0 = param0;
|
|
120
|
+
}
|
|
121
|
+
Result$Err$2$.prototype.$tag = 0;
|
|
122
|
+
function Result$Ok$2$(param0) {
|
|
123
|
+
this._0 = param0;
|
|
124
|
+
}
|
|
125
|
+
Result$Ok$2$.prototype.$tag = 1;
|
|
126
|
+
function Result$Err$3$(param0) {
|
|
127
|
+
this._0 = param0;
|
|
128
|
+
}
|
|
129
|
+
Result$Err$3$.prototype.$tag = 0;
|
|
130
|
+
function Result$Ok$3$(param0) {
|
|
131
|
+
this._0 = param0;
|
|
132
|
+
}
|
|
133
|
+
Result$Ok$3$.prototype.$tag = 1;
|
|
134
|
+
function KeyPart$Bytes(param0) {
|
|
135
|
+
this._0 = param0;
|
|
136
|
+
}
|
|
137
|
+
KeyPart$Bytes.prototype.$tag = 0;
|
|
138
|
+
function KeyPart$String(param0) {
|
|
139
|
+
this._0 = param0;
|
|
140
|
+
}
|
|
141
|
+
KeyPart$String.prototype.$tag = 1;
|
|
142
|
+
function KeyPart$Int(param0) {
|
|
143
|
+
this._0 = param0;
|
|
144
|
+
}
|
|
145
|
+
KeyPart$Int.prototype.$tag = 2;
|
|
146
|
+
function KeyPart$Float(param0) {
|
|
147
|
+
this._0 = param0;
|
|
148
|
+
}
|
|
149
|
+
KeyPart$Float.prototype.$tag = 3;
|
|
150
|
+
const KeyPart$False = { $tag: 4 };
|
|
151
|
+
const KeyPart$True = { $tag: 5 };
|
|
152
|
+
function Result$Err$4$(param0) {
|
|
153
|
+
this._0 = param0;
|
|
154
|
+
}
|
|
155
|
+
Result$Err$4$.prototype.$tag = 0;
|
|
156
|
+
function Result$Ok$4$(param0) {
|
|
157
|
+
this._0 = param0;
|
|
158
|
+
}
|
|
159
|
+
Result$Ok$4$.prototype.$tag = 1;
|
|
160
|
+
function KeyJsPart$Number(param0) {
|
|
161
|
+
this._0 = param0;
|
|
162
|
+
}
|
|
163
|
+
KeyJsPart$Number.prototype.$tag = 0;
|
|
164
|
+
function KeyJsPart$String(param0) {
|
|
165
|
+
this._0 = param0;
|
|
166
|
+
}
|
|
167
|
+
KeyJsPart$String.prototype.$tag = 1;
|
|
168
|
+
function KeyJsPart$Bytes(param0) {
|
|
169
|
+
this._0 = param0;
|
|
170
|
+
}
|
|
171
|
+
KeyJsPart$Bytes.prototype.$tag = 2;
|
|
172
|
+
const KeyJsPart$True = { $tag: 3 };
|
|
173
|
+
const KeyJsPart$False = { $tag: 4 };
|
|
174
|
+
const zxch3n$expect$$to_string$46$42$bind$124$178 = ";";
|
|
175
|
+
const zxch3n$expect$$red$46$constr$47$350 = 1;
|
|
176
|
+
const zxch3n$expect$$yellow$46$constr$47$352 = 3;
|
|
177
|
+
const zxch3n$expect$$blue$46$constr$47$354 = 4;
|
|
178
|
+
const moonbitlang$core$double$$not_a_number = moonbitlang$core$int64$$Int64$reinterpret_as_double($9221120237041090561L);
|
|
179
|
+
function moonbitlang$core$abort$$abort$0$(msg) {
|
|
180
|
+
return $panic();
|
|
181
|
+
}
|
|
182
|
+
function moonbitlang$core$abort$$abort$1$(msg) {
|
|
183
|
+
return $panic();
|
|
184
|
+
}
|
|
185
|
+
function moonbitlang$core$abort$$abort$2$(msg) {
|
|
186
|
+
return $panic();
|
|
187
|
+
}
|
|
188
|
+
function moonbitlang$core$abort$$abort$3$(msg) {
|
|
189
|
+
$panic();
|
|
190
|
+
}
|
|
191
|
+
function moonbitlang$core$abort$$abort$4$(msg) {
|
|
192
|
+
return $panic();
|
|
193
|
+
}
|
|
194
|
+
function moonbitlang$core$uint$$UInt$to_int64(self) {
|
|
195
|
+
return moonbitlang$core$uint$$UInt$to_uint64(self);
|
|
196
|
+
}
|
|
197
|
+
function moonbitlang$core$array$$ArrayView$join$5$(self, separator) {
|
|
198
|
+
if ((self.end - self.start | 0) === 0) {
|
|
199
|
+
return "";
|
|
200
|
+
} else {
|
|
201
|
+
const _hd = self.buf[self.start];
|
|
202
|
+
const _bind = self.buf;
|
|
203
|
+
const _bind$2 = 1 + self.start | 0;
|
|
204
|
+
const _bind$3 = self.end;
|
|
205
|
+
const _x = { buf: _bind, start: _bind$2, end: _bind$3 };
|
|
206
|
+
const hd = moonbitlang$core$string$$ToStringView$to_string_view$5$(_hd);
|
|
207
|
+
let size_hint = hd.end - hd.start | 0;
|
|
208
|
+
const _len = _x.end - _x.start | 0;
|
|
209
|
+
let _tmp = 0;
|
|
210
|
+
while (true) {
|
|
211
|
+
const _i = _tmp;
|
|
212
|
+
if (_i < _len) {
|
|
213
|
+
const s = _bind[_bind$2 + _i | 0];
|
|
214
|
+
const _tmp$2 = size_hint;
|
|
215
|
+
const _p = moonbitlang$core$string$$ToStringView$to_string_view$5$(s);
|
|
216
|
+
size_hint = _tmp$2 + ((_p.end - _p.start | 0) + (separator.end - separator.start | 0) | 0) | 0;
|
|
217
|
+
_tmp = _i + 1 | 0;
|
|
218
|
+
continue;
|
|
219
|
+
} else {
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
size_hint = size_hint << 1;
|
|
224
|
+
const buf = moonbitlang$core$builtin$$StringBuilder$new$46$inner(size_hint);
|
|
225
|
+
moonbitlang$core$builtin$$Logger$write_substring$6$(buf, hd.str, hd.start, hd.end - hd.start | 0);
|
|
226
|
+
if (moonbitlang$core$string$$String$char_length_eq$46$inner(separator.str, 0, separator.start, separator.end)) {
|
|
227
|
+
const _len$2 = _x.end - _x.start | 0;
|
|
228
|
+
let _tmp$2 = 0;
|
|
229
|
+
while (true) {
|
|
230
|
+
const _i = _tmp$2;
|
|
231
|
+
if (_i < _len$2) {
|
|
232
|
+
const s = _bind[_bind$2 + _i | 0];
|
|
233
|
+
const s$2 = moonbitlang$core$string$$ToStringView$to_string_view$5$(s);
|
|
234
|
+
moonbitlang$core$builtin$$Logger$write_substring$6$(buf, s$2.str, s$2.start, s$2.end - s$2.start | 0);
|
|
235
|
+
_tmp$2 = _i + 1 | 0;
|
|
236
|
+
continue;
|
|
237
|
+
} else {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
const _len$2 = _x.end - _x.start | 0;
|
|
243
|
+
let _tmp$2 = 0;
|
|
244
|
+
while (true) {
|
|
245
|
+
const _i = _tmp$2;
|
|
246
|
+
if (_i < _len$2) {
|
|
247
|
+
const s = _bind[_bind$2 + _i | 0];
|
|
248
|
+
const s$2 = moonbitlang$core$string$$ToStringView$to_string_view$5$(s);
|
|
249
|
+
moonbitlang$core$builtin$$Logger$write_substring$6$(buf, separator.str, separator.start, separator.end - separator.start | 0);
|
|
250
|
+
moonbitlang$core$builtin$$Logger$write_substring$6$(buf, s$2.str, s$2.start, s$2.end - s$2.start | 0);
|
|
251
|
+
_tmp$2 = _i + 1 | 0;
|
|
252
|
+
continue;
|
|
253
|
+
} else {
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return buf.val;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function moonbitlang$core$array$$Array$push_iter$7$(self, iter) {
|
|
262
|
+
iter((x) => {
|
|
263
|
+
moonbitlang$core$array$$Array$push$7$(self, x);
|
|
264
|
+
return 1;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function moonbitlang$core$array$$Array$join$5$(self, separator) {
|
|
268
|
+
return moonbitlang$core$array$$ArrayView$join$5$({ buf: self, start: 0, end: self.length }, separator);
|
|
269
|
+
}
|
|
270
|
+
function moonbitlang$core$builtin$$Compare$compare$8$(self, other) {
|
|
271
|
+
return moonbitlang$core$bigint$$BigInt$compare(self, other);
|
|
272
|
+
}
|
|
273
|
+
function moonbitlang$core$builtin$$Eq$equal$8$(self, other) {
|
|
274
|
+
return moonbitlang$core$bigint$$BigInt$equal(self, other);
|
|
275
|
+
}
|
|
276
|
+
function moonbitlang$core$builtin$$Neg$neg$8$(self) {
|
|
277
|
+
return moonbitlang$core$bigint$$BigInt$op_neg_ffi(self);
|
|
278
|
+
}
|
|
279
|
+
function moonbitlang$core$builtin$$Add$add$8$(self, other) {
|
|
280
|
+
return moonbitlang$core$bigint$$BigInt$op_add_ffi(self, other);
|
|
281
|
+
}
|
|
282
|
+
function moonbitlang$core$builtin$$Mul$mul$8$(self, other) {
|
|
283
|
+
return moonbitlang$core$bigint$$BigInt$op_mul_ffi(self, other);
|
|
284
|
+
}
|
|
285
|
+
function moonbitlang$core$builtin$$Div$div$8$(self, other) {
|
|
286
|
+
return moonbitlang$core$bigint$$BigInt$op_div_ffi(self, other);
|
|
287
|
+
}
|
|
288
|
+
function moonbitlang$core$builtin$$Mod$mod$8$(self, other) {
|
|
289
|
+
return moonbitlang$core$bigint$$BigInt$op_mod_ffi(self, other);
|
|
290
|
+
}
|
|
291
|
+
function moonbitlang$core$builtin$$Shr$shr$8$(self, n) {
|
|
292
|
+
if (n < 0) {
|
|
293
|
+
moonbitlang$core$abort$$abort$3$("negative shift count");
|
|
294
|
+
}
|
|
295
|
+
return moonbitlang$core$bigint$$BigInt$js_shr(self, n);
|
|
296
|
+
}
|
|
297
|
+
function moonbitlang$core$bigint$$BigInt$to_int64(self) {
|
|
298
|
+
const hi = moonbitlang$core$bigint$$BigInt$to_uint(moonbitlang$core$builtin$$Shr$shr$8$(self, 32));
|
|
299
|
+
const lo = moonbitlang$core$bigint$$BigInt$to_uint(self);
|
|
300
|
+
return moonbitlang$core$builtin$$BitOr$lor$9$(moonbitlang$core$builtin$$Shl$shl$9$(moonbitlang$core$uint$$UInt$to_int64(hi), 32), moonbitlang$core$uint$$UInt$to_int64(lo));
|
|
301
|
+
}
|
|
302
|
+
function moonbitlang$core$bytes$$BytesView$at(self, index) {
|
|
303
|
+
if (index >= 0 && index < (self.end - self.start | 0)) {
|
|
304
|
+
const _tmp = self.bytes;
|
|
305
|
+
const _tmp$2 = self.start + index | 0;
|
|
306
|
+
$bound_check(_tmp, _tmp$2);
|
|
307
|
+
return _tmp[_tmp$2];
|
|
308
|
+
} else {
|
|
309
|
+
return moonbitlang$core$abort$$abort$2$(`index out of bounds: the len is from 0 to ${moonbitlang$core$builtin$$Show$to_string$10$(self.end - self.start | 0)} but the index is ${moonbitlang$core$builtin$$Show$to_string$10$(index)}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function moonbitlang$core$bytes$$Bytes$sub$46$inner(self, start, end) {
|
|
313
|
+
const len = self.length;
|
|
314
|
+
let end$2;
|
|
315
|
+
if (end === undefined) {
|
|
316
|
+
end$2 = len;
|
|
317
|
+
} else {
|
|
318
|
+
const _Some = end;
|
|
319
|
+
const _end = _Some;
|
|
320
|
+
end$2 = _end < 0 ? len + _end | 0 : _end;
|
|
321
|
+
}
|
|
322
|
+
const start$2 = start < 0 ? len + start | 0 : start;
|
|
323
|
+
return start$2 >= 0 && (start$2 <= end$2 && end$2 <= len) ? { bytes: self, start: start$2, end: end$2 } : moonbitlang$core$abort$$abort$1$("Invalid index for View");
|
|
324
|
+
}
|
|
325
|
+
function moonbitlang$core$bytes$$BytesView$sub$46$inner(self, start, end) {
|
|
326
|
+
const len = self.end - self.start | 0;
|
|
327
|
+
let end$2;
|
|
328
|
+
if (end === undefined) {
|
|
329
|
+
end$2 = len;
|
|
330
|
+
} else {
|
|
331
|
+
const _Some = end;
|
|
332
|
+
const _end = _Some;
|
|
333
|
+
end$2 = _end < 0 ? len + _end | 0 : _end;
|
|
334
|
+
}
|
|
335
|
+
const start$2 = start < 0 ? len + start | 0 : start;
|
|
336
|
+
return start$2 >= 0 && (start$2 <= end$2 && end$2 <= len) ? { bytes: self.bytes, start: self.start + start$2 | 0, end: (self.start + start$2 | 0) + (end$2 - start$2 | 0) | 0 } : moonbitlang$core$abort$$abort$1$("Invalid index for View");
|
|
337
|
+
}
|
|
338
|
+
function moonbitlang$core$bytes$$BytesView$iter(self) {
|
|
339
|
+
const _p = (yield_) => {
|
|
340
|
+
const _end383 = self.end - self.start | 0;
|
|
341
|
+
let _tmp = 0;
|
|
342
|
+
while (true) {
|
|
343
|
+
const i = _tmp;
|
|
344
|
+
if (i < _end383) {
|
|
345
|
+
const _bind = yield_(moonbitlang$core$bytes$$BytesView$at(self, i));
|
|
346
|
+
if (_bind === 1) {
|
|
347
|
+
} else {
|
|
348
|
+
return 0;
|
|
349
|
+
}
|
|
350
|
+
_tmp = i + 1 | 0;
|
|
351
|
+
continue;
|
|
352
|
+
} else {
|
|
353
|
+
return 1;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
return _p;
|
|
358
|
+
}
|
|
359
|
+
function moonbitlang$core$bytes$$BytesView$iterator(self) {
|
|
360
|
+
const i = { val: 0 };
|
|
361
|
+
const len = self.end - self.start | 0;
|
|
362
|
+
const _p = () => {
|
|
363
|
+
if (i.val < len) {
|
|
364
|
+
const _p$2 = i.val;
|
|
365
|
+
const _tmp = self.bytes;
|
|
366
|
+
const _tmp$2 = self.start + _p$2 | 0;
|
|
367
|
+
$bound_check(_tmp, _tmp$2);
|
|
368
|
+
const result = _tmp[_tmp$2];
|
|
369
|
+
i.val = i.val + 1 | 0;
|
|
370
|
+
return result;
|
|
371
|
+
} else {
|
|
372
|
+
return -1;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
return _p;
|
|
376
|
+
}
|
|
377
|
+
function moonbitlang$core$bytes$$Bytes$from_array(arr) {
|
|
378
|
+
return moonbitlang$core$bytes$$Bytes$makei$11$(arr.end - arr.start | 0, (i) => moonbitlang$core$array$$ArrayView$at$2$(arr, i));
|
|
379
|
+
}
|
|
380
|
+
function moonbitlang$core$bytes$$Bytes$from_iter(iter) {
|
|
381
|
+
const _bind = moonbitlang$core$builtin$$Iter$collect$2$(iter);
|
|
382
|
+
return moonbitlang$core$bytes$$Bytes$from_array({ buf: _bind, start: 0, end: _bind.length });
|
|
383
|
+
}
|
|
384
|
+
function moonbitlang$core$byte$$Byte$to_uint64(self) {
|
|
385
|
+
return moonbitlang$core$uint$$UInt$to_uint64(self);
|
|
386
|
+
}
|
|
387
|
+
function moonbitlang$core$string$$ToStringView$to_string_view$5$(self) {
|
|
388
|
+
return { str: self, start: 0, end: self.length };
|
|
389
|
+
}
|
|
390
|
+
function moonbitlang$core$array$$FixedArray$unsafe_blit$2$(dst, dst_offset, src, src_offset, len) {
|
|
391
|
+
if (dst === src && dst_offset < src_offset) {
|
|
392
|
+
let _tmp = 0;
|
|
393
|
+
while (true) {
|
|
394
|
+
const i = _tmp;
|
|
395
|
+
if (i < len) {
|
|
396
|
+
const _tmp$2 = dst_offset + i | 0;
|
|
397
|
+
const _tmp$3 = src_offset + i | 0;
|
|
398
|
+
$bound_check(src, _tmp$3);
|
|
399
|
+
$bound_check(dst, _tmp$2);
|
|
400
|
+
dst[_tmp$2] = src[_tmp$3];
|
|
401
|
+
_tmp = i + 1 | 0;
|
|
402
|
+
continue;
|
|
403
|
+
} else {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
let _tmp = len - 1 | 0;
|
|
409
|
+
while (true) {
|
|
410
|
+
const i = _tmp;
|
|
411
|
+
if (i >= 0) {
|
|
412
|
+
const _tmp$2 = dst_offset + i | 0;
|
|
413
|
+
const _tmp$3 = src_offset + i | 0;
|
|
414
|
+
$bound_check(src, _tmp$3);
|
|
415
|
+
$bound_check(dst, _tmp$2);
|
|
416
|
+
dst[_tmp$2] = src[_tmp$3];
|
|
417
|
+
_tmp = i - 1 | 0;
|
|
418
|
+
continue;
|
|
419
|
+
} else {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function moonbitlang$core$builtin$$StringBuilder$new$46$inner(size_hint) {
|
|
426
|
+
return { val: "" };
|
|
427
|
+
}
|
|
428
|
+
function moonbitlang$core$builtin$$Logger$write_char$6$(self, ch) {
|
|
429
|
+
const _bind = self;
|
|
430
|
+
_bind.val = `${_bind.val}${String.fromCodePoint(ch)}`;
|
|
431
|
+
}
|
|
432
|
+
function moonbitlang$core$builtin$$Logger$write_string$6$(self, str) {
|
|
433
|
+
const _bind = self;
|
|
434
|
+
_bind.val = `${_bind.val}${str}`;
|
|
435
|
+
}
|
|
436
|
+
function moonbitlang$core$builtin$$Compare$op_gt$12$(x, y) {
|
|
437
|
+
return moonbitlang$core$builtin$$Compare$compare$8$(x, y) > 0;
|
|
438
|
+
}
|
|
439
|
+
function moonbitlang$core$builtin$$Show$to_string$10$(self) {
|
|
440
|
+
const logger = moonbitlang$core$builtin$$StringBuilder$new$46$inner(0);
|
|
441
|
+
moonbitlang$core$builtin$$Show$output$13$(self, { self: logger, method_0: moonbitlang$core$builtin$$Logger$write_string$6$, method_1: moonbitlang$core$builtin$$Logger$write_substring$6$, method_2: moonbitlang$core$builtin$$Logger$write_char$6$ });
|
|
442
|
+
return logger.val;
|
|
443
|
+
}
|
|
444
|
+
function moonbitlang$core$int$$Int$to_string$46$inner(self, radix) {
|
|
445
|
+
return moonbitlang$core$builtin$$int_to_string_js(self, radix);
|
|
446
|
+
}
|
|
447
|
+
function moonbitlang$core$string$$String$char_length_eq$46$inner(self, len, start_offset, end_offset) {
|
|
448
|
+
let end_offset$2;
|
|
449
|
+
if (end_offset === undefined) {
|
|
450
|
+
end_offset$2 = self.length;
|
|
451
|
+
} else {
|
|
452
|
+
const _Some = end_offset;
|
|
453
|
+
end_offset$2 = _Some;
|
|
454
|
+
}
|
|
455
|
+
let _tmp = start_offset;
|
|
456
|
+
let _tmp$2 = 0;
|
|
457
|
+
while (true) {
|
|
458
|
+
const index = _tmp;
|
|
459
|
+
const count = _tmp$2;
|
|
460
|
+
if (index < end_offset$2 && count < len) {
|
|
461
|
+
const c1 = self.charCodeAt(index);
|
|
462
|
+
if (55296 <= c1 && c1 <= 56319 && (index + 1 | 0) < end_offset$2) {
|
|
463
|
+
const _tmp$3 = index + 1 | 0;
|
|
464
|
+
const c2 = self.charCodeAt(_tmp$3);
|
|
465
|
+
if (56320 <= c2 && c2 <= 57343) {
|
|
466
|
+
_tmp = index + 2 | 0;
|
|
467
|
+
_tmp$2 = count + 1 | 0;
|
|
468
|
+
continue;
|
|
469
|
+
} else {
|
|
470
|
+
moonbitlang$core$abort$$abort$3$("invalid surrogate pair");
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
_tmp = index + 1 | 0;
|
|
474
|
+
_tmp$2 = count + 1 | 0;
|
|
475
|
+
continue;
|
|
476
|
+
} else {
|
|
477
|
+
return count === len && index === end_offset$2;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function moonbitlang$core$string$$String$substring$46$inner(self, start, end) {
|
|
482
|
+
const len = self.length;
|
|
483
|
+
let end$2;
|
|
484
|
+
if (end === undefined) {
|
|
485
|
+
end$2 = len;
|
|
486
|
+
} else {
|
|
487
|
+
const _Some = end;
|
|
488
|
+
end$2 = _Some;
|
|
489
|
+
}
|
|
490
|
+
return start >= 0 && (start <= end$2 && end$2 <= len) ? self.substring(start, end$2) : $panic();
|
|
491
|
+
}
|
|
492
|
+
function moonbitlang$core$builtin$$Logger$write_substring$6$(self, str, start, len) {
|
|
493
|
+
const _bind = self;
|
|
494
|
+
_bind.val = `${_bind.val}${moonbitlang$core$string$$String$substring$46$inner(str, start, start + len | 0)}`;
|
|
495
|
+
}
|
|
496
|
+
function moonbitlang$core$array$$Array$new$46$inner$14$(capacity) {
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
function moonbitlang$core$array$$Array$new$46$inner$15$(capacity) {
|
|
500
|
+
return [];
|
|
501
|
+
}
|
|
502
|
+
function moonbitlang$core$array$$Array$new$46$inner$2$(capacity) {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
function moonbitlang$core$array$$Array$push$15$(self, value) {
|
|
506
|
+
moonbitlang$core$builtin$$JSArray$push(self, value);
|
|
507
|
+
}
|
|
508
|
+
function moonbitlang$core$array$$Array$push$14$(self, value) {
|
|
509
|
+
moonbitlang$core$builtin$$JSArray$push(self, value);
|
|
510
|
+
}
|
|
511
|
+
function moonbitlang$core$array$$Array$push$2$(self, value) {
|
|
512
|
+
moonbitlang$core$builtin$$JSArray$push(self, value);
|
|
513
|
+
}
|
|
514
|
+
function moonbitlang$core$array$$Array$push$5$(self, value) {
|
|
515
|
+
moonbitlang$core$builtin$$JSArray$push(self, value);
|
|
516
|
+
}
|
|
517
|
+
function moonbitlang$core$array$$Array$push$7$(self, value) {
|
|
518
|
+
moonbitlang$core$builtin$$JSArray$push(self, value);
|
|
519
|
+
}
|
|
520
|
+
function moonbitlang$core$builtin$$Show$to_string$16$(self) {
|
|
521
|
+
return String.fromCodePoint(self);
|
|
522
|
+
}
|
|
523
|
+
function moonbitlang$core$builtin$$Iter$each$17$(self, f) {
|
|
524
|
+
const _foreach_result = { val: $64$moonbitlang$47$core$47$builtin$46$ForeachResult$Continue$0$ };
|
|
525
|
+
self((a) => {
|
|
526
|
+
f(a);
|
|
527
|
+
return 1;
|
|
528
|
+
});
|
|
529
|
+
const _tmp = _foreach_result.val;
|
|
530
|
+
switch (_tmp.$tag) {
|
|
531
|
+
case 0: {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
case 1: {
|
|
535
|
+
const _break = _tmp;
|
|
536
|
+
_break._0;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
case 2: {
|
|
540
|
+
const _return = _tmp;
|
|
541
|
+
return _return._0;
|
|
542
|
+
}
|
|
543
|
+
case 3: {
|
|
544
|
+
$panic();
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
default: {
|
|
548
|
+
$panic();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function moonbitlang$core$builtin$$Iter$collect$2$(self) {
|
|
554
|
+
const result = [];
|
|
555
|
+
moonbitlang$core$builtin$$Iter$each$17$(self, (e) => {
|
|
556
|
+
moonbitlang$core$array$$Array$push$2$(result, e);
|
|
557
|
+
});
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
function moonbitlang$core$builtin$$Iterator$next$2$(self) {
|
|
561
|
+
const _func = self;
|
|
562
|
+
return _func();
|
|
563
|
+
}
|
|
564
|
+
function moonbitlang$core$builtin$$Show$output$13$(self, logger) {
|
|
565
|
+
logger.method_0(logger.self, moonbitlang$core$int$$Int$to_string$46$inner(self, 10));
|
|
566
|
+
}
|
|
567
|
+
function moonbitlang$core$array$$Array$iter$7$(self) {
|
|
568
|
+
const _p = (yield_) => {
|
|
569
|
+
const _len = self.length;
|
|
570
|
+
let _tmp = 0;
|
|
571
|
+
while (true) {
|
|
572
|
+
const _i = _tmp;
|
|
573
|
+
if (_i < _len) {
|
|
574
|
+
const v = self[_i];
|
|
575
|
+
const _bind = yield_(v);
|
|
576
|
+
if (_bind === 1) {
|
|
577
|
+
} else {
|
|
578
|
+
return 0;
|
|
579
|
+
}
|
|
580
|
+
_tmp = _i + 1 | 0;
|
|
581
|
+
continue;
|
|
582
|
+
} else {
|
|
583
|
+
return 1;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
return _p;
|
|
588
|
+
}
|
|
589
|
+
function moonbitlang$core$array$$FixedArray$sub$46$inner$2$(self, start, end) {
|
|
590
|
+
const len = self.length;
|
|
591
|
+
let end$2;
|
|
592
|
+
if (end === undefined) {
|
|
593
|
+
end$2 = len;
|
|
594
|
+
} else {
|
|
595
|
+
const _Some = end;
|
|
596
|
+
const _end = _Some;
|
|
597
|
+
end$2 = _end < 0 ? len + _end | 0 : _end;
|
|
598
|
+
}
|
|
599
|
+
const start$2 = start < 0 ? len + start | 0 : start;
|
|
600
|
+
return start$2 >= 0 && (start$2 <= end$2 && end$2 <= len) ? { buf: self, start: start$2, end: end$2 } : moonbitlang$core$abort$$abort$4$("View index out of bounds");
|
|
601
|
+
}
|
|
602
|
+
function moonbitlang$core$builtin$$MyInt64$extend_i32_u(value) {
|
|
603
|
+
return { hi: 0, lo: value };
|
|
604
|
+
}
|
|
605
|
+
function moonbitlang$core$uint64$$UInt64$extend_uint(value) {
|
|
606
|
+
return moonbitlang$core$builtin$$MyInt64$extend_i32_u(value);
|
|
607
|
+
}
|
|
608
|
+
function moonbitlang$core$uint$$UInt$to_uint64(self) {
|
|
609
|
+
return moonbitlang$core$uint64$$UInt64$extend_uint(self);
|
|
610
|
+
}
|
|
611
|
+
function moonbitlang$core$int64$$Int64$reinterpret_as_double(self) {
|
|
612
|
+
return moonbitlang$core$builtin$$MyInt64$reinterpret_as_double(self);
|
|
613
|
+
}
|
|
614
|
+
function moonbitlang$core$builtin$$MyInt64$from_int(value) {
|
|
615
|
+
return { hi: value >> 31 & -1, lo: value | 0 };
|
|
616
|
+
}
|
|
617
|
+
function moonbitlang$core$int$$Int$to_int64(self) {
|
|
618
|
+
return moonbitlang$core$builtin$$MyInt64$from_int(self);
|
|
619
|
+
}
|
|
620
|
+
function moonbitlang$core$uint64$$UInt64$to_int(self) {
|
|
621
|
+
const _p = self;
|
|
622
|
+
return _p.lo;
|
|
623
|
+
}
|
|
624
|
+
function moonbitlang$core$uint64$$UInt64$to_byte(self) {
|
|
625
|
+
return moonbitlang$core$uint64$$UInt64$to_int(self) & 255;
|
|
626
|
+
}
|
|
627
|
+
function moonbitlang$core$builtin$$MyInt64$land(self, other) {
|
|
628
|
+
return { hi: self.hi & other.hi, lo: self.lo & other.lo };
|
|
629
|
+
}
|
|
630
|
+
function moonbitlang$core$builtin$$MyInt64$lor(self, other) {
|
|
631
|
+
return { hi: self.hi | other.hi, lo: self.lo | other.lo };
|
|
632
|
+
}
|
|
633
|
+
function moonbitlang$core$builtin$$MyInt64$lxor(self, other) {
|
|
634
|
+
return { hi: self.hi ^ other.hi, lo: self.lo ^ other.lo };
|
|
635
|
+
}
|
|
636
|
+
function moonbitlang$core$builtin$$MyInt64$lsl(self, shift) {
|
|
637
|
+
const shift$2 = shift & 63;
|
|
638
|
+
if (shift$2 === 0) {
|
|
639
|
+
return self;
|
|
640
|
+
} else {
|
|
641
|
+
if (shift$2 < 32) {
|
|
642
|
+
const _hi = self.hi;
|
|
643
|
+
const _lo = self.lo;
|
|
644
|
+
const hi = _hi;
|
|
645
|
+
const lo = _lo;
|
|
646
|
+
const hi$2 = hi << shift$2 | (lo >>> (32 - shift$2 | 0) | 0);
|
|
647
|
+
const lo$2 = lo << shift$2;
|
|
648
|
+
return { hi: hi$2, lo: lo$2 };
|
|
649
|
+
} else {
|
|
650
|
+
return { hi: self.lo << (shift$2 - 32 | 0), lo: 0 };
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function moonbitlang$core$builtin$$MyInt64$lsr(self, shift) {
|
|
655
|
+
const shift$2 = shift & 63;
|
|
656
|
+
return shift$2 === 0 ? self : shift$2 < 32 ? { hi: self.hi >>> shift$2 | 0, lo: self.lo >>> shift$2 | self.hi << (32 - shift$2 | 0) } : { hi: 0, lo: self.hi >>> (shift$2 - 32 | 0) | 0 };
|
|
657
|
+
}
|
|
658
|
+
function moonbitlang$core$builtin$$BitOr$lor$9$(self, other) {
|
|
659
|
+
return moonbitlang$core$builtin$$MyInt64$lor(self, other);
|
|
660
|
+
}
|
|
661
|
+
function moonbitlang$core$builtin$$Shl$shl$9$(self, other) {
|
|
662
|
+
return moonbitlang$core$builtin$$MyInt64$lsl(self, other);
|
|
663
|
+
}
|
|
664
|
+
function moonbitlang$core$double$$Double$convert_int64(value) {
|
|
665
|
+
return moonbitlang$core$builtin$$MyInt64$convert_to_double(value);
|
|
666
|
+
}
|
|
667
|
+
function moonbitlang$core$int64$$Int64$to_double(self) {
|
|
668
|
+
return moonbitlang$core$double$$Double$convert_int64(self);
|
|
669
|
+
}
|
|
670
|
+
function moonbitlang$core$uint64$$UInt64$reinterpret_as_double(self) {
|
|
671
|
+
return moonbitlang$core$builtin$$MyInt64$reinterpret_as_double(self);
|
|
672
|
+
}
|
|
673
|
+
function moonbitlang$core$double$$Double$reinterpret_as_uint64(self) {
|
|
674
|
+
return moonbitlang$core$builtin$$MyInt64$reinterpret_double(self);
|
|
675
|
+
}
|
|
676
|
+
function moonbitlang$core$builtin$$Eq$equal$18$(self, other) {
|
|
677
|
+
const _p = self;
|
|
678
|
+
const _p$2 = other;
|
|
679
|
+
return _p.hi === _p$2.hi && _p.lo === _p$2.lo;
|
|
680
|
+
}
|
|
681
|
+
function moonbitlang$core$builtin$$BitAnd$land$18$(self, other) {
|
|
682
|
+
return moonbitlang$core$builtin$$MyInt64$land(self, other);
|
|
683
|
+
}
|
|
684
|
+
function moonbitlang$core$builtin$$BitOr$lor$18$(self, other) {
|
|
685
|
+
return moonbitlang$core$builtin$$MyInt64$lor(self, other);
|
|
686
|
+
}
|
|
687
|
+
function moonbitlang$core$builtin$$BitXOr$lxor$18$(self, other) {
|
|
688
|
+
return moonbitlang$core$builtin$$MyInt64$lxor(self, other);
|
|
689
|
+
}
|
|
690
|
+
function moonbitlang$core$builtin$$Shl$shl$18$(self, shift) {
|
|
691
|
+
return moonbitlang$core$builtin$$MyInt64$lsl(self, shift);
|
|
692
|
+
}
|
|
693
|
+
function moonbitlang$core$builtin$$Shr$shr$18$(self, shift) {
|
|
694
|
+
return moonbitlang$core$builtin$$MyInt64$lsr(self, shift);
|
|
695
|
+
}
|
|
696
|
+
function moonbitlang$core$double$$Double$to_int64(self) {
|
|
697
|
+
return moonbitlang$core$builtin$$MyInt64$from_double(self);
|
|
698
|
+
}
|
|
699
|
+
function moonbitlang$core$bytes$$Bytes$makei$11$(length, value) {
|
|
700
|
+
if (length <= 0) {
|
|
701
|
+
return $bytes_literal$0;
|
|
702
|
+
}
|
|
703
|
+
const arr = $makebytes(length, value(0));
|
|
704
|
+
let _tmp = 1;
|
|
705
|
+
while (true) {
|
|
706
|
+
const i = _tmp;
|
|
707
|
+
if (i < length) {
|
|
708
|
+
$bound_check(arr, i);
|
|
709
|
+
arr[i] = value(i);
|
|
710
|
+
_tmp = i + 1 | 0;
|
|
711
|
+
continue;
|
|
712
|
+
} else {
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return arr;
|
|
717
|
+
}
|
|
718
|
+
function moonbitlang$core$builtin$$println$5$(input) {
|
|
719
|
+
console.log(input);
|
|
720
|
+
}
|
|
721
|
+
function moonbitlang$core$array$$FixedArray$blit_from_bytes(self, bytes_offset, src, src_offset, length) {
|
|
722
|
+
const e1 = (bytes_offset + length | 0) - 1 | 0;
|
|
723
|
+
const e2 = (src_offset + length | 0) - 1 | 0;
|
|
724
|
+
const len1 = self.length;
|
|
725
|
+
const len2 = src.length;
|
|
726
|
+
if (length >= 0 && (bytes_offset >= 0 && (e1 < len1 && (src_offset >= 0 && e2 < len2)))) {
|
|
727
|
+
moonbitlang$core$array$$FixedArray$unsafe_blit$2$(self, bytes_offset, src, src_offset, length);
|
|
728
|
+
return;
|
|
729
|
+
} else {
|
|
730
|
+
$panic();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function moonbitlang$core$array$$ArrayView$at$2$(self, index) {
|
|
735
|
+
if (index >= 0 && index < (self.end - self.start | 0)) {
|
|
736
|
+
const _tmp = self.buf;
|
|
737
|
+
const _tmp$2 = self.start + index | 0;
|
|
738
|
+
$bound_check(_tmp, _tmp$2);
|
|
739
|
+
return _tmp[_tmp$2];
|
|
740
|
+
} else {
|
|
741
|
+
return moonbitlang$core$abort$$abort$2$(`index out of bounds: the len is from 0 to ${moonbitlang$core$builtin$$Show$to_string$10$(self.end - self.start | 0)} but the index is ${moonbitlang$core$builtin$$Show$to_string$10$(index)}`);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function moonbitlang$core$array$$Array$rev$2$(self) {
|
|
745
|
+
const len = self.length;
|
|
746
|
+
const arr = new Array(len);
|
|
747
|
+
let _tmp = 0;
|
|
748
|
+
while (true) {
|
|
749
|
+
const i = _tmp;
|
|
750
|
+
if (i < len) {
|
|
751
|
+
arr[i] = self[(len - i | 0) - 1 | 0];
|
|
752
|
+
_tmp = i + 1 | 0;
|
|
753
|
+
continue;
|
|
754
|
+
} else {
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return arr;
|
|
759
|
+
}
|
|
760
|
+
function moonbitlang$core$buffer$$Buffer$grow_if_necessary(self, required) {
|
|
761
|
+
const start = self.data.length <= 0 ? 1 : self.data.length;
|
|
762
|
+
let enough_space;
|
|
763
|
+
let _tmp = start;
|
|
764
|
+
while (true) {
|
|
765
|
+
const space = _tmp;
|
|
766
|
+
if (space >= required) {
|
|
767
|
+
enough_space = space;
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
_tmp = Math.imul(space, 2) | 0;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (enough_space !== self.data.length) {
|
|
774
|
+
const new_data = $makebytes(enough_space, 0);
|
|
775
|
+
moonbitlang$core$array$$FixedArray$unsafe_blit$2$(new_data, 0, self.data, 0, self.len);
|
|
776
|
+
self.data = new_data;
|
|
777
|
+
return;
|
|
778
|
+
} else {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function moonbitlang$core$buffer$$Buffer$write_byte(self, value) {
|
|
783
|
+
moonbitlang$core$buffer$$Buffer$grow_if_necessary(self, self.len + 1 | 0);
|
|
784
|
+
const _tmp = self.data;
|
|
785
|
+
const _tmp$2 = self.len;
|
|
786
|
+
$bound_check(_tmp, _tmp$2);
|
|
787
|
+
_tmp[_tmp$2] = value;
|
|
788
|
+
self.len = self.len + 1 | 0;
|
|
789
|
+
}
|
|
790
|
+
function moonbitlang$core$buffer$$Buffer$contents(self) {
|
|
791
|
+
return moonbitlang$core$bytes$$Bytes$from_array(moonbitlang$core$array$$FixedArray$sub$46$inner$2$(self.data, 0, self.len));
|
|
792
|
+
}
|
|
793
|
+
function moonbitlang$core$buffer$$new$46$inner(size_hint) {
|
|
794
|
+
const initial = size_hint < 1 ? 1 : size_hint;
|
|
795
|
+
const data = $makebytes(initial, 0);
|
|
796
|
+
return { data: data, len: 0 };
|
|
797
|
+
}
|
|
798
|
+
function moonbitlang$core$buffer$$Buffer$write_bytes(self, value) {
|
|
799
|
+
const val_len = value.length;
|
|
800
|
+
moonbitlang$core$buffer$$Buffer$grow_if_necessary(self, self.len + val_len | 0);
|
|
801
|
+
moonbitlang$core$array$$FixedArray$blit_from_bytes(self.data, self.len, value, 0, val_len);
|
|
802
|
+
self.len = self.len + val_len | 0;
|
|
803
|
+
}
|
|
804
|
+
function zxch3n$expect$$Color$to_bg_color_code(self) {
|
|
805
|
+
switch (self) {
|
|
806
|
+
case 0: {
|
|
807
|
+
return "40";
|
|
808
|
+
}
|
|
809
|
+
case 1: {
|
|
810
|
+
return "41";
|
|
811
|
+
}
|
|
812
|
+
case 2: {
|
|
813
|
+
return "42";
|
|
814
|
+
}
|
|
815
|
+
case 3: {
|
|
816
|
+
return "43";
|
|
817
|
+
}
|
|
818
|
+
case 4: {
|
|
819
|
+
return "44";
|
|
820
|
+
}
|
|
821
|
+
case 5: {
|
|
822
|
+
return "45";
|
|
823
|
+
}
|
|
824
|
+
case 6: {
|
|
825
|
+
return "46";
|
|
826
|
+
}
|
|
827
|
+
case 7: {
|
|
828
|
+
return "47";
|
|
829
|
+
}
|
|
830
|
+
default: {
|
|
831
|
+
return "49";
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function zxch3n$expect$$Color$to_color_code(self) {
|
|
836
|
+
switch (self) {
|
|
837
|
+
case 0: {
|
|
838
|
+
return "30";
|
|
839
|
+
}
|
|
840
|
+
case 1: {
|
|
841
|
+
return "31";
|
|
842
|
+
}
|
|
843
|
+
case 2: {
|
|
844
|
+
return "32";
|
|
845
|
+
}
|
|
846
|
+
case 3: {
|
|
847
|
+
return "33";
|
|
848
|
+
}
|
|
849
|
+
case 4: {
|
|
850
|
+
return "34";
|
|
851
|
+
}
|
|
852
|
+
case 5: {
|
|
853
|
+
return "35";
|
|
854
|
+
}
|
|
855
|
+
case 6: {
|
|
856
|
+
return "36";
|
|
857
|
+
}
|
|
858
|
+
case 7: {
|
|
859
|
+
return "37";
|
|
860
|
+
}
|
|
861
|
+
default: {
|
|
862
|
+
return "39";
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function zxch3n$expect$$Formated$to_string(self) {
|
|
867
|
+
const styles = [];
|
|
868
|
+
const _bind = self.color;
|
|
869
|
+
if (_bind === undefined) {
|
|
870
|
+
} else {
|
|
871
|
+
const _Some = _bind;
|
|
872
|
+
const _color = _Some;
|
|
873
|
+
moonbitlang$core$array$$Array$push$5$(styles, zxch3n$expect$$Color$to_color_code(_color));
|
|
874
|
+
}
|
|
875
|
+
const _bind$2 = self.bg_color;
|
|
876
|
+
if (_bind$2 === undefined) {
|
|
877
|
+
} else {
|
|
878
|
+
const _Some = _bind$2;
|
|
879
|
+
const _bg_color = _Some;
|
|
880
|
+
moonbitlang$core$array$$Array$push$5$(styles, zxch3n$expect$$Color$to_bg_color_code(_bg_color));
|
|
881
|
+
}
|
|
882
|
+
const _arr = self.formats;
|
|
883
|
+
const _len = _arr.length;
|
|
884
|
+
let _tmp = 0;
|
|
885
|
+
while (true) {
|
|
886
|
+
const _i = _tmp;
|
|
887
|
+
if (_i < _len) {
|
|
888
|
+
const format = _arr[_i];
|
|
889
|
+
switch (format) {
|
|
890
|
+
case 0: {
|
|
891
|
+
moonbitlang$core$array$$Array$push$5$(styles, "1");
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
case 1: {
|
|
895
|
+
moonbitlang$core$array$$Array$push$5$(styles, "4");
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
case 2: {
|
|
899
|
+
moonbitlang$core$array$$Array$push$5$(styles, "5");
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
case 3: {
|
|
903
|
+
moonbitlang$core$array$$Array$push$5$(styles, "7");
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
case 4: {
|
|
907
|
+
moonbitlang$core$array$$Array$push$5$(styles, "8");
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
case 5: {
|
|
911
|
+
moonbitlang$core$array$$Array$push$5$(styles, "9");
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
default: {
|
|
915
|
+
moonbitlang$core$array$$Array$push$5$(styles, "3");
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
_tmp = _i + 1 | 0;
|
|
919
|
+
continue;
|
|
920
|
+
} else {
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (styles.length > 0) {
|
|
925
|
+
const style_string = moonbitlang$core$array$$Array$join$5$(styles, { str: zxch3n$expect$$to_string$46$42$bind$124$178, start: 0, end: zxch3n$expect$$to_string$46$42$bind$124$178.length });
|
|
926
|
+
return `[${style_string}m${self.str}[0m`;
|
|
927
|
+
} else {
|
|
928
|
+
return self.str;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
function zxch3n$expect$$Formated$format(str) {
|
|
932
|
+
return { str: str, bg_color: undefined, color: undefined, formats: [] };
|
|
933
|
+
}
|
|
934
|
+
function zxch3n$expect$$Formated$red(self) {
|
|
935
|
+
return { str: self.str, bg_color: self.bg_color, color: zxch3n$expect$$red$46$constr$47$350, formats: self.formats };
|
|
936
|
+
}
|
|
937
|
+
function zxch3n$expect$$Formated$yellow(self) {
|
|
938
|
+
return { str: self.str, bg_color: self.bg_color, color: zxch3n$expect$$yellow$46$constr$47$352, formats: self.formats };
|
|
939
|
+
}
|
|
940
|
+
function zxch3n$expect$$Formated$blue(self) {
|
|
941
|
+
return { str: self.str, bg_color: self.bg_color, color: zxch3n$expect$$blue$46$constr$47$354, formats: self.formats };
|
|
942
|
+
}
|
|
943
|
+
function zxch3n$expect$$Formated$bold(self) {
|
|
944
|
+
const _tmp = self.str;
|
|
945
|
+
const _tmp$2 = self.bg_color;
|
|
946
|
+
const _tmp$3 = self.color;
|
|
947
|
+
const _self = [];
|
|
948
|
+
moonbitlang$core$array$$Array$push$7$(_self, 0);
|
|
949
|
+
moonbitlang$core$array$$Array$push_iter$7$(_self, moonbitlang$core$array$$Array$iter$7$(self.formats));
|
|
950
|
+
return { str: _tmp, bg_color: _tmp$2, color: _tmp$3, formats: _self };
|
|
951
|
+
}
|
|
952
|
+
function zxch3n$expect$$panic$46$inner$3$(reason, loc) {
|
|
953
|
+
const msg = `${zxch3n$expect$$Formated$to_string(zxch3n$expect$$Formated$red(zxch3n$expect$$Formated$bold(zxch3n$expect$$Formated$format("Panic: "))))}${zxch3n$expect$$Formated$to_string(zxch3n$expect$$Formated$yellow(zxch3n$expect$$Formated$format(reason)))} at ${zxch3n$expect$$Formated$to_string(zxch3n$expect$$Formated$blue(zxch3n$expect$$Formated$format(loc)))}`;
|
|
954
|
+
moonbitlang$core$builtin$$println$5$(msg);
|
|
955
|
+
moonbitlang$core$abort$$abort$3$(msg);
|
|
956
|
+
}
|
|
957
|
+
function zxch3n$flock$types$$string_to_utf8(str) {
|
|
958
|
+
const bytes = moonbitlang$core$array$$Array$new$46$inner$2$(0);
|
|
959
|
+
let i = 0;
|
|
960
|
+
while (true) {
|
|
961
|
+
if (i < str.length) {
|
|
962
|
+
const _tmp = i;
|
|
963
|
+
$bound_check(str, _tmp);
|
|
964
|
+
const code = str.charCodeAt(_tmp);
|
|
965
|
+
if (code >= 55296 && (code <= 56319 && (i + 1 | 0) < str.length)) {
|
|
966
|
+
const _tmp$2 = i + 1 | 0;
|
|
967
|
+
$bound_check(str, _tmp$2);
|
|
968
|
+
const low = str.charCodeAt(_tmp$2);
|
|
969
|
+
if (low >= 56320 && low <= 57343) {
|
|
970
|
+
const code_point = (65536 + (code - 55296 << 10) | 0) + (low - 56320 | 0) | 0;
|
|
971
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (240 | code_point >> 18) & 255);
|
|
972
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code_point >> 12 & 63) & 255);
|
|
973
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code_point >> 6 & 63) & 255);
|
|
974
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code_point & 63) & 255);
|
|
975
|
+
i = i + 1 | 0;
|
|
976
|
+
} else {
|
|
977
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (224 | code >> 12) & 255);
|
|
978
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code >> 6 & 63) & 255);
|
|
979
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code & 63) & 255);
|
|
980
|
+
}
|
|
981
|
+
} else {
|
|
982
|
+
if (code < 128) {
|
|
983
|
+
moonbitlang$core$array$$Array$push$2$(bytes, code & 255);
|
|
984
|
+
} else {
|
|
985
|
+
if (code < 2048) {
|
|
986
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (192 | code >> 6) & 255);
|
|
987
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code & 63) & 255);
|
|
988
|
+
} else {
|
|
989
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (224 | code >> 12) & 255);
|
|
990
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code >> 6 & 63) & 255);
|
|
991
|
+
moonbitlang$core$array$$Array$push$2$(bytes, (128 | code & 63) & 255);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
i = i + 1 | 0;
|
|
996
|
+
continue;
|
|
997
|
+
} else {
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return moonbitlang$core$bytes$$Bytes$from_array({ buf: bytes, start: 0, end: bytes.length });
|
|
1002
|
+
}
|
|
1003
|
+
function zxch3n$flock$types$$Utf8Str$from_string(str) {
|
|
1004
|
+
return { bytes: zxch3n$flock$types$$string_to_utf8(str) };
|
|
1005
|
+
}
|
|
1006
|
+
function zxch3n$flock$types$$is_valid_utf8(utf8Arr) {
|
|
1007
|
+
let i = 0;
|
|
1008
|
+
while (true) {
|
|
1009
|
+
if (i < (utf8Arr.end - utf8Arr.start | 0)) {
|
|
1010
|
+
const byte = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i);
|
|
1011
|
+
const _p = 128;
|
|
1012
|
+
const _p$2 = byte & _p & 255;
|
|
1013
|
+
const _p$3 = 0;
|
|
1014
|
+
if (_p$2 === _p$3) {
|
|
1015
|
+
i = i + 1 | 0;
|
|
1016
|
+
} else {
|
|
1017
|
+
const _p$4 = 224;
|
|
1018
|
+
const _p$5 = byte & _p$4 & 255;
|
|
1019
|
+
const _p$6 = 192;
|
|
1020
|
+
if (_p$5 === _p$6) {
|
|
1021
|
+
if ((i + 1 | 0) >= (utf8Arr.end - utf8Arr.start | 0)) {
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
const byte2 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 1 | 0);
|
|
1025
|
+
const _p$7 = 192;
|
|
1026
|
+
if ((byte2 & _p$7 & 255) !== 128) {
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
i = i + 2 | 0;
|
|
1030
|
+
} else {
|
|
1031
|
+
const _p$7 = 240;
|
|
1032
|
+
const _p$8 = byte & _p$7 & 255;
|
|
1033
|
+
const _p$9 = 224;
|
|
1034
|
+
if (_p$8 === _p$9) {
|
|
1035
|
+
if ((i + 2 | 0) >= (utf8Arr.end - utf8Arr.start | 0)) {
|
|
1036
|
+
return false;
|
|
1037
|
+
}
|
|
1038
|
+
const byte2 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 1 | 0);
|
|
1039
|
+
const byte3 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 2 | 0);
|
|
1040
|
+
let _tmp;
|
|
1041
|
+
const _p$10 = 192;
|
|
1042
|
+
if ((byte2 & _p$10 & 255) !== 128) {
|
|
1043
|
+
_tmp = true;
|
|
1044
|
+
} else {
|
|
1045
|
+
const _p$11 = 192;
|
|
1046
|
+
_tmp = (byte3 & _p$11 & 255) !== 128;
|
|
1047
|
+
}
|
|
1048
|
+
if (_tmp) {
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
i = i + 3 | 0;
|
|
1052
|
+
} else {
|
|
1053
|
+
const _p$10 = 248;
|
|
1054
|
+
const _p$11 = byte & _p$10 & 255;
|
|
1055
|
+
const _p$12 = 240;
|
|
1056
|
+
if (_p$11 === _p$12) {
|
|
1057
|
+
if ((i + 3 | 0) >= (utf8Arr.end - utf8Arr.start | 0)) {
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
const byte2 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 1 | 0);
|
|
1061
|
+
const byte3 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 2 | 0);
|
|
1062
|
+
const byte4 = moonbitlang$core$bytes$$BytesView$at(utf8Arr, i + 3 | 0);
|
|
1063
|
+
let _tmp;
|
|
1064
|
+
const _p$13 = 192;
|
|
1065
|
+
if ((byte2 & _p$13 & 255) !== 128) {
|
|
1066
|
+
_tmp = true;
|
|
1067
|
+
} else {
|
|
1068
|
+
let _tmp$2;
|
|
1069
|
+
const _p$14 = 192;
|
|
1070
|
+
if ((byte3 & _p$14 & 255) !== 128) {
|
|
1071
|
+
_tmp$2 = true;
|
|
1072
|
+
} else {
|
|
1073
|
+
const _p$15 = 192;
|
|
1074
|
+
_tmp$2 = (byte4 & _p$15 & 255) !== 128;
|
|
1075
|
+
}
|
|
1076
|
+
_tmp = _tmp$2;
|
|
1077
|
+
}
|
|
1078
|
+
if (_tmp) {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
i = i + 4 | 0;
|
|
1082
|
+
} else {
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
continue;
|
|
1089
|
+
} else {
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return true;
|
|
1094
|
+
}
|
|
1095
|
+
function zxch3n$flock$types$$Utf8Str$from_bytes_view(bytes) {
|
|
1096
|
+
if (!zxch3n$flock$types$$is_valid_utf8(moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, 0, undefined))) {
|
|
1097
|
+
return undefined;
|
|
1098
|
+
}
|
|
1099
|
+
return { bytes: moonbitlang$core$bytes$$Bytes$from_iter(moonbitlang$core$bytes$$BytesView$iter(bytes)) };
|
|
1100
|
+
}
|
|
1101
|
+
function zxch3n$flock$types$$new_string_from_utf8(utf8Arr) {
|
|
1102
|
+
let i = 0;
|
|
1103
|
+
let result = "";
|
|
1104
|
+
while (true) {
|
|
1105
|
+
if (i < utf8Arr.length) {
|
|
1106
|
+
const _tmp = i;
|
|
1107
|
+
$bound_check(utf8Arr, _tmp);
|
|
1108
|
+
const byte = utf8Arr[_tmp];
|
|
1109
|
+
let code_point;
|
|
1110
|
+
const _p = 128;
|
|
1111
|
+
const _p$2 = byte & _p & 255;
|
|
1112
|
+
const _p$3 = 0;
|
|
1113
|
+
if (_p$2 === _p$3) {
|
|
1114
|
+
code_point = byte;
|
|
1115
|
+
} else {
|
|
1116
|
+
const _p$4 = 224;
|
|
1117
|
+
const _p$5 = byte & _p$4 & 255;
|
|
1118
|
+
const _p$6 = 192;
|
|
1119
|
+
if (_p$5 === _p$6) {
|
|
1120
|
+
if ((i + 1 | 0) >= utf8Arr.length) {
|
|
1121
|
+
return undefined;
|
|
1122
|
+
}
|
|
1123
|
+
const _tmp$2 = i + 1 | 0;
|
|
1124
|
+
$bound_check(utf8Arr, _tmp$2);
|
|
1125
|
+
const byte2 = utf8Arr[_tmp$2];
|
|
1126
|
+
const _p$7 = 192;
|
|
1127
|
+
if ((byte2 & _p$7 & 255) !== 128) {
|
|
1128
|
+
return undefined;
|
|
1129
|
+
}
|
|
1130
|
+
i = i + 1 | 0;
|
|
1131
|
+
const _p$8 = 31;
|
|
1132
|
+
const _tmp$3 = (byte & _p$8 & 255) << 6;
|
|
1133
|
+
const _p$9 = 63;
|
|
1134
|
+
code_point = _tmp$3 | byte2 & _p$9 & 255;
|
|
1135
|
+
} else {
|
|
1136
|
+
const _p$7 = 240;
|
|
1137
|
+
const _p$8 = byte & _p$7 & 255;
|
|
1138
|
+
const _p$9 = 224;
|
|
1139
|
+
if (_p$8 === _p$9) {
|
|
1140
|
+
if ((i + 2 | 0) >= utf8Arr.length) {
|
|
1141
|
+
return undefined;
|
|
1142
|
+
}
|
|
1143
|
+
const _tmp$2 = i + 1 | 0;
|
|
1144
|
+
$bound_check(utf8Arr, _tmp$2);
|
|
1145
|
+
const byte2 = utf8Arr[_tmp$2];
|
|
1146
|
+
const _tmp$3 = i + 2 | 0;
|
|
1147
|
+
$bound_check(utf8Arr, _tmp$3);
|
|
1148
|
+
const byte3 = utf8Arr[_tmp$3];
|
|
1149
|
+
let _tmp$4;
|
|
1150
|
+
const _p$10 = 192;
|
|
1151
|
+
if ((byte2 & _p$10 & 255) !== 128) {
|
|
1152
|
+
_tmp$4 = true;
|
|
1153
|
+
} else {
|
|
1154
|
+
const _p$11 = 192;
|
|
1155
|
+
_tmp$4 = (byte3 & _p$11 & 255) !== 128;
|
|
1156
|
+
}
|
|
1157
|
+
if (_tmp$4) {
|
|
1158
|
+
return undefined;
|
|
1159
|
+
}
|
|
1160
|
+
i = i + 2 | 0;
|
|
1161
|
+
const _p$11 = 15;
|
|
1162
|
+
const _tmp$5 = (byte & _p$11 & 255) << 12;
|
|
1163
|
+
const _p$12 = 63;
|
|
1164
|
+
const _tmp$6 = _tmp$5 | (byte2 & _p$12 & 255) << 6;
|
|
1165
|
+
const _p$13 = 63;
|
|
1166
|
+
code_point = _tmp$6 | byte3 & _p$13 & 255;
|
|
1167
|
+
} else {
|
|
1168
|
+
const _p$10 = 248;
|
|
1169
|
+
const _p$11 = byte & _p$10 & 255;
|
|
1170
|
+
const _p$12 = 240;
|
|
1171
|
+
if (_p$11 === _p$12) {
|
|
1172
|
+
if ((i + 3 | 0) >= utf8Arr.length) {
|
|
1173
|
+
return undefined;
|
|
1174
|
+
}
|
|
1175
|
+
const _tmp$2 = i + 1 | 0;
|
|
1176
|
+
$bound_check(utf8Arr, _tmp$2);
|
|
1177
|
+
const byte2 = utf8Arr[_tmp$2];
|
|
1178
|
+
const _tmp$3 = i + 2 | 0;
|
|
1179
|
+
$bound_check(utf8Arr, _tmp$3);
|
|
1180
|
+
const byte3 = utf8Arr[_tmp$3];
|
|
1181
|
+
const _tmp$4 = i + 3 | 0;
|
|
1182
|
+
$bound_check(utf8Arr, _tmp$4);
|
|
1183
|
+
const byte4 = utf8Arr[_tmp$4];
|
|
1184
|
+
let _tmp$5;
|
|
1185
|
+
const _p$13 = 192;
|
|
1186
|
+
if ((byte2 & _p$13 & 255) !== 128) {
|
|
1187
|
+
_tmp$5 = true;
|
|
1188
|
+
} else {
|
|
1189
|
+
let _tmp$6;
|
|
1190
|
+
const _p$14 = 192;
|
|
1191
|
+
if ((byte3 & _p$14 & 255) !== 128) {
|
|
1192
|
+
_tmp$6 = true;
|
|
1193
|
+
} else {
|
|
1194
|
+
const _p$15 = 192;
|
|
1195
|
+
_tmp$6 = (byte4 & _p$15 & 255) !== 128;
|
|
1196
|
+
}
|
|
1197
|
+
_tmp$5 = _tmp$6;
|
|
1198
|
+
}
|
|
1199
|
+
if (_tmp$5) {
|
|
1200
|
+
return undefined;
|
|
1201
|
+
}
|
|
1202
|
+
i = i + 3 | 0;
|
|
1203
|
+
const _p$14 = 7;
|
|
1204
|
+
const _tmp$6 = (byte & _p$14 & 255) << 18;
|
|
1205
|
+
const _p$15 = 63;
|
|
1206
|
+
const _tmp$7 = _tmp$6 | (byte2 & _p$15 & 255) << 12;
|
|
1207
|
+
const _p$16 = 63;
|
|
1208
|
+
const _tmp$8 = _tmp$7 | (byte3 & _p$16 & 255) << 6;
|
|
1209
|
+
const _p$17 = 63;
|
|
1210
|
+
code_point = _tmp$8 | byte4 & _p$17 & 255;
|
|
1211
|
+
} else {
|
|
1212
|
+
return undefined;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
result = `${result}${moonbitlang$core$builtin$$Show$to_string$16$(code_point)}`;
|
|
1218
|
+
i = i + 1 | 0;
|
|
1219
|
+
continue;
|
|
1220
|
+
} else {
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return result;
|
|
1225
|
+
}
|
|
1226
|
+
function zxch3n$flock$types$$Utf8Str$to_string(self) {
|
|
1227
|
+
const _p = zxch3n$flock$types$$new_string_from_utf8(self.bytes);
|
|
1228
|
+
if (_p === undefined) {
|
|
1229
|
+
return $panic();
|
|
1230
|
+
} else {
|
|
1231
|
+
const _p$2 = _p;
|
|
1232
|
+
return _p$2;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function zxch3n$flock$memcomparable$$double_to_bits(d) {
|
|
1236
|
+
return moonbitlang$core$double$$Double$reinterpret_as_uint64(d);
|
|
1237
|
+
}
|
|
1238
|
+
function zxch3n$flock$memcomparable$$double_from_bits(bits) {
|
|
1239
|
+
return moonbitlang$core$uint64$$UInt64$reinterpret_as_double(bits);
|
|
1240
|
+
}
|
|
1241
|
+
function zxch3n$flock$memcomparable$$uint64_to_be_bytes(n) {
|
|
1242
|
+
const bytes = moonbitlang$core$array$$Array$new$46$inner$2$(0);
|
|
1243
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 56), $255L)));
|
|
1244
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 48), $255L)));
|
|
1245
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 40), $255L)));
|
|
1246
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 32), $255L)));
|
|
1247
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 24), $255L)));
|
|
1248
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 16), $255L)));
|
|
1249
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(moonbitlang$core$builtin$$Shr$shr$18$(n, 8), $255L)));
|
|
1250
|
+
moonbitlang$core$array$$Array$push$2$(bytes, moonbitlang$core$uint64$$UInt64$to_byte(moonbitlang$core$builtin$$BitAnd$land$18$(n, $255L)));
|
|
1251
|
+
return moonbitlang$core$bytes$$Bytes$from_array({ buf: bytes, start: 0, end: bytes.length });
|
|
1252
|
+
}
|
|
1253
|
+
function zxch3n$flock$memcomparable$$uint64_from_be_bytes(bytes) {
|
|
1254
|
+
if (bytes.length !== 8) {
|
|
1255
|
+
zxch3n$expect$$panic$46$inner$3$("Invalid byte array length", "/Users/zxch3n/Code/flock/moon/memcomparable/utils.mbt:28:5-28:54");
|
|
1256
|
+
}
|
|
1257
|
+
let result = $0L;
|
|
1258
|
+
const _tmp = result;
|
|
1259
|
+
$bound_check(bytes, 0);
|
|
1260
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[0]), 56));
|
|
1261
|
+
const _tmp$2 = result;
|
|
1262
|
+
$bound_check(bytes, 1);
|
|
1263
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$2, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[1]), 48));
|
|
1264
|
+
const _tmp$3 = result;
|
|
1265
|
+
$bound_check(bytes, 2);
|
|
1266
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$3, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[2]), 40));
|
|
1267
|
+
const _tmp$4 = result;
|
|
1268
|
+
$bound_check(bytes, 3);
|
|
1269
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$4, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[3]), 32));
|
|
1270
|
+
const _tmp$5 = result;
|
|
1271
|
+
$bound_check(bytes, 4);
|
|
1272
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$5, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[4]), 24));
|
|
1273
|
+
const _tmp$6 = result;
|
|
1274
|
+
$bound_check(bytes, 5);
|
|
1275
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$6, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[5]), 16));
|
|
1276
|
+
const _tmp$7 = result;
|
|
1277
|
+
$bound_check(bytes, 6);
|
|
1278
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$7, moonbitlang$core$builtin$$Shl$shl$18$(moonbitlang$core$byte$$Byte$to_uint64(bytes[6]), 8));
|
|
1279
|
+
const _tmp$8 = result;
|
|
1280
|
+
$bound_check(bytes, 7);
|
|
1281
|
+
result = moonbitlang$core$builtin$$BitOr$lor$18$(_tmp$8, moonbitlang$core$byte$$Byte$to_uint64(bytes[7]));
|
|
1282
|
+
return result;
|
|
1283
|
+
}
|
|
1284
|
+
function zxch3n$flock$memcomparable$$Key$new() {
|
|
1285
|
+
return { parts: moonbitlang$core$array$$Array$new$46$inner$15$(0) };
|
|
1286
|
+
}
|
|
1287
|
+
function zxch3n$flock$memcomparable$$Key$push(self, part) {
|
|
1288
|
+
moonbitlang$core$array$$Array$push$15$(self.parts, part);
|
|
1289
|
+
}
|
|
1290
|
+
function zxch3n$flock$memcomparable$$canonicalize_f64(n) {
|
|
1291
|
+
return n !== n ? (n < 0 ? -moonbitlang$core$double$$not_a_number : moonbitlang$core$double$$not_a_number) : n;
|
|
1292
|
+
}
|
|
1293
|
+
function zxch3n$flock$memcomparable$$encode_bytes(bytes, output) {
|
|
1294
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 1);
|
|
1295
|
+
const _it = moonbitlang$core$bytes$$BytesView$iterator(bytes);
|
|
1296
|
+
while (true) {
|
|
1297
|
+
const _bind = moonbitlang$core$builtin$$Iterator$next$2$(_it);
|
|
1298
|
+
if (_bind === -1) {
|
|
1299
|
+
break;
|
|
1300
|
+
} else {
|
|
1301
|
+
const _Some = _bind;
|
|
1302
|
+
const _b = _Some;
|
|
1303
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, _b);
|
|
1304
|
+
const _p = 0;
|
|
1305
|
+
if (_b === _p) {
|
|
1306
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 255);
|
|
1307
|
+
}
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 0);
|
|
1312
|
+
}
|
|
1313
|
+
function zxch3n$flock$memcomparable$$encode_string(s, output) {
|
|
1314
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 2);
|
|
1315
|
+
const bytes = s.bytes;
|
|
1316
|
+
const _len = bytes.length;
|
|
1317
|
+
let _tmp = 0;
|
|
1318
|
+
while (true) {
|
|
1319
|
+
const _i = _tmp;
|
|
1320
|
+
if (_i < _len) {
|
|
1321
|
+
const b = bytes[_i];
|
|
1322
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, b);
|
|
1323
|
+
const _p = 0;
|
|
1324
|
+
if (b === _p) {
|
|
1325
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 255);
|
|
1326
|
+
}
|
|
1327
|
+
_tmp = _i + 1 | 0;
|
|
1328
|
+
continue;
|
|
1329
|
+
} else {
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 0);
|
|
1334
|
+
}
|
|
1335
|
+
function zxch3n$flock$memcomparable$$encode_float(f, output) {
|
|
1336
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 33);
|
|
1337
|
+
const f$2 = zxch3n$flock$memcomparable$$canonicalize_f64(f);
|
|
1338
|
+
const bits = f$2 < 0 ? moonbitlang$core$builtin$$BitXOr$lxor$18$(zxch3n$flock$memcomparable$$double_to_bits(f$2), $_1L) : moonbitlang$core$builtin$$BitXOr$lxor$18$(zxch3n$flock$memcomparable$$double_to_bits(f$2), $_9223372036854775808L);
|
|
1339
|
+
const bytes = zxch3n$flock$memcomparable$$uint64_to_be_bytes(bits);
|
|
1340
|
+
const _len = bytes.length;
|
|
1341
|
+
let _tmp = 0;
|
|
1342
|
+
while (true) {
|
|
1343
|
+
const _i = _tmp;
|
|
1344
|
+
if (_i < _len) {
|
|
1345
|
+
const b = bytes[_i];
|
|
1346
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, b);
|
|
1347
|
+
_tmp = _i + 1 | 0;
|
|
1348
|
+
continue;
|
|
1349
|
+
} else {
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function zxch3n$flock$memcomparable$$biguint_to_be_bytes(n) {
|
|
1355
|
+
const bytes = [];
|
|
1356
|
+
let x = n;
|
|
1357
|
+
while (true) {
|
|
1358
|
+
if (moonbitlang$core$builtin$$Compare$op_gt$12$(x, 0n)) {
|
|
1359
|
+
const byte = moonbitlang$core$bigint$$BigInt$to_int(moonbitlang$core$builtin$$Mod$mod$8$(x, 256n));
|
|
1360
|
+
moonbitlang$core$array$$Array$push$2$(bytes, byte & 255);
|
|
1361
|
+
x = moonbitlang$core$builtin$$Div$div$8$(x, 256n);
|
|
1362
|
+
continue;
|
|
1363
|
+
} else {
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
const _bind = moonbitlang$core$array$$Array$rev$2$(bytes);
|
|
1368
|
+
return moonbitlang$core$bytes$$Bytes$from_array({ buf: _bind, start: 0, end: _bind.length });
|
|
1369
|
+
}
|
|
1370
|
+
function zxch3n$flock$memcomparable$$bigint_to_be_bytes(n, output) {
|
|
1371
|
+
if (moonbitlang$core$builtin$$Eq$equal$8$(n, 0n)) {
|
|
1372
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 20);
|
|
1373
|
+
return undefined;
|
|
1374
|
+
}
|
|
1375
|
+
const sign = moonbitlang$core$builtin$$Compare$op_gt$12$(n, 0n);
|
|
1376
|
+
const bytes = sign ? zxch3n$flock$memcomparable$$biguint_to_be_bytes(n) : zxch3n$flock$memcomparable$$biguint_to_be_bytes(moonbitlang$core$builtin$$Neg$neg$8$(n));
|
|
1377
|
+
const n$2 = bytes.length;
|
|
1378
|
+
if (sign === false) {
|
|
1379
|
+
if (n$2 <= 8) {
|
|
1380
|
+
const _p = 20;
|
|
1381
|
+
const _p$2 = n$2 & 255;
|
|
1382
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, (_p - _p$2 | 0) & 255);
|
|
1383
|
+
} else {
|
|
1384
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 11);
|
|
1385
|
+
if (n$2 > 255) {
|
|
1386
|
+
moonbitlang$core$abort$$abort$3$("n is too large");
|
|
1387
|
+
}
|
|
1388
|
+
const _p = n$2 & 255;
|
|
1389
|
+
const _p$2 = 255;
|
|
1390
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, (_p ^ _p$2) & 255);
|
|
1391
|
+
}
|
|
1392
|
+
const inverted = moonbitlang$core$buffer$$new$46$inner(0);
|
|
1393
|
+
let _tmp = 0;
|
|
1394
|
+
while (true) {
|
|
1395
|
+
const i = _tmp;
|
|
1396
|
+
if (i < bytes.length) {
|
|
1397
|
+
$bound_check(bytes, i);
|
|
1398
|
+
const _p = bytes[i];
|
|
1399
|
+
const _p$2 = 255;
|
|
1400
|
+
moonbitlang$core$buffer$$Buffer$write_byte(inverted, (_p ^ _p$2) & 255);
|
|
1401
|
+
_tmp = i + 1 | 0;
|
|
1402
|
+
continue;
|
|
1403
|
+
} else {
|
|
1404
|
+
break;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
moonbitlang$core$buffer$$Buffer$write_bytes(output, moonbitlang$core$buffer$$Buffer$contents(inverted));
|
|
1408
|
+
return;
|
|
1409
|
+
} else {
|
|
1410
|
+
if (n$2 <= 8) {
|
|
1411
|
+
const _p = 20;
|
|
1412
|
+
const _p$2 = n$2 & 255;
|
|
1413
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, (_p + _p$2 | 0) & 255);
|
|
1414
|
+
} else {
|
|
1415
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 29);
|
|
1416
|
+
if (n$2 > 255) {
|
|
1417
|
+
moonbitlang$core$abort$$abort$3$("n is too large");
|
|
1418
|
+
}
|
|
1419
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, n$2 & 255);
|
|
1420
|
+
}
|
|
1421
|
+
moonbitlang$core$buffer$$Buffer$write_bytes(output, bytes);
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
function zxch3n$flock$memcomparable$$KeyPart$encode_with_output(self, output) {
|
|
1426
|
+
switch (self.$tag) {
|
|
1427
|
+
case 0: {
|
|
1428
|
+
const _Bytes = self;
|
|
1429
|
+
const _bytes = _Bytes._0;
|
|
1430
|
+
const _bind = _bytes;
|
|
1431
|
+
zxch3n$flock$memcomparable$$encode_bytes(moonbitlang$core$bytes$$Bytes$sub$46$inner(_bind, 0, _bind.length), output);
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
case 1: {
|
|
1435
|
+
const _String = self;
|
|
1436
|
+
const _s = _String._0;
|
|
1437
|
+
zxch3n$flock$memcomparable$$encode_string(_s, output);
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
case 2: {
|
|
1441
|
+
const _Int = self;
|
|
1442
|
+
const _n = _Int._0;
|
|
1443
|
+
zxch3n$flock$memcomparable$$bigint_to_be_bytes(_n, output);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
case 3: {
|
|
1447
|
+
const _Float = self;
|
|
1448
|
+
const _f = _Float._0;
|
|
1449
|
+
zxch3n$flock$memcomparable$$encode_float(_f, output);
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
case 4: {
|
|
1453
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 38);
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
default: {
|
|
1457
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 39);
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function zxch3n$flock$memcomparable$$Key$encode(self) {
|
|
1463
|
+
const output = moonbitlang$core$buffer$$new$46$inner(0);
|
|
1464
|
+
const _arr = self.parts;
|
|
1465
|
+
const _len = _arr.length;
|
|
1466
|
+
let _tmp = 0;
|
|
1467
|
+
while (true) {
|
|
1468
|
+
const _i = _tmp;
|
|
1469
|
+
if (_i < _len) {
|
|
1470
|
+
const part = _arr[_i];
|
|
1471
|
+
zxch3n$flock$memcomparable$$KeyPart$encode_with_output(part, output);
|
|
1472
|
+
_tmp = _i + 1 | 0;
|
|
1473
|
+
continue;
|
|
1474
|
+
} else {
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return moonbitlang$core$buffer$$Buffer$contents(output);
|
|
1479
|
+
}
|
|
1480
|
+
function zxch3n$flock$memcomparable$$parse_slice(bytes, start) {
|
|
1481
|
+
const output = moonbitlang$core$buffer$$new$46$inner(0);
|
|
1482
|
+
let i = start;
|
|
1483
|
+
while (true) {
|
|
1484
|
+
if (i < (bytes.end - bytes.start | 0)) {
|
|
1485
|
+
const b = moonbitlang$core$bytes$$BytesView$at(bytes, i);
|
|
1486
|
+
i = i + 1 | 0;
|
|
1487
|
+
const _p = 0;
|
|
1488
|
+
if (b === _p) {
|
|
1489
|
+
let _tmp;
|
|
1490
|
+
if (i < (bytes.end - bytes.start | 0)) {
|
|
1491
|
+
const _p$2 = moonbitlang$core$bytes$$BytesView$at(bytes, i);
|
|
1492
|
+
const _p$3 = 255;
|
|
1493
|
+
_tmp = _p$2 === _p$3;
|
|
1494
|
+
} else {
|
|
1495
|
+
_tmp = false;
|
|
1496
|
+
}
|
|
1497
|
+
if (_tmp) {
|
|
1498
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, 0);
|
|
1499
|
+
i = i + 1 | 0;
|
|
1500
|
+
continue;
|
|
1501
|
+
} else {
|
|
1502
|
+
const _bind = moonbitlang$core$buffer$$Buffer$contents(output);
|
|
1503
|
+
return new Result$Ok$1$({ _0: moonbitlang$core$bytes$$Bytes$sub$46$inner(_bind, 0, _bind.length), _1: i });
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
moonbitlang$core$buffer$$Buffer$write_byte(output, b);
|
|
1507
|
+
continue;
|
|
1508
|
+
} else {
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return new Result$Err$1$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1513
|
+
}
|
|
1514
|
+
function zxch3n$flock$memcomparable$$bytes_to_bigint(bytes) {
|
|
1515
|
+
let n = moonbitlang$core$bigint$$BigInt$from_int64($0L);
|
|
1516
|
+
let base = moonbitlang$core$bigint$$BigInt$from_int64($1L);
|
|
1517
|
+
let _tmp = (bytes.end - bytes.start | 0) - 1 | 0;
|
|
1518
|
+
while (true) {
|
|
1519
|
+
const i = _tmp;
|
|
1520
|
+
if (i >= 0) {
|
|
1521
|
+
const byte_val = moonbitlang$core$bigint$$BigInt$from_int64(moonbitlang$core$int$$Int$to_int64(moonbitlang$core$bytes$$BytesView$at(bytes, i)));
|
|
1522
|
+
n = moonbitlang$core$builtin$$Add$add$8$(n, moonbitlang$core$builtin$$Mul$mul$8$(base, byte_val));
|
|
1523
|
+
base = moonbitlang$core$builtin$$Mul$mul$8$(base, moonbitlang$core$bigint$$BigInt$from_int64($256L));
|
|
1524
|
+
_tmp = i - 1 | 0;
|
|
1525
|
+
continue;
|
|
1526
|
+
} else {
|
|
1527
|
+
break;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return n;
|
|
1531
|
+
}
|
|
1532
|
+
function zxch3n$flock$memcomparable$$bigint_from_be_bytes_with_tag(bytes, tag) {
|
|
1533
|
+
let _tmp;
|
|
1534
|
+
if (20 <= tag) {
|
|
1535
|
+
const _p = 20;
|
|
1536
|
+
const _p$2 = 8 & 255;
|
|
1537
|
+
_tmp = tag <= ((_p + _p$2 | 0) & 255);
|
|
1538
|
+
} else {
|
|
1539
|
+
_tmp = false;
|
|
1540
|
+
}
|
|
1541
|
+
if (_tmp) {
|
|
1542
|
+
const _p = 20;
|
|
1543
|
+
const n = (tag - _p | 0) & 255;
|
|
1544
|
+
if ((bytes.end - bytes.start | 0) < n) {
|
|
1545
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1546
|
+
}
|
|
1547
|
+
const num_bytes = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, 0, n);
|
|
1548
|
+
const rest = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, n, undefined);
|
|
1549
|
+
return new Result$Ok$2$({ _0: rest, _1: zxch3n$flock$memcomparable$$bytes_to_bigint(num_bytes) });
|
|
1550
|
+
} else {
|
|
1551
|
+
let _tmp$2;
|
|
1552
|
+
const _p = 20;
|
|
1553
|
+
const _p$2 = 8 & 255;
|
|
1554
|
+
if (((_p - _p$2 | 0) & 255) <= tag) {
|
|
1555
|
+
_tmp$2 = tag < 20;
|
|
1556
|
+
} else {
|
|
1557
|
+
_tmp$2 = false;
|
|
1558
|
+
}
|
|
1559
|
+
if (_tmp$2) {
|
|
1560
|
+
const _p$3 = 20;
|
|
1561
|
+
const n = (_p$3 - tag | 0) & 255;
|
|
1562
|
+
if ((bytes.end - bytes.start | 0) < n) {
|
|
1563
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1564
|
+
}
|
|
1565
|
+
const num_bytes = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, 0, n);
|
|
1566
|
+
const rest = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, n, undefined);
|
|
1567
|
+
const inverted = moonbitlang$core$buffer$$new$46$inner(0);
|
|
1568
|
+
let _tmp$3 = 0;
|
|
1569
|
+
while (true) {
|
|
1570
|
+
const i = _tmp$3;
|
|
1571
|
+
if (i < (num_bytes.end - num_bytes.start | 0)) {
|
|
1572
|
+
const _p$4 = moonbitlang$core$bytes$$BytesView$at(num_bytes, i);
|
|
1573
|
+
const _p$5 = 255;
|
|
1574
|
+
moonbitlang$core$buffer$$Buffer$write_byte(inverted, (_p$4 ^ _p$5) & 255);
|
|
1575
|
+
_tmp$3 = i + 1 | 0;
|
|
1576
|
+
continue;
|
|
1577
|
+
} else {
|
|
1578
|
+
break;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
const _bind = moonbitlang$core$buffer$$Buffer$contents(inverted);
|
|
1582
|
+
return new Result$Ok$2$({ _0: rest, _1: moonbitlang$core$builtin$$Neg$neg$8$(zxch3n$flock$memcomparable$$bytes_to_bigint(moonbitlang$core$bytes$$Bytes$sub$46$inner(_bind, 0, _bind.length))) });
|
|
1583
|
+
} else {
|
|
1584
|
+
const _p$3 = 11;
|
|
1585
|
+
if (tag === _p$3) {
|
|
1586
|
+
if ((bytes.end - bytes.start | 0) < 1) {
|
|
1587
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1588
|
+
}
|
|
1589
|
+
const raw_length = moonbitlang$core$bytes$$BytesView$at(bytes, 0);
|
|
1590
|
+
const _p$4 = 255;
|
|
1591
|
+
const n = (raw_length ^ _p$4) & 255;
|
|
1592
|
+
if ((bytes.end - bytes.start | 0) < (n + 1 | 0)) {
|
|
1593
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1594
|
+
}
|
|
1595
|
+
const num_bytes = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, 1, n + 1 | 0);
|
|
1596
|
+
const rest = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, n + 1 | 0, undefined);
|
|
1597
|
+
const inverted = moonbitlang$core$buffer$$new$46$inner(0);
|
|
1598
|
+
let _tmp$3 = 0;
|
|
1599
|
+
while (true) {
|
|
1600
|
+
const i = _tmp$3;
|
|
1601
|
+
if (i < (num_bytes.end - num_bytes.start | 0)) {
|
|
1602
|
+
const _p$5 = moonbitlang$core$bytes$$BytesView$at(num_bytes, i);
|
|
1603
|
+
const _p$6 = 255;
|
|
1604
|
+
moonbitlang$core$buffer$$Buffer$write_byte(inverted, (_p$5 ^ _p$6) & 255);
|
|
1605
|
+
_tmp$3 = i + 1 | 0;
|
|
1606
|
+
continue;
|
|
1607
|
+
} else {
|
|
1608
|
+
break;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
const _bind = moonbitlang$core$buffer$$Buffer$contents(inverted);
|
|
1612
|
+
return new Result$Ok$2$({ _0: rest, _1: moonbitlang$core$builtin$$Neg$neg$8$(zxch3n$flock$memcomparable$$bytes_to_bigint(moonbitlang$core$bytes$$Bytes$sub$46$inner(_bind, 0, _bind.length))) });
|
|
1613
|
+
} else {
|
|
1614
|
+
const _p$4 = 29;
|
|
1615
|
+
if (tag === _p$4) {
|
|
1616
|
+
if ((bytes.end - bytes.start | 0) < 1) {
|
|
1617
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1618
|
+
}
|
|
1619
|
+
const raw_length = moonbitlang$core$bytes$$BytesView$at(bytes, 0);
|
|
1620
|
+
const n = raw_length;
|
|
1621
|
+
if ((bytes.end - bytes.start | 0) < (n + 1 | 0)) {
|
|
1622
|
+
return new Result$Err$2$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1623
|
+
}
|
|
1624
|
+
const num_bytes = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, 1, n + 1 | 0);
|
|
1625
|
+
const rest = moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, n + 1 | 0, undefined);
|
|
1626
|
+
return new Result$Ok$2$({ _0: rest, _1: zxch3n$flock$memcomparable$$bytes_to_bigint(num_bytes) });
|
|
1627
|
+
} else {
|
|
1628
|
+
return new Result$Err$2$(new Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidTag(tag));
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
function zxch3n$flock$memcomparable$$decode_float(bytes, start) {
|
|
1635
|
+
if ((start + 8 | 0) > (bytes.end - bytes.start | 0)) {
|
|
1636
|
+
return new Result$Err$3$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$UnexpectedEOF);
|
|
1637
|
+
}
|
|
1638
|
+
const data = moonbitlang$core$array$$Array$new$46$inner$2$(0);
|
|
1639
|
+
let _tmp = 0;
|
|
1640
|
+
while (true) {
|
|
1641
|
+
const i = _tmp;
|
|
1642
|
+
if (i < 8) {
|
|
1643
|
+
moonbitlang$core$array$$Array$push$2$(data, moonbitlang$core$bytes$$BytesView$at(bytes, start + i | 0));
|
|
1644
|
+
_tmp = i + 1 | 0;
|
|
1645
|
+
continue;
|
|
1646
|
+
} else {
|
|
1647
|
+
break;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
const bits = zxch3n$flock$memcomparable$$uint64_from_be_bytes(moonbitlang$core$bytes$$Bytes$from_array({ buf: data, start: 0, end: data.length }));
|
|
1651
|
+
const f = moonbitlang$core$builtin$$Eq$equal$18$(moonbitlang$core$builtin$$BitAnd$land$18$(bits, $_9223372036854775808L), $0L) ? zxch3n$flock$memcomparable$$double_from_bits(moonbitlang$core$builtin$$BitXOr$lxor$18$(bits, $_1L)) : zxch3n$flock$memcomparable$$double_from_bits(moonbitlang$core$builtin$$BitXOr$lxor$18$(bits, $_9223372036854775808L));
|
|
1652
|
+
return new Result$Ok$3$({ _0: f, _1: start + 8 | 0 });
|
|
1653
|
+
}
|
|
1654
|
+
function zxch3n$flock$memcomparable$$Key$decode(bytes) {
|
|
1655
|
+
const key = zxch3n$flock$memcomparable$$Key$new();
|
|
1656
|
+
let i = 0;
|
|
1657
|
+
while (true) {
|
|
1658
|
+
if (i < (bytes.end - bytes.start | 0)) {
|
|
1659
|
+
const tag = moonbitlang$core$bytes$$BytesView$at(bytes, i);
|
|
1660
|
+
i = i + 1 | 0;
|
|
1661
|
+
if (tag === 2) {
|
|
1662
|
+
const _bind = zxch3n$flock$memcomparable$$parse_slice(bytes, i);
|
|
1663
|
+
let _bind$2;
|
|
1664
|
+
if (_bind.$tag === 1) {
|
|
1665
|
+
const _ok = _bind;
|
|
1666
|
+
_bind$2 = _ok._0;
|
|
1667
|
+
} else {
|
|
1668
|
+
return _bind;
|
|
1669
|
+
}
|
|
1670
|
+
const _data = _bind$2._0;
|
|
1671
|
+
const _next_i = _bind$2._1;
|
|
1672
|
+
const _bind$3 = zxch3n$flock$types$$Utf8Str$from_bytes_view(_data);
|
|
1673
|
+
if (_bind$3 === undefined) {
|
|
1674
|
+
return new Result$Err$4$(Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidUTF8);
|
|
1675
|
+
} else {
|
|
1676
|
+
const _Some = _bind$3;
|
|
1677
|
+
const _s = _Some;
|
|
1678
|
+
zxch3n$flock$memcomparable$$Key$push(key, new KeyPart$String(_s));
|
|
1679
|
+
}
|
|
1680
|
+
i = _next_i;
|
|
1681
|
+
} else {
|
|
1682
|
+
if (tag === 1) {
|
|
1683
|
+
const _bind = zxch3n$flock$memcomparable$$parse_slice(bytes, i);
|
|
1684
|
+
let _bind$2;
|
|
1685
|
+
if (_bind.$tag === 1) {
|
|
1686
|
+
const _ok = _bind;
|
|
1687
|
+
_bind$2 = _ok._0;
|
|
1688
|
+
} else {
|
|
1689
|
+
return _bind;
|
|
1690
|
+
}
|
|
1691
|
+
const _data = _bind$2._0;
|
|
1692
|
+
const _next_i = _bind$2._1;
|
|
1693
|
+
zxch3n$flock$memcomparable$$Key$push(key, new KeyPart$Bytes(moonbitlang$core$bytes$$Bytes$from_iter(moonbitlang$core$bytes$$BytesView$iter(_data))));
|
|
1694
|
+
i = _next_i;
|
|
1695
|
+
} else {
|
|
1696
|
+
if (tag >= 11 && tag <= 29) {
|
|
1697
|
+
const _bind = zxch3n$flock$memcomparable$$bigint_from_be_bytes_with_tag(moonbitlang$core$bytes$$BytesView$sub$46$inner(bytes, i, undefined), tag);
|
|
1698
|
+
let _bind$2;
|
|
1699
|
+
if (_bind.$tag === 1) {
|
|
1700
|
+
const _ok = _bind;
|
|
1701
|
+
_bind$2 = _ok._0;
|
|
1702
|
+
} else {
|
|
1703
|
+
return _bind;
|
|
1704
|
+
}
|
|
1705
|
+
const _view = _bind$2._0;
|
|
1706
|
+
const _data = _bind$2._1;
|
|
1707
|
+
zxch3n$flock$memcomparable$$Key$push(key, new KeyPart$Int(_data));
|
|
1708
|
+
i = (bytes.end - bytes.start | 0) - (_view.end - _view.start | 0) | 0;
|
|
1709
|
+
} else {
|
|
1710
|
+
if (tag === 33) {
|
|
1711
|
+
const _bind = zxch3n$flock$memcomparable$$decode_float(bytes, i);
|
|
1712
|
+
let _bind$2;
|
|
1713
|
+
if (_bind.$tag === 1) {
|
|
1714
|
+
const _ok = _bind;
|
|
1715
|
+
_bind$2 = _ok._0;
|
|
1716
|
+
} else {
|
|
1717
|
+
return _bind;
|
|
1718
|
+
}
|
|
1719
|
+
const _data = _bind$2._0;
|
|
1720
|
+
const _next_i = _bind$2._1;
|
|
1721
|
+
zxch3n$flock$memcomparable$$Key$push(key, new KeyPart$Float(_data));
|
|
1722
|
+
i = _next_i;
|
|
1723
|
+
} else {
|
|
1724
|
+
if (tag === 38) {
|
|
1725
|
+
zxch3n$flock$memcomparable$$Key$push(key, KeyPart$False);
|
|
1726
|
+
} else {
|
|
1727
|
+
if (tag === 39) {
|
|
1728
|
+
zxch3n$flock$memcomparable$$Key$push(key, KeyPart$True);
|
|
1729
|
+
} else {
|
|
1730
|
+
return new Result$Err$4$(new Error$zxch3n$47$flock$47$memcomparable$46$KeyError$46$InvalidTag(tag));
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
continue;
|
|
1738
|
+
} else {
|
|
1739
|
+
break;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
return new Result$Ok$4$(key);
|
|
1743
|
+
}
|
|
1744
|
+
function zxch3n$flock$memcomparable$$key_part_to_js_part(part) {
|
|
1745
|
+
switch (part.$tag) {
|
|
1746
|
+
case 0: {
|
|
1747
|
+
const _Bytes = part;
|
|
1748
|
+
const _bytes = _Bytes._0;
|
|
1749
|
+
return new KeyJsPart$Bytes(_bytes);
|
|
1750
|
+
}
|
|
1751
|
+
case 1: {
|
|
1752
|
+
const _String = part;
|
|
1753
|
+
const _s = _String._0;
|
|
1754
|
+
return new KeyJsPart$String(zxch3n$flock$types$$Utf8Str$to_string(_s));
|
|
1755
|
+
}
|
|
1756
|
+
case 2: {
|
|
1757
|
+
const _Int = part;
|
|
1758
|
+
const _n = _Int._0;
|
|
1759
|
+
return new KeyJsPart$Number(moonbitlang$core$int64$$Int64$to_double(moonbitlang$core$bigint$$BigInt$to_int64(_n)));
|
|
1760
|
+
}
|
|
1761
|
+
case 3: {
|
|
1762
|
+
const _Float = part;
|
|
1763
|
+
const _f = _Float._0;
|
|
1764
|
+
return new KeyJsPart$Number(_f);
|
|
1765
|
+
}
|
|
1766
|
+
case 4: {
|
|
1767
|
+
return KeyJsPart$False;
|
|
1768
|
+
}
|
|
1769
|
+
default: {
|
|
1770
|
+
return KeyJsPart$True;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
function zxch3n$flock$memcomparable$$js_part_to_key_part(part) {
|
|
1775
|
+
switch (part.$tag) {
|
|
1776
|
+
case 2: {
|
|
1777
|
+
const _Bytes = part;
|
|
1778
|
+
const _bytes = _Bytes._0;
|
|
1779
|
+
return new KeyPart$Bytes(_bytes);
|
|
1780
|
+
}
|
|
1781
|
+
case 1: {
|
|
1782
|
+
const _String = part;
|
|
1783
|
+
const _s = _String._0;
|
|
1784
|
+
return new KeyPart$String(zxch3n$flock$types$$Utf8Str$from_string(_s));
|
|
1785
|
+
}
|
|
1786
|
+
case 0: {
|
|
1787
|
+
const _Number = part;
|
|
1788
|
+
const _n = _Number._0;
|
|
1789
|
+
return moonbitlang$core$int64$$Int64$to_double(moonbitlang$core$double$$Double$to_int64(_n)) === _n ? new KeyPart$Int(moonbitlang$core$bigint$$BigInt$from_int64(moonbitlang$core$double$$Double$to_int64(_n))) : new KeyPart$Float(_n);
|
|
1790
|
+
}
|
|
1791
|
+
case 3: {
|
|
1792
|
+
return KeyPart$True;
|
|
1793
|
+
}
|
|
1794
|
+
default: {
|
|
1795
|
+
return KeyPart$False;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
function zxch3n$flock$memcomparable$$encode_key(parts) {
|
|
1800
|
+
const key = zxch3n$flock$memcomparable$$Key$new();
|
|
1801
|
+
const _len = parts.length;
|
|
1802
|
+
let _tmp = 0;
|
|
1803
|
+
while (true) {
|
|
1804
|
+
const _i = _tmp;
|
|
1805
|
+
if (_i < _len) {
|
|
1806
|
+
const part = parts[_i];
|
|
1807
|
+
moonbitlang$core$array$$Array$push$15$(key.parts, zxch3n$flock$memcomparable$$js_part_to_key_part(part));
|
|
1808
|
+
_tmp = _i + 1 | 0;
|
|
1809
|
+
continue;
|
|
1810
|
+
} else {
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
return zxch3n$flock$memcomparable$$Key$encode(key);
|
|
1815
|
+
}
|
|
1816
|
+
function zxch3n$flock$memcomparable$$decode_key(bytes) {
|
|
1817
|
+
let key;
|
|
1818
|
+
let _try_err;
|
|
1819
|
+
_L: {
|
|
1820
|
+
_L$2: {
|
|
1821
|
+
const _bind = zxch3n$flock$memcomparable$$Key$decode(moonbitlang$core$bytes$$Bytes$sub$46$inner(bytes, 0, bytes.length));
|
|
1822
|
+
if (_bind.$tag === 1) {
|
|
1823
|
+
const _ok = _bind;
|
|
1824
|
+
key = _ok._0;
|
|
1825
|
+
} else {
|
|
1826
|
+
const _err = _bind;
|
|
1827
|
+
const _tmp = _err._0;
|
|
1828
|
+
_try_err = _tmp;
|
|
1829
|
+
break _L$2;
|
|
1830
|
+
}
|
|
1831
|
+
break _L;
|
|
1832
|
+
}
|
|
1833
|
+
key = moonbitlang$core$abort$$abort$0$("Failed to decode key");
|
|
1834
|
+
}
|
|
1835
|
+
const parts = moonbitlang$core$array$$Array$new$46$inner$14$(0);
|
|
1836
|
+
const _arr = key.parts;
|
|
1837
|
+
const _len = _arr.length;
|
|
1838
|
+
let _tmp = 0;
|
|
1839
|
+
while (true) {
|
|
1840
|
+
const _i = _tmp;
|
|
1841
|
+
if (_i < _len) {
|
|
1842
|
+
const part = _arr[_i];
|
|
1843
|
+
moonbitlang$core$array$$Array$push$14$(parts, zxch3n$flock$memcomparable$$key_part_to_js_part(part));
|
|
1844
|
+
_tmp = _i + 1 | 0;
|
|
1845
|
+
continue;
|
|
1846
|
+
} else {
|
|
1847
|
+
break;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return parts;
|
|
1851
|
+
}
|
|
1852
|
+
export { zxch3n$flock$memcomparable$$encode_key as encode_key, zxch3n$flock$memcomparable$$decode_key as decode_key }
|