@fraczak/k 6.10.3 → 6.10.5
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/FILE_FORMATS.md +51 -16
- package/Examples/arithmetics.k +222 -110
- package/Examples/karatsuba-mult.k +215 -0
- package/Examples/poly.k +14 -5
- package/backends/arm64/scripts/run-tests.mjs +16 -0
- package/backends/llvm/bin/k-llvm-build.mjs +40 -14
- package/backends/llvm/bin/k-llvm-compile.mjs +29 -12
- package/backends/llvm/runtime/krt.c +10 -10
- package/backends/llvm/runtime/krt.h +6 -1
- package/backends/llvm/scripts/run-tests.mjs +16 -0
- package/backends/llvm/src/cli.mjs +1 -1
- package/backends/llvm/src/executable.mjs +36 -0
- package/backends/llvm/src/kvm2llvm.mjs +10 -4
- package/backends/llvm/tests/integration.sh +11 -0
- package/backends/llvm/tests/test-llvm.mjs +15 -1
- package/backends/wasm/scripts/run-tests.mjs +16 -0
- package/browser/shims/fs.mjs +12 -7
- package/browser/vfs-data.mjs +7 -10
- package/core.k +25 -18
- package/harness/suites/poly.mjs +1 -1
- package/package.json +2 -1
- package/repl-codecs.mjs +6 -3
- package/scripts/benchmark-idempotency.mjs +27 -0
- package/scripts/benchmark.mjs +51 -0
- package/scripts/build-repl-html.mjs +28 -10
- package/scripts/generate-dependency-graph.mjs +25 -1
- package/scripts/perf-ieee.mjs +75 -0
- package/scripts/perf-int.mjs +67 -0
- package/scripts/perf-multiplication.mjs +644 -0
- package/scripts/perf-poly.mjs +68 -1
- package/scripts/render-benchmark.mjs +25 -0
- package/scripts/run-tests.mjs +19 -0
- package/tests/test-arithmetics.mjs +96 -0
- package/tests/test-karatsuba.mjs +133 -0
- package/tests/test-repl-html.mjs +23 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { compileObjectBuffer, decodeObject } from "@fraczak/k/object.mjs";
|
|
3
|
-
import { compileObjectToLLVM, emitLLVMModule, llvmIdentifier } from "../src/llvm.mjs";
|
|
3
|
+
import { compileObjectToLLVM, compileLLVMArtifactFromKVM, emitLLVMModule, llvmIdentifier } from "../src/llvm.mjs";
|
|
4
|
+
import { objectToKVMArtifact } from "@fraczak/k/kvm.mjs";
|
|
4
5
|
|
|
5
6
|
function kirP(body, { patternGraph = null } = {}) {
|
|
6
7
|
return {
|
|
@@ -256,4 +257,17 @@ const { llvm: productRecurseLLVM } = compileObjectToLLVM(productRecurseObject, {
|
|
|
256
257
|
// Calls inside product fields must not return tail status (i32 2)
|
|
257
258
|
assert.doesNotMatch(productRecurseLLVM, /insertvalue %k_result undef, i32 2, 0/);
|
|
258
259
|
|
|
260
|
+
const kvmArtifact = objectToKVMArtifact(productObject, "__main__");
|
|
261
|
+
assert.equal(kvmArtifact.format, "k-vm");
|
|
262
|
+
const kvmLLVM = compileLLVMArtifactFromKVM(kvmArtifact, {
|
|
263
|
+
inputPattern: [
|
|
264
|
+
["closed-product", [["x", 1], ["y", 2]]],
|
|
265
|
+
["closed-product", [["valA", 1]]],
|
|
266
|
+
["closed-product", [["valB", 2]]]
|
|
267
|
+
]
|
|
268
|
+
});
|
|
269
|
+
assert.match(kvmLLVM, /source_filename = "k-llvm:__main__"/);
|
|
270
|
+
assert.match(kvmLLVM, /define %k_result @k_main/);
|
|
271
|
+
assert.match(kvmLLVM, /store ptr %product_fields\d+, ptr %ptr_slot\d+/);
|
|
272
|
+
|
|
259
273
|
console.log("OK");
|
|
@@ -6,6 +6,22 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
|
|
7
7
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
8
|
const node = process.execPath;
|
|
9
|
+
|
|
10
|
+
function printHelp() {
|
|
11
|
+
console.log(`Usage: node backends/wasm/scripts/run-tests.mjs [options]
|
|
12
|
+
|
|
13
|
+
Runs WebAssembly backend test suite and integration tests.
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
-h, --help
|
|
17
|
+
Show this help message and exit.`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
21
|
+
printHelp();
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
const tests = [
|
|
10
26
|
["tests/test-wasm.mjs", node, ["tests/test-wasm.mjs"]],
|
|
11
27
|
["tests/integration.sh", path.join(root, "tests/integration.sh"), []]
|
package/browser/shims/fs.mjs
CHANGED
|
@@ -25,7 +25,10 @@ function cleanPath(p) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function setVfsFile(path, content) {
|
|
28
|
-
|
|
28
|
+
let cleaned = cleanPath(path);
|
|
29
|
+
if (cleaned.endsWith(".mjs") && !cleaned.startsWith("codecs/")) {
|
|
30
|
+
cleaned = `codecs/${cleaned}`;
|
|
31
|
+
}
|
|
29
32
|
vfs.set(cleaned, content);
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -53,11 +56,13 @@ const CURATED_VFS_FILES = [
|
|
|
53
56
|
"core.k",
|
|
54
57
|
"arithmetics.k",
|
|
55
58
|
"ieee.k",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
59
|
+
"poly.k",
|
|
60
|
+
"karatsuba-mult.k",
|
|
61
|
+
"codecs/json.mjs",
|
|
62
|
+
"codecs/utf8.mjs",
|
|
63
|
+
"codecs/int.mjs",
|
|
64
|
+
"codecs/unit.mjs",
|
|
65
|
+
"codecs/ieee.mjs"
|
|
61
66
|
];
|
|
62
67
|
|
|
63
68
|
export function getAllVfsFiles() {
|
|
@@ -69,7 +74,7 @@ export function getAllVfsFiles() {
|
|
|
69
74
|
}
|
|
70
75
|
for (const key of vfs.keys()) {
|
|
71
76
|
if (key.endsWith("runtime.wat") || key.startsWith("backends/")) continue;
|
|
72
|
-
if (key.startsWith("Examples/")
|
|
77
|
+
if (key.startsWith("Examples/")) continue;
|
|
73
78
|
result.add(key);
|
|
74
79
|
}
|
|
75
80
|
return Array.from(result);
|