@fraczak/k 6.2.4 → 6.3.2
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/Value.mjs +50 -40
- package/a.klib +1 -1
- package/a.kvm +142676 -0
- package/a.wasm +0 -0
- package/backend-api.mjs +1 -1
- package/benchmark-results.html +532 -0
- package/benchmark-results.json +480 -0
- package/codecs/example-pipeline.mjs +7 -7
- package/codecs/ieee.mjs +8 -8
- package/codecs/int.mjs +6 -6
- package/codecs/json-codec.mjs +15 -15
- package/codecs/runtime/codec.mjs +13 -13
- package/codecs/runtime/prefix-codec.mjs +18 -18
- package/codecs/runtime/show-value.mjs +3 -3
- package/codecs/runtime/test-codec.mjs +7 -7
- package/codecs/runtime/typeFromValue.mjs +4 -4
- package/codecs/runtime/unicode-string.mjs +30 -30
- package/codecs/unit.mjs +4 -4
- package/index.mjs +2 -2
- package/kvm.mjs +86 -19
- package/package.json +4 -1
- package/repl.mjs +2 -2
- package/run.mjs +9 -9
- package/scripts/benchmark.mjs +393 -0
- package/scripts/git-hooks/pre-commit +10 -0
- package/scripts/render-benchmark.mjs +343 -0
- package/scripts/run-tests.mjs +2 -0
- package/tests/code-derivation/codec-witness-pattern.mjs +4 -4
- package/tests/code-derivation/pattern-envelope.mjs +12 -12
- package/tests/integration.sh +7 -0
- package/tests/test-arithmetics.mjs +95 -0
- package/tests/test-deep-wire-value.mjs +4 -4
- package/tests/test-ieee-arithmetic.mjs +3 -3
- package/tests/test-k-object.mjs +10 -10
- package/tests/test-kvm.mjs +1 -1
- package/tests/test-repl.mjs +4 -4
- package/tests/test-structural-values.mjs +27 -0
- package/valueIO.mjs +1 -1
- package/valueParser.jison +9 -9
- package/valueParser.mjs +7 -7
package/tests/test-kvm.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import assert from "node:assert";
|
|
|
2
2
|
import k from "../index.mjs";
|
|
3
3
|
import { lowerToKVM, executeKVM } from "../kvm.mjs";
|
|
4
4
|
import codes from "../codes.mjs";
|
|
5
|
-
import { fromObject
|
|
5
|
+
import { fromObject } from "../Value.mjs";
|
|
6
6
|
import run, { run_converged } from "../run.mjs";
|
|
7
7
|
|
|
8
8
|
function runKVM(script, data, options = {}) {
|
package/tests/test-repl.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
lineTerminatesSnippet
|
|
19
19
|
} from "../repl.mjs";
|
|
20
20
|
import { decodeObject, objectToFunction } from "../object.mjs";
|
|
21
|
-
import {
|
|
21
|
+
import { Value } from "../Value.mjs";
|
|
22
22
|
|
|
23
23
|
const state = createState();
|
|
24
24
|
|
|
@@ -123,7 +123,7 @@ assert(completions.includes(`:load --no-alias ${libPath}`));
|
|
|
123
123
|
output = await evaluateInput(`:ko ${koPath} succ`, state);
|
|
124
124
|
assert.equal(output[0], `saved ${koPath} (succ)`);
|
|
125
125
|
const objectFn = objectToFunction(decodeObject(fs.readFileSync(koPath)));
|
|
126
|
-
const objectResult = objectFn(
|
|
126
|
+
const objectResult = objectFn(Value.product({}, [["closed-product", []]]));
|
|
127
127
|
assert.equal(objectResult.toJSON(), "succ");
|
|
128
128
|
|
|
129
129
|
fs.writeFileSync(sourcePath, "$ nat = <{} zero, nat succ>;\nsucc = $nat |succ $nat;\ntwice = succ succ;\n");
|
|
@@ -145,7 +145,7 @@ assert.match(output[0], /^\$ bool = @/);
|
|
|
145
145
|
const boolHash = codecState.typeAliases.bool;
|
|
146
146
|
const valueModuleUrl = pathToFileURL(path.resolve("Value.mjs")).href;
|
|
147
147
|
fs.writeFileSync(codecPath, `
|
|
148
|
-
import {
|
|
148
|
+
import { Value } from ${JSON.stringify(valueModuleUrl)};
|
|
149
149
|
|
|
150
150
|
export const name = "yn";
|
|
151
151
|
export const codes = [${JSON.stringify(boolHash)}];
|
|
@@ -153,7 +153,7 @@ export const codes = [${JSON.stringify(boolHash)}];
|
|
|
153
153
|
export function parse(text) {
|
|
154
154
|
const tag = text.trim();
|
|
155
155
|
if (tag !== "true" && tag !== "false") throw new Error("expected true or false");
|
|
156
|
-
return
|
|
156
|
+
return Value.variant(tag, Value.product({}));
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
export function print(value) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
|
|
3
|
+
import { Value, isProduct, isVariant, isValue } from "../Value.mjs";
|
|
4
|
+
import { INT_PATTERN, print as printInt } from "../codecs/int.mjs";
|
|
5
|
+
import { print as printUnit } from "../codecs/unit.mjs";
|
|
6
|
+
import { valueToK } from "../codecs/runtime/show-value.mjs";
|
|
7
|
+
import { decodeWire, encodeToWire } from "../codecs/runtime/prefix-codec.mjs";
|
|
8
|
+
|
|
9
|
+
const foreign = await import("../Value.mjs?structural-values-regression");
|
|
10
|
+
|
|
11
|
+
assert.notEqual(foreign.Value, Value);
|
|
12
|
+
|
|
13
|
+
const foreignUnit = foreign.Value.product({});
|
|
14
|
+
const foreignTwo = foreign.Value.variant("+",
|
|
15
|
+
foreign.Value.variant("1",
|
|
16
|
+
foreign.Value.variant("0",
|
|
17
|
+
foreign.Value.variant("_", foreignUnit))));
|
|
18
|
+
|
|
19
|
+
assert.equal(isProduct(foreignUnit), true);
|
|
20
|
+
assert.equal(isVariant(foreignTwo), true);
|
|
21
|
+
assert.equal(isValue(foreignTwo), true);
|
|
22
|
+
assert.equal(printUnit(foreignUnit), "{}");
|
|
23
|
+
assert.equal(printInt(foreignTwo), "2");
|
|
24
|
+
assert.equal(valueToK(foreignTwo), "{}|_|0|1|+");
|
|
25
|
+
|
|
26
|
+
const decoded = decodeWire(encodeToWire(foreignTwo, INT_PATTERN)).value;
|
|
27
|
+
assert.equal(printInt(decoded), "2");
|
package/valueIO.mjs
CHANGED
package/valueParser.jison
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
%{
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Value } from "./Value.mjs";
|
|
4
4
|
|
|
5
5
|
//--------------------------
|
|
6
6
|
|
|
@@ -87,19 +87,19 @@ input_with_eof
|
|
|
87
87
|
exp
|
|
88
88
|
: lc labelled rc { $$ = {value: $2.value, start: $1.start, end: $3.end}; }
|
|
89
89
|
| lb exps rb { $$ = {value: $2.value, start: $1.start, end: $3.end}; }
|
|
90
|
-
| str { $$ = {value:
|
|
91
|
-
| name { $$ = {value:
|
|
90
|
+
| str { $$ = {value: Value.variant($1.value, Value.product({})), start: $1.start, end: $1.end}; }
|
|
91
|
+
| name { $$ = {value: Value.variant($1.value, Value.product({})), start: $1.start, end: $1.end}; }
|
|
92
92
|
;
|
|
93
93
|
|
|
94
94
|
exps
|
|
95
|
-
: /* empty */ { $$ = {value:
|
|
95
|
+
: /* empty */ { $$ = {value: Value.product({})}; }
|
|
96
96
|
| non_empty_exps {
|
|
97
97
|
if ($1.list.length === 1) {
|
|
98
|
-
$$ = {value:
|
|
98
|
+
$$ = {value: Value.variant('0', $1.list[0].value)};
|
|
99
99
|
} else {
|
|
100
100
|
const product = {};
|
|
101
101
|
$1.list.forEach( (e, i) => product[i] = e.value );
|
|
102
|
-
$$ = {value:
|
|
102
|
+
$$ = {value: Value.product(product)};
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
;
|
|
@@ -111,10 +111,10 @@ non_empty_exps
|
|
|
111
111
|
;
|
|
112
112
|
|
|
113
113
|
labelled
|
|
114
|
-
: /* empty */ { $$ = {value:
|
|
114
|
+
: /* empty */ { $$ = {value: Value.product({})}; }
|
|
115
115
|
| non_empty_labelled {
|
|
116
116
|
if ($1.list.length === 1) {
|
|
117
|
-
$$ = {value:
|
|
117
|
+
$$ = {value: Value.variant($1.list[0].label, $1.list[0].value)};
|
|
118
118
|
} else {
|
|
119
119
|
const product = {};
|
|
120
120
|
for (const {label, value} of $1.list) {
|
|
@@ -122,7 +122,7 @@ labelled
|
|
|
122
122
|
anError(@0,`Duplicate label '${label}'.`);
|
|
123
123
|
product[label] = value;
|
|
124
124
|
}
|
|
125
|
-
$$ = {value:
|
|
125
|
+
$$ = {value: Value.product(product)};
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
;
|
package/valueParser.mjs
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
import {
|
|
78
|
+
import { Value } from "./Value.mjs";
|
|
79
79
|
|
|
80
80
|
//--------------------------
|
|
81
81
|
|
|
@@ -144,19 +144,19 @@ case 10: case 11:
|
|
|
144
144
|
this.$ = {value: $$[$0-1].value, start: $$[$0-2].start, end: $$[$0].end};
|
|
145
145
|
break;
|
|
146
146
|
case 12: case 13:
|
|
147
|
-
this.$ = {value:
|
|
147
|
+
this.$ = {value: Value.variant($$[$0].value, Value.product({})), start: $$[$0].start, end: $$[$0].end};
|
|
148
148
|
break;
|
|
149
149
|
case 14: case 18:
|
|
150
|
-
this.$ = {value:
|
|
150
|
+
this.$ = {value: Value.product({})};
|
|
151
151
|
break;
|
|
152
152
|
case 15:
|
|
153
153
|
|
|
154
154
|
if ($$[$0].list.length === 1) {
|
|
155
|
-
this.$ = {value:
|
|
155
|
+
this.$ = {value: Value.variant('0', $$[$0].list[0].value)};
|
|
156
156
|
} else {
|
|
157
157
|
const product = {};
|
|
158
158
|
$$[$0].list.forEach( (e, i) => product[i] = e.value );
|
|
159
|
-
this.$ = {value:
|
|
159
|
+
this.$ = {value: Value.product(product)};
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
break;
|
|
@@ -169,7 +169,7 @@ break;
|
|
|
169
169
|
case 19:
|
|
170
170
|
|
|
171
171
|
if ($$[$0].list.length === 1) {
|
|
172
|
-
this.$ = {value:
|
|
172
|
+
this.$ = {value: Value.variant($$[$0].list[0].label, $$[$0].list[0].value)};
|
|
173
173
|
} else {
|
|
174
174
|
const product = {};
|
|
175
175
|
for (const {label, value} of $$[$0].list) {
|
|
@@ -177,7 +177,7 @@ case 19:
|
|
|
177
177
|
anError(this._$,`Duplicate label '${label}'.`);
|
|
178
178
|
product[label] = value;
|
|
179
179
|
}
|
|
180
|
-
this.$ = {value:
|
|
180
|
+
this.$ = {value: Value.product(product)};
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
break;
|