@fraczak/k 6.2.4 → 6.3.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.
@@ -0,0 +1,480 @@
1
+ {
2
+ "generatedAt": "2026-06-08T02:51:16.016Z",
3
+ "node": "v22.22.2",
4
+ "platform": "linux arm64",
5
+ "cpuCount": 8,
6
+ "samples": 3,
7
+ "timeoutMs": 120000,
8
+ "parallelJobs": 8,
9
+ "results": [
10
+ {
11
+ "status": "ok",
12
+ "mode": "kVM Interpreter (Env-Free)",
13
+ "case": "ieee.add",
14
+ "samples": [
15
+ 447.74282700000003,
16
+ 11.988949000000048,
17
+ 6.373372999999901
18
+ ],
19
+ "avgMs": 155.368383,
20
+ "minMs": 6.373372999999901,
21
+ "maxMs": 447.74282700000003,
22
+ "setupMs": 2611.927592,
23
+ "maxRssMiB": 262.02734375,
24
+ "heapUsedMiB": 155.26434326171875,
25
+ "heapDeltaMiB": 27.24445343017578,
26
+ "resultDigest": "d7b0ed6ef57dd554",
27
+ "resultBytes": 316
28
+ },
29
+ {
30
+ "status": "ok",
31
+ "mode": "Native JS (Envelope-Aware)",
32
+ "case": "ieee.add",
33
+ "samples": [
34
+ 356.52031099999977,
35
+ 87.59474500000033,
36
+ 61.995670999999675
37
+ ],
38
+ "avgMs": 168.70357566666658,
39
+ "minMs": 61.995670999999675,
40
+ "maxMs": 356.52031099999977,
41
+ "setupMs": 2563.048168,
42
+ "maxRssMiB": 252.5703125,
43
+ "heapUsedMiB": 139.03865814208984,
44
+ "heapDeltaMiB": 9.963470458984375,
45
+ "resultDigest": "d7b0ed6ef57dd554",
46
+ "resultBytes": 316
47
+ },
48
+ {
49
+ "status": "ok",
50
+ "mode": "Native JS (Envelope-Free)",
51
+ "case": "ieee.add",
52
+ "samples": [
53
+ 22.51372100000026,
54
+ 2.6233070000002954,
55
+ 2.53559899999982
56
+ ],
57
+ "avgMs": 9.224209000000124,
58
+ "minMs": 2.53559899999982,
59
+ "maxMs": 22.51372100000026,
60
+ "setupMs": 2733.047042,
61
+ "maxRssMiB": 245.69140625,
62
+ "heapUsedMiB": 136.9601593017578,
63
+ "heapDeltaMiB": 8.301094055175781,
64
+ "resultDigest": "d7b0ed6ef57dd554",
65
+ "resultBytes": 316
66
+ },
67
+ {
68
+ "status": "ok",
69
+ "mode": "kVM Interpreter (Env-Free)",
70
+ "case": "ieee.div",
71
+ "samples": [
72
+ 1494.0216979999996,
73
+ 247.03601399999934,
74
+ 187.72085900000002
75
+ ],
76
+ "avgMs": 642.926190333333,
77
+ "minMs": 187.72085900000002,
78
+ "maxMs": 1494.0216979999996,
79
+ "setupMs": 2473.0460319999997,
80
+ "maxRssMiB": 302.87890625,
81
+ "heapUsedMiB": 187.9837646484375,
82
+ "heapDeltaMiB": 59.79613494873047,
83
+ "resultDigest": "238b6430f024764d",
84
+ "resultBytes": 319
85
+ },
86
+ {
87
+ "status": "ok",
88
+ "mode": "Native JS (Envelope-Aware)",
89
+ "case": "ieee.div",
90
+ "samples": [
91
+ 2267.003936,
92
+ 2140.1767010000003,
93
+ 1925.5459679999994
94
+ ],
95
+ "avgMs": 2110.9088683333334,
96
+ "minMs": 1925.5459679999994,
97
+ "maxMs": 2267.003936,
98
+ "setupMs": 2448.4977569999996,
99
+ "maxRssMiB": 274.9453125,
100
+ "heapUsedMiB": 155.26318359375,
101
+ "heapDeltaMiB": 30.547073364257812,
102
+ "resultDigest": "238b6430f024764d",
103
+ "resultBytes": 319
104
+ },
105
+ {
106
+ "status": "ok",
107
+ "mode": "Native JS (Envelope-Free)",
108
+ "case": "ieee.div",
109
+ "samples": [
110
+ 76.03142400000024,
111
+ 58.418858,
112
+ 57.84806299999991
113
+ ],
114
+ "avgMs": 64.09944833333338,
115
+ "minMs": 57.84806299999991,
116
+ "maxMs": 76.03142400000024,
117
+ "setupMs": 2452.4751149999997,
118
+ "maxRssMiB": 218.34765625,
119
+ "heapUsedMiB": 103.76214599609375,
120
+ "heapDeltaMiB": 1.9882583618164062,
121
+ "resultDigest": "238b6430f024764d",
122
+ "resultBytes": 319
123
+ },
124
+ {
125
+ "status": "ok",
126
+ "mode": "kVM Interpreter (Env-Free)",
127
+ "case": "ieee.mul",
128
+ "samples": [
129
+ 1233.2960589999998,
130
+ 162.31878700000016,
131
+ 147.70536400000037
132
+ ],
133
+ "avgMs": 514.4400700000001,
134
+ "minMs": 147.70536400000037,
135
+ "maxMs": 1233.2960589999998,
136
+ "setupMs": 2464.557772,
137
+ "maxRssMiB": 296.69921875,
138
+ "heapUsedMiB": 182.89031219482422,
139
+ "heapDeltaMiB": 40.20558166503906,
140
+ "resultDigest": "4c83c565baa5bb08",
141
+ "resultBytes": 316
142
+ },
143
+ {
144
+ "status": "ok",
145
+ "mode": "Native JS (Envelope-Aware)",
146
+ "case": "ieee.mul",
147
+ "samples": [
148
+ 2359.545586,
149
+ 1981.5436869999994,
150
+ 2235.1848250000003
151
+ ],
152
+ "avgMs": 2192.091366,
153
+ "minMs": 1981.5436869999994,
154
+ "maxMs": 2359.545586,
155
+ "setupMs": 2494.265413,
156
+ "maxRssMiB": 263.08203125,
157
+ "heapUsedMiB": 147.53301239013672,
158
+ "heapDeltaMiB": 16.31543731689453,
159
+ "resultDigest": "4c83c565baa5bb08",
160
+ "resultBytes": 316
161
+ },
162
+ {
163
+ "status": "ok",
164
+ "mode": "Native JS (Envelope-Free)",
165
+ "case": "ieee.mul",
166
+ "samples": [
167
+ 102.26896099999976,
168
+ 54.66246000000001,
169
+ 52.20027800000025
170
+ ],
171
+ "avgMs": 69.71056633333335,
172
+ "minMs": 52.20027800000025,
173
+ "maxMs": 102.26896099999976,
174
+ "setupMs": 2648.174606,
175
+ "maxRssMiB": 248.7890625,
176
+ "heapUsedMiB": 145.31277465820312,
177
+ "heapDeltaMiB": 19.026832580566406,
178
+ "resultDigest": "4c83c565baa5bb08",
179
+ "resultBytes": 316
180
+ },
181
+ {
182
+ "status": "ok",
183
+ "mode": "kVM Interpreter (Env-Free)",
184
+ "case": "ieee.sub",
185
+ "samples": [
186
+ 517.2682530000002,
187
+ 46.239408999999796,
188
+ 23.57639399999971
189
+ ],
190
+ "avgMs": 195.69468533333324,
191
+ "minMs": 23.57639399999971,
192
+ "maxMs": 517.2682530000002,
193
+ "setupMs": 2581.687532,
194
+ "maxRssMiB": 268.609375,
195
+ "heapUsedMiB": 151.7156524658203,
196
+ "heapDeltaMiB": 19.859275817871094,
197
+ "resultDigest": "5c7179ae0117965a",
198
+ "resultBytes": 316
199
+ },
200
+ {
201
+ "status": "ok",
202
+ "mode": "Native JS (Envelope-Aware)",
203
+ "case": "ieee.sub",
204
+ "samples": [
205
+ 512.3046810000001,
206
+ 273.7816780000003,
207
+ 327.3219220000001
208
+ ],
209
+ "avgMs": 371.1360936666668,
210
+ "minMs": 273.7816780000003,
211
+ "maxMs": 512.3046810000001,
212
+ "setupMs": 2493.3290309999998,
213
+ "maxRssMiB": 253.37109375,
214
+ "heapUsedMiB": 134.08831787109375,
215
+ "heapDeltaMiB": -4.949058532714844,
216
+ "resultDigest": "5c7179ae0117965a",
217
+ "resultBytes": 316
218
+ },
219
+ {
220
+ "status": "ok",
221
+ "mode": "Native JS (Envelope-Free)",
222
+ "case": "ieee.sub",
223
+ "samples": [
224
+ 32.63270000000011,
225
+ 8.940972000000329,
226
+ 11.802614000000176
227
+ ],
228
+ "avgMs": 17.79209533333354,
229
+ "minMs": 8.940972000000329,
230
+ "maxMs": 32.63270000000011,
231
+ "setupMs": 2452.8188670000004,
232
+ "maxRssMiB": 212.8203125,
233
+ "heapUsedMiB": 100.97000122070312,
234
+ "heapDeltaMiB": -2.9156417846679688,
235
+ "resultDigest": "5c7179ae0117965a",
236
+ "resultBytes": 316
237
+ },
238
+ {
239
+ "status": "ok",
240
+ "mode": "kVM Interpreter (Env-Free)",
241
+ "case": "int.factorial.101",
242
+ "samples": [
243
+ 1008.146804,
244
+ 1010.4200680000001,
245
+ 927.0946409999997
246
+ ],
247
+ "avgMs": 981.887171,
248
+ "minMs": 927.0946409999997,
249
+ "maxMs": 1010.4200680000001,
250
+ "setupMs": 154.14531999999997,
251
+ "maxRssMiB": 144.66796875,
252
+ "heapUsedMiB": 50.41716766357422,
253
+ "heapDeltaMiB": 23.594528198242188,
254
+ "resultDigest": "c48039eab26792fd",
255
+ "resultBytes": 3201
256
+ },
257
+ {
258
+ "status": "ok",
259
+ "mode": "Native JS (Envelope-Aware)",
260
+ "case": "int.factorial.101",
261
+ "samples": [
262
+ 4155.8708879999995,
263
+ 3962.579386999999,
264
+ 3794.4382920000007
265
+ ],
266
+ "avgMs": 3970.962855666666,
267
+ "minMs": 3794.4382920000007,
268
+ "maxMs": 4155.8708879999995,
269
+ "setupMs": 206.03668,
270
+ "maxRssMiB": 186.40234375,
271
+ "heapUsedMiB": 88.2265396118164,
272
+ "heapDeltaMiB": 63.99357604980469,
273
+ "resultDigest": "c48039eab26792fd",
274
+ "resultBytes": 3201
275
+ },
276
+ {
277
+ "status": "ok",
278
+ "mode": "Native JS (Envelope-Free)",
279
+ "case": "int.factorial.101",
280
+ "samples": [
281
+ 220.68472700000007,
282
+ 208.8797800000001,
283
+ 210.9588349999999
284
+ ],
285
+ "avgMs": 213.5077806666667,
286
+ "minMs": 208.8797800000001,
287
+ "maxMs": 220.68472700000007,
288
+ "setupMs": 214.25627199999997,
289
+ "maxRssMiB": 134.63671875,
290
+ "heapUsedMiB": 30.165908813476562,
291
+ "heapDeltaMiB": 4.183555603027344,
292
+ "resultDigest": "c48039eab26792fd",
293
+ "resultBytes": 3201
294
+ },
295
+ {
296
+ "status": "failed",
297
+ "mode": "kVM Interpreter (Env-Free)",
298
+ "case": "int.factorial.1174",
299
+ "code": 1,
300
+ "signal": null,
301
+ "stderr": "RangeError: Maximum call stack size exceeded\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:279:28)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:405:27)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:429:27)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeKVM (file:///home/wojtek/gits/k/kvm.mjs:451:18)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:371:19)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:429:27)"
302
+ },
303
+ {
304
+ "status": "failed",
305
+ "mode": "Native JS (Envelope-Aware)",
306
+ "case": "int.factorial.1174",
307
+ "code": 1,
308
+ "signal": null,
309
+ "stderr": "RangeError: Maximum call stack size exceeded\n at visit (file:///home/wojtek/gits/k/Value.mjs:68:17)\n at cloneSubpattern (file:///home/wojtek/gits/k/Value.mjs:78:3)\n at edgeSubpattern (file:///home/wojtek/gits/k/Value.mjs:87:10)\n at projectionPattern (file:///home/wojtek/gits/k/run.mjs:126:32)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:205:52)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:151:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:219:27)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:151:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:246:32)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:151:23)"
310
+ },
311
+ {
312
+ "status": "failed",
313
+ "mode": "Native JS (Envelope-Free)",
314
+ "case": "int.factorial.1174",
315
+ "code": 1,
316
+ "signal": null,
317
+ "stderr": "RangeError: Maximum call stack size exceeded\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:414:12)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:345:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:392:27)\n at fn (file:///home/wojtek/gits/k/run.mjs:345:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:363:61)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:345:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:392:27)\n at Array.fn (file:///home/wojtek/gits/k/run.mjs:345:23)\n at Object.fn [as target] (file:///home/wojtek/gits/k/run.mjs:404:34)\n at fn (file:///home/wojtek/gits/k/run.mjs:345:23)"
318
+ },
319
+ {
320
+ "status": "ok",
321
+ "mode": "kVM Interpreter (Env-Free)",
322
+ "case": "int.factorial.242",
323
+ "samples": [
324
+ 9212.264533000001,
325
+ 8737.175806,
326
+ 8607.513240999997
327
+ ],
328
+ "avgMs": 8852.31786,
329
+ "minMs": 8607.513240999997,
330
+ "maxMs": 9212.264533000001,
331
+ "setupMs": 218.00846100000007,
332
+ "maxRssMiB": 201.8203125,
333
+ "heapUsedMiB": 21.159713745117188,
334
+ "heapDeltaMiB": -17.372802734375,
335
+ "resultDigest": "2d5fded69485a5de",
336
+ "resultBytes": 9447
337
+ },
338
+ {
339
+ "status": "ok",
340
+ "mode": "Native JS (Envelope-Aware)",
341
+ "case": "int.factorial.242",
342
+ "samples": [
343
+ 33301.702731000005,
344
+ 28909.626589,
345
+ 28784.374435000005
346
+ ],
347
+ "avgMs": 30331.90125166667,
348
+ "minMs": 28784.374435000005,
349
+ "maxMs": 33301.702731000005,
350
+ "setupMs": 233.95651699999996,
351
+ "maxRssMiB": 191.296875,
352
+ "heapUsedMiB": 22.9791259765625,
353
+ "heapDeltaMiB": -2.4043426513671875,
354
+ "resultDigest": "2d5fded69485a5de",
355
+ "resultBytes": 9447
356
+ },
357
+ {
358
+ "status": "ok",
359
+ "mode": "Native JS (Envelope-Free)",
360
+ "case": "int.factorial.242",
361
+ "samples": [
362
+ 2151.695687,
363
+ 2165.5316169999996,
364
+ 2067.250534999999
365
+ ],
366
+ "avgMs": 2128.1592796666664,
367
+ "minMs": 2067.250534999999,
368
+ "maxMs": 2165.5316169999996,
369
+ "setupMs": 211.027419,
370
+ "maxRssMiB": 174.53515625,
371
+ "heapUsedMiB": 77.53760528564453,
372
+ "heapDeltaMiB": 51.71900177001953,
373
+ "resultDigest": "2d5fded69485a5de",
374
+ "resultBytes": 9447
375
+ },
376
+ {
377
+ "status": "ok",
378
+ "mode": "kVM Interpreter (Env-Free)",
379
+ "case": "int.gcd.90d",
380
+ "samples": [
381
+ 1515.073453,
382
+ 1403.5270610000002,
383
+ 1498.0233900000003
384
+ ],
385
+ "avgMs": 1472.207968,
386
+ "minMs": 1403.5270610000002,
387
+ "maxMs": 1515.073453,
388
+ "setupMs": 255.31398199999995,
389
+ "maxRssMiB": 154.3203125,
390
+ "heapUsedMiB": 58.64311981201172,
391
+ "heapDeltaMiB": 21.39154052734375,
392
+ "resultDigest": "5d1377581b4f4558",
393
+ "resultBytes": 783
394
+ },
395
+ {
396
+ "status": "ok",
397
+ "mode": "Native JS (Envelope-Aware)",
398
+ "case": "int.gcd.90d",
399
+ "samples": [
400
+ 9585.996507999998,
401
+ 8697.202526000001,
402
+ 8497.087249
403
+ ],
404
+ "avgMs": 8926.762094333333,
405
+ "minMs": 8497.087249,
406
+ "maxMs": 9585.996507999998,
407
+ "setupMs": 274.172347,
408
+ "maxRssMiB": 185.015625,
409
+ "heapUsedMiB": 41.226470947265625,
410
+ "heapDeltaMiB": 15.748123168945312,
411
+ "resultDigest": "5d1377581b4f4558",
412
+ "resultBytes": 783
413
+ },
414
+ {
415
+ "status": "ok",
416
+ "mode": "Native JS (Envelope-Free)",
417
+ "case": "int.gcd.90d",
418
+ "samples": [
419
+ 429.591549,
420
+ 426.7347819999999,
421
+ 483.9726750000002
422
+ ],
423
+ "avgMs": 446.7663353333334,
424
+ "minMs": 426.7347819999999,
425
+ "maxMs": 483.9726750000002,
426
+ "setupMs": 244.61237400000005,
427
+ "maxRssMiB": 145.96484375,
428
+ "heapUsedMiB": 52.13642120361328,
429
+ "heapDeltaMiB": 27.70124053955078,
430
+ "resultDigest": "5d1377581b4f4558",
431
+ "resultBytes": 783
432
+ },
433
+ {
434
+ "status": "failed",
435
+ "mode": "kVM Interpreter (Env-Free)",
436
+ "case": "int.times.220d",
437
+ "code": 1,
438
+ "signal": null,
439
+ "stderr": "RangeError: Maximum call stack size exceeded\n at Value.hasOwn (<anonymous>)\n at Function.hasOwn (<anonymous>)\n at isVariant (file:///home/wojtek/gits/k/Value.mjs:44:12)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:334:12)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:405:27)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeInstruction (file:///home/wojtek/gits/k/kvm.mjs:429:27)\n at executeBlock (file:///home/wojtek/gits/k/kvm.mjs:268:17)\n at executeKVM (file:///home/wojtek/gits/k/kvm.mjs:451:18)"
440
+ },
441
+ {
442
+ "status": "ok",
443
+ "mode": "Native JS (Envelope-Aware)",
444
+ "case": "int.times.220d",
445
+ "samples": [
446
+ 18565.357441,
447
+ 16694.949756,
448
+ 15405.098607
449
+ ],
450
+ "avgMs": 16888.468601333334,
451
+ "minMs": 15405.098607,
452
+ "maxMs": 18565.357441,
453
+ "setupMs": 336.384312,
454
+ "maxRssMiB": 186.9453125,
455
+ "heapUsedMiB": 40.17704772949219,
456
+ "heapDeltaMiB": 14.222763061523438,
457
+ "resultDigest": "fe1d1bb07a950218",
458
+ "resultBytes": 8763
459
+ },
460
+ {
461
+ "status": "ok",
462
+ "mode": "Native JS (Envelope-Free)",
463
+ "case": "int.times.220d",
464
+ "samples": [
465
+ 1040.311709,
466
+ 1067.6816689999998,
467
+ 1018.106698
468
+ ],
469
+ "avgMs": 1042.0333586666668,
470
+ "minMs": 1018.106698,
471
+ "maxMs": 1067.6816689999998,
472
+ "setupMs": 293.96959400000003,
473
+ "maxRssMiB": 180.08203125,
474
+ "heapUsedMiB": 68.24949645996094,
475
+ "heapDeltaMiB": 41.00365447998047,
476
+ "resultDigest": "fe1d1bb07a950218",
477
+ "resultBytes": 8763
478
+ }
479
+ ]
480
+ }
@@ -14,7 +14,7 @@
14
14
  import { deriveClosedPattern } from './runtime/codec.mjs';
15
15
  import { encodeToWire, decodeWire } from './runtime/prefix-codec.mjs';
16
16
  import { patternToPropertyList } from './runtime/pattern-json.mjs';
17
- import { Product, Variant } from '../Value.mjs';
17
+ import { Value, isVariant } from '../Value.mjs';
18
18
  import hash from '../hash.mjs';
19
19
  import { argv, exit } from 'node:process';
20
20
 
@@ -84,9 +84,9 @@ function resolveType(typeName) {
84
84
  // Step 3: Create input value: Maybe Bool = something(true)
85
85
  // ============================================================================
86
86
 
87
- const inputValue = new Variant(
87
+ const inputValue = Value.variant(
88
88
  'something',
89
- new Variant('true', new Product({}))
89
+ Value.variant('true', Value.product({}))
90
90
  );
91
91
 
92
92
  console.log('Input value:', inputValue.toString());
@@ -119,14 +119,14 @@ console.log('Program sees value:', programInput.toString());
119
119
 
120
120
  // Example transformation: NOT operation (flip bool inside Maybe)
121
121
  let programOutput;
122
- if (programInput instanceof Variant && programInput.tag === 'something') {
122
+ if (isVariant(programInput) && programInput.tag === 'something') {
123
123
  const innerBool = programInput.value;
124
- if (innerBool instanceof Variant) {
125
- const flipped = new Variant(
124
+ if (isVariant(innerBool)) {
125
+ const flipped = Value.variant(
126
126
  innerBool.tag === 'true' ? 'false' : 'true',
127
127
  innerBool.value
128
128
  );
129
- programOutput = new Variant('something', flipped);
129
+ programOutput = Value.variant('something', flipped);
130
130
  }
131
131
  } else {
132
132
  programOutput = programInput; // nothing → nothing
package/codecs/ieee.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { stdin, stdout, argv, exit } from "node:process";
4
- import { Product, Variant } from "../Value.mjs";
4
+ import { Value, isProduct, isVariant } from "../Value.mjs";
5
5
  import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
6
6
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
7
7
  import { FLOAT64_PATTERN } from "./runtime/ieee-pattern.mjs";
8
- const UNIT = new Product({});
8
+ const UNIT = Value.product({});
9
9
  const name = "ieee";
10
10
  const patterns = [FLOAT64_PATTERN];
11
11
 
@@ -17,7 +17,7 @@ function usage(stream = console.error) {
17
17
  }
18
18
 
19
19
  function bitValue(bit) {
20
- return new Variant(bit === 0 ? "0" : "1", UNIT);
20
+ return Value.variant(bit === 0 ? "0" : "1", UNIT);
21
21
  }
22
22
 
23
23
  function bitsProduct(width, value) {
@@ -26,7 +26,7 @@ function bitsProduct(width, value) {
26
26
  for (let i = width - 1; i >= 0; i--) {
27
27
  product[String(i)] = bitValue(Number((big >> BigInt(i)) & 1n));
28
28
  }
29
- return new Product(product);
29
+ return Value.product(product);
30
30
  }
31
31
 
32
32
  function encodeNumberToValue(number) {
@@ -37,22 +37,22 @@ function encodeNumberToValue(number) {
37
37
  const exponent = Number((bits >> 52n) & 0x7ffn);
38
38
  const fraction = bits & ((1n << 52n) - 1n);
39
39
 
40
- return new Product({
41
- sign: new Variant(sign === 0 ? "+" : "-", UNIT),
40
+ return Value.product({
41
+ sign: Value.variant(sign === 0 ? "+" : "-", UNIT),
42
42
  exponent: bitsProduct(11, exponent),
43
43
  fraction: bitsProduct(52, fraction)
44
44
  });
45
45
  }
46
46
 
47
47
  function requireProduct(value, where) {
48
- if (!(value instanceof Product)) {
48
+ if (!isProduct(value)) {
49
49
  throw new Error(`${where}: expected Product`);
50
50
  }
51
51
  return value.product;
52
52
  }
53
53
 
54
54
  function requireVariant(value, where) {
55
- if (!(value instanceof Variant)) {
55
+ if (!isVariant(value)) {
56
56
  throw new Error(`${where}: expected Variant`);
57
57
  }
58
58
  return value;
package/codecs/int.mjs CHANGED
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  import { stdin, stdout, argv, exit } from "node:process";
17
- import { Product, Variant } from "../Value.mjs";
17
+ import { Value, isVariant } from "../Value.mjs";
18
18
  import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
19
19
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
20
20
 
@@ -47,9 +47,9 @@ function readAll(stream) {
47
47
  // Build bits Value (MSB outermost) from a non-negative BigInt.
48
48
  function buildBits(n) {
49
49
  const bitChars = n === 0n ? ["0"] : n.toString(2).split("");
50
- let v = new Variant("_", new Product({}));
50
+ let v = Value.variant("_", Value.product({}));
51
51
  for (let i = bitChars.length - 1; i >= 0; i--) {
52
- v = new Variant(bitChars[i], v);
52
+ v = Value.variant(bitChars[i], v);
53
53
  }
54
54
  return v;
55
55
  }
@@ -65,18 +65,18 @@ function parseIntStr(str) {
65
65
  }
66
66
  const n = BigInt(str);
67
67
  if (n === 0n) sign = "+"; // zero is always '+'
68
- return new Variant(sign, buildBits(n));
68
+ return Value.variant(sign, buildBits(n));
69
69
  }
70
70
 
71
71
  // Walk a decoded int Value (Variant sign → bits) and return a decimal string.
72
72
  function printIntValue(value) {
73
- if (!(value instanceof Variant) || (value.tag !== "+" && value.tag !== "-")) {
73
+ if (!isVariant(value) || (value.tag !== "+" && value.tag !== "-")) {
74
74
  throw new Error("Not a valid k int value");
75
75
  }
76
76
  const sign = value.tag;
77
77
  let bits = "";
78
78
  let node = value.value;
79
- while (node instanceof Variant && node.tag !== "_") {
79
+ while (isVariant(node) && node.tag !== "_") {
80
80
  bits += node.tag;
81
81
  node = node.value;
82
82
  }