@fraczak/k 6.10.6 → 7.0.1

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/CLAUDE.md +1 -1
  3. package/DOCS/BIG_PICTURE.md +156 -172
  4. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
  5. package/DOCS/CODEC_ARCHITECTURE.md +2 -2
  6. package/DOCS/DICTIONARY.md +243 -250
  7. package/DOCS/DIVERGENCE_DETECTION.md +0 -1
  8. package/DOCS/FILE_FORMATS.md +5 -5
  9. package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
  10. package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
  11. package/DOCS/PATTERNS.md +17 -17
  12. package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
  13. package/DOCS/REPL.md +9 -19
  14. package/DOCS/TYPE_DERIVATION.md +2 -8
  15. package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
  16. package/DOCS/book/01-introduction.md +8 -11
  17. package/DOCS/book/02-syntax-and-values.md +19 -20
  18. package/DOCS/book/03-types-as-finite-automata.md +42 -43
  19. package/DOCS/book/04-partial-functions-and-composition.md +2 -3
  20. package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
  21. package/DOCS/book/06-values-in-memory.md +10 -10
  22. package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
  23. package/DOCS/book/09-compiler-architecture.md +11 -11
  24. package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
  25. package/DOCS/book/14-canonical-serialization.md +2 -2
  26. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
  27. package/DOCS/book.md +5 -5
  28. package/Examples/arithmetics.k +49 -153
  29. package/Examples/bnat.k +13 -13
  30. package/Examples/byte.k +2 -50
  31. package/Examples/ieee.k +408 -423
  32. package/Examples/karatsuba-mult.k +30 -34
  33. package/Examples/nat.k +5 -6
  34. package/README.md +54 -49
  35. package/TODO.md +13 -18
  36. package/backend-api.mjs +9 -1
  37. package/backends/llvm/scripts/run-tests.mjs +5 -0
  38. package/backends/llvm/src/kvm2llvm.mjs +2 -1
  39. package/backends/llvm/src/llvm.mjs +18 -25
  40. package/backends/llvm/tests/integration.sh +2 -2
  41. package/backends/llvm/tests/test-llvm.mjs +3 -3
  42. package/backends/llvm/tests/test-open-product-misalignment.mjs +140 -0
  43. package/backends/wasm/demo_ieee.mjs +2 -3
  44. package/backends/wasm/runtime.wat +157 -5
  45. package/backends/wasm/src/kvm2wasm.mjs +57 -34
  46. package/backends/wasm/src/wasm.mjs +38 -17
  47. package/backends/wasm/tests/perf-support.mjs +4 -4
  48. package/backends/wasm/tests/test-wasm.mjs +13 -14
  49. package/browser/vfs-data.mjs +12 -12
  50. package/codecs/BINARY_FORMAT.md +4 -4
  51. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
  52. package/codecs/README.md +6 -6
  53. package/codecs/ieee.mjs +15 -11
  54. package/codecs/int.mjs +9 -5
  55. package/codecs/string-codec.mjs +46 -47
  56. package/core.k +123 -95
  57. package/kir.mjs +213 -17
  58. package/object.mjs +0 -7
  59. package/package.json +5 -2
  60. package/parser.jison +2 -41
  61. package/parser.mjs +55 -95
  62. package/pretty.mjs +11 -4
  63. package/repl.mjs +8 -63
  64. package/scripts/build-repl-html.mjs +8 -38
  65. package/tests/code-derivation/blowup.mjs +2 -4
  66. package/tests/code-derivation/bnat.mjs +2 -3
  67. package/tests/code-derivation/dot.mjs +5 -11
  68. package/tests/code-derivation/nat.mjs +2 -2
  69. package/tests/code-derivation/not-not.mjs +6 -6
  70. package/tests/code-derivation/pattern-envelope.mjs +4 -6
  71. package/tests/code-derivation/product.mjs +3 -6
  72. package/tests/code-derivation/rlz.mjs +4 -5
  73. package/tests/test-codecs.mjs +1 -1
  74. package/tests/test-fingerprint.mjs +36 -41
  75. package/tests/test-hash-normalization.mjs +4 -6
  76. package/tests/test-ieee-arithmetic.mjs +6 -7
  77. package/tests/test-k-object.mjs +11 -15
  78. package/tests/test-kir.mjs +0 -1
  79. package/tests/test-kvm-polymorphic.mjs +1 -2
  80. package/tests/test-kvm.mjs +8 -11
  81. package/tests/test-repl-html.mjs +20 -2
  82. package/tests/test-repl.mjs +48 -53
  83. package/tests/test.mjs +2 -3
@@ -194,7 +194,7 @@ console.log("==> Running Product Operations Integration Tests");
194
194
  for (let i = 0; i < N; i++) {
195
195
  const offsetVal = 8 + 4 * N + 4 * i;
196
196
  const val = fieldsMap[keys[i]];
197
- view.setUint32(ptr + 8 + 4 * i, offsetVal, true);
197
+ view.setUint32(ptr + 8 + 4 * i, getTagId(keys[i]), true);
198
198
  view.setUint32(ptr + offsetVal, val, true);
199
199
  }
200
200
  return ptr;
@@ -215,8 +215,8 @@ console.log("==> Running Product Operations Integration Tests");
215
215
  const view = new DataView(exports.memory.buffer);
216
216
  assert.equal(view.getUint32(ptrOut, true), 24, "Product total size should be 24");
217
217
  assert.equal(view.getUint32(ptrOut + 4, true), 2, "Product field count should be 2");
218
- assert.equal(view.getUint32(ptrOut + 8, true), 16, "Offset of first field (x) should be 16");
219
- assert.equal(view.getUint32(ptrOut + 12, true), 20, "Offset of second field (y) should be 20");
218
+ assert.equal(view.getUint32(ptrOut + 8, true), getTagId("x"), "TagId of first field (x)");
219
+ assert.equal(view.getUint32(ptrOut + 12, true), getTagId("y"), "TagId of second field (y)");
220
220
 
221
221
  // The first field value should be the projection of x from ptrIn (101)
222
222
  const valXPtr = view.getUint32(ptrOut + 16, true);
@@ -443,12 +443,12 @@ console.log("==> Running End-to-End Peano Addition & Serialization Tests");
443
443
  const runtimeWat = fs.readFileSync("runtime.wat", "utf8");
444
444
 
445
445
  const script = `
446
- $ nat = < {} 0, nat +1 >;
447
- 0 = {} | 0 $ nat;
448
- inc = | +1 $ nat;
449
- dec = $ nat / +1;
450
- add = $ { nat x, nat y } <
451
- { . x dec x, . y inc y } add,
446
+ nat = ?< {} 0, nat +1 >;
447
+ 0 = {} | 0 nat;
448
+ inc = | +1 nat;
449
+ dec = nat / +1;
450
+ add = ?{ nat x, nat y } = X <
451
+ { . x dec x, . y inc y } ?X add,
452
452
  . y
453
453
  >;
454
454
  ()
@@ -483,8 +483,7 @@ console.log("==> Running End-to-End Peano Addition & Serialization Tests");
483
483
 
484
484
  for (let i = 0; i < N; i++) {
485
485
  const edge = patternNode.edges[i];
486
- const offsetVal = view.getUint32(ptr + 8 + 4 * i, true);
487
- const childPtr = view.getUint32(ptr + offsetVal, true);
486
+ const childPtr = view.getUint32(ptr + 8 + 4 * N + 4 * i, true);
488
487
  productObj[edge.label] = readArenaValue(childPtr, pattern, edge.target);
489
488
  }
490
489
  return Value.product(productObj, pattern);
@@ -530,7 +529,7 @@ console.log("==> Running End-to-End Peano Addition & Serialization Tests");
530
529
 
531
530
  for (let i = 0; i < N; i++) {
532
531
  const offsetVal = 8 + 4 * N + 4 * i;
533
- view.setUint32(ptr + 8 + 4 * i, offsetVal, true);
532
+ view.setUint32(ptr + 8 + 4 * i, getTagId(keys[i]), true);
534
533
  view.setUint32(ptr + offsetVal, childPtrs[i], true);
535
534
  }
536
535
  return ptr;
@@ -580,8 +579,8 @@ console.log("==> Running End-to-End Peano Addition & Serialization Tests");
580
579
  const view = new DataView(exports.memory.buffer);
581
580
  view.setUint32(ptr, 24, true);
582
581
  view.setUint32(ptr + 4, 2, true);
583
- view.setUint32(ptr + 8, 16, true);
584
- view.setUint32(ptr + 12, 20, true);
582
+ view.setUint32(ptr + 8, getTagId("x"), true);
583
+ view.setUint32(ptr + 12, getTagId("y"), true);
585
584
  view.setUint32(ptr + 16, xPtr, true);
586
585
  view.setUint32(ptr + 20, yPtr, true);
587
586
  return ptr;