@northtalk/ts 0.6.0 → 0.8.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/{binary-value-C4ZiXVjv.d.ts → binary-value-B93hEK7l.d.ts} +1 -1
- package/{checker-CUhn2XaM.js → checker-Q4w7rLXk.js} +600 -85
- package/{core-egHbNmve.d.ts → core-BBPI6EhG.d.ts} +1 -1
- package/{debug--Of4MSLw.d.ts → debug-s6QIovKS.d.ts} +142 -10
- package/debug.d.ts +1 -1
- package/debug.js +1 -1
- package/{driver-BIm1mL77.d.ts → driver-D5yrK3Nu.d.ts} +1 -1
- package/driver.d.ts +1 -1
- package/driver.js +1 -1
- package/encoding-B7MCQ4ii.js +338 -0
- package/{engine-DbDcopGM.d.ts → engine-Dy-BCoiw.d.ts} +2 -2
- package/{engine-CXf5FCwi.js → engine-OL1BveVZ.js} +6 -6
- package/{errors-D11zizZg.js → errors-VuwK669R.js} +157 -23
- package/{group-BpzTo0k4.js → group-Ccuqwq12.js} +477 -110
- package/{http-fetch-DFwVIOQg.js → http-fetch--O27xjSW.js} +2 -2
- package/http.d.ts +1 -1
- package/http.js +4 -4
- package/index.d.ts +6 -6
- package/index.js +15 -14
- package/{inline-grants-XbX9HL_w.js → inline-grants-DmOdgSoK.js} +4 -5
- package/{lean-aCvN6y52.js → lean-BjhQvHyr.js} +13 -8
- package/{lean-DiS9rUcn.d.ts → lean-D6DQfbqH.d.ts} +42 -7
- package/lean.d.ts +6 -6
- package/lean.js +15 -14
- package/{manifest-CCfpn0kC.js → manifest-BeViDIoy.js} +4 -3
- package/{manifest-mpivREn-.d.ts → manifest-l07K7nW-.d.ts} +4 -2
- package/message-layer.d.ts +2 -2
- package/message-layer.js +2 -2
- package/notify.d.ts +1 -1
- package/notify.js +1 -1
- package/{objects-DmUc0lha.js → objects-TarIKBL8.js} +1 -1
- package/{objects-DYq_YvaQ.d.ts → objects-q0lnCK-4.d.ts} +8 -3
- package/{operations-DnCcztkZ.js → operations-BAELnqwf.js} +133 -58
- package/package.json +5 -1
- package/peer-capability-B8eKbljR.js +151 -0
- package/peer.d.ts +180 -0
- package/peer.js +559 -0
- package/{readers-8WCimMop.d.ts → readers-AeB1bJ--.d.ts} +1 -1
- package/{readers-CsvlahLi.js → readers-BG8g59qS.js} +1 -1
- package/{request-pump-binary-oqjWFqZA.js → request-pump-binary-87klb6sX.js} +9 -4
- package/{router-BZ-aYeXA.js → router-DXmPA-qi.js} +4 -4
- package/{router-BQsO8aPV.d.ts → router-DXoJ_2Z4.d.ts} +2 -2
- package/session.d.ts +2 -2
- package/session.js +64 -16
- package/setup.d.ts +3 -2
- package/setup.js +14 -16
- package/sqlite.d.ts +2 -2
- package/sqlite.js +5 -5
- package/{store-DHlo6fP5.js → store-DzpyWjt2.js} +2 -2
- package/store-capability-CxQJ_Huz.js +187 -0
- package/store.d.ts +2 -2
- package/store.js +2 -2
- package/{user-capability-BcRQyyEw.js → user-capability-ClYd8Vln.js} +3 -4
- package/wasm.d.ts +13 -6
- package/wasm.js +47 -19
- package/encoding-RUuES_e4.js +0 -99
- package/store-capability-BrUUAwVS.js +0 -389
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import { a as rebindObject, i as propertyChecks, n as makeObject, o as stateOf$1, r as objectKind } from "./objects-
|
|
4
|
-
import {
|
|
5
|
-
import { _ as viewSource, d as operationUses, g as checkDecisionCalls, n as checkSourceForLoad, t as checkSource, u as checkEffectCall } from "./checker-
|
|
6
|
-
import { a as operationsOf, c as CallMeter, r as grantData, s as invoke, t as canonicalJSON } from "./manifest-
|
|
2
|
+
import { $ as smallCoefficient, Dt as integerOf, H as num, Ht as civilFromFields, J as range, Jt as isInstant, K as quantity, L as map, O as instantOf$1, Ot as isInteger, P as listValues, R as mapLayout, S as displayText, T as functionsBelongTo, V as nothing, X as requireArgs, Z as requireValue, _ as civilOf, a as hostDetail, b as dec, d as bytes, f as bytesOf, ft as parseUnit, gn as libraryExports, h as canonicalNumber, hn as grammar, i as ScriptError, it as text, l as Value, mn as diagnosticCodes, n as LoadError, pn as builtins, q as quantityOf, qt as formatInstant, r as MailboxFull, s as sendFailed, t as HostError, tt as smallExponent, u as bool, w as functionValue, x as decimalParts, z as mapOfLayout } from "./errors-VuwK669R.js";
|
|
3
|
+
import { a as rebindObject, i as propertyChecks, n as makeObject, o as stateOf$1, r as objectKind } from "./objects-TarIKBL8.js";
|
|
4
|
+
import { $ as arityOf, A as musicalCount, At as validMessageSelector, B as splice, C as isKind, D as matchCaptures, E as makeRange, F as randomBound, G as cacheBuild, H as textForm, I as search, J as keysContents, K as charge, L as setKey, M as outOfRange, N as prepareConversion, O as matchesOf, Ot as shapeDiagnostics, P as property, Pt as runTask, Q as sizeOf, R as smallArithmetic, S as isEmpty, St as diagnosticRecord, T as makePatternValue, Tt as mismatch, U as waitUs, V as subjectText, W as wrongKind, X as rateOf, Y as partSize, Z as resetMeasured, _ as deleteKey, _t as acceptsArgumentCount, a as builtin, at as numberText, b as hasKey, c as canConvert, ct as splicesOf, d as chunkSet, dt as costModel, f as chunkThere, ft as errorMessages, g as decodeUtf8, h as convert, ht as reservedErrorKeys, i as arithmetic, it as capturesOf, j as negated, k as member, kt as validComputedMessageName, l as chunkDelete, lt as textDisplay, m as concat, mt as limitDefaults, n as ScriptError$1, nt as instructionSpec, o as builtinDefaults, ot as patternSource, p as comparison, pt as languageVersion, q as fixedRates, r as appendTo, rt as opcodes, s as byteOf, st as quantityText, t as NotImplementedError, tt as functionHead, u as chunkGet, ut as compareText, v as equals, w as keyText, x as integerValue, y as getKey, yt as decodeShape, z as smallCoefficientOf } from "./operations-BAELnqwf.js";
|
|
5
|
+
import { _ as viewSource, d as operationUses, g as checkDecisionCalls, n as checkSourceForLoad, t as checkSource, u as checkEffectCall } from "./checker-Q4w7rLXk.js";
|
|
6
|
+
import { a as operationsOf, c as CallMeter, r as grantData, s as invoke, t as canonicalJSON } from "./manifest-BeViDIoy.js";
|
|
7
7
|
import { n as trackOperation } from "./operation-promises-ClA1BTaS.js";
|
|
8
|
-
import { c as readDisplay } from "./readers-
|
|
9
|
-
import {
|
|
8
|
+
import { c as readDisplay } from "./readers-BG8g59qS.js";
|
|
9
|
+
import { l as isMusicalClock, p as standardChecks, r as MUSICAL_CLOCK } from "./encoding-B7MCQ4ii.js";
|
|
10
|
+
import { r as PEER_POST, t as PEER_CALL } from "./peer-capability-B8eKbljR.js";
|
|
10
11
|
import { n as sha256, r as sha256Bytes, t as Sha256 } from "./sha256-9CGf5BS_.js";
|
|
11
12
|
//#region src/stdlib-registry.ts
|
|
12
13
|
/** The seven stdlib Library names, which a Host may not register. */
|
|
@@ -466,6 +467,10 @@ var UnitLowering = class {
|
|
|
466
467
|
for (const body of this.bodies) {
|
|
467
468
|
body.start = code.length;
|
|
468
469
|
if (body.acceptedAt !== void 0) body.acceptedAt += body.start;
|
|
470
|
+
if (body.tests) {
|
|
471
|
+
body.tests.guardAt += body.start;
|
|
472
|
+
for (const shape of body.tests.shapes) shape.at += body.start;
|
|
473
|
+
}
|
|
469
474
|
for (const ins of this.code.get(body.index) ?? []) {
|
|
470
475
|
const opcode = opcodes.get(ins.op);
|
|
471
476
|
if (opcode === void 0) throw new Error(`\`${ins.op}\` isn't an instruction`);
|
|
@@ -617,6 +622,21 @@ var BodyLowering = class BodyLowering {
|
|
|
617
622
|
if (this.isIt(binding)) return this.whoseIt.at(-1) ?? 0;
|
|
618
623
|
return this.overrides.get(binding) ?? this.slots.get(binding);
|
|
619
624
|
}
|
|
625
|
+
namedShape(name) {
|
|
626
|
+
const binding = this.u.scopes[0].bindings.find((b) => b.name === name && b.shape);
|
|
627
|
+
return binding ? {
|
|
628
|
+
kind: "name",
|
|
629
|
+
role: "value",
|
|
630
|
+
text: name,
|
|
631
|
+
binding,
|
|
632
|
+
span: binding.span ?? {
|
|
633
|
+
line: 0,
|
|
634
|
+
col: 0,
|
|
635
|
+
start: 0,
|
|
636
|
+
end: 0
|
|
637
|
+
}
|
|
638
|
+
} : void 0;
|
|
639
|
+
}
|
|
620
640
|
load(name, at) {
|
|
621
641
|
const binding = name.binding;
|
|
622
642
|
const slot = this.slotOf(binding);
|
|
@@ -683,7 +703,7 @@ var BodyLowering = class BodyLowering {
|
|
|
683
703
|
const args = this.layout(params, [], this.scopeLocals());
|
|
684
704
|
if (decl.during?.binding) this.body.duringSlot = this.slots.get(decl.during.binding);
|
|
685
705
|
const failed = this.label();
|
|
686
|
-
yield this.guarded(failed, this.parameters(params, args, decl.guard, failed));
|
|
706
|
+
yield this.guarded(failed, this.parameters(params, args, decl.guard, failed, decl.shapes));
|
|
687
707
|
this.body.acceptedAt = this.code.length;
|
|
688
708
|
yield decl.finally ? this.tryStatement({
|
|
689
709
|
k: "try",
|
|
@@ -698,8 +718,29 @@ var BodyLowering = class BodyLowering {
|
|
|
698
718
|
this.emit(decl.end, "clause-fail");
|
|
699
719
|
this.finish();
|
|
700
720
|
}
|
|
701
|
-
*parameters(params, args, guard, failed) {
|
|
721
|
+
*parameters(params, args, guard, failed, shapes = []) {
|
|
702
722
|
for (const [i, p] of params.entries()) if (p.k !== "bind") yield this.pattern(p, args[i], failed, null, false);
|
|
723
|
+
const tests = {
|
|
724
|
+
guardAt: 0,
|
|
725
|
+
shapes: []
|
|
726
|
+
};
|
|
727
|
+
for (const [i, s] of shapes.entries()) if (s) {
|
|
728
|
+
const shape = this.namedShape(s.kind);
|
|
729
|
+
const definition = shape && this.u.definitionOf.get(shape.binding);
|
|
730
|
+
tests.shapes.push({
|
|
731
|
+
arg: i,
|
|
732
|
+
at: this.code.length,
|
|
733
|
+
...shape ? definition === void 0 ? {} : { definition } : { kind: s.kind }
|
|
734
|
+
});
|
|
735
|
+
this.emit(s.pos, "load", args[i]);
|
|
736
|
+
if (shape) {
|
|
737
|
+
this.load(shape, s.pos);
|
|
738
|
+
this.emit(s.pos, "call-builtin", "conforms", 2);
|
|
739
|
+
} else this.emit(s.pos, "is-kind", s.kind);
|
|
740
|
+
this.emit(s.pos, "branch-false", failed);
|
|
741
|
+
}
|
|
742
|
+
tests.guardAt = this.code.length;
|
|
743
|
+
if (this.body.kind === "handler" || this.body.kind === "fallback") this.body.tests = tests;
|
|
703
744
|
if (guard) yield this.guard(guard, failed);
|
|
704
745
|
}
|
|
705
746
|
*guard(guard, failed) {
|
|
@@ -1791,7 +1832,10 @@ var BodyLowering = class BodyLowering {
|
|
|
1791
1832
|
case "is-kind":
|
|
1792
1833
|
case "is-empty":
|
|
1793
1834
|
yield this.expr(e.l);
|
|
1794
|
-
if (e.k === "is-kind"
|
|
1835
|
+
if (e.k === "is-kind" && this.namedShape(e.kind)) {
|
|
1836
|
+
this.load(this.namedShape(e.kind), at);
|
|
1837
|
+
this.emit(at, "call-builtin", "conforms", 2);
|
|
1838
|
+
} else if (e.k === "is-kind") this.emit(at, "is-kind", e.kind);
|
|
1795
1839
|
else this.emit(at, "is-empty");
|
|
1796
1840
|
e.neg && this.emit(at, "not");
|
|
1797
1841
|
return;
|
|
@@ -2085,22 +2129,46 @@ const eventReads = (event, guard) => {
|
|
|
2085
2129
|
}
|
|
2086
2130
|
return out.sort((a, b) => a.start - b.start).map((entry) => entry.name);
|
|
2087
2131
|
};
|
|
2088
|
-
|
|
2132
|
+
const isTokenText = (element, text) => element?.kind === "token" && element.text === text;
|
|
2133
|
+
const declaredName = (element) => {
|
|
2134
|
+
while (element?.kind === "node") element = element.children[0];
|
|
2135
|
+
return element.text;
|
|
2136
|
+
};
|
|
2137
|
+
/**
|
|
2138
|
+
* A checked Library's exports, for the Scripts and Libraries that import it.
|
|
2139
|
+
* It reads only declaration headers, so it never converts a body.
|
|
2140
|
+
*/
|
|
2089
2141
|
const exportsOf = (tree) => {
|
|
2090
2142
|
const out = {};
|
|
2091
|
-
for (const
|
|
2092
|
-
if (
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2143
|
+
for (const child of tree.root.children) {
|
|
2144
|
+
if (child.kind !== "node" || isTokenText(child.children[0], "private")) continue;
|
|
2145
|
+
const first = child.children[0];
|
|
2146
|
+
const decl = child.rule === "Declaration" && first?.kind === "node" ? first : child;
|
|
2147
|
+
if (decl.rule === "Function") {
|
|
2148
|
+
let required = 0;
|
|
2149
|
+
let total = 0;
|
|
2150
|
+
for (const part of decl.children.slice(2)) if (part.kind === "node" && part.rule === "Parameter") {
|
|
2151
|
+
total++;
|
|
2152
|
+
required += part.children[2] ? 0 : 1;
|
|
2153
|
+
} else if (part.kind === "node" && part.rule === "Block" || isTokenText(part, "end")) break;
|
|
2154
|
+
out[declaredName(decl.children[1])] = {
|
|
2155
|
+
kind: "function",
|
|
2156
|
+
contract: {
|
|
2157
|
+
required,
|
|
2158
|
+
total
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
} else if (decl.rule === "Handler") {
|
|
2162
|
+
if (isTokenText(decl.children[1], "any")) continue;
|
|
2163
|
+
const name = declaredName(decl.children[1]);
|
|
2164
|
+
out[name] = {
|
|
2165
|
+
kind: "handler",
|
|
2166
|
+
maySuspend: tree.maySuspend?.includes(name) ?? false
|
|
2167
|
+
};
|
|
2168
|
+
} else if (decl.rule === "Declaration" && (isTokenText(first, "constant") || isTokenText(first, "shape"))) out[declaredName(decl.children[1])] = {
|
|
2169
|
+
kind: "constant",
|
|
2170
|
+
...isTokenText(first, "shape") ? { shape: true } : {}
|
|
2099
2171
|
};
|
|
2100
|
-
else out[decl.k === "handler" ? decl.name : decl.name.text] = decl.k === "handler" ? {
|
|
2101
|
-
kind: decl.k,
|
|
2102
|
-
maySuspend: tree.maySuspend?.includes(decl.name) ?? false
|
|
2103
|
-
} : { kind: decl.k };
|
|
2104
2172
|
}
|
|
2105
2173
|
return out;
|
|
2106
2174
|
};
|
|
@@ -2528,15 +2596,11 @@ var Waits = class {
|
|
|
2528
2596
|
}
|
|
2529
2597
|
/** Waits on a call or reply, as a Run's own Wait or a Join Member's. */
|
|
2530
2598
|
add(id, s, running, timer, join) {
|
|
2531
|
-
this.pending.set(id,
|
|
2599
|
+
this.pending.set(id, {
|
|
2532
2600
|
s,
|
|
2533
2601
|
running,
|
|
2534
|
-
timer,
|
|
2535
|
-
join
|
|
2536
|
-
} : {
|
|
2537
|
-
s,
|
|
2538
|
-
running,
|
|
2539
|
-
timer
|
|
2602
|
+
...timer ? { timer } : {},
|
|
2603
|
+
...join ? { join } : {}
|
|
2540
2604
|
});
|
|
2541
2605
|
}
|
|
2542
2606
|
has(id) {
|
|
@@ -2553,7 +2617,8 @@ var Waits = class {
|
|
|
2553
2617
|
cut(members, reason) {
|
|
2554
2618
|
const cut = this.pendingMembers(members);
|
|
2555
2619
|
for (const m of cut) {
|
|
2556
|
-
this.pending.get(m.id).timer
|
|
2620
|
+
const t = this.pending.get(m.id).timer;
|
|
2621
|
+
if (t) t.live = false;
|
|
2557
2622
|
this.pending.delete(m.id);
|
|
2558
2623
|
abandon(m.abort, reason);
|
|
2559
2624
|
}
|
|
@@ -2571,7 +2636,7 @@ var Waits = class {
|
|
|
2571
2636
|
return { k: "late" };
|
|
2572
2637
|
}
|
|
2573
2638
|
this.pending.delete(id);
|
|
2574
|
-
p.timer.live = false;
|
|
2639
|
+
if (p.timer) p.timer.live = false;
|
|
2575
2640
|
const { s, running } = p;
|
|
2576
2641
|
if (!p.join) return {
|
|
2577
2642
|
k: "ready",
|
|
@@ -3089,7 +3154,7 @@ const iteratorOver = (v) => {
|
|
|
3089
3154
|
};
|
|
3090
3155
|
const isValue = (item) => Value.isValue(item);
|
|
3091
3156
|
const isBoolean = (item) => isValue(item) && item.kind === "boolean";
|
|
3092
|
-
const
|
|
3157
|
+
const decimalAt = (item) => isValue(item) ? item.asDecimal() : void 0;
|
|
3093
3158
|
const drop = (stack, n) => {
|
|
3094
3159
|
for (let i = 0; i < n; i++) stack.pop();
|
|
3095
3160
|
};
|
|
@@ -3109,7 +3174,7 @@ const fixedCharges = fixedRates();
|
|
|
3109
3174
|
const compareCharges = [];
|
|
3110
3175
|
const numberCharges = [];
|
|
3111
3176
|
const numberCharge = (rate, result) => {
|
|
3112
|
-
const n = Math.abs(
|
|
3177
|
+
const n = Math.abs(smallCoefficientOf(result));
|
|
3113
3178
|
let digits = 1;
|
|
3114
3179
|
for (let ten = 10; n >= ten; ten *= 10) digits++;
|
|
3115
3180
|
return (numberCharges[rate] ??= [])[digits] ??= charge(rate, { result });
|
|
@@ -3327,6 +3392,15 @@ var Run = class Run {
|
|
|
3327
3392
|
clause = 0;
|
|
3328
3393
|
/** Its entry dispatch reached the Fallback Handler's clauses (ADR 0064). */
|
|
3329
3394
|
viaFallback = false;
|
|
3395
|
+
/**
|
|
3396
|
+
* Why dispatch skipped each named clause of the entry Delivery, for the
|
|
3397
|
+
* Trace's `mismatches` (ADR 0172). Tooling-only, never saved or charged.
|
|
3398
|
+
*/
|
|
3399
|
+
mismatches = [];
|
|
3400
|
+
stepFrame = null;
|
|
3401
|
+
stepPc = -1;
|
|
3402
|
+
priorFrame = null;
|
|
3403
|
+
priorPc = -1;
|
|
3330
3404
|
during = nothing;
|
|
3331
3405
|
/** Its Fuel when its cancellation cleanup began, if it has been cancelled. */
|
|
3332
3406
|
cleanupFrom = null;
|
|
@@ -4001,7 +4075,12 @@ var Run = class Run {
|
|
|
4001
4075
|
for (;;) {
|
|
4002
4076
|
while (d.next < d.clauses.length) {
|
|
4003
4077
|
const body = d.clauses[d.next++];
|
|
4004
|
-
if (body.params.length
|
|
4078
|
+
if (body.params.length !== d.args.length) {
|
|
4079
|
+
if (!this.frames.length && !this.viaFallback) this.mismatches.push({
|
|
4080
|
+
clause: body.clause ?? 0,
|
|
4081
|
+
reason: "arity"
|
|
4082
|
+
});
|
|
4083
|
+
} else {
|
|
4005
4084
|
if (!this.frames.length) this.clause = body.clause ?? 0;
|
|
4006
4085
|
this.push(d.code, body, d.args, d);
|
|
4007
4086
|
return true;
|
|
@@ -4016,6 +4095,29 @@ var Run = class Run {
|
|
|
4016
4095
|
this.viaFallback = true;
|
|
4017
4096
|
}
|
|
4018
4097
|
}
|
|
4098
|
+
mismatchOf(frame) {
|
|
4099
|
+
const clause = frame.body.clause ?? 0;
|
|
4100
|
+
const tests = frame.body.tests;
|
|
4101
|
+
const pc = this.priorFrame === frame ? this.priorPc : null;
|
|
4102
|
+
if (!tests || pc === null || pc >= tests.guardAt) return {
|
|
4103
|
+
clause,
|
|
4104
|
+
reason: "guard"
|
|
4105
|
+
};
|
|
4106
|
+
let shape;
|
|
4107
|
+
for (const s of tests.shapes) if (s.at <= pc) shape = s;
|
|
4108
|
+
if (!shape) return {
|
|
4109
|
+
clause,
|
|
4110
|
+
reason: "pattern"
|
|
4111
|
+
};
|
|
4112
|
+
const definition = shape.definition === void 0 ? void 0 : frame.code.definitions[shape.definition];
|
|
4113
|
+
return {
|
|
4114
|
+
clause,
|
|
4115
|
+
reason: "shape",
|
|
4116
|
+
argument: shape.arg + 1,
|
|
4117
|
+
value: frame.dispatch.args[shape.arg],
|
|
4118
|
+
shape: shape.kind !== void 0 ? text(shape.kind) : definition && homeConstant(definition, this.script.home ?? this.script)
|
|
4119
|
+
};
|
|
4120
|
+
}
|
|
4019
4121
|
/** Whether a dispatch has a clause left to try after the current one. */
|
|
4020
4122
|
static more(d) {
|
|
4021
4123
|
return !!d && (!!d.fallback?.clauses.length || d.clauses.slice(d.next).some((b) => b.params.length === d.args.length));
|
|
@@ -4135,6 +4237,10 @@ var Run = class Run {
|
|
|
4135
4237
|
const frame = this.frame;
|
|
4136
4238
|
const ins = frame.code.unit.code[frame.pc];
|
|
4137
4239
|
const rate = ins.rate;
|
|
4240
|
+
this.priorFrame = this.stepFrame;
|
|
4241
|
+
this.priorPc = this.stepPc;
|
|
4242
|
+
this.stepFrame = frame;
|
|
4243
|
+
this.stepPc = frame.pc;
|
|
4138
4244
|
const m = this.m;
|
|
4139
4245
|
resetMeasured(m);
|
|
4140
4246
|
const resumption = this.resumption;
|
|
@@ -4200,7 +4306,9 @@ var Run = class Run {
|
|
|
4200
4306
|
fastSteps(room) {
|
|
4201
4307
|
if (!fastPath.enabled || !this.charging || this.cancelling || this.resumption || this.entryError || this.suspended || this.outcome || !this.frames.length) return;
|
|
4202
4308
|
let frame = this.frame;
|
|
4203
|
-
if (frame.restricted || frame.clauseCharge) return;
|
|
4309
|
+
if (frame.restricted || frame.clauseCharge && frame === this.frames[0]) return;
|
|
4310
|
+
const clauseFuel = fixedCharges[CLAUSE].fuel;
|
|
4311
|
+
let clause = frame.clauseCharge ? clauseFuel : 0;
|
|
4204
4312
|
let { locals, stack, code } = frame;
|
|
4205
4313
|
let instructions = code.unit.code;
|
|
4206
4314
|
const m = this.m;
|
|
@@ -4239,9 +4347,12 @@ var Run = class Run {
|
|
|
4239
4347
|
case 34:
|
|
4240
4348
|
case 29:
|
|
4241
4349
|
case 30: {
|
|
4242
|
-
const
|
|
4243
|
-
const
|
|
4244
|
-
if (
|
|
4350
|
+
const left = decimalAt(stack.at(-2));
|
|
4351
|
+
const right = decimalAt(stack.at(-1));
|
|
4352
|
+
if (!left || !right) break;
|
|
4353
|
+
const x = smallCoefficient(left);
|
|
4354
|
+
const y = smallCoefficient(right);
|
|
4355
|
+
if (Number.isNaN(x) || Number.isNaN(y) || smallExponent(left) !== smallExponent(right)) break;
|
|
4245
4356
|
cost = compareCharges[ins.rate] ??= charge(ins.rate, {
|
|
4246
4357
|
result: bool(true),
|
|
4247
4358
|
scanned: 0
|
|
@@ -4249,7 +4360,7 @@ var Run = class Run {
|
|
|
4249
4360
|
const holds = ordered(opcode, x, y);
|
|
4250
4361
|
const following = instructions[pc + 1];
|
|
4251
4362
|
const branch = fixedCharges[following.rate];
|
|
4252
|
-
if ((following.opcode === 15 || following.opcode === 16) && branch && fuel + cost.fuel < end && fuel + cost.fuel + branch.fuel <= fuelLimit && alloc + cost.alloc + branch.alloc <= allocLimit) {
|
|
4363
|
+
if ((following.opcode === 15 || following.opcode === 16) && branch && clause === 0 && fuel + cost.fuel < end && fuel + cost.fuel + branch.fuel <= fuelLimit && alloc + cost.alloc + branch.alloc <= allocLimit) {
|
|
4253
4364
|
fuel += cost.fuel + branch.fuel;
|
|
4254
4365
|
alloc += cost.alloc + branch.alloc;
|
|
4255
4366
|
drop(stack, 2);
|
|
@@ -4279,6 +4390,12 @@ var Run = class Run {
|
|
|
4279
4390
|
if (isValue(receiver) && receiver.kind === "map") cost = fixedCharges[ins.rate];
|
|
4280
4391
|
break;
|
|
4281
4392
|
}
|
|
4393
|
+
case 63:
|
|
4394
|
+
cost = this.fastSetKeyCharge(ins, stack);
|
|
4395
|
+
break;
|
|
4396
|
+
case 91:
|
|
4397
|
+
cost = this.fastCallHandlerCharge(ins, code);
|
|
4398
|
+
break;
|
|
4282
4399
|
case 67: {
|
|
4283
4400
|
const current = stack.at(-2);
|
|
4284
4401
|
const input = stack.at(-1);
|
|
@@ -4299,11 +4416,20 @@ var Run = class Run {
|
|
|
4299
4416
|
break;
|
|
4300
4417
|
case 19:
|
|
4301
4418
|
case 20:
|
|
4302
|
-
case 21:
|
|
4303
|
-
|
|
4419
|
+
case 21: {
|
|
4420
|
+
const left = decimalAt(stack.at(-2));
|
|
4421
|
+
const right = decimalAt(stack.at(-1));
|
|
4422
|
+
result = left && right ? smallArithmetic(ins.op, smallCoefficient(left), smallExponent(left), smallCoefficient(right), smallExponent(right)) : void 0;
|
|
4304
4423
|
if (result) cost = numberCharge(ins.rate, result);
|
|
4424
|
+
break;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
if (!cost || fuel + clause + cost.fuel > fuelLimit || alloc + cost.alloc > allocLimit) break;
|
|
4428
|
+
if (clause !== 0) {
|
|
4429
|
+
frame.clauseCharge = false;
|
|
4430
|
+
fuel += clause;
|
|
4431
|
+
clause = 0;
|
|
4305
4432
|
}
|
|
4306
|
-
if (!cost || fuel + cost.fuel > fuelLimit || alloc + cost.alloc > allocLimit) break;
|
|
4307
4433
|
fuel += cost.fuel;
|
|
4308
4434
|
alloc += cost.alloc;
|
|
4309
4435
|
const [a, b] = ins.operands;
|
|
@@ -4349,10 +4475,16 @@ var Run = class Run {
|
|
|
4349
4475
|
case 44:
|
|
4350
4476
|
stack[stack.length - 1] = stack.at(-1).get(a);
|
|
4351
4477
|
break;
|
|
4478
|
+
case 63:
|
|
4479
|
+
stack.pop();
|
|
4480
|
+
stack[stack.length - 1] = this.m.result;
|
|
4481
|
+
break;
|
|
4352
4482
|
case 89:
|
|
4483
|
+
case 91:
|
|
4353
4484
|
case 97:
|
|
4354
4485
|
frame.pc = pc;
|
|
4355
|
-
if (opcode ===
|
|
4486
|
+
if (opcode === 91) this.fastCallHandler(code, a, b);
|
|
4487
|
+
else if (opcode === 89) {
|
|
4356
4488
|
const body = code.unit.bodies[a];
|
|
4357
4489
|
const args = stack.slice(stack.length - b);
|
|
4358
4490
|
this.push(code, body, this.fillDefaults(code, body, args), null);
|
|
@@ -4368,6 +4500,7 @@ var Run = class Run {
|
|
|
4368
4500
|
({locals, stack, code} = frame);
|
|
4369
4501
|
instructions = code.unit.code;
|
|
4370
4502
|
pc = frame.pc;
|
|
4503
|
+
clause = frame.clauseCharge ? clauseFuel : 0;
|
|
4371
4504
|
continue;
|
|
4372
4505
|
default:
|
|
4373
4506
|
stack.pop();
|
|
@@ -4380,6 +4513,39 @@ var Run = class Run {
|
|
|
4380
4513
|
this.alloc = alloc;
|
|
4381
4514
|
}
|
|
4382
4515
|
/**
|
|
4516
|
+
* `fastSteps`' charge for writing a key its Map already has, with the new
|
|
4517
|
+
* Map version left as the measured result; or nothing, for `step`. The
|
|
4518
|
+
* entry count doesn't change, so the result's charge is the Map's.
|
|
4519
|
+
*/
|
|
4520
|
+
fastSetKeyCharge(ins, stack) {
|
|
4521
|
+
const receiver = stack.at(-2);
|
|
4522
|
+
const input = stack.at(-1);
|
|
4523
|
+
const key = ins.operands[0];
|
|
4524
|
+
if (!isValue(receiver) || !isValue(input) || receiver.kind !== "map" || !receiver.hasKey(key)) return;
|
|
4525
|
+
const m = this.m;
|
|
4526
|
+
resetMeasured(m);
|
|
4527
|
+
m.input = input;
|
|
4528
|
+
m.result = receiver;
|
|
4529
|
+
const cost = charge(ins.rate, m, this.instructionCharge);
|
|
4530
|
+
m.result = setKey(receiver, key, input);
|
|
4531
|
+
return cost;
|
|
4532
|
+
}
|
|
4533
|
+
/** `fastSteps`' charge for calling the unit's own Handler, whose first clause takes the arguments. */
|
|
4534
|
+
fastCallHandlerCharge(ins, code) {
|
|
4535
|
+
return code.clauses.get(ins.operands[0])?.[0]?.params.length === ins.operands[1] && !this.callWouldExceedDepth() ? fixedCharges[CALL] : void 0;
|
|
4536
|
+
}
|
|
4537
|
+
fastCallHandler(code, name, n) {
|
|
4538
|
+
const stack = this.frame.stack;
|
|
4539
|
+
const args = stack.slice(stack.length - n);
|
|
4540
|
+
drop(stack, n);
|
|
4541
|
+
this.dispatch({
|
|
4542
|
+
clauses: code.clauses.get(name),
|
|
4543
|
+
code,
|
|
4544
|
+
next: 0,
|
|
4545
|
+
args
|
|
4546
|
+
});
|
|
4547
|
+
}
|
|
4548
|
+
/**
|
|
4383
4549
|
* Run instructions, fast and general, while they spend less than `room`
|
|
4384
4550
|
* Fuel and the Group has nothing to do between them: none writes a record
|
|
4385
4551
|
* or ends, suspends or cancels the Run. Returns whether any took the
|
|
@@ -4531,7 +4697,7 @@ var Run = class Run {
|
|
|
4531
4697
|
this.abandoning = own === void 0 ? [] : [own];
|
|
4532
4698
|
}
|
|
4533
4699
|
const value = this.settled(s.k === "ask" ? s.call : null, r);
|
|
4534
|
-
if (s.k !== "wait") frame.stack.push(value);
|
|
4700
|
+
if (s.k !== "wait" && frame.code.unit.code[frame.pc].opcode !== 136) frame.stack.push(value);
|
|
4535
4701
|
frame.pc++;
|
|
4536
4702
|
}
|
|
4537
4703
|
settled(call, r) {
|
|
@@ -5527,6 +5693,21 @@ var Run = class Run {
|
|
|
5527
5693
|
return this.frame.stack.slice(this.frame.stack.length - n);
|
|
5528
5694
|
}
|
|
5529
5695
|
/**
|
|
5696
|
+
* `wait q` in a Musical Unit (chapter 5): `wait 0 bars` goes straight on;
|
|
5697
|
+
* any other count calls the Group's musical clock with `q`, as an
|
|
5698
|
+
* `ask … and wait` would, or raises `no musical time` without one.
|
|
5699
|
+
*/
|
|
5700
|
+
musicalWait(count, rate, frame) {
|
|
5701
|
+
if (count === 0n) {
|
|
5702
|
+
this.pay(rate);
|
|
5703
|
+
this.pop();
|
|
5704
|
+
next(frame);
|
|
5705
|
+
return;
|
|
5706
|
+
}
|
|
5707
|
+
if (!this.host?.grants.has("musical-clock") || this.host.isUnbound?.("musical-clock")) throw new ScriptError$1("no musical time");
|
|
5708
|
+
this.capability(MUSICAL_CLOCK, "wait", [this.peek()], CAPABILITY);
|
|
5709
|
+
}
|
|
5710
|
+
/**
|
|
5530
5711
|
* A Capability call (chapter 9): the arguments checked against their
|
|
5531
5712
|
* Shapes, uncharged; the declared cost; the Host function, which may
|
|
5532
5713
|
* `Charge` more while it starts; then an immediate call's result checked
|
|
@@ -5697,8 +5878,9 @@ var Run = class Run {
|
|
|
5697
5878
|
charged
|
|
5698
5879
|
});
|
|
5699
5880
|
callSites.get(ctx).charged = charged;
|
|
5700
|
-
const ms = op.maxPendingMs ?? this.limits.maxWaitMs;
|
|
5881
|
+
const ms = grantName === "musical-clock" ? null : op.maxPendingMs ?? this.limits.maxWaitMs;
|
|
5701
5882
|
if (member) {
|
|
5883
|
+
const memberMs = ms ?? this.limits.maxWaitMs;
|
|
5702
5884
|
const m = {
|
|
5703
5885
|
site: {
|
|
5704
5886
|
frame: this.frame,
|
|
@@ -5707,8 +5889,8 @@ var Run = class Run {
|
|
|
5707
5889
|
id,
|
|
5708
5890
|
call: ctx,
|
|
5709
5891
|
abort,
|
|
5710
|
-
ms,
|
|
5711
|
-
at: this.host.now + BigInt(
|
|
5892
|
+
ms: memberMs,
|
|
5893
|
+
at: this.host.now + BigInt(memberMs) * 1000n
|
|
5712
5894
|
};
|
|
5713
5895
|
waitOrders.set(m, this.host.waitOrder?.() ?? 0);
|
|
5714
5896
|
m.order = this.host.timerOrder?.();
|
|
@@ -5853,7 +6035,9 @@ var Run = class Run {
|
|
|
5853
6035
|
case 49:
|
|
5854
6036
|
case 50: return true;
|
|
5855
6037
|
case 44:
|
|
5856
|
-
case 45:
|
|
6038
|
+
case 45:
|
|
6039
|
+
case 46:
|
|
6040
|
+
case 47: return this.peek().kind === "object" && (ins.opcode === 44 || ins.opcode === 46 ? ins.operands[0] !== "id" : this.peek(1).asText() !== "id");
|
|
5857
6041
|
default: return false;
|
|
5858
6042
|
}
|
|
5859
6043
|
}
|
|
@@ -5993,6 +6177,12 @@ var Run = class Run {
|
|
|
5993
6177
|
const computed = ins.opcode === 47;
|
|
5994
6178
|
const key = computed ? keyText(this.peek(1)) : a;
|
|
5995
6179
|
const receiver = this.peek();
|
|
6180
|
+
if (receiver.kind === "object") {
|
|
6181
|
+
m.result = this.getProperty(receiver, key, rate);
|
|
6182
|
+
drop(frame.stack, computed ? 2 : 1);
|
|
6183
|
+
frame.stack.push(m.result);
|
|
6184
|
+
return next(frame);
|
|
6185
|
+
}
|
|
5996
6186
|
m.result = receiver.kind === "nothing" ? receiver : getKey(receiver, key);
|
|
5997
6187
|
return this.replace(computed ? 2 : 1, rate);
|
|
5998
6188
|
}
|
|
@@ -6360,6 +6550,8 @@ var Run = class Run {
|
|
|
6360
6550
|
return next(frame);
|
|
6361
6551
|
}
|
|
6362
6552
|
case 136: {
|
|
6553
|
+
const count = musicalCount(this.peek());
|
|
6554
|
+
if (count !== void 0) return this.musicalWait(count, rate, frame);
|
|
6363
6555
|
const us = waitUs(this.peek());
|
|
6364
6556
|
this.checkDeadline();
|
|
6365
6557
|
this.checkScopeBoundary();
|
|
@@ -6404,6 +6596,7 @@ var Run = class Run {
|
|
|
6404
6596
|
const x = items[i++];
|
|
6405
6597
|
if (isValue(x)) {
|
|
6406
6598
|
if (x.kind !== "object") throw wrongKind("object", x);
|
|
6599
|
+
if (x.asObjectRef()?.kind === "peer") throw new ScriptError$1("out of domain", [["function", text("wait for")], ["value", x]]);
|
|
6407
6600
|
from = x;
|
|
6408
6601
|
} else if (x.k === "receiver") from = x.name;
|
|
6409
6602
|
else throw new Error("A from expression must produce a receiver or Value");
|
|
@@ -6495,6 +6688,24 @@ var Run = class Run {
|
|
|
6495
6688
|
target = o;
|
|
6496
6689
|
}
|
|
6497
6690
|
const args = spread ?? this.frame.stack.slice(this.frame.stack.length - n - (up ? 0 : 1), up ? void 0 : -1);
|
|
6691
|
+
const waitsHere = ins.opcode !== 128 && ins.opcode !== 130 && ins.opcode !== 132 && ins.opcode !== 134;
|
|
6692
|
+
if (typeof target === "object" && target?.handle.kind.name === "peer") {
|
|
6693
|
+
const peer = target.handle.value;
|
|
6694
|
+
const opName = waitsHere ? PEER_CALL : PEER_POST;
|
|
6695
|
+
const grantName = [...this.host.grants].find(([, g]) => g.capability.name === "peer")?.[0];
|
|
6696
|
+
if (grantName === void 0 || !this.host.grants.get(grantName).ops.has(opName)) throw new ScriptError$1("out of domain", [["function", text("send")], ["value", peer]]);
|
|
6697
|
+
const opArgs = [
|
|
6698
|
+
peer,
|
|
6699
|
+
text(message),
|
|
6700
|
+
listValues(args)
|
|
6701
|
+
];
|
|
6702
|
+
drop(frame.stack, spread ? 3 : n + 1 + (named ? 1 : 0));
|
|
6703
|
+
frame.stack.push(...opArgs);
|
|
6704
|
+
this.capability(grantName, opName, opArgs, CAPABILITY, join);
|
|
6705
|
+
if (waitsHere && !join) return;
|
|
6706
|
+
drop(frame.stack, opArgs.length);
|
|
6707
|
+
return next(frame);
|
|
6708
|
+
}
|
|
6498
6709
|
m.inputSize = partSize("message", 0, args.reduce((sum, v) => sum + sizeOf(v), 0));
|
|
6499
6710
|
const waits = ins.opcode !== 128 && ins.opcode !== 130 && ins.opcode !== 132 && ins.opcode !== 134;
|
|
6500
6711
|
if (waits) {
|
|
@@ -6702,6 +6913,7 @@ var Run = class Run {
|
|
|
6702
6913
|
case 98: {
|
|
6703
6914
|
if (this.frames.length === 1 && !Run.more(frame.dispatch)) this.checkState();
|
|
6704
6915
|
this.pay(rate);
|
|
6916
|
+
if (this.frames.length === 1 && !this.viaFallback) this.mismatches.push(this.mismatchOf(frame));
|
|
6705
6917
|
const d = this.frames.pop().dispatch;
|
|
6706
6918
|
if (this.dispatch(d)) return;
|
|
6707
6919
|
if (!this.frames.length) {
|
|
@@ -7056,7 +7268,9 @@ const loadOrReject = (name, load) => {
|
|
|
7056
7268
|
/**
|
|
7057
7269
|
* Compile a Library, once per process for each code identity. `imports` holds
|
|
7058
7270
|
* every Library its `use` lines name, other than the stdlib's, which are
|
|
7059
|
-
* always there.
|
|
7271
|
+
* always there. `declarations` holds the Operations of every Capability its
|
|
7272
|
+
* code calls, built with `operationDeclarations`; without them each `ask` or
|
|
7273
|
+
* `tell` fails with `unknown operation`. Throws LoadError.
|
|
7060
7274
|
*/
|
|
7061
7275
|
const compileLibrary = (src, imports = [], declarations = {}, options = {}) => build(src, imports, false, declarations, options.atCaller);
|
|
7062
7276
|
const stdlib = /* @__PURE__ */ new Map();
|
|
@@ -7228,11 +7442,13 @@ const saveSections = {
|
|
|
7228
7442
|
inputs: 11,
|
|
7229
7443
|
decisions: 12,
|
|
7230
7444
|
accounting: 13,
|
|
7231
|
-
sources: 14
|
|
7445
|
+
sources: 14,
|
|
7446
|
+
suspension: 15
|
|
7232
7447
|
};
|
|
7233
7448
|
const lastRequired = saveSections.accounting;
|
|
7234
|
-
const isKnown = (tag) => tag >= 1 && tag <= saveSections.
|
|
7235
|
-
|
|
7449
|
+
const isKnown = (tag) => tag >= 1 && tag <= saveSections.suspension;
|
|
7450
|
+
/** Whether a section is one of the known optional ones. */
|
|
7451
|
+
const isOptionalKnown = (tag) => tag === saveSections.sources || tag === saveSections.suspension;
|
|
7236
7452
|
const invalidSave = () => {
|
|
7237
7453
|
throw new HostError("invalid save");
|
|
7238
7454
|
};
|
|
@@ -8169,6 +8385,9 @@ var RecordWriter = class {
|
|
|
8169
8385
|
sources(ss) {
|
|
8170
8386
|
this.w.list(ss, (w, s) => w.text(s.source).list(s.extensions, (w, e) => w.text(e)));
|
|
8171
8387
|
}
|
|
8388
|
+
suspension(forbidden) {
|
|
8389
|
+
this.w.list(forbidden, (w, n) => w.uint(n));
|
|
8390
|
+
}
|
|
8172
8391
|
};
|
|
8173
8392
|
var RecordReader = class {
|
|
8174
8393
|
r;
|
|
@@ -8908,6 +9127,9 @@ var RecordReader = class {
|
|
|
8908
9127
|
extensions: r.list((r) => r.text())
|
|
8909
9128
|
}));
|
|
8910
9129
|
}
|
|
9130
|
+
suspension() {
|
|
9131
|
+
return this.r.list((r) => r.uint());
|
|
9132
|
+
}
|
|
8911
9133
|
};
|
|
8912
9134
|
//#endregion
|
|
8913
9135
|
//#region src/save-state.ts
|
|
@@ -9447,6 +9669,8 @@ const openSave = (bytes) => {
|
|
|
9447
9669
|
const skipped = valueRecords(section, tables);
|
|
9448
9670
|
check(skipped);
|
|
9449
9671
|
if (sources && sources.length !== skipped.scripts.length) invalidSave();
|
|
9672
|
+
const suspension = save.body(saveSections.suspension) ? section(saveSections.suspension, (r) => r.suspension()) : void 0;
|
|
9673
|
+
if (suspension && (suspension.length === 0 || suspension.some((n, i) => n >= skipped.scripts.length || i > 0 && n <= suspension[i - 1]))) invalidSave();
|
|
9450
9674
|
return {
|
|
9451
9675
|
language: save.language,
|
|
9452
9676
|
costModel: save.costModel,
|
|
@@ -9458,6 +9682,7 @@ const openSave = (bytes) => {
|
|
|
9458
9682
|
functions,
|
|
9459
9683
|
scripts: skipped.scripts,
|
|
9460
9684
|
sources,
|
|
9685
|
+
suspension,
|
|
9461
9686
|
texts: textList,
|
|
9462
9687
|
values: (io) => {
|
|
9463
9688
|
const t = {
|
|
@@ -9494,7 +9719,7 @@ const writeSections = (header, io, bodies, texts = new TextTable()) => {
|
|
|
9494
9719
|
if (body) sections.push({
|
|
9495
9720
|
tag,
|
|
9496
9721
|
body,
|
|
9497
|
-
optional: tag
|
|
9722
|
+
optional: isOptionalKnown(tag)
|
|
9498
9723
|
});
|
|
9499
9724
|
}
|
|
9500
9725
|
return writeSave(header, sections);
|
|
@@ -9803,7 +10028,7 @@ var RunWriter = class {
|
|
|
9803
10028
|
let after = 0n;
|
|
9804
10029
|
let branch = 0;
|
|
9805
10030
|
if (block) after = microsOf(s.deadline.after);
|
|
9806
|
-
else if (s.k === "ask") after = BigInt(s.ms) * 1000n;
|
|
10031
|
+
else if (s.k === "ask") after = BigInt(s.ms ?? 0) * 1000n;
|
|
9807
10032
|
else if (s.k === "send" || s.k === "call-value") after = BigInt(r.limits.maxWaitMs) * 1000n;
|
|
9808
10033
|
else if (s.k === "wait-for" && earliest?.action.k === "event") branch = earliest.action.branch;
|
|
9809
10034
|
const fields = this.waitFields(running, s);
|
|
@@ -10378,10 +10603,17 @@ const runFromRecord = (rec, ctx) => {
|
|
|
10378
10603
|
deadline: block
|
|
10379
10604
|
} : x;
|
|
10380
10605
|
switch (at) {
|
|
10381
|
-
case "wait":
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10606
|
+
case "wait":
|
|
10607
|
+
if (w.grant === "musical-clock" && w.call !== void 0) return withBlock({
|
|
10608
|
+
k: "ask",
|
|
10609
|
+
call: ctx.call(w.call),
|
|
10610
|
+
abort: new AbortController(),
|
|
10611
|
+
ms: null
|
|
10612
|
+
});
|
|
10613
|
+
return withBlock({
|
|
10614
|
+
k: "wait",
|
|
10615
|
+
us: 0n
|
|
10616
|
+
});
|
|
10385
10617
|
case "ask-wait": {
|
|
10386
10618
|
const call = w.call === void 0 ? ctx.invalid() : ctx.call(w.call);
|
|
10387
10619
|
return withBlock({
|
|
@@ -10640,7 +10872,8 @@ const encodeGroup = (g) => {
|
|
|
10640
10872
|
...g.sources === "embedded" ? { sources: (w) => w.sources(g.scripts.map((s) => ({
|
|
10641
10873
|
source: s.units[0].source,
|
|
10642
10874
|
extensions: s.units.slice(1).map((u) => u.source)
|
|
10643
|
-
}))) } : {}
|
|
10875
|
+
}))) } : {},
|
|
10876
|
+
...g.scripts.some((s) => s.forbidSuspension) ? { suspension: (w) => w.suspension(g.scripts.flatMap((s, i) => s.forbidSuspension ? [i] : [])) } : {}
|
|
10644
10877
|
});
|
|
10645
10878
|
};
|
|
10646
10879
|
const compareBytes = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -10894,6 +11127,7 @@ const nextRandom = (state, n) => {
|
|
|
10894
11127
|
};
|
|
10895
11128
|
//#endregion
|
|
10896
11129
|
//#region src/group.ts
|
|
11130
|
+
const CAPABILITY_RATE = rateOf("capability");
|
|
10897
11131
|
const compiledScripts = /* @__PURE__ */ new Map();
|
|
10898
11132
|
const faultNames = {
|
|
10899
11133
|
cleanupBudget: "cleanup",
|
|
@@ -10916,7 +11150,7 @@ const overridable = /* @__PURE__ */ new Set([
|
|
|
10916
11150
|
"maxJoin"
|
|
10917
11151
|
]);
|
|
10918
11152
|
const sameClause = (a, b) => a.run.fallback === b.run.fallback && (a.run.fallback || a.delivery.message === b.delivery.message) && a.run.clauseNumber === b.run.clauseNumber;
|
|
10919
|
-
const declarationsOf = (grants) => Object.fromEntries([...grants].map(([name, grant]) => [name, Object.fromEntries([...grant.ops].map((op) => {
|
|
11153
|
+
const declarationsOf = (grants) => Object.fromEntries([...grants].filter(([name]) => name !== MUSICAL_CLOCK).map(([name, grant]) => [name, Object.fromEntries([...grant.ops].map((op) => {
|
|
10920
11154
|
const decl = grant.capability.operations.get(op);
|
|
10921
11155
|
return [op, {
|
|
10922
11156
|
mode: decl.mode,
|
|
@@ -10934,6 +11168,10 @@ const keepOperations = (grant, names) => {
|
|
|
10934
11168
|
kept.add(op.scope.abandon);
|
|
10935
11169
|
}
|
|
10936
11170
|
}
|
|
11171
|
+
if (grant.capability.name === "peer") {
|
|
11172
|
+
const also = [...kept.has("reach") || kept.has("expose") ? ["post", "call"] : [], ...kept.has("expose") ? ["caller"] : []];
|
|
11173
|
+
for (const name of also) if (grant.ops.has(name)) kept.add(name);
|
|
11174
|
+
}
|
|
10937
11175
|
return {
|
|
10938
11176
|
...grant,
|
|
10939
11177
|
ops: kept
|
|
@@ -11047,6 +11285,8 @@ var TsGroup = class TsGroup {
|
|
|
11047
11285
|
accounting = emptyAccounting();
|
|
11048
11286
|
discardReason = "stop";
|
|
11049
11287
|
inputs = [];
|
|
11288
|
+
urgentInputs = 0;
|
|
11289
|
+
chargeInputs = 0;
|
|
11050
11290
|
deliveries = 0;
|
|
11051
11291
|
broadcasts = 0;
|
|
11052
11292
|
/**
|
|
@@ -11067,6 +11307,8 @@ var TsGroup = class TsGroup {
|
|
|
11067
11307
|
saves = 0;
|
|
11068
11308
|
lastClock = null;
|
|
11069
11309
|
randomState = seedState(0n);
|
|
11310
|
+
/** The musical clock's Grant, which every Script holds (chapter 9). */
|
|
11311
|
+
musicalClock;
|
|
11070
11312
|
pumping = false;
|
|
11071
11313
|
combining = false;
|
|
11072
11314
|
combinedAdmission = false;
|
|
@@ -11223,7 +11465,7 @@ var TsGroup = class TsGroup {
|
|
|
11223
11465
|
debugEvaluate(body, frameIndex) {
|
|
11224
11466
|
const pause = this.debugController.current;
|
|
11225
11467
|
const s = this.scripts.find((x) => x.name === pause.script);
|
|
11226
|
-
const frames = this.
|
|
11468
|
+
const frames = this.findRun(s, (r) => r.id === pause.run).run.debugFrames();
|
|
11227
11469
|
const view = frames[frameIndex ?? frames.length - 1];
|
|
11228
11470
|
if (!view) return { error: `There is no frame ${frameIndex}` };
|
|
11229
11471
|
const valueOf = (name) => {
|
|
@@ -11326,14 +11568,15 @@ var TsGroup = class TsGroup {
|
|
|
11326
11568
|
reply: (id, reply) => this.settleReply(id, reply)
|
|
11327
11569
|
});
|
|
11328
11570
|
}
|
|
11329
|
-
/** Worker. A Fingerprint covers code, declarations and
|
|
11571
|
+
/** Worker. A Fingerprint covers code, declarations, limits and `forbidSuspension`, never state. */
|
|
11330
11572
|
fingerprint() {
|
|
11331
11573
|
this.worker();
|
|
11332
11574
|
const scripts = [...this.scripts].sort(byName).map((s) => ({
|
|
11333
11575
|
name: s.name,
|
|
11334
11576
|
identity: s.identity,
|
|
11335
11577
|
grants: Object.fromEntries([...s.grants].sort(([a], [b]) => compareNames(a, b)).map(([name, grant]) => [name, grantData(grant)])),
|
|
11336
|
-
limits: Object.fromEntries(Object.keys(defaultLimits).map((name) => [name, s.limits[name]]))
|
|
11578
|
+
limits: Object.fromEntries(Object.keys(defaultLimits).map((name) => [name, s.limits[name]])),
|
|
11579
|
+
...s.forbidSuspension ? { forbidSuspension: true } : {}
|
|
11337
11580
|
}));
|
|
11338
11581
|
return hexBytes(sha256(canonicalJSON({
|
|
11339
11582
|
language: languageVersion,
|
|
@@ -11365,7 +11608,7 @@ var TsGroup = class TsGroup {
|
|
|
11365
11608
|
return stateFingerprint(this.snapshot());
|
|
11366
11609
|
}
|
|
11367
11610
|
effectsPending() {
|
|
11368
|
-
return this.effectStateUnknown || this.charges.length > 0 || this.waits.awaitedCalls(() => this.holders(), compareCallIds).some(([id]) => this.issuedEligibility(id) === true) || this.scripts.some((s) => this.
|
|
11611
|
+
return this.effectStateUnknown || this.charges.length > 0 || this.waits.awaitedCalls(() => this.holders(), compareCallIds).some(([id]) => this.issuedEligibility(id) === true) || this.scripts.some((s) => !!this.findRun(s, (r) => r.run.hasOpenScopes || r.run.hasParticipant));
|
|
11369
11612
|
}
|
|
11370
11613
|
snapshot() {
|
|
11371
11614
|
return {
|
|
@@ -11397,6 +11640,7 @@ var TsGroup = class TsGroup {
|
|
|
11397
11640
|
const group = new TsGroup({
|
|
11398
11641
|
name: o.name,
|
|
11399
11642
|
onReady: o.onReady,
|
|
11643
|
+
...o.musicalClock ? { musicalClock: o.musicalClock } : {},
|
|
11400
11644
|
trace: o.trace ? (line) => {
|
|
11401
11645
|
if (emitting) o.trace?.(line);
|
|
11402
11646
|
} : void 0
|
|
@@ -11440,12 +11684,13 @@ var TsGroup = class TsGroup {
|
|
|
11440
11684
|
const grants = Object.create(null);
|
|
11441
11685
|
const revoked = /* @__PURE__ */ new Set();
|
|
11442
11686
|
const grantNames = /* @__PURE__ */ new Set();
|
|
11687
|
+
let musicalClock;
|
|
11443
11688
|
for (const grant of script.grants) {
|
|
11444
11689
|
if (grantNames.has(grant.name)) invalidSave();
|
|
11445
11690
|
grantNames.add(grant.name);
|
|
11446
11691
|
const declared = operationsOf(grant.declarations);
|
|
11447
11692
|
if (declared.capability !== grant.capability || grant.operations.some((op) => !declared.operations.has(op.name))) invalidSave();
|
|
11448
|
-
const offered = o.grants(script.name, grant.name);
|
|
11693
|
+
const offered = grant.name === "musical-clock" ? group.musicalClock : o.grants(script.name, grant.name);
|
|
11449
11694
|
const rebound = offered ? keepOperations(offered, new Set(grant.operations.map((op) => op.name))) : void 0;
|
|
11450
11695
|
const placeholder = {
|
|
11451
11696
|
binding: void 0,
|
|
@@ -11462,19 +11707,22 @@ var TsGroup = class TsGroup {
|
|
|
11462
11707
|
revoked.add(grant.name);
|
|
11463
11708
|
unbound.push(`${script.name}.${grant.name}`);
|
|
11464
11709
|
} else if (canonicalJSON(grantData(rebound)) !== grant.declarations) wholeGroup = true;
|
|
11465
|
-
|
|
11710
|
+
if (grant.name === "musical-clock") musicalClock = rebound ?? placeholder;
|
|
11711
|
+
else grants[grant.name] = rebound ?? placeholder;
|
|
11466
11712
|
}
|
|
11467
11713
|
if (loadFailure) continue;
|
|
11468
11714
|
try {
|
|
11469
11715
|
group.load({
|
|
11470
11716
|
name: script.name,
|
|
11471
11717
|
source: sources[0],
|
|
11718
|
+
forbidSuspension: save.suspension?.includes(i) === true,
|
|
11472
11719
|
limits: limitsOf(script.limits),
|
|
11473
11720
|
grants,
|
|
11474
11721
|
owner: script.owner === void 0 ? void 0 : objects[script.owner].handle,
|
|
11475
11722
|
objects: Object.fromEntries(script.objects.map((x) => [x.name, (x.object === void 0 ? invalidSave() : objects[x.object]).handle]))
|
|
11476
11723
|
});
|
|
11477
11724
|
const state = group.scripts.at(-1);
|
|
11725
|
+
if (musicalClock) state.grants = new Map(state.grants).set(MUSICAL_CLOCK, musicalClock);
|
|
11478
11726
|
for (const source of sources.slice(1)) group.applyExtension(state, source, void 0, false);
|
|
11479
11727
|
if (state.units.length !== identities.length || state.units.some((unit, i) => unit.identity !== identities[i])) changed.add(script.name);
|
|
11480
11728
|
state.revoked = revoked;
|
|
@@ -11779,11 +12027,10 @@ var TsGroup = class TsGroup {
|
|
|
11779
12027
|
const operation = operations.get(i) ?? invalidSave();
|
|
11780
12028
|
if (c.script !== s.name) invalidSave();
|
|
11781
12029
|
const op = (s.grants.get(c.grant) ?? invalidSave()).capability.operations.get(operation) ?? invalidSave();
|
|
11782
|
-
const ins = ([...s.loaded.units].find((u) => u.name === c.atUnit) ?? this.libraryCode(s, c.atUnit))?.unit.code[c.atPc];
|
|
11783
12030
|
ctx = {
|
|
11784
12031
|
id: c.id,
|
|
11785
12032
|
op,
|
|
11786
|
-
rate:
|
|
12033
|
+
rate: CAPABILITY_RATE,
|
|
11787
12034
|
named: [["capability", text(c.grant)], ["operation", text(operation)]],
|
|
11788
12035
|
declared: op.cost.fuel,
|
|
11789
12036
|
opName: `${c.grant}.${operation}`,
|
|
@@ -11962,7 +12209,7 @@ var TsGroup = class TsGroup {
|
|
|
11962
12209
|
for (const s of this.scripts) s.incoming = 0;
|
|
11963
12210
|
} else {
|
|
11964
12211
|
this.importWaits(state, restored);
|
|
11965
|
-
this.inputs
|
|
12212
|
+
this.setInputs(inputs);
|
|
11966
12213
|
for (const x of restored) {
|
|
11967
12214
|
if (partial && changed.has(x.s.name)) continue;
|
|
11968
12215
|
x.running.run.validateSnapshot(this.knownCode());
|
|
@@ -12083,10 +12330,15 @@ var TsGroup = class TsGroup {
|
|
|
12083
12330
|
else {
|
|
12084
12331
|
const id = x.pendingId ?? invalidSave();
|
|
12085
12332
|
const ms = sus.k === "ask" ? sus.ms : running.run.limits.maxWaitMs;
|
|
12333
|
+
if (ms === null && !p.block) {
|
|
12334
|
+
if (p.deadline !== void 0) invalidSave();
|
|
12335
|
+
this.waits.add(id, s, running);
|
|
12336
|
+
continue;
|
|
12337
|
+
}
|
|
12086
12338
|
const timer = this.waits.timer(p.deadline ?? invalidSave(), {
|
|
12087
12339
|
k: "call",
|
|
12088
12340
|
id,
|
|
12089
|
-
ms,
|
|
12341
|
+
ms: ms ?? 0,
|
|
12090
12342
|
...sus.k === "ask" ? { abort: sus.abort } : {},
|
|
12091
12343
|
...p.block ? { deadline: sus.deadline?.after ?? msOf(p.after) } : {}
|
|
12092
12344
|
}, running);
|
|
@@ -12271,10 +12523,6 @@ var TsGroup = class TsGroup {
|
|
|
12271
12523
|
}
|
|
12272
12524
|
return known;
|
|
12273
12525
|
}
|
|
12274
|
-
/** A Library's code a Script imports, by its unit name. */
|
|
12275
|
-
libraryCode(s, name) {
|
|
12276
|
-
for (const code of this.knownCode()) if (code.name === name && s.loaded.units.length >= 0) return code;
|
|
12277
|
-
}
|
|
12278
12526
|
discardedDecisions = [];
|
|
12279
12527
|
unsettled = /* @__PURE__ */ new Set();
|
|
12280
12528
|
restored = false;
|
|
@@ -12364,9 +12612,9 @@ var TsGroup = class TsGroup {
|
|
|
12364
12612
|
const code = eligible === void 0 ? "unknown call" : !valid || !eligible || this.charges.some((q) => q.call === call) ? "invalid value" : null;
|
|
12365
12613
|
if (code) {
|
|
12366
12614
|
const line = recordLine("charge-request", [call], [["fuel", valid ? String(fuel) : "\"invalid\""]], true);
|
|
12367
|
-
if (this.
|
|
12615
|
+
if (this.chargeInputs > 0) {
|
|
12368
12616
|
this.combinedAdmission = false;
|
|
12369
|
-
this.
|
|
12617
|
+
this.pushInput({
|
|
12370
12618
|
line,
|
|
12371
12619
|
action: {
|
|
12372
12620
|
k: "refusal",
|
|
@@ -12574,7 +12822,7 @@ var TsGroup = class TsGroup {
|
|
|
12574
12822
|
break;
|
|
12575
12823
|
case "revoke": {
|
|
12576
12824
|
const s = this.scripts.find((s) => s.name === action.name);
|
|
12577
|
-
if (s.grants.has(action.grant) && !s.revoked.has(action.grant)) {
|
|
12825
|
+
if (action.grant !== "musical-clock" && s.grants.has(action.grant) && !s.revoked.has(action.grant)) {
|
|
12578
12826
|
s.revoked.add(action.grant);
|
|
12579
12827
|
this.releaseGrant(s, action.grant, "revoke");
|
|
12580
12828
|
}
|
|
@@ -12591,13 +12839,13 @@ var TsGroup = class TsGroup {
|
|
|
12591
12839
|
break;
|
|
12592
12840
|
case "cancel-run": {
|
|
12593
12841
|
const s = this.scripts.find((s) => s.name === action.name);
|
|
12594
|
-
const running = this.
|
|
12842
|
+
const running = this.findRun(s, (r) => r.id === action.id);
|
|
12595
12843
|
if (running) this.cancelRunning(s, running);
|
|
12596
12844
|
break;
|
|
12597
12845
|
}
|
|
12598
12846
|
case "rewind-run": {
|
|
12599
12847
|
const s = this.scripts.find((s) => s.name === action.name);
|
|
12600
|
-
const running = this.
|
|
12848
|
+
const running = this.findRun(s, (r) => r.id === action.id);
|
|
12601
12849
|
if (running?.run.rewindable && !s.stopped) this.rewindRunning(s, running);
|
|
12602
12850
|
else this.trace?.(recordLine("note", [action.id], [["kind", "not-rewindable"]]));
|
|
12603
12851
|
break;
|
|
@@ -12661,11 +12909,19 @@ var TsGroup = class TsGroup {
|
|
|
12661
12909
|
}
|
|
12662
12910
|
}
|
|
12663
12911
|
runsOf(s) {
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12912
|
+
const runs = [];
|
|
12913
|
+
for (const item of s.queue) if ("run" in item) runs.push(item);
|
|
12914
|
+
runs.push(...s.suspended, ...s.parked);
|
|
12915
|
+
if (runs.length < 2) return runs;
|
|
12916
|
+
return runs.map((r) => ({
|
|
12917
|
+
n: Number(r.id.split("/r")[1]),
|
|
12918
|
+
r
|
|
12919
|
+
})).sort((a, b) => a.n - b.n).map((x) => x.r);
|
|
12920
|
+
}
|
|
12921
|
+
findRun(s, match) {
|
|
12922
|
+
for (const item of s.queue) if ("run" in item && match(item)) return item;
|
|
12923
|
+
for (const r of s.suspended) if (match(r)) return r;
|
|
12924
|
+
return s.parked.find(match);
|
|
12669
12925
|
}
|
|
12670
12926
|
forgetWait(s, running) {
|
|
12671
12927
|
s.suspended.delete(running);
|
|
@@ -12855,7 +13111,7 @@ var TsGroup = class TsGroup {
|
|
|
12855
13111
|
}
|
|
12856
13112
|
recordRefusal(line, code) {
|
|
12857
13113
|
this.combinedAdmission = false;
|
|
12858
|
-
if (this.pumping) this.
|
|
13114
|
+
if (this.pumping) this.pushInput({
|
|
12859
13115
|
line,
|
|
12860
13116
|
urgent: true,
|
|
12861
13117
|
action: {
|
|
@@ -12868,10 +13124,22 @@ var TsGroup = class TsGroup {
|
|
|
12868
13124
|
this.trace?.(recordLine("refused", [], [["code", JSON.stringify(code)]]));
|
|
12869
13125
|
}
|
|
12870
13126
|
}
|
|
13127
|
+
pushInput(input) {
|
|
13128
|
+
this.inputs.push(input);
|
|
13129
|
+
if (input.urgent) this.urgentInputs++;
|
|
13130
|
+
else if (input.action.k === "charge") this.chargeInputs++;
|
|
13131
|
+
}
|
|
13132
|
+
setInputs(inputs) {
|
|
13133
|
+
this.inputs = [];
|
|
13134
|
+
this.urgentInputs = 0;
|
|
13135
|
+
this.chargeInputs = 0;
|
|
13136
|
+
for (const input of inputs) this.pushInput(input);
|
|
13137
|
+
}
|
|
12871
13138
|
landUrgentInputs() {
|
|
12872
|
-
while (this.
|
|
13139
|
+
while (this.urgentInputs > 0) {
|
|
12873
13140
|
const urgent = this.inputs.filter((i) => i.urgent);
|
|
12874
13141
|
this.inputs = this.inputs.filter((i) => !i.urgent);
|
|
13142
|
+
this.urgentInputs = 0;
|
|
12875
13143
|
for (const input of urgent) {
|
|
12876
13144
|
if (this.trace) this.trace(typeof input.line === "string" ? input.line : input.line());
|
|
12877
13145
|
this.applyInput(input.action);
|
|
@@ -12885,6 +13153,10 @@ var TsGroup = class TsGroup {
|
|
|
12885
13153
|
if (options.seed < 0n || options.seed > 18446744073709551615n) throw new HostError("invalid value", "A seed is a whole number 0 to 2^64 - 1");
|
|
12886
13154
|
this.randomState = seedState(options.seed);
|
|
12887
13155
|
}
|
|
13156
|
+
if (options.musicalClock !== void 0) {
|
|
13157
|
+
if (!isMusicalClock(options.musicalClock)) throw new HostError("invalid value", "A musical clock comes from musicalClockCapability");
|
|
13158
|
+
this.musicalClock = options.musicalClock.grant("all", void 0);
|
|
13159
|
+
}
|
|
12888
13160
|
this.trace = options.trace ? (line) => {
|
|
12889
13161
|
if (this.drainingTrace) this.drainingTrace.push(line);
|
|
12890
13162
|
else options.trace(line);
|
|
@@ -12901,7 +13173,7 @@ var TsGroup = class TsGroup {
|
|
|
12901
13173
|
queueInput(input, notify = true) {
|
|
12902
13174
|
const landing = this.debugController?.current;
|
|
12903
13175
|
if (landing && (input.action.k === "stop" || input.action.k === "cancel-run" || input.action.k === "rewind-run") && typeof input.line === "string") input.line += ` pc=${landing.pc}`;
|
|
12904
|
-
this.
|
|
13176
|
+
this.pushInput(input);
|
|
12905
13177
|
if (!notify) return;
|
|
12906
13178
|
if (this.onReady) {
|
|
12907
13179
|
if (this.pumping || this.cleaning) queueMicrotask(() => this.onReady?.());
|
|
@@ -12956,7 +13228,7 @@ var TsGroup = class TsGroup {
|
|
|
12956
13228
|
}
|
|
12957
13229
|
scriptGrants(name) {
|
|
12958
13230
|
this.worker();
|
|
12959
|
-
return Object.fromEntries([...this.scripts.find((s) => s.name === name).grants].sort(([a], [b]) => compareText(a, b)).map(([name, grant]) => [name, [...grant.ops].sort(compareText)]));
|
|
13231
|
+
return Object.fromEntries([...this.scripts.find((s) => s.name === name).grants].filter(([name]) => name !== MUSICAL_CLOCK).sort(([a], [b]) => compareText(a, b)).map(([name, grant]) => [name, [...grant.ops].sort(compareText)]));
|
|
12960
13232
|
}
|
|
12961
13233
|
/** Worker. Compiles, checks and loads a Script, or throws LoadError. */
|
|
12962
13234
|
load(o) {
|
|
@@ -12967,7 +13239,12 @@ var TsGroup = class TsGroup {
|
|
|
12967
13239
|
if (owner?.owner) throw new HostError("invalid value", `${owner.handle.value} already has an Owning Script, ${owner.owner}`);
|
|
12968
13240
|
for (const object of Object.values(o.objects ?? {})) this.held(object);
|
|
12969
13241
|
const grants = new Map(Object.entries(o.grants ?? {}));
|
|
12970
|
-
|
|
13242
|
+
if (grants.has("musical-clock")) throw new HostError("invalid value", `${MUSICAL_CLOCK} is the Group's own Grant name`);
|
|
13243
|
+
if ([...grants.values()].filter((g) => g.capability.name === "peer").length > 1) throw new HostError("invalid value", `Script ${o.name} has more than one peer Grant`);
|
|
13244
|
+
const p = prepare("script", o.name, o.source, this.libraries, objects, declarationsOf(grants), void 0, {
|
|
13245
|
+
...propertyChecks(o.objects ?? {}, o.owner),
|
|
13246
|
+
forbidSuspension: o.forbidSuspension === true
|
|
13247
|
+
});
|
|
12971
13248
|
this.trace?.(recordLine("load", [o.name], [["identity", p.identity]], true));
|
|
12972
13249
|
const limits = {
|
|
12973
13250
|
...defaultLimits,
|
|
@@ -12979,6 +13256,7 @@ var TsGroup = class TsGroup {
|
|
|
12979
13256
|
const bound = keepOperations(grant, used?.get(name) ?? (used ? /* @__PURE__ */ new Set() : grant.ops));
|
|
12980
13257
|
return used && bound.ops.size === 0 ? [] : [[name, bound]];
|
|
12981
13258
|
}));
|
|
13259
|
+
if (this.musicalClock) kept.set(MUSICAL_CLOCK, this.musicalClock);
|
|
12982
13260
|
const handle = new TsScript(this.channel, o.name);
|
|
12983
13261
|
if (owner) owner.owner = o.name;
|
|
12984
13262
|
this.scripts.push({
|
|
@@ -12990,6 +13268,7 @@ var TsGroup = class TsGroup {
|
|
|
12990
13268
|
grants: kept,
|
|
12991
13269
|
revoked: /* @__PURE__ */ new Set(),
|
|
12992
13270
|
disabled: /* @__PURE__ */ new Set(),
|
|
13271
|
+
forbidSuspension: o.forbidSuspension === true,
|
|
12993
13272
|
handle,
|
|
12994
13273
|
loaded,
|
|
12995
13274
|
identity: p.identity,
|
|
@@ -13036,7 +13315,10 @@ var TsGroup = class TsGroup {
|
|
|
13036
13315
|
}
|
|
13037
13316
|
replacement(s, source, carry, libraries = this.libraries, extensions = [], keepMailbox = false) {
|
|
13038
13317
|
const grants = availableGrants(s);
|
|
13039
|
-
const p = prepare("script", s.name, source, libraries, Object.keys(s.objects), declarationsOf(grants), void 0,
|
|
13318
|
+
const p = prepare("script", s.name, source, libraries, Object.keys(s.objects), declarationsOf(grants), void 0, {
|
|
13319
|
+
...propertyChecks(s.objects, s.owner?.handle),
|
|
13320
|
+
forbidSuspension: s.forbidSuspension
|
|
13321
|
+
});
|
|
13040
13322
|
const loaded = this.loadPrepared(s.name, p, s.limits);
|
|
13041
13323
|
const staged = {
|
|
13042
13324
|
...s,
|
|
@@ -13109,6 +13391,7 @@ var TsGroup = class TsGroup {
|
|
|
13109
13391
|
const current = {
|
|
13110
13392
|
kind: binding.kind,
|
|
13111
13393
|
contract: binding.contract,
|
|
13394
|
+
...binding.shape ? { shape: true } : {},
|
|
13112
13395
|
importedFrom: binding.kind === "script variable" ? void 0 : binding.importedFrom ?? {
|
|
13113
13396
|
library: key,
|
|
13114
13397
|
name: binding.name
|
|
@@ -13122,7 +13405,10 @@ var TsGroup = class TsGroup {
|
|
|
13122
13405
|
}
|
|
13123
13406
|
}
|
|
13124
13407
|
}
|
|
13125
|
-
const p = prepare("script", name, source, libraries, Object.keys(s.objects), declarationsOf(availableGrants(s)), existing,
|
|
13408
|
+
const p = prepare("script", name, source, libraries, Object.keys(s.objects), declarationsOf(availableGrants(s)), existing, {
|
|
13409
|
+
...propertyChecks(s.objects, s.owner?.handle),
|
|
13410
|
+
forbidSuspension: s.forbidSuspension
|
|
13411
|
+
});
|
|
13126
13412
|
const identity = codeIdentity("extension", s.name, source, p.imports.map(identityOf));
|
|
13127
13413
|
const diagnostics = [...p.diagnostics ?? []];
|
|
13128
13414
|
if (p.checked.tree) {
|
|
@@ -13249,11 +13535,13 @@ var TsGroup = class TsGroup {
|
|
|
13249
13535
|
this.libraries.set(l.name, l);
|
|
13250
13536
|
}
|
|
13251
13537
|
/** Worker. Prepare every dependent before changing the Group. */
|
|
13252
|
-
replaceLibrary(l, carry) {
|
|
13538
|
+
replaceLibrary(l, carry, o) {
|
|
13539
|
+
const keepMailbox = !!o?.keepMailbox;
|
|
13253
13540
|
this.worker();
|
|
13254
13541
|
this.requireKnownEffects();
|
|
13255
13542
|
this.trace?.(recordLine("replace-library", [l.name], [
|
|
13256
13543
|
["carry", carry === "carry variables" ? "yes" : "no"],
|
|
13544
|
+
["mailbox", keepMailbox ? "keep" : null],
|
|
13257
13545
|
["source", displayText(l.source)],
|
|
13258
13546
|
["identity", identityOf(l)]
|
|
13259
13547
|
], true));
|
|
@@ -13278,12 +13566,12 @@ var TsGroup = class TsGroup {
|
|
|
13278
13566
|
affected.add(l.name);
|
|
13279
13567
|
const replacements = this.scripts.filter((s) => s.units.some((u) => u.imports.some((i) => affected.has(i.name)))).map((s) => ({
|
|
13280
13568
|
s,
|
|
13281
|
-
...this.replacement(s, s.units[0].source, carry, libraries, s.units.slice(1).map((u) => u.source))
|
|
13569
|
+
...this.replacement(s, s.units[0].source, carry, libraries, s.units.slice(1).map((u) => u.source), keepMailbox)
|
|
13282
13570
|
}));
|
|
13283
13571
|
this.discardReason = "library replacement";
|
|
13284
13572
|
let reports;
|
|
13285
13573
|
try {
|
|
13286
|
-
reports = this.replaceScripts(replacements);
|
|
13574
|
+
reports = this.replaceScripts(replacements, keepMailbox);
|
|
13287
13575
|
} finally {
|
|
13288
13576
|
this.discardReason = "stop";
|
|
13289
13577
|
}
|
|
@@ -13324,7 +13612,7 @@ var TsGroup = class TsGroup {
|
|
|
13324
13612
|
group,
|
|
13325
13613
|
disableGrant: (name) => {
|
|
13326
13614
|
s.disabled.add(name);
|
|
13327
|
-
const running = this.
|
|
13615
|
+
const running = this.findRun(s, (r) => r.run === run);
|
|
13328
13616
|
if (running) this.writeRecords(running, 0);
|
|
13329
13617
|
},
|
|
13330
13618
|
isDisabled: (name) => s.disabled.has(name),
|
|
@@ -13523,7 +13811,7 @@ var TsGroup = class TsGroup {
|
|
|
13523
13811
|
*/
|
|
13524
13812
|
markWait(running, sus, now) {
|
|
13525
13813
|
const last = lastWaits.get(running);
|
|
13526
|
-
const suspendedAt = sus
|
|
13814
|
+
const suspendedAt = suspendReason(sus);
|
|
13527
13815
|
const block = sus.deadline;
|
|
13528
13816
|
if (sus.k === "join") {
|
|
13529
13817
|
if (block) waitOrders.set(running, ++this.waitOrder);
|
|
@@ -13542,7 +13830,7 @@ var TsGroup = class TsGroup {
|
|
|
13542
13830
|
return;
|
|
13543
13831
|
}
|
|
13544
13832
|
waitOrders.set(running, ++this.waitOrder);
|
|
13545
|
-
const own = sus.k === "ask" ? BigInt(sus.ms) * 1000n : sus.k === "send" || sus.k === "call-value" ? BigInt(running.run.limits.maxWaitMs) * 1000n : null;
|
|
13833
|
+
const own = sus.k === "ask" ? sus.ms === null ? null : BigInt(sus.ms) * 1000n : sus.k === "send" || sus.k === "call-value" ? BigInt(running.run.limits.maxWaitMs) * 1000n : null;
|
|
13546
13834
|
const bounded = !!block && (sus.k === "wait" ? block.at <= now + sus.us : sus.k === "wait-for" ? true : own !== null && block.at <= now + own);
|
|
13547
13835
|
const [grant, operation] = sus.k === "ask" ? sus.call.opName.split(".") : ["", ""];
|
|
13548
13836
|
lastWaits.set(running, {
|
|
@@ -13618,12 +13906,16 @@ var TsGroup = class TsGroup {
|
|
|
13618
13906
|
}
|
|
13619
13907
|
const id = sus.k === "ask" ? sus.call.id : sus.id;
|
|
13620
13908
|
const ms = sus.k === "ask" ? sus.ms : running.run.limits.maxWaitMs;
|
|
13621
|
-
const own = now + BigInt(ms) * 1000n;
|
|
13909
|
+
const own = ms === null ? null : now + BigInt(ms) * 1000n;
|
|
13622
13910
|
const bounded = ends(own);
|
|
13911
|
+
if (own === null && !bounded) {
|
|
13912
|
+
this.waits.add(id, s, running);
|
|
13913
|
+
return null;
|
|
13914
|
+
}
|
|
13623
13915
|
const timer = this.waits.timer(bounded ? block.at : own, {
|
|
13624
13916
|
k: "call",
|
|
13625
13917
|
id,
|
|
13626
|
-
ms,
|
|
13918
|
+
ms: ms ?? 0,
|
|
13627
13919
|
...sus.k === "ask" ? { abort: sus.abort } : {},
|
|
13628
13920
|
...bounded ? { deadline: block.after } : {}
|
|
13629
13921
|
}, running);
|
|
@@ -13960,7 +14252,7 @@ var TsGroup = class TsGroup {
|
|
|
13960
14252
|
this.objects.set(key, state);
|
|
13961
14253
|
if (up && this.trace) {
|
|
13962
14254
|
const line = recordLine("object", [], [["object", traceValue(state.handle.value)], ["parent", traceValue(up.handle.value)]]);
|
|
13963
|
-
if (this.pumping) this.
|
|
14255
|
+
if (this.pumping) this.pushInput({
|
|
13964
14256
|
line,
|
|
13965
14257
|
urgent: true,
|
|
13966
14258
|
action: { k: "record" }
|
|
@@ -14073,7 +14365,7 @@ var TsGroup = class TsGroup {
|
|
|
14073
14365
|
});
|
|
14074
14366
|
if (delivery.request) {
|
|
14075
14367
|
if (outcome.kind === "completed") delivery.request.resolve(outcome.result);
|
|
14076
|
-
else delivery.request.reject(sendFailed(outcome.kind));
|
|
14368
|
+
else delivery.request.reject(sendFailed(outcome.kind, outcome.kind === "errored" ? outcome.error : null));
|
|
14077
14369
|
}
|
|
14078
14370
|
}
|
|
14079
14371
|
deliveryLine(record, id, to, m, fn) {
|
|
@@ -14108,7 +14400,7 @@ var TsGroup = class TsGroup {
|
|
|
14108
14400
|
const slice = o.fuelSlice ?? 0;
|
|
14109
14401
|
const cap = o.fuelCap ?? 0;
|
|
14110
14402
|
const drained = this.inputs;
|
|
14111
|
-
this.
|
|
14403
|
+
this.setInputs([]);
|
|
14112
14404
|
const reports = [];
|
|
14113
14405
|
this.drainReports = reports;
|
|
14114
14406
|
const inputLines = [];
|
|
@@ -14424,10 +14716,10 @@ var TsGroup = class TsGroup {
|
|
|
14424
14716
|
...start,
|
|
14425
14717
|
...stretch,
|
|
14426
14718
|
["state", String(this.persistentState(s))],
|
|
14427
|
-
["end", suspension
|
|
14719
|
+
["end", suspendReason(suspension)],
|
|
14428
14720
|
["until", deadline === null || !isInstant(deadline) ? null : formatInstant(deadline)]
|
|
14429
14721
|
]));
|
|
14430
|
-
observe(suspension
|
|
14722
|
+
observe(suspendReason(suspension), deadline ?? void 0);
|
|
14431
14723
|
this.seal(running.delivery, { verdict: "allowed" });
|
|
14432
14724
|
run.openVerdict = false;
|
|
14433
14725
|
return;
|
|
@@ -14676,6 +14968,7 @@ var TsGroup = class TsGroup {
|
|
|
14676
14968
|
["status", text(outcome.effect.status)],
|
|
14677
14969
|
...outcome.effect.scope ? [["scope", text(outcome.effect.scope)]] : []
|
|
14678
14970
|
])) : null],
|
|
14971
|
+
["mismatches", (outcome.kind === "unhandled" || fallback) && run.mismatches.length ? traceValue(mismatchesValue(run.mismatches)) : null],
|
|
14679
14972
|
["fuel", String(run.fuel)],
|
|
14680
14973
|
["alloc", String(run.alloc)]
|
|
14681
14974
|
]));
|
|
@@ -14764,7 +15057,7 @@ var TsGroup = class TsGroup {
|
|
|
14764
15057
|
}
|
|
14765
15058
|
releaseParked(s, ended) {
|
|
14766
15059
|
const same = (r) => !r.delivery.fn && !ended.delivery.fn && sameClause(r, ended);
|
|
14767
|
-
if (this.
|
|
15060
|
+
if (this.findRun(s, (r) => !r.parked && same(r))) return;
|
|
14768
15061
|
const next = s.parked.find(same);
|
|
14769
15062
|
if (!next) return;
|
|
14770
15063
|
s.parked = s.parked.filter((r) => r !== next);
|
|
@@ -14792,7 +15085,7 @@ var TsGroup = class TsGroup {
|
|
|
14792
15085
|
const until = this.waits.until(running, !!sus.deadline && sus.k !== "join");
|
|
14793
15086
|
const calls = sus.k === "ask" ? [sus.call.id] : sus.k === "send" || sus.k === "call-value" ? [sus.id] : sus.k === "join" ? this.waits.pendingMembers(sus.members).map((m) => m.id) : [];
|
|
14794
15087
|
return {
|
|
14795
|
-
wait: sus
|
|
15088
|
+
wait: suspendReason(sus),
|
|
14796
15089
|
...until === void 0 || !isInstant(until) ? {} : { until },
|
|
14797
15090
|
...calls.length ? { calls } : {}
|
|
14798
15091
|
};
|
|
@@ -14819,7 +15112,7 @@ var TsGroup = class TsGroup {
|
|
|
14819
15112
|
return { scripts: this.inspection().scripts.map((s, i) => ({
|
|
14820
15113
|
...s,
|
|
14821
15114
|
runs: s.runs.map((view) => {
|
|
14822
|
-
const run = this.
|
|
15115
|
+
const run = this.findRun(this.scripts[i], (r) => r.id === view.id).run;
|
|
14823
15116
|
return {
|
|
14824
15117
|
...view,
|
|
14825
15118
|
fuel: run.fuel,
|
|
@@ -14855,6 +15148,7 @@ var TsGroup = class TsGroup {
|
|
|
14855
15148
|
return {
|
|
14856
15149
|
name: s.name,
|
|
14857
15150
|
...s.disabled.size ? { disabledGrants: [...s.disabled].sort(compareText) } : {},
|
|
15151
|
+
...s.forbidSuspension ? { forbidSuspension: true } : {},
|
|
14858
15152
|
vars,
|
|
14859
15153
|
runs: this.runsOf(s).map((item) => ({
|
|
14860
15154
|
id: item.id,
|
|
@@ -14882,6 +15176,7 @@ const suspendReasons = {
|
|
|
14882
15176
|
join: "join-end",
|
|
14883
15177
|
"wait-for": "wait-for"
|
|
14884
15178
|
};
|
|
15179
|
+
const suspendReason = (s) => s.k === "wait-for" && s.any ? "wait-for-any" : s.k === "ask" && s.ms === null ? "wait" : suspendReasons[s.k];
|
|
14885
15180
|
const hostError = (error) => {
|
|
14886
15181
|
const message = error.get("message");
|
|
14887
15182
|
const textMessage = message.kind === "text";
|
|
@@ -15018,8 +15313,80 @@ const messageFields = (m) => {
|
|
|
15018
15313
|
["limits", limits.length ? `{${limits.map(([k, v]) => `${k}: ${v}`).join(", ")}}` : null]
|
|
15019
15314
|
];
|
|
15020
15315
|
};
|
|
15021
|
-
const
|
|
15316
|
+
const fastStepsPrimer = `function weigh v
|
|
15317
|
+
if v > 2 then return v * 2
|
|
15318
|
+
return v
|
|
15319
|
+
end weigh
|
|
15320
|
+
|
|
15321
|
+
on tick state
|
|
15322
|
+
if state's x < 100 then
|
|
15323
|
+
put state's x + 1 into state's x
|
|
15324
|
+
end if
|
|
15325
|
+
return state
|
|
15326
|
+
end tick
|
|
15327
|
+
|
|
15328
|
+
on run n
|
|
15329
|
+
put {x: 0} into state
|
|
15330
|
+
put [] into items
|
|
15331
|
+
put "" into word
|
|
15332
|
+
put 0 into j
|
|
15333
|
+
repeat for each i in 1..n
|
|
15334
|
+
put tick(state) into state
|
|
15335
|
+
put i after items
|
|
15336
|
+
put "x" after word
|
|
15337
|
+
put weigh(i) into state's y
|
|
15338
|
+
put i - 1 into j
|
|
15339
|
+
put i = 2 into flag
|
|
15340
|
+
if flag then add 1 to j
|
|
15341
|
+
end repeat
|
|
15342
|
+
repeat for each v in items
|
|
15343
|
+
add weigh(v) * 3 to j
|
|
15344
|
+
end repeat
|
|
15345
|
+
add 0.5 to j
|
|
15346
|
+
put 9007199254740990 * 9007199254740990 into big
|
|
15347
|
+
return [state, word, j, big]
|
|
15348
|
+
end run`;
|
|
15349
|
+
let fastStepsPrimed = false;
|
|
15350
|
+
const onJavaScriptCore = typeof globalThis.process?.versions?.bun === "string" || typeof navigator === "object" && /AppleWebKit/.test(navigator.userAgent) && !/Chrome|Chromium|Edg\//.test(navigator.userAgent);
|
|
15351
|
+
const primeFastSteps = () => {
|
|
15352
|
+
if (fastStepsPrimed || !onJavaScriptCore) return;
|
|
15353
|
+
fastStepsPrimed = true;
|
|
15354
|
+
const group = new TsGroup({ name: "fast-steps-primer" });
|
|
15355
|
+
group.load({
|
|
15356
|
+
name: "primer",
|
|
15357
|
+
source: fastStepsPrimer
|
|
15358
|
+
});
|
|
15359
|
+
group.script("primer").deliver({
|
|
15360
|
+
args: [num(4)],
|
|
15361
|
+
name: "run"
|
|
15362
|
+
});
|
|
15363
|
+
for (let i = 0; i < 100 && group.pump(0n, {}).state !== "idle"; i++);
|
|
15364
|
+
};
|
|
15365
|
+
const newGroup = (o) => {
|
|
15366
|
+
primeFastSteps();
|
|
15367
|
+
return new TsGroup(o);
|
|
15368
|
+
};
|
|
15022
15369
|
const messageSize = (d) => partSize("message", 0, d.args.reduce((sum, v) => sum + sizeOf(v), 0) + (d.fn ? sizeOf(d.fn) : 0));
|
|
15023
|
-
const restore = (bytes, options) =>
|
|
15370
|
+
const restore = (bytes, options) => {
|
|
15371
|
+
primeFastSteps();
|
|
15372
|
+
return TsGroup.restore(bytes, options);
|
|
15373
|
+
};
|
|
15374
|
+
/**
|
|
15375
|
+
* A Run's `mismatches`, built only for the Trace and charged to no one
|
|
15376
|
+
* (ADR 0172): each skipped named clause's reason, and for a Clause Shape,
|
|
15377
|
+
* what `explain` gives for its argument.
|
|
15378
|
+
*/
|
|
15379
|
+
const mismatchesValue = (mismatches) => listValues(mismatches.map((m) => {
|
|
15380
|
+
const entries = [["clause", num(m.clause)], ["reason", text(m.reason)]];
|
|
15381
|
+
if (m.reason === "shape") {
|
|
15382
|
+
entries.push(["argument", num(m.argument)]);
|
|
15383
|
+
const shape = m.shape && decodeShape(m.shape).shape;
|
|
15384
|
+
if (shape) {
|
|
15385
|
+
const { diags } = shapeDiagnostics(m.value, shape, false, 0);
|
|
15386
|
+
entries.push(["mismatches", listValues(diags.map(diagnosticRecord))]);
|
|
15387
|
+
}
|
|
15388
|
+
}
|
|
15389
|
+
return map(entries);
|
|
15390
|
+
}));
|
|
15024
15391
|
//#endregion
|
|
15025
15392
|
export { registeredStdlib as C, registerStdlib as S, stdlibSource as T, loadScript as _, recordLine as a, exportsOf as b, codeIdentity as c, Run as d, Script as f, deliver as g, defaultLimits as h, restore as i, compileLibrary as l, callFunction as m, TsScript as n, traceValue as o, UnitLoadError as p, newGroup as r, stateFingerprint$1 as s, TsGroup as t, replacementLibraries as u, LoweringError as v, stdlibNames as w, lowerTree as x, compileSource as y };
|