@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.
Files changed (71) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/DOCS/CODECS.md +20 -14
  3. package/DOCS/FILE_FORMATS.md +79 -12
  4. package/DOCS/GETTING_STARTED.md +17 -8
  5. package/DOCS/PATTERNS.md +17 -0
  6. package/DOCS/REPL.md +15 -8
  7. package/Examples/arithmetics.k +81 -468
  8. package/Examples/ieee-arithmetics.k +37 -33
  9. package/Examples/poly.k +107 -104
  10. package/README.md +19 -11
  11. package/backend-api.mjs +3 -1
  12. package/backends/llvm/README.md +1 -1
  13. package/backends/llvm/bin/k-llvm-build.mjs +5 -5
  14. package/backends/llvm/bin/k-llvm-compile.mjs +4 -4
  15. package/backends/llvm/bin/k-llvm.mjs +6 -6
  16. package/backends/llvm/src/cli.mjs +17 -12
  17. package/backends/llvm/tests/integration.sh +4 -1
  18. package/backends/wasm/README.md +3 -3
  19. package/backends/wasm/bin/k-wasm-compile.mjs +4 -4
  20. package/backends/wasm/bin/k-wasm.mjs +4 -4
  21. package/backends/wasm/src/cli.mjs +12 -10
  22. package/backends/wasm/src/wasm.mjs +6 -2
  23. package/backends/wasm/tests/integration.sh +8 -3
  24. package/browser/shims/fs.mjs +19 -3
  25. package/canonical-pattern.mjs +351 -82
  26. package/core.k +2 -1
  27. package/harness/suites/poly.mjs +14 -30
  28. package/k.mjs +17 -13
  29. package/kvm.mjs +13 -9
  30. package/lib/arithmetics.k +287 -0
  31. package/lib/bit.k +68 -0
  32. package/lib/bits.k +221 -0
  33. package/lib/btrie.k +187 -0
  34. package/lib/djson.k +326 -0
  35. package/lib/ieee.k +709 -0
  36. package/lib/list.k +49 -0
  37. package/lib/string.k +588 -0
  38. package/named-patterns.mjs +2 -2
  39. package/object.mjs +52 -10
  40. package/objects/README.md +10 -3
  41. package/objects/compile.mjs +10 -8
  42. package/package.json +1 -1
  43. package/repl.mjs +227 -22
  44. package/scripts/benchmark-idempotency.mjs +22 -15
  45. package/scripts/benchmark.mjs +29 -10
  46. package/scripts/build-repl-html.mjs +49 -14
  47. package/scripts/perf-ieee.mjs +9 -1
  48. package/scripts/perf-int.mjs +10 -17
  49. package/scripts/perf-multiplication.mjs +9 -15
  50. package/scripts/perf-poly.mjs +16 -32
  51. package/scripts/run-tests.mjs +2 -2
  52. package/scripts/test-package.mjs +8 -2
  53. package/tests/helpers/cli.mjs +11 -3
  54. package/tests/integration.sh +9 -4
  55. package/tests/test-arithmetics.mjs +4 -2
  56. package/tests/test-djson-methods.mjs +16 -12
  57. package/tests/test-ieee-arithmetic.mjs +11 -3
  58. package/tests/test-ieee-text.mjs +15 -4
  59. package/tests/test-k-object.mjs +11 -3
  60. package/tests/test-karatsuba.mjs +1 -1
  61. package/tests/test-kvm-polymorphic.mjs +54 -34
  62. package/tests/test-lib.mjs +115 -0
  63. package/tests/test-named-patterns.mjs +12 -3
  64. package/tests/test-parse-json.mjs +33 -13
  65. package/tests/test-poly.mjs +10 -4
  66. package/tests/test-repl-html.mjs +18 -7
  67. package/tests/test-repl.mjs +154 -54
  68. package/Examples/djson.k +0 -894
  69. package/Examples/ieee.k +0 -969
  70. package/Examples/karatsuba-mult.k +0 -227
  71. package/Examples/list.k +0 -10
@@ -309,24 +309,20 @@ 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
- output = await evaluateInput(":load Examples/arithmetics.k", arithState);
313
- assert.equal(output[0], "loaded Examples/arithmetics.k");
312
+ await evaluateInput(":load lib/bit.k", arithState);
313
+ await evaluateInput(":load lib/bits.k", arithState);
314
+ output = await evaluateInput(":load lib/arithmetics.k", arithState);
315
+ assert.equal(output[0], "loaded lib/arithmetics.k");
314
316
  output = await evaluateInput(":pat bits", arithState);
315
317
  assert.equal(
316
318
  output[0],
317
- "bits[] = <B 0, B 1, {} _>=B; -- " +
319
+ "bits[] = <X0 0, X0 1, {} _>=X0; -- " +
318
320
  "@VtPHxGf5GNMzzyVFxtv7gegFfJRYapBGtCeyV56bs5Zb[]"
319
321
  );
320
- // output = await evaluateInput(":pat bit", arithState);
321
- // assert.equal(
322
- // output[0],
323
- // "bit[] = <{} 0, {} 1>; -- " +
324
- // "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
325
- // );
326
322
  output = await evaluateInput(":pat int[]", arithState);
327
323
  assert.equal(
328
324
  output[0],
329
- "int[] = <bits[] +, bits[] ->; -- " +
325
+ "int[] = <<X0 0, X0 1, {} _>=X0 +, X0 ->; -- " +
330
326
  "@Nws3vysWqC9PznraTP4kWPp44Rd77NAqrx9dgbtHAjGA[]"
331
327
  );
332
328
  output = await evaluateInput("10", arithState);
@@ -389,7 +385,9 @@ assert.match(output[0], /^\{\}\|a/);
389
385
 
390
386
  // Explicit loading of dependencies and codec testing (no auto-loading)
391
387
  const intState = createState();
392
- await evaluateInput(":load Examples/arithmetics.k", intState);
388
+ await evaluateInput(":load lib/bit.k", intState);
389
+ await evaluateInput(":load lib/bits.k", intState);
390
+ await evaluateInput(":load lib/arithmetics.k", intState);
393
391
  output = await evaluateInput(":codec load ./codecs/int.mjs", intState);
394
392
  assert.match(output[0], /^loaded codec int\.mjs/);
395
393
  output = await evaluateInput(":input int.mjs", intState);
@@ -408,8 +406,9 @@ output = await evaluateInput("test utf8", utf8AutoState);
408
406
  assert.match(output[0], /utf8\.mjs: test utf8/);
409
407
 
410
408
  const ieeeAutoState = createState();
411
- await evaluateInput(":load core.k", ieeeAutoState);
412
- await evaluateInput(":load Examples/ieee.k", ieeeAutoState);
409
+ for (const file of ["lib/bit.k", "lib/bits.k", "lib/list.k", "lib/btrie.k", "lib/string.k", "lib/ieee.k"]) {
410
+ await evaluateInput(`:load ${file}`, ieeeAutoState);
411
+ }
413
412
  output = await evaluateInput(":codec load ./codecs/ieee.mjs", ieeeAutoState);
414
413
  assert.match(output[0], /^loaded codec ieee\.mjs/);
415
414
  assert.ok(ieeeAutoState.codecs["ieee.mjs"], "ieee codec should be registered");
@@ -417,8 +416,9 @@ output = await evaluateInput(":input ieee.mjs 1.5", ieeeAutoState);
417
416
  assert.match(output[0], /ieee\.mjs: 1\.5/);
418
417
 
419
418
  const jsonInputState = createState();
420
- await evaluateInput(":load core.k", jsonInputState);
421
- await evaluateInput(":load Examples/ieee.k", jsonInputState);
419
+ for (const file of ["lib/bit.k", "lib/bits.k", "lib/list.k", "lib/btrie.k", "lib/string.k", "lib/ieee.k"]) {
420
+ await evaluateInput(`:load ${file}`, jsonInputState);
421
+ }
422
422
  await evaluateInput(":codec load ./codecs/json.mjs", jsonInputState);
423
423
  output = await evaluateInput(':input json.mjs {"a":"Woj","n":123}', jsonInputState);
424
424
  assert.match(output[0], /json\.mjs: \{"a":"Woj","n":123\}/);
@@ -479,16 +479,14 @@ assert.match(output[0], /unit\.mjs: \{\}/);
479
479
  const polyFreshState = createState();
480
480
  await assert.rejects(
481
481
  () => evaluateInput(":load Examples/poly.k", polyFreshState),
482
- /Unknown pattern template/
482
+ /Unknown pattern template|No definition found for/
483
483
  );
484
484
 
485
- // Explicitly loading arithmetics.k then poly.k succeeds
485
+ // Explicitly loading dependencies then poly.k succeeds
486
486
  const polyExplicitState = createState();
487
- output = await evaluateInput(
488
- ":load Examples/arithmetics.k",
489
- polyExplicitState
490
- );
491
- assert.equal(output[0], "loaded Examples/arithmetics.k");
487
+ for (const file of ["lib/bit.k", "lib/bits.k", "lib/arithmetics.k", "lib/list.k"]) {
488
+ await evaluateInput(`:load ${file}`, polyExplicitState);
489
+ }
492
490
  output = await evaluateInput(
493
491
  ":load Examples/poly.k",
494
492
  polyExplicitState
@@ -571,8 +569,10 @@ output = await evaluateInput("not = </true | false, /false | true >;\n{} | true
571
569
  assert.match(output[0], /^\{\}\|false/);
572
570
  assert.match(output[1], /\(js\)/);
573
571
 
574
- output = await evaluateInput(":load Examples/arithmetics.k", jsState);
575
- assert.equal(output[0], "loaded Examples/arithmetics.k");
572
+ await evaluateInput(":load lib/bit.k", jsState);
573
+ await evaluateInput(":load lib/bits.k", jsState);
574
+ output = await evaluateInput(":load lib/arithmetics.k", jsState);
575
+ assert.equal(output[0], "loaded lib/arithmetics.k");
576
576
  output = await evaluateInput("{ 10 int x, 5 int y } plus", jsState);
577
577
  assert.match(output[0], /^\{\}\|_\|1\|1\|1\|1\|\+/);
578
578
  assert.match(output[1], /\(js\)/);
@@ -595,15 +595,19 @@ output = await evaluateInput(
595
595
  assert.match(output[0], /^\{\}\|false/);
596
596
  assert.match(output[1], /\(pkir\)/);
597
597
 
598
- output = await evaluateInput(":load Examples/arithmetics.k", pkirState);
599
- assert.equal(output[0], "loaded Examples/arithmetics.k");
598
+ await evaluateInput(":load lib/bit.k", pkirState);
599
+ await evaluateInput(":load lib/bits.k", pkirState);
600
+ output = await evaluateInput(":load lib/arithmetics.k", pkirState);
601
+ assert.equal(output[0], "loaded lib/arithmetics.k");
600
602
  output = await evaluateInput("{ 10 int x, 5 int y } plus", pkirState);
601
603
  assert.match(output[0], /^\{\}\|_\|1\|1\|1\|1\|\+/);
602
604
  assert.match(output[1], /\(pkir\)/);
603
605
 
604
606
  // Verify open product projection in wasm engine
605
607
  const wasmListState = createState({ engine: "wasm" });
606
- await evaluateInput(":load Examples/arithmetics.k", wasmListState);
608
+ await evaluateInput(":load lib/bit.k", wasmListState);
609
+ await evaluateInput(":load lib/bits.k", wasmListState);
610
+ await evaluateInput(":load lib/arithmetics.k", wasmListState);
607
611
  await evaluateInput(":codec load codecs/int.mjs", wasmListState);
608
612
  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);
609
613
  await evaluateInput(":input int.mjs [3,3,3]", wasmListState);
@@ -622,7 +626,9 @@ assert.equal(output[0], "output limit set to 40");
622
626
  output = await evaluateInput(":limit", limitState);
623
627
  assert.equal(output[0], "Current output limit: 40");
624
628
 
625
- output = await evaluateInput(":load Examples/arithmetics.k", limitState);
629
+ await evaluateInput(":load lib/bit.k", limitState);
630
+ await evaluateInput(":load lib/bits.k", limitState);
631
+ output = await evaluateInput(":load lib/arithmetics.k", limitState);
626
632
  output = await evaluateInput("{ 10 int x, 5 int y } plus", limitState);
627
633
  assert(output[0].includes("..."));
628
634
  assert(output[0].length <= 80);
@@ -632,12 +638,13 @@ assert.equal(output[0], "output limit disabled");
632
638
  output = await evaluateInput(":limit", limitState);
633
639
  assert.equal(output[0], "Current output limit: none");
634
640
 
635
- // Verify Examples/djson.k (json?, get, nth, set, del)
641
+ // Verify lib/djson.k (json?, get, nth, set, del)
636
642
  const djsonKState = createState({ engine: "wasm" });
637
- await evaluateInput(":load core.k", djsonKState);
638
- await evaluateInput(":load Examples/ieee.k", djsonKState);
639
- output = await evaluateInput(":load Examples/djson.k", djsonKState);
640
- assert.equal(output[0], "loaded Examples/djson.k");
643
+ for (const file of ["lib/bit.k", "lib/bits.k", "lib/list.k", "lib/btrie.k", "lib/string.k", "lib/ieee.k"]) {
644
+ await evaluateInput(`:load ${file}`, djsonKState);
645
+ }
646
+ output = await evaluateInput(":load lib/djson.k", djsonKState);
647
+ assert.equal(output[0], "loaded lib/djson.k");
641
648
  await evaluateInput(":codec load codecs/djson.mjs", djsonKState);
642
649
  await evaluateInput(
643
650
  ':input djson.mjs ["age", {"name":"Alice","age":30}]',
@@ -686,19 +693,19 @@ assert.equal(
686
693
  output = await evaluateInput(":pattern bit", patState);
687
694
  assert.equal(
688
695
  output[0],
689
- "bit[] = <{} 0, {} 1>; -- " +
696
+ "bit[] = <{}=X0 0, X0 1>; -- " +
690
697
  "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
691
698
  );
692
699
  output = await evaluateInput(":pattern bit[]", patState);
693
700
  assert.equal(
694
701
  output[0],
695
- "bit[] = <{} 0, {} 1>; -- " +
702
+ "bit[] = <{}=X0 0, X0 1>; -- " +
696
703
  "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
697
704
  );
698
705
  output = await evaluateInput(":pat bit", patState);
699
706
  assert.equal(
700
707
  output[0],
701
- "bit[] = <{} 0, {} 1>; -- " +
708
+ "bit[] = <{}=X0 0, X0 1>; -- " +
702
709
  "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
703
710
  );
704
711
  output = await evaluateInput(
@@ -720,8 +727,8 @@ output = await evaluateInput(
720
727
  output = await evaluateInput(":pattern byte", patState);
721
728
  assert.equal(
722
729
  output[0],
723
- "byte[] = {bit[] b0, bit[] b1, bit[] b2, bit[] b3, " +
724
- "bit[] b4, bit[] b5, bit[] b6, bit[] b7}; -- " +
730
+ "byte[] = {<{}=X1 0, X1 1>=X0 b0, X0 b1, X0 b2, X0 b3, " +
731
+ "X0 b4, X0 b5, X0 b6, X0 b7}; -- " +
725
732
  "@4ukq2gpiEBFa7WXxcfRm8pfdr2kgYLTTnwsmLHeMd9i5[]"
726
733
  );
727
734
 
@@ -774,8 +781,10 @@ assert.equal(
774
781
  "@KqTBNkznjWWwync2Mm94XjCez63neJBJtgYcJJEE5kEm[A, B]"
775
782
  );
776
783
 
777
- output = await evaluateInput(":load Examples/list.k", patState);
778
- assert.equal(output[0], "loaded Examples/list.k");
784
+ await evaluateInput(":load lib/bit.k", patState);
785
+ await evaluateInput(":load lib/bits.k", patState);
786
+ output = await evaluateInput(":load lib/list.k", patState);
787
+ assert.equal(output[0], "loaded lib/list.k");
779
788
  output = await evaluateInput(":patterns", patState);
780
789
  assert(output[0].includes("bit[] = @Mjusy"));
781
790
  assert(output[0].includes("list[X] = @JagVex"));
@@ -784,7 +793,7 @@ assert(output[0].includes("pair[A,B] = @KqTB"));
784
793
  output = await evaluateInput(":pattern list", patState);
785
794
  assert.equal(
786
795
  output[0],
787
- "list[X] = <{} nil, {X car, Y cdr} cons>=Y; -- " +
796
+ "list[X] = <{X car, X0 cdr} cons, {} nil>=X0; -- " +
788
797
  "@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X]"
789
798
  );
790
799
 
@@ -812,13 +821,13 @@ assert.equal(
812
821
  output = await evaluateInput(":pattern pair", freshState);
813
822
  assert.equal(
814
823
  output[0],
815
- "pair[A, B] = {X0 first, X1 second}; -- " +
824
+ "pair[A, B] = {A first, B second}; -- " +
816
825
  "@KqTBNkznjWWwync2Mm94XjCez63neJBJtgYcJJEE5kEm[A, B]"
817
826
  );
818
827
  output = await evaluateInput(":pattern list", freshState);
819
828
  assert.equal(
820
829
  output[0],
821
- "list[X] = <{X1 car, X0 cdr} cons, {} nil>=X0; -- " +
830
+ "list[X] = <{X car, X0 cdr} cons, {} nil>=X0; -- " +
822
831
  "@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X]"
823
832
  );
824
833
  output = await evaluateInput(
@@ -838,7 +847,7 @@ output = await evaluateInput("a[] = x;", freshState);
838
847
  output = await evaluateInput(":pattern a", freshState);
839
848
  assert.equal(
840
849
  output[0],
841
- "a[] = x; -- " +
850
+ "a[] = (...); -- " +
842
851
  "@QfyLpmn56wuppuGvrrUJz8LKtgaXfbMtad7RnzBcFk2S[(...)]"
843
852
  );
844
853
  output = await evaluateInput(
@@ -860,13 +869,13 @@ output = await evaluateInput(
860
869
  output = await evaluateInput(":pat a", freshState);
861
870
  assert.equal(
862
871
  output[0],
863
- "a[] = {X x, Y y}; -- " +
872
+ "a[] = {(...) x, (...) y}; -- " +
864
873
  "@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[(...), (...)]"
865
874
  );
866
875
  output = await evaluateInput(":pat b", freshState);
867
876
  assert.equal(
868
877
  output[0],
869
- "b[X] = {X x, Y y}; -- " +
878
+ "b[X] = {X x, (...) y}; -- " +
870
879
  "@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X, (...)]"
871
880
  );
872
881
  output = await evaluateInput(":pat c", freshState);
@@ -980,7 +989,15 @@ assert(
980
989
  )
981
990
  );
982
991
 
983
- // Verify :rel prints canonical pattern names for input and output patterns
992
+ // Verify :rel prints inline when <= 45 and canonical pattern names when > maxPatLength
993
+ output = await evaluateInput(":rel reverse", polyExplicitState);
994
+ assert.equal(
995
+ output[0],
996
+ "reverse = ?<{(...) car, X0 cdr} cons, {} nil>=X0 " +
997
+ "{() x, nil y} rev_append ?X0; " +
998
+ "-- @peiZq2evd5u4Qk42AT3W4YmWZZ3JAeXNKTnmDtpb9EZh"
999
+ );
1000
+ await evaluateInput(":max-pat-length 30", polyExplicitState);
984
1001
  output = await evaluateInput(":rel car", polyExplicitState);
985
1002
  assert.equal(
986
1003
  output[0],
@@ -992,30 +1009,30 @@ output = await evaluateInput(":rel reverse", polyExplicitState);
992
1009
  assert.equal(
993
1010
  output[0],
994
1011
  "reverse = ?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X0] " +
995
- "{() xs, nil acc} _reverse " +
1012
+ "{() x, nil y} rev_append " +
996
1013
  "?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X0]; " +
997
- "-- @JbJ2aQugNct2GGeCJ65zKjN55Bf5YPyGHzsikTCjx82w"
1014
+ "-- @peiZq2evd5u4Qk42AT3W4YmWZZ3JAeXNKTnmDtpb9EZh"
998
1015
  );
999
1016
  output = await evaluateInput(":rel nil?", polyExplicitState);
1000
1017
  assert.equal(
1001
1018
  output[0],
1002
1019
  "nil? = ?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[(...)] " +
1003
- "/nil nil " +
1020
+ "un_nil nil " +
1004
1021
  "?@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[(...)]; " +
1005
- "-- @YHZEettEijtfW68ekdSKKiZRfiiEkqJjLDb9NNcJnwcg"
1022
+ "-- @BqMbBgmNtqci4fKjrUh5dwMrAehZcGSeEpEdLaMeCXSA"
1006
1023
  );
1007
1024
  output = await evaluateInput(":rel parseJson", djsonKState);
1008
1025
  assert.equal(
1009
1026
  output[0],
1010
1027
  "parseJson = " +
1011
1028
  "?@Pt3MwQwzUPxQKu58zXR3qUBHWTzfycx5bSZGzcK6EZQK[] " +
1012
- "json_value {.rest ws /nil end, .value value} .value " +
1029
+ "json_value {.rest ws un_nil end, .value value} .value " +
1013
1030
  "?@P5C7TQKTSPnFUkYkYzTudJamxAQ3T3fHbvZNqwWMfAA2[]; " +
1014
- "-- @tWaZchv9AbbWxSHVk8nBpz8jVnjswiwDNhpFZeFwg6Pt"
1031
+ "-- @BNjpkLgR3SxNvVMuAE9xkBxvJFhaDUhaHHsBBjmx4RRK"
1015
1032
  );
1016
1033
  const shortThresholdState = createState();
1017
1034
  output = await evaluateInput(":max-pat-length", shortThresholdState);
1018
- assert.equal(output[0], "Current max pattern length: 30");
1035
+ assert.equal(output[0], "Current max pattern length: 45");
1019
1036
  output = await evaluateInput(":maxPatLength 10", shortThresholdState);
1020
1037
  assert.equal(output[0], "max pattern length set to 10");
1021
1038
  output = await evaluateInput(":max-pat-length", shortThresholdState);
@@ -1072,6 +1089,89 @@ completions = completeInput(":max", shortThresholdState)[0];
1072
1089
  assert(completions.includes(":max-pat-length"));
1073
1090
  assert(completions.includes(":maxPatLength"));
1074
1091
 
1092
+ // Verify canonical :pat output and :all-patterns / :all-pats
1093
+ const allPatState = createState();
1094
+ output = await evaluateInput(":all-patterns", allPatState);
1095
+ assert.equal(output[0], "(none)");
1096
+ await evaluateInput("p[X,Y] = {X x, Y y};", allPatState);
1097
+ await evaluateInput("bit[] = <{} 1, {} 0>;", allPatState);
1098
+ await evaluateInput("u[] = p[bit[], bit[]];", allPatState);
1099
+ await evaluateInput("w[] = {<{} 0, {} 1>=X x, X y};", allPatState);
1100
+ output = await evaluateInput(":pat u", allPatState);
1101
+ assert.equal(
1102
+ output[0],
1103
+ "u[] = {<{}=X1 0, X1 1>=X0 x, X0 y}; " +
1104
+ "-- @akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[]"
1105
+ );
1106
+ output = await evaluateInput(":pat w", allPatState);
1107
+ assert.equal(
1108
+ output[0],
1109
+ "w[] = {<{}=X1 0, X1 1>=X0 x, X0 y}; " +
1110
+ "-- @akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[]"
1111
+ );
1112
+ output = await evaluateInput(":all-patterns", allPatState);
1113
+ assert.equal(
1114
+ output[0],
1115
+ [
1116
+ "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[] = " +
1117
+ "<{}=X0 0, X0 1>; -- bit[] = @[]",
1118
+ "@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
1119
+ "{X0 x, X1 y}; -- p[X,Y] = @[X,Y]",
1120
+ "@akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[] = " +
1121
+ "{<{}=X1 0, X1 1>=X0 x, X0 y}; -- u[] = @[], w[] = @[]"
1122
+ ].join("\n")
1123
+ );
1124
+ output = await evaluateInput(":all-pats", allPatState);
1125
+ assert.equal(
1126
+ output[0],
1127
+ [
1128
+ "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[] = " +
1129
+ "<{}=X0 0, X0 1>; -- bit[] = @[]",
1130
+ "@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
1131
+ "{X0 x, X1 y}; -- p[X,Y] = @[X,Y]",
1132
+ "@akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[] = " +
1133
+ "{<{}=X1 0, X1 1>=X0 x, X0 y}; -- u[] = @[], w[] = @[]"
1134
+ ].join("\n")
1135
+ );
1136
+
1137
+ const pqState = createState();
1138
+ await evaluateInput("p[X] = {X x, Y y};", pqState);
1139
+ await evaluateInput("q[ZZZ] = {ZZZ x, ZZZ y};", pqState);
1140
+ output = await evaluateInput(":all-pat", pqState);
1141
+ assert.equal(
1142
+ output[0],
1143
+ "@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
1144
+ "{X0 x, X1 y}; -- p[X] = @[X,(...)], q[ZZZ] = @[ZZZ,ZZZ]"
1145
+ );
1146
+ completions = completeInput(":all", allPatState)[0];
1147
+ assert(completions.includes(":all-patterns"));
1148
+ assert(completions.includes(":all-pat"));
1149
+
1150
+ const relPatState = createState();
1151
+ await evaluateInput("ww = ?<{} x, {}y, Z z > = Z;", relPatState);
1152
+ output = await evaluateInput(":pats", relPatState);
1153
+ assert.equal(output[0], "(none)");
1154
+ output = await evaluateInput(":all-pats", relPatState);
1155
+ assert.equal(
1156
+ output[0],
1157
+ "@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[] = " +
1158
+ "<{}=X1 x, X1 y, X0 z>=X0;"
1159
+ );
1160
+ output = await evaluateInput(":rel ww", relPatState);
1161
+ assert.equal(
1162
+ output[0],
1163
+ "ww = ?<{}=X1 x, X1 y, X0 z>=X0 () ?X0; " +
1164
+ "-- @VmhPa6q6x9eeN8pnyJnz89w9GVjNhWtz5zZghJb4zjUx"
1165
+ );
1166
+ await evaluateInput(":max-pat-length 10", relPatState);
1167
+ output = await evaluateInput(":rel ww", relPatState);
1168
+ assert.equal(
1169
+ output[0],
1170
+ "ww = ?@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[] () " +
1171
+ "?@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[]; " +
1172
+ "-- @VmhPa6q6x9eeN8pnyJnz89w9GVjNhWtz5zZghJb4zjUx"
1173
+ );
1174
+
1075
1175
  fs.rmSync(tmpDir, { recursive: true, force: true });
1076
1176
  fs.rmSync(symlinkPath, { force: true });
1077
1177
  console.log("OK");