@fraczak/k 7.0.1 → 7.1.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 +78 -0
- package/DOCS/BIG_PICTURE.md +5 -5
- package/DOCS/FILE_FORMATS.md +241 -18
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +9 -9
- package/DOCS/PATTERNS.md +3 -3
- package/DOCS/POLYMORPHIC_IR.md +104 -0
- package/DOCS/PROFILING_AND_TRACING.md +60 -72
- package/DOCS/REPL.md +3 -3
- package/DOCS/book/03-types-as-finite-automata.md +4 -4
- package/DOCS/book/06-values-in-memory.md +9 -9
- package/DOCS/book/08-operational-semantics-and-execution.md +1 -1
- package/DOCS/book/09-compiler-architecture.md +2 -2
- package/DOCS/book/10-from-ast-to-intermediate-representation.md +2 -2
- package/DOCS/book/14-canonical-serialization.md +1 -1
- package/Examples/arithmetics.k +2 -2
- package/Examples/bnat.k +1 -1
- package/Examples/karatsuba-mult.k +2 -2
- package/JOURNAL.md +288 -0
- package/README.md +13 -10
- package/access-table.mjs +343 -0
- package/backend-api.mjs +18 -0
- package/backends/llvm/README.md +20 -21
- package/backends/llvm/bin/k-llvm-build.mjs +105 -32
- package/backends/llvm/bin/k-llvm-compile.mjs +63 -24
- package/backends/llvm/bin/k-llvm.mjs +292 -0
- package/backends/llvm/runtime/krt.c +41 -0
- package/backends/llvm/runtime/krt.h +2 -0
- package/backends/llvm/src/cli.mjs +95 -17
- package/backends/llvm/src/executable.mjs +132 -15
- package/backends/llvm/src/kvm2llvm.mjs +50 -23
- package/backends/llvm/src/llvm.mjs +133 -20
- package/backends/llvm/tests/integration.sh +11 -11
- package/backends/llvm/{bin → tests}/k-llvm-run.mjs +48 -22
- package/backends/llvm/tests/perf-support.mjs +25 -58
- package/backends/llvm/tests/test-llvm.mjs +25 -4
- package/backends/wasm/bin/k-wasm-compile.mjs +46 -20
- package/backends/wasm/bin/k-wasm-run.mjs +61 -20
- package/backends/wasm/bin/k-wasm.mjs +47 -13
- package/backends/wasm/src/cli.mjs +141 -19
- package/backends/wasm/src/wasm.mjs +132 -24
- package/backends/wasm/tests/test-wasm.mjs +5 -5
- package/browser/repl-browser.mjs +16 -5
- package/browser/vfs-data.mjs +5 -5
- package/codecs/k-parse.mjs +29 -8
- package/codecs/k-print.mjs +22 -6
- package/codecs/runtime/codec-sdk.mjs +8 -4
- package/codecs/show.mjs +20 -6
- package/core.k +8 -8
- package/harness/format.mjs +2 -2
- package/harness/registry.mjs +0 -2
- package/k.mjs +56 -16
- package/kir.mjs +200 -75
- package/kvm.mjs +49 -12
- package/objects/compile.mjs +37 -23
- package/objects/decompile.mjs +40 -10
- package/objects/extract-aliases.mjs +44 -14
- package/objects/inspect.mjs +19 -14
- package/objects/validate.mjs +18 -11
- package/package.json +10 -7
- package/pkir.mjs +772 -0
- package/repl.mjs +36 -18
- package/scripts/benchmark-idempotency.mjs +12 -8
- package/scripts/benchmark.mjs +5 -9
- package/scripts/build-repl-html.mjs +16 -4
- package/scripts/perf-ieee.mjs +253 -103
- package/scripts/perf-int.mjs +585 -297
- package/scripts/perf-multiplication.mjs +66 -25
- package/scripts/perf-poly.mjs +292 -164
- package/scripts/run-tests.mjs +3 -0
- package/tests/code-derivation/pattern-envelope.mjs +4 -4
- package/tests/test-access-table.mjs +213 -0
- package/tests/test-kvm-polymorphic.mjs +2 -2
- package/tests/test-pkir.mjs +530 -0
- package/tests/test-polymorphic-tdd.mjs +196 -0
- package/tests/test-repl-html.mjs +15 -2
- package/tests/test-repl.mjs +30 -1
- package/backends/arm64/README.md +0 -103
- package/backends/arm64/bin/k-arm64-compile.mjs +0 -93
- package/backends/arm64/bin/k-arm64-run.mjs +0 -58
- package/backends/arm64/bin/k-arm64.mjs +0 -88
- package/backends/arm64/scripts/run-tests.mjs +0 -57
- package/backends/arm64/src/arm64.mjs +0 -229
- package/backends/arm64/src/cli.mjs +0 -155
- package/backends/arm64/src/kvm2arm64.mjs +0 -906
- package/backends/arm64/src/runtime.c +0 -744
- package/backends/arm64/tests/integration.sh +0 -112
- package/backends/arm64/tests/test-arm64.mjs +0 -240
- package/backends/llvm/bin/k-llvm-jit.mjs +0 -160
- package/harness/adapters/arm64.mjs +0 -105
|
@@ -5,24 +5,28 @@ import { argv, exit, stdin, stdout } from "node:process";
|
|
|
5
5
|
import { extractAliasesFromObjectBuffer } from "../object.mjs";
|
|
6
6
|
|
|
7
7
|
function helpText() {
|
|
8
|
+
const prog = argv[1] || "extract-aliases.mjs";
|
|
8
9
|
return [
|
|
9
|
-
"Extract metadata aliases from a .ko or .klib as
|
|
10
|
+
"Extract metadata aliases from a .ko or .klib as valid k source.",
|
|
10
11
|
"",
|
|
11
|
-
`Usage: ${
|
|
12
|
+
`Usage: ${prog} [options] [ object-file [ k-file ] ]`,
|
|
12
13
|
"",
|
|
13
|
-
"Output is grouped by metadata type (code, then rel), then sorted
|
|
14
|
-
"name and compiledAt. Earlier definitions of the same alias
|
|
15
|
-
"out so only the latest one remains active.",
|
|
14
|
+
"Output is grouped by metadata type (code, then rel), then sorted",
|
|
15
|
+
"by alias name and compiledAt. Earlier definitions of the same alias",
|
|
16
|
+
"are commented out so only the latest one remains active.",
|
|
16
17
|
"",
|
|
17
18
|
"Arguments:",
|
|
18
|
-
" object-file
|
|
19
|
-
"
|
|
19
|
+
" object-file Input .ko or .klib path.",
|
|
20
|
+
" Reads object data from stdin when omitted.",
|
|
21
|
+
" k-file Output .k path (default: stdout).",
|
|
20
22
|
"",
|
|
21
23
|
"Options:",
|
|
22
|
-
" -
|
|
24
|
+
" -o, --output path Specify output file path explicitly.",
|
|
25
|
+
" -h, --help Show this help.",
|
|
23
26
|
"",
|
|
24
|
-
"
|
|
25
|
-
` ${
|
|
27
|
+
"Examples:",
|
|
28
|
+
` ${prog} core.klib -o aliases.k`,
|
|
29
|
+
` ${prog} core.klib aliases.k`
|
|
26
30
|
].join("\n");
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -39,13 +43,39 @@ async function readStdinBuffer() {
|
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
try {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
46
|
+
const rawArgs = argv.slice(2);
|
|
47
|
+
if (rawArgs.includes("-h") || rawArgs.includes("--help")) {
|
|
44
48
|
usage(console.log);
|
|
45
49
|
exit(0);
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
let explicitOutput = null;
|
|
53
|
+
const remainingArgs = [];
|
|
54
|
+
while (rawArgs.length > 0) {
|
|
55
|
+
const arg = rawArgs[0];
|
|
56
|
+
if (arg === "-o" || arg === "--output") {
|
|
57
|
+
rawArgs.shift();
|
|
58
|
+
explicitOutput = rawArgs.shift();
|
|
59
|
+
if (!explicitOutput) {
|
|
60
|
+
throw new Error("-o/--output requires a file argument");
|
|
61
|
+
}
|
|
62
|
+
} else if (arg.startsWith("-")) {
|
|
63
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
64
|
+
} else {
|
|
65
|
+
remainingArgs.push(rawArgs.shift());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const objectPath = remainingArgs.shift() || null;
|
|
70
|
+
const positionalOutput = remainingArgs.shift() || null;
|
|
71
|
+
if (remainingArgs.length > 0) {
|
|
72
|
+
throw new Error(`Unexpected argument: ${remainingArgs[0]}`);
|
|
73
|
+
}
|
|
74
|
+
const outputPath = explicitOutput || positionalOutput || null;
|
|
75
|
+
|
|
76
|
+
const objectBuffer = objectPath == null
|
|
77
|
+
? await readStdinBuffer()
|
|
78
|
+
: fs.readFileSync(objectPath);
|
|
49
79
|
const source = extractAliasesFromObjectBuffer(objectBuffer);
|
|
50
80
|
if (outputPath == null) {
|
|
51
81
|
stdout.write(source);
|
|
@@ -53,7 +83,7 @@ try {
|
|
|
53
83
|
fs.writeFileSync(outputPath, source);
|
|
54
84
|
}
|
|
55
85
|
} catch (error) {
|
|
56
|
-
console.error(error);
|
|
86
|
+
console.error(error.message || String(error));
|
|
57
87
|
usage();
|
|
58
88
|
exit(1);
|
|
59
89
|
}
|
package/objects/inspect.mjs
CHANGED
|
@@ -6,20 +6,26 @@ import { decodeObject } from "../object.mjs";
|
|
|
6
6
|
import { objectToKIRP } from "../kir.mjs";
|
|
7
7
|
|
|
8
8
|
function helpText() {
|
|
9
|
+
const prog = argv[1] || "inspect.mjs";
|
|
9
10
|
return [
|
|
10
11
|
"Inspect a k .ko or .klib object.",
|
|
11
12
|
"",
|
|
12
|
-
`Usage: ${
|
|
13
|
+
`Usage: ${prog} [options] [object-file]`,
|
|
13
14
|
"",
|
|
14
15
|
"Arguments:",
|
|
15
|
-
" object-file Input .ko or .klib file
|
|
16
|
+
" object-file Input .ko or .klib file (default: stdin).",
|
|
16
17
|
"",
|
|
17
18
|
"Options:",
|
|
18
19
|
" --kir Print the KIR-P JSON view.",
|
|
19
|
-
" --summary Print a compact section summary
|
|
20
|
+
" --summary Print a compact section summary (default).",
|
|
20
21
|
" -h, --help Show this help.",
|
|
21
22
|
"",
|
|
22
|
-
"KIR-P is an inspection/export view; it does not change the stored
|
|
23
|
+
"KIR-P is an inspection/export view; it does not change the stored",
|
|
24
|
+
"object format.",
|
|
25
|
+
"",
|
|
26
|
+
"Examples:",
|
|
27
|
+
` ${prog} program.ko`,
|
|
28
|
+
` ${prog} --kir program.ko`
|
|
23
29
|
].join("\n");
|
|
24
30
|
}
|
|
25
31
|
|
|
@@ -66,22 +72,21 @@ try {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
let mode = "summary";
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
75
|
+
let inputPath = null;
|
|
76
|
+
for (const arg of args) {
|
|
77
|
+
if (arg === "--kir") {
|
|
72
78
|
mode = "kir";
|
|
73
|
-
} else if (
|
|
79
|
+
} else if (arg === "--summary") {
|
|
74
80
|
mode = "summary";
|
|
81
|
+
} else if (arg.startsWith("-")) {
|
|
82
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
83
|
+
} else if (inputPath == null) {
|
|
84
|
+
inputPath = arg;
|
|
75
85
|
} else {
|
|
76
|
-
throw new Error(`
|
|
86
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
const inputPath = args.shift() || null;
|
|
81
|
-
if (args.length > 0) {
|
|
82
|
-
throw new Error(`Unexpected argument: ${args[0]}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
90
|
const buffer = inputPath == null ? await readStdinBytes() : fs.readFileSync(inputPath);
|
|
86
91
|
const object = decodeObject(buffer);
|
|
87
92
|
if (mode === "kir") {
|
package/objects/validate.mjs
CHANGED
|
@@ -346,19 +346,25 @@ export function validateKIRP(kir) {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
function helpText() {
|
|
349
|
+
const prog = argv[1] || "validate.mjs";
|
|
349
350
|
return [
|
|
350
351
|
"Validate a k .ko/.klib object or KIR-P JSON file.",
|
|
351
352
|
"",
|
|
352
|
-
`Usage: ${
|
|
353
|
+
`Usage: ${prog} [options] [input-file]`,
|
|
353
354
|
"",
|
|
354
355
|
"Arguments:",
|
|
355
|
-
" input-file Input .ko/.klib file, or KIR JSON with --kir.
|
|
356
|
+
" input-file Input .ko/.klib file, or KIR JSON with --kir.",
|
|
357
|
+
" Reads stdin when omitted.",
|
|
356
358
|
"",
|
|
357
359
|
"Options:",
|
|
358
|
-
" --kir Validate input as KIR-P JSON instead of
|
|
360
|
+
" --kir Validate input as KIR-P JSON instead of an object.",
|
|
359
361
|
" -h, --help Show this help.",
|
|
360
362
|
"",
|
|
361
|
-
"Object validation also validates the derived KIR-P export view."
|
|
363
|
+
"Object validation also validates the derived KIR-P export view.",
|
|
364
|
+
"",
|
|
365
|
+
"Examples:",
|
|
366
|
+
` ${prog} program.ko`,
|
|
367
|
+
` ${prog} --kir program.kir.json`
|
|
362
368
|
].join("\n");
|
|
363
369
|
}
|
|
364
370
|
|
|
@@ -382,18 +388,19 @@ async function main() {
|
|
|
382
388
|
}
|
|
383
389
|
|
|
384
390
|
let mode = "object";
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (
|
|
391
|
+
let inputPath = null;
|
|
392
|
+
for (const arg of args) {
|
|
393
|
+
if (arg === "--kir") {
|
|
388
394
|
mode = "kir";
|
|
395
|
+
} else if (arg.startsWith("-")) {
|
|
396
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
397
|
+
} else if (inputPath == null) {
|
|
398
|
+
inputPath = arg;
|
|
389
399
|
} else {
|
|
390
|
-
throw new Error(`
|
|
400
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
391
401
|
}
|
|
392
402
|
}
|
|
393
403
|
|
|
394
|
-
const inputPath = args.shift() || null;
|
|
395
|
-
if (args.length > 0) throw new Error(`Unexpected argument: ${args[0]}`);
|
|
396
|
-
|
|
397
404
|
const input = inputPath == null ? await readStdinBytes() : fs.readFileSync(inputPath);
|
|
398
405
|
if (mode === "kir") {
|
|
399
406
|
validateKIRP(JSON.parse(input.toString("utf8")));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "k — a language for content-addressable schemas and data transformations over algebraic data types (products and tagged unions); includes runtime, contract derivation, REPL, and codec toolchain",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,15 +16,22 @@
|
|
|
16
16
|
"test:backends": "node backends/llvm/scripts/run-tests.mjs && node backends/wasm/scripts/run-tests.mjs",
|
|
17
17
|
"test:llvm": "node backends/llvm/scripts/run-tests.mjs",
|
|
18
18
|
"test:wasm": "node backends/wasm/scripts/run-tests.mjs",
|
|
19
|
-
"test:arm64": "node backends/arm64/scripts/run-tests.mjs",
|
|
20
19
|
"conformance": "node conformance/run.mjs",
|
|
21
20
|
"benchmark": "node scripts/benchmark.mjs",
|
|
22
21
|
"benchmark:html": "node scripts/render-benchmark.mjs",
|
|
23
22
|
"perf:ieee": "node scripts/perf-ieee.mjs",
|
|
24
23
|
"perf:ieee:full": "node scripts/perf-ieee.mjs --full",
|
|
24
|
+
"perf:ieee:pkir": "BACKENDS=pkir node scripts/perf-ieee.mjs",
|
|
25
|
+
"perf:ieee:llvm-pkir": "BACKENDS=llvm-pkir node scripts/perf-ieee.mjs",
|
|
25
26
|
"perf:int": "node scripts/perf-int.mjs",
|
|
27
|
+
"perf:int:pkir": "BACKENDS=pkir node scripts/perf-int.mjs",
|
|
28
|
+
"perf:int:llvm-pkir": "BACKENDS=llvm-pkir node scripts/perf-int.mjs",
|
|
26
29
|
"perf:mult": "node scripts/perf-multiplication.mjs",
|
|
30
|
+
"perf:mult:pkir": "node scripts/perf-multiplication.mjs --backends pkir",
|
|
31
|
+
"perf:mult:llvm-pkir": "node scripts/perf-multiplication.mjs --backends llvm-pkir",
|
|
27
32
|
"perf:poly": "node scripts/perf-poly.mjs",
|
|
33
|
+
"perf:poly:pkir": "BACKENDS=pkir node scripts/perf-poly.mjs",
|
|
34
|
+
"perf:poly:llvm-pkir": "BACKENDS=llvm-pkir node scripts/perf-poly.mjs",
|
|
28
35
|
"perf:poly:trace": "node scripts/perf-poly.mjs --trace",
|
|
29
36
|
"perf:idempotency": "node scripts/benchmark-idempotency.mjs",
|
|
30
37
|
"deps:graph": "node scripts/generate-dependency-graph.mjs",
|
|
@@ -45,13 +52,9 @@
|
|
|
45
52
|
"k-inspect-object": "objects/inspect.mjs",
|
|
46
53
|
"k-validate-object": "objects/validate.mjs",
|
|
47
54
|
"k-kir": "kir.mjs",
|
|
55
|
+
"k-llvm": "backends/llvm/bin/k-llvm.mjs",
|
|
48
56
|
"k-llvm-build": "backends/llvm/bin/k-llvm-build.mjs",
|
|
49
57
|
"k-llvm-compile": "backends/llvm/bin/k-llvm-compile.mjs",
|
|
50
|
-
"k-llvm-jit": "backends/llvm/bin/k-llvm-jit.mjs",
|
|
51
|
-
"k-llvm-run": "backends/llvm/bin/k-llvm-run.mjs",
|
|
52
|
-
"k-arm64": "backends/arm64/bin/k-arm64.mjs",
|
|
53
|
-
"k-arm64-compile": "backends/arm64/bin/k-arm64-compile.mjs",
|
|
54
|
-
"k-arm64-run": "backends/arm64/bin/k-arm64-run.mjs",
|
|
55
58
|
"k-wasm": "backends/wasm/bin/k-wasm.mjs",
|
|
56
59
|
"k-wasm-compile": "backends/wasm/bin/k-wasm-compile.mjs",
|
|
57
60
|
"k-wasm-run": "backends/wasm/bin/k-wasm-run.mjs",
|