@polyengine/runtime 0.1.0-pre.g633468a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +23 -0
- package/esm/cabi/async_values.js +162 -0
- package/esm/cabi/bulk_lists.js +198 -0
- package/esm/cabi/context.js +42 -0
- package/esm/cabi/flatten.js +145 -0
- package/esm/cabi/float.js +67 -0
- package/esm/cabi/handles.js +253 -0
- package/esm/cabi/layout.js +149 -0
- package/esm/cabi/lift.js +196 -0
- package/esm/cabi/load.js +146 -0
- package/esm/cabi/lower.js +141 -0
- package/esm/cabi/memory.js +182 -0
- package/esm/cabi/mod.js +22 -0
- package/esm/cabi/store.js +186 -0
- package/esm/cabi/strings.js +336 -0
- package/esm/cabi/trap.js +38 -0
- package/esm/cabi/types.js +264 -0
- package/esm/cabi/values.js +64 -0
- package/esm/cache/core.js +156 -0
- package/esm/cache/dir.js +170 -0
- package/esm/cache/mod.js +4 -0
- package/esm/cache/web.js +136 -0
- package/esm/digest/digest.js +332 -0
- package/esm/digest/mod.js +3 -0
- package/esm/digest/verify.js +129 -0
- package/esm/embedder/casing.js +56 -0
- package/esm/embedder/copy.js +42 -0
- package/esm/embedder/errors.js +26 -0
- package/esm/embedder/imports.js +63 -0
- package/esm/embedder/instantiate.js +978 -0
- package/esm/embedder/mod.js +40 -0
- package/esm/embedder/resources.js +406 -0
- package/esm/embedder/streams.js +770 -0
- package/esm/embedder/values.js +450 -0
- package/esm/embedder/version.js +273 -0
- package/esm/exec/boundary.js +1902 -0
- package/esm/exec/executor.js +1004 -0
- package/esm/exec/host_streams.js +818 -0
- package/esm/exec/mod.js +4 -0
- package/esm/intrinsics/async_builtins.js +510 -0
- package/esm/intrinsics/context.js +90 -0
- package/esm/intrinsics/errors.js +13 -0
- package/esm/intrinsics/fact_calls.js +865 -0
- package/esm/intrinsics/mod.js +564 -0
- package/esm/intrinsics/stream_builtins.js +578 -0
- package/esm/intrinsics/transcode.js +443 -0
- package/esm/jspi/bridge.js +579 -0
- package/esm/jspi/mechanics.js +89 -0
- package/esm/jspi/mod.js +5 -0
- package/esm/jspi/suspending.js +15 -0
- package/esm/jspi/types.js +29 -0
- package/esm/package.json +3 -0
- package/esm/plan/format.js +5 -0
- package/esm/plan/loader.js +657 -0
- package/esm/plan/mod.js +3 -0
- package/esm/shim/mod.js +2 -0
- package/esm/shim/translator.js +94 -0
- package/esm/task/mod.js +483 -0
- package/esm/task/scheduler.js +1028 -0
- package/esm/task/streams.js +786 -0
- package/esm/task/subtask.js +135 -0
- package/esm/task/thread.js +255 -0
- package/esm/task/waitable.js +144 -0
- package/package.json +91 -0
- package/types/cabi/async_values.d.ts +35 -0
- package/types/cabi/bulk_lists.d.ts +18 -0
- package/types/cabi/context.d.ts +59 -0
- package/types/cabi/flatten.d.ts +14 -0
- package/types/cabi/float.d.ts +14 -0
- package/types/cabi/handles.d.ts +70 -0
- package/types/cabi/layout.d.ts +13 -0
- package/types/cabi/lift.d.ts +25 -0
- package/types/cabi/load.d.ts +14 -0
- package/types/cabi/lower.d.ts +10 -0
- package/types/cabi/memory.d.ts +58 -0
- package/types/cabi/mod.d.ts +15 -0
- package/types/cabi/store.d.ts +12 -0
- package/types/cabi/strings.d.ts +23 -0
- package/types/cabi/trap.d.ts +11 -0
- package/types/cabi/types.d.ts +206 -0
- package/types/cabi/values.d.ts +5 -0
- package/types/cache/core.d.ts +97 -0
- package/types/cache/dir.d.ts +6 -0
- package/types/cache/mod.d.ts +3 -0
- package/types/cache/web.d.ts +10 -0
- package/types/digest/digest.d.ts +17 -0
- package/types/digest/mod.d.ts +2 -0
- package/types/digest/verify.d.ts +48 -0
- package/types/embedder/casing.d.ts +40 -0
- package/types/embedder/copy.d.ts +24 -0
- package/types/embedder/errors.d.ts +11 -0
- package/types/embedder/imports.d.ts +47 -0
- package/types/embedder/instantiate.d.ts +88 -0
- package/types/embedder/mod.d.ts +11 -0
- package/types/embedder/resources.d.ts +158 -0
- package/types/embedder/streams.d.ts +202 -0
- package/types/embedder/values.d.ts +70 -0
- package/types/embedder/version.d.ts +85 -0
- package/types/exec/boundary.d.ts +360 -0
- package/types/exec/executor.d.ts +125 -0
- package/types/exec/host_streams.d.ts +165 -0
- package/types/exec/mod.d.ts +3 -0
- package/types/intrinsics/async_builtins.d.ts +69 -0
- package/types/intrinsics/context.d.ts +28 -0
- package/types/intrinsics/errors.d.ts +5 -0
- package/types/intrinsics/fact_calls.d.ts +120 -0
- package/types/intrinsics/mod.d.ts +187 -0
- package/types/intrinsics/stream_builtins.d.ts +113 -0
- package/types/intrinsics/transcode.d.ts +21 -0
- package/types/jspi/bridge.d.ts +227 -0
- package/types/jspi/mechanics.d.ts +50 -0
- package/types/jspi/mod.d.ts +3 -0
- package/types/jspi/suspending.d.ts +1 -0
- package/types/jspi/types.d.ts +26 -0
- package/types/plan/format.d.ts +369 -0
- package/types/plan/loader.d.ts +113 -0
- package/types/plan/mod.d.ts +2 -0
- package/types/shim/mod.d.ts +1 -0
- package/types/shim/translator.d.ts +55 -0
- package/types/task/mod.d.ts +257 -0
- package/types/task/scheduler.d.ts +421 -0
- package/types/task/streams.d.ts +370 -0
- package/types/task/subtask.d.ts +96 -0
- package/types/task/thread.d.ts +73 -0
- package/types/task/waitable.d.ts +67 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { MemInst } from "./memory.js";
|
|
2
|
+
import type { StringEncoding } from "./types.js";
|
|
3
|
+
import type { Table } from "./handles.js";
|
|
4
|
+
/**
|
|
5
|
+
* definitions.py realloc signature: (original_ptr, original_size, alignment,
|
|
6
|
+
* new_size) -> ptr. Addresses as JS numbers (see memory.ts).
|
|
7
|
+
*/
|
|
8
|
+
export type ReallocFn = (originalPtr: number, originalSize: number, alignment: number, newSize: number) => number;
|
|
9
|
+
export interface LiftOptions {
|
|
10
|
+
stringEncoding: StringEncoding;
|
|
11
|
+
memory: MemInst | null;
|
|
12
|
+
}
|
|
13
|
+
export interface LiftLowerOptions extends LiftOptions {
|
|
14
|
+
realloc: ReallocFn | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CanonicalOptions extends LiftLowerOptions {
|
|
17
|
+
postReturn: (() => void) | null;
|
|
18
|
+
async_: boolean;
|
|
19
|
+
callback: unknown | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function mkCanonicalOptions(partial?: Partial<CanonicalOptions>): CanonicalOptions;
|
|
22
|
+
/** Memory accessor that traps-or-asserts like `cx.opts.memory` derefs. */
|
|
23
|
+
export declare function requireMemory(opts: LiftOptions): MemInst;
|
|
24
|
+
/**
|
|
25
|
+
* Minimal component-instance stand-in for the value interpreter: a handle
|
|
26
|
+
* table plus the `may_leave` gate. The full ComponentInstance (may_enter,
|
|
27
|
+
* backpressure, threads, ...) belongs to the deferred task machinery.
|
|
28
|
+
*/
|
|
29
|
+
export interface ComponentInstanceLike {
|
|
30
|
+
handles: Table<unknown>;
|
|
31
|
+
mayLeave: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Borrow scopes (definitions.py `LiftLowerContext.borrow_scope`):
|
|
35
|
+
* - lifting a borrow requires the *subtask* side: `add_lender`.
|
|
36
|
+
* - lowering a borrow requires the *task* side: `num_borrows`.
|
|
37
|
+
* The real Task/Subtask classes are deferred; these are the minimal
|
|
38
|
+
* interfaces the value code needs.
|
|
39
|
+
*/
|
|
40
|
+
export interface SubtaskBorrowScope {
|
|
41
|
+
addLender(h: import("./handles.js").ResourceHandle): void;
|
|
42
|
+
}
|
|
43
|
+
export interface TaskBorrowScope {
|
|
44
|
+
numBorrows: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class LiftLowerContext {
|
|
47
|
+
opts: LiftLowerOptions;
|
|
48
|
+
inst: ComponentInstanceLike | null;
|
|
49
|
+
borrowScope: SubtaskBorrowScope | TaskBorrowScope | null;
|
|
50
|
+
constructor(opts: LiftLowerOptions, inst?: ComponentInstanceLike | null, borrowScope?: SubtaskBorrowScope | TaskBorrowScope | null);
|
|
51
|
+
/**
|
|
52
|
+
* definitions.py `LiftLowerContext.reallocate` routes the call through
|
|
53
|
+
* canon_lift (reentrance bookkeeping and may_leave toggling around a
|
|
54
|
+
* guest-side realloc export). v1 simplification: call the provided realloc
|
|
55
|
+
* directly. The full path returns with the task machinery.
|
|
56
|
+
*/
|
|
57
|
+
reallocate(old: number, oldByteLength: number, alignment: number, newByteLength: number): number;
|
|
58
|
+
allocate(alignment: number, byteLength: number): number;
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CaseType, type CoreFuncType, type CoreType, type FieldType, type FuncType, type ValType } from "./types.js";
|
|
2
|
+
import type { CanonicalOptions, LiftOptions } from "./context.js";
|
|
3
|
+
export declare const MAX_FLAT_PARAMS = 16;
|
|
4
|
+
export declare const MAX_FLAT_ASYNC_PARAMS = 4;
|
|
5
|
+
export declare let MAX_FLAT_RESULTS: number;
|
|
6
|
+
export declare function setMaxFlatResultsForTesting(n: number): number;
|
|
7
|
+
export type FlattenContext = "lift" | "lower";
|
|
8
|
+
export declare function flattenFunctype(opts: CanonicalOptions, ft: FuncType, context: FlattenContext): CoreFuncType;
|
|
9
|
+
export declare function flattenTypes(ts: ValType[], opts: LiftOptions): CoreType[];
|
|
10
|
+
export declare function flattenType(t: ValType, opts: LiftOptions): CoreType[];
|
|
11
|
+
export declare function flattenList(elemType: ValType, maybeLength: number | null, opts: LiftOptions): CoreType[];
|
|
12
|
+
export declare function flattenRecord(fields: FieldType[], opts: LiftOptions): CoreType[];
|
|
13
|
+
export declare function flattenVariant(cases: CaseType[], opts: LiftOptions): CoreType[];
|
|
14
|
+
export declare function join(a: CoreType, b: CoreType): CoreType;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const CANONICAL_FLOAT32_NAN = 2143289344;
|
|
2
|
+
export declare const CANONICAL_FLOAT64_NAN = 9221120237041090560n;
|
|
3
|
+
export declare function coreF32ReinterpretI32(i: number): number;
|
|
4
|
+
export declare function coreF64ReinterpretI64(i: bigint): number;
|
|
5
|
+
export declare function coreI32ReinterpretF32(f: number): number;
|
|
6
|
+
export declare function coreI64ReinterpretF64(f: number): bigint;
|
|
7
|
+
export declare function canonicalizeNan32(f: number): number;
|
|
8
|
+
export declare function canonicalizeNan64(f: number): number;
|
|
9
|
+
export declare function decodeI32AsFloat(i: number): number;
|
|
10
|
+
export declare function decodeI64AsFloat(i: bigint): number;
|
|
11
|
+
export declare function maybeScrambleNan32(f: number): number;
|
|
12
|
+
export declare function maybeScrambleNan64(f: number): number;
|
|
13
|
+
export declare function encodeFloatAsI32(f: number): number;
|
|
14
|
+
export declare function encodeFloatAsI64(f: number): bigint;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ComponentInstanceLike, LiftLowerContext, TaskBorrowScope } from "./context.js";
|
|
2
|
+
import type { BorrowType, OwnType, ResourceTypeInfo } from "./types.js";
|
|
3
|
+
export declare class Table<T> {
|
|
4
|
+
static readonly MAX_LENGTH: number;
|
|
5
|
+
array: (T | null)[];
|
|
6
|
+
free: number[];
|
|
7
|
+
get(i: number): T;
|
|
8
|
+
add(e: T): number;
|
|
9
|
+
remove(i: number): T;
|
|
10
|
+
[Symbol.iterator](): Iterator<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare class ResourceHandle {
|
|
13
|
+
rt: ResourceTypeInfo;
|
|
14
|
+
rep: number;
|
|
15
|
+
own: boolean;
|
|
16
|
+
borrowScope: TaskBorrowScope | null;
|
|
17
|
+
numLends: number;
|
|
18
|
+
constructor(rt: ResourceTypeInfo, rep: number, own: boolean, borrowScope?: TaskBorrowScope | null);
|
|
19
|
+
}
|
|
20
|
+
export declare function liftOwn(cx: LiftLowerContext, i: number, t: OwnType): number;
|
|
21
|
+
export declare function liftBorrow(cx: LiftLowerContext, i: number, t: BorrowType): number;
|
|
22
|
+
export declare function lowerOwn(cx: LiftLowerContext, rep: number, t: OwnType): number;
|
|
23
|
+
export declare function lowerBorrow(cx: LiftLowerContext, rep: number, t: BorrowType): number;
|
|
24
|
+
export declare function canonResourceNew(inst: ComponentInstanceLike, rt: ResourceTypeInfo, rep: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Invoke a resource destructor through the reference's entry bracket.
|
|
27
|
+
*
|
|
28
|
+
* definitions.py `canon_resource_drop` (line 2319) does not call `rt.dtor`
|
|
29
|
+
* directly. It builds the dtor into a function instance and calls it through
|
|
30
|
+
* `Store.lift` / `Store.lower` (lines 2330-2333):
|
|
31
|
+
*
|
|
32
|
+
* ```python
|
|
33
|
+
* dtor = rt.dtor or (lambda rep: [])
|
|
34
|
+
* callee = inst.store.lift(dtor, ft, opts, rt.impl)
|
|
35
|
+
* caller = inst.store.lower(callee, ft, opts, inst)
|
|
36
|
+
* caller([h.rep])
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* so the dtor inherits `Store.lift`'s gate verbatim (lines 579-584):
|
|
40
|
+
* `trap_if(not inst.may_enter_from(caller))`, `enter_from(caller)`, the call,
|
|
41
|
+
* then `leave_to(caller)` — which a trap skips, leaving the *implementing*
|
|
42
|
+
* instance permanently unenterable (poisoned).
|
|
43
|
+
*
|
|
44
|
+
* Two consequences that are easy to get wrong, both taken from the reference
|
|
45
|
+
* rather than from intuition:
|
|
46
|
+
*
|
|
47
|
+
* - the bracket runs even when `rt.dtor is None` (the `or (lambda rep: [])`
|
|
48
|
+
* above), so a dtor-less resource whose impl instance is mid-execution is
|
|
49
|
+
* still a trap. `may_enter_from`/`enter_from` walk `entering_set(caller)`
|
|
50
|
+
* (line 230), which is empty when the caller *is* the implementing
|
|
51
|
+
* instance — that, not a special case, is the same-instance exemption:
|
|
52
|
+
* a component dropping a handle to its own resource never traps.
|
|
53
|
+
* - poisoning applies to `rt.impl`, not to the dropping instance. The
|
|
54
|
+
* dropper's own bracket (its `Store.lift` frame) is broken by the same
|
|
55
|
+
* propagating trap at its own level; here only the callee is retired.
|
|
56
|
+
*
|
|
57
|
+
* Capability signals (`NeedsJspi`, `PendingCapability`) are not traps — see
|
|
58
|
+
* `isCapabilitySignal` in exec/boundary.ts — so they release the gate.
|
|
59
|
+
*
|
|
60
|
+
* SCOPE (#160): this is the **guest-initiated** path only. A guest-initiated
|
|
61
|
+
* drop must complete synchronously (the reference lifts the dtor with
|
|
62
|
+
* `async_ = False`), so a thenable here is a trap. The host-initiated path
|
|
63
|
+
* used to share this function with an `allowAsync` flag that held the entry
|
|
64
|
+
* bracket across the dtor's promise; it now goes through the full lift
|
|
65
|
+
* harness instead (`hostDtorCall` in exec/boundary.ts), which is what
|
|
66
|
+
* definitions.py actually does and what unwedges #160.
|
|
67
|
+
*/
|
|
68
|
+
export declare function callDtorGated(rt: ResourceTypeInfo, rep: number, caller: unknown): void;
|
|
69
|
+
export declare function canonResourceDrop(inst: ComponentInstanceLike, rt: ResourceTypeInfo, i: number): void;
|
|
70
|
+
export declare function canonResourceRep(inst: ComponentInstanceLike, rt: ResourceTypeInfo, i: number): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CaseType, type FieldType, type PtrType, type ValType } from "./types.js";
|
|
2
|
+
export declare function alignTo(ptr: number, alignment: number): number;
|
|
3
|
+
export declare function alignment(t: ValType, ptrType: PtrType): number;
|
|
4
|
+
export declare function alignmentList(elemType: ValType, maybeLength: number | null, ptrType: PtrType): number;
|
|
5
|
+
export declare function alignmentRecord(fields: FieldType[], ptrType: PtrType): number;
|
|
6
|
+
export declare function alignmentVariant(cases: CaseType[], ptrType: PtrType): number;
|
|
7
|
+
export declare function maxCaseAlignment(cases: CaseType[], ptrType: PtrType): number;
|
|
8
|
+
export declare function alignmentFlags(labels: string[]): number;
|
|
9
|
+
export declare function elemSize(t: ValType, ptrType: PtrType): number;
|
|
10
|
+
export declare function elemSizeList(elemType: ValType, maybeLength: number | null, ptrType: PtrType): number;
|
|
11
|
+
export declare function elemSizeRecord(fields: FieldType[], ptrType: PtrType): number;
|
|
12
|
+
export declare function elemSizeVariant(cases: CaseType[], ptrType: PtrType): number;
|
|
13
|
+
export declare function elemSizeFlags(labels: string[]): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LiftLowerContext } from "./context.js";
|
|
2
|
+
import { type CaseType, type ComponentValue, type CoreType, type CoreValue, type FieldType, type ValType } from "./types.js";
|
|
3
|
+
/** Anything lift can pull core values from (CoreValueIter or the variant
|
|
4
|
+
* coercion iterator). */
|
|
5
|
+
export interface ValueIter {
|
|
6
|
+
next(t: CoreType): CoreValue;
|
|
7
|
+
}
|
|
8
|
+
export declare class CoreValueIter implements ValueIter {
|
|
9
|
+
values: CoreValue[];
|
|
10
|
+
i: number;
|
|
11
|
+
constructor(values: CoreValue[]);
|
|
12
|
+
next(t: CoreType): CoreValue;
|
|
13
|
+
done(): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function liftFlat(cx: LiftLowerContext, vi: ValueIter, t: ValType): ComponentValue;
|
|
16
|
+
export declare function liftFlatUnsigned32(vi: ValueIter, tWidth: number): number;
|
|
17
|
+
export declare function liftFlatUnsigned64(vi: ValueIter): bigint;
|
|
18
|
+
export declare function liftFlatSigned32(vi: ValueIter, tWidth: number): number;
|
|
19
|
+
export declare function liftFlatSigned64(vi: ValueIter): bigint;
|
|
20
|
+
export declare function liftFlatString(cx: LiftLowerContext, vi: ValueIter): ComponentValue;
|
|
21
|
+
export declare function liftFlatList(cx: LiftLowerContext, vi: ValueIter, elemType: ValType, maybeLength: number | null): ComponentValue;
|
|
22
|
+
export declare function liftFlatRecord(cx: LiftLowerContext, vi: ValueIter, fields: FieldType[]): ComponentValue;
|
|
23
|
+
export declare function liftFlatVariant(cx: LiftLowerContext, vi: ValueIter, cases: CaseType[]): ComponentValue;
|
|
24
|
+
export declare function wrapI64ToI32(i: bigint): number;
|
|
25
|
+
export declare function liftFlatFlags(vi: ValueIter, labels: string[]): ComponentValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type LiftLowerContext } from "./context.js";
|
|
2
|
+
import { type CaseType, type ComponentValue, type FieldType, type ValType } from "./types.js";
|
|
3
|
+
export declare const MAX_LIST_BYTE_LENGTH: number;
|
|
4
|
+
export declare function load(cx: LiftLowerContext, ptr: number, t: ValType): ComponentValue;
|
|
5
|
+
export declare function convertIntToBool(i: number): boolean;
|
|
6
|
+
export declare function loadList(cx: LiftLowerContext, ptr: number, elemType: ValType, maybeLength: number | null): ComponentValue;
|
|
7
|
+
export declare function loadListFromRange(cx: LiftLowerContext, ptr: number | bigint, length: number | bigint, elemType: ValType): ComponentValue;
|
|
8
|
+
export declare function loadListFromValidRange(cx: LiftLowerContext, ptr: number, length: number, elemType: ValType): ComponentValue;
|
|
9
|
+
export declare function loadRecord(cx: LiftLowerContext, ptr: number, fields: FieldType[]): ComponentValue;
|
|
10
|
+
export declare function loadVariant(cx: LiftLowerContext, ptr: number, cases: CaseType[]): ComponentValue;
|
|
11
|
+
export declare function loadFlags(cx: LiftLowerContext, ptr: number, labels: string[]): ComponentValue;
|
|
12
|
+
export declare function unpackFlagsFromInt(i: number, labels: string[]): {
|
|
13
|
+
[label: string]: ComponentValue;
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type LiftLowerContext } from "./context.js";
|
|
2
|
+
import { type CaseType, type ComponentValue, type CoreValue, type FieldType, type ValType } from "./types.js";
|
|
3
|
+
export declare function lowerFlat(cx: LiftLowerContext, v: ComponentValue, t: ValType): CoreValue[];
|
|
4
|
+
export declare function lowerFlatSigned32(i: number): CoreValue[];
|
|
5
|
+
export declare function lowerFlatSigned64(i: bigint): CoreValue[];
|
|
6
|
+
export declare function lowerFlatString(cx: LiftLowerContext, v: string): CoreValue[];
|
|
7
|
+
export declare function lowerFlatList(cx: LiftLowerContext, v: ArrayLike<ComponentValue>, elemType: ValType, maybeLength: number | null): CoreValue[];
|
|
8
|
+
export declare function lowerFlatRecord(cx: LiftLowerContext, v: Record<string, ComponentValue>, fields: FieldType[]): CoreValue[];
|
|
9
|
+
export declare function lowerFlatVariant(cx: LiftLowerContext, v: Record<string, ComponentValue>, cases: CaseType[]): CoreValue[];
|
|
10
|
+
export declare function lowerFlatFlags(v: Record<string, ComponentValue>, labels: string[]): CoreValue[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PtrType } from "./types.js";
|
|
2
|
+
export declare function ptrSize(ptrType: PtrType): 4 | 8;
|
|
3
|
+
/**
|
|
4
|
+
* `MemInst` caches its `Uint8Array`/`DataView` at construction time and never
|
|
5
|
+
* re-derives them. That is only sound for a memory that cannot grow within
|
|
6
|
+
* this instance's lifetime: `memory.grow` (guest-triggered or host-triggered)
|
|
7
|
+
* detaches the backing `ArrayBuffer`, and a cached view over a detached
|
|
8
|
+
* buffer reads/writes garbage rather than trapping.
|
|
9
|
+
*
|
|
10
|
+
* Production call/lift/lower paths do NOT construct `MemInst` directly against
|
|
11
|
+
* a live, growable `WebAssembly.Memory` for this reason: the executor
|
|
12
|
+
* re-derives a fresh view per access via `LiveMemory`
|
|
13
|
+
* (`exec/boundary.ts:97-160`), which is grow-safe. `MemInst` is for contexts
|
|
14
|
+
* where the buffer is known fixed for the duration (tests, or a snapshot
|
|
15
|
+
* already taken).
|
|
16
|
+
*/
|
|
17
|
+
export declare class MemInst {
|
|
18
|
+
readonly bytes: Uint8Array;
|
|
19
|
+
readonly view: DataView;
|
|
20
|
+
readonly addrType: PtrType;
|
|
21
|
+
constructor(bytes: Uint8Array, addrType: PtrType);
|
|
22
|
+
get length(): number;
|
|
23
|
+
ptrType(): PtrType;
|
|
24
|
+
ptrSize(): 4 | 8;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert a (possibly BigInt) address/length to a JS number index, after the
|
|
28
|
+
* caller has already trapped on any out-of-bounds condition using exact
|
|
29
|
+
* (BigInt) arithmetic. Asserts rather than traps: by this point the value is
|
|
30
|
+
* known small.
|
|
31
|
+
*/
|
|
32
|
+
export declare function asIndex(v: number | bigint): number;
|
|
33
|
+
export declare function loadIntU(mem: MemInst, ptr: number, nbytes: 1 | 2 | 4): number;
|
|
34
|
+
export declare function loadIntU(mem: MemInst, ptr: number, nbytes: 8): bigint;
|
|
35
|
+
export declare function loadIntS(mem: MemInst, ptr: number, nbytes: 1 | 2 | 4): number;
|
|
36
|
+
export declare function loadIntS(mem: MemInst, ptr: number, nbytes: 8): bigint;
|
|
37
|
+
/** Load a pointer-sized unsigned integer (returns bigint for i64 memories). */
|
|
38
|
+
export declare function loadPtr(mem: MemInst, ptr: number): number | bigint;
|
|
39
|
+
export declare function storeInt(mem: MemInst, v: number | bigint, ptr: number, nbytes: 1 | 2 | 4 | 8, signed?: boolean): void;
|
|
40
|
+
/** Store a pointer-sized unsigned integer, taking a JS number. */
|
|
41
|
+
export declare function storePtr(mem: MemInst, v: number, ptr: number): void;
|
|
42
|
+
/** Bounds-checked byte-range read (callers trap on OOB before calling). */
|
|
43
|
+
export declare function bytesOf(mem: MemInst, ptr: number, len: number): Uint8Array;
|
|
44
|
+
/** Copy bytes into memory; used by string/list stores after trap checks. */
|
|
45
|
+
export declare function writeBytes(mem: MemInst, ptr: number, src: Uint8Array): void;
|
|
46
|
+
/**
|
|
47
|
+
* Exact bounds check usable with i64-lane values: traps when
|
|
48
|
+
* `ptr + byteLength > len(memory)`, computed without precision loss.
|
|
49
|
+
*
|
|
50
|
+
* `what` selects the trap wording only. Callers that are checking a pointer
|
|
51
|
+
* *returned by realloc* pass wasmtime's phrasing for that case
|
|
52
|
+
* ("realloc return: beyond end of memory",
|
|
53
|
+
* `wasmtime/src/runtime/component/func/options.rs:185`) and the string-lift
|
|
54
|
+
* path passes its own ("string pointer/length out of bounds of memory",
|
|
55
|
+
* `.../func/typed.rs:1528`), because the official suite matches those texts.
|
|
56
|
+
* The default is unchanged.
|
|
57
|
+
*/
|
|
58
|
+
export declare function trapIfRangeExceedsMemory(mem: MemInst, ptr: number | bigint, byteLength: number | bigint, what?: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./trap.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./memory.js";
|
|
4
|
+
export * from "./layout.js";
|
|
5
|
+
export * from "./float.js";
|
|
6
|
+
export * from "./context.js";
|
|
7
|
+
export * from "./handles.js";
|
|
8
|
+
export * from "./strings.js";
|
|
9
|
+
export * from "./bulk_lists.js";
|
|
10
|
+
export * from "./load.js";
|
|
11
|
+
export * from "./store.js";
|
|
12
|
+
export * from "./flatten.js";
|
|
13
|
+
export * from "./lift.js";
|
|
14
|
+
export * from "./lower.js";
|
|
15
|
+
export * from "./values.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type LiftLowerContext } from "./context.js";
|
|
2
|
+
import { type CaseType, type ComponentValue, type FieldType, type ValType } from "./types.js";
|
|
3
|
+
export declare function store(cx: LiftLowerContext, v: ComponentValue, t: ValType, ptr: number): void;
|
|
4
|
+
export declare function storeList(cx: LiftLowerContext, v: ArrayLike<ComponentValue>, ptr: number, elemType: ValType, maybeLength: number | null): void;
|
|
5
|
+
export declare function storeListIntoRange(cx: LiftLowerContext, v: ArrayLike<ComponentValue>, elemType: ValType): [number, number];
|
|
6
|
+
export declare function storeListIntoValidRange(cx: LiftLowerContext, v: ArrayLike<ComponentValue>, ptr: number, elemType: ValType): void;
|
|
7
|
+
export declare function storeRecord(cx: LiftLowerContext, v: Record<string, ComponentValue>, ptr: number, fields: FieldType[]): void;
|
|
8
|
+
/** definitions.py match_case: the value is a single-key object. */
|
|
9
|
+
export declare function matchCase(v: Record<string, ComponentValue>, cases: CaseType[]): [number, ComponentValue];
|
|
10
|
+
export declare function storeVariant(cx: LiftLowerContext, v: Record<string, ComponentValue>, ptr: number, cases: CaseType[]): void;
|
|
11
|
+
export declare function storeFlags(cx: LiftLowerContext, v: Record<string, ComponentValue>, ptr: number, labels: string[]): void;
|
|
12
|
+
export declare function packFlagsIntoInt(v: Record<string, ComponentValue>, labels: string[]): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type LiftLowerContext } from "./context.js";
|
|
2
|
+
import type { PtrType } from "./types.js";
|
|
3
|
+
export declare const REALLOC_I32_MAX: number;
|
|
4
|
+
export declare const REALLOC_MISALIGNED = "realloc return: result not aligned";
|
|
5
|
+
export declare const REALLOC_OOB = "realloc return: beyond end of memory";
|
|
6
|
+
export declare const MAX_STRING_BYTE_LENGTH: number;
|
|
7
|
+
/** definitions.py utf16_tag: the high bit of a pointer-sized integer. */
|
|
8
|
+
export declare function utf16TagBig(ptrType: PtrType): bigint;
|
|
9
|
+
/** WebIDL USVString conversion: unpaired surrogates -> U+FFFD. */
|
|
10
|
+
export declare function toWellFormed(s: string): string;
|
|
11
|
+
export declare function encodeUtf16Le(s: string): Uint8Array;
|
|
12
|
+
export declare function loadString(cx: LiftLowerContext, ptr: number): string;
|
|
13
|
+
export declare function loadStringFromRange(cx: LiftLowerContext, ptr: number | bigint, taggedCodeUnits: number | bigint): string;
|
|
14
|
+
export declare function storeString(cx: LiftLowerContext, v: string, ptr: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* definitions.py store_string_into_range, specialized to a JS-string source
|
|
17
|
+
* (src_encoding = 'utf16', src_code_units = s.length — see module comment).
|
|
18
|
+
* Returns [ptr, tagged_code_units]; tagged units as bigint because the
|
|
19
|
+
* latin1+utf16 tag bit exceeds Number.MAX_SAFE_INTEGER on i64 memories.
|
|
20
|
+
*/
|
|
21
|
+
export declare function storeStringIntoRange(cx: LiftLowerContext, src: string): [number, bigint];
|
|
22
|
+
export declare function convertI32ToChar(i: number): string;
|
|
23
|
+
export declare function charToI32(c: string): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { isTrap, Trap } from "@polyengine/protocol";
|
|
2
|
+
export declare function trap(message?: string): never;
|
|
3
|
+
export declare function trapIf(cond: boolean, message?: string): void;
|
|
4
|
+
export declare class AssertionError extends Error {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function assert_(cond: boolean, message?: string): asserts cond;
|
|
8
|
+
/** Marks a definitions.py code path this v1 interpreter does not port yet. */
|
|
9
|
+
export declare class NotImplemented extends Error {
|
|
10
|
+
constructor(what: string);
|
|
11
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/** Core wasm value types, as strings (mirrors definitions.py flat types). */
|
|
2
|
+
export type CoreType = "i32" | "i64" | "f32" | "f64";
|
|
3
|
+
/** Pointer type of a linear memory: wasm32 or wasm64. */
|
|
4
|
+
export type PtrType = "i32" | "i64";
|
|
5
|
+
/**
|
|
6
|
+
* A flat core function signature (definitions.py `CoreFuncType`).
|
|
7
|
+
* Equality is structural (see `coreFuncTypeEquals`).
|
|
8
|
+
*/
|
|
9
|
+
export interface CoreFuncType {
|
|
10
|
+
params: CoreType[];
|
|
11
|
+
results: CoreType[];
|
|
12
|
+
}
|
|
13
|
+
export declare function coreFuncTypeEquals(a: CoreFuncType, b: CoreFuncType): boolean;
|
|
14
|
+
/** String encodings selectable by canonical options. */
|
|
15
|
+
export type StringEncoding = "utf8" | "utf16" | "latin1+utf16";
|
|
16
|
+
/**
|
|
17
|
+
* Opaque token standing in for the implementing component instance of a
|
|
18
|
+
* resource type (definitions.py `ResourceType.impl`). The value interpreter
|
|
19
|
+
* only ever compares these by identity.
|
|
20
|
+
*/
|
|
21
|
+
export interface InstanceLike {
|
|
22
|
+
handles: unknown;
|
|
23
|
+
mayLeave: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* definitions.py `ResourceType`: identity + implementing instance + optional
|
|
27
|
+
* destructor. Compared by object identity everywhere.
|
|
28
|
+
*
|
|
29
|
+
* `dtorHost` is the **host-initiated**-drop entry (#85, reshaped by #160):
|
|
30
|
+
* the dtor built as a fully LIFTED sync function — definitions.py
|
|
31
|
+
* `canon_resource_drop` (line 2319) `inst.store.lift(dtor, ft, opts,
|
|
32
|
+
* rt.impl)` — so the destructor's activation gets a real Task/Thread, the
|
|
33
|
+
* reentrance bracket is released at its first park, and its suspension
|
|
34
|
+
* points are resumable by the scheduler. It is wired by exec/executor.ts
|
|
35
|
+
* (jspi-`promising` entry only when the dtor is suspension-capable, docs §7)
|
|
36
|
+
* and called through `hostDtorCall` (exec/boundary.ts), which also fills it
|
|
37
|
+
* in lazily for tokens built directly. It returns `undefined` or a Promise,
|
|
38
|
+
* so it is NOT callable from inside a guest activation.
|
|
39
|
+
*
|
|
40
|
+
* Guest-initiated drops (`callDtorGated`) always use `dtor` directly: they
|
|
41
|
+
* must complete synchronously (reference lifts the dtor with
|
|
42
|
+
* `async_ = False`), and any thenable there is a trap.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ResourceTypeInfo {
|
|
45
|
+
impl: InstanceLike | null;
|
|
46
|
+
dtor: ((rep: number) => void) | null;
|
|
47
|
+
dtorHost: ((rep: number) => unknown) | null;
|
|
48
|
+
constructor(impl: InstanceLike | null, dtor?: ((rep: number) => void) | null, dtorHost?: ((rep: number) => unknown) | null);
|
|
49
|
+
}
|
|
50
|
+
export type PrimKind = "bool" | "s8" | "u8" | "s16" | "u16" | "s32" | "u32" | "s64" | "u64" | "f32" | "f64" | "char" | "string";
|
|
51
|
+
export interface PrimType {
|
|
52
|
+
kind: PrimKind;
|
|
53
|
+
}
|
|
54
|
+
export interface ErrorContextType {
|
|
55
|
+
kind: "error-context";
|
|
56
|
+
}
|
|
57
|
+
export interface ListType {
|
|
58
|
+
kind: "list";
|
|
59
|
+
element: ValType;
|
|
60
|
+
/** Fixed-length list when present (list<t, n>). */
|
|
61
|
+
length?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface FieldType {
|
|
64
|
+
label: string;
|
|
65
|
+
type: ValType;
|
|
66
|
+
}
|
|
67
|
+
export interface RecordType {
|
|
68
|
+
kind: "record";
|
|
69
|
+
fields: FieldType[];
|
|
70
|
+
}
|
|
71
|
+
export interface TupleType {
|
|
72
|
+
kind: "tuple";
|
|
73
|
+
elements: ValType[];
|
|
74
|
+
}
|
|
75
|
+
export interface CaseType {
|
|
76
|
+
label: string;
|
|
77
|
+
type: ValType | null;
|
|
78
|
+
}
|
|
79
|
+
export interface VariantType {
|
|
80
|
+
kind: "variant";
|
|
81
|
+
cases: CaseType[];
|
|
82
|
+
}
|
|
83
|
+
export interface EnumType {
|
|
84
|
+
kind: "enum";
|
|
85
|
+
labels: string[];
|
|
86
|
+
}
|
|
87
|
+
export interface OptionType {
|
|
88
|
+
kind: "option";
|
|
89
|
+
type: ValType;
|
|
90
|
+
}
|
|
91
|
+
export interface ResultType {
|
|
92
|
+
kind: "result";
|
|
93
|
+
ok: ValType | null;
|
|
94
|
+
error: ValType | null;
|
|
95
|
+
}
|
|
96
|
+
export interface MapType {
|
|
97
|
+
kind: "map";
|
|
98
|
+
key: ValType;
|
|
99
|
+
value: ValType;
|
|
100
|
+
}
|
|
101
|
+
export interface FlagsType {
|
|
102
|
+
kind: "flags";
|
|
103
|
+
labels: string[];
|
|
104
|
+
}
|
|
105
|
+
export interface OwnType {
|
|
106
|
+
kind: "own";
|
|
107
|
+
rt: ResourceTypeInfo;
|
|
108
|
+
}
|
|
109
|
+
export interface BorrowType {
|
|
110
|
+
kind: "borrow";
|
|
111
|
+
rt: ResourceTypeInfo;
|
|
112
|
+
}
|
|
113
|
+
export interface StreamType {
|
|
114
|
+
kind: "stream";
|
|
115
|
+
element: ValType | null;
|
|
116
|
+
}
|
|
117
|
+
export interface FutureType {
|
|
118
|
+
kind: "future";
|
|
119
|
+
element: ValType | null;
|
|
120
|
+
}
|
|
121
|
+
export type ValType = PrimType | ErrorContextType | ListType | RecordType | TupleType | VariantType | EnumType | OptionType | ResultType | MapType | FlagsType | OwnType | BorrowType | StreamType | FutureType;
|
|
122
|
+
/**
|
|
123
|
+
* definitions.py `FuncType`, without parameter/result names (names do not
|
|
124
|
+
* affect the ABI; bindings generation reads WIT instead — docs/architecture.md §9).
|
|
125
|
+
* `results` holds zero or one type in current CM, but stays a list to mirror
|
|
126
|
+
* the reference (`FuncType.result`).
|
|
127
|
+
*/
|
|
128
|
+
export interface FuncType {
|
|
129
|
+
params: ValType[];
|
|
130
|
+
results: ValType[];
|
|
131
|
+
async?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Host-side value representation produced by lifting / consumed by lowering:
|
|
135
|
+
* bool -> boolean
|
|
136
|
+
* u8..u32, s8..s32, f32, f64 -> number
|
|
137
|
+
* u64, s64 -> bigint
|
|
138
|
+
* char -> single-code-point string
|
|
139
|
+
* string -> string (plain; see README on dropped encoding provenance)
|
|
140
|
+
* list<u8> -> Uint8Array (copy; docs/architecture.md §7) — other lists -> Array
|
|
141
|
+
* record -> { [fieldLabel]: value }
|
|
142
|
+
* tuple -> despecialized record { "0": v0, "1": v1, ... }
|
|
143
|
+
* variant/enum/option/result -> single-key object { [caseLabel]: payload|null }
|
|
144
|
+
* flags -> { [label]: boolean }
|
|
145
|
+
* own/borrow -> number (the resource rep at this layer)
|
|
146
|
+
* These mirror definitions.py's Python shapes; final host-facing bindings
|
|
147
|
+
* representations are an open question (README).
|
|
148
|
+
*/
|
|
149
|
+
/**
|
|
150
|
+
* Opaque host token for the async value types.
|
|
151
|
+
*
|
|
152
|
+
* `stream`, `future` and `error-context` do not lift to plain data: the
|
|
153
|
+
* reference's `lift_async_value` (definitions.py line 1530) yields the
|
|
154
|
+
* *shared* stream/future object itself, because its identity is the value —
|
|
155
|
+
* two components holding ends of one stream must see each other's copies.
|
|
156
|
+
* Concretely these are `SharedStreamImpl`, `SharedFutureImpl` and
|
|
157
|
+
* `ErrorContext` instances (runtime/src/task/streams.ts); they are declared
|
|
158
|
+
* opaquely here to keep `cabi/types.ts` free of a dependency on the task
|
|
159
|
+
* layer. Host code should treat one as a token and pass it back unchanged.
|
|
160
|
+
*
|
|
161
|
+
* LIMITATION: this brand is *structural*, so an all-optional interface admits
|
|
162
|
+
* any object — it documents intent, it does not enforce it. The enforcement is
|
|
163
|
+
* at the lowering sites, which `assert_` on the concrete class before using a
|
|
164
|
+
* value (`lowerStream`/`lowerFuture` in cabi/async_values.ts check
|
|
165
|
+
* `instanceof SharedStreamImpl`/`SharedFutureImpl`). A nominal brand would
|
|
166
|
+
* need a required property, which the real classes could not satisfy without
|
|
167
|
+
* cabi importing the task layer — the cycle this declaration exists to avoid.
|
|
168
|
+
*/
|
|
169
|
+
export interface AsyncValue {
|
|
170
|
+
readonly __asyncValue?: never;
|
|
171
|
+
}
|
|
172
|
+
export type ComponentValue = AsyncValue | boolean | number | bigint | string | null | Uint8Array | ComponentValue[] | {
|
|
173
|
+
[label: string]: ComponentValue;
|
|
174
|
+
};
|
|
175
|
+
/** Core (flat) values: numbers for i32/f32/f64 lanes, bigints for i64 lanes. */
|
|
176
|
+
export type CoreValue = number | bigint;
|
|
177
|
+
export type DespecializedValType = Exclude<ValType, TupleType | EnumType | OptionType | ResultType | MapType>;
|
|
178
|
+
export declare function despecialize(t: ValType): DespecializedValType;
|
|
179
|
+
export declare function discriminantType(cases: CaseType[]): PrimType;
|
|
180
|
+
export declare function containsBorrow(t: ValType | null): boolean;
|
|
181
|
+
export declare function containsAsyncValue(t: ValType | null): boolean;
|
|
182
|
+
export declare function contains(t: ValType | null, p: (t: DespecializedValType) => boolean): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Structural `ValType` equality.
|
|
185
|
+
*
|
|
186
|
+
* CONTRACT (bugfix, TRACK C2-D; generalized during the #18 tls smoke): naive
|
|
187
|
+
* `JSON.stringify(a) === JSON.stringify(b)` recurses into `own`/`borrow`'s
|
|
188
|
+
* `ResourceTypeInfo` — a class whose `impl` field is documented "Compared by
|
|
189
|
+
* object identity everywhere" (see `ResourceTypeInfo` above) and which cycles
|
|
190
|
+
* back to the owning instance state (`impl.handles` holds live resource
|
|
191
|
+
* tables that reference their types), so `JSON.stringify` throws
|
|
192
|
+
* `TypeError: Converting circular structure to JSON` on ANY type containing
|
|
193
|
+
* `own<R>`/`borrow<R>` at any depth. First hit by `task.return` result types
|
|
194
|
+
* (C2-D, polymorph-test's `list<own<test-case>>`), then by stream/future
|
|
195
|
+
* element types (polymorph-tls streams carrying resource-bearing payloads).
|
|
196
|
+
* Object-identity types (`ResourceTypeInfo`) are compared by reference, per
|
|
197
|
+
* the documented invariant.
|
|
198
|
+
*/
|
|
199
|
+
export declare function valTypesEqual(a: ValType[], b: ValType[]): boolean;
|
|
200
|
+
export declare function valTypeEqual(a: ValType, b: ValType): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Cycle-safe display form for diagnostics. `JSON.stringify(t)` is UNSAFE on
|
|
203
|
+
* any resource-bearing type (see `valTypeEqual`'s contract note); this prints
|
|
204
|
+
* the structural shape and elides `ResourceTypeInfo` identities.
|
|
205
|
+
*/
|
|
206
|
+
export declare function fmtValType(t: ValType | null): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type CoreValueIter, type ValueIter } from "./lift.js";
|
|
2
|
+
import { type LiftLowerContext } from "./context.js";
|
|
3
|
+
import type { ComponentValue, CoreValue, ValType } from "./types.js";
|
|
4
|
+
export declare function liftFlatValues(cx: LiftLowerContext, maxFlat: number, vi: CoreValueIter, ts: ValType[]): ComponentValue[];
|
|
5
|
+
export declare function lowerFlatValues(cx: LiftLowerContext, maxFlat: number, vs: ComponentValue[], ts: ValType[], outParam?: ValueIter | null): CoreValue[];
|