Skip to content

Commit

Permalink
fix named
Browse files Browse the repository at this point in the history
  • Loading branch information
shumbo committed Aug 5, 2024
1 parent 3efa670 commit 02b5631
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ describe("core", () => {
await g([]);
expect(count).toBe(2);
});
test("naked", async () => {
let check = "";
const test: Choreography<Locations> = async ({ locally, multicast, naked, enclave }) => {
const msg = await locally("alice", () => "Hello, world!");
const mlv = await multicast(
"alice",
["bob"],
msg,
);
// @ts-expect-error: xx
naked(mlv);
enclave(["alice", "bob"], async ({ naked }) => {
check = naked(mlv);
return [];
},[])
return [];
};
const g = runner.compile(test);
await g([]);
expect(check).toBe("Hello, world!");
});
test("broadcast", async () => {
let count = 0;
const test: Choreography<Locations> = async ({ locally, broadcast }) => {
Expand Down
31 changes: 26 additions & 5 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ export class MultiplyLocated<T, L extends Location> {
protected phantom?: (x: L) => void;
}

export class Faceted<T, L extends Location> {
constructor(value: T, key: symbol) {
this.value = value;
this.key = key;
}
public getValue(key: symbol) {
if (this.key !== key) {
throw new Error("Invalid key");
}
return this.value;
}
protected value: T;
protected key: symbol;
protected phantom?: (x: L) => void;
}

/**
* The dependencies of a choreography
*/
Expand Down Expand Up @@ -106,8 +122,8 @@ export type Enclave<L extends Location> = <
args: Args,
) => Promise<Return>;

export type Naked<L extends Location> = <LL extends L, T>(
mlv: MultiplyLocated<T, LL>,
export type Naked<L extends Location> = <T>(
mlv: MultiplyLocated<T, L>,
) => T;

export type Multicast<L extends Location> = <
Expand Down Expand Up @@ -489,9 +505,6 @@ export class Projector<L extends Location, L1 extends L> {
}
};

const naked: Naked<L> = <LL extends L, T>(cv: MultiplyLocated<T, LL>) =>
cv.getValue(key);

const call: (t: Tag) => Call<L> =
(t: Tag) =>
async <
Expand All @@ -503,6 +516,8 @@ export class Projector<L extends Location, L1 extends L> {
a: Args,
) => {
const childTag = t.call();
const naked: Naked<LL> = <T>(cv: MultiplyLocated<T, LL>) =>
cv.getValue(key);
return await c(
wrapMethods((m) => ctxManager.checkContext(m), {
locally: locally(childTag),
Expand All @@ -517,6 +532,8 @@ export class Projector<L extends Location, L1 extends L> {
);
};

const naked: Naked<L> = <T>(cv: MultiplyLocated<T, L>) =>
cv.getValue(key);
const ret = await choreography(
wrapMethods((m) => ctxManager.checkContext(m), {
locally: locally(tag),
Expand Down Expand Up @@ -613,6 +630,8 @@ export class Runner {
choreography: Choreography<LL, Args, Return>,
args: Args,
) => {
const naked: Naked<LL> = <T>(cv: MultiplyLocated<T, LL>) =>
cv.getValue(key);
const ret = await choreography(
wrapMethods((m) => m, {
locally: locally,
Expand Down Expand Up @@ -652,6 +671,8 @@ export class Runner {
c: Choreography<LL, Args, Return>,
a: Args,
) => {
const naked: Naked<LL> = <T>(cv: MultiplyLocated<T, LL>) =>
cv.getValue(key);
const ret = await c(
wrapMethods((m) => m, {
locally: locally,
Expand Down

0 comments on commit 02b5631

Please sign in to comment.