diff --git a/actor.ts b/actor.ts index 083e5a2..2688b76 100644 --- a/actor.ts +++ b/actor.ts @@ -101,6 +101,9 @@ export function isRef(v: any): v is Ref { } let nextActorId = 0; +// export function __setNextActorId(v: number) { +// nextActorId = v; +// } export class Actor { readonly id = nextActorId++; diff --git a/box-protocol.ts b/box-protocol.ts index 366c570..38f4d0c 100644 --- a/box-protocol.ts +++ b/box-protocol.ts @@ -1,7 +1,10 @@ import { Ref } from "actor"; import { Record } from "preserves"; +export const _BoxState = Symbol.for('BoxState'); export const BoxState = Record.makeConstructor<{value: number}, Ref>()( - Symbol.for('BoxState'), ['value']); + _BoxState, ['value']); + +export const _SetBox = Symbol.for('SetBox'); export const SetBox = Record.makeConstructor<{newValue: number}, Ref>()( - Symbol.for('SetBox'), ['newValue']); + _SetBox, ['newValue']); diff --git a/main.ts b/main.ts index d30d5a3..a2cf9c5 100644 --- a/main.ts +++ b/main.ts @@ -1,8 +1,9 @@ -import { Actor, Assertion, Turn } from './actor.js'; -import { Record } from 'preserves'; -import { Dataspace } from './dataspace.js'; +import { Actor, Assertion, attenuate, CRec, Lit, Pattern, PCompound, Ref, rfilter, Turn } from './actor.js'; +import { Dictionary, Record } from 'preserves'; +import { Dataspace, Observe } from './dataspace.js'; import { Worker } from 'worker_threads'; import { Relay, spawnRelay } from './relay.js'; +import { BoxState, SetBox } from './box-protocol.js'; const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()( Symbol.for('Instance'), ['moduleName', 'arg']); @@ -33,31 +34,37 @@ function spawnModule(t: Turn, moduleName: string, arg: Assertion) { m.default(t, arg)))); } +// __setNextActorId(1000); + Turn.for(new Actor(), async (t: Turn) => { const ds = t.ref(new Dataspace()); + const ds_for_box = attenuate( + ds, + rfilter(PCompound(CRec(BoxState.constructorInfo.label, + BoxState.constructorInfo.arity), + new Dictionary()), + PCompound(CRec(Observe.constructorInfo.label, + Observe.constructorInfo.arity), + new Dictionary([ + [0, Lit(SetBox.constructorInfo.label)]])))); + + const ds_for_client = attenuate( + ds, + rfilter(PCompound(CRec(SetBox.constructorInfo.label, + SetBox.constructorInfo.arity), + new Dictionary()), + PCompound(CRec(Observe.constructorInfo.label, + Observe.constructorInfo.arity), + new Dictionary([ + [0, Lit(BoxState.constructorInfo.label)]])))); + + // spawnModule(t, './box.js', [ds, 500000, 25000]); - spawnWorker(t, './box.js', [ds, 50000, 2500]); + spawnWorker(t, './box.js', [ds_for_box, 50000, 2500]); - spawnModule(t, './client.js', ds); - // spawnWorker(t, './client.js', ds); + // spawnModule(t, './client.js', ds_for_client); + spawnWorker(t, './client.js', ds_for_client); - // spawnBox(t, attenuate( - // ds, - // rfilter(PCompound(CRec(BoxState.constructorInfo.label, - // BoxState.constructorInfo.arity), - // new Dictionary()), - // PCompound(CRec(Observe.constructorInfo.label, - // Observe.constructorInfo.arity), - // new Dictionary([[0, Lit(SetBox.constructorInfo.label)]]))))); - - // spawnClient(t, attenuate( - // ds, - // rfilter(PCompound(CRec(SetBox.constructorInfo.label, - // SetBox.constructorInfo.arity), - // new Dictionary()), - // PCompound(CRec(Observe.constructorInfo.label, - // Observe.constructorInfo.arity), - // new Dictionary([[0, Lit(BoxState.constructorInfo.label)]]))))); });