Dynamic currentSyndicateTarget
This commit is contained in:
parent
7a34dc9716
commit
248d22a3ef
|
@ -194,10 +194,10 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
))
|
))
|
||||||
})`;
|
})`;
|
||||||
if (s.test === void 0) {
|
if (s.test === void 0) {
|
||||||
return t`assertDataflow(() => ({ target: currentSyndicateTarget, assertion: ${assertion} }));`;
|
return t`assertDataflow(() => ({ target: currentSyndicateTarget(), assertion: ${assertion} }));`;
|
||||||
} else {
|
} else {
|
||||||
return t`assertDataflow(() => (${walk(s.test)})
|
return t`assertDataflow(() => (${walk(s.test)})
|
||||||
? ({ target: currentSyndicateTarget, assertion: ${assertion} })
|
? ({ target: currentSyndicateTarget(), assertion: ${assertion} })
|
||||||
: ({ target: void 0, assertion: void 0 }));`;
|
: ({ target: void 0, assertion: void 0 }));`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -222,7 +222,7 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
});
|
});
|
||||||
|
|
||||||
x(ctx.parser.atStatement, (s, t) => {
|
x(ctx.parser.atStatement, (s, t) => {
|
||||||
return t`(((${ctx.argDecl(t, 'currentSyndicateTarget', '__SYNDICATE__.Ref')}) => {${walk(s.body)}})(${walk(s.target)}));`;
|
return t`(((${ctx.argDecl(t, 'currentSyndicateTarget', '() => __SYNDICATE__.Ref')}) => {${walk(s.body)}})(() => (${walk(s.target)})));`;
|
||||||
});
|
});
|
||||||
|
|
||||||
x(ctx.parser.createExpression, (s, t) => {
|
x(ctx.parser.createExpression, (s, t) => {
|
||||||
|
@ -232,17 +232,17 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
xf(ctx.parser.assertionEndpointStatement, (s, t) => {
|
xf(ctx.parser.assertionEndpointStatement, (s, t) => {
|
||||||
if (s.isDynamic) {
|
if (s.isDynamic) {
|
||||||
if (s.test === void 0) {
|
if (s.test === void 0) {
|
||||||
return t`assertDataflow(() => ({ target: currentSyndicateTarget, assertion: ${walk(s.template)} }));`;
|
return t`assertDataflow(() => ({ target: currentSyndicateTarget(), assertion: ${walk(s.template)} }));`;
|
||||||
} else {
|
} else {
|
||||||
return t`assertDataflow(() => (${walk(s.test)})
|
return t`assertDataflow(() => (${walk(s.test)})
|
||||||
? ({ target: currentSyndicateTarget, assertion: ${walk(s.template)} })
|
? ({ target: currentSyndicateTarget(), assertion: ${walk(s.template)} })
|
||||||
: ({ target: void 0, assertion: void 0 }));`;
|
: ({ target: void 0, assertion: void 0 }));`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (s.test === void 0) {
|
if (s.test === void 0) {
|
||||||
return t`assert(currentSyndicateTarget, ${walk(s.template)});`;
|
return t`assert(currentSyndicateTarget(), ${walk(s.template)});`;
|
||||||
} else {
|
} else {
|
||||||
return t`replace(currentSyndicateTarget, void 0, (${walk(s.test)}) ? (${walk(s.template)}) : void 0);`;
|
return t`replace(currentSyndicateTarget(), void 0, (${walk(s.test)}) ? (${walk(s.template)}) : void 0);`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -297,17 +297,17 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
|
|
||||||
if (s.isDynamic) {
|
if (s.isDynamic) {
|
||||||
if (s.test === void 0) {
|
if (s.test === void 0) {
|
||||||
return wrap(t`__SYNDICATE__.Turn.active.assertDataflow(() => ({ target: currentSyndicateTarget, assertion: ${assertion} }));`);
|
return wrap(t`__SYNDICATE__.Turn.active.assertDataflow(() => ({ target: currentSyndicateTarget(), assertion: ${assertion} }));`);
|
||||||
} else {
|
} else {
|
||||||
return wrap(t`__SYNDICATE__.Turn.active.assertDataflow(() => (${walk(s.test)})
|
return wrap(t`__SYNDICATE__.Turn.active.assertDataflow(() => (${walk(s.test)})
|
||||||
? ({ target: currentSyndicateTarget, assertion: ${assertion} })
|
? ({ target: currentSyndicateTarget(), assertion: ${assertion} })
|
||||||
: ({ target: void 0, assertion: void 0 }));`);
|
: ({ target: void 0, assertion: void 0 }));`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (s.test === void 0) {
|
if (s.test === void 0) {
|
||||||
return wrap(t`__SYNDICATE__.Turn.active.replace(currentSyndicateTarget, void 0, ${assertion});`);
|
return wrap(t`__SYNDICATE__.Turn.active.replace(currentSyndicateTarget(), void 0, ${assertion});`);
|
||||||
} else {
|
} else {
|
||||||
return wrap(t`__SYNDICATE__.Turn.active.replace(currentSyndicateTarget, void 0, (${walk(s.test)}) ? ${assertion} : void 0);`);
|
return wrap(t`__SYNDICATE__.Turn.active.replace(currentSyndicateTarget(), void 0, (${walk(s.test)}) ? ${assertion} : void 0);`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -322,7 +322,7 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
return t`const ${[s.label]} = __SYNDICATE__.Record.makeConstructor${fs}()(${maybeWalk(s.wireName) ?? l}, ${fns});`;
|
return t`const ${[s.label]} = __SYNDICATE__.Record.makeConstructor${fs}()(${maybeWalk(s.wireName) ?? l}, ${fns});`;
|
||||||
});
|
});
|
||||||
|
|
||||||
xf(ctx.parser.messageSendStatement, (s, t) => t`message(currentSyndicateTarget, ${walk(s.expr)});`);
|
xf(ctx.parser.messageSendStatement, (s, t) => t`message(currentSyndicateTarget(), ${walk(s.expr)});`);
|
||||||
|
|
||||||
x(ctx.parser.reactStatement, (s, t) => facetWrap(t, s.label ?? 'default', s.body));
|
x(ctx.parser.reactStatement, (s, t) => facetWrap(t, s.label ?? 'default', s.body));
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2023-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2023-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
const __SYNDICATE__ = Syndicate;
|
const __SYNDICATE__ = Syndicate;
|
||||||
const currentSyndicateTarget = Syndicate.Dataspace.local;
|
const currentSyndicateTarget = () => Syndicate.Dataspace.local;
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
async function translateScripts() {
|
async function translateScripts() {
|
||||||
|
|
|
@ -61,6 +61,20 @@ __SYNDICATE__.Turn.active._sync(p, __SYNDICATE__.Turn.ref({
|
||||||
}));`));
|
}));`));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('at', () => {
|
||||||
|
it('produces a closure for currentSyndicateTarget', () => {
|
||||||
|
expectCodeEqual(`at someField.value { foo(); }`,
|
||||||
|
`(((currentSyndicateTarget) => {
|
||||||
|
foo();
|
||||||
|
})(() => (someField.value)));`);
|
||||||
|
expectCodeEqual(`at someField.value { foo(); }`,
|
||||||
|
`(((currentSyndicateTarget: () => __SYNDICATE__.Ref) => {
|
||||||
|
foo();
|
||||||
|
})(() => (someField.value)));`,
|
||||||
|
{ typescript: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('spawn', () => {
|
describe('spawn', () => {
|
||||||
|
|
||||||
it('without name', () => expectCodeEqual(`spawn { a; b; c; }`, `
|
it('without name', () => expectCodeEqual(`spawn { a; b; c; }`, `
|
||||||
|
@ -147,7 +161,7 @@ describe('during', () => {
|
||||||
|
|
||||||
it('stop in body', () => expectCodeEqual(`during P => { a; stop; b; }`, `
|
it('stop in body', () => expectCodeEqual(`during P => { a; stop; b; }`, `
|
||||||
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
||||||
observer: __SYNDICATE__.Turn.ref(__SYNDICATE__.assertionFacetObserver(
|
observer: __SYNDICATE__.Turn.ref(__SYNDICATE__.assertionFacetObserver(
|
||||||
|
@ -167,7 +181,7 @@ __SYNDICATE__.Turn.active.assertDataflow(() => ({
|
||||||
|
|
||||||
it('capture with type at top', () => expectCodeEqual(`during $v: T => { ok() }`, `
|
it('capture with type at top', () => expectCodeEqual(`during $v: T => { ok() }`, `
|
||||||
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.bind((__SYNDICATE__.QuasiValue._)))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.bind((__SYNDICATE__.QuasiValue._)))),
|
||||||
observer: __SYNDICATE__.Turn.ref(__SYNDICATE__.assertionFacetObserver(
|
observer: __SYNDICATE__.Turn.ref(__SYNDICATE__.assertionFacetObserver(
|
||||||
|
@ -191,7 +205,7 @@ describe('once', () => {
|
||||||
__SYNDICATE__.Turn.active.facet(() => {
|
__SYNDICATE__.Turn.active.facet(() => {
|
||||||
const __once_facet = __SYNDICATE__.Turn.activeFacet;
|
const __once_facet = __SYNDICATE__.Turn.activeFacet;
|
||||||
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
||||||
observer: __SYNDICATE__.Turn.ref({
|
observer: __SYNDICATE__.Turn.ref({
|
||||||
|
@ -210,7 +224,7 @@ __SYNDICATE__.Turn.active.facet(() => {
|
||||||
__SYNDICATE__.Turn.active.facet(() => {
|
__SYNDICATE__.Turn.active.facet(() => {
|
||||||
const __once_facet = __SYNDICATE__.Turn.activeFacet;
|
const __once_facet = __SYNDICATE__.Turn.activeFacet;
|
||||||
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
__SYNDICATE__.Turn.active.assertDataflow(() => ({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
||||||
observer: __SYNDICATE__.Turn.ref({
|
observer: __SYNDICATE__.Turn.ref({
|
||||||
|
@ -233,7 +247,7 @@ describe('on', () => {
|
||||||
text.node.focus();
|
text.node.focus();
|
||||||
}`, `__SYNDICATE__.Turn.active.assertDataflow(() => (isLast.value) ?
|
}`, `__SYNDICATE__.Turn.active.assertDataflow(() => (isLast.value) ?
|
||||||
({
|
({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.ctor(S.Focus, (__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(entity)))))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.ctor(S.Focus, (__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(entity)))))),
|
||||||
observer: __SYNDICATE__.Turn.ref({
|
observer: __SYNDICATE__.Turn.ref({
|
||||||
|
@ -256,7 +270,7 @@ describe('on', () => {
|
||||||
it('asserted with guard', () => expectCodeEqual(`on asserted P when (someTest) => x;`, `
|
it('asserted with guard', () => expectCodeEqual(`on asserted P when (someTest) => x;`, `
|
||||||
__SYNDICATE__.Turn.active.assertDataflow(() => (someTest) ?
|
__SYNDICATE__.Turn.active.assertDataflow(() => (someTest) ?
|
||||||
({
|
({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget(),
|
||||||
assertion: __SYNDICATE__.Observe({
|
assertion: __SYNDICATE__.Observe({
|
||||||
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
pattern: __SYNDICATE__.QuasiValue.finish((__SYNDICATE__.QuasiValue.lit(__SYNDICATE__.fromJS(P)))),
|
||||||
observer: __SYNDICATE__.Turn.ref({
|
observer: __SYNDICATE__.Turn.ref({
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Pos = Syntax.Pos;
|
||||||
|
|
||||||
import * as Syndicate from '@syndicate-lang/core';
|
import * as Syndicate from '@syndicate-lang/core';
|
||||||
Object.defineProperty(globalThis, 'currentSyndicateTarget', {
|
Object.defineProperty(globalThis, 'currentSyndicateTarget', {
|
||||||
value: Syndicate.Dataspace.local,
|
value: () => Syndicate.Dataspace.local,
|
||||||
writable: false,
|
writable: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue