@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.
Files changed (155) hide show
  1. package/DOCS/CODECS.md +258 -0
  2. package/DOCS/DICTIONARY.md +1172 -0
  3. package/DOCS/KIR_SPECIALIZATION_DESIGN.md +51 -46
  4. package/DOCS/KIR_V1.md +221 -0
  5. package/DOCS/KVM_EXECUTION_MODEL.md +56 -19
  6. package/DOCS/OBJECT_FILE_AND_PATTERN.md +2 -1
  7. package/DOCS/PROFILING_AND_TRACING.md +196 -0
  8. package/DOCS/REPL.md +61 -4
  9. package/DOCS/WEB_REPL_REQUIREMENTS.md +135 -0
  10. package/DOCS/dependency-graph.md +144 -0
  11. package/Examples/arithmetics.k +51 -48
  12. package/Examples/bnat.k +1 -1
  13. package/Examples/buda.k +44 -0
  14. package/Examples/ieee.k +300 -8671
  15. package/Examples/poly.k +67 -0
  16. package/README.md +68 -19
  17. package/augmentation.mjs +9 -7
  18. package/backend-api.mjs +11 -2
  19. package/backends/arm64/README.md +104 -0
  20. package/backends/arm64/bin/k-arm64-compile.mjs +101 -0
  21. package/backends/arm64/bin/k-arm64-run.mjs +58 -0
  22. package/backends/arm64/bin/k-arm64.mjs +88 -0
  23. package/backends/arm64/scripts/run-tests.mjs +41 -0
  24. package/backends/arm64/src/arm64.mjs +229 -0
  25. package/backends/arm64/src/cli.mjs +155 -0
  26. package/backends/arm64/src/kvm2arm64.mjs +906 -0
  27. package/backends/arm64/src/runtime.c +728 -0
  28. package/backends/arm64/tests/integration.sh +112 -0
  29. package/backends/arm64/tests/test-arm64.mjs +240 -0
  30. package/backends/llvm/README.md +135 -0
  31. package/backends/llvm/bin/k-llvm-build.mjs +71 -0
  32. package/backends/llvm/bin/k-llvm-compile.mjs +68 -0
  33. package/backends/llvm/bin/k-llvm-jit.mjs +160 -0
  34. package/backends/llvm/bin/k-llvm-run.mjs +90 -0
  35. package/backends/llvm/runtime/krt.c +1508 -0
  36. package/backends/llvm/runtime/krt.h +109 -0
  37. package/backends/llvm/scripts/conformance.mjs +76 -0
  38. package/backends/llvm/scripts/run-tests.mjs +28 -0
  39. package/backends/llvm/src/executable.mjs +562 -0
  40. package/backends/llvm/src/kvm2llvm.mjs +998 -0
  41. package/backends/llvm/src/llvm.mjs +1092 -0
  42. package/backends/llvm/tests/composition-driver.c +22 -0
  43. package/backends/llvm/tests/identity-driver.c +27 -0
  44. package/backends/llvm/tests/integration.sh +153 -0
  45. package/backends/llvm/tests/perf-support.mjs +735 -0
  46. package/backends/llvm/tests/product-driver.c +23 -0
  47. package/backends/llvm/tests/projection-driver.c +19 -0
  48. package/backends/llvm/tests/relation-driver.c +29 -0
  49. package/backends/llvm/tests/test-llvm.mjs +240 -0
  50. package/backends/llvm/tests/union-driver.c +31 -0
  51. package/backends/llvm/tests/variant-driver.c +19 -0
  52. package/backends/llvm/tests/variant-projection-driver.c +21 -0
  53. package/backends/wasm/DOCS/USE-WEB-ASSEMBLY.md +233 -0
  54. package/backends/wasm/README.md +97 -0
  55. package/backends/wasm/TECHNICAL-DEBT.md +60 -0
  56. package/backends/wasm/bin/k-wasm-compile.mjs +50 -0
  57. package/backends/wasm/bin/k-wasm-run.mjs +140 -0
  58. package/backends/wasm/bin/k-wasm.mjs +49 -0
  59. package/backends/wasm/demo_ieee.mjs +319 -0
  60. package/backends/wasm/runtime.wat +102 -0
  61. package/backends/wasm/scripts/run-tests.mjs +41 -0
  62. package/backends/wasm/src/cli.mjs +133 -0
  63. package/backends/wasm/src/kvm2wasm.mjs +661 -0
  64. package/backends/wasm/src/wasm.mjs +1010 -0
  65. package/backends/wasm/tests/integration.sh +182 -0
  66. package/backends/wasm/tests/perf-support.mjs +336 -0
  67. package/backends/wasm/tests/test-wasm.mjs +617 -0
  68. package/browser/repl-browser.mjs +1584 -0
  69. package/browser/shims/assert.mjs +19 -0
  70. package/browser/shims/buffer.mjs +224 -0
  71. package/browser/shims/crypto.mjs +103 -0
  72. package/browser/shims/fs.mjs +159 -0
  73. package/browser/shims/os.mjs +17 -0
  74. package/browser/shims/path.mjs +54 -0
  75. package/browser/shims/process.mjs +44 -0
  76. package/browser/shims/readline.mjs +11 -0
  77. package/browser/shims/url.mjs +12 -0
  78. package/browser/vfs-data.mjs +19 -0
  79. package/codecs/README.md +3 -0
  80. package/codecs/runtime/show-value.mjs +2 -2
  81. package/conformance/helper-reuse/case.json +8 -0
  82. package/conformance/helper-reuse/expected.kv +1 -0
  83. package/conformance/helper-reuse/input.kv +1 -0
  84. package/conformance/helper-reuse/program.k +2 -0
  85. package/conformance/identity/case.json +8 -0
  86. package/conformance/identity/expected.kv +1 -0
  87. package/conformance/identity/input.kv +1 -0
  88. package/conformance/identity/program.k +1 -0
  89. package/conformance/product-projection/case.json +8 -0
  90. package/conformance/product-projection/expected.kv +1 -0
  91. package/conformance/product-projection/input.kv +1 -0
  92. package/conformance/product-projection/program.k +1 -0
  93. package/conformance/run.mjs +149 -0
  94. package/conformance/variant-construction/case.json +8 -0
  95. package/conformance/variant-construction/expected.kv +1 -0
  96. package/conformance/variant-construction/input.kv +1 -0
  97. package/conformance/variant-construction/program.k +1 -0
  98. package/harness/adapters/arm64.mjs +105 -0
  99. package/harness/adapters/kvm.mjs +144 -0
  100. package/harness/adapters/llvm.mjs +118 -0
  101. package/harness/adapters/native.mjs +77 -0
  102. package/harness/adapters/wasm.mjs +169 -0
  103. package/harness/backend.mjs +95 -0
  104. package/harness/cli.mjs +130 -0
  105. package/harness/format.mjs +95 -0
  106. package/harness/index.mjs +25 -0
  107. package/harness/persistent.mjs +121 -0
  108. package/harness/registry.mjs +44 -0
  109. package/harness/suite.mjs +257 -0
  110. package/harness/suites/poly.mjs +156 -0
  111. package/harness/trace.mjs +50 -0
  112. package/harness/util.mjs +92 -0
  113. package/intrinsics.mjs +41 -0
  114. package/kir.mjs +399 -0
  115. package/kvm.mjs +585 -81
  116. package/objects/README.md +37 -3
  117. package/objects/compile.mjs +15 -22
  118. package/objects/inspect.mjs +96 -0
  119. package/objects/validate.mjs +415 -0
  120. package/package.json +51 -19
  121. package/repl-codecs.mjs +105 -6
  122. package/repl.mjs +335 -49
  123. package/run.mjs +2 -7
  124. package/scripts/benchmark.mjs +406 -22
  125. package/scripts/build-repl-html.mjs +1784 -0
  126. package/scripts/perf-ieee.mjs +586 -0
  127. package/scripts/perf-int.mjs +531 -0
  128. package/scripts/perf-poly.mjs +945 -0
  129. package/scripts/render-benchmark.mjs +12 -8
  130. package/scripts/run-tests.mjs +6 -0
  131. package/tests/integration.sh +19 -2
  132. package/tests/test-arithmetics.mjs +54 -0
  133. package/tests/test-ieee-arithmetic.mjs +4 -0
  134. package/tests/test-kir.mjs +85 -0
  135. package/tests/test-kvm-polymorphic.mjs +278 -0
  136. package/tests/test-kvm.mjs +25 -6
  137. package/tests/test-poly.mjs +129 -0
  138. package/tests/test-repl-html.mjs +303 -0
  139. package/tests/test-repl.mjs +144 -1
  140. package/tests/test-validate-object.mjs +40 -0
  141. package/a.klib +0 -1
  142. package/a.kvm +0 -142676
  143. package/a.wasm +0 -0
  144. package/benchmark-results.html +0 -532
  145. package/benchmark-results.json +0 -480
  146. package/k-vscode/.vscode/launch.json +0 -14
  147. package/k-vscode/README.md +0 -75
  148. package/k-vscode/extension.js +0 -273
  149. package/k-vscode/language-configuration.json +0 -42
  150. package/k-vscode/package.json +0 -79
  151. package/k-vscode/snippets/k.json +0 -92
  152. package/k-vscode/syntaxes/k.tmLanguage.json +0 -599
  153. package/k-vscode/test/background-ranges.test.js +0 -50
  154. package/k-vscode/themes/k-contrast-color-theme.json +0 -104
  155. package/scripts/git-hooks/pre-commit +0 -10
@@ -15,10 +15,10 @@ cdr = list? /cons .cdr;
15
15
  $ bits = < {} _, bits 0, bits 1 >;
16
16
 
17
17
  0b = {} | _;
18
- 1_ = | 1;
19
- 0_ = | 0;
18
+ -- |1 = | 1;
19
+ -- |0 = | 0;
20
20
 
21
- 0 = 0b 0_;
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 0_ y} concat_,
43
- {.x /1 x, .y 1_ y} concat_,
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 0_ r} _inv, {.x /1 x, .r 1_ r} _inv, .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 0_ then} .then,
74
- {car /1 if, cdr fromBitList 1_ then} .then
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 1_ y} concat_,
103
- {.x /1 x, .y 0_ y} _inc,
104
- .y 1_
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 0_ y} concat_,
115
- {.x /0 x, .y 1_ y} _dec
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, <.c/0 0, 1> then} .then,
147
- {.x empty? if, .c/0 and, .y then} .then,
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} _plus,
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} _plus,
154
+ .y y, .x empty? c0 c, .r r} _plus_,
152
155
 
153
- {.x /0 x, .y /0 y, .c/0 c0 c} _plus 0_,
154
- {.x /0 x, .y /0 y, .c/1 c0 c} _plus 1_,
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} _plus 1_,
157
- {.x /0 x, .y /1 y, .c/1 c1 c} _plus 0_,
158
- {.x /1 x, .y /0 y, .c/0 c0 c} _plus 1_,
159
- {.x /1 x, .y /0 y, .c/1 c1 c} _plus 0_,
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} _plus 0_,
162
- {.x /1 x, .y /1 y, .c/1 c1 c} _plus 1_
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 0_,
172
- {.x/0 x, .y empty? y, .c/1 c1 c} _minus 1_,
173
- {.x/0 x, .y/0 y, .c/0 c0 c} _minus 0_,
174
- {.x/0 x, .y/0 y, .c/1 c1 c} _minus 1_,
175
- {.x/0 x, .y/1 y, .c/0 c1 c} _minus 1_,
176
- {.x/0 x, .y/1 y, .c/1 c1 c} _minus 0_,
177
- {.x/1 x, .y/0 y, .c/0 c0 c} _minus 1_,
178
- {.x/1 x, .y/0 y, .c/1 c0 c} _minus 0_,
179
- {.x/1 x, .y/1 y, .c/0 c0 c} _minus 0_,
180
- {.x/1 x, .y/1 y, .c/1 c1 c} _minus 1_
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 0_ result,
216
+ .result |0 result,
214
217
  ._x _x,
215
218
  .y /0 y
216
219
  } _times,
217
220
  {
218
- {._x x, .result 0_ y, c0 c } _plus 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 0_ inv y
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 0_ _x, .k dec k} _x_times_2_to_the_power_of_k
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 _log! drop
448
+ ratToString drop
446
449
  } .carryOn;
447
450
 
448
451
 
package/Examples/bnat.k CHANGED
@@ -288,4 +288,4 @@ _sqrt =
288
288
 
289
289
  --------------------
290
290
 
291
- _log! lcm
291
+ lcm
@@ -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
+ ;