@fraczak/k 6.10.6 → 7.0.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/CHANGELOG.md +41 -0
- package/CLAUDE.md +1 -1
- package/DOCS/BIG_PICTURE.md +156 -172
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
- package/DOCS/CODEC_ARCHITECTURE.md +2 -2
- package/DOCS/DICTIONARY.md +243 -250
- package/DOCS/DIVERGENCE_DETECTION.md +0 -1
- package/DOCS/FILE_FORMATS.md +5 -5
- package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
- package/DOCS/PATTERNS.md +17 -17
- package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
- package/DOCS/REPL.md +9 -19
- package/DOCS/TYPE_DERIVATION.md +2 -8
- package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
- package/DOCS/book/01-introduction.md +8 -11
- package/DOCS/book/02-syntax-and-values.md +19 -20
- package/DOCS/book/03-types-as-finite-automata.md +42 -43
- package/DOCS/book/04-partial-functions-and-composition.md +2 -3
- package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
- package/DOCS/book/06-values-in-memory.md +10 -10
- package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
- package/DOCS/book/09-compiler-architecture.md +11 -11
- package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
- package/DOCS/book/14-canonical-serialization.md +2 -2
- package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
- package/DOCS/book.md +5 -5
- package/Examples/arithmetics.k +49 -153
- package/Examples/bnat.k +13 -13
- package/Examples/byte.k +2 -50
- package/Examples/ieee.k +408 -423
- package/Examples/karatsuba-mult.k +30 -34
- package/Examples/nat.k +5 -6
- package/README.md +54 -49
- package/TODO.md +13 -18
- package/browser/vfs-data.mjs +11 -11
- package/codecs/BINARY_FORMAT.md +4 -4
- package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
- package/codecs/README.md +6 -6
- package/codecs/ieee.mjs +15 -11
- package/codecs/int.mjs +9 -5
- package/codecs/string-codec.mjs +46 -47
- package/core.k +123 -95
- package/object.mjs +0 -7
- package/package.json +5 -2
- package/parser.jison +2 -41
- package/parser.mjs +55 -95
- package/pretty.mjs +11 -4
- package/repl.mjs +8 -63
- package/scripts/build-repl-html.mjs +8 -38
- package/tests/code-derivation/blowup.mjs +2 -4
- package/tests/code-derivation/bnat.mjs +2 -3
- package/tests/code-derivation/dot.mjs +5 -11
- package/tests/code-derivation/nat.mjs +2 -2
- package/tests/code-derivation/not-not.mjs +6 -6
- package/tests/code-derivation/pattern-envelope.mjs +4 -6
- package/tests/code-derivation/product.mjs +3 -6
- package/tests/code-derivation/rlz.mjs +4 -5
- package/tests/test-codecs.mjs +1 -1
- package/tests/test-fingerprint.mjs +36 -41
- package/tests/test-hash-normalization.mjs +4 -6
- package/tests/test-ieee-arithmetic.mjs +6 -7
- package/tests/test-k-object.mjs +11 -15
- package/tests/test-kir.mjs +0 -1
- package/tests/test-kvm-polymorphic.mjs +1 -2
- package/tests/test-kvm.mjs +8 -11
- package/tests/test-repl-html.mjs +5 -2
- package/tests/test-repl.mjs +38 -53
- package/tests/test.mjs +2 -3
package/Examples/bnat.k
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
-- Standard binary encoding of natural numbers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
bnat = ?< {} _, bnat 0, bnat 1 > = bnat;
|
|
4
4
|
|
|
5
5
|
_ = {}|_;
|
|
6
6
|
_1 = |1;
|
|
@@ -23,7 +23,7 @@ remove_leading_zeros = < /0 remove_leading_zeros, () >;
|
|
|
23
23
|
reverse = {() x, _ result} _reverse;
|
|
24
24
|
|
|
25
25
|
_reverse =
|
|
26
|
-
|
|
26
|
+
?{ <X 0, X 1, {} _>=X x, ... }
|
|
27
27
|
<
|
|
28
28
|
{.x/_ if, .result then} .then,
|
|
29
29
|
{.x/0 x, .result _0 result} _reverse,
|
|
@@ -33,11 +33,11 @@ _reverse =
|
|
|
33
33
|
|
|
34
34
|
append_0 = reverse _0 reverse; -- i.e., shift_left, double, or times2
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
c0 = {} |0 ;
|
|
38
38
|
c1 = {} |1 ;
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
|
|
42
42
|
plus =
|
|
43
43
|
-- ${bnat x, bnat y} -- $ pair
|
|
@@ -52,7 +52,7 @@ plus =
|
|
|
52
52
|
|
|
53
53
|
_plus =
|
|
54
54
|
-- least significant bit first addition with carry
|
|
55
|
-
|
|
55
|
+
?{ <X 0, X 1, {} _>=X x, ... }
|
|
56
56
|
<
|
|
57
57
|
{.x/_ if1, .y/_ if2, <.c/0 bnat_0, bnat_1> then} .then,
|
|
58
58
|
{.x/_ if1, .c/0 if2, .y then} .then,
|
|
@@ -88,7 +88,7 @@ minus =
|
|
|
88
88
|
|
|
89
89
|
_minus =
|
|
90
90
|
-- least significat bit first substraction with carry
|
|
91
|
-
|
|
91
|
+
?{ <X 0, X 1, {} _>=X x, <Y 0, Y 1, {} _>=Y y, ... }
|
|
92
92
|
<
|
|
93
93
|
{.x x, .y/_ y, .c/0 if} .x,
|
|
94
94
|
{.x/1 x, .y/_ y, .c/1 if} .x _0,
|
|
@@ -116,7 +116,7 @@ times =
|
|
|
116
116
|
;
|
|
117
117
|
|
|
118
118
|
_times =
|
|
119
|
-
|
|
119
|
+
?{ <Y 0, Y 1, {} _>=Y y, ... }
|
|
120
120
|
<
|
|
121
121
|
{ .y/_ if, .result then } .then,
|
|
122
122
|
{ .result _0 result, ._x _x, .y/0 y } _times,
|
|
@@ -149,7 +149,7 @@ align =
|
|
|
149
149
|
;
|
|
150
150
|
|
|
151
151
|
_align =
|
|
152
|
-
|
|
152
|
+
?{ <X 0, X 1, {} _>=X _x, <Y 0, Y 1, {} _>=Y _y, ... }
|
|
153
153
|
<
|
|
154
154
|
{._x/_ if1, ._y/_ if2, {.x x, .y y} then} .then,
|
|
155
155
|
{._x </0, /_ _> _x, ._y </0, /_ _> _y, .x _0 x, .y _0 y} _align,
|
|
@@ -159,14 +159,14 @@ _align =
|
|
|
159
159
|
>
|
|
160
160
|
;
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
lt = {} |lt;
|
|
164
164
|
eq = {} |eq;
|
|
165
165
|
gt = {} |gt;
|
|
166
166
|
|
|
167
167
|
compare = align _compare;
|
|
168
168
|
_compare =
|
|
169
|
-
|
|
169
|
+
?{ <X 0, X 1, {} _>=X x, <Y 0, Y 1, {} _>=Y y, ... }
|
|
170
170
|
<
|
|
171
171
|
{.x/_ if1, .y/_ if2 } eq,
|
|
172
172
|
{.x/0 x, .y/0 y} _compare,
|
|
@@ -174,7 +174,7 @@ _compare =
|
|
|
174
174
|
.x/0 lt,
|
|
175
175
|
gt
|
|
176
176
|
>
|
|
177
|
-
|
|
177
|
+
|
|
178
178
|
;
|
|
179
179
|
|
|
180
180
|
zero? = remove_leading_zeros /_ bnat_0;
|
|
@@ -214,7 +214,7 @@ append_n_times_0 =
|
|
|
214
214
|
;
|
|
215
215
|
|
|
216
216
|
div =
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
{.x x, .y step, bnat_0 res} _div
|
|
219
219
|
;
|
|
220
220
|
|
|
@@ -241,7 +241,7 @@ _div =
|
|
|
241
241
|
;
|
|
242
242
|
|
|
243
243
|
lcm =
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
{times x, gcd y}
|
|
246
246
|
div .div
|
|
247
247
|
;
|
package/Examples/byte.k
CHANGED
|
@@ -1,56 +1,8 @@
|
|
|
1
|
-
$ bit = < {} 0, {} 1 >;
|
|
2
|
-
|
|
3
|
-
$ byte = {
|
|
4
|
-
bit 0, bit 1, bit 2, bit 3,
|
|
5
|
-
bit 4, bit 5, bit 6, bit 7
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
$ bytes = < {} nil, {byte car, bytes cdr} cons >;
|
|
9
|
-
|
|
10
|
-
$ ascii = { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
|
|
11
|
-
|
|
12
|
-
$ u0080_07FF = { bit 10, bit 9, bit 8, bit 7, bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
|
|
13
|
-
|
|
14
|
-
$ bmp_hi_common = <
|
|
15
|
-
{ bit 2, bit 1, bit 0 } h08_0F,
|
|
16
|
-
{ bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h10_7F,
|
|
17
|
-
{ bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h80_CF,
|
|
18
|
-
{ bit 2, bit 1, bit 0 } hD0_D7,
|
|
19
|
-
{} hF9,
|
|
20
|
-
{ bit 0 } hFA_FB,
|
|
21
|
-
{ bit 0 } hFC_FD,
|
|
22
|
-
{ bit 0 } hFE_FF
|
|
23
|
-
>;
|
|
24
|
-
|
|
25
|
-
$ bmp_hi_private_use = <
|
|
26
|
-
{ bit 3, bit 2, bit 1, bit 0 } hE0_EF,
|
|
27
|
-
{ bit 2, bit 1, bit 0 } hF0_F7,
|
|
28
|
-
{} hF8
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
$ plane_02_10 = <
|
|
32
|
-
{ bit 0 } p02_03,
|
|
33
|
-
{ bit 1, bit 0 } p04_07,
|
|
34
|
-
{ bit 2, bit 1, bit 0 } p08_0F,
|
|
35
|
-
{} p10
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
$ unicode = <
|
|
39
|
-
ascii ascii,
|
|
40
|
-
u0080_07FF plane0,
|
|
41
|
-
{ bmp_hi_common hi, byte lo } bmp_common,
|
|
42
|
-
{ bmp_hi_private_use hi, byte lo } bmp_private_use,
|
|
43
|
-
{ byte mid, byte lo } supplementary_plane1,
|
|
44
|
-
{ plane_02_10 plane, byte mid, byte lo } supplementary_planes2_16
|
|
45
|
-
>;
|
|
46
|
-
|
|
47
|
-
$ string = < {} nil, { unicode car, string cdr } cons >;
|
|
48
|
-
|
|
49
1
|
0 = {}|0;
|
|
50
2
|
1 = {}|1;
|
|
51
3
|
|
|
52
4
|
_ = {1 6, 0 5, 1 4, 1 3, 1 2, 1 1, 1 0};
|
|
53
|
-
map =
|
|
5
|
+
map = <
|
|
54
6
|
/ascii <
|
|
55
7
|
{.6/1 6, .5/1 5, .4/1 4, .3/1 3, .2/1 2, .1/1 1, .0/1 0 } _,
|
|
56
8
|
{{.6/0 6, .5/1 5} if, () then} .then,
|
|
@@ -59,7 +11,7 @@ map = $ unicode <
|
|
|
59
11
|
_
|
|
60
12
|
> | ascii;
|
|
61
13
|
|
|
62
|
-
filter =
|
|
14
|
+
filter = ?< {} nil, { (...) car, S cdr } cons > = S <
|
|
63
15
|
/cons {.car map car, .cdr filter cdr} | cons,
|
|
64
16
|
()
|
|
65
17
|
>;
|