@mark1russell7/coeval 0.3.1 → 0.3.3
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.map +1 -1
- package/build/index.js +152 -55
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/doc.ts +7 -3
- package/src/evaluate.ts +102 -37
- package/src/formula.ts +12 -5
- package/src/parts.ts +7 -1
- package/src/static.ts +27 -14
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Shape","Part"],"sources":["../src/doc.ts","../src/errors.ts","../src/world.ts","../src/ladder.ts","../src/deref.ts","../src/classify.ts","../src/parts.ts","../src/evaluate.ts","../src/stdlib.ts","../src/order.ts","../src/context.ts","../src/static.ts","../src/formula.ts"],"mappings":";;KACY,mDAAmD;YAAmC,cAAA;;;KAGtF;YAAuC,cAAA;;;KAGvC;;;;;;;;;;;KAYA,4BAA4B;WAAmB;WAAsB,gBAAgB;;;;;;KAMrF;;WAED,MAAM;;WAEN,OAAO;;WAEP;;WAEA,MAAM,SAAS;;;qBAIb;;;;;;;;wBASG,SAAS,iBAAiB,SAAS;;;;;;;;wBAanC,MAAM,QAAQ,YAAY,cAAc;;;;;;;wBAUxC,MAAM,iBAAiB,SAAS;;;;;;;;wBAWhC,UAAU,iBAAiB,SAAS;;;;;;;wBAcpC,SAAS,MAAM,mBAAmB;;;;;;;wBAalC,SAAS,MAAM;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Shape","Part"],"sources":["../src/doc.ts","../src/errors.ts","../src/world.ts","../src/ladder.ts","../src/deref.ts","../src/classify.ts","../src/parts.ts","../src/evaluate.ts","../src/stdlib.ts","../src/order.ts","../src/context.ts","../src/static.ts","../src/formula.ts"],"mappings":";;KACY,mDAAmD;YAAmC,cAAA;;;KAGtF;YAAuC,cAAA;;;KAGvC;;;;;;;;;;;KAYA,4BAA4B;WAAmB;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AS,gBAAqB,OAAM,QAAQ,WAAgB"}
|
package/build/index.js
CHANGED
|
@@ -70,6 +70,7 @@ function typePath(type) {
|
|
|
70
70
|
* @returns The text, for example `git.push`.
|
|
71
71
|
*/
|
|
72
72
|
function typeName(type) {
|
|
73
|
+
if (typeof type === "string") return type;
|
|
73
74
|
return typePath(type)?.join(".") ?? "(computed)";
|
|
74
75
|
}
|
|
75
76
|
function headerFits(value) {
|
|
@@ -88,9 +89,9 @@ function headerFits(value) {
|
|
|
88
89
|
* @returns `true` when the value has the form of an envelope.
|
|
89
90
|
*/
|
|
90
91
|
function isEnvelope(value) {
|
|
91
|
-
if (
|
|
92
|
-
for (const key in value) if (
|
|
93
|
-
return
|
|
92
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
93
|
+
for (const key in value) if (key !== "type" && key !== "value" && key !== "name" && key !== "own" && Object.hasOwn(value, key)) return false;
|
|
94
|
+
return isRecord(value) && headerFits(value);
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* This function reads a stored document: an envelope that also has the keys of a store, for example `{ _id, type,
|
|
@@ -1018,14 +1019,17 @@ var Bad = class {
|
|
|
1018
1019
|
this.at = at;
|
|
1019
1020
|
}
|
|
1020
1021
|
};
|
|
1022
|
+
/** This function sets an own data property. Only the key `__proto__` needs `defineProperty`. */
|
|
1021
1023
|
function setOwn$1(target, key, value) {
|
|
1022
|
-
Object.defineProperty(target, key, {
|
|
1024
|
+
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
1023
1025
|
value,
|
|
1024
1026
|
enumerable: true,
|
|
1025
1027
|
writable: true,
|
|
1026
1028
|
configurable: true
|
|
1027
1029
|
});
|
|
1030
|
+
else target[key] = value;
|
|
1028
1031
|
}
|
|
1032
|
+
const NO_SLOTS = Object.freeze([]);
|
|
1029
1033
|
function hasSlots(template) {
|
|
1030
1034
|
return template.t !== "data";
|
|
1031
1035
|
}
|
|
@@ -1038,6 +1042,12 @@ function hasSlots(template) {
|
|
|
1038
1042
|
* @returns The parts and a way to fill their places, or the reason why the value does not have the shape.
|
|
1039
1043
|
*/
|
|
1040
1044
|
function splitParts(shape, value) {
|
|
1045
|
+
if (shape === void 0 || shape.shape === "none") return {
|
|
1046
|
+
ok: true,
|
|
1047
|
+
parts: NO_SLOTS,
|
|
1048
|
+
data: value,
|
|
1049
|
+
fill: () => value
|
|
1050
|
+
};
|
|
1041
1051
|
const parts = [];
|
|
1042
1052
|
const slot = (item, path, of) => {
|
|
1043
1053
|
parts.push({
|
|
@@ -1551,32 +1561,73 @@ function finish(c, meta, code, run) {
|
|
|
1551
1561
|
run: tracedRun
|
|
1552
1562
|
};
|
|
1553
1563
|
}
|
|
1564
|
+
/**
|
|
1565
|
+
* This function finds the evaluator of the verb `eval` without the record of the rungs, for a compilation without a
|
|
1566
|
+
* trace. It gives the same evaluator as `ask`: the own entry, then the kind, then the default of the world.
|
|
1567
|
+
*/
|
|
1568
|
+
function evaluatorOf(world, envelope, found) {
|
|
1569
|
+
const own = envelope?.own;
|
|
1570
|
+
const ownName = own !== void 0 && Object.hasOwn(own, "eval") ? own["eval"] : void 0;
|
|
1571
|
+
if (ownName !== void 0) return {
|
|
1572
|
+
name: ownName,
|
|
1573
|
+
unknown: false
|
|
1574
|
+
};
|
|
1575
|
+
if (!found.ok) return { unknown: true };
|
|
1576
|
+
const verbs = found.kind.verbs;
|
|
1577
|
+
const name = Object.hasOwn(verbs, "eval") ? verbs["eval"] : Object.hasOwn(world.defaults, "eval") ? world.defaults["eval"] : void 0;
|
|
1578
|
+
return name === void 0 ? { unknown: false } : {
|
|
1579
|
+
name,
|
|
1580
|
+
unknown: false
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
/** The meta of a node of a compilation without a trace. Only a trace reads the meta of a node. */
|
|
1584
|
+
const NO_META = Object.freeze({
|
|
1585
|
+
path: [],
|
|
1586
|
+
doc: {
|
|
1587
|
+
type: "?",
|
|
1588
|
+
value: null
|
|
1589
|
+
},
|
|
1590
|
+
declared: false,
|
|
1591
|
+
answer: NO_ANSWER,
|
|
1592
|
+
side: "derive"
|
|
1593
|
+
});
|
|
1554
1594
|
function compileNode(c, value, place, declared, depth) {
|
|
1555
1595
|
const envelope = isEnvelope(value) ? value : void 0;
|
|
1556
1596
|
const doc = envelope ?? {
|
|
1557
1597
|
type: declared ?? "?",
|
|
1558
1598
|
value
|
|
1559
1599
|
};
|
|
1560
|
-
const meta0 = {
|
|
1600
|
+
const meta0 = c.traced ? {
|
|
1561
1601
|
path: place.map(String),
|
|
1562
1602
|
doc,
|
|
1563
1603
|
declared: envelope === void 0,
|
|
1564
1604
|
answer: NO_ANSWER,
|
|
1565
1605
|
side: "derive"
|
|
1566
|
-
};
|
|
1606
|
+
} : NO_META;
|
|
1567
1607
|
if (envelope === void 0 && declared === void 0) return failing(c, meta0, place, "#PART?", "The value has no envelope, and its position declares no type.");
|
|
1568
1608
|
if (depth > c.maxDepth) return failing(c, meta0, place, "#DEPTH!", `The nesting is deeper than ${c.maxDepth} documents.`);
|
|
1569
|
-
const
|
|
1570
|
-
const found = lookupKind(
|
|
1609
|
+
const world = c.machine.world;
|
|
1610
|
+
const found = lookupKind(world, doc.type);
|
|
1571
1611
|
const kind = found.ok ? found.kind : void 0;
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1612
|
+
let meta = meta0;
|
|
1613
|
+
let name;
|
|
1614
|
+
let unknown;
|
|
1615
|
+
if (c.traced) {
|
|
1616
|
+
const answer = ask(world, envelope ?? {}, "eval", declared === void 0 ? {} : { declaredType: declared });
|
|
1617
|
+
meta = {
|
|
1618
|
+
...meta0,
|
|
1619
|
+
answer,
|
|
1620
|
+
side: kind?.side ?? "derive"
|
|
1621
|
+
};
|
|
1622
|
+
name = answer.evaluator;
|
|
1623
|
+
unknown = answer.error === "unknown-kind";
|
|
1624
|
+
} else {
|
|
1625
|
+
const quick = evaluatorOf(world, envelope, found);
|
|
1626
|
+
name = quick.name;
|
|
1627
|
+
unknown = quick.unknown;
|
|
1628
|
+
}
|
|
1577
1629
|
const kindText = typeName(doc.type);
|
|
1578
|
-
if (
|
|
1579
|
-
const name = answer.evaluator;
|
|
1630
|
+
if (unknown) return failing(c, meta, place, "#KIND?", `The world has no kind ${kindText}.`);
|
|
1580
1631
|
const runners = c.machine.runners ?? {};
|
|
1581
1632
|
const runner = name !== void 0 && Object.hasOwn(runners, name) ? runners[name] : void 0;
|
|
1582
1633
|
const evaluator = name !== void 0 && Object.hasOwn(c.machine.evaluators, name) ? c.machine.evaluators[name] : void 0;
|
|
@@ -1587,12 +1638,18 @@ function compileNode(c, value, place, declared, depth) {
|
|
|
1587
1638
|
return failing(c, meta, place, "#VALUE!", `${split.reason}${at} The kind is ${kindText}.`);
|
|
1588
1639
|
}
|
|
1589
1640
|
const parts = split.parts.map((slot) => {
|
|
1590
|
-
const
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1641
|
+
const item = slot.item;
|
|
1642
|
+
const compiled = compileNode(c, item, place.concat(slot.path), slot.of, depth + 1);
|
|
1643
|
+
const header = typeof item?.name === "string" && isEnvelope(item) ? item.name : void 0;
|
|
1644
|
+
return header === void 0 ? {
|
|
1593
1645
|
key: slot.key,
|
|
1594
1646
|
path: slot.path,
|
|
1595
|
-
|
|
1647
|
+
code: compiled.code,
|
|
1648
|
+
run: compiled.run
|
|
1649
|
+
} : {
|
|
1650
|
+
key: slot.key,
|
|
1651
|
+
path: slot.path,
|
|
1652
|
+
name: header,
|
|
1596
1653
|
code: compiled.code,
|
|
1597
1654
|
run: compiled.run
|
|
1598
1655
|
};
|
|
@@ -1606,32 +1663,48 @@ function compileNode(c, value, place, declared, depth) {
|
|
|
1606
1663
|
parts,
|
|
1607
1664
|
place,
|
|
1608
1665
|
machine: c.machine,
|
|
1609
|
-
fill: (
|
|
1666
|
+
fill: fillOf(split, doc)
|
|
1610
1667
|
};
|
|
1611
|
-
const who = `the evaluator ${name}`;
|
|
1612
1668
|
if (runner !== void 0) {
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1615
|
-
try {
|
|
1616
|
-
return placed(yield* inner(ctx, rt), place);
|
|
1617
|
-
} catch (error) {
|
|
1618
|
-
return placed(thrown(error, `the runner ${name}`), place);
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
const code = (ctx, rt) => rt.running ? fail("#CALC!", `${kindText} waits for effects, and its parent cannot wait. Give the parent a runner.`, { place }) : drive(run(ctx, rt));
|
|
1622
|
-
return finish(c, meta, code, run);
|
|
1669
|
+
const run = placedRun(isCompiledRunner(runner) ? runner.compileRun(input) : interpretRun(runner, input, split.fill), place, name);
|
|
1670
|
+
return finish(c, meta, runnerCode(run, place, kindText), run);
|
|
1623
1671
|
}
|
|
1624
|
-
const
|
|
1625
|
-
|
|
1672
|
+
const code = placedCode(isCompiledEvaluator(evaluator) ? evaluator.compile(input) : interpret(evaluator, input, split.fill), place, name);
|
|
1673
|
+
return finish(c, meta, code, runOf(code));
|
|
1674
|
+
}
|
|
1675
|
+
/** This function gives the code of a document: the code of its evaluator, with the place of each error and of each exception. */
|
|
1676
|
+
function placedCode(inner, place, name) {
|
|
1677
|
+
return (ctx, rt) => {
|
|
1626
1678
|
try {
|
|
1627
1679
|
return placed(inner(ctx, rt), place);
|
|
1628
1680
|
} catch (error) {
|
|
1629
|
-
return placed(thrown(error,
|
|
1681
|
+
return placed(thrown(error, `the evaluator ${name}`), place);
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
/** This function gives the steps of a runner, with the place of each error and of each exception. */
|
|
1686
|
+
function placedRun(inner, place, name) {
|
|
1687
|
+
return function* (ctx, rt) {
|
|
1688
|
+
try {
|
|
1689
|
+
return placed(yield* inner(ctx, rt), place);
|
|
1690
|
+
} catch (error) {
|
|
1691
|
+
return placed(thrown(error, `the runner ${name}`), place);
|
|
1630
1692
|
}
|
|
1631
1693
|
};
|
|
1632
|
-
|
|
1694
|
+
}
|
|
1695
|
+
/** This function gives the code of a runner in an evaluation: its steps, which cannot wait. */
|
|
1696
|
+
function runnerCode(run, place, kindText) {
|
|
1697
|
+
return (ctx, rt) => rt.running ? fail("#CALC!", `${kindText} waits for effects, and its parent cannot wait. Give the parent a runner.`, { place }) : drive(run(ctx, rt));
|
|
1698
|
+
}
|
|
1699
|
+
/** This function gives the steps of a run of an evaluator. The code runs at the first step, and it does not wait. */
|
|
1700
|
+
function runOf(code) {
|
|
1701
|
+
return function* (ctx, rt) {
|
|
1633
1702
|
return code(ctx, rt);
|
|
1634
|
-
}
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
/** This function gives the fill of a compile input: the value with an item in the place of each part. */
|
|
1706
|
+
function fillOf(split, doc) {
|
|
1707
|
+
return (items) => split.parts.length === 0 ? doc.value : split.fill(items);
|
|
1635
1708
|
}
|
|
1636
1709
|
function interpret(fn, input, fill) {
|
|
1637
1710
|
const { kind, typePath, doc, data, place } = input;
|
|
@@ -1725,16 +1798,20 @@ function prepare(machine, doc, options = {}) {
|
|
|
1725
1798
|
code: root.code,
|
|
1726
1799
|
run: root.run
|
|
1727
1800
|
};
|
|
1801
|
+
return planOf(machine, c.traced, compiled);
|
|
1802
|
+
}
|
|
1803
|
+
/** This function makes the object of a plan. Its closures keep only the machine and the compiled root. */
|
|
1804
|
+
function planOf(machine, traced, root) {
|
|
1728
1805
|
return {
|
|
1729
1806
|
machine,
|
|
1730
|
-
traced
|
|
1731
|
-
root
|
|
1732
|
-
evaluate(context = makeContext(), evalOptions
|
|
1733
|
-
const s = new Session(machine, false,
|
|
1807
|
+
traced,
|
|
1808
|
+
root,
|
|
1809
|
+
evaluate(context = makeContext(), evalOptions) {
|
|
1810
|
+
const s = new Session(machine, false, traced, void 0, void 0, evalOptions?.effects);
|
|
1734
1811
|
return root.code(rootContext(machine, context), s);
|
|
1735
1812
|
},
|
|
1736
1813
|
run(context = makeContext(), runOptions = {}) {
|
|
1737
|
-
const s = new Session(machine, true,
|
|
1814
|
+
const s = new Session(machine, true, traced, runOptions.perform, runOptions.signal, void 0);
|
|
1738
1815
|
return driveWaiting(root.run(rootContext(machine, context), s), runOptions.signal);
|
|
1739
1816
|
}
|
|
1740
1817
|
};
|
|
@@ -2727,6 +2804,13 @@ function scopesOf(rules, value, slots) {
|
|
|
2727
2804
|
later
|
|
2728
2805
|
};
|
|
2729
2806
|
}
|
|
2807
|
+
/** The names of a walk without names. A walk does not change a set at any time: it makes a new set to add names. */
|
|
2808
|
+
const NO_NAMES = /* @__PURE__ */ new Set();
|
|
2809
|
+
/** This function gives the options of a walk without the names of the host. */
|
|
2810
|
+
function withoutNames(options) {
|
|
2811
|
+
const { names: _host, ...rest } = options;
|
|
2812
|
+
return rest;
|
|
2813
|
+
}
|
|
2730
2814
|
/**
|
|
2731
2815
|
* This function visits each document of a document: the root and each part at each depth, by the contracts of the
|
|
2732
2816
|
* kinds. A part of a kind that the world does not have is not visited. The walk uses no stack of the host for the
|
|
@@ -2738,14 +2822,15 @@ function scopesOf(rules, value, slots) {
|
|
|
2738
2822
|
* @param options - The type of a bare root value, the names of the host, and a function for the problems.
|
|
2739
2823
|
*/
|
|
2740
2824
|
function walk(world, doc, visit, options = {}) {
|
|
2825
|
+
const names = options.names === void 0 || options.names.length === 0 ? NO_NAMES : new Set(options.names);
|
|
2741
2826
|
const stack = [{
|
|
2742
2827
|
value: doc,
|
|
2743
2828
|
place: [],
|
|
2744
2829
|
at: [],
|
|
2745
2830
|
declared: options.declaredType,
|
|
2746
2831
|
depth: 0,
|
|
2747
|
-
names
|
|
2748
|
-
later:
|
|
2832
|
+
names,
|
|
2833
|
+
later: NO_NAMES
|
|
2749
2834
|
}];
|
|
2750
2835
|
while (stack.length > 0) {
|
|
2751
2836
|
const item = stack.pop();
|
|
@@ -2765,15 +2850,21 @@ function walk(world, doc, visit, options = {}) {
|
|
|
2765
2850
|
};
|
|
2766
2851
|
const found = lookupKind(world, doc.type);
|
|
2767
2852
|
const kind = found.ok ? found.kind : void 0;
|
|
2768
|
-
if (visit({
|
|
2853
|
+
if (visit(kind === void 0 ? {
|
|
2769
2854
|
place: item.place,
|
|
2770
2855
|
at: item.at,
|
|
2771
2856
|
doc,
|
|
2772
2857
|
declared: envelope === void 0,
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2858
|
+
depth: item.depth,
|
|
2859
|
+
names: item.names,
|
|
2860
|
+
later: item.later
|
|
2861
|
+
} : {
|
|
2862
|
+
place: item.place,
|
|
2863
|
+
at: item.at,
|
|
2864
|
+
doc,
|
|
2865
|
+
declared: envelope === void 0,
|
|
2866
|
+
kind,
|
|
2867
|
+
typePath: found.ok ? found.path : [],
|
|
2777
2868
|
depth: item.depth,
|
|
2778
2869
|
names: item.names,
|
|
2779
2870
|
later: item.later
|
|
@@ -2819,7 +2910,6 @@ function walk(world, doc, visit, options = {}) {
|
|
|
2819
2910
|
*/
|
|
2820
2911
|
function refsOf(world, doc, options = {}) {
|
|
2821
2912
|
const out = [];
|
|
2822
|
-
const { names: _host, ...rest } = options;
|
|
2823
2913
|
walk(world, doc, (v) => {
|
|
2824
2914
|
if (!isRef(v.doc)) return void 0;
|
|
2825
2915
|
const path = v.doc.value;
|
|
@@ -2834,7 +2924,7 @@ function refsOf(world, doc, options = {}) {
|
|
|
2834
2924
|
free: !bound
|
|
2835
2925
|
});
|
|
2836
2926
|
return "skip";
|
|
2837
|
-
},
|
|
2927
|
+
}, options.names === void 0 ? options : withoutNames(options));
|
|
2838
2928
|
return out;
|
|
2839
2929
|
}
|
|
2840
2930
|
function setAt(value, path, next) {
|
|
@@ -3021,13 +3111,18 @@ function jsTruthy(value) {
|
|
|
3021
3111
|
function strictTruthy(value) {
|
|
3022
3112
|
return typeof value === "boolean" ? value : void 0;
|
|
3023
3113
|
}
|
|
3114
|
+
/**
|
|
3115
|
+
* This function sets an own data property. Only the key `__proto__` needs `defineProperty`: an assignment to it
|
|
3116
|
+
* changes the prototype. An assignment is faster for each other key of a new plain object.
|
|
3117
|
+
*/
|
|
3024
3118
|
function setOwn(target, key, value) {
|
|
3025
|
-
Object.defineProperty(target, key, {
|
|
3119
|
+
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
3026
3120
|
value,
|
|
3027
3121
|
enumerable: true,
|
|
3028
3122
|
writable: true,
|
|
3029
3123
|
configurable: true
|
|
3030
3124
|
});
|
|
3125
|
+
else target[key] = value;
|
|
3031
3126
|
}
|
|
3032
3127
|
function compiled(compile) {
|
|
3033
3128
|
return { compile };
|
|
@@ -3210,16 +3305,18 @@ function formulaEvaluators(profile = {}) {
|
|
|
3210
3305
|
};
|
|
3211
3306
|
}),
|
|
3212
3307
|
"formula.record": compiled(({ value }) => {
|
|
3213
|
-
const fields =
|
|
3308
|
+
const fields = partsOf(value);
|
|
3309
|
+
const keys = Object.keys(fields);
|
|
3310
|
+
const codes = keys.map((key) => fields[key].code);
|
|
3214
3311
|
return (ctx, rt) => {
|
|
3215
3312
|
const out = {};
|
|
3216
|
-
for (
|
|
3217
|
-
const result =
|
|
3313
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
3314
|
+
const result = codes[index](ctx, rt);
|
|
3218
3315
|
if (!result.ok) {
|
|
3219
3316
|
if (omit !== void 0 && omit(result.error)) continue;
|
|
3220
3317
|
return result;
|
|
3221
3318
|
}
|
|
3222
|
-
setOwn(out,
|
|
3319
|
+
setOwn(out, keys[index], result.value);
|
|
3223
3320
|
}
|
|
3224
3321
|
return ok(out);
|
|
3225
3322
|
};
|