Browse Source

The Great Renaming: Pointer -> Embedded

main
Tony Garnock-Jones 4 months ago
parent
commit
5cd3198739
  1. 4
      package.json
  2. 6
      schemas/box-protocol.prs
  3. 6
      schemas/dataspace.prs
  4. 6
      schemas/gatekeeper.prs
  5. 4
      schemas/protocol.prs
  6. 6
      schemas/secure-chat-protocol.prs
  7. 2
      schemas/simple-chat-protocol.prs
  8. 4
      schemas/sturdy.prs
  9. 2
      schemas/worker.prs
  10. 4
      src/examples/box.ts
  11. 4
      src/examples/client.ts
  12. 6
      src/examples/main.ts
  13. 4
      src/examples/secure-chat-client.ts
  14. 14
      src/examples/secure-chat-moderator.ts
  15. 4
      src/examples/simple-chat.ts
  16. 2
      src/examples/sturdy-demo.ts
  17. 8
      src/gen/box-protocol.ts
  18. 14
      src/gen/dataspace.ts
  19. 24
      src/gen/gatekeeper.ts
  20. 20
      src/gen/protocol.ts
  21. 30
      src/gen/secure-chat-protocol.ts
  22. 8
      src/gen/simple-chat-protocol.ts
  23. 84
      src/gen/sturdy.ts
  24. 6
      src/gen/worker.ts
  25. 4
      src/runtime/bag.ts
  26. 20
      src/runtime/rewrite.ts
  27. 4
      src/tools/attenuate.ts
  28. 12
      src/transport/protocol.ts
  29. 12
      src/transport/relay.ts
  30. 12
      src/transport/sturdy.ts
  31. 20
      yarn.lock

4
package.json

@ -6,8 +6,8 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@preserves/core": "^0.14.0",
"@preserves/schema": "^0.7.0"
"@preserves/core": "^0.15.0",
"@preserves/schema": "^0.8.1"
},
"scripts": {
"regenerate": "rm -rf ./src/gen && preserves-schema-ts --module Actor=./src/runtime/actor.ts --output ./src/gen './schemas/**/*.prs'",

6
schemas/box-protocol.prs

@ -1,9 +1,9 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
BoxState = <BoxState @value int>.
SetBox = <SetBox @value int>.
; BoxCap = BoxState / <Observe =SetBox @observer ref>.
; ClientCap = SetBox / <Observe =BoxState @observer ref>.
; BoxCap = BoxState / <Observe =SetBox @observer embedded>.
; ClientCap = SetBox / <Observe =BoxState @observer embedded>.
.

6
schemas/dataspace.prs

@ -1,9 +1,9 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
;As implemented
Observe = <Observe @label symbol @observer ref>.
Observe = <Observe @label symbol @observer embedded>.
; ;As will be implemented soon
; Observe = <Observe @pattern Pattern @observer ref>.
; Observe = <Observe @pattern Pattern @observer embedded>.
.

6
schemas/gatekeeper.prs

@ -1,5 +1,5 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
Resolve = <resolve @sturdyref sturdy.SturdyRef @observer ref>.
Bind = <bind @oid any @key bytes @target ref>.
Resolve = <resolve @sturdyref sturdy.SturdyRef @observer embedded>.
Bind = <bind @oid any @key bytes @target embedded>.

4
schemas/protocol.prs

@ -1,5 +1,5 @@
version 1 .
pointer sturdy.WireRef .
embeddedType sturdy.WireRef .
Assertion = any .
Handle = int .
@ -11,4 +11,4 @@ TurnEvent = [@oid Oid @event Event].
Assert = <assert @assertion Assertion @handle Handle>.
Retract = <retract @handle Handle>.
Message = <message @body Assertion>.
Sync = <sync @peer ref>.
Sync = <sync @peer embedded>.

6
schemas/secure-chat-protocol.prs

@ -1,11 +1,11 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
UserId = int .
Join = <joinedUser @uid UserId @handle ref>.
Join = <joinedUser @uid UserId @handle embedded>.
NickClaim = <claimNick @uid UserId @name string @k ref>.
NickClaim = <claimNick @uid UserId @name string @k embedded>.
UserInfo = <user @uid UserId @name string>.

2
schemas/simple-chat-protocol.prs

@ -1,5 +1,5 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
Present = <Present @username string>.
Says = <Says @who string @what string>.

4
schemas/sturdy.prs

@ -26,10 +26,10 @@ CDict = <dict>.
Lit = <lit @value any>.
Pattern = PDiscard / PAtom / PPointer / PBind / PAnd / PNot / Lit / PCompound .
Pattern = PDiscard / PAtom / PEmbedded / PBind / PAnd / PNot / Lit / PCompound .
PDiscard = <_>.
PAtom = =Boolean / =Float / =Double / =SignedInteger / =String / =ByteString / =Symbol .
PPointer = =Pointer .
PEmbedded = =Embedded .
PBind = <bind @name symbol @pattern Pattern>.
PAnd = <and [@patterns Pattern ...]>.
PNot = <not @pattern Pattern>.

2
schemas/worker.prs

@ -1,4 +1,4 @@
version 1 .
pointer Actor.Ref .
embeddedType Actor.Ref .
Instance = <Instance @name string @argument any>.

4
src/examples/box.ts

@ -1,4 +1,4 @@
import { Pointer } from "@preserves/core";
import { Embedded } from "@preserves/core";
import { BoxState, $SetBox, fromBoxState } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
@ -7,7 +7,7 @@ let startTime = Date.now();
let prevValue = 0;
export default function (t: Turn, arg: Assertion) {
const [ds_p, LIMIT, REPORT_EVERY]: [Pointer<Ref>, number, number] = Array.isArray(arg) && arg.length === 3
const [ds_p, LIMIT, REPORT_EVERY]: [Embedded<Ref>, number, number] = Array.isArray(arg) && arg.length === 3
? arg as any
: [arg, 50000, 2500];
const ds = ds_p.embeddedValue;

4
src/examples/client.ts

@ -1,9 +1,9 @@
import { Pointer } from "@preserves/core";
import { Embedded } from "@preserves/core";
import { $BoxState, fromSetBox, SetBox } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { Assertion, Ref, Turn } from "../runtime/actor.js";
export default function (t: Turn, ds_p: Pointer<Ref>) {
export default function (t: Turn, ds_p: Embedded<Ref>) {
const ds = ds_p.embeddedValue;
console.log('Spawning Client');
let count = 0;

6
src/examples/main.ts

@ -1,7 +1,7 @@
import { Actor, Assertion, Turn } from '../runtime/actor.js';
import { Dictionary, embed } from '@preserves/core';
import { Dataspace } from '../runtime/dataspace.js';
import { _ptr, attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from '../runtime/rewrite.js';
import { _embedded, attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from '../runtime/rewrite.js';
import { $BoxState, $SetBox } from '../gen/box-protocol.js';
import { $Observe } from '../gen/dataspace.js';
import { spawnWorker } from '../worker/index.js';
@ -38,7 +38,7 @@ new Actor(async (t: Turn) => {
})),
Pattern.PCompound(PCompound({
ctor: ConstructorSpec.CRec(CRec({ label: $Observe, arity: 2 })),
members: new Dictionary<_ptr, Pattern>([
members: new Dictionary<_embedded, Pattern>([
[0, Pattern.Lit(Lit($SetBox))]])
}))));
@ -51,7 +51,7 @@ new Actor(async (t: Turn) => {
})),
Pattern.PCompound(PCompound({
ctor: ConstructorSpec.CRec(CRec({ label: $Observe, arity: 2 })),
members: new Dictionary<_ptr, Pattern>([
members: new Dictionary<_embedded, Pattern>([
[0, Pattern.Lit(Lit($BoxState))]])
}))));

4
src/examples/secure-chat-client.ts

@ -2,9 +2,9 @@ import { $joinedUser, $says, $user, asJoin, asSays, asUserInfo, fromNickClaim, f
import { during, observe } from "../runtime/dataspace.js";
import { Assertion, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
import { Pointer } from "@preserves/core";
import { Embedded } from "@preserves/core";
export default function (t: Turn, ds_ptr: Pointer<Ref>) {
export default function (t: Turn, ds_ptr: Embedded<Ref>) {
const ds = ds_ptr.embeddedValue;
observe(t, ds, $joinedUser, during(async (t, j0) => {
const j = asJoin(j0);

14
src/examples/secure-chat-moderator.ts

@ -14,12 +14,12 @@ import {
} from "../gen/secure-chat-protocol.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { observe, during, $Observe, asObserve, Dataspace } from "../runtime/dataspace.js";
import { attenuate, rfilter, pRec, pPointer, pString, pLit } from "../runtime/rewrite.js";
import { attenuate, rfilter, pRec, pEmbedded, pString, pLit } from "../runtime/rewrite.js";
import { attenuate as sturdyAttenuate, KEY_LENGTH, sturdyEncode, fromSturdyRef, mint } from "../transport/sturdy.js";
import { Bind, fromBind } from "../gen/gatekeeper.js";
import { Bytes, Pointer } from "@preserves/core";
import { Bytes, Embedded } from "@preserves/core";
export default function (t: Turn, gatekeeperDs_ptr: Pointer<Ref>) {
export default function (t: Turn, gatekeeperDs_ptr: Embedded<Ref>) {
const gatekeeperDs = gatekeeperDs_ptr.embeddedValue;
const ds = t.ref(new Dataspace());
@ -28,7 +28,7 @@ export default function (t: Turn, gatekeeperDs_ptr: Pointer<Ref>) {
const chatKey = new Bytes(KEY_LENGTH);
t.assert(gatekeeperDs, fromBind(Bind({ oid: chatOid, key: chatKey, target: ds })));
mint(chatOid, chatKey).then(async r => {
r = await sturdyAttenuate(r, rfilter(pRec($Observe, pLit($joinedUser), pPointer())));
r = await sturdyAttenuate(r, rfilter(pRec($Observe, pLit($joinedUser), pEmbedded())));
console.log(fromSturdyRef(r).asPreservesText());
console.log(sturdyEncode(fromSturdyRef(r)).toHex());
});
@ -45,9 +45,9 @@ export default function (t: Turn, gatekeeperDs_ptr: Pointer<Ref>) {
t.assert(o.observer, fromJoin(Join({
uid,
handle: attenuate(ds, rfilter(
pRec($Observe, pLit($user), pPointer()),
pRec($Observe, pLit($says), pPointer()),
pRec($claimNick, pLit(uid), pString(), pPointer()),
pRec($Observe, pLit($user), pEmbedded()),
pRec($Observe, pLit($says), pEmbedded()),
pRec($claimNick, pLit(uid), pString(), pEmbedded()),
pRec($says, pLit(uid), pString()))),
})));
let infoHandle: Handle | undefined;

4
src/examples/simple-chat.ts

@ -2,9 +2,9 @@ import { $Present, $Says, asPresent, asSays, fromPresent, fromSays, Present, Say
import { during, observe } from "../runtime/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
import { Pointer } from "@preserves/core";
import { Embedded } from "@preserves/core";
export default function (t: Turn, ds_ptr: Pointer<Ref>) {
export default function (t: Turn, ds_ptr: Embedded<Ref>) {
const ds = ds_ptr.embeddedValue;
let username = '';

2
src/examples/sturdy-demo.ts

@ -14,7 +14,7 @@ async function main() {
label: Symbol.for('says'),
arity: 2
})),
members: new Dictionary<RW._ptr, RW.Pattern>([
members: new Dictionary<RW._embedded, RW.Pattern>([
[0, RW.Pattern.Lit(RW.Lit('Tony'))]])
}))
})),

8
src/gen/box-protocol.ts

@ -4,9 +4,9 @@ import * as _i_Actor from "../runtime/actor";
export const $BoxState = Symbol.for("BoxState");
export const $SetBox = Symbol.for("SetBox");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type BoxState = {"value": number};
@ -25,7 +25,7 @@ export function asBoxState(v: _val): BoxState {
export function toBoxState(v: _val): undefined | BoxState {
let result: undefined | BoxState;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $BoxState) ? null : void 0;
if (_tmp0 !== void 0) {
@ -47,7 +47,7 @@ export function asSetBox(v: _val): SetBox {
export function toSetBox(v: _val): undefined | SetBox {
let result: undefined | SetBox;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $SetBox) ? null : void 0;
if (_tmp0 !== void 0) {

14
src/gen/dataspace.ts

@ -3,14 +3,14 @@ import * as _i_Actor from "../runtime/actor";
export const $Observe = Symbol.for("Observe");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type Observe = {"label": symbol, "observer": _ptr};
export type Observe = {"label": symbol, "observer": _embedded};
export function Observe({label, observer}: {label: symbol, observer: _ptr}): Observe {return {"label": label, "observer": observer};}
export function Observe({label, observer}: {label: symbol, observer: _embedded}): Observe {return {"label": label, "observer": observer};}
export function asObserve(v: _val): Observe {
let result = toObserve(v);
@ -20,15 +20,15 @@ export function asObserve(v: _val): Observe {
export function toObserve(v: _val): undefined | Observe {
let result: undefined | Observe;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Observe) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (symbol) | undefined;
_tmp1 = typeof v[0] === 'symbol' ? v[0] : void 0;
if (_tmp1 !== void 0) {
let _tmp2: (_ptr) | undefined;
_tmp2 = _.isPointer<_ptr>(v[1]) ? v[1].embeddedValue : void 0;
let _tmp2: (_embedded) | undefined;
_tmp2 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp2 !== void 0) {result = {"label": _tmp1, "observer": _tmp2};};
};
};

24
src/gen/gatekeeper.ts

@ -5,18 +5,18 @@ import * as _i_sturdy from "./sturdy";
export const $bind = Symbol.for("bind");
export const $resolve = Symbol.for("resolve");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type Resolve = {"sturdyref": _i_sturdy.SturdyRef, "observer": _ptr};
export type Resolve = {"sturdyref": _i_sturdy.SturdyRef, "observer": _embedded};
export type Bind = {"oid": _val, "key": _.Bytes, "target": _ptr};
export type Bind = {"oid": _val, "key": _.Bytes, "target": _embedded};
export function Resolve({sturdyref, observer}: {sturdyref: _i_sturdy.SturdyRef, observer: _ptr}): Resolve {return {"sturdyref": sturdyref, "observer": observer};}
export function Resolve({sturdyref, observer}: {sturdyref: _i_sturdy.SturdyRef, observer: _embedded}): Resolve {return {"sturdyref": sturdyref, "observer": observer};}
export function Bind({oid, key, target}: {oid: _val, key: _.Bytes, target: _ptr}): Bind {return {"oid": oid, "key": key, "target": target};}
export function Bind({oid, key, target}: {oid: _val, key: _.Bytes, target: _embedded}): Bind {return {"oid": oid, "key": key, "target": target};}
export function asResolve(v: _val): Resolve {
let result = toResolve(v);
@ -26,15 +26,15 @@ export function asResolve(v: _val): Resolve {
export function toResolve(v: _val): undefined | Resolve {
let result: undefined | Resolve;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $resolve) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_i_sturdy.SturdyRef) | undefined;
_tmp1 = _i_sturdy.toSturdyRef(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (_ptr) | undefined;
_tmp2 = _.isPointer<_ptr>(v[1]) ? v[1].embeddedValue : void 0;
let _tmp2: (_embedded) | undefined;
_tmp2 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp2 !== void 0) {result = {"sturdyref": _tmp1, "observer": _tmp2};};
};
};
@ -54,7 +54,7 @@ export function asBind(v: _val): Bind {
export function toBind(v: _val): undefined | Bind {
let result: undefined | Bind;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $bind) ? null : void 0;
if (_tmp0 !== void 0) {
@ -64,8 +64,8 @@ export function toBind(v: _val): undefined | Bind {
let _tmp2: (_.Bytes) | undefined;
_tmp2 = _.Bytes.isBytes(v[1]) ? v[1] : void 0;
if (_tmp2 !== void 0) {
let _tmp3: (_ptr) | undefined;
_tmp3 = _.isPointer<_ptr>(v[2]) ? v[2].embeddedValue : void 0;
let _tmp3: (_embedded) | undefined;
_tmp3 = _.isEmbedded<_embedded>(v[2]) ? v[2].embeddedValue : void 0;
if (_tmp3 !== void 0) {result = {"oid": _tmp1, "key": _tmp2, "target": _tmp3};};
};
};

20
src/gen/protocol.ts

@ -6,9 +6,9 @@ export const $message = Symbol.for("message");
export const $retract = Symbol.for("retract");
export const $sync = Symbol.for("sync");
export type _ptr = _i_sturdy.WireRef;
export type _embedded = _i_sturdy.WireRef;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type Assertion = _val;
@ -33,7 +33,7 @@ export type Retract = {"handle": Handle};
export type Message = {"body": Assertion};
export type Sync = {"peer": _ptr};
export type Sync = {"peer": _embedded};
export function Assertion(value: _val): Assertion {return value;}
@ -59,7 +59,7 @@ export function Retract(handle: Handle): Retract {return {"handle": handle};}
export function Message(body: Assertion): Message {return {"body": body};}
export function Sync(peer: _ptr): Sync {return {"peer": peer};}
export function Sync(peer: _embedded): Sync {return {"peer": peer};}
export function asAssertion(v: _val): Assertion {
let result = toAssertion(v);
@ -202,7 +202,7 @@ export function asAssert(v: _val): Assert {
export function toAssert(v: _val): undefined | Assert {
let result: undefined | Assert;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $assert) ? null : void 0;
if (_tmp0 !== void 0) {
@ -230,7 +230,7 @@ export function asRetract(v: _val): Retract {
export function toRetract(v: _val): undefined | Retract {
let result: undefined | Retract;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $retract) ? null : void 0;
if (_tmp0 !== void 0) {
@ -252,7 +252,7 @@ export function asMessage(v: _val): Message {
export function toMessage(v: _val): undefined | Message {
let result: undefined | Message;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $message) ? null : void 0;
if (_tmp0 !== void 0) {
@ -274,12 +274,12 @@ export function asSync(v: _val): Sync {
export function toSync(v: _val): undefined | Sync {
let result: undefined | Sync;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $sync) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_ptr) | undefined;
_tmp1 = _.isPointer<_ptr>(v[0]) ? v[0].embeddedValue : void 0;
let _tmp1: (_embedded) | undefined;
_tmp1 = _.isEmbedded<_embedded>(v[0]) ? v[0].embeddedValue : void 0;
if (_tmp1 !== void 0) {result = {"peer": _tmp1};};
};
};

30
src/gen/secure-chat-protocol.ts

@ -7,15 +7,15 @@ export const $nickConflict = Symbol.for("nickConflict");
export const $says = Symbol.for("says");
export const $user = Symbol.for("user");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type UserId = number;
export type Join = {"uid": UserId, "handle": _ptr};
export type Join = {"uid": UserId, "handle": _embedded};
export type NickClaim = {"uid": UserId, "name": string, "k": _ptr};
export type NickClaim = {"uid": UserId, "name": string, "k": _embedded};
export type UserInfo = {"uid": UserId, "name": string};
@ -26,9 +26,9 @@ export type NickConflict = null;
export function UserId(value: number): UserId {return value;}
export function Join({uid, handle}: {uid: UserId, handle: _ptr}): Join {return {"uid": uid, "handle": handle};}
export function Join({uid, handle}: {uid: UserId, handle: _embedded}): Join {return {"uid": uid, "handle": handle};}
export function NickClaim({uid, name, k}: {uid: UserId, name: string, k: _ptr}): NickClaim {return {"uid": uid, "name": name, "k": k};}
export function NickClaim({uid, name, k}: {uid: UserId, name: string, k: _embedded}): NickClaim {return {"uid": uid, "name": name, "k": k};}
export function UserInfo({uid, name}: {uid: UserId, name: string}): UserInfo {return {"uid": uid, "name": name};}
@ -60,15 +60,15 @@ export function asJoin(v: _val): Join {
export function toJoin(v: _val): undefined | Join {
let result: undefined | Join;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $joinedUser) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (UserId) | undefined;
_tmp1 = toUserId(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (_ptr) | undefined;
_tmp2 = _.isPointer<_ptr>(v[1]) ? v[1].embeddedValue : void 0;
let _tmp2: (_embedded) | undefined;
_tmp2 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp2 !== void 0) {result = {"uid": _tmp1, "handle": _tmp2};};
};
};
@ -86,7 +86,7 @@ export function asNickClaim(v: _val): NickClaim {
export function toNickClaim(v: _val): undefined | NickClaim {
let result: undefined | NickClaim;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $claimNick) ? null : void 0;
if (_tmp0 !== void 0) {
@ -96,8 +96,8 @@ export function toNickClaim(v: _val): undefined | NickClaim {
let _tmp2: (string) | undefined;
_tmp2 = typeof v[1] === 'string' ? v[1] : void 0;
if (_tmp2 !== void 0) {
let _tmp3: (_ptr) | undefined;
_tmp3 = _.isPointer<_ptr>(v[2]) ? v[2].embeddedValue : void 0;
let _tmp3: (_embedded) | undefined;
_tmp3 = _.isEmbedded<_embedded>(v[2]) ? v[2].embeddedValue : void 0;
if (_tmp3 !== void 0) {result = {"uid": _tmp1, "name": _tmp2, "k": _tmp3};};
};
};
@ -118,7 +118,7 @@ export function asUserInfo(v: _val): UserInfo {
export function toUserInfo(v: _val): undefined | UserInfo {
let result: undefined | UserInfo;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $user) ? null : void 0;
if (_tmp0 !== void 0) {
@ -144,7 +144,7 @@ export function asSays(v: _val): Says {
export function toSays(v: _val): undefined | Says {
let result: undefined | Says;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $says) ? null : void 0;
if (_tmp0 !== void 0) {
@ -170,7 +170,7 @@ export function asNickConflict(v: _val): NickConflict {
export function toNickConflict(v: _val): undefined | NickConflict {
let result: undefined | NickConflict;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $nickConflict) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};

8
src/gen/simple-chat-protocol.ts

@ -4,9 +4,9 @@ import * as _i_Actor from "../runtime/actor";
export const $Present = Symbol.for("Present");
export const $Says = Symbol.for("Says");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type Present = {"username": string};
@ -25,7 +25,7 @@ export function asPresent(v: _val): Present {
export function toPresent(v: _val): undefined | Present {
let result: undefined | Present;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Present) ? null : void 0;
if (_tmp0 !== void 0) {
@ -47,7 +47,7 @@ export function asSays(v: _val): Says {
export function toSays(v: _val): undefined | Says {
let result: undefined | Says;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Says) ? null : void 0;
if (_tmp0 !== void 0) {

84
src/gen/sturdy.ts

@ -5,8 +5,8 @@ export const $1 = 1;
export const $Boolean = Symbol.for("Boolean");
export const $ByteString = Symbol.for("ByteString");
export const $Double = Symbol.for("Double");
export const $Embedded = Symbol.for("Embedded");
export const $Float = Symbol.for("Float");
export const $Pointer = Symbol.for("Pointer");
export const $SignedInteger = Symbol.for("SignedInteger");
export const $String = Symbol.for("String");
export const $Symbol = Symbol.for("Symbol");
@ -23,9 +23,9 @@ export const $rec = Symbol.for("rec");
export const $ref = Symbol.for("ref");
export const $rewrite = Symbol.for("rewrite");
export type _ptr = any;
export type _embedded = any;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type SturdyRef = {"oid": _val, "caveatChain": Array<Attenuation>, "sig": _.Bytes};
@ -64,7 +64,7 @@ export type Lit = {"value": _val};
export type Pattern = (
{"_variant": "PDiscard", "value": PDiscard} |
{"_variant": "PAtom", "value": PAtom} |
{"_variant": "PPointer", "value": PPointer} |
{"_variant": "PEmbedded", "value": PEmbedded} |
{"_variant": "PBind", "value": PBind} |
{"_variant": "PAnd", "value": PAnd} |
{"_variant": "PNot", "value": PNot} |
@ -84,7 +84,7 @@ export type PAtom = (
{"_variant": "Symbol"}
);
export type PPointer = null;
export type PEmbedded = null;
export type PBind = {"name": symbol, "pattern": Pattern};
@ -94,7 +94,7 @@ export type PNot = {"pattern": Pattern};
export type PCompound = {"ctor": ConstructorSpec, "members": PCompoundMembers};
export type PCompoundMembers = _.KeyedDictionary<_val, Pattern, _ptr>;
export type PCompoundMembers = _.KeyedDictionary<_val, Pattern, _embedded>;
export type Template = (
{"_variant": "TRef", "value": TRef} |
@ -106,7 +106,7 @@ export type TRef = {"name": symbol};
export type TCompound = {"ctor": ConstructorSpec, "members": TCompoundMembers};
export type TCompoundMembers = _.KeyedDictionary<_val, Template, _ptr>;
export type TCompoundMembers = _.KeyedDictionary<_val, Template, _embedded>;
export function SturdyRef(
@ -148,7 +148,7 @@ export function Lit(value: _val): Lit {return {"value": value};}
export namespace Pattern {
export function PDiscard(value: PDiscard): Pattern {return {"_variant": "PDiscard", "value": value};};
export function PAtom(value: PAtom): Pattern {return {"_variant": "PAtom", "value": value};};
export function PPointer(value: PPointer): Pattern {return {"_variant": "PPointer", "value": value};};
export function PEmbedded(value: PEmbedded): Pattern {return {"_variant": "PEmbedded", "value": value};};
export function PBind(value: PBind): Pattern {return {"_variant": "PBind", "value": value};};
export function PAnd(value: PAnd): Pattern {return {"_variant": "PAnd", "value": value};};
export function PNot(value: PNot): Pattern {return {"_variant": "PNot", "value": value};};
@ -168,7 +168,7 @@ export namespace PAtom {
export function Symbol(): PAtom {return {"_variant": "Symbol"};};
}
export function PPointer(): PPointer {return null;}
export function PEmbedded(): PEmbedded {return null;}
export function PBind({name, pattern}: {name: symbol, pattern: Pattern}): PBind {return {"name": name, "pattern": pattern};}
@ -178,7 +178,7 @@ export function PNot(pattern: Pattern): PNot {return {"pattern": pattern};}
export function PCompound({ctor, members}: {ctor: ConstructorSpec, members: PCompoundMembers}): PCompound {return {"ctor": ctor, "members": members};}
export function PCompoundMembers(value: _.KeyedDictionary<_val, Pattern, _ptr>): PCompoundMembers {return value;}
export function PCompoundMembers(value: _.KeyedDictionary<_val, Pattern, _embedded>): PCompoundMembers {return value;}
export namespace Template {
export function TRef(value: TRef): Template {return {"_variant": "TRef", "value": value};};
@ -190,7 +190,7 @@ export function TRef(name: symbol): TRef {return {"name": name};}
export function TCompound({ctor, members}: {ctor: ConstructorSpec, members: TCompoundMembers}): TCompound {return {"ctor": ctor, "members": members};}
export function TCompoundMembers(value: _.KeyedDictionary<_val, Template, _ptr>): TCompoundMembers {return value;}
export function TCompoundMembers(value: _.KeyedDictionary<_val, Template, _embedded>): TCompoundMembers {return value;}
export function asSturdyRef(v: _val): SturdyRef {
let result = toSturdyRef(v);
@ -200,7 +200,7 @@ export function asSturdyRef(v: _val): SturdyRef {
export function toSturdyRef(v: _val): undefined | SturdyRef {
let result: undefined | SturdyRef;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $ref) ? null : void 0;
if (_tmp0 !== void 0) {
@ -296,7 +296,7 @@ export function asRewrite(v: _val): Rewrite {
export function toRewrite(v: _val): undefined | Rewrite {
let result: undefined | Rewrite;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $rewrite) ? null : void 0;
if (_tmp0 !== void 0) {
@ -324,7 +324,7 @@ export function asAlts(v: _val): Alts {
export function toAlts(v: _val): undefined | Alts {
let result: undefined | Alts;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $or) ? null : void 0;
if (_tmp0 !== void 0) {
@ -462,7 +462,7 @@ export function asCRec(v: _val): CRec {
export function toCRec(v: _val): undefined | CRec {
let result: undefined | CRec;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $rec) ? null : void 0;
if (_tmp0 !== void 0) {
@ -488,7 +488,7 @@ export function asCArr(v: _val): CArr {
export function toCArr(v: _val): undefined | CArr {
let result: undefined | CArr;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $arr) ? null : void 0;
if (_tmp0 !== void 0) {
@ -510,7 +510,7 @@ export function asCDict(v: _val): CDict {
export function toCDict(v: _val): undefined | CDict {
let result: undefined | CDict;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $dict) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
@ -528,7 +528,7 @@ export function asLit(v: _val): Lit {
export function toLit(v: _val): undefined | Lit {
let result: undefined | Lit;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $lit) ? null : void 0;
if (_tmp0 !== void 0) {
@ -558,9 +558,9 @@ export function toPattern(v: _val): undefined | Pattern {
_tmp1 = toPAtom(v);
if (_tmp1 !== void 0) {result = {"_variant": "PAtom", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (PPointer) | undefined;
_tmp2 = toPPointer(v);
if (_tmp2 !== void 0) {result = {"_variant": "PPointer", "value": _tmp2};};
let _tmp2: (PEmbedded) | undefined;
_tmp2 = toPEmbedded(v);
if (_tmp2 !== void 0) {result = {"_variant": "PEmbedded", "value": _tmp2};};
if (result === void 0) {
let _tmp3: (PBind) | undefined;
_tmp3 = toPBind(v);
@ -595,7 +595,7 @@ export function fromPattern(_v: Pattern): _val {
switch (_v._variant) {
case "PDiscard": {return fromPDiscard(_v.value);};
case "PAtom": {return fromPAtom(_v.value);};
case "PPointer": {return fromPPointer(_v.value);};
case "PEmbedded": {return fromPEmbedded(_v.value);};
case "PBind": {return fromPBind(_v.value);};
case "PAnd": {return fromPAnd(_v.value);};
case "PNot": {return fromPNot(_v.value);};
@ -612,7 +612,7 @@ export function asPDiscard(v: _val): PDiscard {
export function toPDiscard(v: _val): undefined | PDiscard {
let result: undefined | PDiscard;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $_) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
@ -678,21 +678,21 @@ export function fromPAtom(_v: PAtom): _val {
};
}
export function asPPointer(v: _val): PPointer {
let result = toPPointer(v);
if (result === void 0) throw new TypeError(`Invalid PPointer: ${_.stringify(v)}`);
export function asPEmbedded(v: _val): PEmbedded {
let result = toPEmbedded(v);
if (result === void 0) throw new TypeError(`Invalid PEmbedded: ${_.stringify(v)}`);
return result;
}
export function toPPointer(v: _val): undefined | PPointer {
export function toPEmbedded(v: _val): undefined | PEmbedded {
let _tmp0: (null) | undefined;
let result: undefined | PPointer;
_tmp0 = _.is(v, $Pointer) ? null : void 0;
let result: undefined | PEmbedded;
_tmp0 = _.is(v, $Embedded) ? null : void 0;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromPPointer(_v: PPointer): _val {return $Pointer;}
export function fromPEmbedded(_v: PEmbedded): _val {return $Embedded;}
export function asPBind(v: _val): PBind {
let result = toPBind(v);
@ -702,7 +702,7 @@ export function asPBind(v: _val): PBind {
export function toPBind(v: _val): undefined | PBind {
let result: undefined | PBind;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $bind) ? null : void 0;
if (_tmp0 !== void 0) {
@ -728,7 +728,7 @@ export function asPAnd(v: _val): PAnd {
export function toPAnd(v: _val): undefined | PAnd {
let result: undefined | PAnd;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $and) ? null : void 0;
if (_tmp0 !== void 0) {
@ -763,7 +763,7 @@ export function asPNot(v: _val): PNot {
export function toPNot(v: _val): undefined | PNot {
let result: undefined | PNot;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $not) ? null : void 0;
if (_tmp0 !== void 0) {
@ -785,7 +785,7 @@ export function asPCompound(v: _val): PCompound {
export function toPCompound(v: _val): undefined | PCompound {
let result: undefined | PCompound;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $compound) ? null : void 0;
if (_tmp0 !== void 0) {
@ -815,9 +815,9 @@ export function asPCompoundMembers(v: _val): PCompoundMembers {
}
export function toPCompoundMembers(v: _val): undefined | PCompoundMembers {
let _tmp0: (_.KeyedDictionary<_val, Pattern, _ptr>) | undefined;
let _tmp0: (_.KeyedDictionary<_val, Pattern, _embedded>) | undefined;
let result: undefined | PCompoundMembers;
if (_.Dictionary.isDictionary<_ptr>(v)) {
if (_.Dictionary.isDictionary<_embedded>(v)) {
_tmp0 = new _.KeyedDictionary();
for (const [_tmp2, _tmp1] of v) {
let _tmp3: (_val) | undefined;
@ -836,7 +836,7 @@ export function toPCompoundMembers(v: _val): undefined | PCompoundMembers {
}
export function fromPCompoundMembers(_v: PCompoundMembers): _val {
return new _.Dictionary<_ptr>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromPattern(v)]));
return new _.Dictionary<_embedded>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromPattern(v)]));
}
export function asTemplate(v: _val): Template {
@ -879,7 +879,7 @@ export function asTRef(v: _val): TRef {
export function toTRef(v: _val): undefined | TRef {
let result: undefined | TRef;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $ref) ? null : void 0;
if (_tmp0 !== void 0) {
@ -901,7 +901,7 @@ export function asTCompound(v: _val): TCompound {
export function toTCompound(v: _val): undefined | TCompound {
let result: undefined | TCompound;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $compound) ? null : void 0;
if (_tmp0 !== void 0) {
@ -931,9 +931,9 @@ export function asTCompoundMembers(v: _val): TCompoundMembers {
}
export function toTCompoundMembers(v: _val): undefined | TCompoundMembers {
let _tmp0: (_.KeyedDictionary<_val, Template, _ptr>) | undefined;
let _tmp0: (_.KeyedDictionary<_val, Template, _embedded>) | undefined;
let result: undefined | TCompoundMembers;
if (_.Dictionary.isDictionary<_ptr>(v)) {
if (_.Dictionary.isDictionary<_embedded>(v)) {
_tmp0 = new _.KeyedDictionary();
for (const [_tmp2, _tmp1] of v) {
let _tmp3: (_val) | undefined;
@ -952,6 +952,6 @@ export function toTCompoundMembers(v: _val): undefined | TCompoundMembers {
}
export function fromTCompoundMembers(_v: TCompoundMembers): _val {
return new _.Dictionary<_ptr>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromTemplate(v)]));
return new _.Dictionary<_embedded>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromTemplate(v)]));
}

6
src/gen/worker.ts

@ -3,9 +3,9 @@ import * as _i_Actor from "../runtime/actor";
export const $Instance = Symbol.for("Instance");
export type _ptr = _i_Actor.Ref;
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type _val = _.Value<_embedded>;
export type Instance = {"name": string, "argument": _val};
@ -20,7 +20,7 @@ export function asInstance(v: _val): Instance {
export function toInstance(v: _val): undefined | Instance {
let result: undefined | Instance;
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Instance) ? null : void 0;
if (_tmp0 !== void 0) {

4
src/runtime/bag.ts

@ -1,6 +1,6 @@
// Bags and Deltas (which are Bags where item-counts can be negative).
import { Value, Set, Dictionary, GenericPointer } from '@preserves/core';
import { Value, Set, Dictionary, GenericEmbedded } from '@preserves/core';
export enum ChangeDescription {
PRESENT_TO_ABSENT = -1,
@ -9,7 +9,7 @@ export enum ChangeDescription {
PRESENT_TO_PRESENT = 2,
}
export class Bag<T extends object = GenericPointer> {
export class Bag<T extends object = GenericEmbedded> {
_items: Dictionary<T, number>;
constructor(s?: Set<T>) {

20
src/runtime/rewrite.ts

@ -1,5 +1,5 @@
import type { Assertion, Handle, Ref, Turn } from "./actor.js";
import { Bytes, Dictionary, DoubleFloat, IdentityMap, is, isPointer, Record, SingleFloat, Tuple } from "@preserves/core";
import { Bytes, Dictionary, DoubleFloat, IdentityMap, is, isEmbedded, Record, SingleFloat, Tuple } from "@preserves/core";
import {
Alts,
@ -17,13 +17,13 @@ import {
PCompoundMembers,
PDiscard,
PNot,
PPointer,
PEmbedded,
Pattern,
Rewrite,
TRef,
Template,
_val,
_ptr,
_embedded,
} from '../gen/sturdy.js';
export * from '../gen/sturdy.js';
@ -46,8 +46,8 @@ export function match(p: Pattern, v: Assertion): Bindings | null {
case 'String': return typeof v === 'string';
case 'Symbol': return typeof v === 'symbol';
}
case 'PPointer':
return isPointer(v);
case 'PEmbedded':
return isEmbedded(v);
case 'PBind':
if (walk(p.value.pattern, v)) {
bindings[p.value.name.asPreservesText()] = v;
@ -234,21 +234,21 @@ export function forwarder(t: Turn, ref: Ref): { proxy: Ref, revoker: Ref } {
export function pRec(label: _val, ... members: Array<Pattern>): Pattern {
return Pattern.PCompound(PCompound({
ctor: ConstructorSpec.CRec(CRec({ label: label, arity: members.length })),
members: PCompoundMembers(new Dictionary<_ptr, Pattern>(
members: PCompoundMembers(new Dictionary<_embedded, Pattern>(
members.map((p, i) => [i, p] as const).filter(e => e[1]._variant !== 'PDiscard')))}));
}
export function pArr(... members: Array<Pattern>): Pattern {
return Pattern.PCompound(PCompound({
ctor: ConstructorSpec.CArr(CArr(members.length)),
members: PCompoundMembers(new Dictionary<_ptr, Pattern>(
members: PCompoundMembers(new Dictionary<_embedded, Pattern>(
members.map((p, i) => [i, p] as const).filter(e => e[1]._variant !== 'PDiscard')))}));
}
export function pDict(... entries: [_val, Pattern][]): Pattern {
return Pattern.PCompound(PCompound({
ctor: ConstructorSpec.CDict(CDict()),
members: PCompoundMembers(new Dictionary<_ptr, Pattern>(entries))}));
members: PCompoundMembers(new Dictionary<_embedded, Pattern>(entries))}));
}
export function pLit(value: _val): Pattern {
@ -267,8 +267,8 @@ export function pBind(name: symbol, pattern: Pattern): Pattern {
return Pattern.PBind(PBind({ name, pattern }));
}
export function pPointer(): Pattern {
return Pattern.PPointer(PPointer());
export function pEmbedded(): Pattern {
return Pattern.PEmbedded(PEmbedded());
}
export function pSymbol(): Pattern {

4
src/tools/attenuate.ts

@ -1,10 +1,10 @@
import { Bytes, Reader } from '@preserves/core';
import { fromSturdyRef, toSturdyRef, toCaveat, attenuate, sturdyDecode, sturdyEncode, _ptr } from '../transport/sturdy.js';
import { fromSturdyRef, toSturdyRef, toCaveat, attenuate, sturdyDecode, sturdyEncode, _embedded } from '../transport/sturdy.js';
const [ base, pat ] = process.argv.slice(2);
const baseCap = toSturdyRef(sturdyDecode(Bytes.fromHex(base ?? '')));
if (baseCap === void 0) throw new Error("Cannot decode sturdyref");
const cs0 = new Reader<_ptr>(pat).next();
const cs0 = new Reader<_embedded>(pat).next();
if (!Array.isArray(cs0)) throw new Error("Expected array of caveats");
const cs = cs0.map(c => toCaveat(c) ?? (()=>{ throw new Error("Cannot decode caveat"); })());
attenuate(baseCap, ... cs).then(derived => {

12
src/transport/protocol.ts

@ -1,24 +1,24 @@
import * as S from '../gen/sturdy.js';
import * as IO from '../gen/protocol.js';
import { Ref } from '../runtime/actor.js';
import { Decoder, DecoderState, Encoder, EncoderState, GenericPointer, neverPointerType, PointerType, Value } from '@preserves/core';
import { Decoder, DecoderState, Encoder, EncoderState, GenericEmbedded, neverEmbeddedType, EmbeddedType, Value } from '@preserves/core';
export type WireSymbol = { oid: IO.Oid, ref: Ref, count: number };
export const wireRefPointerType: PointerType<S.WireRef> = {
export const wireRefEmbeddedType: EmbeddedType<S.WireRef> = {
decode(s: DecoderState): S.WireRef {
return S.asWireRef(new Decoder<any>(s).next());
},
encode(s: EncoderState, v: S.WireRef): void {
new Encoder<any>(s, neverPointerType).push(S.fromWireRef(v));
new Encoder<any>(s, neverEmbeddedType).push(S.fromWireRef(v));
},
fromValue(v: Value<GenericPointer>): S.WireRef {
fromValue(v: Value<GenericEmbedded>): S.WireRef {
return S.asWireRef(v as S._val);
},
toValue(v: S.WireRef): Value<GenericPointer> {
return S.fromWireRef(v) as Value<GenericPointer>;
toValue(v: S.WireRef): Value<GenericEmbedded> {
return S.fromWireRef(v) as Value<GenericEmbedded>;
}
};

12
src/transport/relay.ts

@ -1,7 +1,7 @@
import { Actor, Assertion, Entity, Facet, Handle, Ref, Turn } from '../runtime/actor.js';
import { BytesLike, Decoder, Dictionary, embed, encode, IdentityMap, mapPointers, underlying, Value } from '@preserves/core';
import { BytesLike, Decoder, Dictionary, embed, encode, IdentityMap, mapEmbeddeds, underlying, Value } from '@preserves/core';
import * as IO from '../gen/protocol.js';
import { wireRefPointerType, WireSymbol } from './protocol.js';
import { wireRefEmbeddedType, WireSymbol } from './protocol.js';
import { queueTask } from '../runtime/task.js';
import { attenuate } from '../runtime/rewrite.js';
import { fromAttenuation, WireRef } from '../gen/sturdy.js';
@ -137,7 +137,7 @@ export class Relay {
readonly decoder = new Decoder(void 0, {
includeAnnotations: false,
pointerDecode: wireRefPointerType,
embeddedDecode: wireRefEmbeddedType,
});
constructor(t: Turn, options: RelayOptions) {
@ -153,14 +153,14 @@ export class Relay {
rewriteOut(assertion: Assertion, transient: boolean): [Value<WireRef>, Array<WireSymbol>]
{
const exported: Array<WireSymbol> = [];
const rewritten = mapPointers(assertion, r => embed(this.rewriteRefOut(r, transient, exported)));
const rewritten = mapEmbeddeds(assertion, r => embed(this.rewriteRefOut(r, transient, exported)));
return [rewritten, exported];
}
rewriteIn(t: Turn, a: Value<WireRef>): [Assertion, Array<WireSymbol>]
{
const imported: Array<WireSymbol> = [];
const rewritten = mapPointers(a, r => embed(this.rewriteRefIn(t, r, imported)));
const rewritten = mapEmbeddeds(a, r => embed(this.rewriteRefIn(t, r, imported)));
return [rewritten, imported];
}
@ -234,7 +234,7 @@ export class Relay {
if (this.debug) console.log('OUT', IO.fromTurn(this.pendingTurn).asPreservesText());
this.w(underlying(encode(IO.fromTurn(this.pendingTurn), {
canonical: true,
pointerEncode: wireRefPointerType,
embeddedEncode: wireRefEmbeddedType,
})));
this.pendingTurn = [];
});

12
src/transport/sturdy.ts

@ -7,7 +7,7 @@
// California: Internet Society, 2014.
import { mac } from './cryptography.js';
import { Bytes, decode, encode, is, neverPointerType } from '@preserves/core';
import { Bytes, decode, encode, is, neverEmbeddedType } from '@preserves/core';
import * as S from '../gen/sturdy.js';
export * from '../gen/sturdy.js';
@ -15,22 +15,22 @@ export type SturdyValue = S._val;
export const KEY_LENGTH = 16; // 128 bits
export function pointerNotAllowed(): never {
export function embeddedNotAllowed(): never {
throw new Error("Embedded Ref not permitted in SturdyRef");
}
export function sturdyEncode(v: SturdyValue): Bytes {
return encode<S._ptr>(v, {
return encode<S._embedded>(v, {
canonical: true,
includeAnnotations: false,
pointerEncode: neverPointerType,
embeddedEncode: neverEmbeddedType,
});
}
export function sturdyDecode(bs: Bytes): SturdyValue {
return decode<S._ptr>(bs, {
return decode<S._embedded>(bs, {
includeAnnotations: false,
pointerDecode: neverPointerType,
embeddedDecode: neverEmbeddedType,
});