@fraczak/k 6.3.3 → 6.4.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/DOCS/CODECS.md +258 -0
- package/DOCS/DICTIONARY.md +1172 -0
- package/DOCS/KIR_SPECIALIZATION_DESIGN.md +51 -46
- package/DOCS/KIR_V1.md +221 -0
- package/DOCS/KVM_EXECUTION_MODEL.md +56 -19
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +2 -1
- package/DOCS/PROFILING_AND_TRACING.md +196 -0
- package/DOCS/REPL.md +61 -4
- package/DOCS/WEB_REPL_REQUIREMENTS.md +135 -0
- package/DOCS/dependency-graph.md +144 -0
- package/Examples/arithmetics.k +51 -48
- package/Examples/bnat.k +1 -1
- package/Examples/buda.k +44 -0
- package/Examples/ieee.k +300 -8671
- package/Examples/poly.k +67 -0
- package/README.md +68 -19
- package/augmentation.mjs +9 -7
- package/backend-api.mjs +11 -2
- package/backends/arm64/README.md +104 -0
- package/backends/arm64/bin/k-arm64-compile.mjs +101 -0
- package/backends/arm64/bin/k-arm64-run.mjs +58 -0
- package/backends/arm64/bin/k-arm64.mjs +88 -0
- package/backends/arm64/scripts/run-tests.mjs +41 -0
- package/backends/arm64/src/arm64.mjs +229 -0
- package/backends/arm64/src/cli.mjs +155 -0
- package/backends/arm64/src/kvm2arm64.mjs +906 -0
- package/backends/arm64/src/runtime.c +728 -0
- package/backends/arm64/tests/integration.sh +112 -0
- package/backends/arm64/tests/test-arm64.mjs +240 -0
- package/backends/llvm/README.md +135 -0
- package/backends/llvm/bin/k-llvm-build.mjs +71 -0
- package/backends/llvm/bin/k-llvm-compile.mjs +68 -0
- package/backends/llvm/bin/k-llvm-jit.mjs +160 -0
- package/backends/llvm/bin/k-llvm-run.mjs +90 -0
- package/backends/llvm/runtime/krt.c +1508 -0
- package/backends/llvm/runtime/krt.h +109 -0
- package/backends/llvm/scripts/conformance.mjs +76 -0
- package/backends/llvm/scripts/run-tests.mjs +28 -0
- package/backends/llvm/src/executable.mjs +562 -0
- package/backends/llvm/src/kvm2llvm.mjs +998 -0
- package/backends/llvm/src/llvm.mjs +1092 -0
- package/backends/llvm/tests/composition-driver.c +22 -0
- package/backends/llvm/tests/identity-driver.c +27 -0
- package/backends/llvm/tests/integration.sh +153 -0
- package/backends/llvm/tests/perf-support.mjs +735 -0
- package/backends/llvm/tests/product-driver.c +23 -0
- package/backends/llvm/tests/projection-driver.c +19 -0
- package/backends/llvm/tests/relation-driver.c +29 -0
- package/backends/llvm/tests/test-llvm.mjs +240 -0
- package/backends/llvm/tests/union-driver.c +31 -0
- package/backends/llvm/tests/variant-driver.c +19 -0
- package/backends/llvm/tests/variant-projection-driver.c +21 -0
- package/backends/wasm/DOCS/USE-WEB-ASSEMBLY.md +233 -0
- package/backends/wasm/README.md +97 -0
- package/backends/wasm/TECHNICAL-DEBT.md +60 -0
- package/backends/wasm/bin/k-wasm-compile.mjs +50 -0
- package/backends/wasm/bin/k-wasm-run.mjs +140 -0
- package/backends/wasm/bin/k-wasm.mjs +49 -0
- package/backends/wasm/demo_ieee.mjs +319 -0
- package/backends/wasm/runtime.wat +102 -0
- package/backends/wasm/scripts/run-tests.mjs +41 -0
- package/backends/wasm/src/cli.mjs +133 -0
- package/backends/wasm/src/kvm2wasm.mjs +661 -0
- package/backends/wasm/src/wasm.mjs +1010 -0
- package/backends/wasm/tests/integration.sh +182 -0
- package/backends/wasm/tests/perf-support.mjs +336 -0
- package/backends/wasm/tests/test-wasm.mjs +617 -0
- package/browser/repl-browser.mjs +1584 -0
- package/browser/shims/assert.mjs +19 -0
- package/browser/shims/buffer.mjs +224 -0
- package/browser/shims/crypto.mjs +103 -0
- package/browser/shims/fs.mjs +159 -0
- package/browser/shims/os.mjs +17 -0
- package/browser/shims/path.mjs +54 -0
- package/browser/shims/process.mjs +44 -0
- package/browser/shims/readline.mjs +11 -0
- package/browser/shims/url.mjs +12 -0
- package/browser/vfs-data.mjs +19 -0
- package/codecs/README.md +3 -0
- package/codecs/runtime/show-value.mjs +2 -2
- package/conformance/helper-reuse/case.json +8 -0
- package/conformance/helper-reuse/expected.kv +1 -0
- package/conformance/helper-reuse/input.kv +1 -0
- package/conformance/helper-reuse/program.k +2 -0
- package/conformance/identity/case.json +8 -0
- package/conformance/identity/expected.kv +1 -0
- package/conformance/identity/input.kv +1 -0
- package/conformance/identity/program.k +1 -0
- package/conformance/product-projection/case.json +8 -0
- package/conformance/product-projection/expected.kv +1 -0
- package/conformance/product-projection/input.kv +1 -0
- package/conformance/product-projection/program.k +1 -0
- package/conformance/run.mjs +149 -0
- package/conformance/variant-construction/case.json +8 -0
- package/conformance/variant-construction/expected.kv +1 -0
- package/conformance/variant-construction/input.kv +1 -0
- package/conformance/variant-construction/program.k +1 -0
- package/harness/adapters/arm64.mjs +105 -0
- package/harness/adapters/kvm.mjs +144 -0
- package/harness/adapters/llvm.mjs +118 -0
- package/harness/adapters/native.mjs +77 -0
- package/harness/adapters/wasm.mjs +169 -0
- package/harness/backend.mjs +95 -0
- package/harness/cli.mjs +130 -0
- package/harness/format.mjs +95 -0
- package/harness/index.mjs +25 -0
- package/harness/persistent.mjs +121 -0
- package/harness/registry.mjs +44 -0
- package/harness/suite.mjs +257 -0
- package/harness/suites/poly.mjs +156 -0
- package/harness/trace.mjs +50 -0
- package/harness/util.mjs +92 -0
- package/intrinsics.mjs +41 -0
- package/kir.mjs +399 -0
- package/kvm.mjs +585 -81
- package/objects/README.md +37 -3
- package/objects/compile.mjs +15 -22
- package/objects/inspect.mjs +96 -0
- package/objects/validate.mjs +415 -0
- package/package.json +51 -19
- package/repl-codecs.mjs +105 -6
- package/repl.mjs +335 -49
- package/run.mjs +2 -7
- package/scripts/benchmark.mjs +406 -22
- package/scripts/build-repl-html.mjs +1784 -0
- package/scripts/perf-ieee.mjs +586 -0
- package/scripts/perf-int.mjs +531 -0
- package/scripts/perf-poly.mjs +945 -0
- package/scripts/render-benchmark.mjs +12 -8
- package/scripts/run-tests.mjs +6 -0
- package/tests/integration.sh +19 -2
- package/tests/test-arithmetics.mjs +54 -0
- package/tests/test-ieee-arithmetic.mjs +4 -0
- package/tests/test-kir.mjs +85 -0
- package/tests/test-kvm-polymorphic.mjs +278 -0
- package/tests/test-kvm.mjs +25 -6
- package/tests/test-poly.mjs +129 -0
- package/tests/test-repl-html.mjs +303 -0
- package/tests/test-repl.mjs +144 -1
- package/tests/test-validate-object.mjs +40 -0
- package/a.klib +0 -1
- package/a.kvm +0 -142676
- package/a.wasm +0 -0
- package/benchmark-results.html +0 -532
- package/benchmark-results.json +0 -480
- package/k-vscode/.vscode/launch.json +0 -14
- package/k-vscode/README.md +0 -75
- package/k-vscode/extension.js +0 -273
- package/k-vscode/language-configuration.json +0 -42
- package/k-vscode/package.json +0 -79
- package/k-vscode/snippets/k.json +0 -92
- package/k-vscode/syntaxes/k.tmLanguage.json +0 -599
- package/k-vscode/test/background-ranges.test.js +0 -50
- package/k-vscode/themes/k-contrast-color-theme.json +0 -104
- package/scripts/git-hooks/pre-commit +0 -10
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#ifndef KRT_H
|
|
2
|
+
#define KRT_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
|
|
8
|
+
typedef struct k_rt k_rt;
|
|
9
|
+
typedef struct k_value k_value;
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
void *block;
|
|
13
|
+
size_t used;
|
|
14
|
+
} k_rt_checkpoint;
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
const char *label;
|
|
18
|
+
size_t label_length;
|
|
19
|
+
size_t target;
|
|
20
|
+
} k_pattern_edge;
|
|
21
|
+
|
|
22
|
+
typedef struct {
|
|
23
|
+
int kind;
|
|
24
|
+
size_t edge_count;
|
|
25
|
+
k_pattern_edge *edges;
|
|
26
|
+
} k_pattern_node;
|
|
27
|
+
|
|
28
|
+
typedef struct {
|
|
29
|
+
size_t node_count;
|
|
30
|
+
k_pattern_node *nodes;
|
|
31
|
+
} k_pattern;
|
|
32
|
+
|
|
33
|
+
typedef struct {
|
|
34
|
+
k_value *value;
|
|
35
|
+
k_pattern *pattern;
|
|
36
|
+
} k_wire_input;
|
|
37
|
+
|
|
38
|
+
typedef struct {
|
|
39
|
+
unsigned char *bytes;
|
|
40
|
+
size_t length;
|
|
41
|
+
unsigned char current;
|
|
42
|
+
int bit_count;
|
|
43
|
+
int ok;
|
|
44
|
+
} k_wire_prefix;
|
|
45
|
+
|
|
46
|
+
enum {
|
|
47
|
+
KP_ANY,
|
|
48
|
+
KP_OPEN_PRODUCT,
|
|
49
|
+
KP_OPEN_UNION,
|
|
50
|
+
KP_CLOSED_PRODUCT,
|
|
51
|
+
KP_CLOSED_UNION
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
typedef struct {
|
|
55
|
+
int32_t status;
|
|
56
|
+
k_value *value;
|
|
57
|
+
} k_result;
|
|
58
|
+
|
|
59
|
+
enum {
|
|
60
|
+
K_STATUS_OK = 0,
|
|
61
|
+
K_STATUS_UNSUPPORTED = 1,
|
|
62
|
+
K_STATUS_TAIL_CALL = 2
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
k_rt *k_rt_new(void);
|
|
66
|
+
void k_rt_reset(k_rt *rt);
|
|
67
|
+
k_rt_checkpoint k_rt_mark(k_rt *rt);
|
|
68
|
+
void k_rt_rewind(k_rt *rt, k_rt_checkpoint mark);
|
|
69
|
+
void *k_rt_alloc(k_rt *rt, size_t size);
|
|
70
|
+
void k_rt_free(k_rt *rt);
|
|
71
|
+
|
|
72
|
+
k_value *k_unit(k_rt *rt);
|
|
73
|
+
k_value *k_bit0(k_rt *rt);
|
|
74
|
+
k_value *k_bit1(k_rt *rt);
|
|
75
|
+
k_value *k_product(k_rt *rt, size_t count);
|
|
76
|
+
void k_product_set_n(k_value *product, const char *label, size_t label_length, k_value *value);
|
|
77
|
+
void k_product_set_borrowed_n(k_value *product, const char *label, size_t label_length, k_value *value);
|
|
78
|
+
void k_product_set_at(k_value *product, size_t index, const char *label, size_t label_length, k_value *value);
|
|
79
|
+
k_value *k_product_get_n(k_value *product, const char *label, size_t label_length);
|
|
80
|
+
k_value *k_product_get_at(k_value *product, size_t index);
|
|
81
|
+
void k_product_set(k_value *product, const char *label, k_value *value);
|
|
82
|
+
k_value *k_product_get(k_value *product, const char *label);
|
|
83
|
+
|
|
84
|
+
k_value *k_variant_n(k_rt *rt, const char *tag, size_t tag_length, k_value *payload);
|
|
85
|
+
k_value *k_variant_borrowed_n(k_rt *rt, const char *tag, size_t tag_length, k_value *payload);
|
|
86
|
+
k_value *k_variant_borrowed_direct_n(k_rt *rt, const char *tag, size_t tag_length, k_value *payload);
|
|
87
|
+
k_value *k_variant_unit_borrowed_n(k_rt *rt, const char *tag, size_t tag_length);
|
|
88
|
+
k_value *k_variant(k_rt *rt, const char *tag, k_value *payload);
|
|
89
|
+
const char *k_variant_tag(k_value *value);
|
|
90
|
+
size_t k_variant_tag_length(k_value *value);
|
|
91
|
+
int k_variant_tag_matches(k_value *value, const char *tag, size_t tag_length);
|
|
92
|
+
k_value *k_variant_payload(k_value *value);
|
|
93
|
+
|
|
94
|
+
int k_equal(k_value *a, k_value *b);
|
|
95
|
+
void k_print_json(FILE *out, k_value *value);
|
|
96
|
+
k_value *k_read_wire(FILE *in, k_rt *rt);
|
|
97
|
+
k_wire_input k_read_wire_envelope(FILE *in, k_rt *rt);
|
|
98
|
+
k_wire_input k_decode_wire_envelope(const unsigned char *bytes, size_t length, k_rt *rt);
|
|
99
|
+
void k_wire_input_free(k_wire_input input);
|
|
100
|
+
int k_pattern_equal(k_pattern *a, k_pattern *b);
|
|
101
|
+
k_wire_prefix k_wire_prefix_for_pattern(k_pattern *pattern);
|
|
102
|
+
void k_wire_prefix_free(k_wire_prefix prefix);
|
|
103
|
+
k_value *k_decode_wire_value_with_prefix(const unsigned char *bytes, size_t length, k_wire_prefix *prefix, k_pattern *pattern, k_rt *rt);
|
|
104
|
+
unsigned char *k_encode_wire_as_with_prefix(k_wire_prefix *prefix, k_pattern *pattern, k_value *value, size_t *out_length);
|
|
105
|
+
unsigned char *k_encode_wire_as(k_pattern *pattern, k_value *value, size_t *out_length);
|
|
106
|
+
int k_write_wire(FILE *out, k_value *value);
|
|
107
|
+
int k_write_wire_as(FILE *out, k_pattern *pattern, k_value *value);
|
|
108
|
+
|
|
109
|
+
#endif
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { argv, exit } from "node:process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { compileObjectBuffer, decodeObject } from "@fraczak/k/object.mjs";
|
|
8
|
+
import { parseValue } from "@fraczak/k/valueIO.mjs";
|
|
9
|
+
import { compileObjectAndRun } from "../src/executable.mjs";
|
|
10
|
+
|
|
11
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
|
+
const kRoot = path.resolve(root, "../..");
|
|
13
|
+
const conformanceRoot = path.join(kRoot, "conformance");
|
|
14
|
+
|
|
15
|
+
function helpText() {
|
|
16
|
+
return [
|
|
17
|
+
"Run k-llvm executable conformance fixtures.",
|
|
18
|
+
"",
|
|
19
|
+
`Usage: ${argv[1]} [fixture-dir ...]`,
|
|
20
|
+
"",
|
|
21
|
+
"With no fixture dirs, every supported directory under ../../conformance is run."
|
|
22
|
+
].join("\n");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function fixtureDirs(args) {
|
|
26
|
+
if (args.length > 0) return args.map((arg) => path.resolve(root, arg));
|
|
27
|
+
return fs.readdirSync(conformanceRoot, { withFileTypes: true })
|
|
28
|
+
.filter((entry) => entry.isDirectory())
|
|
29
|
+
.map((entry) => path.join(conformanceRoot, entry.name))
|
|
30
|
+
.filter((dir) => fs.existsSync(path.join(dir, "case.json")))
|
|
31
|
+
.sort();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readFixture(dir) {
|
|
35
|
+
const spec = JSON.parse(fs.readFileSync(path.join(dir, "case.json"), "utf8"));
|
|
36
|
+
return {
|
|
37
|
+
dir,
|
|
38
|
+
name: spec.name || path.basename(dir),
|
|
39
|
+
program: fs.readFileSync(path.join(dir, spec.program || "program.k"), "utf8"),
|
|
40
|
+
input: parseValue(fs.readFileSync(path.join(dir, spec.input || "input.kv"), "utf8")),
|
|
41
|
+
expected: parseValue(fs.readFileSync(path.join(dir, spec.expected || "expected.kv"), "utf8"))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function runFixture(fixture) {
|
|
46
|
+
const object = decodeObject(compileObjectBuffer(fixture.program, {
|
|
47
|
+
source: path.relative(kRoot, fixture.dir)
|
|
48
|
+
}));
|
|
49
|
+
compileObjectAndRun(object, {
|
|
50
|
+
input: fixture.input,
|
|
51
|
+
expected: fixture.expected
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const args = argv.slice(2);
|
|
57
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
58
|
+
console.log(helpText());
|
|
59
|
+
exit(0);
|
|
60
|
+
}
|
|
61
|
+
if (args.some((arg) => arg.startsWith("--"))) {
|
|
62
|
+
throw new Error(`Unknown option: ${args.find((arg) => arg.startsWith("--"))}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let count = 0;
|
|
66
|
+
for (const fixture of fixtureDirs(args).map(readFixture)) {
|
|
67
|
+
runFixture(fixture);
|
|
68
|
+
count++;
|
|
69
|
+
console.log(`ok ${fixture.name}`);
|
|
70
|
+
}
|
|
71
|
+
console.log(`OK ${count} fixtures`);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error.stack || error.message || String(error));
|
|
74
|
+
console.error(helpText());
|
|
75
|
+
exit(1);
|
|
76
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const node = process.execPath;
|
|
9
|
+
const tests = [
|
|
10
|
+
["tests/test-llvm.mjs", node, ["tests/test-llvm.mjs"]],
|
|
11
|
+
["tests/integration.sh", path.join(root, "tests/integration.sh"), []],
|
|
12
|
+
["scripts/conformance.mjs", node, ["scripts/conformance.mjs"]]
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
for (const [name, command, args] of tests) {
|
|
16
|
+
console.log(`\n==> ${name}`);
|
|
17
|
+
const result = spawnSync(command, args, {
|
|
18
|
+
cwd: root,
|
|
19
|
+
stdio: "inherit"
|
|
20
|
+
});
|
|
21
|
+
if (result.error) {
|
|
22
|
+
console.error(result.error.message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log("\nAll tests passed");
|