@mark1russell7/vex-compiler 0.13.0 → 0.13.2
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/build/index.d.ts +4 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +460 -66
- package/build/index.js.map +1 -1
- package/package.json +4 -4
- package/src/module.ts +407 -75
- package/src/runtime.ts +4 -0
- package/src/sheet-order.ts +56 -0
package/src/runtime.ts
CHANGED
|
@@ -237,6 +237,10 @@ export function createRuntime(options: RuntimeOptions): Runtime {
|
|
|
237
237
|
});
|
|
238
238
|
if (r !== undefined) return r;
|
|
239
239
|
}
|
|
240
|
+
// LIST.ARRAY: after the domains and the function of the host, a list op on an array is a list op on a list.
|
|
241
|
+
// FALLBACK is an error, and a list op skips an error item, so an exception must stop the program (V-064).
|
|
242
|
+
// Stryker disable next-line StringLiteral: the program catches the exception, so no one reads its message
|
|
243
|
+
if (listOp && fn === undefined && Array.isArray(values[0])) throw new Error("tier 1 gives a list op on an array");
|
|
240
244
|
try {
|
|
241
245
|
// Stryker disable next-line ConditionalExpression: a call of undefined throws, and the catch also gives F
|
|
242
246
|
return fn === undefined ? F : checked(fn(...values));
|
package/src/sheet-order.ts
CHANGED
|
@@ -121,3 +121,59 @@ export function keyOrderOf(d: ReadonlySet<Direction>): KeyOrder {
|
|
|
121
121
|
const post = d.has("down");
|
|
122
122
|
return { reverse, post, back: post !== reverse };
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The place of a read of a cell, relative to the key of the formula. The place `key` is the key itself. The place
|
|
127
|
+
* `children` is the body or a test of the axis `children` of the key. The place `unknown` is each other place.
|
|
128
|
+
*/
|
|
129
|
+
type ReadPlace = "key" | "children" | "unknown";
|
|
130
|
+
|
|
131
|
+
/** This function gives the axis under the tests of `where` and under `reverse`. Both read the targets of that axis. */
|
|
132
|
+
function baseOf(axis: Axis): Axis {
|
|
133
|
+
let base = axis;
|
|
134
|
+
while (base.t === "where" || base.t === "reverse") base = base.axis;
|
|
135
|
+
return base;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* This function tells if each read of a cell of the column `self` reads a finished cell in the static order of the
|
|
140
|
+
* fill (COMPILE.MODULE.SHEET.DIRECT). A read of a column before `self` in `order` reads a finished cell. A read of a
|
|
141
|
+
* column that the sheet does not have also reads a finished cell. A read of `self` reads a finished cell only in
|
|
142
|
+
* these three forms:
|
|
143
|
+
* - in a tree in pre-order, at the move `parent` from the key,
|
|
144
|
+
* - in an array in key order, at an offset of one negative step from the key,
|
|
145
|
+
* - in a tree in post-order, at the key of a target of the axis `children` of the key.
|
|
146
|
+
*
|
|
147
|
+
* A read in the body of a function can evaluate at each place of a call, so it is not one of these forms.
|
|
148
|
+
*/
|
|
149
|
+
export function readsFinished(columns: ReadonlyMap<string, Expr>, order: readonly string[], self: string, tree: boolean): boolean {
|
|
150
|
+
const formula = columns.get(self);
|
|
151
|
+
if (formula === undefined || shapeError(formula) !== undefined) return false;
|
|
152
|
+
const { reverse, post } = keyOrderOf(readsOf(columns, new Map(), self).directions);
|
|
153
|
+
const position = order.indexOf(self);
|
|
154
|
+
const todo: [Expr, ReadPlace][] = [[formula, "key"]];
|
|
155
|
+
for (let item = todo.pop(); item !== undefined; item = todo.pop()) {
|
|
156
|
+
const [e, place] = item;
|
|
157
|
+
if (e.tag === "each" || e.tag === "fold") {
|
|
158
|
+
const inner: ReadPlace = place === "key" && (e.at === undefined || e.at.length === 0) && baseOf(e.axis).t === "children" ? "children" : "unknown";
|
|
159
|
+
const { tests } = partsOf(e.axis);
|
|
160
|
+
for (const x of [...(e.tag === "each" ? [e.body] : Object.values(e.step)), ...tests]) todo.push([x, inner]);
|
|
161
|
+
const list = listOf(e.axis);
|
|
162
|
+
for (const x of [...(e.tag === "fold" ? [...Object.values(e.init), e.result] : []), ...addrExprs(e.at), ...(list === undefined ? [] : [list])]) todo.push([x, place]);
|
|
163
|
+
} else if (e.tag === "fn") todo.push([e.body, "unknown"]);
|
|
164
|
+
else if (e.tag !== "ext") for (const child of children(e)) todo.push([child, place]);
|
|
165
|
+
else if (e.kind === CELL_KIND && isCellRef(e.data)) {
|
|
166
|
+
const { column, at } = e.data;
|
|
167
|
+
const index = order.indexOf(column);
|
|
168
|
+
if (index > position) return false;
|
|
169
|
+
if (column !== self) continue;
|
|
170
|
+
const [move, ...rest] = at;
|
|
171
|
+
const ok =
|
|
172
|
+
place === "key"
|
|
173
|
+
? move !== undefined && rest.length === 0 && ((tree && !post && move.t === "parent") || (!tree && !reverse && move.t === "offset" && move.d.length === 1 && (move.d[0] ?? 0) < 0))
|
|
174
|
+
: place === "children" && tree && post && at.length === 0;
|
|
175
|
+
if (!ok) return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|