@fraczak/k 8.7.0 → 8.7.1
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 +23 -8
- package/DOCS/FILE_FORMATS.md +31 -57
- package/DOCS/GETTING_STARTED.md +5 -7
- package/DOCS/PATTERNS.md +3 -10
- package/DOCS/REPL.md +2 -3
- package/README.md +4 -4
- package/backends/llvm/src/cli.mjs +6 -9
- package/backends/llvm/tests/integration.sh +3 -1
- package/backends/wasm/src/wasm.mjs +2 -6
- package/backends/wasm/tests/integration.sh +22 -7
- package/canonical-pattern.mjs +0 -3
- package/compiler.mjs +26 -0
- package/index.mjs +67 -2
- package/k.mjs +4 -12
- package/kir.mjs +3 -1
- package/kvm.mjs +4 -8
- package/lib/arithmetics.k +1 -2
- package/lib/bits.k +6 -0
- package/lib/djson.k +4 -3
- package/lib/list.k +1 -1
- package/named-patterns.mjs +0 -12
- package/object.mjs +3 -20
- package/objects/README.md +4 -5
- package/objects/compile.mjs +5 -10
- package/package.json +1 -1
- package/repl.mjs +4 -7
- package/scripts/run-tests.mjs +1 -0
- package/scripts/test-package.mjs +6 -1
- package/tests/helpers/cli.mjs +8 -0
- package/tests/integration.sh +22 -7
- package/tests/test-djson-methods.mjs +8 -3
- package/tests/test-ieee-text.mjs +6 -2
- package/tests/test-k-object.mjs +6 -3
- package/tests/test-kvm-polymorphic.mjs +4 -0
- package/tests/test-lib.mjs +8 -6
- package/tests/test-library-isolation.mjs +381 -0
- package/tests/test-named-patterns.mjs +13 -4
- package/tests/test-parse-json.mjs +15 -5
package/named-patterns.mjs
CHANGED
|
@@ -286,11 +286,6 @@ export function expandPatternsInRels(rels, patterns = {}, options = {}) {
|
|
|
286
286
|
allPatterns[name] = pat;
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
for (const [name, hash] of Object.entries(lib.patternAlias || {})) {
|
|
290
|
-
if (libPatterns[name] && !(hash in allPatterns)) {
|
|
291
|
-
allPatterns[hash] = libPatterns[name];
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
289
|
}
|
|
295
290
|
}
|
|
296
291
|
|
|
@@ -322,13 +317,6 @@ export function validatePatternDefinitions(
|
|
|
322
317
|
allPatterns[name] = pat;
|
|
323
318
|
}
|
|
324
319
|
}
|
|
325
|
-
for (const [name, hash] of Object.entries(
|
|
326
|
-
lib.patternAlias || {}
|
|
327
|
-
)) {
|
|
328
|
-
if (libPatterns[name] && !(hash in allPatterns)) {
|
|
329
|
-
allPatterns[hash] = libPatterns[name];
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
320
|
}
|
|
333
321
|
}
|
|
334
322
|
|
package/object.mjs
CHANGED
|
@@ -478,16 +478,7 @@ function collectReachable(mainName, rels, allCodes) {
|
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
function compileObject(script, options = {}) {
|
|
481
|
-
|
|
482
|
-
if (typeof script === "string" && options.libraries?.length > 0) {
|
|
483
|
-
const headerUses = parseHeaderUses(script);
|
|
484
|
-
const allSpecs = [...headerUses, ...(options.useSpecs || options.use || [])];
|
|
485
|
-
if (allSpecs.length > 0) {
|
|
486
|
-
const preamble = buildUsePreamble(allSpecs, options.libraries);
|
|
487
|
-
scriptToAnnotate = preamble + script;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
const annotated = annotate(scriptToAnnotate, options);
|
|
481
|
+
const annotated = annotate(script, options);
|
|
491
482
|
const allCodes = stripDebugFieldsFromCodes(codes.dump());
|
|
492
483
|
const serialized = serializeAnnotated(annotated);
|
|
493
484
|
const meta = mergeMetaEntries(
|
|
@@ -544,16 +535,7 @@ function rewriteRefsToCanonical(exp, relAlias) {
|
|
|
544
535
|
}
|
|
545
536
|
|
|
546
537
|
function compileLibrary(script, options = {}) {
|
|
547
|
-
|
|
548
|
-
if (typeof script === "string" && options.libraries?.length > 0) {
|
|
549
|
-
const headerUses = parseHeaderUses(script);
|
|
550
|
-
const allSpecs = [...headerUses, ...(options.useSpecs || options.use || [])];
|
|
551
|
-
if (allSpecs.length > 0) {
|
|
552
|
-
const preamble = buildUsePreamble(allSpecs, options.libraries);
|
|
553
|
-
scriptToAnnotate = preamble + script;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
const annotated = annotateLibrary(scriptToAnnotate, options);
|
|
538
|
+
const annotated = annotateLibrary(script, options);
|
|
557
539
|
const allCodes = stripDebugFieldsFromCodes(codes.dump());
|
|
558
540
|
const serialized = serializeAnnotated(annotated);
|
|
559
541
|
const meta = mergeMetaEntries(
|
|
@@ -583,6 +565,7 @@ function compileLibrary(script, options = {}) {
|
|
|
583
565
|
}
|
|
584
566
|
for (const [name, rel] of Object.entries(serialized.rels)) {
|
|
585
567
|
if (name === "__main__") continue;
|
|
568
|
+
if (rel._library) continue;
|
|
586
569
|
const canonicalName = libRelAlias[name] || name;
|
|
587
570
|
const { varRefs, ...relWithoutVarRefs } = rel;
|
|
588
571
|
libRels[canonicalName] = {
|
package/objects/README.md
CHANGED
|
@@ -22,11 +22,10 @@ node objects/validate.mjs /tmp/k-ok.ko
|
|
|
22
22
|
output filename or `--format klib`.
|
|
23
23
|
|
|
24
24
|
When compiling source files, required library dependencies and friendly aliases
|
|
25
|
-
can be
|
|
26
|
-
`# --lib <dependency> --use <specs>`
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expressions.
|
|
25
|
+
can be documented directly in the source file header via
|
|
26
|
+
`# --lib <dependency> --use <specs>` comments. When `--lib` is provided on the
|
|
27
|
+
command line, all library relations and patterns are available in memory during
|
|
28
|
+
compilation. CLI `--use` flags allow creating in-memory aliases when needed.
|
|
30
29
|
|
|
31
30
|
The [file-format reference](../DOCS/FILE_FORMATS.md) is the source for container
|
|
32
31
|
fields, executable/library distinctions, header directives, aliases, and
|
package/objects/compile.mjs
CHANGED
|
@@ -8,9 +8,7 @@ import {
|
|
|
8
8
|
compileLibrary,
|
|
9
9
|
compileLibraryBuffer,
|
|
10
10
|
decodeObject,
|
|
11
|
-
loadLibrary
|
|
12
|
-
buildUsePreamble,
|
|
13
|
-
parseHeaderUses
|
|
11
|
+
loadLibrary
|
|
14
12
|
} from "../object.mjs";
|
|
15
13
|
import { objectToKVMArtifact } from "../kvm.mjs";
|
|
16
14
|
|
|
@@ -212,17 +210,14 @@ try {
|
|
|
212
210
|
: input.kind === "inline"
|
|
213
211
|
? input.source
|
|
214
212
|
: fs.readFileSync(input.path, "utf8");
|
|
215
|
-
const
|
|
216
|
-
const preamble = buildUsePreamble(allSpecs, libraries);
|
|
217
|
-
const source = preamble + rawSource;
|
|
218
|
-
const opts = { source: input.sourceName, libraries };
|
|
213
|
+
const opts = { source: input.sourceName, libraries, useSpecs };
|
|
219
214
|
|
|
220
215
|
if (outputFormat === "ko") {
|
|
221
|
-
output = compileObjectBuffer(
|
|
216
|
+
output = compileObjectBuffer(rawSource, opts);
|
|
222
217
|
} else if (outputFormat === "klib") {
|
|
223
|
-
output = compileLibraryBuffer(
|
|
218
|
+
output = compileLibraryBuffer(rawSource, opts);
|
|
224
219
|
} else if (outputFormat === "kvm") {
|
|
225
|
-
const object = decodeObject(compileObjectBuffer(
|
|
220
|
+
const object = decodeObject(compileObjectBuffer(rawSource, opts));
|
|
226
221
|
output = objectToKVM(object);
|
|
227
222
|
}
|
|
228
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "8.7.
|
|
3
|
+
"version": "8.7.1",
|
|
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"
|
package/repl.mjs
CHANGED
|
@@ -40,9 +40,7 @@ import {
|
|
|
40
40
|
encodeLibrary,
|
|
41
41
|
hydrateObject,
|
|
42
42
|
loadLibrary,
|
|
43
|
-
prettyRelation
|
|
44
|
-
buildUsePreamble,
|
|
45
|
-
parseHeaderUses
|
|
43
|
+
prettyRelation
|
|
46
44
|
} from "./object.mjs";
|
|
47
45
|
import {
|
|
48
46
|
propertyListToFilter,
|
|
@@ -1394,10 +1392,9 @@ function loadSourceOrKlib(state, targetPath, options = {}) {
|
|
|
1394
1392
|
} else {
|
|
1395
1393
|
restoreCodes(state);
|
|
1396
1394
|
const source = fs.readFileSync(loadPath, "utf8");
|
|
1397
|
-
const
|
|
1398
|
-
const
|
|
1399
|
-
const
|
|
1400
|
-
const fullSource = [preamble, usePreamble, source].filter(Boolean).join("\n");
|
|
1395
|
+
const usedNames = new Set(definedNamesInSource(source));
|
|
1396
|
+
const preamble = aliasPreamble(state, usedNames);
|
|
1397
|
+
const fullSource = [preamble, source].filter(Boolean).join("\n");
|
|
1401
1398
|
const compileOptions = {
|
|
1402
1399
|
source: targetPath,
|
|
1403
1400
|
libraries: [stateLibrary(state)],
|
package/scripts/run-tests.mjs
CHANGED
|
@@ -48,6 +48,7 @@ const tests = [
|
|
|
48
48
|
["tests/test-djson-methods.mjs"]
|
|
49
49
|
],
|
|
50
50
|
["tests/test-lib.mjs", node, ["tests/test-lib.mjs"]],
|
|
51
|
+
["tests/test-library-isolation.mjs", node, ["tests/test-library-isolation.mjs"]],
|
|
51
52
|
["tests/test-parse-json.mjs", node, ["tests/test-parse-json.mjs"]],
|
|
52
53
|
["tests/test-ieee-text.mjs", node, ["tests/test-ieee-text.mjs"]],
|
|
53
54
|
["tests/test-deep-wire-value.mjs", node, ["tests/test-deep-wire-value.mjs"]],
|
package/scripts/test-package.mjs
CHANGED
|
@@ -50,7 +50,12 @@ try {
|
|
|
50
50
|
const arithKlib = path.join(scratch, "arithmetics.klib");
|
|
51
51
|
run("k-compile", [path.join(packageDir, "lib/bit.k"), bitKlib]);
|
|
52
52
|
run("k-compile", ["--lib", bitKlib, path.join(packageDir, "lib/bits.k"), bitsKlib]);
|
|
53
|
-
run("k-compile", [
|
|
53
|
+
run("k-compile", [
|
|
54
|
+
"--lib", bitsKlib,
|
|
55
|
+
"--use", "trim inv_loop inv cmp inc_bits dec_bits plus_bits minus_bits mul_bits",
|
|
56
|
+
path.join(packageDir, "lib/arithmetics.k"),
|
|
57
|
+
arithKlib
|
|
58
|
+
]);
|
|
54
59
|
const incremented = run("k", ["--lib", arithKlib,
|
|
55
60
|
"--use", "inc", "inc"], integer);
|
|
56
61
|
assert.equal(run("k-int", ["--print"], incremented).toString().trim(), "43");
|
package/tests/helpers/cli.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { spawnSync } from "node:child_process";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { parse, print } from "../../codecs/int.mjs";
|
|
8
8
|
import { encodeToWire, decodeWire } from "../../codecs/runtime/prefix-codec.mjs";
|
|
9
|
+
import { parseHeaderUses } from "../../canonical-pattern.mjs";
|
|
9
10
|
|
|
10
11
|
const root = fileURLToPath(new URL("../../", import.meta.url));
|
|
11
12
|
|
|
@@ -32,6 +33,13 @@ export function withCompiledLibrary(source, test) {
|
|
|
32
33
|
const nextLibrary = path.join(dir, `library-${i}.klib`);
|
|
33
34
|
const args = ["objects/compile.mjs"];
|
|
34
35
|
if (library) args.push("--lib", library);
|
|
36
|
+
const filePath = path.isAbsolute(sources[i]) ? sources[i] : path.join(root, sources[i]);
|
|
37
|
+
if (fs.existsSync(filePath)) {
|
|
38
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
39
|
+
for (const u of parseHeaderUses(raw)) {
|
|
40
|
+
args.push("--use", u.use);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
args.push(sources[i], nextLibrary);
|
|
36
44
|
succeeds(node(args), `compile ${sources[i]}`);
|
|
37
45
|
library = nextLibrary;
|
package/tests/integration.sh
CHANGED
|
@@ -81,13 +81,28 @@ if ./kvm.mjs -k Examples/nat.k > "$TMP_DIR/dash-k-kvm.out" 2> "$TMP_DIR/dash-k-k
|
|
|
81
81
|
fi
|
|
82
82
|
grep -q -- '-k is no longer supported' "$TMP_DIR/dash-k-kvm.err"
|
|
83
83
|
echo
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
compile_step() {
|
|
85
|
+
local prev="$1"
|
|
86
|
+
local src="$2"
|
|
87
|
+
local out="$3"
|
|
88
|
+
local uses=()
|
|
89
|
+
while IFS= read -r line; do
|
|
90
|
+
[ -n "$line" ] && uses+=(--use "$line")
|
|
91
|
+
done < <(node -e 'import("./canonical-pattern.mjs").then(m => { for (const u of m.parseHeaderUses(fs.readFileSync(process.argv[1],"utf8"))) console.log(u.use); })' "$src" 2>/dev/null || true)
|
|
92
|
+
if [ -n "$prev" ]; then
|
|
93
|
+
./objects/compile.mjs --lib "$prev" "${uses[@]}" "$src" "$out"
|
|
94
|
+
else
|
|
95
|
+
./objects/compile.mjs "${uses[@]}" "$src" "$out"
|
|
96
|
+
fi
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
compile_step "" lib/bit.k "$TMP_DIR/bit.klib"
|
|
100
|
+
compile_step "$TMP_DIR/bit.klib" lib/bits.k "$TMP_DIR/bits.klib"
|
|
101
|
+
compile_step "$TMP_DIR/bits.klib" lib/list.k "$TMP_DIR/list.klib"
|
|
102
|
+
compile_step "$TMP_DIR/list.klib" lib/btrie.k "$TMP_DIR/btrie.klib"
|
|
103
|
+
compile_step "$TMP_DIR/btrie.klib" lib/string.k "$TMP_DIR/string.klib"
|
|
104
|
+
compile_step "$TMP_DIR/string.klib" lib/ieee.k "$TMP_DIR/ieee-types.klib"
|
|
105
|
+
compile_step "$TMP_DIR/ieee-types.klib" Examples/ieee-arithmetics.k "$TMP_DIR/ieee.klib"
|
|
91
106
|
MUL=`./objects/extract-aliases.mjs "$TMP_DIR/ieee.klib" | grep '^mul = @' | sed 's/^mul = \(@[^;]*\);.*$/\1/'`
|
|
92
107
|
DIV=`./objects/extract-aliases.mjs "$TMP_DIR/ieee.klib" | grep '^div = @' | sed 's/^div = \(@[^;]*\);.*$/\1/'`
|
|
93
108
|
ARG=0.12
|
|
@@ -3,6 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import k from "../index.mjs";
|
|
4
4
|
import { Value } from "../Value.mjs";
|
|
5
5
|
import { compileLibrary, loadLibrary } from "../object.mjs";
|
|
6
|
+
import { parseHeaderUses } from "../canonical-pattern.mjs";
|
|
6
7
|
import { fromJsonValue, toJsonValue } from "../codecs/djson.mjs";
|
|
7
8
|
import { textToStringValue, stringValueToText } from "../codecs/runtime/unicode-string.mjs";
|
|
8
9
|
import { parse as parseInt } from "../codecs/int.mjs";
|
|
@@ -17,12 +18,16 @@ for (const file of [
|
|
|
17
18
|
"lib/string.k",
|
|
18
19
|
"lib/ieee.k"
|
|
19
20
|
]) {
|
|
20
|
-
|
|
21
|
+
const fileSource = readFileSync(new URL(`../${file}`, import.meta.url), "utf8");
|
|
22
|
+
const uses = parseHeaderUses(fileSource).map((u) => u.use);
|
|
23
|
+
ieee = loadLibrary(compileLibrary(fileSource, {
|
|
21
24
|
source: file,
|
|
22
|
-
libraries: ieee ? [ieee] : []
|
|
25
|
+
libraries: ieee ? [ieee] : [],
|
|
26
|
+
use: uses
|
|
23
27
|
}));
|
|
24
28
|
}
|
|
25
|
-
const
|
|
29
|
+
const djsonUses = parseHeaderUses(source).map((u) => u.use);
|
|
30
|
+
const library = loadLibrary(compileLibrary(source, { libraries: [ieee], use: djsonUses }));
|
|
26
31
|
const run = (op, value) => k.compile(library.relAlias[op], { libraries: [library] })(value);
|
|
27
32
|
|
|
28
33
|
function method(op, json, { key, index, val } = {}) {
|
package/tests/test-ieee-text.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import k from "../index.mjs";
|
|
4
4
|
import { compileLibrary, loadLibrary } from "../object.mjs";
|
|
5
|
+
import { parseHeaderUses } from "../canonical-pattern.mjs";
|
|
5
6
|
import { compileWasmArtifact, instantiateWasmArtifact } from "../backends/wasm/src/wasm.mjs";
|
|
6
7
|
import { encodeNumberToValue, decodeValueToNumber } from "../codecs/ieee.mjs";
|
|
7
8
|
import { textToStringValue, stringValueToText } from "../codecs/runtime/unicode-string.mjs";
|
|
@@ -16,9 +17,12 @@ const ieeeSources = [
|
|
|
16
17
|
];
|
|
17
18
|
let ieee = null;
|
|
18
19
|
for (const file of ieeeSources) {
|
|
19
|
-
|
|
20
|
+
const fileSource = readFileSync(new URL(`../${file}`, import.meta.url), "utf8");
|
|
21
|
+
const uses = parseHeaderUses(fileSource).map((u) => u.use);
|
|
22
|
+
ieee = loadLibrary(compileLibrary(fileSource, {
|
|
20
23
|
source: file,
|
|
21
|
-
libraries: ieee ? [ieee] : []
|
|
24
|
+
libraries: ieee ? [ieee] : [],
|
|
25
|
+
use: uses
|
|
22
26
|
}));
|
|
23
27
|
}
|
|
24
28
|
assert.equal(ieee.relAlias.add, undefined, "Text conversion must not load IEEE arithmetic");
|
package/tests/test-k-object.mjs
CHANGED
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
objectToFunction,
|
|
15
15
|
runConvergedObject,
|
|
16
16
|
decompileObjectBuffer,
|
|
17
|
-
extractAliasesFromObject
|
|
17
|
+
extractAliasesFromObject,
|
|
18
|
+
parseHeaderUses
|
|
18
19
|
} from "../object.mjs";
|
|
19
20
|
|
|
20
21
|
const value = parseValue("{a:{b:x,c:{}}}");
|
|
@@ -109,9 +110,11 @@ const bitsLib = loadLibrary(decodeObject(compileLibraryBuffer(
|
|
|
109
110
|
fs.readFileSync("lib/bits.k", "utf8"),
|
|
110
111
|
{ source: "lib/bits.k", libraries: [bitLib] }
|
|
111
112
|
)));
|
|
113
|
+
const arithRaw = fs.readFileSync("lib/arithmetics.k", "utf8");
|
|
114
|
+
const arithUses = parseHeaderUses(arithRaw).map((u) => u.use);
|
|
112
115
|
const arithmeticsLibraryBuffer = compileLibraryBuffer(
|
|
113
|
-
|
|
114
|
-
{ source: "lib/arithmetics.k", libraries: [bitsLib] }
|
|
116
|
+
arithRaw,
|
|
117
|
+
{ source: "lib/arithmetics.k", libraries: [bitsLib], use: arithUses }
|
|
115
118
|
);
|
|
116
119
|
const arithmeticsDecompiledSource = decompileObjectBuffer(arithmeticsLibraryBuffer);
|
|
117
120
|
const arithmeticsRoundTripSource = decompileObjectBuffer(
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
executeKVM
|
|
7
7
|
} from "../kvm.mjs";
|
|
8
8
|
import { compileObjectBuffer, decodeObject } from "../object.mjs";
|
|
9
|
+
import { parseHeaderUses } from "../canonical-pattern.mjs";
|
|
9
10
|
import { objectToKIRP } from "../kir.mjs";
|
|
10
11
|
import { fromObject, Value } from "../Value.mjs";
|
|
11
12
|
import { lowerToWasm } from "../backends/wasm/src/kvm2wasm.mjs";
|
|
@@ -245,9 +246,12 @@ console.log("==> Starting Polymorphic kVM & Specialization Tests");
|
|
|
245
246
|
let prevLib = null;
|
|
246
247
|
for (const [idx, src] of ["lib/bit.k", "lib/bits.k", "lib/arithmetics.k"].entries()) {
|
|
247
248
|
const nextLib = path.join(tmpDir, `step-${idx}.klib`);
|
|
249
|
+
const fileSource = fs.readFileSync(path.join(__dirname, "..", src), "utf8");
|
|
250
|
+
const uses = parseHeaderUses(fileSource).flatMap((u) => ["--use", u.use]);
|
|
248
251
|
const stepRes = spawnSync(process.execPath, [
|
|
249
252
|
compileScript,
|
|
250
253
|
...(prevLib ? ["--lib", prevLib] : []),
|
|
254
|
+
...uses,
|
|
251
255
|
src,
|
|
252
256
|
nextLib
|
|
253
257
|
], {
|
package/tests/test-lib.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import k from "../index.mjs";
|
|
4
4
|
import { Value } from "../Value.mjs";
|
|
5
5
|
import { compileLibrary, loadLibrary } from "../object.mjs";
|
|
6
|
+
import { parseHeaderUses } from "../canonical-pattern.mjs";
|
|
6
7
|
import { fromJsonValue, toJsonValue } from "../codecs/djson.mjs";
|
|
7
8
|
import { textToStringValue, stringValueToText } from "../codecs/runtime/unicode-string.mjs";
|
|
8
9
|
import { encodeNumberToValue, decodeValueToNumber } from "../codecs/ieee.mjs";
|
|
@@ -11,26 +12,27 @@ import { parse as parseInt, parseIntStr, print as printInt } from "../codecs/int
|
|
|
11
12
|
const libFiles = [
|
|
12
13
|
"lib/bit.k",
|
|
13
14
|
"lib/bits.k",
|
|
14
|
-
"lib/arithmetics.k",
|
|
15
15
|
"lib/list.k",
|
|
16
16
|
"lib/btrie.k",
|
|
17
17
|
"lib/string.k",
|
|
18
18
|
"lib/ieee.k",
|
|
19
|
-
"lib/djson.k"
|
|
19
|
+
"lib/djson.k",
|
|
20
|
+
"lib/arithmetics.k"
|
|
20
21
|
];
|
|
21
22
|
|
|
22
23
|
const libs = [];
|
|
23
24
|
for (const file of libFiles) {
|
|
24
25
|
const source = readFileSync(new URL(`../${file}`, import.meta.url), "utf8");
|
|
26
|
+
const uses = parseHeaderUses(source).map((u) => u.use);
|
|
25
27
|
const compiled = loadLibrary(
|
|
26
|
-
compileLibrary(source, { source: file, libraries: libs })
|
|
28
|
+
compileLibrary(source, { source: file, libraries: libs, use: uses })
|
|
27
29
|
);
|
|
28
30
|
libs.push(compiled);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
33
|
+
const ieeeLib = libs[5];
|
|
34
|
+
const djsonLib = libs[6];
|
|
35
|
+
const arithLib = libs[7];
|
|
34
36
|
|
|
35
37
|
const runArith = (op, value) =>
|
|
36
38
|
k.compile(arithLib.relAlias[op], { libraries: [arithLib] })(value);
|