@fraczak/k 8.7.1 → 8.9.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/CODECS.md +42 -40
- package/DOCS/FILE_FORMATS.md +28 -25
- package/DOCS/GETTING_STARTED.md +10 -15
- package/DOCS/PATTERNS.md +3 -3
- package/DOCS/REPL.md +3 -6
- package/Examples/ieee-arithmetics.k +14 -29
- package/Examples/poly.k +18 -29
- package/README.md +14 -18
- package/backend-api.mjs +1 -3
- package/backends/llvm/src/cli.mjs +1 -2
- package/backends/llvm/tests/integration.sh +2 -6
- package/backends/wasm/tests/integration.sh +5 -10
- package/browser/shims/fs.mjs +2 -6
- package/canonical-pattern.mjs +9 -29
- package/codecs/djson.mjs +2 -3
- package/codecs/int.mjs +66 -14
- package/compiler.mjs +22 -12
- package/harness/suites/poly.mjs +9 -11
- package/index.mjs +119 -50
- package/lib/djson.k +976 -288
- package/lib/generic.k +686 -0
- package/lib/ieee.k +658 -639
- package/lib/integer.k +536 -0
- package/object.mjs +19 -12
- package/objects/README.md +6 -6
- package/package.json +1 -1
- package/scripts/benchmark-idempotency.mjs +16 -17
- package/scripts/benchmark.mjs +39 -29
- package/scripts/build-repl-html.mjs +45 -35
- package/scripts/perf-bigint-compare.mjs +279 -0
- package/scripts/perf-ieee.mjs +1 -5
- package/scripts/perf-int.mjs +12 -27
- package/scripts/perf-multiplication.mjs +8 -9
- package/scripts/perf-poly.mjs +7 -10
- package/scripts/render-benchmark.mjs +1 -1
- package/scripts/run-tests.mjs +4 -2
- package/scripts/test-package.mjs +4 -10
- package/tests/README.md +4 -5
- package/tests/helpers/cli.mjs +30 -7
- package/tests/integration.sh +5 -10
- package/tests/test-arithmetics.mjs +23 -16
- package/tests/test-djson-methods.mjs +16 -25
- package/tests/test-djson.mjs +272 -0
- package/tests/test-generic.mjs +237 -0
- package/tests/test-ieee-arithmetic.mjs +1 -5
- package/tests/test-ieee.mjs +153 -0
- package/tests/test-integer.mjs +264 -0
- package/tests/test-k-object.mjs +12 -18
- package/tests/test-kvm-polymorphic.mjs +6 -7
- package/tests/test-lib.mjs +62 -52
- package/tests/test-library-isolation.mjs +349 -26
- package/tests/test-parse-json.mjs +15 -24
- package/tests/test-poly.mjs +21 -16
- package/tests/test-repl-html.mjs +39 -44
- package/tests/test-repl.mjs +46 -59
- package/tests/test-structural-values.mjs +1 -1
- package/DOCS/book-combined.md +0 -3786
- package/DOCS/dependency-graph.md +0 -144
- package/Examples/arithmetics.k +0 -108
- package/Examples/esc.k +0 -9
- package/lib/arithmetics.k +0 -286
- package/lib/bit.k +0 -68
- package/lib/bits.k +0 -227
- package/lib/btrie.k +0 -187
- package/lib/list.k +0 -49
- package/lib/string.k +0 -588
- package/tests/test-ieee-text.mjs +0 -74
- package/tests/test-karatsuba.mjs +0 -25
package/tests/test-repl-html.mjs
CHANGED
|
@@ -35,7 +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("
|
|
38
|
+
assert(html.includes("nat.k"), "repl.html must embed standard examples");
|
|
39
39
|
assert(html.includes("btn-codecs"), "repl.html must contain Codecs button");
|
|
40
40
|
assert(html.includes("codecs-modal"), "repl.html must contain Codecs modal");
|
|
41
41
|
assert(html.includes("enabled-codecs-grid"), "repl.html must contain enabled codecs grid");
|
|
@@ -150,63 +150,60 @@ if (chromiumBin) {
|
|
|
150
150
|
// Verify VFS curated files
|
|
151
151
|
const vfsList = await evaluateAsync(`window.kRepl.getAllVfsFiles().sort()`);
|
|
152
152
|
const expectedFiles = [
|
|
153
|
-
"arithmetics.k",
|
|
154
|
-
"bit.k",
|
|
155
|
-
"bits.k",
|
|
156
|
-
"btrie.k",
|
|
157
153
|
"core.k",
|
|
158
154
|
"djson.k",
|
|
159
155
|
"djson.mjs",
|
|
160
|
-
"
|
|
156
|
+
"generic.k",
|
|
161
157
|
"ieee-arithmetics.k",
|
|
158
|
+
"ieee.k",
|
|
162
159
|
"ieee.mjs",
|
|
163
160
|
"int.mjs",
|
|
161
|
+
"integer.k",
|
|
164
162
|
"json.mjs",
|
|
165
|
-
"
|
|
163
|
+
"nat.k",
|
|
166
164
|
"poly.k",
|
|
167
|
-
"string.k",
|
|
168
165
|
"unit.mjs",
|
|
169
166
|
"utf8.mjs"
|
|
170
167
|
].sort();
|
|
171
168
|
assert.deepStrictEqual(vfsList, expectedFiles, `getAllVfsFiles() must match curated files list, got: ${JSON.stringify(vfsList)}`);
|
|
172
169
|
|
|
173
|
-
// Test :load
|
|
174
|
-
const
|
|
175
|
-
await window.kRepl.executeCommand(":load
|
|
176
|
-
await window.kRepl.executeCommand(":load bits.k");
|
|
177
|
-
await window.kRepl.executeCommand(":load arithmetics.k");
|
|
170
|
+
// Test :load Examples/nat.k (then :reset so 0 alias does not linger)
|
|
171
|
+
const loadNatOut = await evaluateAsync(`(async () => {
|
|
172
|
+
await window.kRepl.executeCommand(":load Examples/nat.k");
|
|
178
173
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
174
|
+
await window.kRepl.executeCommand(":reset");
|
|
179
175
|
return lines[lines.length - 1];
|
|
180
176
|
})()`);
|
|
181
|
-
assert(
|
|
177
|
+
assert(loadNatOut.includes("loaded Examples/nat.k"), `Expected loaded Examples/nat.k, got: ${loadNatOut}`);
|
|
182
178
|
|
|
183
|
-
// Test :load
|
|
184
|
-
const
|
|
185
|
-
await window.kRepl.executeCommand(":load
|
|
179
|
+
// Test :load core.k, integer.k
|
|
180
|
+
const loadOut = await evaluateAsync(`(async () => {
|
|
181
|
+
await window.kRepl.executeCommand(":load core.k");
|
|
182
|
+
await window.kRepl.executeCommand(":load integer.k");
|
|
186
183
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
187
184
|
return lines[lines.length - 1];
|
|
188
185
|
})()`);
|
|
189
|
-
assert(
|
|
186
|
+
assert(loadOut.includes("loaded integer.k"), `Expected loaded integer.k, got: ${loadOut}`);
|
|
190
187
|
|
|
191
|
-
// Test evaluating {1
|
|
192
|
-
const
|
|
193
|
-
await window.kRepl.executeCommand("{1
|
|
188
|
+
// Test evaluating {1 x, 1 y} times
|
|
189
|
+
const timesVal = await evaluateAsync(`(async () => {
|
|
190
|
+
await window.kRepl.executeCommand("{1 x, 1 y} times");
|
|
194
191
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
195
192
|
return lines[lines.length - 1];
|
|
196
193
|
})()`);
|
|
197
|
-
assert(
|
|
194
|
+
assert(timesVal.includes("{}|_|1|+"), `Expected {}|_|1|+ in output, got: ${timesVal}`);
|
|
198
195
|
|
|
199
|
-
// Test evaluating 10
|
|
196
|
+
// Test evaluating {}|_|0|1|0|1 (bits 10)
|
|
200
197
|
const valOut = await evaluateAsync(`(async () => {
|
|
201
|
-
await window.kRepl.executeCommand("
|
|
198
|
+
await window.kRepl.executeCommand("{}|_|0|1|0|1");
|
|
202
199
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
203
200
|
return lines[lines.length - 1];
|
|
204
201
|
})()`);
|
|
205
|
-
assert(valOut.includes("{}|_|0|1|0|1"), `Expected 10 in output, got: ${valOut}`);
|
|
202
|
+
assert(valOut.includes("{}|_|0|1|0|1"), `Expected 10 bits in output, got: ${valOut}`);
|
|
206
203
|
|
|
207
|
-
// Test {
|
|
204
|
+
// Test {{}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y} plus
|
|
208
205
|
const plusOut = await evaluateAsync(`(async () => {
|
|
209
|
-
await window.kRepl.executeCommand("{
|
|
206
|
+
await window.kRepl.executeCommand("{{}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y} plus");
|
|
210
207
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
211
208
|
return lines[lines.length - 1];
|
|
212
209
|
})()`);
|
|
@@ -232,9 +229,9 @@ if (chromiumBin) {
|
|
|
232
229
|
const badgeCount = await evaluateAsync(`document.getElementById("codecs-count-badge")?.textContent`);
|
|
233
230
|
assert.strictEqual(badgeCount, "1", "Codecs badge count should be 1 after loading int.mjs codec");
|
|
234
231
|
|
|
235
|
-
// Test evaluating
|
|
232
|
+
// Test evaluating {}|_|0|1|0|1 nat with int.mjs codec active -> output should format using int.mjs serializer
|
|
236
233
|
const formattedVal = await evaluateAsync(`(async () => {
|
|
237
|
-
await window.kRepl.executeCommand("
|
|
234
|
+
await window.kRepl.executeCommand("{}|_|0|1|0|1 nat");
|
|
238
235
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
239
236
|
return lines[lines.length - 1];
|
|
240
237
|
})()`);
|
|
@@ -334,10 +331,10 @@ if (chromiumBin) {
|
|
|
334
331
|
|
|
335
332
|
// Test JSON codec with float64 in browser: :input json.mjs then {"a":"Woj","n":123}
|
|
336
333
|
await evaluateAsync(`(async () => {
|
|
337
|
-
await window.kRepl.executeCommand(":load
|
|
338
|
-
await window.kRepl.executeCommand(":load
|
|
339
|
-
await window.kRepl.executeCommand(":load string.k");
|
|
334
|
+
await window.kRepl.executeCommand(":load core.k");
|
|
335
|
+
await window.kRepl.executeCommand(":load generic.k");
|
|
340
336
|
await window.kRepl.executeCommand(":load ieee.k");
|
|
337
|
+
await window.kRepl.executeCommand(":load djson.k");
|
|
341
338
|
await window.kRepl.executeCommand(":codec load json.mjs");
|
|
342
339
|
await window.kRepl.executeCommand(":input json.mjs");
|
|
343
340
|
})()`);
|
|
@@ -398,16 +395,14 @@ if (chromiumBin) {
|
|
|
398
395
|
})()`);
|
|
399
396
|
assert(ieeeResult.includes('ieee.mjs: 3.14159'), `Expected ieee.mjs: 3.14159, got: ${ieeeResult}`);
|
|
400
397
|
|
|
401
|
-
// Test :load poly.k and evaluate '
|
|
398
|
+
// Test :load poly.k and evaluate '{}|_|0|1|0|1 nat (gen_list sort)' in WASM mode
|
|
402
399
|
const sortListResult = await evaluateAsync(`(async () => {
|
|
403
400
|
await window.kRepl.executeCommand(":reset");
|
|
404
|
-
await window.kRepl.executeCommand(":load
|
|
405
|
-
await window.kRepl.executeCommand(":load
|
|
406
|
-
await window.kRepl.executeCommand(":load arithmetics.k");
|
|
407
|
-
await window.kRepl.executeCommand(":load list.k");
|
|
401
|
+
await window.kRepl.executeCommand(":load core.k");
|
|
402
|
+
await window.kRepl.executeCommand(":load integer.k");
|
|
408
403
|
await window.kRepl.executeCommand(":load poly.k");
|
|
409
404
|
await window.kRepl.executeCommand(":codec load int.mjs");
|
|
410
|
-
await window.kRepl.executeCommand("
|
|
405
|
+
await window.kRepl.executeCommand("{}|_|0|1|0|1 nat (gen_list sort)");
|
|
411
406
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
412
407
|
return lines[lines.length - 1];
|
|
413
408
|
})()`);
|
|
@@ -415,7 +410,7 @@ if (chromiumBin) {
|
|
|
415
410
|
|
|
416
411
|
// Test deep tail-loop list generation and compaction (10,000 elements) in browser WASM mode
|
|
417
412
|
const deepWasmResult = await evaluateAsync(`(async () => {
|
|
418
|
-
await window.kRepl.executeCommand("{{{
|
|
413
|
+
await window.kRepl.executeCommand("ten = {}|_|0|1|0|1 nat; {{{ten x, ten y} times x, ten y} times x, ten y} times (gen_list car)");
|
|
419
414
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
|
420
415
|
return lines[lines.length - 1];
|
|
421
416
|
})()`);
|
|
@@ -510,12 +505,12 @@ if (chromiumBin) {
|
|
|
510
505
|
assert.strictEqual(treeCheck.unfoldedHasE, true, "Unfolding level 4 should lazily populate its children");
|
|
511
506
|
|
|
512
507
|
// 2. Test recursive pattern tree with cycle detection
|
|
513
|
-
await evaluateAsync(`window.kRepl.executeCommand("
|
|
508
|
+
await evaluateAsync(`window.kRepl.executeCommand("{}|_|0|1|0|1 ?bits[]")`);
|
|
514
509
|
const patCycleCheck = await evaluateAsync(`(() => {
|
|
515
510
|
const entries = document.querySelectorAll(".terminal-entry");
|
|
516
511
|
const lastEntry = entries[entries.length - 1];
|
|
517
512
|
const patSection = lastEntry.querySelector(".k-tree-pat-section");
|
|
518
|
-
if (!patSection) return { error: "No pattern section for
|
|
513
|
+
if (!patSection) return { error: "No pattern section for {}|_|0|1|0|1 ?bits[]" };
|
|
519
514
|
|
|
520
515
|
const cycleBadges = patSection.querySelectorAll(".k-badge-cycle");
|
|
521
516
|
const varDefs = patSection.querySelectorAll(".k-pat-vardef");
|
|
@@ -529,13 +524,13 @@ if (chromiumBin) {
|
|
|
529
524
|
assert.strictEqual(patCycleCheck.hasCycleBadge, true, "Pattern tree for recursive type should have cycle badge");
|
|
530
525
|
assert.strictEqual(patCycleCheck.hasVarDef, true, "Pattern tree for recursive type should have variable definition (=X0)");
|
|
531
526
|
|
|
532
|
-
// 3. Test variant chain depth limits and Expand All / Collapse All on
|
|
527
|
+
// 3. Test variant chain depth limits and Expand All / Collapse All on {}|_|0|1|0|1
|
|
533
528
|
const variantDepthAndActionsCheck = await evaluateAsync(`(() => {
|
|
534
529
|
const entries = document.querySelectorAll(".terminal-entry");
|
|
535
530
|
const lastEntry = entries[entries.length - 1];
|
|
536
531
|
const valSection = lastEntry.querySelector(".k-tree-value-section");
|
|
537
532
|
|
|
538
|
-
// Hierarchy for
|
|
533
|
+
// Hierarchy for {}|_|0|1|0|1 (variant chain: 1 -> 0 -> 1 -> 0 -> _)
|
|
539
534
|
const v1 = valSection?.querySelector(".k-tree-section-body > .k-tree-node.k-tree-variant");
|
|
540
535
|
const v2 = v1?.querySelector(".k-tree-children .k-tree-node.k-tree-variant");
|
|
541
536
|
const v3 = v2?.querySelector(".k-tree-children .k-tree-node.k-tree-variant");
|
|
@@ -799,7 +794,7 @@ if (chromiumBin) {
|
|
|
799
794
|
const wasmLenCheck = await evaluateAsync(`(async () => {
|
|
800
795
|
await window.kRepl.executeCommand(":engine wasm");
|
|
801
796
|
await window.kRepl.executeCommand(":codec load int.mjs");
|
|
802
|
-
await window.kRepl.executeCommand("len = {()list,0
|
|
797
|
+
await window.kRepl.executeCommand("len = {()list,0 nat len} len_; len_ = ?X <{.list/nil if, .len then} .then, {.list/cons.cdr list, .len inc len} ?X len_ >;");
|
|
803
798
|
await window.kRepl.executeCommand(":input int.mjs [1,2,3]");
|
|
804
799
|
await window.kRepl.executeCommand("len");
|
|
805
800
|
const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
|
package/tests/test-repl.mjs
CHANGED
|
@@ -309,10 +309,9 @@ assert.equal(tcoState.value.toJSON(), "zero");
|
|
|
309
309
|
|
|
310
310
|
// Verify loading library and evaluating constant/recursive relation from library
|
|
311
311
|
const arithState = createState();
|
|
312
|
-
await evaluateInput(":load
|
|
313
|
-
await evaluateInput(":load lib/
|
|
314
|
-
output
|
|
315
|
-
assert.equal(output[0], "loaded lib/arithmetics.k");
|
|
312
|
+
await evaluateInput(":load core.k", arithState);
|
|
313
|
+
output = await evaluateInput(":load lib/integer.k", arithState);
|
|
314
|
+
assert.equal(output[0], "loaded lib/integer.k");
|
|
316
315
|
output = await evaluateInput(":pat bits", arithState);
|
|
317
316
|
assert.equal(
|
|
318
317
|
output[0],
|
|
@@ -325,9 +324,9 @@ assert.equal(
|
|
|
325
324
|
"int[] = <<X0 0, X0 1, {} _>=X0 +, X0 ->; -- " +
|
|
326
325
|
"@Nws3vysWqC9PznraTP4kWPp44Rd77NAqrx9dgbtHAjGA[]"
|
|
327
326
|
);
|
|
328
|
-
output = await evaluateInput("
|
|
329
|
-
assert.match(output[0], /^\{\}\|_\|0\|1\|0\|1
|
|
330
|
-
output = await evaluateInput("{
|
|
327
|
+
output = await evaluateInput("{}|_|0|1|0|1 nat", arithState);
|
|
328
|
+
assert.match(output[0], /^\{\}\|_\|0\|1\|0\|1\|\+/);
|
|
329
|
+
output = await evaluateInput("{{}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y} plus", arithState);
|
|
331
330
|
assert.match(output[0], /^\{\}\|_\|1\|1\|1\|1\|\+/);
|
|
332
331
|
|
|
333
332
|
// Verify codecs loading, listing, and unloading
|
|
@@ -385,9 +384,8 @@ assert.match(output[0], /^\{\}\|a/);
|
|
|
385
384
|
|
|
386
385
|
// Explicit loading of dependencies and codec testing (no auto-loading)
|
|
387
386
|
const intState = createState();
|
|
388
|
-
await evaluateInput(":load
|
|
389
|
-
await evaluateInput(":load lib/
|
|
390
|
-
await evaluateInput(":load lib/arithmetics.k", intState);
|
|
387
|
+
await evaluateInput(":load core.k", intState);
|
|
388
|
+
await evaluateInput(":load lib/integer.k", intState);
|
|
391
389
|
output = await evaluateInput(":codec load ./codecs/int.mjs", intState);
|
|
392
390
|
assert.match(output[0], /^loaded codec int\.mjs/);
|
|
393
391
|
output = await evaluateInput(":input int.mjs", intState);
|
|
@@ -406,7 +404,7 @@ output = await evaluateInput("test utf8", utf8AutoState);
|
|
|
406
404
|
assert.match(output[0], /utf8\.mjs: test utf8/);
|
|
407
405
|
|
|
408
406
|
const ieeeAutoState = createState();
|
|
409
|
-
for (const file of ["
|
|
407
|
+
for (const file of ["core.k", "lib/ieee.k"]) {
|
|
410
408
|
await evaluateInput(`:load ${file}`, ieeeAutoState);
|
|
411
409
|
}
|
|
412
410
|
output = await evaluateInput(":codec load ./codecs/ieee.mjs", ieeeAutoState);
|
|
@@ -416,7 +414,7 @@ output = await evaluateInput(":input ieee.mjs 1.5", ieeeAutoState);
|
|
|
416
414
|
assert.match(output[0], /ieee\.mjs: 1\.5/);
|
|
417
415
|
|
|
418
416
|
const jsonInputState = createState();
|
|
419
|
-
for (const file of ["
|
|
417
|
+
for (const file of ["core.k", "lib/generic.k", "lib/ieee.k", "lib/djson.k"]) {
|
|
420
418
|
await evaluateInput(`:load ${file}`, jsonInputState);
|
|
421
419
|
}
|
|
422
420
|
await evaluateInput(":codec load ./codecs/json.mjs", jsonInputState);
|
|
@@ -475,7 +473,7 @@ assert.equal(promptForState(unitState), "unit.mjs> ");
|
|
|
475
473
|
output = await evaluateInput("{}", unitState);
|
|
476
474
|
assert.match(output[0], /unit\.mjs: \{\}/);
|
|
477
475
|
|
|
478
|
-
// Verify that poly.k does NOT auto-load
|
|
476
|
+
// Verify that poly.k does NOT auto-load lib/integer.k (no autohooks)
|
|
479
477
|
const polyFreshState = createState();
|
|
480
478
|
await assert.rejects(
|
|
481
479
|
() => evaluateInput(":load Examples/poly.k", polyFreshState),
|
|
@@ -484,7 +482,7 @@ await assert.rejects(
|
|
|
484
482
|
|
|
485
483
|
// Explicitly loading dependencies then poly.k succeeds
|
|
486
484
|
const polyExplicitState = createState();
|
|
487
|
-
for (const file of ["
|
|
485
|
+
for (const file of ["core.k", "lib/integer.k"]) {
|
|
488
486
|
await evaluateInput(`:load ${file}`, polyExplicitState);
|
|
489
487
|
}
|
|
490
488
|
output = await evaluateInput(
|
|
@@ -498,7 +496,7 @@ assert.ok(
|
|
|
498
496
|
);
|
|
499
497
|
assert.ok(
|
|
500
498
|
polyExplicitState.relAliases.int,
|
|
501
|
-
"
|
|
499
|
+
"integer int loaded"
|
|
502
500
|
);
|
|
503
501
|
|
|
504
502
|
// Verify timing reporting is always on and reflects active engine
|
|
@@ -569,11 +567,10 @@ output = await evaluateInput("not = </true | false, /false | true >;\n{} | true
|
|
|
569
567
|
assert.match(output[0], /^\{\}\|false/);
|
|
570
568
|
assert.match(output[1], /\(js\)/);
|
|
571
569
|
|
|
572
|
-
await evaluateInput(":load
|
|
573
|
-
await evaluateInput(":load lib/
|
|
574
|
-
output
|
|
575
|
-
|
|
576
|
-
output = await evaluateInput("{ 10 int x, 5 int y } plus", jsState);
|
|
570
|
+
await evaluateInput(":load core.k", jsState);
|
|
571
|
+
output = await evaluateInput(":load lib/integer.k", jsState);
|
|
572
|
+
assert.equal(output[0], "loaded lib/integer.k");
|
|
573
|
+
output = await evaluateInput("{ {}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y } plus", jsState);
|
|
577
574
|
assert.match(output[0], /^\{\}\|_\|1\|1\|1\|1\|\+/);
|
|
578
575
|
assert.match(output[1], /\(js\)/);
|
|
579
576
|
|
|
@@ -595,19 +592,17 @@ output = await evaluateInput(
|
|
|
595
592
|
assert.match(output[0], /^\{\}\|false/);
|
|
596
593
|
assert.match(output[1], /\(pkir\)/);
|
|
597
594
|
|
|
598
|
-
await evaluateInput(":load
|
|
599
|
-
await evaluateInput(":load lib/
|
|
600
|
-
output
|
|
601
|
-
|
|
602
|
-
output = await evaluateInput("{ 10 int x, 5 int y } plus", pkirState);
|
|
595
|
+
await evaluateInput(":load core.k", pkirState);
|
|
596
|
+
output = await evaluateInput(":load lib/integer.k", pkirState);
|
|
597
|
+
assert.equal(output[0], "loaded lib/integer.k");
|
|
598
|
+
output = await evaluateInput("{ {}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y } plus", pkirState);
|
|
603
599
|
assert.match(output[0], /^\{\}\|_\|1\|1\|1\|1\|\+/);
|
|
604
600
|
assert.match(output[1], /\(pkir\)/);
|
|
605
601
|
|
|
606
602
|
// Verify open product projection in wasm engine
|
|
607
603
|
const wasmListState = createState({ engine: "wasm" });
|
|
608
|
-
await evaluateInput(":load
|
|
609
|
-
await evaluateInput(":load lib/
|
|
610
|
-
await evaluateInput(":load lib/arithmetics.k", wasmListState);
|
|
604
|
+
await evaluateInput(":load core.k", wasmListState);
|
|
605
|
+
await evaluateInput(":load lib/integer.k", wasmListState);
|
|
611
606
|
await evaluateInput(":codec load codecs/int.mjs", wasmListState);
|
|
612
607
|
await evaluateInput("len = {()list,0 int len} len_; len_ = ?X <{.list/nil if, .len then} .then, {.list/cons.cdr list, .len inc len} ?X len_ >;", wasmListState);
|
|
613
608
|
await evaluateInput(":input int.mjs [3,3,3]", wasmListState);
|
|
@@ -626,10 +621,9 @@ assert.equal(output[0], "output limit set to 40");
|
|
|
626
621
|
output = await evaluateInput(":limit", limitState);
|
|
627
622
|
assert.equal(output[0], "Current output limit: 40");
|
|
628
623
|
|
|
629
|
-
await evaluateInput(":load
|
|
630
|
-
await evaluateInput(":load lib/
|
|
631
|
-
output = await evaluateInput("
|
|
632
|
-
output = await evaluateInput("{ 10 int x, 5 int y } plus", limitState);
|
|
624
|
+
await evaluateInput(":load core.k", limitState);
|
|
625
|
+
output = await evaluateInput(":load lib/integer.k", limitState);
|
|
626
|
+
output = await evaluateInput("{ {}|_|0|1|0|1 nat x, {}|_|1|0|1 nat y } plus", limitState);
|
|
633
627
|
assert(output[0].includes("..."));
|
|
634
628
|
assert(output[0].length <= 80);
|
|
635
629
|
|
|
@@ -640,7 +634,7 @@ assert.equal(output[0], "Current output limit: none");
|
|
|
640
634
|
|
|
641
635
|
// Verify lib/djson.k (json?, get, nth, set, del)
|
|
642
636
|
const djsonKState = createState({ engine: "wasm" });
|
|
643
|
-
for (const file of ["
|
|
637
|
+
for (const file of ["core.k", "lib/generic.k", "lib/ieee.k"]) {
|
|
644
638
|
await evaluateInput(`:load ${file}`, djsonKState);
|
|
645
639
|
}
|
|
646
640
|
output = await evaluateInput(":load lib/djson.k", djsonKState);
|
|
@@ -651,8 +645,8 @@ await evaluateInput(
|
|
|
651
645
|
djsonKState
|
|
652
646
|
);
|
|
653
647
|
output = await evaluateInput(
|
|
654
|
-
"{{
|
|
655
|
-
"{1 index, () json} nth json} get",
|
|
648
|
+
"{{{}|_ index, () json} nth /string key, " +
|
|
649
|
+
"{{}|_|1 index, () json} nth json} get",
|
|
656
650
|
djsonKState
|
|
657
651
|
);
|
|
658
652
|
assert.match(output[0], /djson\.mjs: 30/);
|
|
@@ -662,8 +656,8 @@ await evaluateInput(
|
|
|
662
656
|
djsonKState
|
|
663
657
|
);
|
|
664
658
|
output = await evaluateInput(
|
|
665
|
-
"{{
|
|
666
|
-
"{1 index, () json} nth json} del",
|
|
659
|
+
"{{{}|_ index, () json} nth /string key, " +
|
|
660
|
+
"{{}|_|1 index, () json} nth json} del",
|
|
667
661
|
djsonKState
|
|
668
662
|
);
|
|
669
663
|
assert.match(output[0], /djson\.mjs: \{"name":"Alice"\}/);
|
|
@@ -781,10 +775,9 @@ assert.equal(
|
|
|
781
775
|
"@KqTBNkznjWWwync2Mm94XjCez63neJBJtgYcJJEE5kEm[A, B]"
|
|
782
776
|
);
|
|
783
777
|
|
|
784
|
-
await evaluateInput(":load
|
|
785
|
-
await evaluateInput(":load lib/
|
|
786
|
-
output
|
|
787
|
-
assert.equal(output[0], "loaded lib/list.k");
|
|
778
|
+
await evaluateInput(":load core.k", patState);
|
|
779
|
+
output = await evaluateInput(":load lib/generic.k", patState);
|
|
780
|
+
assert.equal(output[0], "loaded lib/generic.k");
|
|
788
781
|
output = await evaluateInput(":patterns", patState);
|
|
789
782
|
assert(output[0].includes("bit[] = @Mjusy"));
|
|
790
783
|
assert(output[0].includes("list[X] = @JagVex"));
|
|
@@ -995,40 +988,34 @@ assert.equal(
|
|
|
995
988
|
output[0],
|
|
996
989
|
"reverse = ?<{(...) car, X0 cdr} cons, {} nil>=X0 " +
|
|
997
990
|
"{() x, nil y} rev_append ?X0; " +
|
|
998
|
-
"-- @
|
|
991
|
+
"-- @ekNJ8QvXWXi9J83HXXA7XrtgWjnZ4VYYVUxKRRkQV942"
|
|
999
992
|
);
|
|
1000
993
|
await evaluateInput(":max-pat-length 30", polyExplicitState);
|
|
1001
|
-
|
|
1002
|
-
assert.equal(
|
|
1003
|
-
output[0],
|
|
1004
|
-
"car = ?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X0] " +
|
|
1005
|
-
"/cons .car ?X0; " +
|
|
1006
|
-
"-- @zjRvxpKqktzNfR3VYSqq4bF9XLQTnCp4MpP82JLmysaP"
|
|
1007
|
-
);
|
|
994
|
+
await evaluateInput(":max-pat-length 30", djsonKState);
|
|
1008
995
|
output = await evaluateInput(":rel reverse", polyExplicitState);
|
|
1009
996
|
assert.equal(
|
|
1010
997
|
output[0],
|
|
1011
998
|
"reverse = ?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X0] " +
|
|
1012
999
|
"{() x, nil y} rev_append " +
|
|
1013
1000
|
"?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X0]; " +
|
|
1014
|
-
"-- @
|
|
1001
|
+
"-- @ekNJ8QvXWXi9J83HXXA7XrtgWjnZ4VYYVUxKRRkQV942"
|
|
1015
1002
|
);
|
|
1016
|
-
output = await evaluateInput(":rel nil?",
|
|
1003
|
+
output = await evaluateInput(":rel nil?", djsonKState);
|
|
1017
1004
|
assert.equal(
|
|
1018
1005
|
output[0],
|
|
1019
|
-
"nil? =
|
|
1020
|
-
"
|
|
1021
|
-
"
|
|
1022
|
-
"-- @
|
|
1006
|
+
"nil? = ?<(...) nil, ...>=X0 " +
|
|
1007
|
+
"/nil |nil " +
|
|
1008
|
+
"?X0; " +
|
|
1009
|
+
"-- @5Qr8JE4UUR2XhasfEd7cyV4SFwTpQYvzPdRWDLeJKy5e"
|
|
1023
1010
|
);
|
|
1024
|
-
output = await evaluateInput(":rel
|
|
1011
|
+
output = await evaluateInput(":rel parse_json", djsonKState);
|
|
1025
1012
|
assert.equal(
|
|
1026
1013
|
output[0],
|
|
1027
|
-
"
|
|
1014
|
+
"parse_json = " +
|
|
1028
1015
|
"?@Pt3MwQwzUPxQKu58zXR3qUBHWTzfycx5bSZGzcK6EZQK[] " +
|
|
1029
|
-
"
|
|
1016
|
+
"dj_json_value {.rest dj_ws /nil _, .value value} .value " +
|
|
1030
1017
|
"?@P5C7TQKTSPnFUkYkYzTudJamxAQ3T3fHbvZNqwWMfAA2[]; " +
|
|
1031
|
-
"-- @
|
|
1018
|
+
"-- @3dPQGT29U9k4zMc8WizAimZtrhb6BHtY3UZEHtq7FPwN"
|
|
1032
1019
|
);
|
|
1033
1020
|
const shortThresholdState = createState();
|
|
1034
1021
|
output = await evaluateInput(":max-pat-length", shortThresholdState);
|
|
@@ -34,7 +34,7 @@ const listWire = encodeToWire(parsedList, INT_LIST_PATTERN);
|
|
|
34
34
|
const decodedList = decodeWire(listWire).value;
|
|
35
35
|
assert.equal(
|
|
36
36
|
valueWithEnvelopeToK(decodedList),
|
|
37
|
-
"{{}|_
|
|
37
|
+
"{{}|_|+ car, {{}|_|1|+ car, {{}|_|0|1|+ car, {}|nil cdr}|cons cdr}|cons cdr}|cons ?<{<<X1 0, X1 1, {}=X2 _>=X1 +, X1 -> car, X0 cdr} cons, X2 nil>=X0"
|
|
38
38
|
);
|
|
39
39
|
assert.equal(printInt(decodedList), "[0,1,2]");
|
|
40
40
|
|