@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.
- package/AGENTS.md +35 -0
- package/CHANGELOG.md +48 -0
- package/CLAUDE.md +64 -0
- package/DOCS/BIG_PICTURE.md +4 -8
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +74 -0
- package/DOCS/CONVERGENCE.md +92 -0
- package/DOCS/DIVERGENCE_DETECTION.md +24 -0
- package/DOCS/Makefile +99 -0
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +221 -0
- package/DOCS/PATTERNS.md +114 -0
- package/DOCS/PATTERNS_AND_TYPED_VALUES.md +665 -0
- package/DOCS/REPL.md +127 -126
- package/DOCS/TEXTUAL_VALUES.md +108 -0
- package/DOCS/TYPE_DERIVATION.md +230 -0
- package/DOCS/book/06-values-in-memory.md +1085 -0
- package/DOCS/book/07-the-partial-function-abi.md +143 -0
- package/DOCS/book/08-operational-semantics-and-execution.md +201 -0
- package/DOCS/book/09-compiler-architecture.md +160 -0
- package/DOCS/book/10-from-ast-to-intermediate-representation.md +167 -0
- package/DOCS/book/14-canonical-serialization.md +176 -0
- package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +155 -0
- package/DOCS/book/overview.txt +68 -0
- package/README.md +78 -30
- package/UU/ta.k +1 -0
- package/UU/ta.k~ +0 -0
- package/UU/tb.k +0 -0
- package/UU/tc.k +0 -0
- package/codecs/README.md +12 -0
- package/codecs/pandoc.css +71 -0
- package/codecs/runtime/test-codec.mjs +89 -0
- package/core.klib +0 -0
- package/core.klib~ +0 -0
- package/ieee.klib +0 -0
- package/kkk.k +197 -0
- package/kkk.klib +0 -0
- package/kkk.klib~ +0 -0
- package/object.mjs +162 -8
- package/objects/README.md +10 -0
- package/objects/compile-lib.mjs +26 -2
- package/objects/compile.mjs +26 -2
- package/objects/decompile.mjs +25 -2
- package/objects/extract-aliases.mjs +59 -0
- package/package.json +3 -2
- package/{codecs/k-pattern.mjs → patterns/from-k.mjs} +3 -3
- package/repl2.mjs +345 -83
- package/scripts/generate-dependency-graph.mjs +121 -0
- package/test-k-object.mjs +77 -1
- package/test-repl2.mjs +65 -8
- package/DOCS/book-combined.html +0 -3798
- package/DOCS/book-combined.md +0 -3745
- package/DOCS/book-combined.pdf +0 -0
- package/DOCS/book-combined.tex +0 -5682
- package/DOCS/book.html +0 -65
- package/DOCS/book.pdf +0 -0
- 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.
|
|
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": "./
|
|
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 "
|
|
7
|
-
import { patternToPropertyList } from "
|
|
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
|
|
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'`);
|