@fraczak/k 8.4.1 → 8.5.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 (116) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/DOCS/ARCHITECTURE.md +83 -0
  3. package/DOCS/CODECS.md +93 -204
  4. package/DOCS/DICTIONARY.md +42 -1241
  5. package/DOCS/FILE_FORMATS.md +170 -625
  6. package/DOCS/GETTING_STARTED.md +164 -0
  7. package/DOCS/KIR_V1.md +22 -33
  8. package/DOCS/KVM_EXECUTION_MODEL.md +88 -481
  9. package/DOCS/PATTERNS.md +155 -138
  10. package/DOCS/POLYMORPHIC_IR.md +83 -101
  11. package/DOCS/PROFILING_AND_TRACING.md +52 -166
  12. package/DOCS/README.md +35 -0
  13. package/DOCS/REPL.md +100 -377
  14. package/DOCS/TEXTUAL_VALUES.md +53 -81
  15. package/DOCS/TYPE_DERIVATION.md +95 -234
  16. package/DOCS/book-combined.md +3786 -0
  17. package/Examples/arithmetics.k +45 -59
  18. package/Examples/djson.k +102 -112
  19. package/Examples/karatsuba-mult.k +2 -3
  20. package/Examples/list.k +6 -7
  21. package/Examples/nat.k +6 -6
  22. package/Examples/poly.k +45 -45
  23. package/LICENSE +15 -0
  24. package/README.md +72 -410
  25. package/backends/llvm/README.md +75 -97
  26. package/backends/llvm/src/kvm2llvm.mjs +5 -4
  27. package/backends/llvm/src/llvm.mjs +2 -1
  28. package/backends/llvm/tests/integration.sh +7 -0
  29. package/backends/llvm/tests/test-llvm.mjs +20 -0
  30. package/backends/wasm/README.md +88 -66
  31. package/backends/wasm/src/kvm2wasm.mjs +64 -18
  32. package/backends/wasm/tests/integration.sh +5 -0
  33. package/backends/wasm/tests/test-wasm.mjs +86 -2
  34. package/canonical-pattern.mjs +7 -3
  35. package/codecs/README.md +23 -261
  36. package/codecs/WIRE_FORMAT.md +132 -0
  37. package/core.k +5 -15
  38. package/named-patterns.mjs +19 -7
  39. package/objects/README.md +24 -109
  40. package/package.json +8 -3
  41. package/paper/Makefile +17 -0
  42. package/paper/k-paper.pdf +0 -0
  43. package/paper/k-paper.tex +435 -0
  44. package/parser.jison +0 -10
  45. package/parser.mjs +32 -43
  46. package/repl.mjs +74 -29
  47. package/scripts/benchmark-idempotency.mjs +3 -3
  48. package/scripts/run-tests.mjs +1 -1
  49. package/scripts/test-package.mjs +64 -0
  50. package/tests/README.md +66 -46
  51. package/tests/code-derivation/core.mjs +61 -0
  52. package/tests/helpers/cli.mjs +45 -0
  53. package/tests/integration.sh +2 -3
  54. package/tests/test-arithmetics.mjs +47 -237
  55. package/tests/test-djson-methods.mjs +71 -275
  56. package/tests/test-hash-normalization.mjs +22 -1
  57. package/tests/test-karatsuba.mjs +18 -126
  58. package/tests/test-named-patterns.mjs +174 -621
  59. package/tests/test-paper-examples.mjs +90 -0
  60. package/tests/test-poly.mjs +2 -2
  61. package/tests/test-repl-html.mjs +22 -10
  62. package/tests/test-repl.mjs +49 -41
  63. package/tests/test.mjs +27 -68
  64. package/AGENTS.md +0 -35
  65. package/CLAUDE.md +0 -64
  66. package/DOCS/BIG_PICTURE.md +0 -439
  67. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +0 -74
  68. package/DOCS/CANONICAL_PATTERNS.md +0 -362
  69. package/DOCS/CODEC_ARCHITECTURE.md +0 -257
  70. package/DOCS/CONVERGENCE.md +0 -123
  71. package/DOCS/DIVERGENCE_DETECTION.md +0 -23
  72. package/DOCS/JSON_APPROACHES_COMPARISON.md +0 -302
  73. package/DOCS/KIR_SPECIALIZATION_DESIGN.md +0 -472
  74. package/DOCS/Makefile +0 -99
  75. package/DOCS/NAMED_PATTERNS.md +0 -361
  76. package/DOCS/OBJECT_FILE_AND_PATTERN.md +0 -343
  77. package/DOCS/PATTERNS_AND_TYPED_VALUES.md +0 -665
  78. package/DOCS/WEB_REPL_REQUIREMENTS.md +0 -134
  79. package/DOCS/book/01-introduction.md +0 -48
  80. package/DOCS/book/02-syntax-and-values.md +0 -110
  81. package/DOCS/book/03-types-as-finite-automata.md +0 -155
  82. package/DOCS/book/04-partial-functions-and-composition.md +0 -145
  83. package/DOCS/book/05-typing-filters-and-normalization.md +0 -109
  84. package/DOCS/book/06-values-in-memory.md +0 -1085
  85. package/DOCS/book/07-the-partial-function-abi.md +0 -143
  86. package/DOCS/book/08-operational-semantics-and-execution.md +0 -196
  87. package/DOCS/book/09-compiler-architecture.md +0 -160
  88. package/DOCS/book/10-from-ast-to-intermediate-representation.md +0 -166
  89. package/DOCS/book/14-canonical-serialization.md +0 -176
  90. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +0 -156
  91. package/DOCS/book/overview.txt +0 -68
  92. package/DOCS/book.md +0 -50
  93. package/Examples/bnat.k +0 -308
  94. package/Examples/buda.k +0 -66
  95. package/Examples/byte.k +0 -35
  96. package/Examples/code.k +0 -43
  97. package/Examples/vhdl_to_k.k +0 -67
  98. package/JOURNAL.md +0 -288
  99. package/TODO.md +0 -107
  100. package/backends/wasm/DOCS/USE-WEB-ASSEMBLY.md +0 -233
  101. package/backends/wasm/TECHNICAL-DEBT.md +0 -58
  102. package/backends/wasm/demo_ieee.mjs +0 -318
  103. package/browser/vfs-data.mjs +0 -21
  104. package/codecs/BINARY_FORMAT.md +0 -53
  105. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +0 -303
  106. package/codecs/pandoc.css +0 -71
  107. package/tests/code-derivation/blowup.mjs +0 -25
  108. package/tests/code-derivation/bnat.mjs +0 -11
  109. package/tests/code-derivation/dot.mjs +0 -37
  110. package/tests/code-derivation/index.mjs +0 -20
  111. package/tests/code-derivation/loop.mjs +0 -17
  112. package/tests/code-derivation/nat.mjs +0 -10
  113. package/tests/code-derivation/not-not.mjs +0 -14
  114. package/tests/code-derivation/product.mjs +0 -22
  115. package/tests/code-derivation/rlz.mjs +0 -13
  116. package/tests/test-fingerprint.mjs +0 -38
@@ -1,53 +0,0 @@
1
- # Binary Packaging Notes
2
-
3
- This document no longer defines the active codec semantics.
4
-
5
- The active format is the self-hosted pattern-plus-prefix-tree stream described
6
- in [`POLYMORPHIC_BINARY_FORMAT.md`](./POLYMORPHIC_BINARY_FORMAT.md):
7
-
8
- ```text
9
- encode(pattern_value : pattern) encode(value : decoded_pattern)
10
- ```
11
-
12
- ## Purpose of This File
13
-
14
- This file records constraints for any future optimized container layered above
15
- the canonical stream.
16
-
17
- The design sequence is:
18
-
19
- 1. define the abstract pattern graph,
20
- 2. define prefix-free value-tree encoding relative to that graph,
21
- 3. encode the pattern itself as a k `pattern` value,
22
- 4. optionally add higher-level indexes or compression as separate layers.
23
-
24
- ## Expected Container Shape
25
-
26
- The canonical stream contains:
27
-
28
- ```text
29
- encoded-pattern + value-bitstream
30
- ```
31
-
32
- where:
33
-
34
- - `encoded-pattern` is the k value representation defined in `core.k`,
35
- - the value bitstream is exactly the same prefix-free payload described by the
36
- semantic codec.
37
-
38
- ## Non-Goals
39
-
40
- This future binary package should not redefine the semantic codec.
41
-
42
- In particular, it should not introduce as part of the base semantics:
43
-
44
- - byte-oriented node tables,
45
- - mandatory DAG encoding,
46
- - transport-driven structural compromises.
47
-
48
- Those are explicitly outside the target architecture of the rewrite.
49
-
50
- ## Current Format
51
-
52
- The working concrete format is the canonical stream above. JSON property-list
53
- patterns are debug notation only, not a transport container.
@@ -1,303 +0,0 @@
1
- # K Prefix-Free Pattern Codec
2
-
3
- ## Purpose
4
-
5
- This document defines the new target semantics for binary codecs in `k`.
6
-
7
- The object to be serialized is:
8
-
9
- ```text
10
- (P, v)
11
- ```
12
-
13
- where:
14
-
15
- - `P` is a rooted pattern graph,
16
- - `v` is a value tree compatible with `P`.
17
-
18
- This is both the transport semantics and the runtime value semantics. In the
19
- current JavaScript runtime, the materialized `Value` stores the pattern as
20
- `value.pattern`; the tree is still represented by `Product` and `Variant`
21
- nodes.
22
-
23
- The codec is designed around:
24
-
25
- 1. compactness,
26
- 2. efficient structural navigation,
27
- 3. a clean separation between semantic encoding and optional acceleration
28
- structures.
29
-
30
- This document defines the semantic codec and the canonical wire stream.
31
-
32
- ## Design Principles
33
-
34
- ### 1. Pattern is the structural authority
35
-
36
- The pattern determines:
37
-
38
- - whether a node is a product or union,
39
- - whether it is open or closed,
40
- - what field names or tag names exist,
41
- - how recursive positions are connected.
42
-
43
- The value payload is interpreted relative to the pattern.
44
- During execution, the same pattern context is propagated with materialized
45
- values, so structural operations do not have to reconstruct framing information
46
- after the fact.
47
-
48
- ### 2. Values are trees in the base codec
49
-
50
- The base codec serializes value trees, not value DAGs.
51
-
52
- DAG compression is not part of the primitive codec. If wanted, it should happen
53
- as a separate transform above the base value encoding.
54
-
55
- ### 3. Prefix-free value encoding
56
-
57
- The value payload is a prefix-free bitstream.
58
-
59
- Products rely on structural concatenation.
60
- Unions emit a choice code, then the payload of the selected branch.
61
-
62
- ### 4. One canonical stream
63
-
64
- The pattern graph is embedded as an ordinary k `pattern` value. The canonical
65
- stream is that encoded pattern followed by the value payload interpreted under
66
- the decoded pattern.
67
-
68
- ## Pattern Graph
69
-
70
- ### Semantic node kinds
71
-
72
- There are exactly five node kinds:
73
-
74
- - `any`
75
- - `open-product`
76
- - `open-union`
77
- - `closed-product`
78
- - `closed-union`
79
-
80
- Their informal meanings are:
81
-
82
- - `any`
83
- unconstrained position,
84
- - `open-product`
85
- explicit fields plus possibly more fields in the matched value,
86
- - `open-union`
87
- explicit tags plus possibly more tags in the matched value,
88
- - `closed-product`
89
- exactly the listed fields,
90
- - `closed-union`
91
- exactly the listed tags.
92
-
93
- In the base codec, `any` is not directly value-carrying.
94
-
95
- ### Graph structure
96
-
97
- A pattern graph node is:
98
-
99
- ```text
100
- [kind, edges]
101
- ```
102
-
103
- where `edges` is a list of:
104
-
105
- ```text
106
- [label, target_node_id]
107
- ```
108
-
109
- The root node is node `0`.
110
-
111
- ### Canonical constraints
112
-
113
- - node `0` is the root,
114
- - node order is canonical graph-discovery order,
115
- - edges are sorted by label,
116
- - no duplicate labels occur within one node,
117
- - `any` has no outgoing edges.
118
-
119
- ### Readable property-list notation
120
-
121
- For documentation and tests, the abstract graph may be rendered as:
122
-
123
- ```json
124
- {
125
- "pattern": [
126
- ["closed-union", [["nil", 1], ["cons", 2]]],
127
- ["closed-product", []],
128
- ["closed-product", [["car", 3], ["cdr", 0]]],
129
- ["closed-union", [["_", 1], ["0", 3], ["1", 3]]]
130
- ]
131
- }
132
- ```
133
-
134
- This syntax is only a readable notation for the abstract graph.
135
-
136
- ## Pattern Construction From A Witness Tree
137
-
138
- When no external pattern or type is supplied, the codec tools derive a
139
- pattern from the value tree itself.
140
-
141
- - `{}` derives the closed product leaf `["closed-product", []]`.
142
- - A textual tree node with multiple children derives a closed product.
143
- - A textual tree node with exactly one child derives an open union.
144
- - If an explicit product pattern is supplied, that pattern can disambiguate the
145
- same one-child textual node as a singleton product.
146
-
147
- Example:
148
-
149
- ```text
150
- {a:{b:x,c:{}}}
151
- ```
152
-
153
- derives:
154
-
155
- ```json
156
- [
157
- ["open-union", [["a", 1]]],
158
- ["closed-product", [["b", 2], ["c", 3]]],
159
- ["open-union", [["x", 3]]],
160
- ["closed-product", []]
161
- ]
162
- ```
163
-
164
- The derived graph is canonicalized by a bottom-up closed-node collapse. Starting
165
- from the closed empty product, two closed nodes are collapsible only when their
166
- kind, labels, and already-collapsed children are identical. Open nodes are not
167
- collapsed, and this rule is not value-DAG compression.
168
-
169
- ## Value Encoding
170
-
171
- ### General shape
172
-
173
- The value encoding is defined recursively relative to the current pattern node.
174
-
175
- #### Product node
176
-
177
- For `open-product` or `closed-product`:
178
-
179
- ```text
180
- encode(v_0) encode(v_1) ... encode(v_(n-1))
181
- ```
182
-
183
- in canonical edge order.
184
-
185
- There are no separators between children. The pattern determines where each
186
- child begins and ends.
187
-
188
- #### Union node
189
-
190
- For `open-union` or `closed-union`:
191
-
192
- ```text
193
- encode-choice(tag_ordinal, tag_count)
194
- encode(selected_payload)
195
- ```
196
-
197
- #### Any node
198
-
199
- `any` is not directly value-carrying in the base format.
200
-
201
- If a value would need to descend into an `any` position, the pattern must first
202
- be refined.
203
-
204
- ## Choice Encoding
205
-
206
- The initial concrete choice encoding is fixed-width by cardinality:
207
-
208
- ```text
209
- width(cardinality) = ceil(log2(cardinality))
210
- ```
211
-
212
- A choice with:
213
-
214
- - `cardinality = n`
215
- - `ordinal in [0, n)`
216
-
217
- is encoded as the binary representation of `ordinal` in `width(n)` bits.
218
-
219
- Examples:
220
-
221
- - `n = 1`: `0` bits,
222
- - `n = 2`: `1` bit,
223
- - `n = 3`: `2` bits,
224
- - `n = 4`: `2` bits,
225
- - `n = 5`: `3` bits.
226
-
227
- This is the initial canonical rule for the rewrite. More aggressive coding
228
- schemes may be considered later, but only after the abstract semantics are
229
- stable.
230
-
231
- ## Operational Properties
232
-
233
- ### `/tag`
234
-
235
- At a union node:
236
-
237
- 1. read the choice code,
238
- 2. compare it to the requested tag ordinal,
239
- 3. if it matches, continue with the selected payload.
240
-
241
- This makes `/tag` naturally efficient.
242
-
243
- ### `.field`
244
-
245
- At a product node, child values appear in canonical field order.
246
-
247
- So `.field` is resolved by:
248
-
249
- 1. locating the field ordinal in the pattern,
250
- 2. decoding or skipping earlier children,
251
- 3. decoding the requested child subtree.
252
-
253
- The base codec does not include field-offset indexes. Such indexes may be added
254
- later as separate higher-level acceleration structures.
255
-
256
- In the materialized evaluator, `.field` applies the analogous pattern operation:
257
- the output `Value` carries the subpattern reached by the selected field.
258
- Likewise, `/tag` carries the subpattern reached by the selected variant tag.
259
-
260
- ## Recursive Types
261
-
262
- Recursive pattern graphs are first-class.
263
-
264
- For example, a bit-list-like recursive type:
265
-
266
- ```text
267
- ["closed-union", [["_", 1], ["0", 3], ["1", 3]]]
268
- ```
269
-
270
- is encoded as repeated union choices in a value tree, not as a byte-aligned node
271
- table and not as a built-in primitive integer format.
272
-
273
- This keeps the codec uniform: recursion is handled by the pattern graph itself.
274
-
275
- ## Canonical Wire Format
276
-
277
- The transport format is:
278
-
279
- ```text
280
- encode(pattern_value : pattern) encode(value : decoded_pattern)
281
- ```
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
285
- is then used as the structural authority for the second segment.
286
-
287
- Decoding the stream yields `Value(pattern, tree)`. Encoding a runtime `Value`
288
- uses its carried pattern by default, or an explicit caller-supplied pattern when
289
- one is provided.
290
-
291
- ## Out of Scope for the Base Codec
292
-
293
- The following are intentionally outside the primitive codec:
294
-
295
- - DAG compression,
296
- - subtree deduplication,
297
- - projection indexes,
298
- - alternate transport-specific framing,
299
- - alternate binary pattern serialization,
300
- - exact-type-only specializations.
301
-
302
- These may be added later, but they are not part of the base pattern-plus-tree
303
- prefix codec.
package/codecs/pandoc.css DELETED
@@ -1,71 +0,0 @@
1
- html {
2
- line-height: 1.5;
3
- font-family: Georgia, "Times New Roman", serif;
4
- color: #1f2328;
5
- background: #ffffff;
6
- }
7
-
8
- body {
9
- max-width: 980px;
10
- margin: 2rem auto 4rem;
11
- padding: 0 1.25rem;
12
- }
13
-
14
- h1, h2, h3, h4 {
15
- line-height: 1.2;
16
- margin-top: 1.8rem;
17
- }
18
-
19
- h1 {
20
- border-bottom: 1px solid #d0d7de;
21
- padding-bottom: 0.3rem;
22
- }
23
-
24
- p, li {
25
- max-width: 78ch;
26
- }
27
-
28
- pre, code {
29
- font-family: "Iosevka Term", "SFMono-Regular", Consolas, monospace;
30
- }
31
-
32
- code {
33
- background: #f6f8fa;
34
- padding: 0.1rem 0.25rem;
35
- border-radius: 4px;
36
- }
37
-
38
- pre {
39
- background: #f6f8fa;
40
- border: 1px solid #d0d7de;
41
- border-radius: 8px;
42
- padding: 0.9rem 1rem;
43
- overflow-x: auto;
44
- }
45
-
46
- pre code {
47
- background: transparent;
48
- padding: 0;
49
- }
50
-
51
- blockquote {
52
- margin-left: 0;
53
- padding-left: 1rem;
54
- border-left: 4px solid #d0d7de;
55
- color: #57606a;
56
- }
57
-
58
- table {
59
- border-collapse: collapse;
60
- margin: 1rem 0;
61
- }
62
-
63
- th, td {
64
- border: 1px solid #d0d7de;
65
- padding: 0.4rem 0.7rem;
66
- vertical-align: top;
67
- }
68
-
69
- th {
70
- background: #f6f8fa;
71
- }
@@ -1,25 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import fs from 'node:fs';
3
- import assert from 'assert';
4
-
5
- // t(fs.readFileSync("./Examples/blowup.k", "utf8"), (annotated) => {
6
- // // console.log(JSON.stringify(annotated,null,2));
7
- // const {input,output} = in_out(annotated);
8
- // console.log(input);
9
- // console.log(output);
10
- // assert.equal(output.pattern, '<...>');
11
- // assert.equal(input.pattern, '(...)');
12
- // console.log("OK");
13
- // });
14
-
15
- t(`
16
- B = {}|u A;
17
- A = ?X < /a, /b ?X A, /c |z ?X A, B >;
18
- A
19
- `, (annotated) => {
20
- // console.log(JSON.stringify(annotated,null,2));
21
- const {input,output} = in_out(annotated);
22
- assert.equal(output.pattern, '(...)');
23
- assert.equal(input.pattern, '<...>');
24
- console.log("OK");
25
- });
@@ -1,11 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import fs from 'node:fs';
3
- import assert from 'assert';
4
-
5
- t(fs.readFileSync("./Examples/bnat.k", "utf8"), (annotated) => {
6
- // console.log(JSON.stringify(annotated,null,2));
7
- const {input,output} = in_out(annotated);
8
- assert.equal(output.type, "@VtPHxGf5GNMzzyVFxtv7gegFfJRYapBGtCeyV56bs5Zb");
9
- assert.equal(input.type, "@R7RD2sgu6yPqpCQBBcJqkzxHQMZfEJLcNW4UKBcTiC3m");
10
- console.log("OK");
11
- });
@@ -1,37 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import { hash } from '../../hash.mjs';
3
- import assert from 'assert';
4
-
5
- t(`
6
- 1 = {} |1 ?< {} 0, {} 1 >;
7
- ?< {} true, {} false > {1 one, () two, () c} .one
8
-
9
- `, (annotated) => {
10
- const {input,output} = in_out(annotated);
11
- assert.equal(input.type, "@GWnxJCupZr96BZfdpDsfQQKxKjCbjyDh7Qaur7y9enCY");
12
- assert.equal(output.type, "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg");
13
- console.log("OK");
14
- });
15
-
16
- t(`
17
- ?< <{} 0, {} 1> true, <{} 0, {} 1> false > /true
18
- `, (annotated) => {
19
- const {input,output} = in_out(annotated);
20
- console.log({input,output});
21
- });
22
-
23
- t(`
24
- x = /x;
25
- xy = x/y;
26
- f = {
27
- {} | y | x xy i,
28
- {} | y | x xy b
29
- };
30
- f .b
31
- `, (annotated) => {
32
- const {input,output} = in_out(annotated);
33
- console.log({input,output});
34
- assert.equal(input.pattern, '(...)');
35
- assert.equal(output.type, hash("$C0={};"));
36
- console.log("OK");
37
- });
@@ -1,20 +0,0 @@
1
- import { annotate } from "../../index.mjs";
2
-
3
- function in_out(annotated) {
4
- const [input,output] = annotated.rels.__main__.def.patterns.map( (pat) =>
5
- annotated.rels.__main__.typePatternGraph.get_pattern(pat)
6
- );
7
- return { input, output };
8
- }
9
-
10
-
11
- function t(script, cb = (annotated) => console.log(in_out(annotated))) {
12
- // console.log("--- Testing Code Derivation ---");
13
- const annotated = annotate(script);
14
- // console.log(JSON.stringify(annotated, "", 2));
15
- return cb(annotated);
16
- }
17
-
18
- export default { t, in_out };
19
- export { t, in_out };
20
-
@@ -1,17 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import assert from 'assert';
3
-
4
- t(` < /a, () > `, (annotated) => {
5
- const {input,output} = in_out(annotated);
6
- assert.equal(input.pattern, "<...>");
7
- assert.equal(output, input);
8
- console.log("OK");
9
- });
10
- t(` < .a, () > `, (annotated) => {
11
- const {input,output} = in_out(annotated);
12
- assert.equal(input.pattern, "{...}");
13
- assert.equal(output, input);
14
- console.log("OK");
15
- });
16
-
17
- // Notice that the following are equivalent: '<(), /a>', '<()>', and '()';
@@ -1,10 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import fs from 'node:fs';
3
- import assert from 'assert';
4
-
5
- t(fs.readFileSync("./Examples/nat.k", "utf8"), (annotated) => {
6
- const {input,output} = in_out(annotated);
7
- assert.equal(output.type, input.type);
8
- assert.equal(output.type, "@e9WP6QX6URfgnd9hHYrrYUBhiL7UcvbWErVmyQJfFcr8");
9
- console.log("OK");
10
- });
@@ -1,14 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import assert from 'assert';
3
-
4
- t(`
5
- true = {} |true;
6
- false = {} |false;
7
- not = ?< {} true, {} false > < /true false, /false true > ?< {} true, {} false >;
8
- not not
9
- `, (annotated) => {
10
- const {input,output} = in_out(annotated);
11
- assert.equal(input.type, output.type);
12
- assert.equal(input.type, "@GWnxJCupZr96BZfdpDsfQQKxKjCbjyDh7Qaur7y9enCY");
13
- console.log("OK");
14
- });
@@ -1,22 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import assert from 'assert';
3
- import hash from "../../hash.mjs";
4
-
5
- const unitCode = hash('$C0={};');
6
-
7
- t('{}', (annotated) => {
8
- const {input,output} = in_out(annotated);
9
- assert.equal(input.pattern, '(...)');
10
- assert.equal(output.type, unitCode);
11
- console.log("OK");
12
- });
13
-
14
- t(`
15
- ?< {} true, {} false > {() one, () two} ?{ < {} true, {} false > one, < {} true, {} false > two }
16
- `, (annotated) => {
17
- const {input,output} = in_out(annotated);
18
-
19
- assert.equal(input.type, "@GWnxJCupZr96BZfdpDsfQQKxKjCbjyDh7Qaur7y9enCY");
20
- assert.equal(output.type, "@ZR2yff4pdXTVqZdMu9x3t9GG5rwmhEfQuenbAwFnD2Nk");
21
- console.log("OK");
22
- });
@@ -1,13 +0,0 @@
1
- import { t, in_out } from './index.mjs';
2
- import assert from 'assert';
3
-
4
- t(`
5
- zero = {}|_|0;
6
- rlz = ?<X 0, X 1, {} _>=X </0/_ zero, /0 rlz, ()> ?X;
7
- rlz
8
- `, (annotated) => {
9
- const {input,output} = in_out(annotated);
10
- assert.equal(output.type, input.type);
11
- assert.equal(output.type, "@VtPHxGf5GNMzzyVFxtv7gegFfJRYapBGtCeyV56bs5Zb");
12
- console.log("OK");
13
- });
@@ -1,38 +0,0 @@
1
- import codes, { encodeCodeToString } from '../codes.mjs';
2
- import hash from '../hash.mjs';
3
- import assert from 'assert';
4
-
5
- console.log("test-fingerprint:");
6
- const codeDefs = {
7
- bits: { code: "union", union: { "0": "bits", "1": "bits", "_": "{}" } },
8
- nat: { code: "union", union: { zero: "{}", succ: "nat" } },
9
- pair: { code: "product", product: { x: "nat", y: "nat" } },
10
- b: { code: "product", product: { x: "bits", y: "bits" } },
11
- tree: { code: "union", union: {
12
- binary: "binNode",
13
- leaf: "nat",
14
- unary: "unNode"
15
- } },
16
- binNode: { code: "product", product: { value: "nat", left: "tree", right: "tree" } },
17
- unNode: { code: "product", product: { value: "nat", tree: "tree" } },
18
- "{}": { code: "product", product: {} }
19
- };
20
-
21
- const reps = codes.register(codeDefs);
22
- let errors = 0;
23
- for (const code in reps) {
24
- const rep = reps[code];
25
- const s = encodeCodeToString(rep);
26
- const h = hash(s);
27
- if (rep !== h) {
28
- errors++;
29
- console.log(` ERROR - fingerprint mismatch for ${code}: ${rep} !== ${h}`);
30
- }
31
- }
32
-
33
- if (errors === 0) {
34
- console.log("OK");
35
- } else {
36
- console.log(" ----- ERRORS");
37
- }
38
-