@opencode/codemode 2.2.0 → 2.2.1
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/README.md +33 -4
- package/dist/codemode.d.ts +9 -7
- package/dist/codemode.js +1 -1
- package/dist/data.d.ts +5 -4
- package/dist/data.js +7 -4
- package/dist/extension.d.ts +17 -4
- package/dist/extension.js +8 -0
- package/dist/interpreter/callback.d.ts +10 -10
- package/dist/interpreter/callback.js +43 -31
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/errors.js +12 -15
- package/dist/interpreter/execute.js +59 -29
- package/dist/interpreter/extensions.d.ts +2 -2
- package/dist/interpreter/extensions.js +46 -18
- package/dist/interpreter/generators.js +162 -19
- package/dist/interpreter/globals.js +12 -9
- package/dist/interpreter/interpreter.d.ts +20 -13
- package/dist/interpreter/interpreter.js +1329 -1147
- package/dist/interpreter/intrinsics.js +1 -2
- package/dist/interpreter/model.d.ts +4 -7
- package/dist/interpreter/model.js +1 -11
- package/dist/interpreter/native.d.ts +7 -8
- package/dist/interpreter/native.js +4 -10
- package/dist/interpreter/objects.d.ts +47 -21
- package/dist/interpreter/objects.js +33 -12
- package/dist/interpreter/promises.d.ts +15 -53
- package/dist/interpreter/promises.js +226 -401
- package/dist/interpreter/runner.d.ts +188 -0
- package/dist/interpreter/runner.js +492 -0
- package/dist/stdlib/array.d.ts +3 -3
- package/dist/stdlib/array.js +106 -102
- package/dist/stdlib/bytes.d.ts +3 -3
- package/dist/stdlib/bytes.js +46 -41
- package/dist/stdlib/collections.d.ts +5 -5
- package/dist/stdlib/collections.js +160 -165
- package/dist/stdlib/date.d.ts +1 -1
- package/dist/stdlib/date.js +28 -20
- package/dist/stdlib/headers.d.ts +1 -1
- package/dist/stdlib/headers.js +14 -19
- package/dist/stdlib/iterator.d.ts +1 -1
- package/dist/stdlib/iterator.js +140 -122
- package/dist/stdlib/json.js +9 -12
- package/dist/stdlib/math.js +10 -10
- package/dist/stdlib/number.d.ts +2 -2
- package/dist/stdlib/object.d.ts +1 -1
- package/dist/stdlib/object.js +21 -22
- package/dist/stdlib/regexp.d.ts +1 -1
- package/dist/stdlib/regexp.js +2 -3
- package/dist/stdlib/string.d.ts +1 -1
- package/dist/stdlib/string.js +18 -20
- package/dist/stdlib/url.d.ts +5 -5
- package/dist/stdlib/url.js +32 -33
- package/dist/stdlib/value.d.ts +2 -2
- package/dist/stdlib/web.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import { define, hidden, Native, Arr, ErrorObj, Obj } from "./objects.js";
|
|
3
2
|
export const errorTypes = [
|
|
4
3
|
"Error",
|
|
@@ -56,7 +55,7 @@ export const primitivePrototype = (builtins, value) => {
|
|
|
56
55
|
export const createBuiltins = () => {
|
|
57
56
|
const object = new Obj(null);
|
|
58
57
|
// Function.prototype is itself callable and returns undefined.
|
|
59
|
-
const fn = new Native(object, { name: "", call: () =>
|
|
58
|
+
const fn = new Native(object, { name: "", call: () => undefined });
|
|
60
59
|
const plain = () => new Obj(object);
|
|
61
60
|
const error = plain();
|
|
62
61
|
define(error, "name", "Error", hidden);
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import type { Node } from "acorn";
|
|
2
|
-
import { Context } from "effect";
|
|
3
2
|
import type { ErrorType } from "./intrinsics.js";
|
|
4
3
|
import type { DiagnosticKind } from "../codemode.js";
|
|
5
4
|
import type { ErrorObj, Value } from "./objects.js";
|
|
6
5
|
/** Any parsed node; the interpreter narrows on `type` and reads `loc` for diagnostics. */
|
|
7
6
|
export type AstNode = Node;
|
|
8
|
-
/** The program call a built-in is running under: where to locate failures born inside it, and how deep the stack is there. */
|
|
9
|
-
export declare const CallSite: Context.Reference<{
|
|
10
|
-
readonly node?: AstNode;
|
|
11
|
-
readonly depth: number;
|
|
12
|
-
}>;
|
|
13
7
|
export type Binding = {
|
|
14
8
|
mutable: boolean;
|
|
15
9
|
value: Value;
|
|
@@ -68,4 +62,7 @@ export declare const sourceLocation: (node: AstNode) => {
|
|
|
68
62
|
readonly line: number;
|
|
69
63
|
readonly column: number;
|
|
70
64
|
};
|
|
71
|
-
export declare const formatLocation: (
|
|
65
|
+
export declare const formatLocation: (location?: {
|
|
66
|
+
readonly line: number;
|
|
67
|
+
readonly column: number;
|
|
68
|
+
}) => string;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
2
|
-
/** The program call a built-in is running under: where to locate failures born inside it, and how deep the stack is there. */
|
|
3
|
-
export const CallSite = Context.Reference("codemode/CallSite", {
|
|
4
|
-
defaultValue: () => ({ depth: 0 }),
|
|
5
|
-
});
|
|
6
1
|
export const AsyncIteratorSymbol = Symbol("codemode.async-iterator");
|
|
7
2
|
export const IteratorSymbol = Symbol("codemode.iterator");
|
|
8
3
|
export const IteratorSymbols = [AsyncIteratorSymbol, IteratorSymbol];
|
|
@@ -56,9 +51,4 @@ export const sourceLocation = (node) => ({
|
|
|
56
51
|
line: node.loc?.start.line ?? 1,
|
|
57
52
|
column: (node.loc?.start.column ?? 0) + 1,
|
|
58
53
|
});
|
|
59
|
-
export const formatLocation = (
|
|
60
|
-
if (!node?.loc)
|
|
61
|
-
return "";
|
|
62
|
-
const location = sourceLocation(node);
|
|
63
|
-
return ` (line ${location.line}, col ${location.column})`;
|
|
64
|
-
};
|
|
54
|
+
export const formatLocation = (location) => location ? ` (line ${location.line}, col ${location.column})` : "";
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import type { Builtins } from "./intrinsics.js";
|
|
3
|
-
import { type Callable, Native, type NativeOptions, Obj, type Value } from "./objects.js";
|
|
4
|
-
/** A native function body: a value, a thrown `PendingThrow`, or
|
|
5
|
-
export type Impl =
|
|
6
|
-
export declare const native:
|
|
7
|
-
export declare const fn:
|
|
2
|
+
import { type Callable, Native, type NativeCall, type NativeOptions, Obj, type Value } from "./objects.js";
|
|
3
|
+
/** A native function body: a value, a thrown `PendingThrow`, or interpreter work producing a value. */
|
|
4
|
+
export type Impl = NativeCall;
|
|
5
|
+
export declare const native: (builtins: Builtins, options: NativeOptions) => Native;
|
|
6
|
+
export declare const fn: (builtins: Builtins, name: string, length: number, impl: Impl) => Native;
|
|
8
7
|
export type Method = readonly [name: string, length: number, impl: Impl];
|
|
9
8
|
export declare const methods: (builtins: Builtins, target: Obj, table: ReadonlyArray<Method>) => void;
|
|
10
9
|
export declare const constants: (target: Obj, table: Record<string, Value>) => void;
|
|
11
10
|
/** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
|
|
12
|
-
export declare const constructor:
|
|
11
|
+
export declare const constructor: (builtins: Builtins, proto: Obj, options: NativeOptions) => Native;
|
|
13
12
|
/** The `call` of a constructor that JS requires to be invoked with `new`. */
|
|
14
|
-
export declare const requiresNew: (name: string) => () =>
|
|
13
|
+
export declare const requiresNew: (name: string) => () => never;
|
|
15
14
|
/** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
|
|
16
15
|
export declare const prototypeFrom: (newTarget: Callable, fallback: Obj) => Obj;
|
|
17
16
|
/** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import { typeError } from "./model.js";
|
|
3
|
-
import { define, frozen, hidden, Native, Obj } from "./objects.js";
|
|
2
|
+
import { define, frozen, hidden, Native, Obj, } from "./objects.js";
|
|
4
3
|
import { describeValue } from "./references.js";
|
|
5
|
-
// The dispatch in `Frame.call` suspends every native call, so a synchronous throw here is a defect.
|
|
6
|
-
const lift = (impl) => (thisValue, args) => {
|
|
7
|
-
const result = impl(thisValue, args);
|
|
8
|
-
return Effect.isEffect(result) ? result : Effect.succeed(result);
|
|
9
|
-
};
|
|
10
4
|
export const native = (builtins, options) => new Native(builtins.Function, options);
|
|
11
|
-
export const fn = (builtins, name, length, impl) => native(builtins, { name, length, call:
|
|
5
|
+
export const fn = (builtins, name, length, impl) => native(builtins, { name, length, call: impl });
|
|
12
6
|
export const methods = (builtins, target, table) => {
|
|
13
7
|
for (const [name, length, impl] of table)
|
|
14
8
|
define(target, name, fn(builtins, name, length, impl), hidden);
|
|
@@ -25,9 +19,9 @@ export const constructor = (builtins, proto, options) => {
|
|
|
25
19
|
return ctor;
|
|
26
20
|
};
|
|
27
21
|
/** The `call` of a constructor that JS requires to be invoked with `new`. */
|
|
28
|
-
export const requiresNew = (name) => () =>
|
|
22
|
+
export const requiresNew = (name) => () => {
|
|
29
23
|
throw typeError(`Constructor ${name} requires 'new'.`);
|
|
30
|
-
}
|
|
24
|
+
};
|
|
31
25
|
/** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
|
|
32
26
|
export const prototypeFrom = (newTarget, fallback) => {
|
|
33
27
|
const proto = newTarget.props.get("prototype");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { BlockStatement, Expression, Pattern } from "acorn";
|
|
2
|
-
import { Effect, type Fiber } from "effect";
|
|
3
2
|
import { ToolReference } from "../tool-runtime.js";
|
|
4
3
|
import type { Builtins } from "./intrinsics.js";
|
|
5
|
-
import { type
|
|
4
|
+
import { type AstNode, type Binding } from "./model.js";
|
|
5
|
+
import type { Entry, Eval, GeneratorRequest, Reaction, Resolving } from "./runner.js";
|
|
6
6
|
/** Property attributes, as in a JS property descriptor. */
|
|
7
7
|
export type Attributes = {
|
|
8
8
|
readonly writable: boolean;
|
|
@@ -73,8 +73,8 @@ export declare class Arr extends Obj {
|
|
|
73
73
|
/** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
|
|
74
74
|
export declare class ErrorObj extends Obj {
|
|
75
75
|
readonly tag = "Error";
|
|
76
|
-
/** The
|
|
77
|
-
host?:
|
|
76
|
+
/** The failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
|
|
77
|
+
host?: unknown;
|
|
78
78
|
/** Error.prototype.toString: "name: message", or just one when the other is empty. */
|
|
79
79
|
toString(): string;
|
|
80
80
|
inspect(): string;
|
|
@@ -107,35 +107,59 @@ export declare class Arguments extends Obj {
|
|
|
107
107
|
constructor(proto: Obj, args: Array<Value>);
|
|
108
108
|
iterator(): ArrayIterator<Value>;
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
export type
|
|
112
|
-
|
|
110
|
+
/** A native function body: a value, or interpreter work for bodies that call program code or the host. */
|
|
111
|
+
export type NativeResult = Value | Eval<Value>;
|
|
112
|
+
/** `site` is the call running the built-in, where a failure it reports later (a rejection) is located. */
|
|
113
|
+
export type NativeCall = (thisValue: Value, args: Array<Value>, site: AstNode | undefined) => NativeResult;
|
|
114
|
+
export type NativeConstruct = (args: Array<Value>, newTarget: Callable, site: AstNode | undefined) => NativeResult;
|
|
115
|
+
export type NativeOptions = {
|
|
113
116
|
readonly name: string;
|
|
114
117
|
readonly length?: number;
|
|
115
|
-
readonly call: NativeCall
|
|
118
|
+
readonly call: NativeCall;
|
|
116
119
|
/** `new name(...)`; without it the function is not a constructor. */
|
|
117
|
-
readonly construct?: NativeConstruct
|
|
120
|
+
readonly construct?: NativeConstruct;
|
|
118
121
|
/** Whether callback sites (array methods, replacers, promise reactions) admit this function. Defaults to true. */
|
|
119
122
|
readonly callback?: boolean;
|
|
120
123
|
};
|
|
121
|
-
export declare class Native
|
|
122
|
-
readonly call: NativeCall
|
|
123
|
-
readonly construct: NativeConstruct
|
|
124
|
+
export declare class Native extends Callable {
|
|
125
|
+
readonly call: NativeCall;
|
|
126
|
+
readonly construct: NativeConstruct | undefined;
|
|
124
127
|
readonly callback: boolean;
|
|
125
|
-
constructor(proto: Obj, options: NativeOptions
|
|
128
|
+
constructor(proto: Obj, options: NativeOptions);
|
|
126
129
|
}
|
|
127
130
|
export declare class PromiseObj extends Opaque {
|
|
128
|
-
|
|
131
|
+
/** Creation order, for reporting unhandled rejections in the order their promises were made. */
|
|
132
|
+
readonly id: number;
|
|
129
133
|
readonly tag = "Promise";
|
|
130
|
-
|
|
134
|
+
state: "pending" | "fulfilled" | "rejected";
|
|
135
|
+
/** The value, or the failure as thrown; a handler receives it materialized. */
|
|
136
|
+
result: unknown;
|
|
137
|
+
reactions: Array<Reaction>;
|
|
138
|
+
/** [[PromiseIsHandled]]: a reaction was attached, so a rejection is not reported as unhandled. */
|
|
139
|
+
handled: boolean;
|
|
140
|
+
constructor(proto: Obj,
|
|
141
|
+
/** Creation order, for reporting unhandled rejections in the order their promises were made. */
|
|
142
|
+
id: number);
|
|
131
143
|
get describe(): string;
|
|
132
144
|
inspect(): string;
|
|
133
145
|
}
|
|
146
|
+
export type GeneratorState = "suspendedStart" | "suspendedYield" | "executing" | "awaiting-return" | "draining" | "completed";
|
|
134
147
|
export declare class GeneratorObj extends Opaque {
|
|
135
148
|
readonly asynchronous: boolean;
|
|
136
|
-
|
|
149
|
+
/** The body, started by the first `next()`. */
|
|
150
|
+
readonly body: Eval<Value>;
|
|
137
151
|
readonly tag = "Generator";
|
|
138
|
-
|
|
152
|
+
state: GeneratorState;
|
|
153
|
+
/** The suspended body's activations, kept while it waits for the next request. */
|
|
154
|
+
entries: Array<Entry> | undefined;
|
|
155
|
+
/** An async generator's requests, oldest first, each with the functions that settle its promise. */
|
|
156
|
+
readonly queue: Array<{
|
|
157
|
+
readonly request: GeneratorRequest;
|
|
158
|
+
readonly resolving: Resolving;
|
|
159
|
+
}>;
|
|
160
|
+
constructor(proto: Obj, asynchronous: boolean,
|
|
161
|
+
/** The body, started by the first `next()`. */
|
|
162
|
+
body: Eval<Value>);
|
|
139
163
|
get describe(): string;
|
|
140
164
|
}
|
|
141
165
|
/** One pull from an iterator, as `for...of` sees it. */
|
|
@@ -144,12 +168,12 @@ export type Step = {
|
|
|
144
168
|
readonly value: Value;
|
|
145
169
|
};
|
|
146
170
|
/** How the interpreter drives any iterator: pull the next step, or close it early. */
|
|
147
|
-
export type Cursor
|
|
148
|
-
readonly next:
|
|
149
|
-
readonly close:
|
|
171
|
+
export type Cursor = {
|
|
172
|
+
readonly next: () => Eval<Step>;
|
|
173
|
+
readonly close: () => Eval<void>;
|
|
150
174
|
};
|
|
151
175
|
/** A cursor over a host iterator; there is nothing to close. */
|
|
152
|
-
export declare const hostCursor: (iterator: Iterator<Value, undefined>) => Cursor
|
|
176
|
+
export declare const hostCursor: (iterator: Iterator<Value, undefined>) => Cursor;
|
|
153
177
|
/** A built-in iterator: a live cursor over a host collection or an iterator helper, yielding program values. */
|
|
154
178
|
export declare class IteratorObj extends Opaque {
|
|
155
179
|
readonly cursor: Cursor;
|
|
@@ -271,5 +295,7 @@ export declare const enumerableKeys: (target: Obj) => Array<string | symbol>;
|
|
|
271
295
|
export declare const keys: (target: Obj) => Array<string>;
|
|
272
296
|
/** Own enumerable string entries: `Object.entries` and serialization. */
|
|
273
297
|
export declare const entries: (target: Obj) => Array<[string, Value]>;
|
|
298
|
+
/** An iterator result `{ value, done }`, built directly since every iteration step makes one. */
|
|
299
|
+
export declare const iteratorResult: (proto: Obj, value: Value, done: boolean) => Obj;
|
|
274
300
|
export declare const record: (proto: Obj, fields: Record<string, Value>) => Obj;
|
|
275
301
|
export declare const assign: (target: Obj, source: Obj, skip?: ReadonlySet<PropertyKey>) => void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import { ToolReference } from "../tool-runtime.js";
|
|
3
2
|
import { checkArrayLength } from "./limits.js";
|
|
4
|
-
import { AsyncIteratorSymbol, IteratorSymbol, rangeError, typeError
|
|
3
|
+
import { AsyncIteratorSymbol, IteratorSymbol, rangeError, typeError } from "./model.js";
|
|
5
4
|
/** Ordinary assignment: writable, enumerable, configurable. */
|
|
6
5
|
export const data = { writable: true, enumerable: true, configurable: true };
|
|
7
6
|
/** Built-in methods and `constructor`: writable and configurable but hidden from enumeration. */
|
|
@@ -87,7 +86,7 @@ export class Arr extends Obj {
|
|
|
87
86
|
/** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
|
|
88
87
|
export class ErrorObj extends Obj {
|
|
89
88
|
tag = "Error";
|
|
90
|
-
/** The
|
|
89
|
+
/** The failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
|
|
91
90
|
host;
|
|
92
91
|
/** Error.prototype.toString: "name: message", or just one when the other is empty. */
|
|
93
92
|
toString() {
|
|
@@ -170,11 +169,19 @@ export class Native extends Callable {
|
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
export class PromiseObj extends Opaque {
|
|
173
|
-
|
|
172
|
+
id;
|
|
174
173
|
tag = "Promise";
|
|
175
|
-
|
|
174
|
+
state = "pending";
|
|
175
|
+
/** The value, or the failure as thrown; a handler receives it materialized. */
|
|
176
|
+
result = undefined;
|
|
177
|
+
reactions = [];
|
|
178
|
+
/** [[PromiseIsHandled]]: a reaction was attached, so a rejection is not reported as unhandled. */
|
|
179
|
+
handled = false;
|
|
180
|
+
constructor(proto,
|
|
181
|
+
/** Creation order, for reporting unhandled rejections in the order their promises were made. */
|
|
182
|
+
id) {
|
|
176
183
|
super(proto);
|
|
177
|
-
this.
|
|
184
|
+
this.id = id;
|
|
178
185
|
}
|
|
179
186
|
get describe() {
|
|
180
187
|
return "an un-awaited Promise";
|
|
@@ -185,12 +192,19 @@ export class PromiseObj extends Opaque {
|
|
|
185
192
|
}
|
|
186
193
|
export class GeneratorObj extends Opaque {
|
|
187
194
|
asynchronous;
|
|
188
|
-
|
|
195
|
+
body;
|
|
189
196
|
tag = "Generator";
|
|
190
|
-
|
|
197
|
+
state = "suspendedStart";
|
|
198
|
+
/** The suspended body's activations, kept while it waits for the next request. */
|
|
199
|
+
entries;
|
|
200
|
+
/** An async generator's requests, oldest first, each with the functions that settle its promise. */
|
|
201
|
+
queue = [];
|
|
202
|
+
constructor(proto, asynchronous,
|
|
203
|
+
/** The body, started by the first `next()`. */
|
|
204
|
+
body) {
|
|
191
205
|
super(proto);
|
|
192
206
|
this.asynchronous = asynchronous;
|
|
193
|
-
this.
|
|
207
|
+
this.body = body;
|
|
194
208
|
}
|
|
195
209
|
get describe() {
|
|
196
210
|
return "a generator";
|
|
@@ -198,11 +212,11 @@ export class GeneratorObj extends Opaque {
|
|
|
198
212
|
}
|
|
199
213
|
/** A cursor over a host iterator; there is nothing to close. */
|
|
200
214
|
export const hostCursor = (iterator) => ({
|
|
201
|
-
next:
|
|
215
|
+
next: function* () {
|
|
202
216
|
const step = iterator.next();
|
|
203
217
|
return { done: Boolean(step.done), value: step.value };
|
|
204
|
-
}
|
|
205
|
-
close:
|
|
218
|
+
},
|
|
219
|
+
close: function* () { },
|
|
206
220
|
});
|
|
207
221
|
/** A built-in iterator: a live cursor over a host collection or an iterator helper, yielding program values. */
|
|
208
222
|
export class IteratorObj extends Opaque {
|
|
@@ -556,6 +570,13 @@ export const enumerableKeys = (target) => ownKeys(target).filter((key) => (typeo
|
|
|
556
570
|
export const keys = (target) => ownKeys(target).filter((key) => typeof key === "string" && enumerable(target, key));
|
|
557
571
|
/** Own enumerable string entries: `Object.entries` and serialization. */
|
|
558
572
|
export const entries = (target) => keys(target).map((key) => [key, getOwn(target, key)]);
|
|
573
|
+
/** An iterator result `{ value, done }`, built directly since every iteration step makes one. */
|
|
574
|
+
export const iteratorResult = (proto, value, done) => {
|
|
575
|
+
const target = new Obj(proto);
|
|
576
|
+
target.props.set("value", { value, writable: true, enumerable: true, configurable: true });
|
|
577
|
+
target.props.set("done", { value: done, writable: true, enumerable: true, configurable: true });
|
|
578
|
+
return target;
|
|
579
|
+
};
|
|
559
580
|
export const record = (proto, fields) => {
|
|
560
581
|
const target = new Obj(proto);
|
|
561
582
|
for (const [key, value] of Object.entries(fields))
|
|
@@ -1,56 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
import { Obj, PromiseObj, type Value } from "./objects.js";
|
|
1
|
+
import { type AstNode } from "./model.js";
|
|
2
|
+
import { PromiseObj, type Value } from "./objects.js";
|
|
4
3
|
import type { Interpreter } from "./interpreter.js";
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* run program code. A synchronous call into another fiber (an async function's body up to its first await, a
|
|
9
|
-
* generator step) lends that fiber the turn and gets it back when the callee suspends or ends. An await gives the turn
|
|
10
|
-
* to the next waiting job and queues to take it back. Work that only settles a promise or runs host code leaves
|
|
11
|
-
* without it, so tool calls stay concurrent and resolvers settle in the call, as in JavaScript.
|
|
5
|
+
* NewPromiseCapability(%Promise%): a pending promise with the host functions that settle it once. A built-in's own
|
|
6
|
+
* failure that rejects it is located at `site`, the call that created it.
|
|
12
7
|
*/
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
handOff<A, E, R>(start: Effect.Effect<A, E, R>): Effect.Effect<void, E, R>;
|
|
25
|
-
park<A, E, R>(wait: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
26
|
-
fork<A, E, R>(effect: Effect.Effect<A, E, R>, scope: Scope.Scope): Effect.Effect<Fiber.Fiber<A, E>, never, R>;
|
|
27
|
-
private handBack;
|
|
28
|
-
private nest;
|
|
29
|
-
}
|
|
30
|
-
export declare class Pending<R> {
|
|
31
|
-
private readonly scope;
|
|
32
|
-
private readonly proto;
|
|
33
|
-
readonly turn: Turn;
|
|
34
|
-
private readonly active;
|
|
35
|
-
private readonly ids;
|
|
36
|
-
private readonly observed;
|
|
37
|
-
private readonly failures;
|
|
38
|
-
private nextID;
|
|
39
|
-
constructor(scope: Scope.Scope, proto: Obj);
|
|
40
|
-
createWithSelf(body: (self: {
|
|
41
|
-
promise?: PromiseObj;
|
|
42
|
-
}) => Effect.Effect<Value, unknown, R>): Effect.Effect<PromiseObj, never, R>;
|
|
43
|
-
create(effect: Effect.Effect<Value, unknown, R>): Effect.Effect<PromiseObj, never, R>;
|
|
44
|
-
createHost(effect: Effect.Effect<Value, unknown, R>): Effect.Effect<PromiseObj, never, R>;
|
|
45
|
-
private register;
|
|
46
|
-
markObserved(promise: PromiseObj): void;
|
|
47
|
-
await(promise: PromiseObj): Effect.Effect<Exit.Exit<Value, unknown>>;
|
|
48
|
-
fork(effect: Effect.Effect<unknown, unknown, R>): Effect.Effect<void, never, R>;
|
|
49
|
-
diagnostics(): Array<Diagnostic>;
|
|
50
|
-
interrupt(): Effect.Effect<Array<Diagnostic>>;
|
|
51
|
-
}
|
|
52
|
-
export declare const resolvePromiseValue: <R>(ctx: Interpreter<R>, value: Value, own?: {
|
|
53
|
-
promise?: PromiseObj;
|
|
54
|
-
}) => Effect.Effect<Value, unknown, R>;
|
|
55
|
-
export declare const resolvePromise: <R>(ctx: Interpreter<R>, value: Value) => Effect.Effect<PromiseObj, never, R>;
|
|
56
|
-
export declare const promiseGlobal: <R>(ctx: Interpreter<R>) => import("./objects.js").Native<R>;
|
|
8
|
+
export declare const capability: <R>(ctx: Interpreter<R>, site: AstNode | undefined) => {
|
|
9
|
+
resolve: (resolution: Value) => void;
|
|
10
|
+
reject: (reason: unknown) => void;
|
|
11
|
+
promise: PromiseObj;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Lets a synchronous object result also be awaited or chained like a Promise. It inherits non-enumerable
|
|
15
|
+
* then/catch/finally that settle with a plain copy, so data views never show them and awaiting does not recurse.
|
|
16
|
+
*/
|
|
17
|
+
export declare const promiseLike: <R>(ctx: Interpreter<R>, value: Value) => Value;
|
|
18
|
+
export declare const promiseGlobal: <R>(ctx: Interpreter<R>) => import("./objects.js").Native;
|