@fraczak/k 8.9.0 → 9.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/CHANGELOG.md +28 -0
- package/DOCS/ARCHITECTURE.md +5 -4
- package/DOCS/DICTIONARY.md +2 -2
- package/DOCS/FILE_FORMATS.md +11 -9
- package/DOCS/KIR_V1.md +5 -1
- package/DOCS/KTVM_SPEC.md +907 -0
- package/DOCS/KVM_EXECUTION_MODEL.md +3 -2
- package/DOCS/KVM_VS_KTVM_COMPARATIVE_STUDY.md +127 -0
- package/DOCS/PROFILING_AND_TRACING.md +13 -4
- package/DOCS/README.md +3 -2
- package/DOCS/REPL.md +16 -12
- package/README.md +138 -2
- package/backend-api.mjs +31 -16
- package/backends/llvm/README.md +4 -5
- package/backends/llvm/bin/k-llvm-build.mjs +7 -19
- package/backends/llvm/bin/k-llvm-compile.mjs +6 -18
- package/backends/llvm/bin/k-llvm.mjs +11 -33
- package/backends/llvm/src/cli.mjs +2 -12
- package/backends/llvm/src/executable.mjs +7 -95
- package/backends/llvm/src/kvm2llvm.mjs +1 -7
- package/backends/llvm/src/llvm.mjs +4 -113
- package/backends/llvm/tests/k-llvm-run.mjs +1 -6
- package/backends/llvm/tests/perf-support.mjs +3 -5
- package/backends/llvm/tests/test-llvm.mjs +2 -16
- package/backends/wasm/README.md +7 -3
- package/backends/wasm/bin/k-wasm-compile.mjs +4 -7
- package/backends/wasm/bin/k-wasm.mjs +4 -6
- package/backends/wasm/src/cli.mjs +8 -24
- package/backends/wasm/src/wasm.mjs +60 -57
- package/backends/wasm/tests/test-wasm.mjs +41 -2
- package/browser/repl-browser.mjs +9 -8
- package/browser/shims/buffer.mjs +31 -2
- package/browser/shims/child_process.mjs +26 -0
- package/browser/shims/fs.mjs +3 -1
- package/codecs/runtime/prefix-codec.mjs +67 -1
- package/conformance/run.mjs +17 -2
- package/harness/adapters/ktvm-llvm.mjs +118 -0
- package/harness/adapters/ktvm-wasm.mjs +104 -0
- package/harness/adapters/ktvm.mjs +133 -0
- package/harness/registry.mjs +9 -0
- package/ktvm/ast.mjs +218 -0
- package/ktvm/bit-deque.mjs +497 -0
- package/ktvm/fixtures/integer-streaming.k +477 -0
- package/ktvm/index.mjs +130 -0
- package/ktvm/llvm/index.mjs +202 -0
- package/ktvm/llvm/lower-c.mjs +1258 -0
- package/ktvm/llvm/runtime.h +3542 -0
- package/ktvm/llvm/test-llvm.mjs +476 -0
- package/ktvm/lower-kir.mjs +2221 -0
- package/ktvm/optimize/fuse-kernel.mjs +2111 -0
- package/ktvm/optimize/index.mjs +116 -0
- package/ktvm/optimize/mwtr.mjs +283 -0
- package/ktvm/optimize/simplify-procs.mjs +5250 -0
- package/ktvm/optimize/synthesize-tables.mjs +1105 -0
- package/ktvm/parser.mjs +1101 -0
- package/ktvm/printer.mjs +281 -0
- package/ktvm/schema.mjs +1134 -0
- package/ktvm/specialize.mjs +538 -0
- package/ktvm/test-conformance.mjs +597 -0
- package/ktvm/test-ktvm.mjs +1805 -0
- package/ktvm/test-optimize.mjs +598 -0
- package/ktvm/validator.mjs +1280 -0
- package/ktvm/vm.mjs +2225 -0
- package/ktvm/wasm/index.mjs +331 -0
- package/ktvm/wasm/lower-wasm.mjs +1272 -0
- package/ktvm/wasm/runtime.wat +4404 -0
- package/ktvm/wasm/test-wasm.mjs +429 -0
- package/ktvm/wire.mjs +679 -0
- package/package.json +1 -9
- package/paper/Makefile +8 -5
- package/paper/k-transducer-compiler.pdf +0 -0
- package/paper/k-transducer-compiler.tex +658 -0
- package/paper/replay-diagnostic.mjs +63 -0
- package/repl.mjs +101 -20
- package/scripts/build-repl-html.mjs +40 -18
- package/scripts/perf-bigint-compare.mjs +12 -16
- package/scripts/perf-ieee.mjs +14 -232
- package/scripts/perf-int.mjs +16 -274
- package/scripts/perf-multiplication.mjs +116 -121
- package/scripts/perf-poly.mjs +9 -263
- package/scripts/run-tests.mjs +5 -2
- package/scripts/test-package.mjs +15 -3
- package/tests/README.md +3 -3
- package/tests/test-repl-html.mjs +72 -15
- package/tests/test-repl.mjs +24 -17
- package/DOCS/POLYMORPHIC_IR.md +0 -86
- package/access-table.mjs +0 -343
- package/pkir.mjs +0 -772
- package/tests/test-access-table.mjs +0 -213
- package/tests/test-pkir.mjs +0 -530
package/scripts/perf-poly.mjs
CHANGED
|
@@ -62,7 +62,7 @@ function printHelp() {
|
|
|
62
62
|
|
|
63
63
|
Polymorphic List Operations Benchmark Harness.
|
|
64
64
|
Benchmarks reverse, concat, split_by, get_nth, and length on
|
|
65
|
-
Examples/poly.k across Native JS, kVM interpreter, LLVM,
|
|
65
|
+
Examples/poly.k across Native JS, kVM interpreter, LLVM, and Wasm.
|
|
66
66
|
|
|
67
67
|
Options:
|
|
68
68
|
--trace
|
|
@@ -71,20 +71,16 @@ Options:
|
|
|
71
71
|
Enable per-function call count profiling.
|
|
72
72
|
--wasm-in-process
|
|
73
73
|
Run WebAssembly in-process instead of persistent subprocess runner.
|
|
74
|
-
--pkir-only
|
|
75
|
-
Run only PKIR backend.
|
|
76
74
|
-h, --help
|
|
77
75
|
Show this help message and exit.
|
|
78
76
|
|
|
79
77
|
Environment Variables:
|
|
80
78
|
BACKENDS
|
|
81
|
-
Target backend to run: 'llvm'
|
|
79
|
+
Target backend to run: 'llvm' or 'wasm'.
|
|
82
80
|
LLVM_ONLY
|
|
83
81
|
Run only LLVM backend ('1' to enable).
|
|
84
82
|
WASM_ONLY
|
|
85
83
|
Run only WebAssembly backend ('1' to enable).
|
|
86
|
-
PKIR_ONLY
|
|
87
|
-
Run only PKIR backend ('1' to enable).
|
|
88
84
|
BACKENDS_ONLY
|
|
89
85
|
Skip JS and kVM interpreter baselines ('1' to enable).
|
|
90
86
|
LIST_LENGTH
|
|
@@ -123,49 +119,28 @@ const backendsEnv = process.env.BACKENDS?.toLowerCase();
|
|
|
123
119
|
const backendsList = backendsEnv
|
|
124
120
|
? backendsEnv.split(",").map(s => s.trim())
|
|
125
121
|
: null;
|
|
126
|
-
const
|
|
122
|
+
const llvmOnly = process.env.LLVM_ONLY === "1"
|
|
127
123
|
|| (backendsList && backendsList.length === 1 &&
|
|
128
|
-
backendsList[0] === "llvm
|
|
129
|
-
|
|
130
|
-
const pkirOnly = !llvmPkirOnly && (
|
|
131
|
-
process.env.PKIR_ONLY === "1"
|
|
132
|
-
|| (backendsList && backendsList.length === 1 &&
|
|
133
|
-
backendsList[0] === "pkir")
|
|
134
|
-
|| process.argv.includes("--pkir-only")
|
|
135
|
-
);
|
|
136
|
-
const llvmOnly = !pkirOnly && !llvmPkirOnly && (
|
|
137
|
-
process.env.LLVM_ONLY === "1"
|
|
138
|
-
|| (backendsList && backendsList.length === 1 &&
|
|
139
|
-
backendsList[0] === "llvm")
|
|
140
|
-
);
|
|
141
|
-
const wasmOnly = !pkirOnly && !llvmPkirOnly && !llvmOnly && (
|
|
124
|
+
backendsList[0] === "llvm");
|
|
125
|
+
const wasmOnly = !llvmOnly && (
|
|
142
126
|
process.env.WASM_ONLY === "1"
|
|
143
127
|
|| (backendsList && backendsList.length === 1 &&
|
|
144
128
|
backendsList[0] === "wasm")
|
|
145
129
|
);
|
|
146
130
|
const runLLVM = backendsList
|
|
147
131
|
? backendsList.includes("llvm")
|
|
148
|
-
: !wasmOnly
|
|
149
|
-
const runLLVMPKIR = backendsList
|
|
150
|
-
? backendsList.includes("llvm-pkir")
|
|
151
|
-
: !wasmOnly && !pkirOnly && !llvmOnly;
|
|
132
|
+
: !wasmOnly;
|
|
152
133
|
const runWasm = backendsList
|
|
153
134
|
? backendsList.includes("wasm")
|
|
154
|
-
: !llvmOnly
|
|
155
|
-
const runPKIR = backendsList
|
|
156
|
-
? backendsList.includes("pkir")
|
|
157
|
-
: !llvmOnly && !wasmOnly && !llvmPkirOnly;
|
|
135
|
+
: !llvmOnly;
|
|
158
136
|
const runBaselines = !process.env.BACKENDS_ONLY
|
|
159
137
|
&& (backendsList == null || backendsList.includes("kvm") ||
|
|
160
138
|
backendsList.includes("js"))
|
|
161
|
-
&& !llvmOnly && !wasmOnly
|
|
139
|
+
&& !llvmOnly && !wasmOnly;
|
|
162
140
|
|
|
163
141
|
function llvmLaneNameStr() {
|
|
164
142
|
return llvmLaneName();
|
|
165
143
|
}
|
|
166
|
-
function llvmPkirLaneNameStr() {
|
|
167
|
-
return llvmLaneName().replace("LLVM", "LLVM-PKIR");
|
|
168
|
-
}
|
|
169
144
|
|
|
170
145
|
const ops = ["reverse", "concat", "split_by", "get_nth", "length"];
|
|
171
146
|
const benchNames = Object.fromEntries(ops.map(op => [op, `bench_${op}`]));
|
|
@@ -188,9 +163,6 @@ function wasmLaneName() {
|
|
|
188
163
|
const mode = wasmPipe ? "persistent" : "in-process";
|
|
189
164
|
return `WebAssembly (${mode})`;
|
|
190
165
|
}
|
|
191
|
-
function pkirLaneName() {
|
|
192
|
-
return "PKIR (Wasm persistent)";
|
|
193
|
-
}
|
|
194
166
|
|
|
195
167
|
|
|
196
168
|
console.log("==> Loading @fraczak/k/lib/integer.k as library");
|
|
@@ -324,36 +296,13 @@ if (runLLVM) {
|
|
|
324
296
|
inputPattern: tc.inputPattern,
|
|
325
297
|
cacheDir,
|
|
326
298
|
sourceLabel:
|
|
327
|
-
`@fraczak/k/Examples/poly.k#${relation.relationName}
|
|
328
|
-
usePKIR: false
|
|
299
|
+
`@fraczak/k/Examples/poly.k#${relation.relationName}`
|
|
329
300
|
});
|
|
330
301
|
}
|
|
331
302
|
codes.load(state.codes);
|
|
332
303
|
printCompileFailures(testSuite);
|
|
333
304
|
}
|
|
334
305
|
|
|
335
|
-
// Setup LLVM-PKIR
|
|
336
|
-
if (runLLVMPKIR) {
|
|
337
|
-
console.log("==> Compiling LLVM-PKIR executables");
|
|
338
|
-
for (const tc of testSuite) {
|
|
339
|
-
const relation = relations[tc.op];
|
|
340
|
-
tc.llvmPKIR = tryCompileCase({
|
|
341
|
-
object: relation.object,
|
|
342
|
-
relationName: relation.relationName,
|
|
343
|
-
relHash: relation.relHash,
|
|
344
|
-
inputPattern: tc.inputPattern,
|
|
345
|
-
cacheDir,
|
|
346
|
-
sourceLabel:
|
|
347
|
-
`@fraczak/k/Examples/poly.k#${relation.relationName}`,
|
|
348
|
-
usePKIR: true
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
codes.load(state.codes);
|
|
352
|
-
printCompileFailures(
|
|
353
|
-
testSuite.map(tc => ({ ...tc, llvm: tc.llvmPKIR }))
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
306
|
// Setup Wasm
|
|
358
307
|
let wasmExports = null;
|
|
359
308
|
let wasmProfileFunctions = [];
|
|
@@ -396,34 +345,6 @@ if (runWasm) {
|
|
|
396
345
|
}
|
|
397
346
|
}
|
|
398
347
|
|
|
399
|
-
// Setup PKIR (persistent runner)
|
|
400
|
-
const pkirExes = new Map();
|
|
401
|
-
if (runPKIR) {
|
|
402
|
-
console.log("==> Compiling PKIR executables (persistent runner)...");
|
|
403
|
-
for (const tc of testSuite) {
|
|
404
|
-
const relation = relations[tc.op];
|
|
405
|
-
try {
|
|
406
|
-
const wasmPath = path.join(cacheDir, `perf_poly_pkir_${tc.op}.wasm`);
|
|
407
|
-
const exePath = path.join(cacheDir, `perf_poly_pkir_${tc.op}.exe`);
|
|
408
|
-
const wasmBuf = await compileWasmArtifactFromObject(relation.object, {
|
|
409
|
-
entry: relation.relHash,
|
|
410
|
-
usePKIR: true
|
|
411
|
-
});
|
|
412
|
-
fs.writeFileSync(wasmPath, wasmBuf);
|
|
413
|
-
const runBin = fileURLToPath(import.meta.resolve("../backends/wasm/bin/k-wasm-run.mjs"));
|
|
414
|
-
fs.writeFileSync(exePath, `#!/bin/sh\nexec node "${runBin}" "${wasmPath}" "$@"\n`, { mode: 0o755 });
|
|
415
|
-
tc.pkir = { status: "ok", exePath, wasmPath };
|
|
416
|
-
pkirExes.set(tc.op, tc.pkir);
|
|
417
|
-
} catch (error) {
|
|
418
|
-
tc.pkir = {
|
|
419
|
-
status: "failed",
|
|
420
|
-
error: error.stack || error.message || String(error)
|
|
421
|
-
};
|
|
422
|
-
pkirExes.set(tc.op, tc.pkir);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
348
|
function createWasmRunner(testSuite) {
|
|
428
349
|
const wasmCases = testSuite.filter(tc => tc.wasm?.status === "ok");
|
|
429
350
|
const servers = new Map();
|
|
@@ -452,34 +373,6 @@ function createWasmRunner(testSuite) {
|
|
|
452
373
|
};
|
|
453
374
|
}
|
|
454
375
|
|
|
455
|
-
function createPKIRRunner(testSuite) {
|
|
456
|
-
const pkirCases = testSuite.filter(tc => tc.pkir?.status === "ok");
|
|
457
|
-
const servers = new Map();
|
|
458
|
-
function serverFor(exePath) {
|
|
459
|
-
let server = servers.get(exePath);
|
|
460
|
-
if (server == null) {
|
|
461
|
-
server = new PersistentExecutable(exePath);
|
|
462
|
-
servers.set(exePath, server);
|
|
463
|
-
}
|
|
464
|
-
return server;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return {
|
|
468
|
-
async run(iterations) {
|
|
469
|
-
if (pkirCases.length === 0) return null;
|
|
470
|
-
return runTimedIterationsAsync(iterations, async () => {
|
|
471
|
-
for (const tc of pkirCases) {
|
|
472
|
-
await serverFor(tc.pkir.exePath).request(tc.inputWire);
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
},
|
|
476
|
-
serverFor,
|
|
477
|
-
close() {
|
|
478
|
-
for (const server of servers.values()) server.close();
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
|
|
483
376
|
function printBenchmarkDescription() {
|
|
484
377
|
const lanes = [];
|
|
485
378
|
if (runBaselines) {
|
|
@@ -488,9 +381,7 @@ function printBenchmarkDescription() {
|
|
|
488
381
|
lanes.push("kVM Interpreter (Env-Free)");
|
|
489
382
|
}
|
|
490
383
|
if (runLLVM) lanes.push(llvmLaneNameStr());
|
|
491
|
-
if (runLLVMPKIR) lanes.push(llvmPkirLaneNameStr());
|
|
492
384
|
if (runWasm) lanes.push(wasmLaneName());
|
|
493
|
-
if (runPKIR) lanes.push(pkirLaneName());
|
|
494
385
|
|
|
495
386
|
console.log("==> Benchmark description");
|
|
496
387
|
console.log(" source: @fraczak/k/Examples/poly.k");
|
|
@@ -502,18 +393,11 @@ function printBenchmarkDescription() {
|
|
|
502
393
|
console.log(` llvm-ready cases: ${testSuite.filter(tc => tc.llvm?.status === "ok").length}`);
|
|
503
394
|
console.log(` llvm warmup iterations: ${llvmWarmupIterations}`);
|
|
504
395
|
}
|
|
505
|
-
if (runLLVMPKIR) {
|
|
506
|
-
console.log(` llvm-pkir ready cases: ${testSuite.filter(tc => tc.llvmPKIR?.status === "ok").length}`);
|
|
507
|
-
console.log(` llvm-pkir warmup iterations: ${llvmWarmupIterations}`);
|
|
508
|
-
}
|
|
509
396
|
if (runWasm) {
|
|
510
397
|
console.log(` wasm runner mode: ${wasmPipe ? "persistent pipe" : "in-process"}`);
|
|
511
398
|
console.log(` wasm warmup iterations: ${wasmWarmupIterations}`);
|
|
512
399
|
if (!wasmPipe) console.log(` wasm arena reset: ${wasmReset ? "yes" : "no"}`);
|
|
513
400
|
}
|
|
514
|
-
if (runPKIR) {
|
|
515
|
-
console.log(` pkir warmup iterations: ${wasmWarmupIterations}`);
|
|
516
|
-
}
|
|
517
401
|
console.log(` iterations: ${iterations}`);
|
|
518
402
|
console.log(` benchmark lanes: ${lanes.join("; ")}`);
|
|
519
403
|
console.log(" conformance: all outputs are compared to native expected values");
|
|
@@ -549,23 +433,6 @@ if (runLLVM) {
|
|
|
549
433
|
}
|
|
550
434
|
}
|
|
551
435
|
|
|
552
|
-
// 2b. LLVM-PKIR lane
|
|
553
|
-
let llvmPkirResult = null;
|
|
554
|
-
if (runLLVMPKIR) {
|
|
555
|
-
const llvmPkirCases = testSuite.map(tc => ({ ...tc, llvm: tc.llvmPKIR }));
|
|
556
|
-
const llvmPkirRunner = createLLVMRunner(llvmPkirCases);
|
|
557
|
-
try {
|
|
558
|
-
if (llvmWarmupIterations > 0) {
|
|
559
|
-
console.log(`==> Warming LLVM-PKIR executables (${llvmWarmupIterations} iterations)...`);
|
|
560
|
-
await llvmPkirRunner.run(llvmWarmupIterations);
|
|
561
|
-
}
|
|
562
|
-
console.log(`==> Running LLVM-PKIR (${iterations} iterations)...`);
|
|
563
|
-
llvmPkirResult = await llvmPkirRunner.run(iterations);
|
|
564
|
-
} finally {
|
|
565
|
-
llvmPkirRunner.close();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
436
|
// 3. Wasm lane
|
|
570
437
|
let wasmResult = null;
|
|
571
438
|
if (runWasm) {
|
|
@@ -611,25 +478,6 @@ if (runWasm) {
|
|
|
611
478
|
}
|
|
612
479
|
}
|
|
613
480
|
|
|
614
|
-
// 4. PKIR lane
|
|
615
|
-
let pkirResult = null;
|
|
616
|
-
if (runPKIR) {
|
|
617
|
-
const pkirCases = testSuite.filter(tc => tc.pkir?.status === "ok");
|
|
618
|
-
if (pkirCases.length === testSuite.length) {
|
|
619
|
-
const pkirRunner = createPKIRRunner(testSuite);
|
|
620
|
-
try {
|
|
621
|
-
if (wasmWarmupIterations > 0) {
|
|
622
|
-
console.log(`==> Warming PKIR (${wasmWarmupIterations} iterations)...`);
|
|
623
|
-
await pkirRunner.run(wasmWarmupIterations);
|
|
624
|
-
}
|
|
625
|
-
console.log(`==> Running PKIR (${iterations} iterations)...`);
|
|
626
|
-
pkirResult = await pkirRunner.run(iterations);
|
|
627
|
-
} finally {
|
|
628
|
-
pkirRunner.close();
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
481
|
console.log("\n=================== POLYMORPHIC BENCHMARK RESULTS ===================");
|
|
634
482
|
console.log(`Polymorphic operations per iteration: ${testSuite.length}`);
|
|
635
483
|
console.log(`Total requested operation calls: ${iterations * testSuite.length}`);
|
|
@@ -644,16 +492,9 @@ if (runLLVM) {
|
|
|
644
492
|
const name = llvmLaneNameStr().padEnd(29);
|
|
645
493
|
console.log(`${laneIndex++}. ${name} ${formatTiming(llvmResult)}`);
|
|
646
494
|
}
|
|
647
|
-
if (runLLVMPKIR) {
|
|
648
|
-
const name = llvmPkirLaneNameStr().padEnd(29);
|
|
649
|
-
console.log(`${laneIndex++}. ${name} ${formatTiming(llvmPkirResult)}`);
|
|
650
|
-
}
|
|
651
495
|
if (runWasm) {
|
|
652
496
|
console.log(`${laneIndex++}. ${wasmLaneName().padEnd(29)} ${formatTiming(wasmResult)}`);
|
|
653
497
|
}
|
|
654
|
-
if (runPKIR) {
|
|
655
|
-
console.log(`${laneIndex++}. ${pkirLaneName().padEnd(29)} ${formatTiming(pkirResult)}`);
|
|
656
|
-
}
|
|
657
498
|
console.log("=====================================================================\n");
|
|
658
499
|
|
|
659
500
|
// Conformance Validation
|
|
@@ -680,23 +521,6 @@ for (const tc of testSuite) {
|
|
|
680
521
|
}
|
|
681
522
|
}
|
|
682
523
|
|
|
683
|
-
if (runLLVMPKIR) {
|
|
684
|
-
if (tc.llvmPKIR.status !== "ok") {
|
|
685
|
-
tc.llvmPkirConformance = "compile-failed";
|
|
686
|
-
} else {
|
|
687
|
-
try {
|
|
688
|
-
const outputWire = await runExecutable(tc.llvmPKIR.exePath, tc.inputWire);
|
|
689
|
-
const actual = decodeWire(outputWire).value;
|
|
690
|
-
assert.ok(safeDeepEqual(actual, tc.expected), `LLVM-PKIR output mismatch for ${tc.op}`);
|
|
691
|
-
tc.llvmPkirConformance = "ok";
|
|
692
|
-
} catch (error) {
|
|
693
|
-
tc.llvmPkirConformance = "failed";
|
|
694
|
-
tc.llvmPKIR.error = error.stack || error.message || String(error);
|
|
695
|
-
console.log(`LLVM-PKIR conformance failure for ${tc.op}:`, tc.llvmPKIR.error.split("\n")[0]);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
524
|
if (runWasm) {
|
|
701
525
|
if (wasmPipe) {
|
|
702
526
|
if (tc.wasm?.status !== "ok") {
|
|
@@ -736,23 +560,6 @@ for (const tc of testSuite) {
|
|
|
736
560
|
}
|
|
737
561
|
}
|
|
738
562
|
|
|
739
|
-
if (runPKIR) {
|
|
740
|
-
if (tc.pkir?.status !== "ok") {
|
|
741
|
-
tc.pkirConformance = "compile-failed";
|
|
742
|
-
} else {
|
|
743
|
-
try {
|
|
744
|
-
const outputWire = await runExecutable(tc.pkir.exePath, tc.inputWire);
|
|
745
|
-
const actual = decodeWire(outputWire).value;
|
|
746
|
-
assert.ok(safeDeepEqual(actual, tc.expected), `PKIR output mismatch for ${tc.op}`);
|
|
747
|
-
tc.pkirConformance = "ok";
|
|
748
|
-
} catch (error) {
|
|
749
|
-
tc.pkirConformance = "failed";
|
|
750
|
-
tc.pkir.error = error.stack || error.message || String(error);
|
|
751
|
-
console.log(`PKIR conformance failure for ${tc.op}:`, tc.pkir.error.split("\n")[0]);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
563
|
}
|
|
757
564
|
|
|
758
565
|
const validationSummary = [];
|
|
@@ -761,24 +568,14 @@ if (runLLVM) {
|
|
|
761
568
|
const llvmOk = testSuite.filter(tc => tc.llvmConformance === "ok").length;
|
|
762
569
|
validationSummary.push(`LLVM ${llvmOk}/${testSuite.length}`);
|
|
763
570
|
}
|
|
764
|
-
if (runLLVMPKIR) {
|
|
765
|
-
const pkirOk = testSuite.filter(tc => tc.llvmPkirConformance === "ok").length;
|
|
766
|
-
validationSummary.push(`LLVM-PKIR ${pkirOk}/${testSuite.length}`);
|
|
767
|
-
}
|
|
768
571
|
if (runWasm) {
|
|
769
572
|
const wasmOk = testSuite.filter(tc => tc.wasmConformance === "ok").length;
|
|
770
573
|
validationSummary.push(`Wasm ${wasmOk}/${testSuite.length}`);
|
|
771
574
|
}
|
|
772
|
-
if (runPKIR) {
|
|
773
|
-
const pkirOk = testSuite.filter(tc => tc.pkirConformance === "ok").length;
|
|
774
|
-
validationSummary.push(`PKIR ${pkirOk}/${testSuite.length}`);
|
|
775
|
-
}
|
|
776
575
|
|
|
777
576
|
console.log(`Conformance validation: ${validationSummary.join(", ")} cases match expected values.`);
|
|
778
577
|
if (runLLVM && shouldStrictFail(testSuite)) process.exitCode = 1;
|
|
779
|
-
if (runLLVMPKIR && shouldStrictFail(testSuite.map(tc => ({ ...tc, llvm: tc.llvmPKIR })))) process.exitCode = 1;
|
|
780
578
|
if (runWasm && testSuite.some(tc => tc.wasmConformance !== "ok")) process.exitCode = 1;
|
|
781
|
-
if (runPKIR && testSuite.some(tc => tc.pkirConformance !== "ok")) process.exitCode = 1;
|
|
782
579
|
|
|
783
580
|
if (runTrace && process.exitCode !== 1) {
|
|
784
581
|
console.log("\n=================== RUNNING MACRO-PHASE TRACING ===================");
|
|
@@ -794,18 +591,6 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
794
591
|
}
|
|
795
592
|
}
|
|
796
593
|
|
|
797
|
-
const llvmPkirServers = new Map();
|
|
798
|
-
if (runLLVMPKIR) {
|
|
799
|
-
for (const tc of testSuite) {
|
|
800
|
-
if (tc.llvmPKIR?.status === "ok") {
|
|
801
|
-
llvmPkirServers.set(
|
|
802
|
-
tc.op,
|
|
803
|
-
new PersistentExecutable(tc.llvmPKIR.exePath)
|
|
804
|
-
);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
|
|
809
594
|
const wasmServers = new Map();
|
|
810
595
|
if (runWasm && wasmPipe) {
|
|
811
596
|
for (const tc of testSuite) {
|
|
@@ -815,15 +600,6 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
815
600
|
}
|
|
816
601
|
}
|
|
817
602
|
|
|
818
|
-
const pkirServers = new Map();
|
|
819
|
-
if (runPKIR) {
|
|
820
|
-
for (const tc of testSuite) {
|
|
821
|
-
if (tc.pkir?.status === "ok") {
|
|
822
|
-
pkirServers.set(tc.op, new PersistentExecutable(tc.pkir.exePath));
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
|
|
827
603
|
const averageTrace = (samples) => {
|
|
828
604
|
if (!samples || samples.length === 0) return null;
|
|
829
605
|
const avg = {};
|
|
@@ -868,18 +644,6 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
868
644
|
opData.llvm = averageTrace(samples);
|
|
869
645
|
}
|
|
870
646
|
|
|
871
|
-
// 2b. LLVM-PKIR
|
|
872
|
-
if (llvmPkirServers.has(op)) {
|
|
873
|
-
const server = llvmPkirServers.get(op);
|
|
874
|
-
for (let i = 0; i < 3; i++) await server.requestWithTrace(tc.inputWire);
|
|
875
|
-
const samples = [];
|
|
876
|
-
for (let i = 0; i < sampleReps; i++) {
|
|
877
|
-
const res = await server.requestWithTrace(tc.inputWire);
|
|
878
|
-
if (res.trace) samples.push(res.trace);
|
|
879
|
-
}
|
|
880
|
-
opData.llvmPkir = averageTrace(samples);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
647
|
// 3. Wasm
|
|
884
648
|
if (runWasm) {
|
|
885
649
|
if (wasmPipe) {
|
|
@@ -940,18 +704,6 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
940
704
|
}
|
|
941
705
|
}
|
|
942
706
|
|
|
943
|
-
// PKIR
|
|
944
|
-
if (runPKIR && pkirServers.has(op)) {
|
|
945
|
-
const server = pkirServers.get(op);
|
|
946
|
-
for (let i = 0; i < 3; i++) await server.requestWithTrace(tc.inputWire);
|
|
947
|
-
const samples = [];
|
|
948
|
-
for (let i = 0; i < sampleReps; i++) {
|
|
949
|
-
const res = await server.requestWithTrace(tc.inputWire);
|
|
950
|
-
if (res.trace) samples.push(res.trace);
|
|
951
|
-
}
|
|
952
|
-
opData.pkir = averageTrace(samples);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
707
|
// 4. kVM
|
|
956
708
|
if (runBaselines) {
|
|
957
709
|
const relDef = relations[op].relDef;
|
|
@@ -998,9 +750,7 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
998
750
|
}
|
|
999
751
|
|
|
1000
752
|
for (const s of llvmServers.values()) s.close();
|
|
1001
|
-
for (const s of llvmPkirServers.values()) s.close();
|
|
1002
753
|
for (const s of wasmServers.values()) s.close();
|
|
1003
|
-
for (const s of pkirServers.values()) s.close();
|
|
1004
754
|
|
|
1005
755
|
function formatUs(ns) {
|
|
1006
756
|
if (ns == null || ns === 0) return " - ";
|
|
@@ -1023,11 +773,7 @@ if (runTrace && process.exitCode !== 1) {
|
|
|
1023
773
|
if (runLLVM) {
|
|
1024
774
|
activeTraceLanes.push({ id: "llvm", label: "LLVM" });
|
|
1025
775
|
}
|
|
1026
|
-
if (runLLVMPKIR) {
|
|
1027
|
-
activeTraceLanes.push({ id: "llvmPkir", label: "LLVM-PKIR" });
|
|
1028
|
-
}
|
|
1029
776
|
if (runWasm) activeTraceLanes.push({ id: "wasm", label: "WebAssembly" });
|
|
1030
|
-
if (runPKIR) activeTraceLanes.push({ id: "pkir", label: "PKIR (Wasm)" });
|
|
1031
777
|
if (runBaselines) activeTraceLanes.push({ id: "kvm", label: "kVM Interp" });
|
|
1032
778
|
|
|
1033
779
|
const traceHeader = ["Phase ", ...activeTraceLanes.map(l => l.label.padEnd(13))].join(" | ");
|
package/scripts/run-tests.mjs
CHANGED
|
@@ -64,11 +64,14 @@ const tests = [
|
|
|
64
64
|
["tests/test-tree-view.mjs", node, ["tests/test-tree-view.mjs"]],
|
|
65
65
|
["tests/test-kvm.mjs", node, ["tests/test-kvm.mjs"]],
|
|
66
66
|
["tests/test-kvm-polymorphic.mjs", node, ["tests/test-kvm-polymorphic.mjs"]],
|
|
67
|
+
["ktvm/test-ktvm.mjs", node, ["ktvm/test-ktvm.mjs"]],
|
|
68
|
+
["ktvm/test-conformance.mjs", node, ["ktvm/test-conformance.mjs"]],
|
|
69
|
+
["ktvm/test-optimize.mjs", node, ["ktvm/test-optimize.mjs"]],
|
|
70
|
+
["ktvm/wasm/test-wasm.mjs", node, ["ktvm/wasm/test-wasm.mjs"]],
|
|
71
|
+
["ktvm/llvm/test-llvm.mjs", node, ["ktvm/llvm/test-llvm.mjs"]],
|
|
67
72
|
["tests/test-arithmetics.mjs", node, ["tests/test-arithmetics.mjs"]],
|
|
68
73
|
["tests/test-poly.mjs", node, ["tests/test-poly.mjs"]],
|
|
69
74
|
["tests/test-polymorphic-tdd.mjs", node, ["tests/test-polymorphic-tdd.mjs"]],
|
|
70
|
-
["tests/test-access-table.mjs", node, ["tests/test-access-table.mjs"]],
|
|
71
|
-
["tests/test-pkir.mjs", node, ["tests/test-pkir.mjs"]],
|
|
72
75
|
["tests/test-ieee-arithmetic.mjs", node, ["tests/test-ieee-arithmetic.mjs"]],
|
|
73
76
|
["tests/integration.sh", path.join(root, "tests/integration.sh"), []]
|
|
74
77
|
];
|
package/scripts/test-package.mjs
CHANGED
|
@@ -11,12 +11,13 @@ const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"
|
|
|
11
11
|
assert.equal(manifest.name, expected.name);
|
|
12
12
|
assert.equal(manifest.version, expected.version);
|
|
13
13
|
for (const file of ["parser.mjs", "valueParser.mjs", "core.k", "LICENSE",
|
|
14
|
-
"backends/wasm/runtime.wat", "backends/llvm/runtime/krt.c"
|
|
14
|
+
"backends/wasm/runtime.wat", "backends/llvm/runtime/krt.c",
|
|
15
|
+
"ktvm/wasm/runtime.wat", "ktvm/llvm/runtime.h"]) {
|
|
15
16
|
assert.ok(fs.existsSync(path.join(packageDir, file)), file);
|
|
16
17
|
}
|
|
17
18
|
assert.ok(!fs.existsSync(path.join(packageDir, "browser/vfs-data.mjs")),
|
|
18
19
|
"Generated VFS data must not be packed");
|
|
19
|
-
for (const file of ["AGENTS.md", "CLAUDE.md"]) {
|
|
20
|
+
for (const file of ["AGENTS.md", "CLAUDE.md", "experiments", "DOCS/speed-eval.pdf"]) {
|
|
20
21
|
assert.ok(!fs.existsSync(path.join(packageDir, file)), file);
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -63,7 +64,18 @@ try {
|
|
|
63
64
|
run("k-wasm-compile", ["?{} {} |ok", wasm]);
|
|
64
65
|
assert.equal(run("k-print", [], run("k-wasm-run", [wasm], unit)).toString().trim(), '"ok"');
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
const { decodeObject } = await import(pathToFileURL(path.join(packageDir, "object.mjs")));
|
|
68
|
+
const { compileObjectToKTVMWasm, instantiateKTVMWasm } = await import(
|
|
69
|
+
pathToFileURL(path.join(packageDir, "ktvm/wasm/index.mjs"))
|
|
70
|
+
);
|
|
71
|
+
const okObj = decodeObject(fs.readFileSync(object));
|
|
72
|
+
const ktvmArtifact = await compileObjectToKTVMWasm(okObj, "__main__", [["closed-product", []]]);
|
|
73
|
+
const ktvmRunner = await instantiateKTVMWasm(ktvmArtifact);
|
|
74
|
+
const ktvmRes = ktvmRunner.executeWire(unit, { decodeValue: true });
|
|
75
|
+
assert.equal(ktvmRes.status, "OK");
|
|
76
|
+
assert.equal(ktvmRes.value.tag, "ok");
|
|
77
|
+
|
|
78
|
+
console.log(`Package ${manifest.name}@${manifest.version}: API, ${Object.keys(manifest.bin).length} CLIs, codecs, objects, Wasm, and kTVM passed on ${process.version}`);
|
|
67
79
|
} finally {
|
|
68
80
|
fs.rmSync(scratch, { recursive: true, force: true });
|
|
69
81
|
}
|
package/tests/README.md
CHANGED
|
@@ -8,14 +8,14 @@ client. The source parser and runtime can run without a browser.
|
|
|
8
8
|
|
|
9
9
|
| Command | Coverage |
|
|
10
10
|
| --- | --- |
|
|
11
|
-
| `npm test` | Registered runtime, patterns, paper examples, codecs, hashes, objects, REPL, browser, kVM,
|
|
11
|
+
| `npm test` | Registered runtime, patterns, paper examples, codecs, hashes, objects, REPL, browser, kVM, kTVM, library, and shell suites |
|
|
12
12
|
| `npm run conformance` | Shared source/object/KIR-P fixtures |
|
|
13
13
|
| `npm run test:wasm` | Wasm runtime/lowering and backend shell integration |
|
|
14
14
|
| `npm run test:llvm` | LLVM runtime/lowering, field-layout regression, shell integration, and shared fixtures |
|
|
15
15
|
| `npm run test:backends` | Both backend suites |
|
|
16
16
|
| `npm --prefix k-vscode test` | Editor grammar and expression-background tests |
|
|
17
17
|
| `node tests/test-paper-examples.mjs` | Publication examples, including canonical hashes and the half adder |
|
|
18
|
-
| `npm run test:package -- /path/to/installed/@fraczak/k` | Packed installation, API, command help, codec pipeline, objects, and
|
|
18
|
+
| `npm run test:package -- /path/to/installed/@fraczak/k` | Packed installation, API, command help, codec pipeline, objects, Wasm, and kTVM |
|
|
19
19
|
|
|
20
20
|
The backend and editor suites are separate commands; `npm test` does not run
|
|
21
21
|
every suite in this table. The paper command is also available as a focused check.
|
|
@@ -42,7 +42,7 @@ cases; shared helpers live outside the discovered directory.
|
|
|
42
42
|
| Wire values and codecs | `test-codecs.mjs`, `test-deep-wire-value.mjs`, `test-structural-values.mjs` |
|
|
43
43
|
| Objects and portable export | `test-k-object.mjs`, `test-kir.mjs`, `test-validate-object.mjs` |
|
|
44
44
|
| Interactive state and browser UI | `test-repl.mjs`, `test-repl-html.mjs`, `test-tree-view.mjs` |
|
|
45
|
-
| Execution layers | `test-kvm.mjs`, `test-kvm-polymorphic.mjs`, `test-
|
|
45
|
+
| Execution layers | `test-kvm.mjs`, `test-kvm-polymorphic.mjs`, `ktvm/test-ktvm.mjs`, `ktvm/test-conformance.mjs`, `ktvm/test-optimize.mjs`, `ktvm/wasm/test-wasm.mjs`, `ktvm/llvm/test-llvm.mjs` |
|
|
46
46
|
| Libraries | `test-generic.mjs`, `test-integer.mjs`, `test-ieee.mjs`, `test-djson.mjs`, `test-lib.mjs`, and example suites (`test-arithmetics.mjs`, `test-poly.mjs`, `test-ieee-arithmetic.mjs`, `test-djson-methods.mjs`) |
|
|
47
47
|
| JSON text parsing | `test-parse-json.mjs`: RFC 8259 grammar, Unicode escapes, binary64 rounding, Wasm, and CLI |
|
|
48
48
|
|
package/tests/test-repl-html.mjs
CHANGED
|
@@ -35,6 +35,7 @@ assert(html.includes("<style>"), "repl.html must contain inlined CSS styles");
|
|
|
35
35
|
assert(html.includes('<script type="module">'), "repl.html must contain inlined module script");
|
|
36
36
|
assert(!html.includes('<script src="http'), "repl.html must NOT contain external remote scripts");
|
|
37
37
|
assert(html.includes("wasm-in-process"), "repl.html must mention wasm-in-process engine");
|
|
38
|
+
assert(html.includes("ktvm-wasm"), "repl.html must mention ktvm-wasm engine");
|
|
38
39
|
assert(html.includes("nat.k"), "repl.html must embed standard examples");
|
|
39
40
|
assert(html.includes("btn-codecs"), "repl.html must contain Codecs button");
|
|
40
41
|
assert(html.includes("codecs-modal"), "repl.html must contain Codecs modal");
|
|
@@ -685,35 +686,78 @@ if (chromiumBin) {
|
|
|
685
686
|
assert.strictEqual(narrowNavbarCheck.hasTiming, false, "Help modal should not contain :timing");
|
|
686
687
|
assert.strictEqual(narrowNavbarCheck.hasCodecDefine, false, "Help modal should not contain :codec define");
|
|
687
688
|
|
|
688
|
-
// 6. Test 3-way engine switching in browser (wasm ->
|
|
689
|
+
// 6. Test 3-way engine switching in browser (wasm -> ktvm -> js -> wasm) and kTVM execution
|
|
689
690
|
const engineCheck = await evaluateAsync(`(async () => {
|
|
691
|
+
const badge = document.getElementById("engine-badge");
|
|
692
|
+
const badgeTag = badge?.tagName;
|
|
690
693
|
const initialEngine = window.kRepl.getEngine();
|
|
691
|
-
await window.kRepl.executeCommand(":engine
|
|
692
|
-
const
|
|
693
|
-
const
|
|
694
|
+
await window.kRepl.executeCommand(":engine ktvm");
|
|
695
|
+
const ktvmEngine = window.kRepl.getEngine();
|
|
696
|
+
const badgeKtvmText = badge?.textContent;
|
|
697
|
+
const badgeKtvmClass = badge?.classList.contains("ktvm-mode");
|
|
698
|
+
|
|
699
|
+
// Execute K expressions on ktvm-wasm directly in the browser!
|
|
700
|
+
await window.kRepl.executeCommand("{} | ok");
|
|
701
|
+
const ktvmSimpleLines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
702
|
+
const ktvmSimpleOut = ktvmSimpleLines[ktvmSimpleLines.length - 1];
|
|
703
|
+
|
|
704
|
+
await window.kRepl.executeCommand("{{}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y} plus");
|
|
705
|
+
const ktvmPlusLines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
706
|
+
const ktvmPlusOut = ktvmPlusLines[ktvmPlusLines.length - 1];
|
|
707
|
+
|
|
708
|
+
await window.kRepl.executeCommand("{}|_|0|1|0|1 nat (gen_list sort)");
|
|
709
|
+
const ktvmSortLines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
710
|
+
const ktvmSortOut = ktvmSortLines[ktvmSortLines.length - 1];
|
|
711
|
+
|
|
694
712
|
await window.kRepl.executeCommand(":engine js");
|
|
695
713
|
const jsEngine = window.kRepl.getEngine();
|
|
696
|
-
const badgeJsText =
|
|
714
|
+
const badgeJsText = badge?.textContent;
|
|
697
715
|
await window.kRepl.executeCommand("() | ok");
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
716
|
+
// Verify switching from js (open-union state.value) -> ktvm works cleanly
|
|
717
|
+
await window.kRepl.executeCommand(":ktvm");
|
|
718
|
+
await window.kRepl.executeCommand("/ok");
|
|
719
|
+
const ktvmFromJsLines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
720
|
+
const ktvmFromJsOut = ktvmFromJsLines[ktvmFromJsLines.length - 1];
|
|
721
|
+
|
|
722
|
+
// Verify badge click cycles ktvm -> js -> wasm -> ktvm -> ...
|
|
723
|
+
badge.click();
|
|
724
|
+
await new Promise(r => setTimeout(r, 80));
|
|
725
|
+
const clickedToJs = window.kRepl.getEngine();
|
|
726
|
+
badge.click();
|
|
727
|
+
await new Promise(r => setTimeout(r, 80));
|
|
728
|
+
const clickedToWasm = window.kRepl.getEngine();
|
|
729
|
+
const badgeWasmText = badge?.textContent;
|
|
701
730
|
return {
|
|
731
|
+
badgeTag,
|
|
702
732
|
initialEngine,
|
|
703
|
-
|
|
733
|
+
ktvmEngine,
|
|
704
734
|
jsEngine,
|
|
705
|
-
|
|
706
|
-
|
|
735
|
+
clickedToJs,
|
|
736
|
+
clickedToWasm,
|
|
737
|
+
badgeKtvmText,
|
|
738
|
+
badgeKtvmClass,
|
|
707
739
|
badgeJsText,
|
|
708
|
-
badgeWasmText
|
|
740
|
+
badgeWasmText,
|
|
741
|
+
ktvmSimpleOut,
|
|
742
|
+
ktvmPlusOut,
|
|
743
|
+
ktvmSortOut,
|
|
744
|
+
ktvmFromJsOut
|
|
709
745
|
};
|
|
710
746
|
})()`);
|
|
747
|
+
assert.strictEqual(engineCheck.badgeTag, "BUTTON", "#engine-badge should be a native <button>");
|
|
711
748
|
assert.strictEqual(engineCheck.initialEngine, "wasm");
|
|
712
|
-
assert.strictEqual(engineCheck.
|
|
713
|
-
assert.strictEqual(engineCheck.
|
|
749
|
+
assert.strictEqual(engineCheck.ktvmEngine, "ktvm");
|
|
750
|
+
assert.strictEqual(engineCheck.badgeKtvmText, "ktvm-wasm");
|
|
751
|
+
assert.strictEqual(engineCheck.badgeKtvmClass, true, "#engine-badge should have .ktvm-mode class");
|
|
752
|
+
assert(engineCheck.ktvmSimpleOut.includes("{}|ok"), `Expected {}|ok from ktvm in browser, got: ${engineCheck.ktvmSimpleOut}`);
|
|
753
|
+
assert(engineCheck.ktvmPlusOut.includes("int.mjs: 15"), `Expected int.mjs: 15 from ktvm plus in browser, got: ${engineCheck.ktvmPlusOut}`);
|
|
754
|
+
assert(engineCheck.ktvmSortOut.includes("int.mjs: [0,1,2,3,4,5,6,7,8,9,10]"), `Expected sorted list from ktvm in browser, got: ${engineCheck.ktvmSortOut}`);
|
|
714
755
|
assert.strictEqual(engineCheck.jsEngine, "js");
|
|
715
756
|
assert.strictEqual(engineCheck.badgeJsText, "js-in-process");
|
|
716
|
-
assert
|
|
757
|
+
assert(engineCheck.ktvmFromJsOut.includes("{}"), `Expected {} after switching js -> ktvm on /ok, got: ${engineCheck.ktvmFromJsOut}`);
|
|
758
|
+
assert.strictEqual(engineCheck.clickedToJs, "js");
|
|
759
|
+
assert.strictEqual(engineCheck.clickedToWasm, "wasm");
|
|
760
|
+
assert.strictEqual(engineCheck.badgeWasmText, "wasm-in-process");
|
|
717
761
|
// 7. Test uploading a file (adds to VFS without auto-loading)
|
|
718
762
|
const uploadCheck = await evaluateAsync(`(async () => {
|
|
719
763
|
const codecCode = \`export default {
|
|
@@ -805,6 +849,19 @@ if (chromiumBin) {
|
|
|
805
849
|
`Expected 'int.mjs: 3' from wasm execution, got: ${wasmLenCheck}`
|
|
806
850
|
);
|
|
807
851
|
|
|
852
|
+
// Test kTVM-Wasm engine with polymorphic/open list len
|
|
853
|
+
const ktvmLenCheck = await evaluateAsync(`(async () => {
|
|
854
|
+
await window.kRepl.executeCommand(":engine ktvm");
|
|
855
|
+
await window.kRepl.executeCommand(":input int.mjs [1,2,3]");
|
|
856
|
+
await window.kRepl.executeCommand("len");
|
|
857
|
+
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
858
|
+
return lines[lines.length - 1];
|
|
859
|
+
})()`);
|
|
860
|
+
assert(
|
|
861
|
+
ktvmLenCheck.includes("int.mjs: 3"),
|
|
862
|
+
`Expected 'int.mjs: 3' from ktvm execution, got: ${ktvmLenCheck}`
|
|
863
|
+
);
|
|
864
|
+
|
|
808
865
|
ws.close();
|
|
809
866
|
console.log(" Browser execution verified successfully!");
|
|
810
867
|
} finally {
|