@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
@@ -6,7 +6,7 @@ The active format is the self-hosted pattern-plus-prefix-tree stream described
6
6
  in [`POLYMORPHIC_BINARY_FORMAT.md`](./POLYMORPHIC_BINARY_FORMAT.md):
7
7
 
8
8
  ```text
9
- encode($pattern_value : $pattern) encode(value : decoded_pattern)
9
+ encode(pattern_value : pattern) encode(value : decoded_pattern)
10
10
  ```
11
11
 
12
12
  ## Purpose of This File
@@ -18,7 +18,7 @@ The design sequence is:
18
18
 
19
19
  1. define the abstract pattern graph,
20
20
  2. define prefix-free value-tree encoding relative to that graph,
21
- 3. encode the pattern itself as a k `$pattern` value,
21
+ 3. encode the pattern itself as a k `pattern` value,
22
22
  4. optionally add higher-level indexes or compression as separate layers.
23
23
 
24
24
  ## Expected Container Shape
@@ -26,12 +26,12 @@ The design sequence is:
26
26
  The canonical stream contains:
27
27
 
28
28
  ```text
29
- encoded-$pattern + value-bitstream
29
+ encoded-pattern + value-bitstream
30
30
  ```
31
31
 
32
32
  where:
33
33
 
34
- - `encoded-$pattern` is the k value representation defined in `core.k`,
34
+ - `encoded-pattern` is the k value representation defined in `core.k`,
35
35
  - the value bitstream is exactly the same prefix-free payload described by the
36
36
  semantic codec.
37
37
 
@@ -61,7 +61,7 @@ Unions emit a choice code, then the payload of the selected branch.
61
61
 
62
62
  ### 4. One canonical stream
63
63
 
64
- The pattern graph is embedded as an ordinary k `$pattern` value. The canonical
64
+ The pattern graph is embedded as an ordinary k `pattern` value. The canonical
65
65
  stream is that encoded pattern followed by the value payload interpreted under
66
66
  the decoded pattern.
67
67
 
@@ -277,11 +277,11 @@ This keeps the codec uniform: recursion is handled by the pattern graph itself.
277
277
  The transport format is:
278
278
 
279
279
  ```text
280
- encode($pattern_value : $pattern) encode(value : decoded_pattern)
280
+ encode(pattern_value : pattern) encode(value : decoded_pattern)
281
281
  ```
282
282
 
283
- The first segment is a normal k value of type `$pattern`, encoded under the
284
- fixed singleton pattern for `$pattern` defined by `core.k`. The decoded pattern
283
+ The first segment is a normal k value of type `pattern`, encoded under the
284
+ fixed singleton pattern for `pattern` defined by `core.k`. The decoded pattern
285
285
  is then used as the structural authority for the second segment.
286
286
 
287
287
  Decoding the stream yields `Value(pattern, tree)`. Encoding a runtime `Value`
package/codecs/README.md CHANGED
@@ -6,13 +6,13 @@ This directory is centered on the codec design:
6
6
  abstract pattern graph + prefix-free tree encoding
7
7
  ```
8
8
 
9
- The default concrete format is now the binary encoding of a `$pattern`
10
- value, using the `$pattern` type from [`../core.k`](../core.k),
9
+ The default concrete format is now the binary encoding of a `pattern`
10
+ value, using the `pattern` relation from [`../core.k`](../core.k),
11
11
  immediately followed by the binary encoding of the value under that
12
12
  decoded pattern.
13
13
 
14
14
  `core.k` is not loaded automatically as a library when user programs
15
- run. The codec only depends on the canonical `$pattern` definition from
15
+ run. The codec only depends on the canonical `pattern` definition from
16
16
  that file as the schema for the leading pattern value.
17
17
 
18
18
  There is no separate JSON container format.
@@ -63,10 +63,10 @@ primitive value format.
63
63
  The default transport format is:
64
64
 
65
65
  ```text
66
- encode($pattern_value : $pattern) encode(value : decoded_pattern)
66
+ encode(pattern_value : pattern) encode(value : decoded_pattern)
67
67
  ```
68
68
 
69
- `$pattern_value` is a normal k value whose shape is defined in `core.k`.
69
+ `pattern_value` is a normal k value whose shape is defined in `core.k`.
70
70
  After that value is decoded, it becomes the pattern used to decode the
71
71
  remaining value payload.
72
72
 
@@ -151,7 +151,7 @@ Canonical rules:
151
151
  - `"any"` must have no outgoing edges.
152
152
 
153
153
  This JSON-like graph is only a readable notation. The wire
154
- representation is the ordinary k `$pattern` value from `core.k`.
154
+ representation is the ordinary k `pattern` value from `core.k`.
155
155
 
156
156
  For pattern export, see [`../DOCS/PATTERNS.md`](../DOCS/PATTERNS.md) and
157
157
  the repository helper `patterns/from-k.mjs`.
package/codecs/ieee.mjs CHANGED
@@ -9,17 +9,21 @@ Parses decimal floats, Infinity, -Infinity, NaN to 64-bit IEEE products.
9
9
  `;
10
10
 
11
11
  const FLOAT64_PATTERN = patternFromFilter(`
12
- $bit = < {} 0, {} 1 >;
13
- $sign = < {} "+", {} "-" >;
14
- $exp11 = {bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, bit 7, bit 8, bit 9, bit 10};
15
- $frac52 = {bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, bit 7, bit 8, bit 9,
16
- bit 10, bit 11, bit 12, bit 13, bit 14, bit 15, bit 16, bit 17, bit 18, bit 19,
17
- bit 20, bit 21, bit 22, bit 23, bit 24, bit 25, bit 26, bit 27, bit 28, bit 29,
18
- bit 30, bit 31, bit 32, bit 33, bit 34, bit 35, bit 36, bit 37, bit 38, bit 39,
19
- bit 40, bit 41, bit 42, bit 43, bit 44, bit 45, bit 46, bit 47, bit 48, bit 49,
20
- bit 50, bit 51};
21
- $float64 = {sign sign, exp11 exponent, frac52 fraction};
22
- ?$float64
12
+ ? {
13
+ < {} "+", {} "-" > sign,
14
+ {
15
+ < {} 0, {} 1 >=Bit 0,
16
+ Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, Bit 8, Bit 9, Bit 10
17
+ } exponent,
18
+ {
19
+ Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, Bit 8, Bit 9,
20
+ Bit 10, Bit 11, Bit 12, Bit 13, Bit 14, Bit 15, Bit 16, Bit 17, Bit 18, Bit 19,
21
+ Bit 20, Bit 21, Bit 22, Bit 23, Bit 24, Bit 25, Bit 26, Bit 27, Bit 28, Bit 29,
22
+ Bit 30, Bit 31, Bit 32, Bit 33, Bit 34, Bit 35, Bit 36, Bit 37, Bit 38, Bit 39,
23
+ Bit 40, Bit 41, Bit 42, Bit 43, Bit 44, Bit 45, Bit 46, Bit 47, Bit 48, Bit 49,
24
+ Bit 50, Bit 51
25
+ } fraction
26
+ }
23
27
  `);
24
28
 
25
29
  const UNIT = Value.product({});
package/codecs/int.mjs CHANGED
@@ -21,11 +21,15 @@ Syntax:
21
21
  // with $ bits = < {} _, bits 0, bits 1 >
22
22
  const INT_PATTERN = patternFromFilter('?< <bits 0, bits 1, {} _>=bits "+", bits "-">');
23
23
 
24
- // Closed pattern for list of int:
25
- // list = < {} nil, {int car, list cdr} cons >
26
- const INT_LIST_PATTERN = patternFromFilter(
27
- '$ bits = < bits 0, bits 1, {} _ >; $ int = < bits "+", bits "-" >; ?< {} nil, { $int car, list cdr } cons > = list'
28
- );
24
+ const INT_LIST_PATTERN = patternFromFilter(`
25
+ ?<
26
+ {} nil,
27
+ {
28
+ < <bits 0, bits 1, {} _>=bits "+", bits "-" > car,
29
+ list cdr
30
+ } cons
31
+ > = list
32
+ `);
29
33
 
30
34
  // Build bits Value (MSB outermost) from a non-negative BigInt.
31
35
  function buildBits(n) {
@@ -2,53 +2,52 @@ import { patternFromFilter } from "./runtime/codec-sdk.mjs";
2
2
  import { textToStringValue, stringValueToText } from "./runtime/unicode-string.mjs";
3
3
 
4
4
  const STRING_PATTERN_PROPERTY_LIST = patternFromFilter(`
5
- $bit = < {} 0, {} 1 >;
6
- $bits1 = { bit 0 };
7
- $bits2 = { bit 0, bit 1 };
8
- $bits3 = { bit 0, bit 1, bit 2 };
9
- $bits4 = { bit 0, bit 1, bit 2, bit 3 };
10
- $bits7 = { bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6 };
11
- $bits8 = { bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, bit 7 };
12
- $bits11 = { bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, bit 7, bit 8, bit 9, bit 10 };
13
-
14
- $bmp_common_hi = <
15
- bits3 h08_0F,
16
- bits7 h10_7F,
17
- bits7 h80_CF,
18
- bits3 hD0_D7,
19
- {} hF9,
20
- bits1 hFA_FB,
21
- bits1 hFC_FD,
22
- bits1 hFE_FF
23
- >;
24
- $bmp_common = { bmp_common_hi hi, bits8 lo };
25
-
26
- $bmp_private_hi = <
27
- bits4 hE0_EF,
28
- bits3 hF0_F7,
29
- {} hF8
30
- >;
31
- $bmp_private_use = { bmp_private_hi hi, bits8 lo };
32
-
33
- $plane2_16 = <
34
- bits1 p02_03,
35
- bits2 p04_07,
36
- bits3 p08_0F,
37
- {} p10
38
- >;
39
- $supplementary_planes2_16 = { plane2_16 plane, bits8 mid, bits8 lo };
40
- $supplementary_plane1 = { bits8 mid, bits8 lo };
41
-
42
- $unicode_scalar = <
43
- bits7 ascii,
44
- bits11 plane0,
45
- bmp_common bmp_common,
46
- bmp_private_use bmp_private_use,
47
- supplementary_plane1 supplementary_plane1,
48
- supplementary_planes2_16 supplementary_planes2_16
49
- >;
50
-
51
- ?< {} nil, { $unicode_scalar car, str cdr } cons > = str
5
+ ? <
6
+ {} nil,
7
+ {
8
+ <
9
+ {
10
+ < {} 0, {} 1 >=Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6
11
+ }=Bits7 ascii,
12
+ {
13
+ <
14
+ { Bit 0, Bit 1, Bit 2 }=Bits3 h08_0F,
15
+ Bits7 h10_7F,
16
+ Bits7 h80_CF,
17
+ Bits3 hD0_D7,
18
+ {} hF9,
19
+ { Bit 0 }=Bits1 hFA_FB,
20
+ Bits1 hFC_FD,
21
+ Bits1 hFE_FF
22
+ > hi,
23
+ { Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7 }=Bits8 lo
24
+ } bmp_common,
25
+ {
26
+ <
27
+ { Bit 0, Bit 1, Bit 2, Bit 3 } hE0_EF,
28
+ Bits3 hF0_F7,
29
+ {} hF8
30
+ > hi,
31
+ Bits8 lo
32
+ } bmp_private_use,
33
+ {
34
+ Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, Bit 8, Bit 9, Bit 10
35
+ } plane0,
36
+ { Bits8 mid, Bits8 lo } supplementary_plane1,
37
+ {
38
+ <
39
+ Bits1 p02_03,
40
+ { Bit 0, Bit 1 } p04_07,
41
+ Bits3 p08_0F,
42
+ {} p10
43
+ > plane,
44
+ Bits8 mid,
45
+ Bits8 lo
46
+ } supplementary_planes2_16
47
+ > car,
48
+ Str cdr
49
+ } cons
50
+ > = Str
52
51
  `);
53
52
 
54
53
  export { STRING_PATTERN_PROPERTY_LIST, textToStringValue, stringValueToText };
package/core.k CHANGED
@@ -1,17 +1,17 @@
1
1
  -- core.k — the k standard core library
2
2
  --
3
3
  -- Defines:
4
- -- 1. $bits — the canonical binary number / bit-path type
5
- -- 2. $string — unicode strings (used for labels)
6
- -- 3. $pattern — the type of pattern graphs
4
+ -- 1. bits — canonical binary number / bit-path relation
5
+ -- 2. string — unicode strings relation (used for labels)
6
+ -- 3. pattern — pattern graph relation
7
7
 
8
8
  ---------------------------------------------------------------
9
9
  -- §1. Bits
10
10
  ---------------------------------------------------------------
11
11
 
12
- $ bit = < {} 0, {} 1 >;
12
+ bit = ?< {} 0, {} 1 >;
13
13
 
14
- $ bits = < {} _, bits 0, bits 1 >;
14
+ bits = ?< {} _, bits 0, bits 1 > = bits;
15
15
 
16
16
  _ = {}|_;
17
17
 
@@ -22,104 +22,132 @@ _ = {}|_;
22
22
  -- §2. Unicode and String
23
23
  ---------------------------------------------------------------
24
24
 
25
- -- 8-bit octet used as a building block for UTF-8 payload pieces.
26
- $ byte = {
27
- bit 0, bit 1, bit 2, bit 3,
28
- bit 4, bit 5, bit 6, bit 7
29
- };
30
-
31
- -- 7-bit ASCII code point payload (U+0000..U+007F).
32
- $ ascii = { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
33
-
34
- -- 11-bit payload used for Plane 0 code points U+0080..U+07FF.
35
- -- Plane 0 is the Basic Multilingual Plane (BMP): U+0000..U+FFFF.
36
- $ u0080_07FF = { bit 10, bit 9, bit 8, bit 7, bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
37
-
38
- -- High-byte classes for common BMP ranges, excluding surrogate and
39
- -- private-use partitions.
40
- -- BMP (Basic Multilingual Plane) is Plane 0: first 65,536 code points.
41
- $ bmp_hi_common = <
42
- { bit 2, bit 1, bit 0 } h08_0F,
43
- { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h10_7F,
44
- { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h80_CF,
45
- { bit 2, bit 1, bit 0 } hD0_D7,
46
- {} hF9,
47
- { bit 0 } hFA_FB,
48
- { bit 0 } hFC_FD,
49
- { bit 0 } hFE_FF
50
- >;
51
-
52
- -- High-byte classes for BMP private-use/high-reserved slices.
53
- -- These partitions keep Plane 0 subsets explicit in the type encoding.
54
- $ bmp_hi_private_use = <
55
- { bit 3, bit 2, bit 1, bit 0 } hE0_EF,
56
- { bit 2, bit 1, bit 0 } hF0_F7,
57
- {} hF8
58
- >;
59
-
60
- -- Plane selector for supplementary code points in Planes 2..16.
61
- -- Supplementary planes are all planes above BMP (Plane 0).
62
- $ plane_02_10 = <
63
- { bit 0 } p02_03,
64
- { bit 1, bit 0 } p04_07,
65
- { bit 2, bit 1, bit 0 } p08_0F,
66
- {} p10
67
- >;
68
-
69
- -- Canonical Unicode scalar-value partition used by string encoding.
70
- -- Branch meaning:
71
- -- - ascii: U+0000..U+007F (subset of BMP / Plane 0)
72
- -- - plane0: U+0080..U+07FF (still Plane 0)
73
- -- - bmp_common, bmp_private_use: U+0800..U+FFFF partitions (Plane 0)
74
- -- - supplementary_plane1: U+10000..U+1FFFF (Plane 1)
75
- -- - supplementary_planes2_16: U+20000..U+10FFFF (Planes 2..16)
76
- $ unicode = <
77
- ascii ascii,
78
- u0080_07FF plane0,
79
- { bmp_hi_common hi, byte lo } bmp_common,
80
- { bmp_hi_private_use hi, byte lo } bmp_private_use,
81
- { byte mid, byte lo } supplementary_plane1,
82
- { plane_02_10 plane, byte mid, byte lo } supplementary_planes2_16
83
- >;
84
-
85
- -- Linked-list string: nil or (unicode car, string cdr).
86
- $ string = < {} nil, { unicode car, string cdr } cons >;
25
+ string = ? <
26
+ {} nil,
27
+ {
28
+ <
29
+ {
30
+ < {} 0, {} 1 >=Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6
31
+ }=Bits7 ascii,
32
+ {
33
+ <
34
+ { Bit 0, Bit 1, Bit 2 }=Bits3 h08_0F,
35
+ Bits7 h10_7F,
36
+ Bits7 h80_CF,
37
+ Bits3 hD0_D7,
38
+ {} hF9,
39
+ { Bit 0 }=Bits1 hFA_FB,
40
+ Bits1 hFC_FD,
41
+ Bits1 hFE_FF
42
+ > hi,
43
+ { Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7 }=Bits8 lo
44
+ } bmp_common,
45
+ {
46
+ <
47
+ { Bit 0, Bit 1, Bit 2, Bit 3 } hE0_EF,
48
+ Bits3 hF0_F7,
49
+ {} hF8
50
+ > hi,
51
+ Bits8 lo
52
+ } bmp_private_use,
53
+ {
54
+ Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, Bit 8, Bit 9, Bit 10
55
+ } plane0,
56
+ { Bits8 mid, Bits8 lo } supplementary_plane1,
57
+ {
58
+ <
59
+ Bits1 p02_03,
60
+ { Bit 0, Bit 1 } p04_07,
61
+ Bits3 p08_0F,
62
+ {} p10
63
+ > plane,
64
+ Bits8 mid,
65
+ Bits8 lo
66
+ } supplementary_planes2_16
67
+ > car,
68
+ String cdr
69
+ } cons
70
+ > = String;
87
71
 
88
72
  ---------------------------------------------------------------
89
73
  -- §3. Pattern
90
74
  ---------------------------------------------------------------
91
75
 
92
- -- Edge: a labeled edge in a pattern graph.
93
- -- 'label' is the field name or tag name.
94
- -- 'target' is index (as $bits) of the target node in the pattern list.
95
-
96
- $ edge = { string label, bits target };
97
-
98
- -- Edge list: the edges of a pattern node, sorted by label.
99
-
100
- $ edges = < {} nil, { edge car, edges cdr } cons >;
101
-
102
- -- Pattern node: one of five kinds.
103
- -- "any" is the unconstrained position (...), carrying no edges.
104
- -- The four others carry their edge list directly.
105
-
106
- $ pattern-node = <
107
- {} any,
108
- edges open-product,
109
- edges open-union,
110
- edges closed-product,
111
- edges closed-union
112
- >;
113
-
114
76
  -- Pattern: a cons-list of pattern nodes.
115
77
  -- Node 0 (first element) is the root.
116
- -- Edges reference nodes by their index in this list, encoded as $bits.
78
+ -- Edges reference nodes by their index in this list, encoded as bits.
117
79
  --
118
- -- The singleton pattern of $pattern itself is a fixed constant.
80
+ -- The singleton pattern of pattern itself is a fixed constant.
119
81
  -- That constant is the implicit framing for all k wire formats:
120
- -- to decode any value, first decode a $pattern under that constant,
82
+ -- to decode any value, first decode a pattern under that constant,
121
83
  -- then decode the value under the pattern just obtained.
122
84
 
123
- $ pattern = < {} nil, { pattern-node car, pattern cdr } cons >;
124
-
125
- $pattern
85
+ pattern = ? <
86
+ {} nil,
87
+ {
88
+ <
89
+ {} any,
90
+ <
91
+ {} nil,
92
+ {
93
+ {
94
+ <
95
+ {} nil,
96
+ {
97
+ <
98
+ {
99
+ < {} 0, {} 1 >=Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6
100
+ }=Bits7 ascii,
101
+ {
102
+ <
103
+ { Bit 0, Bit 1, Bit 2 }=Bits3 h08_0F,
104
+ Bits7 h10_7F,
105
+ Bits7 h80_CF,
106
+ Bits3 hD0_D7,
107
+ {} hF9,
108
+ { Bit 0 }=Bits1 hFA_FB,
109
+ Bits1 hFC_FD,
110
+ Bits1 hFE_FF
111
+ > hi,
112
+ { Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7 }=Bits8 lo
113
+ } bmp_common,
114
+ {
115
+ <
116
+ { Bit 0, Bit 1, Bit 2, Bit 3 } hE0_EF,
117
+ Bits3 hF0_F7,
118
+ {} hF8
119
+ > hi,
120
+ Bits8 lo
121
+ } bmp_private_use,
122
+ {
123
+ Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, Bit 8, Bit 9, Bit 10
124
+ } plane0,
125
+ { Bits8 mid, Bits8 lo } supplementary_plane1,
126
+ {
127
+ <
128
+ Bits1 p02_03,
129
+ { Bit 0, Bit 1 } p04_07,
130
+ Bits3 p08_0F,
131
+ {} p10
132
+ > plane,
133
+ Bits8 mid,
134
+ Bits8 lo
135
+ } supplementary_planes2_16
136
+ > car,
137
+ String cdr
138
+ } cons
139
+ > = String label,
140
+ < Bits 0, Bits 1, {} _ > = Bits target
141
+ } car,
142
+ Edges cdr
143
+ } cons
144
+ > = Edges open-product,
145
+ Edges open-union,
146
+ Edges closed-product,
147
+ Edges closed-union
148
+ > car,
149
+ Pattern cdr
150
+ } cons
151
+ > = Pattern;
152
+
153
+ pattern