This commit is contained in:
Tony Garnock-Jones 2021-02-24 22:19:37 +01:00
parent 63270a97b4
commit 78662a0d77
1 changed files with 9 additions and 11 deletions

View File

@ -131,9 +131,7 @@ export class Turn {
assert(ref: Ref, assertion: Assertion): Handle {
const h = nextHandle++;
this.enqueue(ref.relay, t => {
const a = ref.attenuation === void 0
? assertion
: runRewrites(ref.attenuation, assertion);
const a = runRewrites(ref.attenuation, assertion);
if (a !== null) {
this.actor.outbound.set(h, ref);
ref.target.assert?.(t, a, h);
@ -167,9 +165,7 @@ export class Turn {
}
message(ref: Ref, assertion: Assertion): void {
const a = ref.attenuation === void 0
? assertion
: runRewrites(ref.attenuation, assertion);
const a = runRewrites(ref.attenuation, assertion);
if (a !== null) this.enqueue(ref.relay, t => ref.target.message?.(t, assertion));
}
@ -261,11 +257,13 @@ export function rewrite(r: Rewrite, v: Assertion): Assertion | null {
return instantiate(r.template, bindings);
}
export function runRewrites(a: Attenuation, v: Assertion): Assertion | null {
for (const r of a) {
const w = rewrite(r, v);
if (w === null) return null;
v = w;
export function runRewrites(a: Attenuation | undefined, v: Assertion): Assertion | null {
if (a !== void 0) {
for (const r of a) {
const w = rewrite(r, v);
if (w === null) return null;
v = w;
}
}
return v;
}