@mark1russell7/vex-compiler 0.10.0 → 0.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/facts.ts","../src/loop.ts","../src/tiers.ts","../src/module.ts","../src/runtime.ts"],"mappings":";;;KAgCY,aAAa;;;;;KAMb,OAAO;;;;;UAYF;WACN,SAAS,SAAS,eAAe;WACjC,OAAO,SAAS,eAAe;;;UAIzB;WACN,mBAAmB;WACnB,MAAM,SAAS,eAAe;WAC9B,aAAa,SAAS,eAAe;WACrC,SAAS;;;;;KCzCR;;KAeA;;KA2BA;WACG;WAAqB;;WACrB;WAAqB;;WACrB;WAAmB;;WACnB;WAAoB;;WACpB;;WACA;WAAqB,gBAAgB;;WACrC;WAAoB,IAAI;WAAiB,eAAe;;WACxD;WAAoB,IAAI;WAAoB,eAAe;;WAK3D;WAAkB;WAAuB,eAAe;WAAkB,iBAAiB;;WAE3F;WAAoB;;WAEpB;WAAuB;WAAuB,gBAAgB,OAAO,OAAO;;;;;;;;;;;KAW/E;WACG;;WACA;WAAwB;WAAwB;aAAoB,MAAM;aAAgB,MAAM;;;WAChG;WAAqB;;;KAGxB;WAEG;WAAmB;WAAoB,OAAO;;WAE9C;WAAmB;WAAoB,OAAO;;WAE9C;WAAqB,IAAI;WAAgB;WAAyB,MAAM;;WAExE;WAAoB,MAAM;;WAC1B;WAAkB,MAAM;WAAgB,cAAc;WAAkB,aAAa;;WAKrF;WAAoB;WAAwB;WAAuB;WAAwB;WAAwB,MAAM;WAAgB,eAAe;;WAExJ;WAAqB;WAAwB,eAAe;;WAE5D;WAAsB;WAAwB,eAAe;;WAE7D;;WAEA;WAAoB;WAAoB,OAAO;;WAC/C;WAAsB,OAAO;;;UAG3B;WACN,eAAe;WACf;;WAEA;;;;;KCrHC,kBAAkB;WAA4B,SAAS;;;;;;KAUvD;WACG;WAAmB,SAAS;WAAs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H,SAAS,QAAQ,OAAO,UAAU,UAAS,kBAAuB;;;;;wBAkBlE,KAAK,WAAW,QAAQ;WAAsB;KAAc;;UAO3D;;WAEN;;WAEA;;;UAIM,sBAAsB;;WAE5B;;WAEA;WACA,OAAO;;;;;;;wBAQF,OAAO,QAAQ,OAAO,UAAU,UAAS,kBAAuB;;;;UCjD/D;WACN,mBAAmB;;WAEnB,QAAQ;;WAER;;;KAIC;WAAqB;WAAmB;;WAA8B;WAAoB;;;;;;;wBAysDtF,WAAW,QAAQ,OAAO,UAAU,SAAS,gBAAgB;;;;qBC5sDhE;KACD,kBAAkB;;KAGlB,iBAAiB;;;;;;UAOZ;MACX;EACJ,GAAG;WACM,IAAI;WACJ,MAAM;;;KAIL,WAAW,QAAQ;WAAiB;;;UAG/B;WACN;WACA;;;UAIM;WACN;WACA;;;;;;UAOM;EACf,IAAI,GAAG,OAAO,2BAA2B;EACzC,IAAI,GAAG,OAAO,0BAA0B,YAAY,cAAc;;;UAgBnD;WACN,GAAG;EACZ,IAAI,GAAG,OAAO;;EAEd,KAAK,GAAG,OAAO,gBAAgB,eAAe,IAAI,MAAM;;;;;EAKxD,KAAK,MAAM,YAAY,GAAG,OAAO,gBAAgB,kBAAkB,UAAU;EAC7E,MAAM,QAAQ,SAAS,eAAe,qBAAqB;EAC3D,KAAK,GAAG;;EAER,KAAK,cAAc,gBAAgB;;EAEnC,QAAQ;;EAER,OAAO,gBAAgB;;EAEvB,MAAM,kBAAkB;EACxB,KAAK,cAAc,cAAc;EACjC,OAAO;EACP,KAAK;EACL,IAAI,0BAA0B;EAC9B,KAAK,yBAAyB;EAC9B,OAAO;EACP,IAAI,cAAc,eAAe,GAAG,OAAO,gBAAgB,eAAe;EAC1E,IAAI,MAAM,SAAS,sCAAsC;;;wBAI3C,cAAc,SAAS,iBAAiB"}
package/build/index.js CHANGED
@@ -10,7 +10,10 @@ import { MAX_NESTING, addrExprs, axisTargets, children, compile, findMethod, fix
10
10
  * twice doubles its body, so a chain of such functions grows fast. A module prints each function once.
11
11
  */
12
12
  const MAX_CALLS = 1e4;
13
- /** The list ops that give a list or read a position of a list (LIST.SORT, LIST.TAKE, LIST.NTH, LIST.BUILD). */
13
+ /**
14
+ * The list ops that give a list, or read a position or a key of a list (LIST.SORT, LIST.TAKE, LIST.NTH, LIST.BUILD,
15
+ * LIST.GET).
16
+ */
14
17
  const ORDER_OPS = /* @__PURE__ */ new Set([
15
18
  "sortBy",
16
19
  "take",
@@ -18,17 +21,20 @@ const ORDER_OPS = /* @__PURE__ */ new Set([
18
21
  "drop",
19
22
  "append",
20
23
  "flat",
21
- "without"
24
+ "without",
25
+ "get"
22
26
  ]);
23
27
  /**
24
- * This function gives the reason that tier 2 cannot take a program with lists as values. The reason is the axis `list`
25
- * or an op on the order of a list. Tier 1 evaluates such a program. It uses a stack, not recursion.
28
+ * This function gives the reason that tier 2 cannot take a program with lists as values. The reason is the axis `list`,
29
+ * an op on the order or the keys of a list, or a list literal. Tier 1 evaluates such a program. It uses a stack, not
30
+ * recursion.
26
31
  */
27
32
  function listReason(expr) {
28
33
  const todo = [expr];
29
34
  for (let x = todo.pop(); x !== void 0; x = todo.pop()) {
30
35
  if ((x.tag === "each" || x.tag === "fold") && listOf(x.axis) !== void 0) return "the program has the axis \"list\", and tier 2 does not have lists as values yet";
31
36
  if (x.tag === "app" && ORDER_OPS.has(x.op)) return `the program has the list op "${x.op}", and tier 2 does not have lists as values yet`;
37
+ if (x.tag === "lit" && isVexList(x.value)) return "the program has a list literal, and tier 2 does not have lists as values yet";
32
38
  todo.push(...children(x));
33
39
  }
34
40
  }
@@ -1332,6 +1338,7 @@ var Lowerer = class {
1332
1338
  case "append":
1333
1339
  case "flat":
1334
1340
  case "without":
1341
+ case "get":
1335
1342
  /* v8 ignore next -- @preserve */
1336
1343
  throw new Unsupported(`the list op "${op}"`);
1337
1344
  }
@@ -2058,12 +2065,13 @@ const BOOLEAN_LIST_OPS = /* @__PURE__ */ new Set([
2058
2065
  "all",
2059
2066
  "none"
2060
2067
  ]);
2061
- /** The list ops that build a list from lists (LIST.BUILD). A module gives a reason for them. */
2068
+ /** The list ops that build a list from lists (LIST.BUILD), and `get` (LIST.GET). A module gives a reason for them. */
2062
2069
  const BUILD_OPS = /* @__PURE__ */ new Set([
2063
2070
  "drop",
2064
2071
  "append",
2065
2072
  "flat",
2066
- "without"
2073
+ "without",
2074
+ "get"
2067
2075
  ]);
2068
2076
  /** This function gives the kind of the result of a list op: first gives the kind of its items. */
2069
2077
  const listKind = (op, item) => NUMBER_LIST_OPS.has(op) ? "number" : BOOLEAN_LIST_OPS.has(op) ? "boolean" : item;
@@ -2256,6 +2264,21 @@ const CALLS = /* @__PURE__ */ new Set([
2256
2264
  "Number.isFinite"
2257
2265
  ]);
2258
2266
  /**
2267
+ * The tokens of the text between the names of an inline form: digits, spaces, operators and parentheses. The tokenizer
2268
+ * takes the first token that matches at each position, as the tokenizer of JavaScript takes the longest operator. So
2269
+ * `<<=`, `>>=` and `>>>=` leave a lone `=`, and an assignment stops the inline form (V-058).
2270
+ */
2271
+ const TOKEN = /\d|\.\d|\s|===?|!==?|<<|>>>?|<=|>=|[+\-*/%<>!?:(),&|^~]/y;
2272
+ /**
2273
+ * This function tells if a text is a sequence of tokens. It takes one token at each step, so its time is linear in the
2274
+ * length of the text. A repeated group of the tokens can split `!==` in two ways, and its time is exponential (V-057).
2275
+ */
2276
+ function isTokens(t) {
2277
+ TOKEN.lastIndex = 0;
2278
+ while (TOKEN.lastIndex < t.length) if (!TOKEN.test(t)) return false;
2279
+ return true;
2280
+ }
2281
+ /**
2259
2282
  * This function gives the inline form of the source of an arrow function. The body of the function must be an
2260
2283
  * expression of operators, numbers, its parameters and the functions of `CALLS`. Such a body cannot throw for primitive
2261
2284
  * values (§7.1). The inline form is the text of the function itself, so it has its bits.
@@ -2269,7 +2292,7 @@ function inlineForm(src) {
2269
2292
  let text = "";
2270
2293
  const split = m[2].split(/([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?)/);
2271
2294
  for (const [i, t] of split.entries()) if (i % 2 === 0) {
2272
- if (!/^(?:\d|\.\d|\s|===?|!==?|<=|>=|[+\-*/%<>!?:(),&|^~])*$/.test(t) || /\+\+|--|\)\s*\(/.test(t)) return void 0;
2295
+ if (!isTokens(t) || /\+\+|--|\)\s*\(/.test(t)) return void 0;
2273
2296
  text += t;
2274
2297
  } else if (CALLS.has(t)) text += t;
2275
2298
  else {