functionalscript 0.8.0 → 0.8.2

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.
Files changed (114) hide show
  1. package/bnf/data/module.f.d.ts +6 -0
  2. package/bnf/data/module.f.js +57 -4
  3. package/bnf/data/test.f.d.ts +1 -0
  4. package/bnf/data/test.f.js +67 -1
  5. package/ci/module.f.d.ts +3 -0
  6. package/ci/module.f.js +169 -0
  7. package/ci/module.js +3 -0
  8. package/crypto/hmac/module.f.d.ts +5 -4
  9. package/crypto/hmac/module.f.js +9 -18
  10. package/crypto/hmac/test.f.d.ts +1 -0
  11. package/crypto/hmac/test.f.js +16 -8
  12. package/crypto/secp/module.f.d.ts +14 -11
  13. package/crypto/secp/module.f.js +33 -13
  14. package/crypto/secp/test.f.js +12 -13
  15. package/crypto/sha2/module.f.d.ts +11 -5
  16. package/crypto/sha2/module.f.js +4 -3
  17. package/crypto/sha2/test.f.d.ts +4 -1
  18. package/crypto/sha2/test.f.js +41 -31
  19. package/crypto/sign/module.f.d.ts +17 -4
  20. package/crypto/sign/module.f.js +141 -46
  21. package/crypto/sign/test.f.d.ts +11 -1
  22. package/crypto/sign/test.f.js +631 -1
  23. package/dev/tf/all.test.js +9 -1
  24. package/djs/ast/module.f.d.ts +3 -3
  25. package/djs/ast/test.f.js +7 -8
  26. package/djs/parser/module.f.d.ts +3 -3
  27. package/djs/parser/module.f.js +4 -4
  28. package/djs/parser/test.f.js +76 -77
  29. package/djs/serializer/module.f.d.ts +8 -8
  30. package/djs/serializer/module.f.js +4 -7
  31. package/djs/serializer/test.f.js +8 -9
  32. package/djs/tokenizer/module.f.d.ts +2 -2
  33. package/djs/tokenizer/module.f.js +3 -5
  34. package/djs/tokenizer/test.f.js +8 -10
  35. package/djs/transpiler/module.f.d.ts +3 -3
  36. package/djs/transpiler/module.f.js +2 -0
  37. package/fsc/bnf.f.d.ts +1 -1
  38. package/fsc/bnf.f.js +39 -51
  39. package/fsc/json.f.d.ts +1 -1
  40. package/fsc/json.f.js +56 -81
  41. package/fsc/test.f.js +4 -6
  42. package/fsm/module.f.js +3 -3
  43. package/fsm/test.f.js +21 -25
  44. package/html/module.f.js +17 -4
  45. package/html/test.f.d.ts +7 -0
  46. package/html/test.f.js +37 -0
  47. package/issues/031-json.f.d.ts +1 -0
  48. package/js/tokenizer/module.f.d.ts +4 -4
  49. package/js/tokenizer/module.f.js +12 -17
  50. package/js/tokenizer/test.f.js +9 -11
  51. package/json/module.f.d.ts +6 -6
  52. package/json/module.f.js +5 -10
  53. package/json/parser/module.f.d.ts +4 -4
  54. package/json/parser/module.f.js +7 -4
  55. package/json/parser/test.f.js +47 -49
  56. package/json/serializer/module.f.d.ts +6 -6
  57. package/json/serializer/module.f.js +3 -2
  58. package/json/serializer/test.f.js +13 -13
  59. package/json/test.f.js +13 -15
  60. package/json/tokenizer/module.f.d.ts +4 -4
  61. package/json/tokenizer/module.f.js +6 -7
  62. package/json/tokenizer/test.f.js +7 -9
  63. package/nanvm-lib/tests/vm/test.f.js +1 -1
  64. package/package.json +5 -5
  65. package/path/module.f.d.ts +3 -2
  66. package/text/ascii/test.f.js +2 -2
  67. package/text/module.f.d.ts +3 -2
  68. package/text/module.f.js +2 -2
  69. package/text/test.f.js +3 -3
  70. package/text/utf16/test.f.js +2 -2
  71. package/text/utf8/test.f.js +2 -2
  72. package/types/array/test.f.js +2 -2
  73. package/types/bigint/module.f.d.ts +6 -3
  74. package/types/bigint/module.f.js +12 -11
  75. package/types/bigint/test.f.d.ts +2 -0
  76. package/types/bigint/test.f.js +21 -2
  77. package/types/bit_vec/module.f.d.ts +66 -34
  78. package/types/bit_vec/module.f.js +97 -32
  79. package/types/bit_vec/test.f.d.ts +7 -0
  80. package/types/bit_vec/test.f.js +283 -62
  81. package/types/btree/find/test.f.js +9 -8
  82. package/types/btree/remove/test.f.js +4 -4
  83. package/types/btree/set/test.f.js +4 -4
  84. package/types/btree/test.f.js +7 -7
  85. package/types/byte_set/test.f.js +2 -2
  86. package/types/function/compare/module.f.d.ts +15 -1
  87. package/types/function/compare/module.f.js +1 -1
  88. package/types/function/compare/test.f.js +37 -4
  89. package/types/list/test.f.js +93 -93
  90. package/types/monoid/module.f.d.ts +4 -4
  91. package/types/monoid/module.f.js +3 -3
  92. package/types/monoid/test.f.js +3 -3
  93. package/types/nominal/module.f.d.ts +5 -0
  94. package/types/nominal/module.f.js +4 -0
  95. package/types/nominal/test.f.d.ts +5 -0
  96. package/types/nominal/test.f.js +53 -0
  97. package/types/number/module.f.js +2 -2
  98. package/{crypto → types}/prime_field/module.f.d.ts +2 -2
  99. package/{crypto → types}/prime_field/module.f.js +5 -4
  100. package/{crypto → types}/prime_field/test.f.js +13 -13
  101. package/types/range_map/test.f.js +21 -21
  102. package/types/sorted_list/test.f.js +10 -10
  103. package/types/sorted_set/test.f.js +14 -14
  104. package/types/string/module.f.js +2 -2
  105. package/types/string_set/module.f.js +3 -3
  106. package/bnf/func/module.f.d.ts +0 -148
  107. package/bnf/func/module.f.js +0 -132
  108. package/bnf/func/test.f.d.ts +0 -12
  109. package/bnf/func/test.f.js +0 -171
  110. package/bnf/func/testlib.f.d.ts +0 -25
  111. package/bnf/func/testlib.f.js +0 -150
  112. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  113. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
  114. /package/{crypto → types}/prime_field/test.f.d.ts +0 -0
@@ -1,7 +1,27 @@
1
- import { empty, vec, length, uint, lsb, msb } from "./module.f.js";
1
+ import { abs, mask } from "../bigint/module.f.js";
2
+ import { asBase, asNominal } from "../nominal/module.f.js";
3
+ import { length, empty, uint, vec, lsb, msb, repeat, vec8 } from "./module.f.js";
4
+ const unsafeVec = (a) => asNominal(a);
5
+ // 0x8 = 0b1000 = 0 + 8
6
+ // 0x9 = 0b1001 = 1 + 8
7
+ // 0xA = 0b1010 = 2 + 8
8
+ // 0xB = 0b1011 = 3 + 8
9
+ // 0xC = 0b1100 = 4 + 8
10
+ // 0xD = 0b1101 = 5 + 8
11
+ // 0xE = 0b1110 = 6 + 8
12
+ // 0xF = 0b1111 = 7 + 8
13
+ const assertEq = (a, b) => {
14
+ if (a !== b) {
15
+ throw [a, b];
16
+ }
17
+ };
18
+ const assertEq2 = ([a0, a1], [b0, b1]) => {
19
+ assertEq(a0, b0);
20
+ assertEq(a1, b1);
21
+ };
2
22
  const frontTest = (e) => (r0) => (r1) => () => {
3
- const vector = vec(8n)(0xf5n); // 0x1F5n
4
- if (vector !== 0x1f5n) {
23
+ const vector = vec(8n)(0xf5n); // 0xF5n
24
+ if (vector !== unsafeVec(0xf5n)) {
5
25
  throw vector;
6
26
  }
7
27
  const result = e.front(4n)(vector);
@@ -14,25 +34,25 @@ const frontTest = (e) => (r0) => (r1) => () => {
14
34
  }
15
35
  };
16
36
  const popFront = (e) => ([r00, r01]) => ([r10, r11]) => () => {
17
- const vector = vec(8n)(0xf5n); // 0x1F5n
37
+ const vector = vec(8n)(0xf5n); // 0xF5n
18
38
  const [result, rest] = e.popFront(4n)(vector);
19
39
  if (result !== r00) {
20
40
  throw result;
21
41
  }
22
- if (rest !== r01) {
42
+ if (rest !== unsafeVec(r01)) {
23
43
  throw rest;
24
44
  }
25
45
  const [result2, rest2] = e.popFront(16n)(vector);
26
46
  if (result2 !== r10) {
27
47
  throw result2;
28
48
  }
29
- if (rest2 !== r11) {
49
+ if (rest2 !== unsafeVec(r11)) {
30
50
  throw rest2;
31
51
  }
32
52
  };
33
53
  const removeFront = (e) => (r0) => (r1) => () => {
34
- const v = vec(16n)(0x3456n); // 0x13456n
35
- if (v !== 0x13456n) {
54
+ const v = vec(16n)(0x3456n); // -0xB456n
55
+ if (v !== unsafeVec(-0xb456n)) {
36
56
  throw v;
37
57
  }
38
58
  const r = e.removeFront(4n)(v);
@@ -46,44 +66,35 @@ const removeFront = (e) => (r0) => (r1) => () => {
46
66
  };
47
67
  const concat = (e) => (r) => () => {
48
68
  const u8 = vec(8n);
49
- const a = u8(0x45n); // 0x145n
50
- if (a !== 0x145n) {
69
+ const a = u8(0x45n); // -0xC5n
70
+ if (a !== unsafeVec(-0xc5n)) {
51
71
  throw a;
52
72
  }
53
- const b = u8(0x89n); // 0x189n
54
- if (b !== 0x189n) {
73
+ const b = u8(0x89n); // 0x89n
74
+ if (b !== unsafeVec(0x89n)) {
55
75
  throw b;
56
76
  }
57
- const ab = e.concat(a)(b); // 0x18945n
77
+ const ab = e.concat(a)(b); // 0x8945n
58
78
  if (ab !== r) {
59
79
  throw ab;
60
80
  }
61
81
  };
62
- const assertEq = (a, b) => {
63
- if (a !== b) {
64
- throw [a, b];
65
- }
66
- };
67
- const assertEq2 = ([a0, a1], [b0, b1]) => {
68
- assertEq(a0, b0);
69
- assertEq(a1, b1);
70
- };
71
82
  export default {
72
83
  examples: {
73
84
  vec: () => {
74
85
  const vec4 = vec(4n);
75
- const v0 = vec4(5n); // 0x15n
76
- if (v0 !== 0x15n) {
86
+ const v0 = vec4(5n); // 0b0101 => -0b1101
87
+ if (v0 !== unsafeVec(-0xdn)) {
77
88
  throw v0;
78
89
  }
79
- const v1 = vec4(0x5fen); // 0x1En
80
- if (v1 !== 0x1en) {
90
+ const v1 = vec4(0x5fen); // 0xEn
91
+ if (v1 !== unsafeVec(0xen)) {
81
92
  throw v1;
82
93
  }
83
94
  },
84
95
  uint: () => {
85
- const vector = vec(8n)(0x5n); // 0x105n
86
- if (vector !== 0x105n) {
96
+ const vector = vec(8n)(0x5n); // -0x85n
97
+ if (vector !== unsafeVec(-0x85n)) {
87
98
  throw vector;
88
99
  }
89
100
  const result = uint(vector); // result is 0x5n
@@ -92,32 +103,32 @@ export default {
92
103
  }
93
104
  },
94
105
  front: () => {
95
- const vector = vec(8n)(0xf5n); // 0x1F5n
106
+ const vector = vec(8n)(0xf5n); // 0xF5n
96
107
  assertEq(lsb.front(4n)(vector), 5n);
97
108
  assertEq(lsb.front(16n)(vector), 0xf5n);
98
109
  assertEq(msb.front(4n)(vector), 0xfn);
99
110
  assertEq(msb.front(16n)(vector), 0xf500n);
100
111
  },
101
112
  removeFront: () => {
102
- const v = vec(16n)(0x3456n); // 0x13456n
103
- assertEq(lsb.removeFront(4n)(v), 0x1345n);
104
- assertEq(lsb.removeFront(24n)(v), 0x1n);
105
- assertEq(msb.removeFront(4n)(v), 0x1456n);
106
- assertEq(msb.removeFront(24n)(v), 0x1n);
113
+ const v = vec(16n)(0x3456n); // -0xB456n
114
+ assertEq(lsb.removeFront(4n)(v), asNominal(-0xb45n));
115
+ assertEq(lsb.removeFront(24n)(v), empty);
116
+ assertEq(msb.removeFront(4n)(v), asNominal(-0xc56n));
117
+ assertEq(msb.removeFront(24n)(v), empty);
107
118
  },
108
119
  popFront: () => {
109
- const vector = vec(8n)(0xf5n); // 0x1F5n
110
- assertEq2(lsb.popFront(4n)(vector), [5n, 0x1fn]);
111
- assertEq2(lsb.popFront(16n)(vector), [0xf5n, 1n]);
112
- assertEq2(msb.popFront(4n)(vector), [0xfn, 0x15n]);
113
- assertEq2(msb.popFront(16n)(vector), [0xf500n, 1n]);
120
+ const vector = vec(8n)(0xf5n); // 0xF5n
121
+ assertEq2(lsb.popFront(4n)(vector), [5n, asNominal(0xfn)]);
122
+ assertEq2(lsb.popFront(16n)(vector), [0xf5n, empty]);
123
+ assertEq2(msb.popFront(4n)(vector), [0xfn, asNominal(-0xdn)]);
124
+ assertEq2(msb.popFront(16n)(vector), [0xf500n, empty]);
114
125
  },
115
126
  concat: () => {
116
127
  const u8 = vec(8n);
117
- const a = u8(0x45n); // 0x145n
118
- const b = u8(0x89n); // 0x189n
119
- assertEq(lsb.concat(a)(b), 0x18945n);
120
- assertEq(msb.concat(a)(b), 0x14589n);
128
+ const a = u8(0x45n); // -0xC5n
129
+ const b = u8(0x89n); // 0x89n
130
+ assertEq(lsb.concat(a)(b), asNominal(0x8945n));
131
+ assertEq(msb.concat(a)(b), asNominal(-0xc589n));
121
132
  }
122
133
  },
123
134
  front: {
@@ -125,19 +136,19 @@ export default {
125
136
  msbf: frontTest(msb)(0xfn)(0xf500n),
126
137
  },
127
138
  popFront: {
128
- lsbm: popFront(lsb)([5n, 0x1fn])([0xf5n, 1n]),
129
- msbm: popFront(msb)([0xfn, 0x15n])([0xf500n, 1n]),
139
+ lsbm: popFront(lsb)([5n, 0xfn])([0xf5n, 0n]),
140
+ msbm: popFront(msb)([0xfn, -0xdn])([0xf500n, 0n]),
130
141
  },
131
142
  removeFront: {
132
- lsbm: removeFront(lsb)(0x1345n)(0x1n),
133
- msbm: removeFront(msb)(0x1456n)(0x1n),
143
+ lsbm: removeFront(lsb)(asNominal(-0xb45n))(empty),
144
+ msbm: removeFront(msb)(asNominal(-0xc56n))(empty),
134
145
  },
135
146
  concat: {
136
- lsbm: concat(lsb)(0x18945n),
137
- msbm: concat(msb)(0x14589n),
147
+ lsbm: concat(lsb)(asNominal(0x8945n)),
148
+ msbm: concat(msb)(asNominal(-0xc589n)),
138
149
  },
139
150
  uintLsb: () => {
140
- const vector = 117n;
151
+ const vector = asNominal(53n);
141
152
  const extract3Bits = lsb.front(3n);
142
153
  const result = extract3Bits(vector); // result is 0b101n (5n)
143
154
  if (result !== 5n) {
@@ -145,7 +156,7 @@ export default {
145
156
  }
146
157
  },
147
158
  uintSmall: () => {
148
- const vector = 3n;
159
+ const vector = asNominal(1n);
149
160
  const extract3Bits = lsb.front(3n)(vector);
150
161
  if (extract3Bits !== 1n) {
151
162
  throw extract3Bits;
@@ -153,20 +164,20 @@ export default {
153
164
  },
154
165
  vecExample: () => {
155
166
  const createVector = vec(4n);
156
- const vector = createVector(5n); // vector is 0b10101n
157
- if (vector !== 21n) {
167
+ const vector = createVector(5n); // vector is -0b1101n
168
+ if (vector !== unsafeVec(-13n)) {
158
169
  throw vector;
159
170
  }
160
171
  },
161
172
  length: () => {
162
- const i = length(empty);
163
- if (i !== 0n) {
164
- throw i;
173
+ const len = length(empty);
174
+ if (len !== 0n) {
175
+ throw len;
165
176
  }
166
177
  },
167
178
  bitset: () => {
168
179
  const v = vec(8n)(0x5fen);
169
- if (v !== 0x1fen) {
180
+ if (v !== unsafeVec(0xfen)) {
170
181
  throw v;
171
182
  }
172
183
  if (length(v) !== 8n) {
@@ -182,7 +193,7 @@ export default {
182
193
  const a = vec8(0x345n);
183
194
  const b = vec8(0x789n);
184
195
  const ab = lsb.concat(a)(b);
185
- if (ab !== 0x18945n) {
196
+ if (ab !== unsafeVec(0x8945n)) {
186
197
  throw ab;
187
198
  }
188
199
  const s = length(ab);
@@ -192,12 +203,222 @@ export default {
192
203
  },
193
204
  removeBack: () => {
194
205
  const v = vec(17n)(0x12345n);
195
- if (v !== 0x32345n) {
196
- throw v.toString(16);
206
+ if (v !== unsafeVec(0x12345n)) {
207
+ throw asBase(v).toString(16);
197
208
  }
198
209
  const r = lsb.removeFront(9n)(v);
199
- if (r !== 0x191n) {
200
- throw r.toString(16);
210
+ if (r !== unsafeVec(0x91n)) {
211
+ throw asBase(r).toString(16);
212
+ }
213
+ },
214
+ uint: [
215
+ // 0
216
+ () => {
217
+ const x = uint(asNominal(0n));
218
+ if (x !== 0n) {
219
+ throw x;
220
+ }
221
+ },
222
+ // 1
223
+ () => {
224
+ const v = asNominal(1n);
225
+ const x = uint(v);
226
+ if (x !== 1n) {
227
+ throw x;
228
+ }
229
+ const len = length(v);
230
+ if (len !== 1n) {
231
+ throw len;
232
+ }
233
+ },
234
+ // 2
235
+ () => {
236
+ const v = asNominal(2n);
237
+ const x = uint(v);
238
+ if (x !== 2n) {
239
+ throw x;
240
+ }
241
+ const len = length(v);
242
+ if (len !== 2n) {
243
+ throw len;
244
+ }
245
+ },
246
+ // 3
247
+ () => {
248
+ const v = asNominal(3n);
249
+ const x = uint(v);
250
+ if (x !== 3n) {
251
+ throw x;
252
+ }
253
+ const len = length(v);
254
+ if (len !== 2n) {
255
+ throw len;
256
+ }
257
+ },
258
+ // 4
259
+ () => {
260
+ const v = asNominal(-1n);
261
+ const x = uint(v);
262
+ if (x !== 0n) {
263
+ throw x;
264
+ }
265
+ const len = length(v);
266
+ if (len !== 1n) {
267
+ throw len;
268
+ }
269
+ },
270
+ () => {
271
+ const v = asNominal(-2n);
272
+ const x = uint(v);
273
+ if (x !== 0n) {
274
+ throw x;
275
+ }
276
+ const len = length(v);
277
+ if (len !== 2n) {
278
+ throw len;
279
+ }
280
+ },
281
+ () => {
282
+ const v = asNominal(-3n);
283
+ const x = uint(v);
284
+ if (x !== 1n) {
285
+ throw x;
286
+ }
287
+ const len = length(v);
288
+ if (len !== 2n) {
289
+ throw len;
290
+ }
291
+ }
292
+ ],
293
+ vec: [
294
+ // 0
295
+ () => {
296
+ const v = asBase(vec(0n)(0n));
297
+ if (v !== 0n) {
298
+ throw v;
299
+ }
300
+ },
301
+ () => {
302
+ const v = asBase(vec(0n)(1n));
303
+ if (v !== 0n) {
304
+ throw v;
305
+ }
306
+ },
307
+ () => {
308
+ const v = asBase(vec(0n)(-1n));
309
+ if (v !== 0n) {
310
+ throw v;
311
+ }
312
+ },
313
+ // 1
314
+ () => {
315
+ const v = asBase(vec(1n)(0n));
316
+ if (v !== -1n) {
317
+ throw v;
318
+ }
319
+ },
320
+ () => {
321
+ const v = asBase(vec(1n)(1n));
322
+ if (v !== 1n) {
323
+ throw v;
324
+ }
325
+ },
326
+ () => {
327
+ const v = asBase(vec(1n)(-1n));
328
+ if (v !== 1n) {
329
+ throw v;
330
+ }
331
+ },
332
+ () => {
333
+ const v = asBase(vec(1n)(2n));
334
+ if (v !== -1n) {
335
+ throw v;
336
+ }
337
+ },
338
+ () => {
339
+ const v = asBase(vec(1n)(3n));
340
+ if (v !== 1n) {
341
+ throw v;
342
+ }
343
+ }
344
+ ],
345
+ both: () => {
346
+ const c = (len) => (ui) => (raw) => {
347
+ const v = vec(len)(ui);
348
+ const x = asBase(v);
349
+ if (x !== raw) {
350
+ throw x;
351
+ }
352
+ const len2 = length(v);
353
+ if (len2 !== len) {
354
+ throw len2;
355
+ }
356
+ const u = uint(v);
357
+ const mui = mask(len) & abs(ui);
358
+ if (u !== mui) {
359
+ throw u;
360
+ }
361
+ };
362
+ // 0n
363
+ for (const i of [0n, 1n, -1n, 2n, -2n, 3n, -3n]) {
364
+ c(0n)(i)(0n);
365
+ }
366
+ return [
367
+ // 1n
368
+ () => c(1n)(0n)(-1n),
369
+ () => c(1n)(1n)(1n),
370
+ () => c(1n)(-11n)(1n), //< overflow
371
+ // 2n
372
+ () => c(2n)(0n)(-2n),
373
+ () => c(2n)(1n)(-3n),
374
+ () => c(2n)(2n)(2n),
375
+ () => c(2n)(3n)(3n),
376
+ () => c(2n)(-7n)(3n), //< overflow
377
+ ];
378
+ },
379
+ concat2: () => {
380
+ const c = (a) => (b) => (abx) => {
381
+ const ab = msb.concat(a)(b);
382
+ const abLen = length(ab);
383
+ const abxLen = length(abx);
384
+ if (abLen !== abxLen) {
385
+ throw abLen;
386
+ }
387
+ const abU = uint(ab);
388
+ const abxU = uint(abx);
389
+ if (abU !== abxU) {
390
+ throw abU;
391
+ }
392
+ };
393
+ c(vec(4n)(0xfn))(vec(8n)(0xa7n))(vec(12n)(0xfa7n));
394
+ c(vec(4n)(0xfn))(vec(8n)(0x57n))(vec(12n)(0xf57n));
395
+ c(vec(4n)(0x5n))(vec(8n)(0xa7n))(vec(12n)(0x5a7n));
396
+ c(vec(4n)(0x5n))(vec(8n)(0x79n))(vec(12n)(0x579n));
397
+ },
398
+ lsbXor: () => {
399
+ const c = (a) => (b) => (e) => {
400
+ const r = lsb.xor(a)(b);
401
+ if (r !== e) {
402
+ throw r;
403
+ }
404
+ };
405
+ c(vec(4n)(0x7n))(vec(8n)(0x12n))(vec(8n)(0x7n ^ 0x12n));
406
+ },
407
+ msbXor: () => {
408
+ const c = (a) => (b) => (e) => {
409
+ const r = msb.xor(a)(b);
410
+ if (r !== e) {
411
+ throw r;
412
+ }
413
+ };
414
+ c(vec(4n)(0x7n))(vec(8n)(0x12n))(vec(8n)(0x70n ^ 0x12n));
415
+ },
416
+ repeat: () => {
417
+ if (repeat(4n)(vec8(0xa5n)) !== vec(32n)(0xa5a5a5a5n)) {
418
+ throw 'repeat failed';
419
+ }
420
+ if (repeat(7n)(vec(5n)(0x13n)) !== vec(35n)(21059194483n)) {
421
+ throw 'repeat failed';
201
422
  }
202
423
  }
203
424
  };
@@ -1,13 +1,14 @@
1
- import * as _ from "./module.f.js";
2
- import * as list from "../../list/module.f.js";
3
- import * as json from "../../../json/module.f.js";
1
+ import { find as btreeFind } from "./module.f.js";
2
+ import { map, toArray } from "../../list/module.f.js";
3
+ import { stringify } from "../../../json/module.f.js";
4
4
  import { sort } from "../../object/module.f.js";
5
+ import {} from "../types/module.f.js";
5
6
  import { cmp } from "../../string/module.f.js";
6
- import * as s from "../set/module.f.js";
7
- const jsonStr = json.stringify(sort);
8
- const set = node => value => s.set(cmp(value))(() => value)(node);
9
- const str = r => jsonStr(list.toArray(list.map((x) => x[0])(r)));
10
- const find = i => m => str(_.find(cmp(i))(m));
7
+ import { set as setSet } from "../set/module.f.js";
8
+ const jsonStr = stringify(sort);
9
+ const set = node => value => setSet(cmp(value))(() => value)(node);
10
+ const str = r => jsonStr(toArray(map((x) => x[0])(r)));
11
+ const find = i => m => str(btreeFind(cmp(i))(m));
11
12
  const test = () => {
12
13
  let _map = ['1'];
13
14
  for (let i = 2; i <= 10; i++) {
@@ -1,11 +1,11 @@
1
1
  import { nodeRemove } from "./module.f.js";
2
- import * as s from "../set/module.f.js";
2
+ import { set as setSet } from "../set/module.f.js";
3
3
  import { cmp } from "../../string/module.f.js";
4
- import * as json from "../../../json/module.f.js";
4
+ import { stringify } from "../../../json/module.f.js";
5
5
  import { sort } from "../../object/module.f.js";
6
- const set = (node) => (value) => s.set(cmp(value))(() => value)(node);
6
+ const set = (node) => (value) => setSet(cmp(value))(() => value)(node);
7
7
  const remove = (node) => (value) => nodeRemove(cmp(value))(node);
8
- const jsonStr = json.stringify(sort);
8
+ const jsonStr = stringify(sort);
9
9
  const test = () => {
10
10
  let _map = ['1'];
11
11
  for (let i = 2; i <= 38; i++)
@@ -1,9 +1,9 @@
1
- import * as _ from "./module.f.js";
1
+ import { set as setSet } from "./module.f.js";
2
2
  import { cmp } from "../../string/module.f.js";
3
- import * as json from "../../../json/module.f.js";
3
+ import { stringify } from "../../../json/module.f.js";
4
4
  import { sort } from "../../object/module.f.js";
5
- const set = (node) => (value) => _.set(cmp(value))(() => value)(node);
6
- const jsonStr = json.stringify(sort);
5
+ const set = (node) => (value) => setSet(cmp(value))(() => value)(node);
6
+ const jsonStr = stringify(sort);
7
7
  const test = [
8
8
  () => {
9
9
  let _map = ['1'];
@@ -1,13 +1,13 @@
1
1
  import { values } from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
2
+ import { stringify as jsonStringify } from "../../json/module.f.js";
3
3
  import { sort } from "../object/module.f.js";
4
4
  import { cmp } from "../string/module.f.js";
5
5
  import { next, toArray } from "../list/module.f.js";
6
- import * as s from "./set/module.f.js";
7
- import * as f from "./find/module.f.js";
8
- const jsonStr = json.stringify(sort);
6
+ import { set as setSet } from "./set/module.f.js";
7
+ import { value, find as findFind } from "./find/module.f.js";
8
+ const jsonStr = jsonStringify(sort);
9
9
  const stringify = sequence => jsonStr(toArray(sequence));
10
- const set = node => value => s.set(cmp(value))(() => value)(node);
10
+ const set = node => value => setSet(cmp(value))(() => value)(node);
11
11
  const valueTest1 = () => {
12
12
  let _map = ['a'];
13
13
  _map = set(_map)('b');
@@ -33,7 +33,7 @@ const findTrue = () => {
33
33
  let _map = ['a'];
34
34
  _map = set(_map)('b');
35
35
  _map = set(_map)('c');
36
- const result = f.value(f.find(cmp('b'))(_map).first);
36
+ const result = value(findFind(cmp('b'))(_map).first);
37
37
  if (result !== 'b') {
38
38
  throw result;
39
39
  }
@@ -42,7 +42,7 @@ const find = () => {
42
42
  let _map = ['a'];
43
43
  _map = set(_map)('b');
44
44
  _map = set(_map)('c');
45
- const result = f.value(f.find(cmp('e'))(_map).first);
45
+ const result = value(findFind(cmp('e'))(_map).first);
46
46
  if (result !== null) {
47
47
  throw result;
48
48
  }
@@ -1,8 +1,8 @@
1
1
  import { has, empty, set, setRange, unset, universe, complement, toRangeMap } from "./module.f.js";
2
2
  import { every, countdown, map, toArray } from "../list/module.f.js";
3
- import * as json from "../../json/module.f.js";
3
+ import { stringify as jsonStringify } from "../../json/module.f.js";
4
4
  import { sort } from "../object/module.f.js";
5
- const stringify = json.stringify(sort);
5
+ const stringify = jsonStringify(sort);
6
6
  export default {
7
7
  has: [
8
8
  () => {
@@ -3,4 +3,18 @@ export type Sign = -1 | 0 | 1;
3
3
  export type Compare<T> = (_: T) => Sign;
4
4
  export declare const index3: <T>(cmp: Compare<T>) => (value: T) => Index3;
5
5
  export declare const index5: <T>(cmp: Compare<T>) => (v2: Array2<T>) => Index5;
6
- export declare const unsafeCmp: <T>(a: T) => (b: T) => Sign;
6
+ export type Cmp1 = boolean | string | number | bigint;
7
+ export type Cmp2<A, B> = [
8
+ A,
9
+ B
10
+ ] extends [boolean, boolean] ? boolean : [
11
+ A,
12
+ B
13
+ ] extends [string, string] ? string : [
14
+ A,
15
+ B
16
+ ] extends [number, number] ? number : [
17
+ A,
18
+ B
19
+ ] extends [bigint, bigint] ? bigint : never;
20
+ export declare const cmp: <A extends Cmp1>(a: A) => <B extends Cmp2<A, B>>(b: B) => Sign;
@@ -3,4 +3,4 @@ export const index5 = cmp => ([v0, v1]) => {
3
3
  const _0 = cmp(v0);
4
4
  return (_0 <= 0 ? _0 + 1 : cmp(v1) + 3);
5
5
  };
6
- export const unsafeCmp = a => b => a < b ? -1 : a > b ? 1 : 0;
6
+ export const cmp = (a) => (b) => a < b ? -1 : a > b ? 1 : 0;
@@ -1,7 +1,40 @@
1
- import { unsafeCmp } from "./module.f.js";
1
+ import { cmp } from "./module.f.js";
2
2
  export default () => {
3
- const result = unsafeCmp(true)(false);
4
- if (result !== 1) {
5
- throw result;
3
+ {
4
+ const result = cmp(true)(false);
5
+ if (result !== 1) {
6
+ throw result;
7
+ }
8
+ const _ = true < false;
9
+ }
10
+ {
11
+ const result = cmp(1)(2);
12
+ if (result !== -1) {
13
+ throw result;
14
+ }
15
+ const _ = 1 < 2;
16
+ }
17
+ {
18
+ const result = cmp(2n)(-10n);
19
+ if (result !== 1) {
20
+ throw result;
21
+ }
22
+ const _ = 2n < -10n;
23
+ }
24
+ {
25
+ const result = cmp("hello")("hello");
26
+ if (result !== 0) {
27
+ throw result;
28
+ }
29
+ const _ = "hello" < "hello";
30
+ }
31
+ {
32
+ // const result = cmp(true)("hello") // compilation error
33
+ const a = "hello";
34
+ const b = 5;
35
+ // const _ = cmp(a)(b) // compilation error
36
+ const _ = cmp(a)("hello"); // ??? TypeScript changes a type definition of `a`.
37
+ // const f = (a: string|number, b: string|number) => cmp(a)(b) // compilation error
38
+ // const f = (a: number, b: string|number) => cmp(a)(b) // compilation error
6
39
  }
7
40
  };