@fraczak/k 8.5.1 → 8.6.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 +42 -0
- package/DOCS/CODECS.md +54 -0
- package/DOCS/REPL.md +2 -0
- package/Examples/djson.k +443 -328
- package/Examples/ieee-arithmetics.k +7183 -0
- package/Examples/ieee.k +895 -7374
- package/Examples/poly.k +1 -1
- package/README.md +3 -2
- package/backends/wasm/tests/integration.sh +2 -1
- package/browser/shims/fs.mjs +1 -0
- package/canonical-pattern.mjs +341 -3
- package/object.mjs +19 -10
- package/package.json +1 -1
- package/repl.mjs +287 -22
- package/scripts/benchmark-idempotency.mjs +20 -5
- package/scripts/benchmark.mjs +42 -10
- package/scripts/build-repl-html.mjs +11 -0
- package/scripts/perf-ieee.mjs +9 -16
- package/scripts/render-benchmark.mjs +1 -1
- package/scripts/run-tests.mjs +2 -0
- package/tests/README.md +2 -0
- package/tests/integration.sh +2 -1
- package/tests/test-djson-methods.mjs +11 -1
- package/tests/test-ieee-arithmetic.mjs +3 -1
- package/tests/test-ieee-text.mjs +59 -0
- package/tests/test-k-object.mjs +9 -0
- package/tests/test-parse-json.mjs +96 -0
- package/tests/test-repl-html.mjs +1 -0
- package/tests/test-repl.mjs +209 -21
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,48 @@ All notable changes to this project will be documented here.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [8.6.1] — 2026-11-04 — REPL `:all-patterns` and Shared-Graph Boundary Pattern Printing
|
|
9
|
+
|
|
10
|
+
- **REPL `:all-patterns` (alias `:all-pat`)**:
|
|
11
|
+
- Add `:all-patterns` / `:all-pat` to list all canonical patterns keyed by
|
|
12
|
+
hash — including patterns derived from relation definitions without named
|
|
13
|
+
aliases — along with any aliases and their routing bindings
|
|
14
|
+
(`-- p[X] = @[X,(...)], q[ZZZ] = @[ZZZ,ZZZ]`).
|
|
15
|
+
- **Canonical `:pat` Display**:
|
|
16
|
+
- Update `:pat <name>` to always display the canonicalized pattern body with
|
|
17
|
+
the alias's routing arguments (`aliasArgs`) substituted via
|
|
18
|
+
`instantiateCanonicalFilter`.
|
|
19
|
+
- **Shared-Graph `:rel` Boundary Pattern Rendering & Default `max-pat-length`**:
|
|
20
|
+
- When neither boundary pattern exceeds `max-pat-length`, `:rel <name>` prints
|
|
21
|
+
the input and output boundary patterns from a single shared pattern graph
|
|
22
|
+
(`patterns2filters`) so shared nodes reuse knot variables across input and
|
|
23
|
+
output (e.g., `ww = ?<{}=X1 x, X1 y, X0 z>=X0 () ?X0;`).
|
|
24
|
+
- When either boundary pattern exceeds `max-pat-length`, render both boundary
|
|
25
|
+
patterns (unless a bare wildcard `?(...)` or bare open variable `?X0`) as
|
|
26
|
+
standalone canonical `@hash[...]` pattern applications.
|
|
27
|
+
- Increase default `max-pat-length` from `30` to `45` (the length of a
|
|
28
|
+
`@hash` name).
|
|
29
|
+
|
|
30
|
+
## [8.6.0] — 2026-11-03 — Native JSON Parser, IEEE Library Split, and REPL Pattern Inspection
|
|
31
|
+
|
|
32
|
+
- **Native JSON Parsing & IEEE Library Split**:
|
|
33
|
+
- Implement native JSON text parser (`parseJson` from `string[]` to `djson[]`)
|
|
34
|
+
in `Examples/djson.k` with strict tail recursion and atomic character
|
|
35
|
+
matching.
|
|
36
|
+
- Split IEEE binary64 types and text conversion (`Examples/ieee.k`) from IEEE
|
|
37
|
+
arithmetic operations (`Examples/ieee-arithmetics.k`), remove unused
|
|
38
|
+
definitions, and document relation contracts.
|
|
39
|
+
- Add go-to-definition and symbol navigation in `k-vscode`.
|
|
40
|
+
- **REPL Canonical Boundary Patterns & `:pat` Improvements**:
|
|
41
|
+
- Render input and output boundary patterns in `:rel <name>` using canonical
|
|
42
|
+
pattern names (`?@hash[...]`) when the inline pattern exceeds `maxPatLength`
|
|
43
|
+
(default `30`), registering canonical patterns in session state for
|
|
44
|
+
inspection via `:pat @hash`.
|
|
45
|
+
- Add `:max-pat-length [num|none]` (alias `:maxPatLength`) runtime REPL
|
|
46
|
+
command and `--max-pat-length=<num|none>` CLI flag.
|
|
47
|
+
- Normalize `:pat` / `:pattern` arguments and tab-completion to strip a
|
|
48
|
+
leading `?` (e.g., `:pat ?@hash`).
|
|
49
|
+
|
|
8
50
|
## [8.5.1] — 2026-10-31 — Fix Union Tail-Call Optimization in Wasm and LLVM Backends
|
|
9
51
|
|
|
10
52
|
- **Restrict Union Tail-Call Optimization to Final Branch (#3)**:
|
package/DOCS/CODECS.md
CHANGED
|
@@ -116,6 +116,60 @@ witness derivation. General wire semantics are specified in
|
|
|
116
116
|
`del`, `push`, `keys`, and `values`. The specializing JSON codec and dynamic
|
|
117
117
|
JSON codec serve different schemas; they are not interchangeable encodings.
|
|
118
118
|
|
|
119
|
+
The library references core and IEEE types by their canonical hashes, as
|
|
120
|
+
`poly.k` references the integer type. Its `number[]` is the IEEE `float64[]`;
|
|
121
|
+
the sign, exponent, and fraction schemas are shared too. In the REPL, load
|
|
122
|
+
`core.k`, `Examples/ieee.k`, then `Examples/djson.k`. When compiling, build the
|
|
123
|
+
IEEE library with core first so it carries both sets of types.
|
|
124
|
+
|
|
125
|
+
`Examples/ieee.k` contains the binary64 representation, small constructors and
|
|
126
|
+
predicates, and text conversion. Heavy add/subtract/multiply/divide definitions
|
|
127
|
+
are in `Examples/ieee-arithmetics.k`; load that file after `core.k` and `ieee.k`
|
|
128
|
+
when arithmetic is needed. JSON parsing uses the lightweight library alone.
|
|
129
|
+
|
|
130
|
+
`parseFloat64`: `string[]` → `float64[]` accepts JSON-style decimal syntax,
|
|
131
|
+
an optional leading `+`, surrounding ASCII JSON whitespace, and the words
|
|
132
|
+
`Infinity` and `NaN` with optional signs. Overflow yields signed infinity;
|
|
133
|
+
underflow preserves signed zero. Invalid text is undefined.
|
|
134
|
+
`printFloat64`: `float64[]` → `string[]` produces an exact decimal expansion
|
|
135
|
+
for finite values, preserving signed zero. It prints infinities as `Infinity`
|
|
136
|
+
or `-Infinity`, and all NaNs as `NaN`. Parsing NaN text selects one canonical
|
|
137
|
+
payload; NaN payloads are not preserved through text.
|
|
138
|
+
The printer prioritizes exact round-trips over shortest formatting: `0.1`
|
|
139
|
+
prints as `0.1000000000000000055511151231257827021181583404541015625`.
|
|
140
|
+
|
|
141
|
+
The library also defines `parseJson`: `string[]` → `djson[]`, entirely in k.
|
|
142
|
+
It consumes one complete JSON document, including nested containers, Unicode
|
|
143
|
+
escapes, and decimal numbers rounded to binary64. Invalid JSON, unpaired
|
|
144
|
+
surrogate escapes, and numbers that overflow to infinity are undefined.
|
|
145
|
+
For example, decode UTF-8 to a k string, then parse that string in k:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
node objects/compile.mjs --lib core.k Examples/ieee.k /tmp/ieee-core.klib
|
|
149
|
+
node objects/compile.mjs --lib /tmp/ieee-core.klib Examples/djson.k /tmp/djson.klib
|
|
150
|
+
printf '%s' '{"answer":42}' | node codecs/utf8.mjs --parse |
|
|
151
|
+
node k.mjs --lib /tmp/djson.klib --export parseJson 'parseJson' |
|
|
152
|
+
node codecs/djson.mjs --print
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This prints `{"answer":42}`. Exact conversion near binary64 limits is expensive
|
|
156
|
+
in the envelope-aware JavaScript interpreter; the Wasm backend runs the same
|
|
157
|
+
relation with much less overhead.
|
|
158
|
+
|
|
159
|
+
The compiled IEEE library also supports a complete text round-trip in k:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
printf '%s' '1.5' | node codecs/utf8.mjs --parse |
|
|
163
|
+
node k.mjs --lib /tmp/ieee-core.klib --export parseFloat64 --export printFloat64 'parseFloat64 printFloat64' |
|
|
164
|
+
node codecs/utf8.mjs --print
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
For arithmetic, compile the optional layer against the same IEEE library:
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
node objects/compile.mjs --lib /tmp/ieee-core.klib Examples/ieee-arithmetics.k /tmp/ieee-arithmetics.klib
|
|
171
|
+
```
|
|
172
|
+
|
|
119
173
|
`k-parse` and `k-print` use [textual k values](TEXTUAL_VALUES.md), rather than
|
|
120
174
|
the external integer/string/JSON interpretations above.
|
|
121
175
|
|
package/DOCS/REPL.md
CHANGED
|
@@ -28,6 +28,7 @@ shows compilation and execution costs for the selected engine.
|
|
|
28
28
|
| `:rel name` / `:rels` | Inspect a relation / list relation aliases |
|
|
29
29
|
| `:pat name` / `:pats` | Inspect a pattern / list pattern aliases |
|
|
30
30
|
| `:pattern` / `:patterns` | Long forms of the preceding pattern commands |
|
|
31
|
+
| `:all-patterns` / `:all-pat` | List all canonical patterns keyed by hash with their aliases |
|
|
31
32
|
| `:load [--no-alias] file` | Load source or a compiled library |
|
|
32
33
|
| `:codec load file` | Register a codec module |
|
|
33
34
|
| `:codec unload name` | Remove a codec |
|
|
@@ -36,6 +37,7 @@ shows compilation and execution costs for the selected engine.
|
|
|
36
37
|
| `:engine [wasm\|pkir\|js]` | Show or select the evaluation engine |
|
|
37
38
|
| `:wasm` / `:pkir` / `:js` | Engine shortcuts |
|
|
38
39
|
| `:limit [number\|none]` | Show or change the output limit (default: 4096 characters) |
|
|
40
|
+
| `:max-pat-length [number\|none]` | Show or change max inline pattern length in `:rel` (default: 45, alias `:maxPatLength`) |
|
|
39
41
|
| `:klib file` | Export the current library |
|
|
40
42
|
| `:ko file expression` | Export an executable object |
|
|
41
43
|
| `:reset` | Clear session state |
|