@fraczak/k 6.10.1 → 6.10.3

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/objects/README.md CHANGED
@@ -1,29 +1,36 @@
1
1
  # objects/
2
2
 
3
- CLI tools for compiling and inspecting k object files (`.ko`) and library files (`.klib`).
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 file
10
- (`.klib`), or polymorphic kVM backend artifact (`.kvm`). Output format is
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]... [--format ko|klib|kvm] [source-snippet | input-file [output-file]]
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`, `.ko`,
18
- or `.klib` extension is reported as a missing file; otherwise it is compiled as
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 carries the
22
- relational function definitions, their principal input/output pattern graphs, and
23
- lowered kVM instruction streams ready for runtime specialization when enveloped
24
- values arrive. Specialization occurs when functions are invoked on concrete values,
25
- eliminating the need for ahead-of-time input pattern or input type flags. Names from
26
- a `--lib` dependency can be imported into the entry scope using `--export (oldname:)?newname`.
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 definition
39
- snippet. Output is grouped by metadata type (`code`, then `rel`), then sorted by
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 summary.
49
- With `--kir`, it prints the current KIR-P export used by backend experiments.
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 direct
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`. Every
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
- - `.klib` files are plain UTF-8 JSON, not binary containers.
73
- - `.ko` files use the `KOBJ\n` binary header followed by a JSON payload.
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"` or
79
- `type: "rel"`.
80
- - Stored relation bodies do not include generated input/output boundary filters.
81
- - KIR-P is available as an inspection/export contract; it does not change the
82
- stored `.ko` or `.klib` payload.
83
- - `.kvm` is not a canonical source/object format; it is a polymorphic backend
84
- template artifact (`layer: "KVM-P"`), lowered from KIR-P for runtime execution
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/OBJECT_FILE_AND_PATTERN.md](../DOCS/OBJECT_FILE_AND_PATTERN.md) — object file format and pattern encoding
90
- - [DOCS/KIR_V1.md](../DOCS/KIR_V1.md) — KIR-P inspection/export contract for backends
91
- - [DOCS/TYPE_DERIVATION.md](../DOCS/TYPE_DERIVATION.md) — type derivation (what compilation skips when loading a `.ko`/`.klib`)
92
- - [DOCS/CONVERGENCE.md](../DOCS/CONVERGENCE.md) — convergence strategies for type inference
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.1",
3
+ "version": "6.10.3",
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": {
package/tests/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # k Test Suite
2
2
 
3
- This directory contains the automated tests, type-derivation validation cases, and integration test scripts for the `k` compiler and runtime.
3
+ This directory contains automated tests, type-derivation validation
4
+ cases, and integration test scripts for the `k` compiler and runtime.
4
5
 
5
6
  ## Running the Tests
6
7
 
@@ -9,27 +10,37 @@ To run all core unit tests, type-derivation checks, and integration tests:
9
10
  ```bash
10
11
  npm test
11
12
  ```
12
- This executes `node scripts/run-tests.mjs`, which discovers and runs the test scripts sequentially.
13
+ This executes `node scripts/run-tests.mjs`, which discovers and runs the
14
+ test scripts sequentially.
13
15
 
14
16
  ## Test Directory Structure
15
17
 
16
18
  ### Core Test Files
17
- - **[test.mjs](file:///Users/wojtek/gits/k/tests/test.mjs)**: Verifies basic parser and runtime execution behavior.
18
- - **[test-kvm.mjs](file:///Users/wojtek/gits/k/tests/test-kvm.mjs)**: Comprehensive conformance testing for the kVM register compiler and interpreter under both envelope-aware and envelope-free modes.
19
- - **[test-ieee-arithmetic.mjs](file:///Users/wojtek/gits/k/tests/test-ieee-arithmetic.mjs)**: Verifies IEEE-754 double precision float arithmetic implementation (`Examples/ieee.k`).
20
- - **[test-repl.mjs](file:///Users/wojtek/gits/k/tests/test-repl.mjs)**: Tests interactive REPL commands, state transitions, imports, and auto-completions.
21
- - **[test-k-object.mjs](file:///Users/wojtek/gits/k/tests/test-k-object.mjs)**: Tests serialization, compilation, and loading of `.ko` binary objects.
22
- - **[test-fingerprint.mjs](file:///Users/wojtek/gits/k/tests/test-fingerprint.mjs)**: Tests semantic expression and relation hashing/fingerprinting.
23
- - **[test-hash-normalization.mjs](file:///Users/wojtek/gits/k/tests/test-hash-normalization.mjs)**: Verifies consistent normalization of type pattern graphs and hashes.
24
- - **[test-hash-fuzz.mjs](file:///Users/wojtek/gits/k/tests/test-hash-fuzz.mjs)**: Fuzzes expression/relation hashing to guard against collisions.
25
-
26
- ### WebAssembly Benchmarks
27
-
28
- The WebAssembly execution benchmark moved to the separate
29
- [`fraczak/k-wasm`](https://github.com/fraczak/k-wasm) backend repository.
19
+ - **[test.mjs](test.mjs)**: Verifies basic parser and runtime
20
+ execution behavior.
21
+ - **[test-kvm.mjs](test-kvm.mjs)**: Conformance testing for the kVM
22
+ register compiler and interpreter in envelope-aware and envelope-free
23
+ modes.
24
+ - **[test-kvm-polymorphic.mjs](test-kvm-polymorphic.mjs)**: Tests for
25
+ polymorphic `.kvm` templates (`layer: "KVM-P"`) and runtime input
26
+ envelope specialization (`specializeKVM`).
27
+ - **[test-ieee-arithmetic.mjs](test-ieee-arithmetic.mjs)**: Verifies
28
+ IEEE-754 double precision float arithmetic (`Examples/ieee.k`).
29
+ - **[test-repl.mjs](test-repl.mjs)**: Tests interactive REPL commands,
30
+ state transitions, imports, `.klib` and `.ko` exports.
31
+ - **[test-k-object.mjs](test-k-object.mjs)**: Tests serialization,
32
+ compilation, and loading of `.ko` binary objects and `.klib` libraries.
33
+ - **[test-fingerprint.mjs](test-fingerprint.mjs)**: Tests semantic
34
+ expression and relation hashing/fingerprinting (`@hash`).
35
+ - **[test-hash-normalization.mjs](test-hash-normalization.mjs)**:
36
+ Verifies consistent normalization of type pattern graphs and hashes.
37
+ - **[test-hash-fuzz.mjs](test-hash-fuzz.mjs)**: Fuzzes expression and
38
+ relation hashing to guard against collisions.
30
39
 
31
40
  ### Type Derivation Suites
32
- - **[code-derivation/](file:///Users/wojtek/gits/k/tests/code-derivation)**: Houses individual files (each containing a focused test scenario) validating type-derivation convergence and pattern-envelope generation.
41
+ - **[code-derivation/](code-derivation/)**: Individual files validating
42
+ type-derivation convergence and pattern-envelope generation.
33
43
 
34
44
  ### Integration Scripts
35
- - **[integration.sh](file:///Users/wojtek/gits/k/tests/integration.sh)**: Shell script checking boundary data pipelines (`k-parse`, `k-show`, `k-print`) against binary outputs.
45
+ - **[integration.sh](integration.sh)**: Shell script checking boundary
46
+ data pipelines (`k-parse`, `k-show`, `k-print`) against binary outputs.
@@ -358,6 +358,25 @@ if (chromiumBin) {
358
358
  })()`);
359
359
  assert(ieeeResult.includes('ieee.mjs: 3.14159'), `Expected ieee.mjs: 3.14159, got: ${ieeeResult}`);
360
360
 
361
+ // Test :load poly.k and evaluate '10 int (gen_list sort)' in WASM mode
362
+ const sortListResult = await evaluateAsync(`(async () => {
363
+ await window.kRepl.executeCommand(":reset");
364
+ await window.kRepl.executeCommand(":load arithmetics.k");
365
+ await window.kRepl.executeCommand(":load poly.k");
366
+ await window.kRepl.executeCommand(":codec load int.mjs");
367
+ await window.kRepl.executeCommand("10 int (gen_list sort)");
368
+ const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
369
+ return lines[lines.length - 1];
370
+ })()`);
371
+ assert(sortListResult.includes('int.mjs: [0,1,2,3,4,5,6,7,8,9,10]'), `Expected sorted int list in browser REPL output, got: ${sortListResult}`);
372
+
373
+ // Test deep tail-loop list generation and compaction (10,000 elements) in browser WASM mode
374
+ const deepWasmResult = await evaluateAsync(`(async () => {
375
+ await window.kRepl.executeCommand("{{{10 int x, 10 int y} times x, 10 int y} times x, 10 int y} times (gen_list car)");
376
+ const lines = Array.from(document.querySelectorAll(".entry-line")).map(el => el.textContent);
377
+ return lines[lines.length - 1];
378
+ })()`);
379
+ assert(deepWasmResult.includes('int.mjs: 0'), `Expected 0 from car of 10,000-element list in browser REPL, got: ${deepWasmResult}`);
361
380
 
362
381
  // Verify text selection holds in output element
363
382
  const selectionCheck = await evaluateAsync(`(() => {