Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = [
...options,
files: ['**/*.test.{ts,js}'],
})),

{
ignores: [
'yarn.config.cjs',
Expand All @@ -29,6 +30,7 @@ const config = [
'**/coverage',
],
},

{
languageOptions: {
parserOptions: {
Expand All @@ -47,15 +49,15 @@ const config = [
},
],

// This prevents using Node.js and/or browser specific globals. We
// currently use both in our codebase, so this rule is disabled.
'no-restricted-globals': 'off',

'import-x/extensions': 'off',
'import-x/no-unassigned-import': 'off',

// This prevents pretty formatting of comments with multi-line lists entries.
'jsdoc/check-indentation': 'off',

// This prevents using Node.js and/or browser specific globals. We
// currently use both in our codebase, so this rule is disabled.
'no-restricted-globals': 'off',
},
},

Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function main(): Promise<void> {
}

switch (message.method) {
case ClusterCommandMethod.InitKernel:
case ClusterCommandMethod.Evaluate:
case ClusterCommandMethod.CapTpCall:
case ClusterCommandMethod.Ping:
Expand Down
82 changes: 82 additions & 0 deletions packages/extension/src/kernel-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* A structured representation of an ocap kernel.
*/
type Queue<Type> = Type[];

type VatId = `v${number}`;
type RemoteId = `r${number}`;
type EndpointId = VatId | RemoteId;

type RefTypeTag = 'o' | 'p';
type RefDirectionTag = '+' | '-';
type InnerKRef = `${RefTypeTag}${number}`;
type InnerERef = `${RefTypeTag}${RefDirectionTag}${number}`;

type KRef = `k${InnerKRef}`;
type VRef = `v${InnerERef}`;
type RRef = `r${InnerERef}`;
type ERef = VRef | RRef;

type CapData = {
body: string;
slots: string[];
};

type Message = {
target: ERef | KRef;
method: string;
params: CapData;
};

// Per-endpoint persistent state
type EndpointState<IdType> = {
name: string;
id: IdType;
nextExportObjectIdCounter: number;
nextExportPromiseIdCounter: number;
eRefToKRef: Map<ERef, KRef>;
kRefToERef: Map<KRef, ERef>;
};

type VatState = {
messagePort: MessagePort;
state: EndpointState<VatId>;
source: string;
kvTable: Map<string, string>;
};

type RemoteState = {
state: EndpointState<RemoteId>;
connectToURL: string;
// more here about maintaining connection...
};

// Kernel persistent state
type KernelObject = {
owner: EndpointId;
reachableCount: number;
recognizableCount: number;
};

type PromiseState = 'unresolved' | 'fulfilled' | 'rejected';

type KernelPromise = {
decider: EndpointId;
state: PromiseState;
referenceCount: number;
messageQueue: Queue<Message>;
value: undefined | CapData;
};

// export temporarily to shut up lint whinges about unusedness
export type KernelState = {
runQueue: Queue<Message>;
nextVatIdCounter: number;
vats: Map<VatId, VatState>;
nextRemoteIdCounter: number;
remotes: Map<RemoteId, RemoteState>;
nextKernelObjectIdCounter: number;
kernelObjects: Map<KRef, KernelObject>;
nextKernePromiseIdCounter: number;
kernelPromises: Map<KRef, KernelPromise>;
};
Loading