@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.
- package/CHANGELOG.md +55 -0
- package/CLAUDE.md +1 -1
- package/DOCS/BIG_PICTURE.md +156 -172
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
- package/DOCS/CODEC_ARCHITECTURE.md +2 -2
- package/DOCS/DICTIONARY.md +243 -250
- package/DOCS/DIVERGENCE_DETECTION.md +0 -1
- package/DOCS/FILE_FORMATS.md +5 -5
- package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
- package/DOCS/PATTERNS.md +17 -17
- package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
- package/DOCS/REPL.md +9 -19
- package/DOCS/TYPE_DERIVATION.md +2 -8
- package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
- package/DOCS/book/01-introduction.md +8 -11
- package/DOCS/book/02-syntax-and-values.md +19 -20
- package/DOCS/book/03-types-as-finite-automata.md +42 -43
- package/DOCS/book/04-partial-functions-and-composition.md +2 -3
- package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
- package/DOCS/book/06-values-in-memory.md +10 -10
- package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
- package/DOCS/book/09-compiler-architecture.md +11 -11
- package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
- package/DOCS/book/14-canonical-serialization.md +2 -2
- package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
- package/DOCS/book.md +5 -5
- package/Examples/arithmetics.k +49 -153
- package/Examples/bnat.k +13 -13
- package/Examples/byte.k +2 -50
- package/Examples/ieee.k +408 -423
- package/Examples/karatsuba-mult.k +30 -34
- package/Examples/nat.k +5 -6
- package/README.md +54 -49
- package/TODO.md +13 -18
- package/backend-api.mjs +9 -1
- package/backends/llvm/scripts/run-tests.mjs +5 -0
- package/backends/llvm/src/kvm2llvm.mjs +2 -1
- package/backends/llvm/src/llvm.mjs +18 -25
- package/backends/llvm/tests/integration.sh +2 -2
- package/backends/llvm/tests/test-llvm.mjs +3 -3
- package/backends/llvm/tests/test-open-product-misalignment.mjs +140 -0
- package/backends/wasm/demo_ieee.mjs +2 -3
- package/backends/wasm/runtime.wat +157 -5
- package/backends/wasm/src/kvm2wasm.mjs +57 -34
- package/backends/wasm/src/wasm.mjs +38 -17
- package/backends/wasm/tests/perf-support.mjs +4 -4
- package/backends/wasm/tests/test-wasm.mjs +13 -14
- package/browser/vfs-data.mjs +12 -12
- package/codecs/BINARY_FORMAT.md +4 -4
- package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
- package/codecs/README.md +6 -6
- package/codecs/ieee.mjs +15 -11
- package/codecs/int.mjs +9 -5
- package/codecs/string-codec.mjs +46 -47
- package/core.k +123 -95
- package/kir.mjs +213 -17
- package/object.mjs +0 -7
- package/package.json +5 -2
- package/parser.jison +2 -41
- package/parser.mjs +55 -95
- package/pretty.mjs +11 -4
- package/repl.mjs +8 -63
- package/scripts/build-repl-html.mjs +8 -38
- package/tests/code-derivation/blowup.mjs +2 -4
- package/tests/code-derivation/bnat.mjs +2 -3
- package/tests/code-derivation/dot.mjs +5 -11
- package/tests/code-derivation/nat.mjs +2 -2
- package/tests/code-derivation/not-not.mjs +6 -6
- package/tests/code-derivation/pattern-envelope.mjs +4 -6
- package/tests/code-derivation/product.mjs +3 -6
- package/tests/code-derivation/rlz.mjs +4 -5
- package/tests/test-codecs.mjs +1 -1
- package/tests/test-fingerprint.mjs +36 -41
- package/tests/test-hash-normalization.mjs +4 -6
- package/tests/test-ieee-arithmetic.mjs +6 -7
- package/tests/test-k-object.mjs +11 -15
- package/tests/test-kir.mjs +0 -1
- package/tests/test-kvm-polymorphic.mjs +1 -2
- package/tests/test-kvm.mjs +8 -11
- package/tests/test-repl-html.mjs +20 -2
- package/tests/test-repl.mjs +48 -53
- package/tests/test.mjs +2 -3
package/codecs/BINARY_FORMAT.md
CHANGED
|
@@ -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(
|
|
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
|
|
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
|
|
29
|
+
encoded-pattern + value-bitstream
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
where:
|
|
33
33
|
|
|
34
|
-
- `encoded
|
|
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
|
|
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(
|
|
280
|
+
encode(pattern_value : pattern) encode(value : decoded_pattern)
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
-
The first segment is a normal k value of type
|
|
284
|
-
fixed singleton pattern for
|
|
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
|
|
10
|
-
value, using the
|
|
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
|
|
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(
|
|
66
|
+
encode(pattern_value : pattern) encode(value : decoded_pattern)
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
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
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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) {
|
package/codecs/string-codec.mjs
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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.
|
|
5
|
-
-- 2.
|
|
6
|
-
-- 3.
|
|
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
|
-
|
|
12
|
+
bit = ?< {} 0, {} 1 >;
|
|
13
13
|
|
|
14
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
78
|
+
-- Edges reference nodes by their index in this list, encoded as bits.
|
|
117
79
|
--
|
|
118
|
-
-- The singleton pattern of
|
|
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
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|