@fraczak/k 6.0.4 → 6.1.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 (59) hide show
  1. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  2. package/.idea/copilot.data.migration.agent.xml +6 -0
  3. package/.idea/copilot.data.migration.ask.xml +6 -0
  4. package/.idea/copilot.data.migration.ask2agent.xml +6 -0
  5. package/.idea/copilot.data.migration.edit.xml +6 -0
  6. package/.idea/k.iml +9 -0
  7. package/.idea/misc.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/AGENTS.md +2 -2
  11. package/CHANGELOG.md +22 -5
  12. package/CLAUDE.md +4 -4
  13. package/DOCS/BIG_PICTURE.md +5 -5
  14. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
  15. package/DOCS/OBJECT_FILE_AND_PATTERN.md +9 -9
  16. package/DOCS/PATTERNS.md +6 -5
  17. package/DOCS/REPL.md +2 -2
  18. package/DOCS/book/06-values-in-memory.md +1 -1
  19. package/DOCS/book.md +20 -24
  20. package/README.md +200 -274
  21. package/codecs/README.md +21 -2
  22. package/codecs/example-pipeline.mjs +14 -0
  23. package/codecs/ieee.mjs +13 -3
  24. package/codecs/int.mjs +13 -3
  25. package/codecs/json.mjs +13 -3
  26. package/codecs/k-parse.mjs +5 -0
  27. package/codecs/k-print.mjs +16 -1
  28. package/codecs/show.mjs +15 -1
  29. package/codecs/unit.mjs +13 -3
  30. package/codecs/utf16.mjs +13 -3
  31. package/codecs/utf8.mjs +13 -3
  32. package/k-vscode/README.md +3 -2
  33. package/k.mjs +9 -1
  34. package/k_compiler/runtime.c +205 -0
  35. package/k_compiler/runtime.h +34 -0
  36. package/objects/README.md +11 -8
  37. package/package.json +13 -7
  38. package/{repl2.mjs → repl.mjs} +47 -9
  39. package/{test-repl2.mjs → test-repl.mjs} +16 -5
  40. package/.codex +0 -0
  41. package/DOCS/a.html +0 -398
  42. package/NAT.k~ +0 -452
  43. package/UU/ta.k +0 -1
  44. package/UU/ta.k~ +0 -0
  45. package/UU/tb.k +0 -0
  46. package/UU/tc.k +0 -0
  47. package/codecs/BINARY_FORMAT.html +0 -471
  48. package/codecs/POLYMORPHIC_BINARY_FORMAT.html +0 -355
  49. package/core.json +0 -1
  50. package/core.klib +0 -1
  51. package/core.klib~ +0 -0
  52. package/ieee.klib +0 -0
  53. package/k-vscode/package-lock.json +0 -4176
  54. package/kkk.k +0 -197
  55. package/kkk.klib +0 -0
  56. package/kkk.klib~ +0 -0
  57. package/p.json +0 -5475
  58. package/type_registry/registry.mjs~ +0 -105
  59. package/type_registry/typeParser.jison~ +0 -132
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AgentMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AskMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Ask2AgentMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EditMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
package/.idea/k.iml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
package/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/k.iml" filepath="$PROJECT_DIR$/.idea/k.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/AGENTS.md CHANGED
@@ -11,8 +11,8 @@
11
11
  - `npm install` installs dev dependencies and runs `prepare` to generate parsers.
12
12
  - `npm run prepare` regenerates `parser.mjs` and `valueParser.mjs` from `.jison` grammars.
13
13
  - `npm test` runs the full suite (`test.mjs`, `Code-derivation-tests/*.mjs`, `test-fingerprint.mjs`, `tests.sh`).
14
- - `node repl2.mjs` (or `k-repl`) starts the interactive REPL.
15
- - `./k.mjs <file.k>` executes a k script on binary pattern+value stream input from stdin or a file; use `k-parse` and `k-print` at the boundaries.
14
+ - `node repl.mjs` (or `k-repl`) starts the interactive REPL.
15
+ - `./k.mjs -k <file.k>` executes a k script on binary pattern+value stream input from stdin or a file; use `k-parse` and `k-print` at the boundaries.
16
16
 
17
17
  ## Coding Style & Naming Conventions
18
18
  - JavaScript uses ES modules (`.mjs`) with 2-space indentation and semicolons.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ---
9
9
 
10
+ ## [6.1.0] — 2026-05-20 — CLI aliases and help
11
+
12
+ ### Toolchain
13
+
14
+ - Renamed the REPL entry point to `repl.mjs` and the installed binary to `k-repl`.
15
+ - Unified installed command names around the `k-` prefix and source basenames.
16
+ - Added `-h` / `--help` support across executable CLI scripts.
17
+ - Added public aliases in `Examples/ieee.k` for `add`, `sub`, `mul`, `div`, comparisons, and `neg`.
18
+
19
+ ### Documentation
20
+
21
+ - Reworked the README around typed data transformations, contributor entry points, and the IEEE example.
22
+ - Updated CLI references across documentation to the current installed command names.
23
+
24
+ ---
25
+
10
26
  ## [6.0.0] — 2026-05-12 — First public release
11
27
 
12
28
  ### Language & Runtime
@@ -22,18 +38,18 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
22
38
  - Finite tree automaton type representation (`codes.mjs`).
23
39
  - Graph-based constraint propagation via `TypePatternGraph`.
24
40
  - SCC-aware convergence with configurable strategy (`auto` / `single_pass` / `fixed_point`).
25
- - `compileStats` API for inspecting convergence behaviour per SCC.
41
+ - `compileStats` API for inspecting convergence behavior per SCC.
26
42
 
27
43
  ### Toolchain
28
44
 
29
45
  - `k` — CLI executor: reads binary pattern+value stream, applies a k script, writes result.
30
- - `k-repl` / `k-repl2` — interactive interpreter with tab-completion.
31
- - `k-pattern` — extract the canonical root pattern from a k script.
32
- - `k-compile-object` / `k-decompile-object` — object file compilation and decompilation.
46
+ - `k-repl` — interactive interpreter with tab-completion.
47
+ - `k-compile` / `k-decompile` — object file compilation and decompilation.
48
+ - `k-compile-lib` / `k-extract-aliases` — library compilation and alias extraction.
33
49
 
34
50
  ### Codec Pipeline
35
51
 
36
- - Binary format: serialised pattern graph followed by value encoded under that pattern.
52
+ - Binary format: serialized pattern graph followed by value encoded under that pattern.
37
53
  - JSON codec, UTF-8/UTF-16 string codec, IEEE 754 codec.
38
54
  - Polymorphic codec streams: pattern carried in-memory through projections and constructors.
39
55
 
@@ -45,4 +61,5 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
45
61
 
46
62
  ---
47
63
 
64
+ [6.1.0]: https://github.com/fraczak/k/releases/tag/v6.1.0
48
65
  [6.0.0]: https://github.com/fraczak/k/releases/tag/v6.0.0
package/CLAUDE.md CHANGED
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
 
5
5
  ## Project Overview
6
6
 
7
- k-language is an experimental programming language for building and manipulating algebraic data types ("codes")—tree-shaped values built from product and tagged union. The native k-like notation is canonical; a JSON-like notation is available as a convenience for newcomers.
7
+ k is an experimental language for describing algebraic data shapes and composing typed transformations over them. Data descriptions and transformations share one syntax; the native k-like notation is canonical, and a JSON-like notation is available as a convenience for textual values.
8
8
 
9
9
  ## Essential Commands
10
10
 
@@ -20,8 +20,8 @@ npm test # Run comprehensive test suite (unit tests, derivation tests, shell te
20
20
 
21
21
  **Running k programs:**
22
22
  ```bash
23
- ./k.mjs <file.k> # Execute k script
24
- ./repl2.mjs # Start interactive REPL (or: k-repl)
23
+ ./k.mjs -k <file.k> # Execute k script
24
+ ./repl.mjs # Start interactive REPL (or: k-repl)
25
25
  ```
26
26
 
27
27
  ## Architecture
@@ -61,4 +61,4 @@ npm test # Run comprehensive test suite (unit tests, derivation tests, shell te
61
61
  - No external runtime dependencies (only jiwson for parser generation)
62
62
  - Uses ES6 modules (.mjs files) throughout
63
63
  - Extensive test suite in `Code-derivation-tests/` for type system validation
64
- - REPL supports commands like `--C name` (show canonical type) and `--R name` (show type derivation)
64
+ - REPL supports commands like `:C name` (show canonical type), `:t name` (show relation type), and `:d name` (show relation definition)
@@ -82,7 +82,7 @@ filter_label_list ::= /* empty */ | '...'
82
82
 
83
83
  Examples:
84
84
 
85
- ```k-repl
85
+ ```text
86
86
  X -- any type
87
87
  ( ... ) -- any type
88
88
  { ... } -- any product type
@@ -178,7 +178,7 @@ The normalization steps are:
178
178
 
179
179
  #### Example 1
180
180
 
181
- ```k-repl
181
+ ```text
182
182
  $ bit = < {} o, {} i >;
183
183
  bit0 = | o $bit;
184
184
  bit1 = | i $bit;
@@ -242,7 +242,7 @@ Such a pattern is called _singleton pattern_, as only one type fits the pattern.
242
242
 
243
243
  Polymorphic list functions:
244
244
 
245
- ```k-repl
245
+ ```text
246
246
  list? = ?< {} nil, {X car, Y cdr} cons > = Y;
247
247
  nil = {} |nil list?;
248
248
  singleton = {() car, nil cdr} |cons list?;
@@ -254,7 +254,7 @@ cdr = list? /cons .cdr;
254
254
 
255
255
  For example, the filter annotation for `car` is:
256
256
 
257
- ```k-repl
257
+ ```text
258
258
  > :t car
259
259
  car : ?<{X1 car, X0 cdr} cons, $KL nil>=X0 --> ?X1 (@...)
260
260
  > :C KL
@@ -301,7 +301,7 @@ A type can be translated into a Rust data structure, and a function can be trans
301
301
 
302
302
  Extending `@string` into `@bits`.
303
303
 
304
- ```k-repl
304
+ ```text
305
305
  $ bits = < {} _, bits 0, bits 1 >;
306
306
  ```
307
307
 
@@ -51,9 +51,9 @@ value-payload DAG compression.
51
51
 
52
52
  ```bash
53
53
  echo '["zebara", "ela", "kupa", ala, owca]' | \
54
- ./codecs/k-parse.mjs | \
55
- ./k.mjs '{.1 0,.3 1}' | \
56
- ./codecs/k-print.mjs
54
+ k-parse | \
55
+ k '{.1 0,.3 1}' | \
56
+ k-print
57
57
  ```
58
58
 
59
59
  Expected output:
@@ -133,7 +133,7 @@ Loading an object hydrates the type-pattern graphs back into runtime
133
133
  Object execution through `k.mjs`:
134
134
 
135
135
  ```sh
136
- echo "..." | ./some-codec --parse | ./k.mjs -k path/to/program.ko | ./some-codec --print
136
+ echo "..." | some-codec --parse | k -k path/to/program.ko | some-codec --print
137
137
  ```
138
138
 
139
139
  The `-k` option accepts either an object file or a source `.k` file. `k.mjs`
@@ -143,17 +143,17 @@ compilation.
143
143
  Standalone helpers live in `objects/`:
144
144
 
145
145
  ```sh
146
- ./objects/compile.mjs path/to/program.k path/to/program.ko
147
- ./objects/compile-lib.mjs path/to/library.k path/to/library.klib
148
- ./objects/decompile.mjs path/to/program.ko path/to/program.decompiled.k
149
- ./objects/extract-aliases.mjs path/to/library.klib path/to/aliases.k
146
+ k-compile path/to/program.k path/to/program.ko
147
+ k-compile-lib path/to/library.k path/to/library.klib
148
+ k-decompile path/to/program.ko path/to/program.decompiled.k
149
+ k-extract-aliases path/to/library.klib path/to/aliases.k
150
150
  ```
151
151
 
152
152
  With no arguments, the helpers read from stdin and write to stdout:
153
153
 
154
154
  ```sh
155
- cat path/to/program.k | ./objects/compile.mjs > path/to/program.ko
156
- cat path/to/program.ko | ./objects/decompile.mjs > path/to/program.decompiled.k
155
+ cat path/to/program.k | k-compile > path/to/program.ko
156
+ cat path/to/program.ko | k-decompile > path/to/program.decompiled.k
157
157
  ```
158
158
 
159
159
  The decompiled source is canonical source regenerated from object IR. It uses
@@ -173,7 +173,7 @@ For a tiny source file:
173
173
  compile it with:
174
174
 
175
175
  ```sh
176
- ./objects/compile.mjs id.k id.ko
176
+ k-compile id.k id.ko
177
177
  ```
178
178
 
179
179
  The first bytes of `id.ko` are the binary container header:
@@ -259,7 +259,7 @@ succ = |succ;
259
259
  compile it with:
260
260
 
261
261
  ```sh
262
- ./objects/compile-lib.mjs defs.k defs.klib
262
+ k-compile-lib defs.k defs.klib
263
263
  ```
264
264
 
265
265
  The output file is plain JSON and starts with `{`, not a binary prefix. Its
package/DOCS/PATTERNS.md CHANGED
@@ -66,9 +66,10 @@ list
66
66
 
67
67
  In both cases, the compiler derives a root pattern from `__main__`.
68
68
 
69
- ## `k-pattern`
69
+ ## Pattern Export Helper
70
70
 
71
- `k-pattern` extracts that root pattern from a k script.
71
+ `patterns/from-k.mjs` extracts that root pattern from a k script. It is a
72
+ repository helper, not an installed `package.json` binary.
72
73
 
73
74
  It:
74
75
 
@@ -84,7 +85,7 @@ It:
84
85
  Example:
85
86
 
86
87
  ```bash
87
- echo '?< {} nil, { $bits car, X cdr } cons > = X' | k-pattern
88
+ echo '?< {} nil, { $bits car, X cdr } cons > = X' | node ./patterns/from-k.mjs
88
89
  ```
89
90
 
90
91
  Typical output:
@@ -101,8 +102,8 @@ The active wire format is:
101
102
  encode($pattern_value : $pattern) encode(value : decoded_pattern)
102
103
  ```
103
104
 
104
- So the property-list array printed by `k-pattern` is a readable externalization
105
- of the same pattern information carried in the wire stream.
105
+ So the property-list array printed by `patterns/from-k.mjs` is a readable
106
+ externalization of the same pattern information carried in the wire stream.
106
107
 
107
108
  `k-parse --input-pattern ...` and `k-parse --input-type ...` both ultimately
108
109
  produce the same kind of root pattern used to interpret textual values.
package/DOCS/REPL.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # k Interpreter
2
2
 
3
- `repl2.mjs` is the interactive k interpreter. `k-repl` and `k-repl2` both
4
- start it.
3
+ `repl.mjs` is the interactive k interpreter. After linking or installing the
4
+ package, start it with `k-repl`.
5
5
 
6
6
  The interpreter keeps a live `.klib`-style state in memory:
7
7
 
@@ -113,7 +113,7 @@ Each node in the value tree is encoded based on its automaton state:
113
113
 
114
114
  For type `bnat`, intuitively binary natural numbers defined by `$bnat = < bnat 0, bnat 1, {} _ >`, we get
115
115
 
116
- ```k-repl
116
+ ```text
117
117
  > :C bnat
118
118
  $ bnat = < @... 0, @... 1, {} _ >; -- @...
119
119
  ```
package/DOCS/book.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: "k-language"
2
+ title: "k"
3
3
  author: "W. Fraczak"
4
4
  ---
5
5
 
@@ -15,32 +15,28 @@ author: "W. Fraczak"
15
15
 
16
16
  </div>
17
17
 
18
- # The k-language Book
19
-
20
- This book describes the k programming language - a minimal functional language for transforming tree-structured data using partial functions and algebraic data types.
21
-
22
- ## Table of Contents
23
-
24
- 1. [Introduction](book/01-introduction.md)
25
- 2. [Syntax and Values](book/02-syntax-and-values.md)
26
- 3. [Types as Finite Automata](book/03-types-as-finite-automata.md)
27
- 4. [Partial Functions and Composition](book/04-partial-functions-and-composition.md)
28
- 5. [Typing, Filters, and Normalization](book/05-typing-filters-and-normalization.md)
29
- 6. [Values in Memory](book/06-values-in-memory.md)
30
- 7. [The Partial Function ABI](book/07-the-partial-function-abi.md)
31
- 8. [Operational Semantics and Execution](book/08-operational-semantics-and-execution.md)
32
- 9. [Compiler Architecture](book/09-compiler-architecture.md)
33
- 10. [From AST to Intermediate Representation](book/10-from-ast-to-intermediate-representation.md)
34
- 11. [LLVM Basics](book/11-llvm-basics.md)
35
- 12. [Code Generation](book/12-code-generation.md)
36
- 13. [Linking and Execution](book/13-linking-and-execution.md)
37
- 14. [Canonical Serialization](book/14-canonical-serialization.md)
38
- 15. [Optimization and Folding](book/15-optimization-and-folding.md)
39
- 16. [Toward a Universal Schema Registry](book/16-toward-a-universal-schema-registry.md)
18
+ # The k Book
19
+
20
+ This book describes the k programming language: a minimal functional language
21
+ for transforming tree-structured data using partial functions and algebraic
22
+ data types.
23
+
24
+ ## Available Chapters
25
+
26
+ - [Introduction](book/01-introduction.md)
27
+ - [Syntax and Values](book/02-syntax-and-values.md)
28
+ - [Types as Finite Automata](book/03-types-as-finite-automata.md)
29
+ - [Partial Functions and Composition](book/04-partial-functions-and-composition.md)
30
+ - [Typing, Filters, and Normalization](book/05-typing-filters-and-normalization.md)
31
+ - [Values in Memory](book/06-values-in-memory.md)
32
+ - [The Partial Function ABI](book/07-the-partial-function-abi.md)
33
+ - [Operational Semantics and Execution](book/08-operational-semantics-and-execution.md)
34
+ - [Compiler Architecture](book/09-compiler-architecture.md)
35
+ - [From AST to Intermediate Representation](book/10-from-ast-to-intermediate-representation.md)
36
+ - [Canonical Serialization](book/14-canonical-serialization.md)
40
37
 
41
38
  ## Appendices
42
39
 
43
- - [Appendix A: Implementing a Prototype Compiler in Python](book/appendix-a-implementing-a-prototype-compiler-in-python.md)
44
40
  - [Appendix B: Incorporating External Predefined Types and Functions](book/appendix-b-incorporating-external-predefined-types-and-functions.md)
45
41
 
46
42
  ---