@fraczak/k 6.0.1 → 6.0.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.
Files changed (55) hide show
  1. package/AGENTS.md +35 -0
  2. package/CHANGELOG.md +48 -0
  3. package/CLAUDE.md +64 -0
  4. package/DOCS/BIG_PICTURE.md +4 -8
  5. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +74 -0
  6. package/DOCS/CONVERGENCE.md +92 -0
  7. package/DOCS/DIVERGENCE_DETECTION.md +24 -0
  8. package/DOCS/Makefile +99 -0
  9. package/DOCS/OBJECT_FILE_AND_PATTERN.md +221 -0
  10. package/DOCS/PATTERNS.md +114 -0
  11. package/DOCS/PATTERNS_AND_TYPED_VALUES.md +665 -0
  12. package/DOCS/REPL.md +127 -126
  13. package/DOCS/TEXTUAL_VALUES.md +108 -0
  14. package/DOCS/TYPE_DERIVATION.md +230 -0
  15. package/DOCS/book/06-values-in-memory.md +1085 -0
  16. package/DOCS/book/07-the-partial-function-abi.md +143 -0
  17. package/DOCS/book/08-operational-semantics-and-execution.md +201 -0
  18. package/DOCS/book/09-compiler-architecture.md +160 -0
  19. package/DOCS/book/10-from-ast-to-intermediate-representation.md +167 -0
  20. package/DOCS/book/14-canonical-serialization.md +176 -0
  21. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +155 -0
  22. package/DOCS/book/overview.txt +68 -0
  23. package/README.md +78 -30
  24. package/UU/ta.k +1 -0
  25. package/UU/ta.k~ +0 -0
  26. package/UU/tb.k +0 -0
  27. package/UU/tc.k +0 -0
  28. package/codecs/README.md +12 -0
  29. package/codecs/pandoc.css +71 -0
  30. package/codecs/runtime/test-codec.mjs +89 -0
  31. package/core.klib +0 -0
  32. package/core.klib~ +0 -0
  33. package/ieee.klib +0 -0
  34. package/kkk.k +197 -0
  35. package/kkk.klib +0 -0
  36. package/kkk.klib~ +0 -0
  37. package/object.mjs +162 -8
  38. package/objects/README.md +10 -0
  39. package/objects/compile-lib.mjs +26 -2
  40. package/objects/compile.mjs +26 -2
  41. package/objects/decompile.mjs +25 -2
  42. package/objects/extract-aliases.mjs +59 -0
  43. package/package.json +3 -2
  44. package/{codecs/k-pattern.mjs → patterns/from-k.mjs} +3 -3
  45. package/repl2.mjs +345 -83
  46. package/scripts/generate-dependency-graph.mjs +121 -0
  47. package/test-k-object.mjs +77 -1
  48. package/test-repl2.mjs +65 -8
  49. package/DOCS/book-combined.html +0 -3798
  50. package/DOCS/book-combined.md +0 -3745
  51. package/DOCS/book-combined.pdf +0 -0
  52. package/DOCS/book-combined.tex +0 -5682
  53. package/DOCS/book.html +0 -65
  54. package/DOCS/book.pdf +0 -0
  55. package/DOCS/book.tex +0 -150
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import { argv, exit, stdin, stdout } from "node:process";
5
+ import { extractAliasesFromObjectBuffer } from "../object.mjs";
6
+
7
+ function helpText() {
8
+ return [
9
+ "Extract metadata aliases from a .ko or .klib as a valid k source snippet.",
10
+ "",
11
+ `Usage: ${argv[1]} [ object-file [ k-file ] ]`,
12
+ "",
13
+ "Output is grouped by metadata type (code, then rel), then sorted by alias",
14
+ "name and compiledAt. Earlier definitions of the same alias are commented",
15
+ "out so only the latest one remains active.",
16
+ "",
17
+ "Arguments:",
18
+ " object-file Input .ko or .klib path. Reads binary object data from stdin when omitted.",
19
+ " k-file Output .k path. Writes source to stdout when omitted.",
20
+ "",
21
+ "Options:",
22
+ " -h, --help Show this help.",
23
+ "",
24
+ "Example:",
25
+ ` ${argv[1]} core.klib aliases.k`
26
+ ].join("\n");
27
+ }
28
+
29
+ function usage(stream = console.error) {
30
+ stream(helpText());
31
+ }
32
+
33
+ async function readStdinBuffer() {
34
+ const chunks = [];
35
+ for await (const chunk of stdin) {
36
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
37
+ }
38
+ return Buffer.concat(chunks);
39
+ }
40
+
41
+ try {
42
+ const [, , objectPath, outputPath] = argv;
43
+ if (objectPath === "-h" || objectPath === "--help") {
44
+ usage(console.log);
45
+ exit(0);
46
+ }
47
+
48
+ const objectBuffer = objectPath == null ? await readStdinBuffer() : fs.readFileSync(objectPath);
49
+ const source = extractAliasesFromObjectBuffer(objectBuffer);
50
+ if (outputPath == null) {
51
+ stdout.write(source);
52
+ } else {
53
+ fs.writeFileSync(outputPath, source);
54
+ }
55
+ } catch (error) {
56
+ console.error(error);
57
+ usage();
58
+ exit(1);
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "6.0.1",
3
+ "version": "6.0.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
  "scripts": {
@@ -18,8 +18,9 @@
18
18
  "k": "./k.mjs",
19
19
  "k-compile-object": "./objects/compile.mjs",
20
20
  "k-decompile-object": "./objects/decompile.mjs",
21
+ "k-extract-aliases": "./objects/extract-aliases.mjs",
21
22
  "k-parse": "./codecs/k-parse.mjs",
22
- "k-pattern": "./codecs/k-pattern.mjs",
23
+ "k-pattern": "./patterns/from-k.mjs",
23
24
  "k-print": "./codecs/k-print.mjs",
24
25
  "k-repl": "./repl2.mjs",
25
26
  "k-repl2": "./repl2.mjs"
@@ -3,14 +3,14 @@
3
3
  import fs from "node:fs";
4
4
  import { argv, exit, stdin, stdout } from "node:process";
5
5
  import k from "../index.mjs";
6
- import { exportPatternGraph } from "./runtime/codec.mjs";
7
- import { patternToPropertyList } from "./runtime/pattern-json.mjs";
6
+ import { exportPatternGraph } from "../codecs/runtime/codec.mjs";
7
+ import { patternToPropertyList } from "../codecs/runtime/pattern-json.mjs";
8
8
 
9
9
  function usage(prog) {
10
10
  console.error(`Usage: ${prog} [script-or-file]`);
11
11
  console.error(" Read a k script from a file argument or stdin.");
12
12
  console.error(" The main expression must be a filter or a type name.");
13
- console.error(" Output is the canonical JSON pattern array.");
13
+ console.error(" Output is the canonical property-list pattern array.");
14
14
  console.error(" Example:");
15
15
  console.error(` cat pattern.k | ${prog}`);
16
16
  console.error(` ${prog} '$ bits = < {} _, bits 0, bits 1 >; ?< {} nil, { $bits car, X cdr } cons > = X'`);