@fraczak/k 6.10.2 → 6.10.4
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 +73 -0
- package/DOCS/BIG_PICTURE.md +174 -100
- package/DOCS/CODECS.md +74 -29
- package/DOCS/CODEC_ARCHITECTURE.md +87 -31
- package/DOCS/CONVERGENCE.md +42 -11
- package/DOCS/DICTIONARY.md +69 -2
- package/DOCS/FILE_FORMATS.md +420 -0
- package/DOCS/KIR_V1.md +53 -42
- package/DOCS/KVM_EXECUTION_MODEL.md +189 -147
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +35 -17
- package/DOCS/PATTERNS.md +10 -6
- package/DOCS/REPL.md +100 -60
- package/DOCS/TEXTUAL_VALUES.md +24 -19
- package/DOCS/TYPE_DERIVATION.md +68 -22
- package/Examples/karatsuba-mult.k +215 -0
- package/README.md +92 -58
- package/backends/arm64/scripts/run-tests.mjs +16 -0
- package/backends/llvm/bin/k-llvm-build.mjs +40 -14
- package/backends/llvm/bin/k-llvm-compile.mjs +29 -12
- package/backends/llvm/runtime/krt.c +10 -10
- package/backends/llvm/runtime/krt.h +6 -1
- package/backends/llvm/scripts/run-tests.mjs +16 -0
- package/backends/llvm/src/cli.mjs +1 -1
- package/backends/llvm/src/executable.mjs +36 -0
- package/backends/llvm/src/kvm2llvm.mjs +10 -4
- package/backends/llvm/tests/integration.sh +11 -0
- package/backends/llvm/tests/test-llvm.mjs +15 -1
- package/backends/wasm/scripts/run-tests.mjs +16 -0
- package/browser/vfs-data.mjs +1 -1
- package/codecs/README.md +78 -67
- package/core.k +5 -5
- package/objects/README.md +57 -37
- package/package.json +2 -1
- package/scripts/benchmark-idempotency.mjs +27 -0
- package/scripts/benchmark.mjs +51 -0
- package/scripts/build-repl-html.mjs +17 -0
- package/scripts/generate-dependency-graph.mjs +25 -1
- package/scripts/perf-ieee.mjs +75 -0
- package/scripts/perf-int.mjs +67 -0
- package/scripts/perf-multiplication.mjs +644 -0
- package/scripts/perf-poly.mjs +67 -0
- package/scripts/render-benchmark.mjs +25 -0
- package/scripts/run-tests.mjs +19 -0
- package/tests/README.md +28 -17
- package/tests/test-karatsuba.mjs +133 -0
package/codecs/README.md
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
# K Codecs
|
|
2
2
|
|
|
3
|
-
This directory is
|
|
3
|
+
This directory is centered on the codec design:
|
|
4
4
|
|
|
5
5
|
```text
|
|
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
|
-
using the `$pattern` type from [`../core.k`](../core.k),
|
|
11
|
-
the binary encoding of the value under that
|
|
9
|
+
The default concrete format is now the binary encoding of a `$pattern`
|
|
10
|
+
value, using the `$pattern` type from [`../core.k`](../core.k),
|
|
11
|
+
immediately followed by the binary encoding of the value under that
|
|
12
|
+
decoded pattern.
|
|
12
13
|
|
|
13
|
-
`core.k` is not loaded automatically as a library when user programs
|
|
14
|
-
codec only depends on the canonical `$pattern` definition from
|
|
15
|
-
schema for the leading pattern value.
|
|
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
|
|
16
|
+
that file as the schema for the leading pattern value.
|
|
16
17
|
|
|
17
18
|
There is no separate JSON container format.
|
|
18
19
|
|
|
19
20
|
## Objectives
|
|
20
21
|
|
|
21
|
-
The
|
|
22
|
+
The design is guided by two hard requirements:
|
|
22
23
|
|
|
23
24
|
1. compactness close to the structural lower bound,
|
|
24
25
|
2. efficient `k` projections, especially `.field` and `/tag`.
|
|
25
26
|
|
|
26
|
-
The current target architecture is the pattern graph plus prefix-free
|
|
27
|
-
stream described here and in
|
|
27
|
+
The current target architecture is the pattern graph plus prefix-free
|
|
28
|
+
value-tree stream described here and in
|
|
28
29
|
[`POLYMORPHIC_BINARY_FORMAT.md`](./POLYMORPHIC_BINARY_FORMAT.md).
|
|
29
30
|
|
|
30
31
|
## Core Idea
|
|
31
32
|
|
|
32
|
-
The semantic object serialized by the
|
|
33
|
+
The semantic object serialized by the codec is:
|
|
33
34
|
|
|
34
35
|
```text
|
|
35
36
|
(P, v)
|
|
@@ -40,10 +41,11 @@ where:
|
|
|
40
41
|
- `P` is an abstract rooted pattern graph,
|
|
41
42
|
- `v` is a value tree compatible with `P`.
|
|
42
43
|
|
|
43
|
-
The same pair is
|
|
44
|
-
attaches `P` to the resulting `Value` as `value.pattern`; evaluation
|
|
45
|
-
that pattern through projections and constructors; encoding
|
|
46
|
-
carried pattern unless an explicit pattern is
|
|
44
|
+
The same pair is the in-memory runtime model as well. Decoding a stream
|
|
45
|
+
attaches `P` to the resulting `Value` as `value.pattern`; evaluation
|
|
46
|
+
propagates that pattern through projections and constructors; encoding
|
|
47
|
+
a `Value` uses its carried pattern unless an explicit pattern is
|
|
48
|
+
supplied.
|
|
47
49
|
|
|
48
50
|
The base value encoding is:
|
|
49
51
|
|
|
@@ -52,9 +54,9 @@ The base value encoding is:
|
|
|
52
54
|
- interpreted relative to the pattern graph,
|
|
53
55
|
- free of repeated field names and tag names in the value payload.
|
|
54
56
|
|
|
55
|
-
The base codec does **not** perform DAG compression. If sharing is
|
|
56
|
-
should happen as a higher-level transform, not inside the
|
|
57
|
-
format.
|
|
57
|
+
The base codec does **not** perform DAG compression. If sharing is
|
|
58
|
+
desired, it should happen as a higher-level transform, not inside the
|
|
59
|
+
primitive value format.
|
|
58
60
|
|
|
59
61
|
## Wire Format
|
|
60
62
|
|
|
@@ -64,9 +66,9 @@ The default transport format is:
|
|
|
64
66
|
encode($pattern_value : $pattern) encode(value : decoded_pattern)
|
|
65
67
|
```
|
|
66
68
|
|
|
67
|
-
`$pattern_value` is a normal k value whose shape is defined in `core.k`.
|
|
68
|
-
that value is decoded, it becomes the pattern used to decode the
|
|
69
|
-
value payload.
|
|
69
|
+
`$pattern_value` is a normal k value whose shape is defined in `core.k`.
|
|
70
|
+
After that value is decoded, it becomes the pattern used to decode the
|
|
71
|
+
remaining value payload.
|
|
70
72
|
|
|
71
73
|
The runtime boundary is therefore:
|
|
72
74
|
|
|
@@ -74,25 +76,28 @@ The runtime boundary is therefore:
|
|
|
74
76
|
binary pattern+value stream <-> Value(pattern, tree)
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
At the command-line boundary, `k-parse` and `k-print` use a JSON-like
|
|
78
|
-
notation for k values. That notation is documented in
|
|
79
|
-
[`../DOCS/TEXTUAL_VALUES.md`](../DOCS/TEXTUAL_VALUES.md). It is a
|
|
80
|
-
notation for k values, not a separate JSON container format.
|
|
79
|
+
At the command-line boundary, `k-parse` and `k-print` use a JSON-like
|
|
80
|
+
textual notation for k values. That notation is documented in
|
|
81
|
+
[`../DOCS/TEXTUAL_VALUES.md`](../DOCS/TEXTUAL_VALUES.md). It is a
|
|
82
|
+
readable notation for k values, not a separate JSON container format.
|
|
81
83
|
|
|
82
84
|
For the codec architecture and specification, see
|
|
83
85
|
[`../DOCS/CODEC_ARCHITECTURE.md`](../DOCS/CODEC_ARCHITECTURE.md).
|
|
84
|
-
For the contributor-facing guide to writing a new external codec module,
|
|
85
|
-
[`../DOCS/CODECS.md`](../DOCS/CODECS.md).
|
|
86
|
+
For the contributor-facing guide to writing a new external codec module,
|
|
87
|
+
see [`../DOCS/CODECS.md`](../DOCS/CODECS.md).
|
|
88
|
+
For the broader view of all artifacts and compilation targets, see
|
|
89
|
+
[`../DOCS/FILE_FORMATS.md`](../DOCS/FILE_FORMATS.md).
|
|
86
90
|
|
|
87
|
-
`k.mjs` is only the command-line adapter for that boundary. The
|
|
88
|
-
runtime sees and preserves the pattern on the `Value`
|
|
91
|
+
`k.mjs` is only the command-line adapter for that boundary. The
|
|
92
|
+
operational runtime sees and preserves the pattern on the `Value`
|
|
93
|
+
itself.
|
|
89
94
|
|
|
90
95
|
## Command-Line Tools
|
|
91
96
|
|
|
92
|
-
Installed codec binaries use the `k-` prefix followed by the source
|
|
93
|
-
without `.mjs`. Source names that already include `k-`, such
|
|
94
|
-
`k-parse.mjs`, keep that name. Every installed codec binary supports
|
|
95
|
-
`--help`.
|
|
97
|
+
Installed codec binaries use the `k-` prefix followed by the source
|
|
98
|
+
basename without `.mjs`. Source names that already include `k-`, such
|
|
99
|
+
as `k-parse.mjs`, keep that name. Every installed codec binary supports
|
|
100
|
+
`-h` and `--help`.
|
|
96
101
|
|
|
97
102
|
| Binary | Source | Purpose |
|
|
98
103
|
| --- | --- | --- |
|
|
@@ -108,8 +113,8 @@ without `.mjs`. Source names that already include `k-`, such as
|
|
|
108
113
|
|
|
109
114
|
## Pattern Graph Representation
|
|
110
115
|
|
|
111
|
-
For documentation and tests, a pattern graph may be shown as a
|
|
112
|
-
style vector of nodes:
|
|
116
|
+
For documentation and tests, a pattern graph may be shown as a
|
|
117
|
+
property-list style vector of nodes:
|
|
113
118
|
|
|
114
119
|
```text
|
|
115
120
|
[kind, edges]
|
|
@@ -145,22 +150,23 @@ Canonical rules:
|
|
|
145
150
|
- edge labels are unique within a node,
|
|
146
151
|
- `"any"` must have no outgoing edges.
|
|
147
152
|
|
|
148
|
-
This JSON-like graph is only a readable notation. The wire
|
|
149
|
-
the ordinary k `$pattern` value from `core.k`.
|
|
153
|
+
This JSON-like graph is only a readable notation. The wire
|
|
154
|
+
representation is the ordinary k `$pattern` value from `core.k`.
|
|
150
155
|
|
|
151
|
-
For pattern export, see [`../DOCS/PATTERNS.md`](../DOCS/PATTERNS.md) and
|
|
152
|
-
repository helper `patterns/from-k.mjs`.
|
|
156
|
+
For pattern export, see [`../DOCS/PATTERNS.md`](../DOCS/PATTERNS.md) and
|
|
157
|
+
the repository helper `patterns/from-k.mjs`.
|
|
153
158
|
|
|
154
159
|
## Witness-Derived Patterns
|
|
155
160
|
|
|
156
|
-
When `k-parse` is used without an explicit input pattern or type, the
|
|
157
|
-
pattern is derived from the parsed value tree.
|
|
161
|
+
When `k-parse` is used without an explicit input pattern or type, the
|
|
162
|
+
wire pattern is derived from the parsed value tree.
|
|
158
163
|
|
|
159
164
|
- An empty textual node is a closed product: `{}`.
|
|
160
165
|
- A textual node with multiple children is a closed product.
|
|
161
|
-
- A textual node with one child is interpreted as an open union by
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
- A textual node with one child is interpreted as an open union by
|
|
167
|
+
default.
|
|
168
|
+
- An explicit product input pattern may force such a node to be
|
|
169
|
+
treated as a singleton product instead.
|
|
164
170
|
|
|
165
171
|
For example, parsing:
|
|
166
172
|
|
|
@@ -179,18 +185,20 @@ without an input pattern derives:
|
|
|
179
185
|
]
|
|
180
186
|
```
|
|
181
187
|
|
|
182
|
-
During this construction, finite closed pattern subtrees are hash-consed
|
|
183
|
-
the leaves upward. The starting closed leaf is `["closed-product",
|
|
184
|
-
closed nodes collapse only when they have the same closed
|
|
185
|
-
and the same already-collapsed child targets.
|
|
186
|
-
and recursive closed nodes are not
|
|
188
|
+
During this construction, finite closed pattern subtrees are hash-consed
|
|
189
|
+
from the leaves upward. The starting closed leaf is `["closed-product",
|
|
190
|
+
[]]`. Two closed nodes collapse only when they have the same closed
|
|
191
|
+
kind, the same labels, and the same already-collapsed child targets.
|
|
192
|
+
Open nodes keep their identity, and recursive closed nodes are not
|
|
193
|
+
collapsed by this witness-tree rule.
|
|
187
194
|
|
|
188
|
-
This is canonicalization of the pattern graph carried in the wire
|
|
189
|
-
not DAG compression of the value payload.
|
|
195
|
+
This is canonicalization of the pattern graph carried in the wire
|
|
196
|
+
stream. It is not DAG compression of the value payload.
|
|
190
197
|
|
|
191
198
|
## Prefix-Free Value Encoding
|
|
192
199
|
|
|
193
|
-
The value payload is a bitstream interpreted relative to the pattern
|
|
200
|
+
The value payload is a bitstream interpreted relative to the pattern
|
|
201
|
+
graph.
|
|
194
202
|
|
|
195
203
|
Base rules:
|
|
196
204
|
|
|
@@ -209,25 +217,27 @@ width = ceil(log2(cardinality))
|
|
|
209
217
|
emit tag ordinal in width bits
|
|
210
218
|
```
|
|
211
219
|
|
|
212
|
-
This is the simplest canonical prefix-free choice encoding. It is not
|
|
213
|
-
word on compression, but it gives a regular and compact base
|
|
214
|
-
later be refined without changing the abstract
|
|
220
|
+
This is the simplest canonical prefix-free choice encoding. It is not
|
|
221
|
+
the final word on compression, but it gives a regular and compact base
|
|
222
|
+
encoding that can later be refined without changing the abstract
|
|
223
|
+
pattern/value model.
|
|
215
224
|
|
|
216
225
|
## Projections
|
|
217
226
|
|
|
218
227
|
The base tree encoding is chosen so that:
|
|
219
228
|
|
|
220
229
|
- `/tag` only needs to read the union choice at the current node,
|
|
221
|
-
- `.field` follows canonical product order and may later be accelerated
|
|
222
|
-
higher-level indexes if necessary.
|
|
230
|
+
- `.field` follows canonical product order and may later be accelerated
|
|
231
|
+
by higher-level indexes if necessary.
|
|
223
232
|
|
|
224
|
-
In the materialized runtime, projections also project the carried
|
|
225
|
-
`.field` returns the subpattern at that product field, and
|
|
226
|
-
subpattern at that union tag. If no carried subpattern
|
|
227
|
-
encoding can still derive a witness pattern from
|
|
233
|
+
In the materialized runtime, projections also project the carried
|
|
234
|
+
pattern: `.field` returns the subpattern at that product field, and
|
|
235
|
+
`/tag` returns the subpattern at that union tag. If no carried subpattern
|
|
236
|
+
is available, later encoding can still derive a witness pattern from
|
|
237
|
+
the result tree.
|
|
228
238
|
|
|
229
|
-
The primitive codec stays minimal. Projection indexes, framing, or
|
|
230
|
-
schemes are explicitly separate concerns.
|
|
239
|
+
The primitive codec stays minimal. Projection indexes, framing, or
|
|
240
|
+
sharing schemes are explicitly separate concerns.
|
|
231
241
|
|
|
232
242
|
## Design Boundary
|
|
233
243
|
|
|
@@ -240,17 +250,18 @@ The new codec work is split into layers:
|
|
|
240
250
|
|
|
241
251
|
## Files
|
|
242
252
|
|
|
253
|
+
- [`../DOCS/FILE_FORMATS.md`](../DOCS/FILE_FORMATS.md):
|
|
254
|
+
comprehensive guide to file formats and compilation pipelines.
|
|
243
255
|
- [`../DOCS/CODEC_ARCHITECTURE.md`](../DOCS/CODEC_ARCHITECTURE.md):
|
|
244
256
|
comprehensive architecture specification for k codecs.
|
|
245
257
|
- [`../DOCS/CODECS.md`](../DOCS/CODECS.md):
|
|
246
258
|
practical guide to writing, running, and testing codecs.
|
|
247
259
|
- [`POLYMORPHIC_BINARY_FORMAT.md`](./POLYMORPHIC_BINARY_FORMAT.md):
|
|
248
|
-
main design document for the
|
|
260
|
+
main design document for the pattern-plus-prefix-tree codec.
|
|
249
261
|
- [`BINARY_FORMAT.md`](./BINARY_FORMAT.md):
|
|
250
262
|
notes on future binary packaging of the same abstract semantics.
|
|
251
263
|
|
|
252
264
|
## Status
|
|
253
265
|
|
|
254
|
-
The active command-line pipeline emits and consumes the self-hosted
|
|
255
|
-
pattern+value stream.
|
|
256
|
-
|
|
266
|
+
The active command-line pipeline emits and consumes the self-hosted
|
|
267
|
+
binary pattern+value stream.
|
package/core.k
CHANGED
|
@@ -39,11 +39,11 @@ concat_ = ${bits x, bits y}
|
|
|
39
39
|
-- successor (increment by 1)
|
|
40
40
|
succ = {inv x, _ y} _inc;
|
|
41
41
|
|
|
42
|
-
_inc =
|
|
43
|
-
|
|
44
|
-
{.x
|
|
45
|
-
.y |
|
|
46
|
-
|
|
42
|
+
_inc = ?{X x, X y}
|
|
43
|
+
<
|
|
44
|
+
{.x </0,/_|_> x, .y |1 y} concat_,
|
|
45
|
+
{.x /1 x, .y |0 y} _inc
|
|
46
|
+
> ?X;
|
|
47
47
|
|
|
48
48
|
-- constants
|
|
49
49
|
2 = 1 succ;
|
package/objects/README.md
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
# objects/
|
|
2
2
|
|
|
3
|
-
CLI tools for compiling and inspecting k object files (`.ko`)
|
|
3
|
+
CLI tools for compiling and inspecting k object files (`.ko`), library
|
|
4
|
+
files (`.klib`), and polymorphic kVM template files (`.kvm`).
|
|
4
5
|
|
|
5
6
|
## Tools
|
|
6
7
|
|
|
7
8
|
### `k-compile`
|
|
8
9
|
|
|
9
|
-
Compiles `.k` source into an executable object file (`.ko`), library
|
|
10
|
-
(`.klib`), or polymorphic kVM backend artifact (`.kvm`). Output
|
|
11
|
-
inferred from the output extension, or from `--format`.
|
|
10
|
+
Compiles `.k` source into an executable object file (`.ko`), library
|
|
11
|
+
file (`.klib`), or polymorphic kVM backend artifact (`.kvm`). Output
|
|
12
|
+
format is inferred from the output extension, or from `--format`.
|
|
12
13
|
|
|
13
14
|
```bash
|
|
14
|
-
k-compile [--lib lib-file] [--export spec]...
|
|
15
|
+
k-compile [--lib lib-file] [--export spec]... \
|
|
16
|
+
[--format ko|klib|kvm] [source-snippet | input-file [output-file]]
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
Existing input paths are read as files. A non-existing input with `.k`,
|
|
18
|
-
or `.klib` extension is reported as a missing file; otherwise it
|
|
19
|
-
inline k source, in the same style as `k.mjs`.
|
|
19
|
+
Existing input paths are read as files. A non-existing input with `.k`,
|
|
20
|
+
`.ko`, or `.klib` extension is reported as a missing file; otherwise it
|
|
21
|
+
is compiled as inline k source, in the same style as `k.mjs`.
|
|
20
22
|
|
|
21
|
-
`.kvm` is a polymorphic kVM template artifact (`layer: "KVM-P"`). It
|
|
22
|
-
relational function definitions,
|
|
23
|
-
lowered kVM instruction streams ready for runtime specialization
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
a `--lib` dependency
|
|
23
|
+
`.kvm` is a polymorphic kVM template artifact (`layer: "KVM-P"`). It
|
|
24
|
+
carries relational function definitions, principal pattern graphs,
|
|
25
|
+
and lowered kVM instruction streams ready for runtime specialization
|
|
26
|
+
when enveloped values arrive (`specializeKVM`).
|
|
27
|
+
|
|
28
|
+
When linking a `--lib` dependency, all relations are loaded under their
|
|
29
|
+
canonical content-addressed hashes (`@hash`). To use human-readable
|
|
30
|
+
alias names in an expression or script, explicitly map them into the
|
|
31
|
+
local scope using `--export <alias>` or
|
|
32
|
+
`--export <libAlias>:<localAlias>`.
|
|
33
|
+
Alternatively, canonical `@hash` names may always be referenced directly.
|
|
27
34
|
|
|
28
35
|
### `k-decompile`
|
|
29
36
|
|
|
@@ -35,9 +42,9 @@ k-decompile [object-file [k-file]]
|
|
|
35
42
|
|
|
36
43
|
### `k-extract-aliases`
|
|
37
44
|
|
|
38
|
-
Extracts metadata aliases from a `.ko` or `.klib` as a valid k
|
|
39
|
-
snippet. Output is grouped by metadata type (`code`, then
|
|
40
|
-
alias name and `compiledAt`.
|
|
45
|
+
Extracts metadata aliases from a `.ko` or `.klib` as a valid k
|
|
46
|
+
definition snippet. Output is grouped by metadata type (`code`, then
|
|
47
|
+
`rel`), then sorted by alias name and `compiledAt`.
|
|
41
48
|
|
|
42
49
|
```bash
|
|
43
50
|
k-extract-aliases [object-file [k-file]]
|
|
@@ -45,15 +52,16 @@ k-extract-aliases [object-file [k-file]]
|
|
|
45
52
|
|
|
46
53
|
### `k-inspect-object`
|
|
47
54
|
|
|
48
|
-
Inspects a `.ko` or `.klib`. By default it prints a compact object
|
|
49
|
-
With `--kir`, it prints the current KIR-P export used by
|
|
55
|
+
Inspects a `.ko` or `.klib`. By default it prints a compact object
|
|
56
|
+
summary. With `--kir`, it prints the current KIR-P export used by
|
|
57
|
+
backend experiments.
|
|
50
58
|
|
|
51
59
|
```bash
|
|
52
60
|
k-inspect-object [--summary | --kir] [object-file]
|
|
53
61
|
```
|
|
54
62
|
|
|
55
|
-
For scripts that only need KIR-P export, `k-kir [object-file]` is the
|
|
56
|
-
exporter backed by `kir.mjs`.
|
|
63
|
+
For scripts that only need KIR-P export, `k-kir [object-file]` is the
|
|
64
|
+
direct exporter backed by `kir.mjs`.
|
|
57
65
|
|
|
58
66
|
### `k-validate-object`
|
|
59
67
|
|
|
@@ -64,29 +72,41 @@ Validates a `.ko` or `.klib` object and its derived KIR-P export. With
|
|
|
64
72
|
k-validate-object [--kir] [input-file]
|
|
65
73
|
```
|
|
66
74
|
|
|
67
|
-
The installed names are `k-` plus the source basename without `.mjs`.
|
|
68
|
-
installed object binary supports `-h` and `--help`.
|
|
75
|
+
The installed names are `k-` plus the source basename without `.mjs`.
|
|
76
|
+
Every installed object binary supports `-h` and `--help`.
|
|
69
77
|
|
|
70
78
|
## Current Format Notes
|
|
71
79
|
|
|
72
|
-
-
|
|
73
|
-
|
|
80
|
+
- For full specifications, see
|
|
81
|
+
[`DOCS/FILE_FORMATS.md`](../DOCS/FILE_FORMATS.md).
|
|
82
|
+
- Both `.ko` and `.klib` are ahead-of-time (AOT) type-checked artifacts.
|
|
83
|
+
Parsing, relation expansion, type derivation, and constraint
|
|
84
|
+
convergence are completed in advance.
|
|
85
|
+
- `.klib` files are plain UTF-8 JSON, not binary containers
|
|
86
|
+
(`main: null`).
|
|
87
|
+
- `.ko` files use the `KOBJ\n` binary header followed by a JSON payload
|
|
88
|
+
(`main: "__main__"`).
|
|
74
89
|
- There is no object payload version field in either format.
|
|
75
90
|
- `typeDerivation` belongs only to relations and currently stores only
|
|
76
91
|
`status`.
|
|
77
92
|
- Source `start` / `end` ranges live on `meta[hash].origins[]` entries.
|
|
78
|
-
- Origin entries do not have `kind`; the metadata entry has `type: "code"`
|
|
79
|
-
`type: "rel"`.
|
|
80
|
-
- Stored relation bodies do not include generated input/output
|
|
81
|
-
- KIR-P is available as an inspection/export contract; it does not change
|
|
82
|
-
stored `.ko` or `.klib` payload.
|
|
83
|
-
- `.kvm` is
|
|
84
|
-
|
|
85
|
-
and JIT specialization.
|
|
93
|
+
- Origin entries do not have `kind`; the metadata entry has `type: "code"`
|
|
94
|
+
or `type: "rel"`.
|
|
95
|
+
- Stored relation bodies do not include generated input/output filters.
|
|
96
|
+
- KIR-P is available as an inspection/export contract; it does not change
|
|
97
|
+
the stored `.ko` or `.klib` payload.
|
|
98
|
+
- `.kvm` is a polymorphic backend template artifact (`layer: "KVM-P"`),
|
|
99
|
+
lowered from KIR-P for runtime execution and JIT specialization.
|
|
86
100
|
|
|
87
101
|
## Further reading
|
|
88
102
|
|
|
89
|
-
- [DOCS/
|
|
90
|
-
|
|
91
|
-
- [DOCS/
|
|
92
|
-
|
|
103
|
+
- [DOCS/FILE_FORMATS.md](../DOCS/FILE_FORMATS.md) — guide to
|
|
104
|
+
.k, .ko, .klib, and .kvm formats
|
|
105
|
+
- [DOCS/OBJECT_FILE_AND_PATTERN.md](../DOCS/OBJECT_FILE_AND_PATTERN.md) —
|
|
106
|
+
object file format and pattern encoding
|
|
107
|
+
- [DOCS/KIR_V1.md](../DOCS/KIR_V1.md) — KIR-P inspection/export contract
|
|
108
|
+
for backends
|
|
109
|
+
- [DOCS/TYPE_DERIVATION.md](../DOCS/TYPE_DERIVATION.md) — type
|
|
110
|
+
derivation (what compilation skips when loading a `.ko`/`.klib`)
|
|
111
|
+
- [DOCS/CONVERGENCE.md](../DOCS/CONVERGENCE.md) — convergence strategies
|
|
112
|
+
for type inference
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "6.10.
|
|
3
|
+
"version": "6.10.4",
|
|
4
4
|
"description": "k — a language for composing first-order partial functions over algebraic data types (products and tagged unions); includes runtime, type derivation, REPL, and codec toolchain",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"perf:ieee": "node scripts/perf-ieee.mjs",
|
|
21
21
|
"perf:ieee:full": "node scripts/perf-ieee.mjs --full",
|
|
22
22
|
"perf:int": "node scripts/perf-int.mjs",
|
|
23
|
+
"perf:mult": "node scripts/perf-multiplication.mjs",
|
|
23
24
|
"perf:poly": "node scripts/perf-poly.mjs",
|
|
24
25
|
"perf:poly:trace": "node scripts/perf-poly.mjs --trace",
|
|
25
26
|
"perf:idempotency": "node scripts/benchmark-idempotency.mjs",
|
|
@@ -14,6 +14,33 @@ const DEFAULT_EXAMPLES = [
|
|
|
14
14
|
"Examples/ieee.k"
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
+
function printHelp() {
|
|
18
|
+
console.log(
|
|
19
|
+
`Usage: node scripts/benchmark-idempotency.mjs [options] [files...]
|
|
20
|
+
|
|
21
|
+
Measures compile and decompile round-trip idempotency performance
|
|
22
|
+
for K source files through the .klib object format.
|
|
23
|
+
|
|
24
|
+
Arguments:
|
|
25
|
+
example.k ...
|
|
26
|
+
One or more .k source files to benchmark.
|
|
27
|
+
(default: Examples/nat.k Examples/byte.k Examples/bnat.k
|
|
28
|
+
Examples/arithmetics.k Examples/ieee.k)
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
-h, --help
|
|
32
|
+
Show this help message and exit.
|
|
33
|
+
|
|
34
|
+
Environment Variables:
|
|
35
|
+
K_BENCH_ITERATIONS
|
|
36
|
+
Number of round-trip benchmark iterations (default: 5).`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
40
|
+
printHelp();
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
17
44
|
const iterations = Number(process.env.K_BENCH_ITERATIONS || 5);
|
|
18
45
|
const examples = process.argv.slice(2);
|
|
19
46
|
const benchmarkExamples = examples.length > 0 ? examples : DEFAULT_EXAMPLES;
|
package/scripts/benchmark.mjs
CHANGED
|
@@ -733,7 +733,58 @@ function printSummary(document) {
|
|
|
733
733
|
console.log("=============================================================\n");
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
+
function printHelp() {
|
|
737
|
+
console.log(`Usage: node scripts/benchmark.mjs [options]
|
|
738
|
+
|
|
739
|
+
Unified Multi-Backend Benchmark Suite.
|
|
740
|
+
Runs comprehensive arithmetic and IEEE benchmarks across Native JS,
|
|
741
|
+
kVM, KIR-P, Wasm, and LLVM-JIT execution engines.
|
|
742
|
+
|
|
743
|
+
Options:
|
|
744
|
+
--worker
|
|
745
|
+
Internal flag: execute an isolated benchmark worker job.
|
|
746
|
+
-h, --help
|
|
747
|
+
Show this help message and exit.
|
|
748
|
+
|
|
749
|
+
Environment Variables:
|
|
750
|
+
BENCHMARK_CASES
|
|
751
|
+
Comma-separated benchmark cases to run (default: all).
|
|
752
|
+
Cases: ieee.add, ieee.sub, ieee.mul, ieee.div,
|
|
753
|
+
int.times.220d, int.gcd.90d, int.factorial.101,
|
|
754
|
+
int.factorial.242, int.factorial.1174
|
|
755
|
+
BENCHMARK_MODES
|
|
756
|
+
Comma-separated execution modes to run (default: all).
|
|
757
|
+
Modes: Native JS (Envelope-Aware), Native JS (Envelope-Free),
|
|
758
|
+
kVM Interpreter (Env-Free), KIR-P Export,
|
|
759
|
+
k-wasm, k-llvm-jit
|
|
760
|
+
BENCHMARK_SAMPLES
|
|
761
|
+
Number of measurement samples per benchmark (default: 3).
|
|
762
|
+
BENCHMARK_TIMEOUT_MS
|
|
763
|
+
Timeout per benchmark job in milliseconds (default: 120000).
|
|
764
|
+
BENCHMARK_JOBS
|
|
765
|
+
Maximum parallel worker concurrency (default: 1).
|
|
766
|
+
BENCHMARK_STRICT
|
|
767
|
+
Exit with non-zero exit code if any case fails ('1' to enable).
|
|
768
|
+
K_LLVM_RUNTIME_MODE
|
|
769
|
+
Default LLVM runtime compilation mode (default: fast).
|
|
770
|
+
K_LLVM_IEEE_RUNTIME_MODE
|
|
771
|
+
LLVM runtime mode for IEEE benchmarks (default: compact).
|
|
772
|
+
K_LLVM_CLANG_OPT
|
|
773
|
+
Clang optimization flag for LLVM (default: -O3).
|
|
774
|
+
K_LLVM_IEEE_CLANG_OPT
|
|
775
|
+
Clang optimization flag for IEEE LLVM (default: -O0).
|
|
776
|
+
K_LLVM_CACHE_DIR
|
|
777
|
+
Directory to cache compiled LLVM executable binaries.
|
|
778
|
+
K_BENCHMARK_RESULT_PATH
|
|
779
|
+
Custom destination file path for benchmark results JSON.`);
|
|
780
|
+
}
|
|
781
|
+
|
|
736
782
|
async function main() {
|
|
783
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
784
|
+
printHelp();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
|
|
737
788
|
if (process.env.K_BENCHMARK_WORKER === "1" || process.argv.includes("--worker")) {
|
|
738
789
|
await workerMain();
|
|
739
790
|
return;
|
|
@@ -10,6 +10,23 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
const projectRoot = path.resolve(__dirname, "..");
|
|
11
11
|
const workspaceRoot = path.resolve(projectRoot, "..");
|
|
12
12
|
|
|
13
|
+
function printHelp() {
|
|
14
|
+
console.log(`Usage: node scripts/build-repl-html.mjs [options]
|
|
15
|
+
|
|
16
|
+
Builds the standalone, self-contained K web REPL (repl.html).
|
|
17
|
+
Bundles browser shims, virtual file system (core.k, Examples, Wasm),
|
|
18
|
+
and UI components into a single zero-dependency HTML file.
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
-h, --help
|
|
22
|
+
Show this help message and exit.`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
26
|
+
printHelp();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
console.log("=== Building Self-Contained K REPL HTML ===");
|
|
14
31
|
|
|
15
32
|
// 1. Node shims plugin for esbuild
|
|
@@ -8,7 +8,31 @@ import { execSync } from "node:child_process";
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
const root = path.resolve(__dirname, "..");
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
function printHelp() {
|
|
13
|
+
console.log(
|
|
14
|
+
`Usage: node scripts/generate-dependency-graph.mjs [options] [out]
|
|
15
|
+
|
|
16
|
+
Generates a Mermaid dependency diagram from tracked ESM imports.
|
|
17
|
+
|
|
18
|
+
Arguments:
|
|
19
|
+
out-file
|
|
20
|
+
Destination markdown file path.
|
|
21
|
+
(default: DOCS/dependency-graph.md)
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
-h, --help
|
|
25
|
+
Show this help message and exit.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
29
|
+
printHelp();
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const outPath = process.argv[2]
|
|
34
|
+
? path.resolve(root, process.argv[2])
|
|
35
|
+
: path.join(root, "DOCS", "dependency-graph.md");
|
|
12
36
|
|
|
13
37
|
function getTrackedMjsFiles() {
|
|
14
38
|
const raw = execSync("git ls-files '*.mjs'", {
|