@toiroakr/chisel 0.1.0 → 0.2.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.
- package/README.md +249 -20
- package/dist/absence.d.ts +27 -0
- package/dist/absence.js +228 -0
- package/dist/absence.js.map +1 -0
- package/dist/behavior.d.ts +21 -9
- package/dist/behavior.js +219 -52
- package/dist/behavior.js.map +1 -1
- package/dist/border.d.ts +4 -7
- package/dist/border.js +43 -35
- package/dist/border.js.map +1 -1
- package/dist/bounds.d.ts +1 -0
- package/dist/bounds.js +26 -0
- package/dist/bounds.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +272 -4
- package/dist/cli.js.map +1 -1
- package/dist/codec.js +7 -4
- package/dist/codec.js.map +1 -1
- package/dist/codegen.js +4 -8
- package/dist/codegen.js.map +1 -1
- package/dist/composition.d.ts +3 -3
- package/dist/composition.js +4 -4
- package/dist/composition.js.map +1 -1
- package/dist/data.d.ts +1 -0
- package/dist/data.js +2 -0
- package/dist/data.js.map +1 -1
- package/dist/dependency.d.ts +9 -6
- package/dist/dependency.js +23 -17
- package/dist/dependency.js.map +1 -1
- package/dist/domain.d.ts +5 -1
- package/dist/domain.js +6 -6
- package/dist/domain.js.map +1 -1
- package/dist/ensures.js +2 -2
- package/dist/ensures.js.map +1 -1
- package/dist/equal.d.ts +1 -0
- package/dist/equal.js +135 -0
- package/dist/equal.js.map +1 -0
- package/dist/feasibility.d.ts +5 -3
- package/dist/feasibility.js +106 -37
- package/dist/feasibility.js.map +1 -1
- package/dist/guard-borders.d.ts +12 -5
- package/dist/guard-borders.js +122 -171
- package/dist/guard-borders.js.map +1 -1
- package/dist/guard-scope.d.ts +61 -0
- package/dist/guard-scope.js +364 -0
- package/dist/guard-scope.js.map +1 -0
- package/dist/index.d.ts +17 -6
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/interleave.d.ts +31 -0
- package/dist/interleave.js +202 -0
- package/dist/interleave.js.map +1 -0
- package/dist/interval.d.ts +7 -0
- package/dist/interval.js +171 -21
- package/dist/interval.js.map +1 -1
- package/dist/isolated.js.map +1 -1
- package/dist/machine-check.d.ts +73 -0
- package/dist/machine-check.js +215 -0
- package/dist/machine-check.js.map +1 -0
- package/dist/machine.d.ts +97 -0
- package/dist/machine.js +200 -0
- package/dist/machine.js.map +1 -0
- package/dist/model.d.ts +74 -9
- package/dist/model.js +469 -34
- package/dist/model.js.map +1 -1
- package/dist/outcomes.d.ts +7 -0
- package/dist/outcomes.js +38 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/pairs.js +12 -4
- package/dist/pairs.js.map +1 -1
- package/dist/partition.d.ts +1 -0
- package/dist/partition.js +90 -11
- package/dist/partition.js.map +1 -1
- package/dist/proof.d.ts +6 -0
- package/dist/proof.js +96 -22
- package/dist/proof.js.map +1 -1
- package/dist/replay.d.ts +45 -0
- package/dist/replay.js +157 -0
- package/dist/replay.js.map +1 -0
- package/dist/rule.d.ts +47 -7
- package/dist/rule.js +284 -17
- package/dist/rule.js.map +1 -1
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.js +16 -12
- package/dist/schema.js.map +1 -1
- package/dist/specification.d.ts +12 -2
- package/dist/specification.js +622 -82
- package/dist/specification.js.map +1 -1
- package/dist/temporal-global.d.ts +4 -0
- package/dist/temporal-global.js +11 -0
- package/dist/temporal-global.js.map +1 -0
- package/dist/temporal.d.ts +22 -0
- package/dist/temporal.js +113 -0
- package/dist/temporal.js.map +1 -0
- package/dist/tla.d.ts +54 -0
- package/dist/tla.js +579 -0
- package/dist/tla.js.map +1 -0
- package/dist/verification.d.ts +7 -0
- package/dist/verification.js +5 -0
- package/dist/verification.js.map +1 -0
- package/dist/ways.d.ts +8 -5
- package/dist/ways.js +30 -39
- package/dist/ways.js.map +1 -1
- package/dist/world.d.ts +98 -0
- package/dist/world.js +467 -0
- package/dist/world.js.map +1 -0
- package/package.json +32 -9
package/dist/guard-borders.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const values = Object.entries(definition.requires).flatMap(([name, declared]) => declared.takes === "nothing" ? [[name, declared.output]] : []);
|
|
9
|
-
if (values.length === 0) {
|
|
10
|
-
return variant;
|
|
11
|
-
}
|
|
12
|
-
const deps = { ...object(Object.fromEntries(values)) };
|
|
13
|
-
return { ...variant, shape: { ...variant.shape, [DEPS]: deps } };
|
|
14
|
-
}
|
|
1
|
+
import { temporalNeighbor, timelineOf } from "./temporal.js";
|
|
2
|
+
import { deepEqual } from "./equal.js";
|
|
3
|
+
import { bordersOf, decimalUnitsCarrier, integerCarrier, nanosecondCarrier, normalize, numberCarrier } from "./border.js";
|
|
4
|
+
import { carrierOf, positionsOf, writeExactly } from "./partition.js";
|
|
5
|
+
import { DEPS, boundTermPath, conjuncts, describeRule, holds, isDecimal, isTerm, readOperand, selfTerm, shiftTerms, termData, termPaths, positionData, positionOf, positionTerm, differenceOf, withDeps, decimalOfUnits, decimalUnits, counts, measured, measureLabel } from "./rule.js";
|
|
6
|
+
import { enumOf, int, isVariantsSchema, object, variants } from "./schema.js";
|
|
7
|
+
import { casesOnTrail, enter, everyStepsOf, framesAt, framesFor, guardScope, inheritedAt, labelsOf, locate, onTrail, pathOf, schemaAlong, schemaAt, segmentsOf, thresholdsIn } from "./guard-scope.js";
|
|
15
8
|
// The case as feasibility reads it: the invariants written on the input sum
|
|
16
9
|
// hold of every case, as the partition passes them down, and read the
|
|
17
10
|
// discriminant as the one value it has under this case.
|
|
18
|
-
export function feasibilityScope(definition, tag) {
|
|
19
|
-
const scope = guardScope(definition, tag);
|
|
11
|
+
export function feasibilityScope(definition, tag, decision, steps = []) {
|
|
12
|
+
const scope = guardScope(definition, tag, decision, steps);
|
|
20
13
|
const { discriminant } = definition.input;
|
|
21
14
|
return {
|
|
22
15
|
...scope,
|
|
@@ -29,18 +22,18 @@ export function feasibilityScope(definition, tag) {
|
|
|
29
22
|
export function guardBordersOf(implementation) {
|
|
30
23
|
const input = implementation.behavior.input;
|
|
31
24
|
const positions = positionsOf(input, { containers: true });
|
|
32
|
-
const at = (segments) => positions.find(position =>
|
|
25
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
33
26
|
return Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
34
27
|
? []
|
|
35
|
-
: decision.guards.flatMap(candidate => walk(candidate.condition,
|
|
28
|
+
: decision.guards.flatMap(candidate => walk(candidate.condition, framesFor(implementation.behavior, tag, decision), at, asGuard).map(drawn => ({
|
|
36
29
|
...drawn,
|
|
37
|
-
origin: { decision, scope: feasibilityScope(implementation.behavior, tag), tag },
|
|
30
|
+
origin: { decision, scope: feasibilityScope(implementation.behavior, tag, decision), tag },
|
|
38
31
|
}))));
|
|
39
32
|
}
|
|
40
33
|
export function ensuresBordersOf(definition) {
|
|
41
34
|
const input = definition.input;
|
|
42
35
|
const positions = positionsOf(input);
|
|
43
|
-
const at = (segments) => positions.find(position =>
|
|
36
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
44
37
|
return definition.ensures.flatMap(clause => conjuncts(clause.rule).flatMap(part => {
|
|
45
38
|
const onInput = unrooted(part);
|
|
46
39
|
if (onInput === undefined) {
|
|
@@ -57,7 +50,7 @@ export function ensuresBordersOf(definition) {
|
|
|
57
50
|
// no single position carries.
|
|
58
51
|
export function invariantPairBordersOf(definition) {
|
|
59
52
|
const positions = positionsOf(definition.input, { containers: true });
|
|
60
|
-
const at = (segments) => positions.find(position =>
|
|
53
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
61
54
|
const reading = {
|
|
62
55
|
source: "invariant",
|
|
63
56
|
describe: (compared, read) => describeRule(compared, read.root.label, labelsOf(read)),
|
|
@@ -214,7 +207,7 @@ export function guardPartitionsOf(implementation) {
|
|
|
214
207
|
const input = implementation.behavior.input;
|
|
215
208
|
const thresholds = Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
216
209
|
? []
|
|
217
|
-
: decision.guards.flatMap(candidate => thresholdsIn(candidate.condition,
|
|
210
|
+
: decision.guards.flatMap(candidate => thresholdsIn(candidate.condition, framesFor(implementation.behavior, tag, decision))));
|
|
218
211
|
const trails = [...new Set(thresholds.map(threshold => JSON.stringify(threshold.segments)))];
|
|
219
212
|
return trails.flatMap(trail => {
|
|
220
213
|
const atPath = thresholds.filter(threshold => JSON.stringify(threshold.segments) === trail);
|
|
@@ -222,95 +215,6 @@ export function guardPartitionsOf(implementation) {
|
|
|
222
215
|
return partition === undefined ? [] : [partition];
|
|
223
216
|
});
|
|
224
217
|
}
|
|
225
|
-
// Guards are read here rather than through offGridEquality, since a guard's
|
|
226
|
-
// terms reach the dependencies and are located through the guard's frames.
|
|
227
|
-
export function offGridEqualityIn(definition, tag, decision) {
|
|
228
|
-
const frames = framesAt(guardScope(definition, tag), `@${tag}`, "$");
|
|
229
|
-
for (const threshold of decision.guards.flatMap(candidate => thresholdsIn(candidate.condition, frames))) {
|
|
230
|
-
const { operator, bound } = normalize(threshold.rule);
|
|
231
|
-
if (holdsNoDecimal(threshold.schema, operator, bound)) {
|
|
232
|
-
const scale = threshold.schema.scale;
|
|
233
|
-
return `compares ${threshold.label} with ${String(bound)}, which no decimal(${scale}) holds: ${threshold.described}`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const scope = guardScope(definition, tag);
|
|
237
|
-
return decision.guards
|
|
238
|
-
.map(candidate => offGridEquality(candidate.condition, path => schemaAtPath(scope, path), "$"))
|
|
239
|
-
.find(found => found !== undefined);
|
|
240
|
-
}
|
|
241
|
-
function framesAt(scope, path, label) {
|
|
242
|
-
return { root: { scope, path, segments: [path], label }, elements: {} };
|
|
243
|
-
}
|
|
244
|
-
function locate(term, frames) {
|
|
245
|
-
const keys = positionOf(term).path;
|
|
246
|
-
const element = keys[0] === undefined ? undefined : frames.elements[keys[0]];
|
|
247
|
-
return element === undefined
|
|
248
|
-
? { frame: frames.root, keys }
|
|
249
|
-
: { frame: element, keys: keys.slice(1) };
|
|
250
|
-
}
|
|
251
|
-
function enter(rule, frames) {
|
|
252
|
-
const { frame, keys } = locate(rule.of, frames);
|
|
253
|
-
const collection = schemaAt(frame.scope, keys);
|
|
254
|
-
if (collection?.kind !== "array") {
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
const suffix = keys.map(key => `.${key}`).join("");
|
|
258
|
-
return {
|
|
259
|
-
root: frames.root,
|
|
260
|
-
elements: {
|
|
261
|
-
...frames.elements,
|
|
262
|
-
[rule.element]: {
|
|
263
|
-
scope: collection.element,
|
|
264
|
-
path: `${frame.path}${suffix}[]`,
|
|
265
|
-
segments: [...segmentsOf(frame, keys), "[]"],
|
|
266
|
-
label: `${frame.label}${suffix}[]`,
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
function labelsOf(frames) {
|
|
272
|
-
return Object.fromEntries(Object.entries(frames.elements).map(([name, frame]) => [name, frame.label]));
|
|
273
|
-
}
|
|
274
|
-
function pathOf(frame, keys) {
|
|
275
|
-
return `${frame.path}${keys.map(key => `.${key}`).join("")}`;
|
|
276
|
-
}
|
|
277
|
-
// The rendered path is for reports; positions are found by segments, since a
|
|
278
|
-
// key holding "." renders the same as the nested path it spells.
|
|
279
|
-
function segmentsOf(frame, keys) {
|
|
280
|
-
return [...frame.segments, ...keys.map(key => `.${key}`)];
|
|
281
|
-
}
|
|
282
|
-
function thresholdsIn(rule, frames) {
|
|
283
|
-
if (rule.kind === "and" || rule.kind === "or") {
|
|
284
|
-
return rule.rules.flatMap(part => thresholdsIn(part, frames));
|
|
285
|
-
}
|
|
286
|
-
if (rule.kind === "not") {
|
|
287
|
-
return thresholdsIn(rule.rule, frames);
|
|
288
|
-
}
|
|
289
|
-
if (rule.kind === "all" || rule.kind === "any") {
|
|
290
|
-
const inner = enter(rule, frames);
|
|
291
|
-
return inner === undefined ? [] : thresholdsIn(rule.each, inner);
|
|
292
|
-
}
|
|
293
|
-
const normalized = normalize(rule);
|
|
294
|
-
if (rule.kind !== "compare" || normalized === undefined || normalized.measure !== "value") {
|
|
295
|
-
return [];
|
|
296
|
-
}
|
|
297
|
-
const term = (isTerm(rule.left) ? rule.left : rule.right);
|
|
298
|
-
const { frame, keys } = locate(term, frames);
|
|
299
|
-
const schema = schemaAt(frame.scope, keys);
|
|
300
|
-
return schema === undefined
|
|
301
|
-
? []
|
|
302
|
-
: [
|
|
303
|
-
{
|
|
304
|
-
path: pathOf(frame, keys),
|
|
305
|
-
label: `${frame.label}${keys.map(key => `.${key}`).join("")}`,
|
|
306
|
-
described: describeRule(rule, frames.root.label, labelsOf(frames)),
|
|
307
|
-
segments: segmentsOf(frame, keys),
|
|
308
|
-
schema,
|
|
309
|
-
inherited: inheritedAt(frame.scope, keys),
|
|
310
|
-
rule,
|
|
311
|
-
},
|
|
312
|
-
];
|
|
313
|
-
}
|
|
314
218
|
function partitionAt(path, segments, schema, inherited, rules) {
|
|
315
219
|
const carrier = carrierOf(schema, "value");
|
|
316
220
|
if (carrier === undefined) {
|
|
@@ -378,19 +282,6 @@ function partitionAt(path, segments, schema, inherited, rules) {
|
|
|
378
282
|
}
|
|
379
283
|
return { path, segments, classes, excluded };
|
|
380
284
|
}
|
|
381
|
-
export function inheritedAt(scope, keys) {
|
|
382
|
-
const [key, ...rest] = keys;
|
|
383
|
-
const unwrapped = scope.kind === "optional" ? scope.schema : scope;
|
|
384
|
-
if (key === undefined || unwrapped.kind !== "object") {
|
|
385
|
-
return [];
|
|
386
|
-
}
|
|
387
|
-
const field = unwrapped.shape[key];
|
|
388
|
-
const here = unwrapped.invariants.flatMap(conjuncts).flatMap(rule => {
|
|
389
|
-
const stepped = keys.reduce((current, next) => (current === undefined ? undefined : stepInto(current, next)), rule);
|
|
390
|
-
return stepped === undefined ? [] : [stepped];
|
|
391
|
-
});
|
|
392
|
-
return field === undefined ? here : [...here, ...inheritedAt(field, rest)];
|
|
393
|
-
}
|
|
394
285
|
function admittedRange(invariants, carrier) {
|
|
395
286
|
let lower;
|
|
396
287
|
let upper;
|
|
@@ -445,48 +336,70 @@ function walk(rule, frames, at, reading) {
|
|
|
445
336
|
}
|
|
446
337
|
const { frame, keys } = locate(term, frames);
|
|
447
338
|
const { measure } = positionOf(term);
|
|
448
|
-
const
|
|
449
|
-
if (
|
|
339
|
+
const whole = schemaAt(frame.scope, keys);
|
|
340
|
+
if (whole === undefined) {
|
|
450
341
|
return [];
|
|
451
342
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
343
|
+
// A field the cases of a sum share is drawn under each, read as that case declares it.
|
|
344
|
+
return everyStepsOf(frame.scope, keys).flatMap(steps => {
|
|
345
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? whole;
|
|
346
|
+
const borders = bordersOf([rule], found => carrierOf(schema, found), {
|
|
347
|
+
source: reading.source,
|
|
348
|
+
describe: () => reading.describe(rule, frames),
|
|
349
|
+
admits: coordinate => measure !== "value" ||
|
|
350
|
+
(schema.parse(coordinate).success &&
|
|
351
|
+
inheritedAt(frame.scope, keys, steps).every(inherited => holds(inherited, coordinate))),
|
|
352
|
+
});
|
|
353
|
+
const positionPath = pathOf(frame, keys, steps);
|
|
354
|
+
const positionSegments = [...frame.segments, ...steps];
|
|
355
|
+
return borders.map(border => ({
|
|
356
|
+
path: positionPath,
|
|
357
|
+
segments: positionSegments,
|
|
358
|
+
comparison: rule,
|
|
359
|
+
border,
|
|
360
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
361
|
+
coordinateOf: (reached) => onTrail(frame.scope, keys, steps, frame === frames.root ? reached.scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), reached.scope)) ? readOperand(term, reached.scope) : undefined,
|
|
362
|
+
compose: (given, coordinate) => {
|
|
363
|
+
const position = at(positionSegments);
|
|
364
|
+
return position === undefined ? undefined : writeExactly(position, given, measure, coordinate);
|
|
365
|
+
},
|
|
366
|
+
}));
|
|
458
367
|
});
|
|
459
|
-
const positionPath = pathOf(frame, keys);
|
|
460
|
-
const positionSegments = segmentsOf(frame, keys);
|
|
461
|
-
return borders.map(border => ({
|
|
462
|
-
path: positionPath,
|
|
463
|
-
segments: positionSegments,
|
|
464
|
-
comparison: rule,
|
|
465
|
-
border,
|
|
466
|
-
coordinateOf: reached => readOperand(term, reached.scope),
|
|
467
|
-
compose: (given, coordinate) => at(positionSegments)?.write(given, measure, coordinate),
|
|
468
|
-
}));
|
|
469
368
|
}
|
|
470
369
|
function betweenExpression(rule, frames, at, reading) {
|
|
471
370
|
const form = differenceOf(rule);
|
|
472
371
|
if (rule.operator === "==" || rule.operator === "!=" || typeof form.constant !== "number") {
|
|
473
372
|
return [];
|
|
474
373
|
}
|
|
475
|
-
|
|
374
|
+
// Every trail through the cases of the sums each part passes, the parts under one sum read under the same case of it.
|
|
375
|
+
const options = form.parts.map(part => {
|
|
476
376
|
const term = positionTerm(part.path, part.measure);
|
|
477
377
|
const { frame, keys } = locate(term, frames);
|
|
478
|
-
|
|
378
|
+
return everyStepsOf(frame.scope, keys).map(steps => ({
|
|
379
|
+
part, term, frame, keys, steps,
|
|
380
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
381
|
+
}));
|
|
382
|
+
});
|
|
383
|
+
const agree = (a, b) => a.every(one => b.every(other => one.at.join("\u0000") !== other.at.join("\u0000") || one.tag === other.tag));
|
|
384
|
+
const trails = options.reduce((all, choices) => all.flatMap(prefix => choices.filter(choice => prefix.every(held => agree(held.cases, choice.cases))).map(choice => [...prefix, choice])), [[]]);
|
|
385
|
+
return trails.flatMap(chosen => betweenExpressionOn(rule, form, chosen, frames, at, reading));
|
|
386
|
+
}
|
|
387
|
+
function betweenExpressionOn(rule, form, chosen, frames, at, reading) {
|
|
388
|
+
const parts = chosen.map(({ part, term, frame, keys, steps }) => {
|
|
389
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? schemaAt(frame.scope, keys);
|
|
479
390
|
const standsIn = frame === frames.root && keys[0] === DEPS;
|
|
480
391
|
return {
|
|
481
392
|
term,
|
|
482
393
|
coefficient: part.coefficient,
|
|
483
394
|
measure: part.measure,
|
|
484
395
|
standsIn,
|
|
485
|
-
path: standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys),
|
|
486
|
-
segments:
|
|
487
|
-
kind: part.measure
|
|
396
|
+
path: measureLabel(standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys, steps), part.measure),
|
|
397
|
+
segments: [...frame.segments, ...steps],
|
|
398
|
+
kind: counts(part.measure) ? "integer" : schema?.kind,
|
|
399
|
+
onTrail: (scope) => onTrail(frame.scope, keys, steps, frame === frames.root ? scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), scope)),
|
|
488
400
|
};
|
|
489
401
|
});
|
|
402
|
+
const cases = chosen.flatMap(item => item.cases).filter((item, index, all) => all.findIndex(other => other.at.join("\u0000") === item.at.join("\u0000")) === index);
|
|
490
403
|
const carrier = parts.every(part => part.kind === "integer")
|
|
491
404
|
? integerCarrier
|
|
492
405
|
: parts.every(part => part.kind === "integer" || part.kind === "number")
|
|
@@ -540,7 +453,10 @@ function betweenExpression(rule, frames, at, reading) {
|
|
|
540
453
|
comparison: rule,
|
|
541
454
|
border,
|
|
542
455
|
...(weighed === undefined ? {} : { form: weighed }),
|
|
456
|
+
cases,
|
|
543
457
|
coordinateOf: reached => {
|
|
458
|
+
if (!parts.every(part => part.onTrail(reached.scope)))
|
|
459
|
+
return undefined;
|
|
544
460
|
let total = constant;
|
|
545
461
|
for (const part of parts) {
|
|
546
462
|
const value = valueOf(part, reached.scope);
|
|
@@ -558,37 +474,63 @@ function betweenExpression(rule, frames, at, reading) {
|
|
|
558
474
|
if (moving === undefined || moved === undefined) {
|
|
559
475
|
return undefined;
|
|
560
476
|
}
|
|
477
|
+
const partValue = (part, scope) => {
|
|
478
|
+
const value = part.standsIn
|
|
479
|
+
? readOperand(part.term, withDeps({}, deps))
|
|
480
|
+
: at(part.segments)?.valuesIn(scope)[0];
|
|
481
|
+
return value === undefined || part.standsIn || !counts(part.measure) ? value : measured(value, part.measure);
|
|
482
|
+
};
|
|
561
483
|
let rest = constant;
|
|
562
484
|
for (const part of parts) {
|
|
563
485
|
if (part === moving) {
|
|
564
486
|
continue;
|
|
565
487
|
}
|
|
566
|
-
const value = part
|
|
567
|
-
? readOperand(part.term, withDeps({}, deps))
|
|
568
|
-
: at(part.segments)?.valuesIn(given)[0];
|
|
488
|
+
const value = partValue(part, given);
|
|
569
489
|
if (value === undefined) {
|
|
570
490
|
return undefined;
|
|
571
491
|
}
|
|
572
|
-
rest += part.coefficient *
|
|
492
|
+
rest += part.coefficient * value;
|
|
573
493
|
}
|
|
574
|
-
|
|
494
|
+
const written = moved.write(given, moving.measure, (coordinate - rest) / moving.coefficient);
|
|
495
|
+
// Moving a part that another reads too, as `length(trim($.code))` reads
|
|
496
|
+
// `$.code`, moves both, so the row is kept only where it stands at the point.
|
|
497
|
+
const shared = parts.some(part => part !== moving && !part.standsIn && deepEqual(part.segments, moving.segments));
|
|
498
|
+
return !shared ||
|
|
499
|
+
parts.reduce((total, part) => {
|
|
500
|
+
const value = partValue(part, written);
|
|
501
|
+
return total === undefined || value === undefined ? undefined : total + part.coefficient * value;
|
|
502
|
+
}, constant) === coordinate
|
|
503
|
+
? written
|
|
504
|
+
: undefined;
|
|
575
505
|
},
|
|
576
506
|
}));
|
|
577
507
|
}
|
|
578
508
|
function between(rule, left, right, frames, at, reading) {
|
|
579
|
-
const
|
|
509
|
+
const options = [left, right].map(term => {
|
|
580
510
|
const { frame, keys } = locate(term, frames);
|
|
511
|
+
return everyStepsOf(frame.scope, keys).map((steps) => ({
|
|
512
|
+
term, frame, keys, steps,
|
|
513
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
514
|
+
}));
|
|
515
|
+
});
|
|
516
|
+
// Two sides under one sum are read under the same case of it.
|
|
517
|
+
const compatible = (a, b) => a.cases.every(one => b.cases.every(other => one.at.join("\u0000") !== other.at.join("\u0000") || one.tag === other.tag));
|
|
518
|
+
return options[0].flatMap(a => options[1].filter(b => compatible(a, b)).flatMap(b => betweenOn(rule, [a, b], frames, at, reading)));
|
|
519
|
+
}
|
|
520
|
+
function betweenOn(rule, options, frames, at, reading) {
|
|
521
|
+
const sides = options.map(({ term, frame, keys, steps }) => {
|
|
581
522
|
const { measure } = positionOf(term);
|
|
582
|
-
const schema = schemaAt(frame.scope, keys);
|
|
523
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? schemaAt(frame.scope, keys);
|
|
583
524
|
const standsIn = frame === frames.root && keys[0] === DEPS;
|
|
584
525
|
return {
|
|
585
526
|
term,
|
|
586
527
|
measure,
|
|
587
528
|
standsIn,
|
|
588
|
-
path: standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys),
|
|
589
|
-
segments:
|
|
590
|
-
kind: measure
|
|
529
|
+
path: measureLabel(standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys, steps), measure),
|
|
530
|
+
segments: [...frame.segments, ...steps],
|
|
531
|
+
kind: counts(measure) ? "integer" : schema?.kind,
|
|
591
532
|
scale: measure === "value" && schema?.kind === "decimal" ? schema.scale : 0,
|
|
533
|
+
onTrail: (scope) => onTrail(frame.scope, keys, steps, frame === frames.root ? scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), scope)),
|
|
592
534
|
};
|
|
593
535
|
});
|
|
594
536
|
const [first, second] = sides;
|
|
@@ -637,7 +579,10 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
637
579
|
comparison: rule,
|
|
638
580
|
border,
|
|
639
581
|
...(form === undefined ? {} : { form }),
|
|
582
|
+
cases: [...options[0].cases, ...options[1].cases.filter(other => !options[0].cases.some(one => one.at.join("\u0000") === other.at.join("\u0000")))],
|
|
640
583
|
coordinateOf: reached => {
|
|
584
|
+
if (!first.onTrail(reached.scope) || !second.onTrail(reached.scope))
|
|
585
|
+
return undefined;
|
|
641
586
|
const a = read(first, reached.scope);
|
|
642
587
|
const b = read(second, reached.scope);
|
|
643
588
|
return a === undefined || b === undefined ? undefined : a - b;
|
|
@@ -677,8 +622,15 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
677
622
|
? undefined
|
|
678
623
|
: held.write(given, fixed.measure, counter);
|
|
679
624
|
}
|
|
680
|
-
const base = fixed.measure
|
|
681
|
-
|
|
625
|
+
const base = counts(fixed.measure) && !fixed.standsIn ? measured(other, fixed.measure) : other;
|
|
626
|
+
const written = moved.write(given, moving.measure, base + sign * coordinate);
|
|
627
|
+
// Moving one side of `length(trim($.code)) < length($.code)` moves the
|
|
628
|
+
// other too, so the row is kept only where it stands at the point.
|
|
629
|
+
if (fixed.standsIn || !deepEqual(fixed.segments, moving.segments)) {
|
|
630
|
+
return written;
|
|
631
|
+
}
|
|
632
|
+
const [a, b] = [first, second].map(side => measured(at(side.segments)?.valuesIn(written)[0], side.measure));
|
|
633
|
+
return typeof a === "number" && typeof b === "number" && a - b === coordinate ? written : undefined;
|
|
682
634
|
},
|
|
683
635
|
}));
|
|
684
636
|
}
|
|
@@ -699,7 +651,7 @@ function decimalMoment(first, second) {
|
|
|
699
651
|
const MOMENTS = {
|
|
700
652
|
instant: {
|
|
701
653
|
read: value => value.epochNanoseconds,
|
|
702
|
-
shift: (value, amount) => value
|
|
654
|
+
shift: (value, amount) => temporalNeighbor(value, { nanoseconds: amount }),
|
|
703
655
|
},
|
|
704
656
|
date: {
|
|
705
657
|
// Counted in the ISO calendar, since until refuses two dates in different
|
|
@@ -708,13 +660,12 @@ const MOMENTS = {
|
|
|
708
660
|
.from("1970-01-01")
|
|
709
661
|
.until(value.withCalendar("iso8601"), { largestUnit: "days" })
|
|
710
662
|
.total("days"),
|
|
711
|
-
shift: (value, amount) => value
|
|
663
|
+
shift: (value, amount) => temporalNeighbor(value, { days: amount }),
|
|
712
664
|
},
|
|
713
665
|
datetime: {
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
shift: (value, amount) => value.add({ nanoseconds: amount }),
|
|
666
|
+
// A date-time can lie beyond the instant range, so it is not read through a UTC instant.
|
|
667
|
+
read: value => timelineOf(value).numerator,
|
|
668
|
+
shift: (value, amount) => temporalNeighbor(value, { nanoseconds: amount }),
|
|
718
669
|
},
|
|
719
670
|
time: {
|
|
720
671
|
read: value => BigInt(value.constructor.from("00:00").until(value, { largestUnit: "hours" }).total("nanoseconds")),
|
|
@@ -750,7 +701,7 @@ export function comparisonsNotReadOf(implementation) {
|
|
|
750
701
|
const input = implementation.behavior.input;
|
|
751
702
|
return Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
752
703
|
? []
|
|
753
|
-
: decision.guards.flatMap(candidate => unreadIn(candidate.condition,
|
|
704
|
+
: decision.guards.flatMap(candidate => unreadIn(candidate.condition, framesFor(implementation.behavior, tag, decision)).map(text => `${decision.id}: ${text}`)));
|
|
754
705
|
}
|
|
755
706
|
function unreadIn(rule, frames) {
|
|
756
707
|
switch (rule.kind) {
|
|
@@ -768,10 +719,13 @@ function unreadIn(rule, frames) {
|
|
|
768
719
|
}
|
|
769
720
|
case "compare": {
|
|
770
721
|
const terms = [rule.left, rule.right].filter(isTerm);
|
|
722
|
+
// Two constants settle without reading anything.
|
|
723
|
+
if (terms.length === 0)
|
|
724
|
+
return [];
|
|
771
725
|
if (terms.some(term => positionData(term) === undefined)) {
|
|
772
726
|
const kinds = differenceOf(rule).parts.map(part => {
|
|
773
727
|
const { frame, keys } = locate(positionTerm(part.path, part.measure), frames);
|
|
774
|
-
return part.measure
|
|
728
|
+
return counts(part.measure) ? "integer" : schemaAt(frame.scope, keys)?.kind;
|
|
775
729
|
});
|
|
776
730
|
return kinds.every(kind => kind === "integer" || kind === "number")
|
|
777
731
|
? []
|
|
@@ -781,7 +735,7 @@ function unreadIn(rule, frames) {
|
|
|
781
735
|
const { frame, keys } = locate(term, frames);
|
|
782
736
|
const schema = schemaAt(frame.scope, keys);
|
|
783
737
|
// The length of an enum is not read: see carrierOf.
|
|
784
|
-
return positionOf(term).measure
|
|
738
|
+
return counts(positionOf(term).measure) ? (schema?.kind === "enum" ? undefined : int()) : schema;
|
|
785
739
|
});
|
|
786
740
|
const sides = schemas.map((schema) => ({
|
|
787
741
|
kind: schema?.kind,
|
|
@@ -803,7 +757,4 @@ function unreadIn(rule, frames) {
|
|
|
803
757
|
}
|
|
804
758
|
}
|
|
805
759
|
}
|
|
806
|
-
function schemaAt(schema, keys) {
|
|
807
|
-
return schemaAtPath(schema, keys);
|
|
808
|
-
}
|
|
809
760
|
//# sourceMappingURL=guard-borders.js.map
|