@fraczak/k 6.3.1 → 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
+ }
package/kvm.mjs CHANGED
@@ -17,6 +17,42 @@ import { decodeObject, loadLibrary } from "./object.mjs";
17
17
  import codes from "./codes.mjs";
18
18
  import { isMainEntrypoint } from "./codecs/runtime/cli-entry.mjs";
19
19
 
20
+ function isFile(filePath) {
21
+ try {
22
+ return fs.statSync(filePath).isFile();
23
+ } catch (error) {
24
+ if (error?.code === "ENOENT" || error?.code === "ENOTDIR") return false;
25
+ throw error;
26
+ }
27
+ }
28
+
29
+ function buildExportPreamble(exports, libraries) {
30
+ if (exports.length === 0) return "";
31
+ const aliasMap = {};
32
+ for (const lib of libraries) {
33
+ for (const [name, hash] of Object.entries(lib.relAlias || {})) {
34
+ if (name !== "__main__") aliasMap[name] = hash;
35
+ }
36
+ for (const [hash, entry] of Object.entries(lib.meta || {})) {
37
+ if (entry?.type !== "rel") continue;
38
+ for (const origin of entry?.origins || []) {
39
+ if (origin?.name && origin.name !== "__main__") {
40
+ aliasMap[origin.name] = hash;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ const lines = [];
46
+ for (const spec of exports) {
47
+ const [libName, localName] = spec.includes(":") ? spec.split(":", 2) : [spec, spec];
48
+ const hash = aliasMap[libName];
49
+ if (!hash) throw new Error(`--export: '${libName}' not found in loaded libraries`);
50
+ const body = hash.startsWith("@") ? hash.slice(1) : hash;
51
+ lines.push(`${localName} = @${body};`);
52
+ }
53
+ return lines.join("\n") + "\n";
54
+ }
55
+
20
56
  class KVMBuilder {
21
57
  constructor(typePatternGraph) {
22
58
  this.typePatternGraph = typePatternGraph;
@@ -428,9 +464,10 @@ export default {
428
464
 
429
465
  function usage() {
430
466
  const prog = argv[1] || "kvm.mjs";
431
- console.error(`Usage: node ${prog} [ options ] ( k-expr | -k file ) [ input-file ]`);
467
+ console.error(`Usage: node ${prog} [ options ] ( k-expr | input-file ) [ input-file ]`);
432
468
  console.error("Options:");
433
469
  console.error(" --lib file Load one .klib dependency before compiling.");
470
+ console.error(" --export spec Export a library alias into scope. 'name' or 'libname:localname'. May be repeated.");
434
471
  console.error(" --envelope-free Run the interpreter in envelope-free mode.");
435
472
  console.error(" -h, --help Show this help.");
436
473
  }
@@ -444,6 +481,7 @@ async function main() {
444
481
 
445
482
  let envelopeFree = false;
446
483
  const libraries = [];
484
+ const exports = [];
447
485
 
448
486
  // Parse options
449
487
  while (args.length > 0) {
@@ -457,22 +495,44 @@ async function main() {
457
495
  if (libraries.length > 0) throw new Error("--lib may be specified at most once");
458
496
  const libBuffer = fs.readFileSync(libPath);
459
497
  libraries.push(loadLibrary(decodeObject(libBuffer)));
498
+ } else if (args[0] === "--export") {
499
+ args.shift();
500
+ const spec = args.shift();
501
+ if (!spec) throw new Error("--export requires a spec argument");
502
+ exports.push(spec);
503
+ } else if (args[0].startsWith("--")) {
504
+ throw new Error(`Unknown option: ${args[0]}`);
460
505
  } else {
461
506
  break;
462
507
  }
463
508
  }
464
509
 
465
- let kScriptStr = (function (arg) {
510
+ const programInput = (function (arg) {
466
511
  if (arg == null) {
467
512
  throw new Error("Missing script argument");
468
513
  }
469
514
  if (arg === "-k") {
470
- const fileArg = args.shift();
471
- if (!fileArg) throw new Error("-k requires a file argument");
472
- return fs.readFileSync(fileArg, "utf8");
473
- } else {
474
- return arg;
515
+ throw new Error("-k is no longer supported; pass the source/object file path directly");
516
+ }
517
+ if (isFile(arg)) {
518
+ const buffer = fs.readFileSync(arg);
519
+ try {
520
+ const object = decodeObject(buffer);
521
+ if (object.main == null) {
522
+ throw new Error("Cannot run a .klib library without a main relation; load it with --lib.");
523
+ }
524
+ return { kind: "object", defs: { rels: object.rels }, main: object.main };
525
+ } catch (error) {
526
+ if (error.message === "Cannot run a .klib library without a main relation; load it with --lib.") {
527
+ throw error;
528
+ }
529
+ return {
530
+ kind: "source",
531
+ source: buildExportPreamble(exports, libraries) + buffer.toString("utf8")
532
+ };
533
+ }
475
534
  }
535
+ return { kind: "source", source: buildExportPreamble(exports, libraries) + arg };
476
536
  })(args.shift());
477
537
 
478
538
  const inputStream = (function (arg) {
@@ -482,13 +542,20 @@ async function main() {
482
542
  return fs.createReadStream(arg);
483
543
  })(args.shift());
484
544
 
485
- const defs = annotate(kScriptStr, { libraries });
486
- const mainRel = defs.rels.__main__;
545
+ if (args.length > 0) {
546
+ throw new Error(`Unexpected argument: ${args[0]}`);
547
+ }
548
+
549
+ const defs = programInput.kind === "object"
550
+ ? programInput.defs
551
+ : annotate(programInput.source, { libraries });
552
+ const mainRelName = programInput.kind === "object" ? programInput.main : "__main__";
553
+ const mainRel = defs.rels[mainRelName];
487
554
  if (!mainRel) {
488
- throw new Error("No main relation (__main__) defined in script");
555
+ throw new Error(`No main relation (${mainRelName}) defined in script`);
489
556
  }
490
557
 
491
- const kvmFunc = lowerToKVM(mainRel, "__main__");
558
+ const kvmFunc = lowerToKVM(mainRel, mainRelName);
492
559
 
493
560
  const buffer = [];
494
561
  inputStream.on("data", (data) => buffer.push(Buffer.isBuffer(data) ? data : Buffer.from(data)));
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "6.3.1",
3
+ "version": "6.3.2",
4
4
  "description": "k — a language for composing first-order partial functions over algebraic data types (products and tagged unions); includes runtime, type derivation, REPL, and codec toolchain",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
7
7
  "prepare": "jiwson -m es6 parser.jison -o parser.mjs; jiwson -m es6 valueParser.jison -o valueParser.mjs; ",
8
8
  "test": "node scripts/run-tests.mjs",
9
+ "benchmark": "node scripts/benchmark.mjs",
10
+ "benchmark:html": "node scripts/render-benchmark.mjs",
11
+ "hooks:install": "git config core.hooksPath scripts/git-hooks",
9
12
  "perf:idempotency": "node scripts/benchmark-idempotency.mjs",
10
13
  "deps:graph": "node scripts/generate-dependency-graph.mjs"
11
14
  },