@mark1russell7/vex-compiler 0.17.0 → 0.17.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/vex-compiler",
4
- "version": "0.17.0",
4
+ "version": "0.17.1",
5
5
  "description": "The Vex compiler: generated JavaScript for Vex programs, at run time and at build time, with the results of the interpreter.",
6
6
  "keywords": [
7
7
  "vex",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@mark1russell7/cue": "github:mark1russell7/cue",
46
- "@mark1russell7/vex-domains": "0.17.0",
47
- "@mark1russell7/vex-testkit": "0.17.0",
46
+ "@mark1russell7/vex-domains": "0.17.1",
47
+ "@mark1russell7/vex-testkit": "0.17.1",
48
48
  "@types/node": "^26.6.4",
49
49
  "fast-check": "^4.10.2",
50
50
  "typescript": "^7.0.2",
51
51
  "vitest": "^5.0.3"
52
52
  },
53
53
  "dependencies": {
54
- "@mark1russell7/vex": "0.17.0"
54
+ "@mark1russell7/vex": "0.17.1"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsdown",
package/src/module.ts CHANGED
@@ -299,13 +299,14 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
299
299
  K: 'function K(k, n) { return typeof k === "string" && /^(0|[1-9]\\d*)$/.test(k) && +k < n ? +k : F(); }',
300
300
  // The ops on the order of a list (LIST.SORT, LIST.TAKE, LIST.NTH) work on the items with values. With strict, an
301
301
  // error item is the error of the op. A sort is stable, and the values are numbers without NaN or texts of one kind.
302
- V: "function V(l, s) { if (s && l.some((x) => x[1] === E)) F(); return l.filter((x) => x[1] !== E); }",
302
+ // V gives the array of VW, so a list without error items is not copied (COMPILE.MODULE.LIST.SHARE). No op changes it.
303
+ V: "function V(l, s) { const o = VW(l); if (s && o.length < l.length) F(); return o; }",
303
304
  SB: [
304
305
  "function SB(l, s) {",
305
306
  " const o = V(l, s);",
306
307
  " const t = o.length > 0 ? typeof o[0][1] : \"number\";",
307
308
  " for (const [, v] of o) if (typeof v !== t || (t !== \"number\" && t !== \"string\") || v !== v) F();",
308
- " return o.sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));",
309
+ " return o.slice().sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));",
309
310
  "}",
310
311
  ].join("\n"),
311
312
  // The option by of sortBy (LIST.SORT.BY): the function f gives the sort value of each item with a value, in order.
@@ -320,11 +321,12 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
320
321
  TK: "function TK(l, n, s) { const o = V(l, s); return Number.isSafeInteger(n) && n >= 0 ? o.slice(0, n) : F(); }",
321
322
  // The items with values of a list stay on its array, as GT keeps its index. Thus a loop that reads each item of a list
322
323
  // of n items with nth costs O(n), not O(n squared). count and first read them too (COMPILE.MODULE.NTH.INDEX).
324
+ // A list without error items is its own array of items with values.
323
325
  VW: [
324
326
  "function VW(l) {",
325
327
  " let o = l.vw;",
326
328
  " if (o === undefined) {",
327
- " o = l.filter((x) => x[1] !== E);",
329
+ " o = l.some((x) => x[1] === E) ? l.filter((x) => x[1] !== E) : l;",
328
330
  " l.vw = o;",
329
331
  " }",
330
332
  " return o;",
@@ -380,9 +382,10 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
380
382
  DR: "function DR(l, n, s) { const o = V(l, s); return Number.isSafeInteger(n) && n >= 0 ? o.slice(n) : F(); }",
381
383
  AP: "function AP(l, o, s) { return V(l, s).concat(V(o, s)); }",
382
384
  // append into the list of a name of a loop (COMPILE.MODULE.APPEND.OWN). w is the array of the last append of the name
383
- // in this run of the loop, and no other part reads it. Such an array has no error items, so V(l, s) is a copy of l.
384
- // Each other list gets the copy of AP. V(o, s) throws before the first push, so an error does not change l.
385
- AO: "function AO(l, o, s, w) { if (l !== w) return AP(l, o, s); for (const x of V(o, s)) l.push(x); return l; }",
385
+ // in this run of the loop, and no other part reads it. Such an array has no error items, so VW of it is the array.
386
+ // Each other list gets the copy of AP. V(o, s) throws before the first push, so an error does not change l. The loop
387
+ // reads n items, so it ends also if a is l.
388
+ AO: "function AO(l, o, s, w) { if (l !== w) return AP(l, o, s); const a = V(o, s), n = a.length; for (let i = 0; i < n; i++) l.push(a[i]); return l; }",
386
389
  WO: [
387
390
  "function WO(l, o, s) {",
388
391
  " const a = V(l, s), g = new Map();",
@@ -823,7 +826,7 @@ const NEEDS: Readonly<Record<Helper, readonly Helper[]>> = {
823
826
  F: [], C: [], T: [], L: [], Q: [], G: ["F"], B: ["F"], U: ["F"], X: ["F"], I: ["F"], K: ["F"], M: ["G"], M1: ["G"], S: ["M1", "F"],
824
827
  // Only the helpers of the list ops use V, and each of them needs F too, so the need of V only completes the list.
825
828
  // Stryker disable next-line ArrayDeclaration: see the comment above
826
- V: ["F"],
829
+ V: ["VW", "F"],
827
830
  SB: ["V", "F"], SK: ["V", "F"], TK: ["V", "F"], VW: [], NT: ["VW", "F"], CT: ["VW", "F"], FS: ["VW", "F"], FI: ["F"], LI: [],
828
831
  DR: ["V", "F"], AP: ["V"], AO: ["AP", "V"], WO: ["V"], FL: ["V"], GT: ["F"], IX: ["V", "F"],
829
832
  // Each module has C, and each move uses F (#move), so these needs only complete the list.