@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
package/Examples/arithmetics.k
CHANGED
|
@@ -15,10 +15,10 @@ cdr = list? /cons .cdr;
|
|
|
15
15
|
$ bits = < {} _, bits 0, bits 1 >;
|
|
16
16
|
|
|
17
17
|
0b = {} | _;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
-- |1 = | 1;
|
|
19
|
+
-- |0 = | 0;
|
|
20
20
|
|
|
21
|
-
0 = 0b
|
|
21
|
+
0 = 0b |0;
|
|
22
22
|
succ = {inv x, 0b y} _inc;
|
|
23
23
|
1 = 0 succ;
|
|
24
24
|
2 = 1 succ;
|
|
@@ -39,12 +39,12 @@ empty? = {empty /yes if, () then} .then;
|
|
|
39
39
|
concat = ${bits x, bits y} {.x inv x, .y y} concat_;
|
|
40
40
|
concat_ = ${bits x, bits y}
|
|
41
41
|
<
|
|
42
|
-
{.x /0 x, .y
|
|
43
|
-
{.x /1 x, .y
|
|
42
|
+
{.x /0 x, .y |0 y} concat_,
|
|
43
|
+
{.x /1 x, .y |1 y} concat_,
|
|
44
44
|
.y
|
|
45
45
|
>;
|
|
46
46
|
inv = {()x, 0b r} _inv;
|
|
47
|
-
_inv = ${bits x, bits r} < {.x /0 x, .r
|
|
47
|
+
_inv = ${bits x, bits r} < {.x /0 x, .r |0 r} _inv, {.x /1 x, .r |1 r} _inv, .r >;
|
|
48
48
|
|
|
49
49
|
inOrder = ${bits x, bits y} {.x inv x, .y inv y, yes inOrder} inOrder_;
|
|
50
50
|
inOrder_ = ${bits x, bits y, yes_no inOrder}
|
|
@@ -70,8 +70,8 @@ _toBitList = <
|
|
|
70
70
|
fromBitList =
|
|
71
71
|
<
|
|
72
72
|
cdr <
|
|
73
|
-
{car /0 if, cdr fromBitList
|
|
74
|
-
{car /1 if, cdr fromBitList
|
|
73
|
+
{car /0 if, cdr fromBitList |0 then} .then,
|
|
74
|
+
{car /1 if, cdr fromBitList |1 then} .then
|
|
75
75
|
>,
|
|
76
76
|
0b
|
|
77
77
|
> $bits;
|
|
@@ -93,26 +93,26 @@ zero_int? = $int {/'+' /0 empty? if, () then} .then;
|
|
|
93
93
|
minus_one? = $int {/'-' /1 empty? if, () then} .then;
|
|
94
94
|
|
|
95
95
|
inc = $int <
|
|
96
|
-
/'+' {inv x, 0b y} _inc |'+',
|
|
96
|
+
/'+' {inv x, 0b y} _inc nat |'+',
|
|
97
97
|
minus_one? 0 int,
|
|
98
|
-
/'-' {inv x, 0b y} _dec |'-'
|
|
99
|
-
|
|
98
|
+
/'-' {inv x, 0b y} _dec nat |'-'
|
|
99
|
+
> $int;
|
|
100
100
|
|
|
101
101
|
_inc = ${bits x, bits y} <
|
|
102
|
-
{.x /0 x, .y
|
|
103
|
-
{.x /1 x, .y
|
|
104
|
-
.y
|
|
102
|
+
{.x /0 x, .y |1 y} concat_,
|
|
103
|
+
{.x /1 x, .y |0 y} _inc,
|
|
104
|
+
.y |1
|
|
105
105
|
>;
|
|
106
106
|
|
|
107
107
|
dec = $int <
|
|
108
108
|
zero_int? 1 |'-',
|
|
109
|
-
/'+' {inv x, 0b y} _dec |'+',
|
|
110
|
-
/'-' {inv x, 0b y} _inc |'-'
|
|
109
|
+
/'+' {inv x, 0b y} _dec nat |'+',
|
|
110
|
+
/'-' {inv x, 0b y} _inc nat |'-'
|
|
111
111
|
> $int;
|
|
112
112
|
|
|
113
113
|
_dec = ?{X x, X y, ...} <
|
|
114
|
-
{.x /1 x, .y
|
|
115
|
-
{.x /0 x, .y
|
|
114
|
+
{.x /1 x, .y |0 y} concat_,
|
|
115
|
+
{.x /0 x, .y |1 y} _dec
|
|
116
116
|
> ?X;
|
|
117
117
|
|
|
118
118
|
$carry = <{} 0, {} 1>;
|
|
@@ -139,27 +139,30 @@ swap_sign = <
|
|
|
139
139
|
minus = ${int x, int y}
|
|
140
140
|
{.x x, .y swap_sign y} plus;
|
|
141
141
|
|
|
142
|
-
_plus =
|
|
142
|
+
_plus = {.x x, .y y, .c c, 0b r} _plus_;
|
|
143
|
+
|
|
144
|
+
_plus_ =
|
|
143
145
|
-- least significant bit first addition with carry
|
|
144
|
-
${bits x, bits y, carry c}
|
|
146
|
+
${bits x, bits y, carry c, bits r}
|
|
145
147
|
<
|
|
146
|
-
{.x empty? if, .y empty? and,
|
|
147
|
-
{.x empty? if, .
|
|
148
|
+
{.x empty? if, .y empty? and, .c/0 c, .r inv then} .then,
|
|
149
|
+
{.x empty? if, .y empty? and, {.r x, 1 r} _inv then} .then,
|
|
150
|
+
{.x empty? if, .c/0 and, {.r x, .y r} _inv then} .then,
|
|
148
151
|
|
|
149
|
-
{.x y, .y empty? x, .c c}
|
|
152
|
+
{.x y, .y empty? x, .c c, .r r} _plus_,
|
|
150
153
|
{<.c/0 0, 1> x,
|
|
151
|
-
.y y, .x empty? c0 c}
|
|
154
|
+
.y y, .x empty? c0 c, .r r} _plus_,
|
|
152
155
|
|
|
153
|
-
{.x /0 x, .y /0 y, .c/0 c0 c}
|
|
154
|
-
{.x /0 x, .y /0 y, .c/1 c0 c}
|
|
156
|
+
{.x /0 x, .y /0 y, .c/0 c0 c, .r |0 r} _plus_,
|
|
157
|
+
{.x /0 x, .y /0 y, .c/1 c0 c, .r |1 r} _plus_,
|
|
155
158
|
|
|
156
|
-
{.x /0 x, .y /1 y, .c/0 c0 c}
|
|
157
|
-
{.x /0 x, .y /1 y, .c/1 c1 c}
|
|
158
|
-
{.x /1 x, .y /0 y, .c/0 c0 c}
|
|
159
|
-
{.x /1 x, .y /0 y, .c/1 c1 c}
|
|
159
|
+
{.x /0 x, .y /1 y, .c/0 c0 c, .r |1 r} _plus_,
|
|
160
|
+
{.x /0 x, .y /1 y, .c/1 c1 c, .r |0 r} _plus_,
|
|
161
|
+
{.x /1 x, .y /0 y, .c/0 c0 c, .r |1 r} _plus_,
|
|
162
|
+
{.x /1 x, .y /0 y, .c/1 c1 c, .r |0 r} _plus_,
|
|
160
163
|
|
|
161
|
-
{.x /1 x, .y /1 y, .c/0 c1 c}
|
|
162
|
-
{.x /1 x, .y /1 y, .c/1 c1 c}
|
|
164
|
+
{.x /1 x, .y /1 y, .c/0 c1 c, .r |0 r} _plus_,
|
|
165
|
+
{.x /1 x, .y /1 y, .c/1 c1 c, .r |1 r} _plus_
|
|
163
166
|
>
|
|
164
167
|
;
|
|
165
168
|
|
|
@@ -168,16 +171,16 @@ _minus =
|
|
|
168
171
|
${bits x, bits y, carry c}
|
|
169
172
|
<
|
|
170
173
|
{.x then, .y empty? if, .c/0 and} .then,
|
|
171
|
-
{.x/1 then, .y empty? if, .c/1 and} .then
|
|
172
|
-
{.x/0 x, .y empty? y, .c/1 c1 c} _minus
|
|
173
|
-
{.x/0 x, .y/0 y, .c/0 c0 c} _minus
|
|
174
|
-
{.x/0 x, .y/0 y, .c/1 c1 c} _minus
|
|
175
|
-
{.x/0 x, .y/1 y, .c/0 c1 c} _minus
|
|
176
|
-
{.x/0 x, .y/1 y, .c/1 c1 c} _minus
|
|
177
|
-
{.x/1 x, .y/0 y, .c/0 c0 c} _minus
|
|
178
|
-
{.x/1 x, .y/0 y, .c/1 c0 c} _minus
|
|
179
|
-
{.x/1 x, .y/1 y, .c/0 c0 c} _minus
|
|
180
|
-
{.x/1 x, .y/1 y, .c/1 c1 c} _minus
|
|
174
|
+
{.x/1 then, .y empty? if, .c/1 and} .then |0,
|
|
175
|
+
{.x/0 x, .y empty? y, .c/1 c1 c} _minus |1,
|
|
176
|
+
{.x/0 x, .y/0 y, .c/0 c0 c} _minus |0,
|
|
177
|
+
{.x/0 x, .y/0 y, .c/1 c1 c} _minus |1,
|
|
178
|
+
{.x/0 x, .y/1 y, .c/0 c1 c} _minus |1,
|
|
179
|
+
{.x/0 x, .y/1 y, .c/1 c1 c} _minus |0,
|
|
180
|
+
{.x/1 x, .y/0 y, .c/0 c0 c} _minus |1,
|
|
181
|
+
{.x/1 x, .y/0 y, .c/1 c0 c} _minus |0,
|
|
182
|
+
{.x/1 x, .y/1 y, .c/0 c0 c} _minus |0,
|
|
183
|
+
{.x/1 x, .y/1 y, .c/1 c1 c} _minus |1
|
|
181
184
|
>
|
|
182
185
|
;
|
|
183
186
|
|
|
@@ -210,12 +213,12 @@ _times =
|
|
|
210
213
|
<
|
|
211
214
|
{ .y empty? if, .result then } .then,
|
|
212
215
|
{
|
|
213
|
-
.result
|
|
216
|
+
.result |0 result,
|
|
214
217
|
._x _x,
|
|
215
218
|
.y /0 y
|
|
216
219
|
} _times,
|
|
217
220
|
{
|
|
218
|
-
{._x x, .result
|
|
221
|
+
{._x x, .result |0 y, c0 c } _plus result,
|
|
219
222
|
._x _x,
|
|
220
223
|
.y /1 y
|
|
221
224
|
} _times
|
|
@@ -225,7 +228,7 @@ _times =
|
|
|
225
228
|
|
|
226
229
|
mod =
|
|
227
230
|
${bits x, bits y}
|
|
228
|
-
_log!
|
|
231
|
+
-- _log!
|
|
229
232
|
<
|
|
230
233
|
-- if y > x then (x mod y) = x
|
|
231
234
|
{.y x, .x y} GT .y,
|
|
@@ -234,7 +237,7 @@ mod =
|
|
|
234
237
|
{
|
|
235
238
|
{
|
|
236
239
|
{.x int x, .y int y} minus /"+" x,
|
|
237
|
-
.y inv
|
|
240
|
+
.y inv |0 inv y
|
|
238
241
|
} mod x,
|
|
239
242
|
.y y
|
|
240
243
|
} mod
|
|
@@ -278,7 +281,7 @@ x_times_2_to_k =
|
|
|
278
281
|
|
|
279
282
|
_x_times_2_to_the_power_of_k = <
|
|
280
283
|
{.k zero_int? if, ._x then} .then,
|
|
281
|
-
{._x
|
|
284
|
+
{._x |0 _x, .k dec k} _x_times_2_to_the_power_of_k
|
|
282
285
|
>
|
|
283
286
|
;
|
|
284
287
|
|
|
@@ -442,7 +445,7 @@ ratToString =
|
|
|
442
445
|
|
|
443
446
|
_rat! = $rat {
|
|
444
447
|
() carryOn,
|
|
445
|
-
ratToString
|
|
448
|
+
ratToString drop
|
|
446
449
|
} .carryOn;
|
|
447
450
|
|
|
448
451
|
|
package/Examples/bnat.k
CHANGED
package/Examples/buda.k
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// we will use arithmetics.k
|
|
2
|
+
|
|
3
|
+
nths = ?{$int n, LIST list}
|
|
4
|
+
<
|
|
5
|
+
{.n pos? dec n, .list cdr list } nths,
|
|
6
|
+
{.n zero_int? if, .list list? car then} .then
|
|
7
|
+
>;
|
|
8
|
+
|
|
9
|
+
reverse = ? LIST list?
|
|
10
|
+
{nil ? LIST reversed, () list } _reverse;
|
|
11
|
+
|
|
12
|
+
_reverse = ?{ LIST reversed, LIST list}
|
|
13
|
+
<
|
|
14
|
+
{{.list car car, .reversed cdr} cons reversed, .list cdr list } _reverse,
|
|
15
|
+
.reversed
|
|
16
|
+
>
|
|
17
|
+
;
|
|
18
|
+
|
|
19
|
+
split = ? LIST
|
|
20
|
+
{ nil ? LIST odd, nil ? LIST even, reverse list } _split
|
|
21
|
+
;
|
|
22
|
+
|
|
23
|
+
_split = ? { LIST odd, LIST even, LIST list }
|
|
24
|
+
<
|
|
25
|
+
{
|
|
26
|
+
{.list car car, .odd cdr} cons odd,
|
|
27
|
+
.even even,
|
|
28
|
+
.list cdr list
|
|
29
|
+
} split_,
|
|
30
|
+
|
|
31
|
+
{.odd odd, .even even}
|
|
32
|
+
>
|
|
33
|
+
;
|
|
34
|
+
|
|
35
|
+
split_ = ? { LIST odd, LIST even, LIST list }
|
|
36
|
+
<
|
|
37
|
+
{
|
|
38
|
+
.odd odd,
|
|
39
|
+
{.list car car, .even cdr} cons even,
|
|
40
|
+
.list cdr list
|
|
41
|
+
} _split,
|
|
42
|
+
{.odd odd, .even even}
|
|
43
|
+
>
|
|
44
|
+
;
|