@fraczak/k 8.6.0 → 8.7.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 +44 -0
- package/DOCS/CODECS.md +20 -14
- package/DOCS/FILE_FORMATS.md +79 -12
- package/DOCS/GETTING_STARTED.md +17 -8
- package/DOCS/PATTERNS.md +17 -0
- package/DOCS/REPL.md +15 -8
- package/Examples/arithmetics.k +81 -468
- package/Examples/ieee-arithmetics.k +37 -33
- package/Examples/poly.k +107 -104
- package/README.md +19 -11
- package/backend-api.mjs +3 -1
- package/backends/llvm/README.md +1 -1
- package/backends/llvm/bin/k-llvm-build.mjs +5 -5
- package/backends/llvm/bin/k-llvm-compile.mjs +4 -4
- package/backends/llvm/bin/k-llvm.mjs +6 -6
- package/backends/llvm/src/cli.mjs +17 -12
- package/backends/llvm/tests/integration.sh +4 -1
- package/backends/wasm/README.md +3 -3
- package/backends/wasm/bin/k-wasm-compile.mjs +4 -4
- package/backends/wasm/bin/k-wasm.mjs +4 -4
- package/backends/wasm/src/cli.mjs +12 -10
- package/backends/wasm/src/wasm.mjs +6 -2
- package/backends/wasm/tests/integration.sh +8 -3
- package/browser/shims/fs.mjs +19 -3
- package/canonical-pattern.mjs +351 -82
- package/core.k +2 -1
- package/harness/suites/poly.mjs +14 -30
- package/k.mjs +17 -13
- package/kvm.mjs +13 -9
- package/lib/arithmetics.k +287 -0
- package/lib/bit.k +68 -0
- package/lib/bits.k +221 -0
- package/lib/btrie.k +187 -0
- package/lib/djson.k +326 -0
- package/lib/ieee.k +709 -0
- package/lib/list.k +49 -0
- package/lib/string.k +588 -0
- package/named-patterns.mjs +2 -2
- package/object.mjs +52 -10
- package/objects/README.md +10 -3
- package/objects/compile.mjs +10 -8
- package/package.json +1 -1
- package/repl.mjs +227 -22
- package/scripts/benchmark-idempotency.mjs +22 -15
- package/scripts/benchmark.mjs +29 -10
- package/scripts/build-repl-html.mjs +49 -14
- package/scripts/perf-ieee.mjs +9 -1
- package/scripts/perf-int.mjs +10 -17
- package/scripts/perf-multiplication.mjs +9 -15
- package/scripts/perf-poly.mjs +16 -32
- package/scripts/run-tests.mjs +2 -2
- package/scripts/test-package.mjs +8 -2
- package/tests/helpers/cli.mjs +11 -3
- package/tests/integration.sh +9 -4
- package/tests/test-arithmetics.mjs +4 -2
- package/tests/test-djson-methods.mjs +16 -12
- package/tests/test-ieee-arithmetic.mjs +11 -3
- package/tests/test-ieee-text.mjs +15 -4
- package/tests/test-k-object.mjs +11 -3
- package/tests/test-karatsuba.mjs +1 -1
- package/tests/test-kvm-polymorphic.mjs +54 -34
- package/tests/test-lib.mjs +115 -0
- package/tests/test-named-patterns.mjs +12 -3
- package/tests/test-parse-json.mjs +33 -13
- package/tests/test-poly.mjs +10 -4
- package/tests/test-repl-html.mjs +18 -7
- package/tests/test-repl.mjs +154 -54
- package/Examples/djson.k +0 -894
- package/Examples/ieee.k +0 -969
- package/Examples/karatsuba-mult.k +0 -227
- package/Examples/list.k +0 -10
|
@@ -223,7 +223,7 @@ console.log("==> Starting Polymorphic kVM & Specialization Tests");
|
|
|
223
223
|
// Test 7: CLI Compilation to Polymorphic .kvm without --input-pattern
|
|
224
224
|
{
|
|
225
225
|
const compileScript = path.join(__dirname, "../objects/compile.mjs");
|
|
226
|
-
const res = spawnSync(process.execPath, [compileScript, "--format", "kvm", "Examples/
|
|
226
|
+
const res = spawnSync(process.execPath, [compileScript, "--format", "kvm", "Examples/nat.k"], {
|
|
227
227
|
cwd: path.join(__dirname, ".."),
|
|
228
228
|
encoding: "utf8"
|
|
229
229
|
});
|
|
@@ -236,41 +236,61 @@ console.log("==> Starting Polymorphic kVM & Specialization Tests");
|
|
|
236
236
|
console.log("Test 7 (CLI Compilation to Polymorphic .kvm): Passed");
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
// Test 8: CLI Compilation with --lib and explicit --
|
|
239
|
+
// Test 8: CLI Compilation with --lib and explicit --use (no auto-export)
|
|
240
240
|
{
|
|
241
241
|
const compileScript = path.join(__dirname, "../objects/compile.mjs");
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
242
|
+
const os = await import("node:os");
|
|
243
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "k-kvm-poly-"));
|
|
244
|
+
try {
|
|
245
|
+
let prevLib = null;
|
|
246
|
+
for (const [idx, src] of ["lib/bit.k", "lib/bits.k", "lib/arithmetics.k"].entries()) {
|
|
247
|
+
const nextLib = path.join(tmpDir, `step-${idx}.klib`);
|
|
248
|
+
const stepRes = spawnSync(process.execPath, [
|
|
249
|
+
compileScript,
|
|
250
|
+
...(prevLib ? ["--lib", prevLib] : []),
|
|
251
|
+
src,
|
|
252
|
+
nextLib
|
|
253
|
+
], {
|
|
254
|
+
cwd: path.join(__dirname, ".."),
|
|
255
|
+
encoding: "utf8"
|
|
256
|
+
});
|
|
257
|
+
assert.equal(stepRes.status, 0, `CLI lib step failed: ${stepRes.stderr}`);
|
|
258
|
+
prevLib = nextLib;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Fails without explicit --use
|
|
262
|
+
const failRes = spawnSync(process.execPath, [
|
|
263
|
+
compileScript,
|
|
264
|
+
"--lib", prevLib,
|
|
265
|
+
"{succ int x,int y}+"
|
|
266
|
+
], {
|
|
267
|
+
cwd: path.join(__dirname, ".."),
|
|
268
|
+
encoding: "utf8"
|
|
269
|
+
});
|
|
270
|
+
assert.notEqual(failRes.status, 0, "Should fail without explicit --use");
|
|
271
|
+
|
|
272
|
+
// Succeeds with explicit --use
|
|
273
|
+
const successRes = spawnSync(process.execPath, [
|
|
274
|
+
compileScript,
|
|
275
|
+
"--lib", prevLib,
|
|
276
|
+
"--use", "plus:+ succ int",
|
|
277
|
+
"--format", "kvm",
|
|
278
|
+
"{succ int x,int y}+"
|
|
279
|
+
], {
|
|
280
|
+
cwd: path.join(__dirname, ".."),
|
|
281
|
+
encoding: "utf8",
|
|
282
|
+
maxBuffer: 10 * 1024 * 1024
|
|
283
|
+
});
|
|
284
|
+
assert.equal(successRes.status, 0, `CLI compile with --use failed: ${successRes.stderr}`);
|
|
285
|
+
const kvm = JSON.parse(successRes.stdout);
|
|
286
|
+
assert.equal(kvm.format, "k-vm");
|
|
287
|
+
assert.equal(kvm.layer, "KVM-P");
|
|
288
|
+
assert.equal(kvm.isPolymorphic, true);
|
|
289
|
+
assert.ok(kvm.functions["__main__"]);
|
|
290
|
+
console.log("Test 8 (CLI Compilation with --lib and explicit --use): Passed");
|
|
291
|
+
} finally {
|
|
292
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
293
|
+
}
|
|
274
294
|
}
|
|
275
295
|
|
|
276
296
|
console.log("==> All Polymorphic kVM Tests Passed Successfully!");
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import k from "../index.mjs";
|
|
4
|
+
import { Value } from "../Value.mjs";
|
|
5
|
+
import { compileLibrary, loadLibrary } from "../object.mjs";
|
|
6
|
+
import { fromJsonValue, toJsonValue } from "../codecs/djson.mjs";
|
|
7
|
+
import { textToStringValue, stringValueToText } from "../codecs/runtime/unicode-string.mjs";
|
|
8
|
+
import { encodeNumberToValue, decodeValueToNumber } from "../codecs/ieee.mjs";
|
|
9
|
+
import { parse as parseInt, parseIntStr, print as printInt } from "../codecs/int.mjs";
|
|
10
|
+
|
|
11
|
+
const libFiles = [
|
|
12
|
+
"lib/bit.k",
|
|
13
|
+
"lib/bits.k",
|
|
14
|
+
"lib/arithmetics.k",
|
|
15
|
+
"lib/list.k",
|
|
16
|
+
"lib/btrie.k",
|
|
17
|
+
"lib/string.k",
|
|
18
|
+
"lib/ieee.k",
|
|
19
|
+
"lib/djson.k"
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const libs = [];
|
|
23
|
+
for (const file of libFiles) {
|
|
24
|
+
const source = readFileSync(new URL(`../${file}`, import.meta.url), "utf8");
|
|
25
|
+
const compiled = loadLibrary(
|
|
26
|
+
compileLibrary(source, { source: file, libraries: libs })
|
|
27
|
+
);
|
|
28
|
+
libs.push(compiled);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const arithLib = libs[2];
|
|
32
|
+
const ieeeLib = libs[6];
|
|
33
|
+
const djsonLib = libs[7];
|
|
34
|
+
|
|
35
|
+
const runArith = (op, value) =>
|
|
36
|
+
k.compile(arithLib.relAlias[op], { libraries: [arithLib] })(value);
|
|
37
|
+
const runIeee = (op, value) =>
|
|
38
|
+
k.compile(ieeeLib.relAlias[op], { libraries: [ieeeLib] })(value);
|
|
39
|
+
const runDjson = (op, value) =>
|
|
40
|
+
k.compile(djsonLib.relAlias[op], { libraries: [djsonLib] })(value);
|
|
41
|
+
|
|
42
|
+
// Verify lib/arithmetics.k integer operations.
|
|
43
|
+
assert.equal(
|
|
44
|
+
printInt(runArith("plus", Value.product({ x: parseIntStr("19"), y: parseIntStr("23") }))),
|
|
45
|
+
"42"
|
|
46
|
+
);
|
|
47
|
+
assert.equal(
|
|
48
|
+
printInt(runArith("times", Value.product({ x: parseIntStr("-6"), y: parseIntStr("7") }))),
|
|
49
|
+
"-42"
|
|
50
|
+
);
|
|
51
|
+
assert.equal(
|
|
52
|
+
printInt(runArith("karatsuba", Value.product({ x: parseIntStr("123456"), y: parseIntStr("-654321") }))),
|
|
53
|
+
String(123456n * -654321n)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Verify lib/ieee.k text parsing, natural conversion, and exact decimal printing.
|
|
57
|
+
for (const num of [0, -0, 1, -1, 3.141592653589793, 1e-10, 1e20, Infinity, -Infinity, NaN]) {
|
|
58
|
+
const val = encodeNumberToValue(num);
|
|
59
|
+
const text = stringValueToText(runIeee("printFloat64", val));
|
|
60
|
+
const parsed = decodeValueToNumber(runIeee("parseFloat64", textToStringValue(text)));
|
|
61
|
+
if (Number.isNaN(num)) {
|
|
62
|
+
assert.ok(Number.isNaN(parsed));
|
|
63
|
+
} else {
|
|
64
|
+
assert.ok(Object.is(parsed, num), `round-trip ${num} via ${text}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const n of [0, 1, 2, 10, 42, 1024, 65535]) {
|
|
69
|
+
const f = decodeValueToNumber(runIeee("natToFloat64", parseInt(String(n)).value));
|
|
70
|
+
assert.equal(f, n);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Verify lib/djson.k methods and RFC 8259 JSON parser.
|
|
74
|
+
function method(op, json, { key, index, val } = {}) {
|
|
75
|
+
const fields = { json: fromJsonValue(json) };
|
|
76
|
+
if (key !== undefined) fields.key = textToStringValue(key);
|
|
77
|
+
if (index !== undefined) fields.index = parseInt(String(index)).value;
|
|
78
|
+
if (val !== undefined) fields.val = fromJsonValue(val);
|
|
79
|
+
return runDjson(op, Value.product(fields));
|
|
80
|
+
}
|
|
81
|
+
const result = (...args) => toJsonValue(method(...args));
|
|
82
|
+
|
|
83
|
+
const doc = { name: "Alice", age: 30, tags: ["developer", "k"] };
|
|
84
|
+
assert.equal(result("get", doc, { key: "name" }), "Alice");
|
|
85
|
+
assert.equal(result("get", doc, { key: "age" }), 30);
|
|
86
|
+
assert.ok(method("has?", doc, { key: "name" }));
|
|
87
|
+
assert.equal(method("has?", doc, { key: "missing" }), undefined);
|
|
88
|
+
|
|
89
|
+
const withCity = result("set", doc, { key: "city", val: "Paris" });
|
|
90
|
+
assert.deepEqual(withCity, { ...doc, city: "Paris" });
|
|
91
|
+
const withoutAge = result("del", withCity, { key: "age" });
|
|
92
|
+
assert.deepEqual(withoutAge, { name: "Alice", tags: doc.tags, city: "Paris" });
|
|
93
|
+
|
|
94
|
+
const arr = [10, 20, 30];
|
|
95
|
+
for (const [index, expected] of arr.entries()) {
|
|
96
|
+
assert.equal(result("nth", arr, { index }), expected);
|
|
97
|
+
}
|
|
98
|
+
assert.ok(method("has_index?", arr, { index: 1 }));
|
|
99
|
+
assert.equal(method("has_index?", arr, { index: 99 }), undefined);
|
|
100
|
+
assert.deepEqual(result("set_nth", arr, { index: 1, val: 99 }), [10, 99, 30]);
|
|
101
|
+
assert.equal(toJsonValue(runDjson("length", fromJsonValue(arr))), 3);
|
|
102
|
+
assert.equal(toJsonValue(runDjson("length", fromJsonValue(doc))), 3);
|
|
103
|
+
assert.equal(toJsonValue(runDjson("length", fromJsonValue("hello"))), 5);
|
|
104
|
+
assert.deepEqual(result("push", arr, { val: 40 }), [10, 20, 30, 40]);
|
|
105
|
+
assert.deepEqual(new Set(toJsonValue(runDjson("keys", fromJsonValue(doc)))), new Set(["name", "age", "tags"]));
|
|
106
|
+
|
|
107
|
+
const sampleJson = JSON.stringify({
|
|
108
|
+
nullVal: null,
|
|
109
|
+
bools: [true, false],
|
|
110
|
+
nums: [0, -0, 42, -12.5, 1e5],
|
|
111
|
+
str: "hello\n\t\"world\"\\/\u0041\uD83D\uDE00",
|
|
112
|
+
empty: [{}, []]
|
|
113
|
+
});
|
|
114
|
+
const parsedJson = toJsonValue(runDjson("parseJson", textToStringValue(sampleJson)));
|
|
115
|
+
assert.deepEqual(parsedJson, JSON.parse(sampleJson));
|
|
@@ -3,7 +3,7 @@ import k from "../index.mjs";
|
|
|
3
3
|
import { Value } from "../Value.mjs";
|
|
4
4
|
import { compileLibrary, extractAliasesFromObject } from "../object.mjs";
|
|
5
5
|
import { validateObjectPayload } from "../objects/validate.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { buildUsePreamble, resolvePatternCanonicalInfo } from "../canonical-pattern.mjs";
|
|
7
7
|
|
|
8
8
|
const BIT = "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg";
|
|
9
9
|
const LIST = "@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe";
|
|
@@ -111,9 +111,11 @@ const aliases = extractAliasesFromObject(library);
|
|
|
111
111
|
for (const expected of [/bit\[\] = @Mjusy/, /list\[X\] = @JagVex/, /pair\[A, B\] = @KqTB/]) {
|
|
112
112
|
assert.match(aliases, expected);
|
|
113
113
|
}
|
|
114
|
-
const preamble =
|
|
114
|
+
const preamble = buildUsePreamble(["bit", "list:my_list"], [library]);
|
|
115
115
|
assert.match(preamble, /bit\[\] = @Mjusy/);
|
|
116
116
|
assert.match(preamble, /my_list\[X\] = @JagVex/);
|
|
117
|
+
const usePreamble = buildUsePreamble(["bit list:my_list"], [library]);
|
|
118
|
+
assert.equal(usePreamble, preamble);
|
|
117
119
|
|
|
118
120
|
{
|
|
119
121
|
const out = evaluate(`
|
|
@@ -130,7 +132,14 @@ assert.equal(evaluate(`
|
|
|
130
132
|
my_list[T] = ${LIST}[T];
|
|
131
133
|
{{}|0 car, {}|nil cdr}|cons ?my_list[my_bit[]]
|
|
132
134
|
`, { libraries: [library] }).tag, "cons");
|
|
133
|
-
|
|
135
|
+
// Unexported pattern templates from a library do not leak into scope:
|
|
136
|
+
assert.throws(
|
|
137
|
+
() => evaluate("is_bit = ?bit[]; ()", { libraries: [library] }),
|
|
138
|
+
/Unknown pattern template 'bit\[\]'/
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const preambleBoth = buildUsePreamble(["bit", "list"], [library]);
|
|
142
|
+
assert.equal(evaluate(preambleBoth + `
|
|
134
143
|
is_bit = ?bit[];
|
|
135
144
|
is_pair = ?${PAIR}[bit[],bit[]];
|
|
136
145
|
is_pair_list = ?list[${PAIR}[bit[],bit[]]];
|
|
@@ -11,11 +11,22 @@ import { textToStringValue } from "../codecs/runtime/unicode-string.mjs";
|
|
|
11
11
|
import { parse as utf8 } from "../codecs/utf8.mjs";
|
|
12
12
|
import { encodeToWire, decodeWire } from "../codecs/runtime/codec-sdk.mjs";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
let ieee = null;
|
|
15
|
+
for (const file of [
|
|
16
|
+
"lib/bit.k",
|
|
17
|
+
"lib/bits.k",
|
|
18
|
+
"lib/list.k",
|
|
19
|
+
"lib/btrie.k",
|
|
20
|
+
"lib/string.k",
|
|
21
|
+
"lib/ieee.k"
|
|
22
|
+
]) {
|
|
23
|
+
ieee = loadLibrary(compileLibrary(readFileSync(new URL(`../${file}`, import.meta.url), "utf8"), {
|
|
24
|
+
source: file,
|
|
25
|
+
libraries: ieee ? [ieee] : []
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const library = loadLibrary(compileLibrary(readFileSync(new URL("../lib/djson.k", import.meta.url), "utf8"), {
|
|
29
|
+
source: "lib/djson.k",
|
|
19
30
|
libraries: [ieee]
|
|
20
31
|
}));
|
|
21
32
|
const wasm = await instantiateWasmArtifact(await compileWasmArtifact(library.relAlias.parseJson, { libraries: [library] }));
|
|
@@ -72,19 +83,28 @@ for (const text of ["1e309", "-1.8e308"]) assert.equal(fast(text), undefined, te
|
|
|
72
83
|
const text = '{"answer":42,"ok":true}';
|
|
73
84
|
const scratch = mkdtempSync(path.join(os.tmpdir(), "k-json-test-"));
|
|
74
85
|
try {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
const chain = [
|
|
87
|
+
"lib/bit.k",
|
|
88
|
+
"lib/bits.k",
|
|
89
|
+
"lib/list.k",
|
|
90
|
+
"lib/btrie.k",
|
|
91
|
+
"lib/string.k",
|
|
92
|
+
"lib/ieee.k",
|
|
93
|
+
"lib/djson.k"
|
|
94
|
+
];
|
|
95
|
+
let prev = null;
|
|
96
|
+
for (let i = 0; i < chain.length; i++) {
|
|
97
|
+
const out = path.join(scratch, `step-${i}.klib`);
|
|
98
|
+
const args = ["objects/compile.mjs", ...(prev ? ["--lib", prev] : []), chain[i], out];
|
|
99
|
+
const built = spawnSync(process.execPath, args, {
|
|
82
100
|
cwd: new URL("..", import.meta.url)
|
|
83
101
|
});
|
|
84
102
|
assert.ifError(built.error);
|
|
85
103
|
assert.equal(built.status, 0, built.stderr.toString());
|
|
104
|
+
prev = out;
|
|
86
105
|
}
|
|
87
|
-
const
|
|
106
|
+
const artifact = prev;
|
|
107
|
+
const cli = spawnSync(process.execPath, ["k.mjs", "--lib", artifact, "--use", "parseJson", "parseJson"], {
|
|
88
108
|
cwd: new URL("..", import.meta.url), input: encodeToWire(utf8(text))
|
|
89
109
|
});
|
|
90
110
|
assert.ifError(cli.error);
|
package/tests/test-poly.mjs
CHANGED
|
@@ -6,14 +6,20 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
import { createState, evaluateInput } from "../backend-api.mjs";
|
|
7
7
|
|
|
8
8
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const polySources = [
|
|
10
|
+
"lib/bit.k",
|
|
11
|
+
"lib/bits.k",
|
|
12
|
+
"lib/arithmetics.k",
|
|
13
|
+
"lib/list.k",
|
|
14
|
+
"Examples/poly.k"
|
|
15
|
+
];
|
|
11
16
|
|
|
12
17
|
console.log("==> Running Polymorphic List Tests (Examples/poly.k)");
|
|
13
18
|
|
|
14
19
|
const state = createState();
|
|
15
|
-
|
|
16
|
-
await evaluateInput(`:load ${
|
|
20
|
+
for (const relPath of polySources) {
|
|
21
|
+
await evaluateInput(`:load ${path.join(root, relPath)}`, state);
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
async function evalK(snippet) {
|
|
19
25
|
const res = await evaluateInput(snippet, state);
|
package/tests/test-repl-html.mjs
CHANGED
|
@@ -151,6 +151,9 @@ if (chromiumBin) {
|
|
|
151
151
|
const vfsList = await evaluateAsync(`window.kRepl.getAllVfsFiles().sort()`);
|
|
152
152
|
const expectedFiles = [
|
|
153
153
|
"arithmetics.k",
|
|
154
|
+
"bit.k",
|
|
155
|
+
"bits.k",
|
|
156
|
+
"btrie.k",
|
|
154
157
|
"core.k",
|
|
155
158
|
"djson.k",
|
|
156
159
|
"djson.mjs",
|
|
@@ -159,28 +162,31 @@ if (chromiumBin) {
|
|
|
159
162
|
"ieee.mjs",
|
|
160
163
|
"int.mjs",
|
|
161
164
|
"json.mjs",
|
|
162
|
-
"
|
|
165
|
+
"list.k",
|
|
163
166
|
"poly.k",
|
|
167
|
+
"string.k",
|
|
164
168
|
"unit.mjs",
|
|
165
169
|
"utf8.mjs"
|
|
166
170
|
].sort();
|
|
167
171
|
assert.deepStrictEqual(vfsList, expectedFiles, `getAllVfsFiles() must match curated files list, got: ${JSON.stringify(vfsList)}`);
|
|
168
172
|
|
|
169
|
-
// Test :load arithmetics.k
|
|
173
|
+
// Test :load bit.k, bits.k, arithmetics.k
|
|
170
174
|
const loadOut = await evaluateAsync(`(async () => {
|
|
175
|
+
await window.kRepl.executeCommand(":load bit.k");
|
|
176
|
+
await window.kRepl.executeCommand(":load bits.k");
|
|
171
177
|
await window.kRepl.executeCommand(":load arithmetics.k");
|
|
172
178
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
173
179
|
return lines[lines.length - 1];
|
|
174
180
|
})()`);
|
|
175
181
|
assert(loadOut.includes("loaded arithmetics.k"), `Expected loaded arithmetics.k, got: ${loadOut}`);
|
|
176
182
|
|
|
177
|
-
// Test :load
|
|
178
|
-
const
|
|
179
|
-
await window.kRepl.executeCommand(":load
|
|
183
|
+
// Test :load Examples/arithmetics.k
|
|
184
|
+
const loadExamplesArithOut = await evaluateAsync(`(async () => {
|
|
185
|
+
await window.kRepl.executeCommand(":load Examples/arithmetics.k");
|
|
180
186
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
181
187
|
return lines[lines.length - 1];
|
|
182
188
|
})()`);
|
|
183
|
-
assert(
|
|
189
|
+
assert(loadExamplesArithOut.includes("loaded Examples/arithmetics.k"), `Expected loaded Examples/arithmetics.k, got: ${loadExamplesArithOut}`);
|
|
184
190
|
|
|
185
191
|
// Test evaluating {1 int x, 1 int y} karatsuba
|
|
186
192
|
const karatsubaVal = await evaluateAsync(`(async () => {
|
|
@@ -328,7 +334,9 @@ if (chromiumBin) {
|
|
|
328
334
|
|
|
329
335
|
// Test JSON codec with float64 in browser: :input json.mjs then {"a":"Woj","n":123}
|
|
330
336
|
await evaluateAsync(`(async () => {
|
|
331
|
-
await window.kRepl.executeCommand(":load
|
|
337
|
+
await window.kRepl.executeCommand(":load list.k");
|
|
338
|
+
await window.kRepl.executeCommand(":load btrie.k");
|
|
339
|
+
await window.kRepl.executeCommand(":load string.k");
|
|
332
340
|
await window.kRepl.executeCommand(":load ieee.k");
|
|
333
341
|
await window.kRepl.executeCommand(":codec load json.mjs");
|
|
334
342
|
await window.kRepl.executeCommand(":input json.mjs");
|
|
@@ -393,7 +401,10 @@ if (chromiumBin) {
|
|
|
393
401
|
// Test :load poly.k and evaluate '10 int (gen_list sort)' in WASM mode
|
|
394
402
|
const sortListResult = await evaluateAsync(`(async () => {
|
|
395
403
|
await window.kRepl.executeCommand(":reset");
|
|
404
|
+
await window.kRepl.executeCommand(":load bit.k");
|
|
405
|
+
await window.kRepl.executeCommand(":load bits.k");
|
|
396
406
|
await window.kRepl.executeCommand(":load arithmetics.k");
|
|
407
|
+
await window.kRepl.executeCommand(":load list.k");
|
|
397
408
|
await window.kRepl.executeCommand(":load poly.k");
|
|
398
409
|
await window.kRepl.executeCommand(":codec load int.mjs");
|
|
399
410
|
await window.kRepl.executeCommand("10 int (gen_list sort)");
|