@opencode/codemode 0.0.0-dev-892 → 0.0.0-dev-900
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 +3 -0
- package/dist/codemode.d.ts +2 -0
- package/dist/codemode.js +10 -4
- package/dist/vm/async.d.ts +78 -0
- package/dist/vm/async.js +335 -0
- package/dist/vm/code.d.ts +122 -0
- package/dist/vm/code.js +407 -0
- package/dist/vm/compiler/compile.d.ts +13 -0
- package/dist/vm/compiler/compile.js +1477 -0
- package/dist/vm/compiler/scope.d.ts +74 -0
- package/dist/vm/compiler/scope.js +515 -0
- package/dist/vm/data.d.ts +7 -0
- package/dist/vm/data.js +13 -0
- package/dist/vm/generators.d.ts +42 -0
- package/dist/vm/generators.js +413 -0
- package/dist/vm/host.d.ts +103 -0
- package/dist/vm/host.js +226 -0
- package/dist/vm/index.d.ts +3 -0
- package/dist/vm/index.js +3 -0
- package/dist/vm/internal-prelude.d.ts +45 -0
- package/dist/vm/internal-prelude.js +534 -0
- package/dist/vm/opcodes.d.ts +222 -0
- package/dist/vm/opcodes.js +235 -0
- package/dist/vm/prelude/bytecode.d.ts +18 -0
- package/dist/vm/prelude/bytecode.js +31 -0
- package/dist/vm/prelude/bytecode.json +1 -0
- package/dist/vm/prelude/helpers.d.ts +8 -0
- package/dist/vm/prelude/helpers.js +258 -0
- package/dist/vm/prelude/prelude.d.ts +21 -0
- package/dist/vm/prelude/prelude.js +53 -0
- package/dist/vm/prelude/source.d.ts +1 -0
- package/dist/vm/prelude/source.js +652 -0
- package/dist/vm/runtime/callback.d.ts +25 -0
- package/dist/vm/runtime/callback.js +51 -0
- package/dist/vm/runtime/driver.d.ts +41 -0
- package/dist/vm/runtime/driver.js +142 -0
- package/dist/vm/runtime/errors.d.ts +23 -0
- package/dist/vm/runtime/errors.js +169 -0
- package/dist/vm/runtime/execute.d.ts +22 -0
- package/dist/vm/runtime/execute.js +278 -0
- package/dist/vm/runtime/extensions.d.ts +16 -0
- package/dist/vm/runtime/extensions.js +270 -0
- package/dist/vm/runtime/generators.d.ts +6 -0
- package/dist/vm/runtime/generators.js +44 -0
- package/dist/vm/runtime/globals.d.ts +6 -0
- package/dist/vm/runtime/globals.js +137 -0
- package/dist/vm/runtime/interpreter.d.ts +50 -0
- package/dist/vm/runtime/interpreter.js +94 -0
- package/dist/vm/runtime/intrinsic-names.d.ts +56 -0
- package/dist/vm/runtime/intrinsic-names.js +166 -0
- package/dist/vm/runtime/intrinsics.d.ts +15 -0
- package/dist/vm/runtime/intrinsics.js +111 -0
- package/dist/vm/runtime/limits.d.ts +10 -0
- package/dist/vm/runtime/limits.js +19 -0
- package/dist/vm/runtime/model.d.ts +58 -0
- package/dist/vm/runtime/model.js +57 -0
- package/dist/vm/runtime/modules.d.ts +4 -0
- package/dist/vm/runtime/modules.js +33 -0
- package/dist/vm/runtime/native.d.ts +19 -0
- package/dist/vm/runtime/native.js +41 -0
- package/dist/vm/runtime/objects.d.ts +403 -0
- package/dist/vm/runtime/objects.js +784 -0
- package/dist/vm/runtime/operations.d.ts +49 -0
- package/dist/vm/runtime/operations.js +288 -0
- package/dist/vm/runtime/promises.d.ts +55 -0
- package/dist/vm/runtime/promises.js +232 -0
- package/dist/vm/runtime/references.d.ts +8 -0
- package/dist/vm/runtime/references.js +51 -0
- package/dist/vm/runtime/signals.d.ts +69 -0
- package/dist/vm/runtime/signals.js +68 -0
- package/dist/vm/runtime/source.d.ts +29 -0
- package/dist/vm/runtime/source.js +63 -0
- package/dist/vm/runtime/table.d.ts +43 -0
- package/dist/vm/runtime/table.js +132 -0
- package/dist/vm/scheduler.d.ts +178 -0
- package/dist/vm/scheduler.js +63 -0
- package/dist/vm/snapshot/codec.d.ts +88 -0
- package/dist/vm/snapshot/codec.js +752 -0
- package/dist/vm/snapshot/snapshot.d.ts +39 -0
- package/dist/vm/snapshot/snapshot.js +69 -0
- package/dist/vm/snapshot.d.ts +29 -0
- package/dist/vm/snapshot.js +304 -0
- package/dist/vm/stdlib/array.d.ts +16 -0
- package/dist/vm/stdlib/array.js +311 -0
- package/dist/vm/stdlib/bytes.d.ts +11 -0
- package/dist/vm/stdlib/bytes.js +222 -0
- package/dist/vm/stdlib/collections.d.ts +7 -0
- package/dist/vm/stdlib/collections.js +188 -0
- package/dist/vm/stdlib/console.d.ts +6 -0
- package/dist/vm/stdlib/console.js +93 -0
- package/dist/vm/stdlib/date.d.ts +2 -0
- package/dist/vm/stdlib/date.js +123 -0
- package/dist/vm/stdlib/headers.d.ts +2 -0
- package/dist/vm/stdlib/headers.js +92 -0
- package/dist/vm/stdlib/iterator.d.ts +2 -0
- package/dist/vm/stdlib/iterator.js +30 -0
- package/dist/vm/stdlib/json.d.ts +3 -0
- package/dist/vm/stdlib/json.js +42 -0
- package/dist/vm/stdlib/math.d.ts +3 -0
- package/dist/vm/stdlib/math.js +73 -0
- package/dist/vm/stdlib/number.d.ts +3 -0
- package/dist/vm/stdlib/number.js +72 -0
- package/dist/vm/stdlib/object.d.ts +6 -0
- package/dist/vm/stdlib/object.js +201 -0
- package/dist/vm/stdlib/regexp.d.ts +8 -0
- package/dist/vm/stdlib/regexp.js +119 -0
- package/dist/vm/stdlib/string.d.ts +2 -0
- package/dist/vm/stdlib/string.js +272 -0
- package/dist/vm/stdlib/url.d.ts +25 -0
- package/dist/vm/stdlib/url.js +255 -0
- package/dist/vm/stdlib/value.d.ts +6 -0
- package/dist/vm/stdlib/value.js +32 -0
- package/dist/vm/stdlib/web.d.ts +5 -0
- package/dist/vm/stdlib/web.js +97 -0
- package/dist/vm/vm.d.ts +224 -0
- package/dist/vm/vm.js +2921 -0
- package/package.json +5 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { locate } from "./runtime/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Host work the program waits on. The VM queues it and hands it to the driver at its next stop; the driver runs it and
|
|
4
|
+
* reports how it ended with `Vm.complete`. A concurrent call's outcome waits in the inbox and settles its promise in a
|
|
5
|
+
* later job; a blocking call stops the VM, and no other job runs until it ends.
|
|
6
|
+
*/
|
|
7
|
+
export class HostCall {
|
|
8
|
+
id;
|
|
9
|
+
request;
|
|
10
|
+
label;
|
|
11
|
+
blocking;
|
|
12
|
+
result;
|
|
13
|
+
resolving;
|
|
14
|
+
site;
|
|
15
|
+
/** Where the call is: `queued` (written ahead, not started), `running`, or `completed`. */
|
|
16
|
+
status = "queued";
|
|
17
|
+
constructor(id, request,
|
|
18
|
+
/** What runs: a tool path, or an extension function's label. */
|
|
19
|
+
label,
|
|
20
|
+
/** The running job waits for it: its outcome continues the frame that asked, before any other job. */
|
|
21
|
+
blocking,
|
|
22
|
+
/** How a concurrent call's result becomes a program value: a tool's crosses as JSON, an extension's is one. */
|
|
23
|
+
result,
|
|
24
|
+
/** Settles a concurrent call's promise. */
|
|
25
|
+
resolving,
|
|
26
|
+
/** The call that started the work, where a defect it raises is located. */
|
|
27
|
+
site) {
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.request = request;
|
|
30
|
+
this.label = label;
|
|
31
|
+
this.blocking = blocking;
|
|
32
|
+
this.result = result;
|
|
33
|
+
this.resolving = resolving;
|
|
34
|
+
this.site = site;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* CreateResolvingFunctions as data: settles one promise at most once, however many `Resolver`s share it. `reject` takes
|
|
39
|
+
* the failure as thrown; one without a location is located at `site`, the call that created the promise.
|
|
40
|
+
*/
|
|
41
|
+
export class Resolving {
|
|
42
|
+
scheduler;
|
|
43
|
+
promise;
|
|
44
|
+
site;
|
|
45
|
+
done = false;
|
|
46
|
+
constructor(scheduler, promise, site) {
|
|
47
|
+
this.scheduler = scheduler;
|
|
48
|
+
this.promise = promise;
|
|
49
|
+
this.site = site;
|
|
50
|
+
}
|
|
51
|
+
resolve(resolution) {
|
|
52
|
+
if (this.done)
|
|
53
|
+
return;
|
|
54
|
+
this.done = true;
|
|
55
|
+
this.scheduler.resolveWith(this.promise, resolution, this.site);
|
|
56
|
+
}
|
|
57
|
+
reject(reason) {
|
|
58
|
+
if (this.done)
|
|
59
|
+
return;
|
|
60
|
+
this.done = true;
|
|
61
|
+
this.scheduler.reject(this.promise, locate(reason, this.site));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type AstNode } from "../runtime/model.js";
|
|
2
|
+
import { Obj } from "../runtime/objects.js";
|
|
3
|
+
import { Interruption } from "../runtime/signals.js";
|
|
4
|
+
/** A plain JSON value, as a snapshot holds it. */
|
|
5
|
+
export type Json = null | boolean | number | string | ReadonlyArray<Json> | {
|
|
6
|
+
readonly [key: string]: Json;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A value inside a record: a JSON primitive, or a tag (an array whose first item says what it is):
|
|
10
|
+
* - `["u"]` undefined, `["n", "NaN" | "Infinity" | "-Infinity" | "-0"]` a number JSON cannot spell, `["-"]` an absent
|
|
11
|
+
* field, `["h"]` an array hole;
|
|
12
|
+
* - `["s", name]` an interpreter symbol;
|
|
13
|
+
* - `["i", name]` a built-in or host global, unchanged since the runtime was made;
|
|
14
|
+
* - `["a", source, index]` an AST node (a call site, an error's location);
|
|
15
|
+
* - `["x", data]` something the engine names itself (the VM's compiled code, by source and function index);
|
|
16
|
+
* - `["r", id]` another record.
|
|
17
|
+
*/
|
|
18
|
+
export type Encoded = string | number | boolean | null | ReadonlyArray<Json>;
|
|
19
|
+
/** One object of the graph. `t` says how to read the rest. */
|
|
20
|
+
export type Record = {
|
|
21
|
+
readonly t: string;
|
|
22
|
+
readonly [field: string]: Json;
|
|
23
|
+
};
|
|
24
|
+
/** A saved state can't be read, or doesn't fit this runtime. */
|
|
25
|
+
export declare class SnapshotError extends Error {
|
|
26
|
+
readonly name = "SnapshotError";
|
|
27
|
+
}
|
|
28
|
+
/** What the encoder asks of the runtime whose state it saves. */
|
|
29
|
+
export type EncodeEnv = {
|
|
30
|
+
/** The name of a built-in or host global object. */
|
|
31
|
+
readonly nameOf: (value: Obj) => string | undefined;
|
|
32
|
+
/** Whether a named object is still as the runtime made it, so its name alone restores it. */
|
|
33
|
+
readonly unchanged: (value: Obj) => boolean;
|
|
34
|
+
/** The anchors: objects the restored runtime already has, filled in place (the VM, its scheduler, ...). */
|
|
35
|
+
readonly anchorOf: (value: object) => string | undefined;
|
|
36
|
+
readonly nodeId: (node: AstNode) => readonly [source: string, index: number] | undefined;
|
|
37
|
+
/** Values with no data form are reported here; strict encoding throws on the first instead. */
|
|
38
|
+
readonly lost: Array<string>;
|
|
39
|
+
readonly strict: boolean;
|
|
40
|
+
/** More classes to save, an engine's own (the VM's frames and closures), after the built-in ones. */
|
|
41
|
+
readonly specs?: ReadonlyArray<ClassSpec> | undefined;
|
|
42
|
+
/** The data an engine names an object or symbol by, saved as `["x", data]`, instead of copying it. */
|
|
43
|
+
readonly external?: ((value: object | symbol) => Json | undefined) | undefined;
|
|
44
|
+
};
|
|
45
|
+
/** What the decoder asks of the fresh runtime it restores into. */
|
|
46
|
+
export type DecodeEnv = {
|
|
47
|
+
readonly named: (name: string) => Obj | undefined;
|
|
48
|
+
readonly anchor: (name: string) => object | undefined;
|
|
49
|
+
readonly node: (source: string, index: number) => AstNode | undefined;
|
|
50
|
+
/** An `Interruption` (it holds an Effect cause, which this module does not make). */
|
|
51
|
+
readonly interruption: () => Interruption;
|
|
52
|
+
readonly specs?: ReadonlyArray<ClassSpec> | undefined;
|
|
53
|
+
/** What `EncodeEnv.external` named. */
|
|
54
|
+
readonly external?: ((data: Json) => unknown) | undefined;
|
|
55
|
+
};
|
|
56
|
+
/** How one class saves: its own fields in order, and how a restored instance is made whole. */
|
|
57
|
+
export type ClassSpec = {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly ctor: Function;
|
|
60
|
+
/** Saved fields, in the order a constructor makes them. */
|
|
61
|
+
readonly fields: ReadonlyArray<string>;
|
|
62
|
+
/** Own fields that are not saved: caches and runtime configuration, set to `reset`'s values. */
|
|
63
|
+
readonly skip?: ReadonlyArray<string>;
|
|
64
|
+
/** Own fields with the same value on every instance. */
|
|
65
|
+
readonly constants?: Readonly<{
|
|
66
|
+
[field: string]: unknown;
|
|
67
|
+
}>;
|
|
68
|
+
/** An `Obj`: its prototype, extensibility, and properties are saved too. */
|
|
69
|
+
readonly obj?: boolean;
|
|
70
|
+
/** The restored runtime already has this object; it is filled in place. */
|
|
71
|
+
readonly anchor?: string;
|
|
72
|
+
/** Sets fields that are not saved, once the saved ones are in. */
|
|
73
|
+
readonly reset?: (value: never) => void;
|
|
74
|
+
/** The saved fields' values, when they are not the own fields as they are (a frame saves its live registers only). */
|
|
75
|
+
readonly view?: (value: never) => ReadonlyArray<unknown>;
|
|
76
|
+
};
|
|
77
|
+
/** The names of every class with a codec: a build that saves a different set cannot read this one's snapshots. */
|
|
78
|
+
export declare const codecShape: (extra?: ReadonlyArray<ClassSpec>) => string;
|
|
79
|
+
/** Encodes everything reachable from `roots`: the roots' values and the records they refer to. */
|
|
80
|
+
export declare const encode: (roots: ReadonlyArray<unknown>, env: EncodeEnv) => {
|
|
81
|
+
readonly roots: Array<Encoded>;
|
|
82
|
+
readonly records: Array<Record>;
|
|
83
|
+
};
|
|
84
|
+
/** Rebuilds the graph `encode` saved, filling anchors in place: the decoded roots. */
|
|
85
|
+
export declare const decode: (saved: {
|
|
86
|
+
readonly roots: ReadonlyArray<unknown>;
|
|
87
|
+
readonly records: ReadonlyArray<unknown>;
|
|
88
|
+
}, env: DecodeEnv) => Array<unknown>;
|