@fraczak/k 6.10.5 → 6.10.6

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/core.k CHANGED
@@ -4,15 +4,12 @@
4
4
  -- 1. $bits — the canonical binary number / bit-path type
5
5
  -- 2. $string — unicode strings (used for labels)
6
6
  -- 3. $pattern — the type of pattern graphs
7
- -- 4. Basic $bits arithmetic: succ, plus, times
8
7
 
9
8
  ---------------------------------------------------------------
10
9
  -- §1. Bits
11
10
  ---------------------------------------------------------------
12
11
 
13
12
  $ bit = < {} 0, {} 1 >;
14
- b0 = {}|0 $bit;
15
- b1 = {}|1 $bit;
16
13
 
17
14
  $ bits = < {} _, bits 0, bits 1 >;
18
15
 
@@ -21,85 +18,8 @@ _ = {}|_;
21
18
  0 = _ |0;
22
19
  1 = _ |1;
23
20
 
24
- inv = {() x, _ r} _inv;
25
- _inv = ${bits x, bits r} < {.x /0 x, .r |0 r} _inv, {.x /1 x, .r |1 r} _inv, .r >;
26
-
27
- concat = ${bits x, bits y} {.x inv x, .y y} concat_;
28
- concat_ = ${bits x, bits y}
29
- <
30
- {.x /0 x, .y |0 y} concat_,
31
- {.x /1 x, .y |1 y} concat_,
32
- .y
33
- >;
34
-
35
- ---------------------------------------------------------------
36
- -- §2. Bits arithmetic
37
- ---------------------------------------------------------------
38
-
39
- -- successor (increment by 1)
40
- succ = {inv x, _ y} _inc;
41
-
42
- _inc = ?{X x, X y}
43
- <
44
- {.x </0,/_|_> x, .y |1 y} concat_,
45
- {.x /1 x, .y |0 y} _inc
46
- > ?X;
47
-
48
- -- constants
49
- 2 = 1 succ;
50
- 3 = 2 succ;
51
- 4 = 3 succ;
52
- 5 = 4 succ;
53
- 6 = 5 succ;
54
- 7 = 6 succ;
55
- 8 = 7 succ;
56
- 9 = 8 succ;
57
- 10 = 9 succ;
58
-
59
- -- addition on $bits (unsigned, LSB-first with carry)
60
- plus = ${bits x, bits y} {.x inv x, .y inv y, b0 c} _plus;
61
- _plus = {.x x, .y y, .c c, _ r} _plus_;
62
- _plus_ = ${bits x, bits y, bit c, bits r}
63
- <
64
- {.x /_ if, .y /_ and, .c/0 c, .r then} .then,
65
- {.x /_ if, .y /_ and, .c/1 c, .r |1 then} .then,
66
- {.x /_ if, .c/0 and, {.y x, .r y} concat_ then} .then,
67
- {.y /_ if, .c/0 and, {.x x, .r y} concat_ then} .then,
68
- <
69
- {.x/_ _ x, .y /0 y, b0 c, .r |1 r},
70
- {.x/_ _ x, .y /1 y, b1 c, .r |0 r},
71
- {.y/_ _ y, .x /0 x, b0 c, .r |1 r},
72
- {.y/_ _ y, .x /1 x, b1 c, .r |0 r},
73
- {.x /0 x, .y /0 y, .c/0 b0 c, .r |0 r},
74
- {.x /0 x, .y /0 y, .c/1 b0 c, .r |1 r},
75
- {.x /0 x, .y /1 y, .c/0 b0 c, .r |1 r},
76
- {.x /0 x, .y /1 y, .c/1 b1 c, .r |0 r},
77
- {.x /1 x, .y /0 y, .c/0 b0 c, .r |1 r},
78
- {.x /1 x, .y /0 y, .c/1 b1 c, .r |0 r},
79
- {.x /1 x, .y /1 y, .c/0 b1 c, .r |0 r},
80
- {.x /1 x, .y /1 y, .c/1 b1 c, .r |1 r}
81
- > _plus_
82
- >;
83
-
84
- -- multiplication on $bits (unsigned, shift-and-add)
85
- times = ${bits x, bits y} {0 result, .x inv _x, .y y} _times;
86
- _times = ${bits result, bits _x, bits y}
87
- <
88
- { .y /_ if, .result then } .then,
89
- {
90
- .result |0 result,
91
- ._x _x,
92
- .y /0 y
93
- } _times,
94
- {
95
- {._x x, .result |0 y, b0 c} _plus result,
96
- ._x _x,
97
- .y /1 y
98
- } _times
99
- >;
100
-
101
21
  ---------------------------------------------------------------
102
- -- §3. Unicode and String
22
+ -- §2. Unicode and String
103
23
  ---------------------------------------------------------------
104
24
 
105
25
  -- 8-bit octet used as a building block for UTF-8 payload pieces.
@@ -115,8 +35,9 @@ $ ascii = { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
115
35
  -- Plane 0 is the Basic Multilingual Plane (BMP): U+0000..U+FFFF.
116
36
  $ u0080_07FF = { bit 10, bit 9, bit 8, bit 7, bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
117
37
 
118
- -- High-byte classes for common BMP ranges, excluding surrogate/private-use partitions.
119
- -- BMP (Basic Multilingual Plane) is Plane 0: the first 65,536 code points.
38
+ -- High-byte classes for common BMP ranges, excluding surrogate and
39
+ -- private-use partitions.
40
+ -- BMP (Basic Multilingual Plane) is Plane 0: first 65,536 code points.
120
41
  $ bmp_hi_common = <
121
42
  { bit 2, bit 1, bit 0 } h08_0F,
122
43
  { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h10_7F,
@@ -165,12 +86,12 @@ $ unicode = <
165
86
  $ string = < {} nil, { unicode car, string cdr } cons >;
166
87
 
167
88
  ---------------------------------------------------------------
168
- -- §4. Pattern
89
+ -- §3. Pattern
169
90
  ---------------------------------------------------------------
170
91
 
171
92
  -- Edge: a labeled edge in a pattern graph.
172
93
  -- 'label' is the field name or tag name.
173
- -- 'target' is the index (as $bits) of the target node in the pattern list.
94
+ -- 'target' is index (as $bits) of the target node in the pattern list.
174
95
 
175
96
  $ edge = { string label, bits target };
176
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "6.10.5",
3
+ "version": "6.10.6",
4
4
  "description": "k — a language for composing first-order partial functions over algebraic data types (products and tagged unions); includes runtime, type derivation, REPL, and codec toolchain",
5
5
  "main": "index.mjs",
6
6
  "exports": {
@@ -130,7 +130,7 @@ for (const filename of verifiedCodecs) {
130
130
  }]
131
131
  });
132
132
  const bundledContent = buildRes.outputFiles[0].text;
133
- vfsFiles[`codecs/${filename}`] = bundledContent;
133
+ vfsFiles[filename] = bundledContent;
134
134
  }
135
135
  }
136
136
 
@@ -1668,7 +1668,6 @@ const htmlContent = `<!DOCTYPE html>
1668
1668
  <option value="expr:{} | ok">{} | ok</option>
1669
1669
  <option value="expr:()">()</option>
1670
1670
  <option value="expr:$ bool = &lt; {} true, {} false &gt;; not = $ bool &lt; / true | false, {} | true &gt; $ bool; {} | true not">not (boolean relation with fallback)</option>
1671
- <option value="expr:{10 x, 5 y} plus">{10 x, 5 y} plus (bits)</option>
1672
1671
  <option value="expr:1 succ">1 succ</option>
1673
1672
  <option value="expr:{10 int x, 5 int y} plus">{10 int x, 5 int y} plus (int)</option>
1674
1673
  <option value="expr:{10 int x, 5 int y} karatsuba">{10 int x, 5 int y} karatsuba</option>
@@ -1681,21 +1680,21 @@ const htmlContent = `<!DOCTYPE html>
1681
1680
  <optgroup label="Codecs &amp; Format Adapters">
1682
1681
  <option value="expr::codecs">:codecs</option>
1683
1682
  <option value="expr::input">:input (interactive dialog)</option>
1684
- <option value="expr::codec load codecs/int.mjs">:codec load codecs/int.mjs</option>
1685
- <option value="expr::codec load codecs/utf8.mjs">:codec load codecs/utf8.mjs</option>
1686
- <option value="expr::codec load codecs/json.mjs">:codec load codecs/json.mjs</option>
1687
- <option value="expr::codec load codecs/ieee.mjs">:codec load codecs/ieee.mjs</option>
1688
- <option value="expr::codec load codecs/unit.mjs">:codec load codecs/unit.mjs</option>
1689
- <option value="expr::input codecs/json.mjs {&quot;a&quot;:12,&quot;b&quot;:&quot;hello&quot;}">:input codecs/json.mjs {"a":12,"b":"hello"}</option>
1690
- <option value="expr::input codecs/int.mjs [0,1,2]">:input codecs/int.mjs [0,1,2]</option>
1683
+ <option value="expr::codec load int.mjs">:codec load int.mjs</option>
1684
+ <option value="expr::codec load utf8.mjs">:codec load utf8.mjs</option>
1685
+ <option value="expr::codec load json.mjs">:codec load json.mjs</option>
1686
+ <option value="expr::codec load ieee.mjs">:codec load ieee.mjs</option>
1687
+ <option value="expr::codec load unit.mjs">:codec load unit.mjs</option>
1688
+ <option value="expr::input json.mjs {&quot;a&quot;:12,&quot;b&quot;:&quot;hello&quot;}">:input json.mjs {"a":12,"b":"hello"}</option>
1689
+ <option value="expr::input int.mjs [0,1,2]">:input int.mjs [0,1,2]</option>
1691
1690
  </optgroup>
1692
1691
  </select>
1693
1692
  <button id="btn-load-example" class="btn btn-primary">Load</button>
1694
1693
  </div>
1695
1694
 
1696
1695
  <!-- File Upload -->
1697
- <label class="btn btn-secondary btn-file" title="Upload local .k or .klib file into VFS">
1698
- <input type="file" id="file-upload" accept=".k,.klib,.wat,.ko" style="display:none;">
1696
+ <label class="btn btn-secondary btn-file" title="Upload local file into VFS">
1697
+ <input type="file" id="file-upload" accept=".k,.klib,.wat,.ko,.mjs,.js,.json" style="display:none;">
1699
1698
  <span>📁 Upload</span>
1700
1699
  </label>
1701
1700
 
@@ -139,15 +139,15 @@ if (chromiumBin) {
139
139
  const vfsList = await evaluateAsync(`window.kRepl.getAllVfsFiles().sort()`);
140
140
  const expectedFiles = [
141
141
  "arithmetics.k",
142
- "codecs/ieee.mjs",
143
- "codecs/int.mjs",
144
- "codecs/json.mjs",
145
- "codecs/unit.mjs",
146
- "codecs/utf8.mjs",
147
142
  "core.k",
148
143
  "ieee.k",
144
+ "ieee.mjs",
145
+ "int.mjs",
146
+ "json.mjs",
149
147
  "karatsuba-mult.k",
150
- "poly.k"
148
+ "poly.k",
149
+ "unit.mjs",
150
+ "utf8.mjs"
151
151
  ].sort();
152
152
  assert.deepStrictEqual(vfsList, expectedFiles, `getAllVfsFiles() must match curated files list, got: ${JSON.stringify(vfsList)}`);
153
153
 
@@ -635,7 +635,81 @@ if (chromiumBin) {
635
635
  assert.strictEqual(engineCheck.jsEngine, "js");
636
636
  assert.strictEqual(engineCheck.badgeJsText, "js-in-process");
637
637
  assert.strictEqual(engineCheck.wasmEngine, "wasm");
638
- assert.strictEqual(engineCheck.badgeWasmText, "wasm-in-process");
638
+ // 7. Test uploading a file (adds to VFS without auto-loading)
639
+ const uploadCheck = await evaluateAsync(`(async () => {
640
+ const codecCode = \`export default {
641
+ name: "custom.mjs",
642
+ target: "(...)",
643
+ format: "custom",
644
+ parse: (raw) => raw,
645
+ print: (v) => "CUSTOM_VAL"
646
+ };\`;
647
+ const file = new File(
648
+ [codecCode],
649
+ "custom.mjs",
650
+ { type: "text/javascript" }
651
+ );
652
+ await window.kRepl.handleFileUpload(file);
653
+
654
+ const vfsContent = window.kRepl.getVfsFile("custom.mjs");
655
+ const inVfsList = window.kRepl.getAllVfsFiles().includes("custom.mjs");
656
+
657
+ // Verify system message showed upload confirmation
658
+ const systemMessages = Array.from(
659
+ document.querySelectorAll(".system-msg")
660
+ ).map(el => el.textContent);
661
+ const hasUploadedMsg = systemMessages.some(
662
+ m => m.includes("Uploaded custom.mjs into VFS")
663
+ );
664
+
665
+ // Verify it was NOT auto-loaded (:codecs does not list it)
666
+ await window.kRepl.executeCommand(":codecs");
667
+ const linesBefore = Array.from(
668
+ document.querySelectorAll(".entry-line")
669
+ ).map(el => el.textContent);
670
+ const codecsBefore = linesBefore[linesBefore.length - 1];
671
+
672
+ // Explicitly load it to prove it can be loaded as a codec
673
+ await window.kRepl.executeCommand(":codec load custom.mjs");
674
+ const linesAfter = Array.from(
675
+ document.querySelectorAll(".entry-line")
676
+ ).map(el => el.textContent);
677
+ const codecsAfter = linesAfter[linesAfter.length - 1];
678
+
679
+ return {
680
+ hasVfsContent: typeof vfsContent === "string" &&
681
+ vfsContent.includes("custom.mjs"),
682
+ inVfsList,
683
+ hasUploadedMsg,
684
+ codecsBefore,
685
+ codecsAfter
686
+ };
687
+ })()`);
688
+ assert.strictEqual(
689
+ uploadCheck.hasVfsContent,
690
+ true,
691
+ "Uploaded file must be present in VFS"
692
+ );
693
+ assert.strictEqual(
694
+ uploadCheck.inVfsList,
695
+ true,
696
+ "Uploaded file must be in getAllVfsFiles()"
697
+ );
698
+ assert.strictEqual(
699
+ uploadCheck.hasUploadedMsg,
700
+ true,
701
+ "Upload confirmation message must be displayed"
702
+ );
703
+ assert.strictEqual(
704
+ uploadCheck.codecsBefore.includes("custom.mjs"),
705
+ false,
706
+ "Upload must NOT auto-load the file"
707
+ );
708
+ assert.strictEqual(
709
+ uploadCheck.codecsAfter.includes("custom.mjs"),
710
+ true,
711
+ "Explicit :codec load of uploaded file must succeed"
712
+ );
639
713
 
640
714
  ws.close();
641
715
  console.log(" Browser execution verified successfully!");