@fraczak/k 8.5.0 → 8.6.0

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 CHANGED
@@ -5,6 +5,41 @@ 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.0] — 2026-11-03 — Native JSON Parser, IEEE Library Split, and REPL Pattern Inspection
9
+
10
+ - **Native JSON Parsing & IEEE Library Split**:
11
+ - Implement native JSON text parser (`parseJson` from `string[]` to `djson[]`)
12
+ in `Examples/djson.k` with strict tail recursion and atomic character
13
+ matching.
14
+ - Split IEEE binary64 types and text conversion (`Examples/ieee.k`) from IEEE
15
+ arithmetic operations (`Examples/ieee-arithmetics.k`), remove unused
16
+ definitions, and document relation contracts.
17
+ - Add go-to-definition and symbol navigation in `k-vscode`.
18
+ - **REPL Canonical Boundary Patterns & `:pat` Improvements**:
19
+ - Render input and output boundary patterns in `:rel <name>` using canonical
20
+ pattern names (`?@hash[...]`) when the inline pattern exceeds `maxPatLength`
21
+ (default `30`), registering canonical patterns in session state for
22
+ inspection via `:pat @hash`.
23
+ - Add `:max-pat-length [num|none]` (alias `:maxPatLength`) runtime REPL
24
+ command and `--max-pat-length=<num|none>` CLI flag.
25
+ - Normalize `:pat` / `:pattern` arguments and tab-completion to strip a
26
+ leading `?` (e.g., `:pat ?@hash`).
27
+
28
+ ## [8.5.1] — 2026-10-31 — Fix Union Tail-Call Optimization in Wasm and LLVM Backends
29
+
30
+ - **Restrict Union Tail-Call Optimization to Final Branch (#3)**:
31
+ - Fix unsound self-tail-call optimization on non-final union branches in
32
+ `backends/wasm/src/kvm2wasm.mjs`, `backends/llvm/src/kvm2llvm.mjs`, and
33
+ `backends/llvm/src/llvm.mjs`. Only the final branch (`i === N - 1`) of a
34
+ union is in tail position; earlier branches must execute regular calls so
35
+ that failure of a recursive call properly backtracks to subsequent branches
36
+ with the original union input.
37
+ - Extend `feedsSelfTailCall` (`tailCallInputTargets`) in
38
+ `backends/wasm/src/kvm2wasm.mjs` so factored tail-recursive unions
39
+ (`< { ... }, { ... } > self` in tail position) continue to forward product
40
+ fields directly into `$tail_in_*` locals and jump to `$tail_loop` without
41
+ intermediate arena allocation.
42
+
8
43
  ## [8.5.0] — 2026-10-28 — Documentation and Test Cleanup
9
44
 
10
45
  - Replace the obsolete book, duplicated paper rendering, design plans, and
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
@@ -36,6 +36,7 @@ shows compilation and execution costs for the selected engine.
36
36
  | `:engine [wasm\|pkir\|js]` | Show or select the evaluation engine |
37
37
  | `:wasm` / `:pkir` / `:js` | Engine shortcuts |
38
38
  | `:limit [number\|none]` | Show or change the output limit (default: 4096 characters) |
39
+ | `:max-pat-length [number\|none]` | Show or change max inline pattern length in `:rel` (default: 30, alias `:maxPatLength`) |
39
40
  | `:klib file` | Export the current library |
40
41
  | `:ko file expression` | Export an executable object |
41
42
  | `:reset` | Clear session state |