@mica-js/simulator 2.0.0 → 2.1.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 +343 -7
- package/dist/ddl.d.ts +4 -0
- package/dist/ddl.js +1 -0
- package/dist/device.d.ts +111 -0
- package/dist/device.js +0 -0
- package/dist/index.d.ts +257 -783
- package/dist/index.js +4339 -3178
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +4 -0
- package/dist/model.js +1 -0
- package/dist/rpc-D-9O3TZf.js +108 -0
- package/dist/rpc-D-9O3TZf.js.map +1 -0
- package/dist/sandbox.d.ts +75 -109
- package/dist/sandbox.js +71 -80
- package/dist/sandbox.js.map +1 -1
- package/package.json +33 -11
- package/dist/rpc-BIxQr_wd.js +0 -12
- package/dist/rpc-BIxQr_wd.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,886 +1,360 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { DeviceSymbolProvider } from '@mica-js/core/schematic';
|
|
1
|
+
import { BlockIR } from '@mica-js/device-model';
|
|
2
|
+
import { DeviceIR } from '@mica-js/device-model';
|
|
3
|
+
import { DeviceMetadata } from '@mica-js/document/schematic';
|
|
4
|
+
import { DevicePortMetadata } from '@mica-js/document/schematic';
|
|
6
5
|
import { Disposable } from '@mica-js/core/lifecycle';
|
|
7
|
-
import { EntryRef } from '@mica-js/ir';
|
|
8
6
|
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { IRJITTuning } from '@mica-js/ir';
|
|
12
|
-
import { IRModule } from '@mica-js/ir';
|
|
13
|
-
import { IRValidationOptions } from '@mica-js/ir';
|
|
14
|
-
import { PayloadType } from '@mica-js/core/canvas';
|
|
15
|
-
import { PropertyValue } from '@mica-js/core/schematic';
|
|
7
|
+
import { InputPath } from '@mica-js/device-model';
|
|
8
|
+
import { JitBlockBuilder } from '@mica-js/device-model';
|
|
16
9
|
import { RpcEndpoint } from '@mica-js/core/rpc';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { Value } from '@mica-js/ir';
|
|
10
|
+
import { RpcServiceId } from '@mica-js/core/rpc';
|
|
11
|
+
import { SchematicDocument } from '@mica-js/document/schematic';
|
|
12
|
+
import { SourceInfo } from '@mica-js/device-model';
|
|
13
|
+
import { TimePs } from '@mica-js/core';
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* { id: 'sink1', type: 'lamp-sink', description: sinkDescription() },
|
|
31
|
-
* ],
|
|
32
|
-
* connections: [
|
|
33
|
-
* { from: 'drive1.PA0', to: 'sink1.anode' },
|
|
34
|
-
* { from: 'sink1.cathode', to: 'GND' },
|
|
35
|
-
* ],
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* circuit.runBatch(1_000_000); // one engine call
|
|
39
|
-
* expect(circuit.tickCount).toBe(1_000_000n);
|
|
40
|
-
* circuit.reset();
|
|
41
|
-
* circuit.step();
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* `Circuit` owns the engine instance, the tick counter and the private
|
|
45
|
-
* step-boundary hook plumbing. RFC 0017 traffic belongs to the
|
|
46
|
-
* `DeviceSimulationHost`: it delivers topic inputs before a step and publishes
|
|
47
|
-
* the topic outputs the device hooks report afterwards. `Circuit` itself
|
|
48
|
-
* exposes no device state, pin or electrical readback.
|
|
49
|
-
*
|
|
50
|
-
* The compiled module keeps every device, net and the main loop in one
|
|
51
|
-
* `@mica-js/ir` module, so a batch is one interpreter/JIT call for the whole
|
|
52
|
-
* circuit.
|
|
53
|
-
*/
|
|
54
|
-
export declare class Circuit {
|
|
55
|
-
#private;
|
|
56
|
-
private constructor();
|
|
57
|
-
/**
|
|
58
|
-
* Compiles `input`, builds the engine instance and runs the generated
|
|
59
|
-
* `initialize` entry once.
|
|
60
|
-
*
|
|
61
|
-
* @throws {UnifiedIRCompilerError} when the circuit cannot be compiled.
|
|
62
|
-
* @throws {CircuitError} for invalid options.
|
|
63
|
-
*/
|
|
64
|
-
static create(input: CircuitCompilationInput, options?: CircuitRuntimeOptions): Promise<Circuit>;
|
|
65
|
-
/**
|
|
66
|
-
* Runs `count` ticks inside one generated loop — the throughput path.
|
|
67
|
-
*
|
|
68
|
-
* The whole batch is one engine call. The clock advances by completed ticks,
|
|
69
|
-
* including the completed prefix of a failed batch.
|
|
70
|
-
*
|
|
71
|
-
* @throws {CircuitError} with code `invalid-count` unless `count` is a u32.
|
|
72
|
-
*/
|
|
73
|
-
runBatch(count: number, dt?: number): void;
|
|
74
|
-
/**
|
|
75
|
-
* Advances exactly one tick — the debugging path.
|
|
76
|
-
*
|
|
77
|
-
* Every call is one engine entry, so prefer `runBatch` for throughput.
|
|
78
|
-
*/
|
|
79
|
-
step(dt?: number): void;
|
|
80
|
-
/**
|
|
81
|
-
* Restores every memory to its declared initial value, re-runs `initialize`
|
|
82
|
-
* and resets `tickCount` to `0n`.
|
|
83
|
-
*
|
|
84
|
-
* Device state written by earlier ticks is discarded, so the circuit behaves
|
|
85
|
-
* exactly like a freshly created one.
|
|
86
|
-
*/
|
|
87
|
-
reset(): void;
|
|
88
|
-
/** Number of ticks completed since creation or the last `reset()`. */
|
|
89
|
-
get tickCount(): bigint;
|
|
90
|
-
/** Virtual tick time completed since creation or the last `reset()`. */
|
|
91
|
-
get virtualTime(): number;
|
|
92
|
-
/** Whether `dispose()` already ran. */
|
|
93
|
-
get disposed(): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Releases the runtime. Idempotent; every later call throws a `CircuitError`
|
|
96
|
-
* with code `disposed`.
|
|
97
|
-
*/
|
|
98
|
-
dispose(): void;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Compiler input: devices plus the connections between their pins. */
|
|
102
|
-
export declare interface CircuitCompilationInput {
|
|
103
|
-
readonly devices: readonly DeviceConfig[];
|
|
104
|
-
readonly connections: readonly Connection[];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Options for the compiler. */
|
|
108
|
-
export declare interface CircuitCompilationOptions {
|
|
109
|
-
/** Explicit GND-referenced voltage sources; GND itself is always 0 V. */
|
|
110
|
-
readonly sources?: Readonly<Record<string, {
|
|
111
|
-
readonly voltage: number;
|
|
112
|
-
}>>;
|
|
113
|
-
readonly interpretation?: 'two-state' | 'retain-in-band';
|
|
114
|
-
/** Reproducible mica-floating-v2 input seed; defaults to 0. */
|
|
115
|
-
readonly floatingSeed?: number;
|
|
116
|
-
/** Runs `validateIR` over the generated module. Defaults to `true`. */
|
|
117
|
-
readonly validate?: boolean;
|
|
118
|
-
/** Overrides for the generated entry-point names. */
|
|
119
|
-
readonly entryPointNames?: {
|
|
120
|
-
readonly tick?: string;
|
|
121
|
-
readonly initialize?: string;
|
|
122
|
-
readonly batch?: string;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Electrical-solve options forwarded to `compileCircuit`. */
|
|
127
|
-
export declare interface CircuitElectricalOptions {
|
|
128
|
-
readonly sources?: CircuitCompilationOptions['sources'];
|
|
129
|
-
readonly interpretation?: CircuitCompilationOptions['interpretation'];
|
|
130
|
-
readonly floatingSeed?: CircuitCompilationOptions['floatingSeed'];
|
|
15
|
+
export declare interface Board extends Disposable {
|
|
16
|
+
readonly time: number;
|
|
17
|
+
readonly status: BoardStatus;
|
|
18
|
+
readonly topics: TopicBridge;
|
|
19
|
+
readonly onDidError: Event_2<RuntimeDiagnostic>;
|
|
20
|
+
readonly onDidDiagnostic: Event_2<RuntimeDiagnostic>;
|
|
21
|
+
runUntil(target: number): void;
|
|
131
22
|
}
|
|
132
23
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
* owns the engine instance, the tick counter and the private step-boundary hook
|
|
138
|
-
* plumbing. Everything here is transport-neutral; no type mentions the device
|
|
139
|
-
* host or the schematic editor.
|
|
140
|
-
*/
|
|
141
|
-
/** Execution engine a `Circuit` runs on. */
|
|
142
|
-
export declare type CircuitEngine = 'jit' | 'reference';
|
|
24
|
+
export declare interface BoardDescription {
|
|
25
|
+
readonly instances: readonly InstanceDescription[];
|
|
26
|
+
readonly nets: readonly NetDescription[];
|
|
27
|
+
}
|
|
143
28
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export declare class CircuitError extends Error {
|
|
151
|
-
readonly name = "CircuitError";
|
|
152
|
-
readonly code: CircuitErrorCode;
|
|
153
|
-
readonly deviceId: string | undefined;
|
|
154
|
-
readonly stateName: string | undefined;
|
|
155
|
-
constructor(code: CircuitErrorCode, message: string, options?: CircuitErrorOptions);
|
|
29
|
+
export declare interface BoardOptions {
|
|
30
|
+
/** uint32,省略为 0;实例派生算法见 execution/random。 */
|
|
31
|
+
readonly seed?: number;
|
|
32
|
+
readonly execution?: 'throughput' | 'precise';
|
|
33
|
+
/** CPU execution quantum in integer picoseconds, default 10_000_000. */
|
|
34
|
+
readonly cpuQuantum?: number;
|
|
156
35
|
}
|
|
157
36
|
|
|
158
|
-
|
|
159
|
-
export declare type CircuitErrorCode = 'invalid-options' | 'invalid-count' | 'unsupported-operation' | 'state-not-found' | 'invalid-state-value' | 'unresolved-device' | 'disposed';
|
|
37
|
+
export declare type BoardStatus = 'ready' | 'faulted' | 'disposed';
|
|
160
38
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
readonly
|
|
164
|
-
readonly cause?: unknown;
|
|
39
|
+
/** 句柄随所属板或本次翻译失效;内容稳定期与允许读取阶段由 memory 合同规定。 */
|
|
40
|
+
export declare interface BorrowedBytes extends ByteReader {
|
|
41
|
+
readonly [borrowedTag]: true;
|
|
165
42
|
}
|
|
166
43
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
readonly engine?: CircuitEngine;
|
|
176
|
-
/** JIT tuning. The runtime always supplies the module's own validation grant. */
|
|
177
|
-
readonly jit?: IRJITTuning;
|
|
178
|
-
/**
|
|
179
|
-
* Run `validateIR` over the generated module during compilation.
|
|
180
|
-
* Defaults to `true`; pass `false` only for measured warm paths.
|
|
181
|
-
*/
|
|
182
|
-
readonly validateIR?: boolean;
|
|
183
|
-
/** Electrical-solve options. */
|
|
184
|
-
readonly electrical?: CircuitElectricalOptions;
|
|
185
|
-
/** Instance id reported to the engine. Defaults to `'unified-circuit'`. */
|
|
186
|
-
readonly instanceId?: string;
|
|
44
|
+
declare const borrowedTag: unique symbol;
|
|
45
|
+
|
|
46
|
+
declare interface ByteReader extends Iterable<number> {
|
|
47
|
+
readonly length: number;
|
|
48
|
+
readonly byteLength: number;
|
|
49
|
+
readonly [index: number]: number | undefined;
|
|
50
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
51
|
+
slice(start?: number, end?: number): Uint8Array;
|
|
187
52
|
}
|
|
188
53
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
* Device models are caller-supplied: every entry of `devices` carries the pins,
|
|
193
|
-
* states and behaviors (or `kernel`) its type needs.
|
|
194
|
-
*
|
|
195
|
-
* ```ts
|
|
196
|
-
* const circuit = compileCircuit({
|
|
197
|
-
* devices: [
|
|
198
|
-
* { id: 'drive1', type: 'push-pull-driver', description: driverDescription() },
|
|
199
|
-
* { id: 'sink1', type: 'lamp-sink', description: sinkDescription() },
|
|
200
|
-
* ],
|
|
201
|
-
* connections: [
|
|
202
|
-
* { from: 'drive1.channel0', to: 'sink1.anode' },
|
|
203
|
-
* { from: 'sink1.cathode', to: 'GND' },
|
|
204
|
-
* ],
|
|
205
|
-
* });
|
|
206
|
-
*
|
|
207
|
-
* const jit = createIRJIT(circuit.module, { validation: circuit.validation });
|
|
208
|
-
* jit.execute(circuit.entryPoints.refs.initialize, []);
|
|
209
|
-
* jit.execute(circuit.entryPoints.refs.tick, []); // drive1 + nets + sink1
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* The pipeline is: validate the input, allocate the global pin and state
|
|
213
|
-
* spaces, analyse the electrical topology, generate one function per device
|
|
214
|
-
* phase, generate the resistive network solver and main loop, then validate the
|
|
215
|
-
* resulting module with `validateIR`.
|
|
216
|
-
*
|
|
217
|
-
* @throws {UnifiedIRCompilerError} for malformed input, duplicate ids, unknown
|
|
218
|
-
* pins, electrical conflicts, or when the generated module fails validation.
|
|
219
|
-
*/
|
|
220
|
-
export declare function compileCircuit(input: CircuitCompilationInput, options?: CircuitCompilationOptions): CompiledCircuit;
|
|
221
|
-
|
|
222
|
-
/** The compiled circuit: one module for every device, net and the main loop. */
|
|
223
|
-
export declare interface CompiledCircuit {
|
|
224
|
-
readonly module: IRModule;
|
|
225
|
-
readonly entryPoints: CompiledEntryPoints;
|
|
226
|
-
/** Completed ticks in the most recent step/batch, including before a fault. */
|
|
227
|
-
readonly progress: StateRef<'u32'>;
|
|
228
|
-
/** `'mcu1.PA0'` -> global pin id. */
|
|
229
|
-
readonly pinMap: ReadonlyMap<string, number>;
|
|
230
|
-
readonly deviceMap: ReadonlyMap<string, DeviceMetadata>;
|
|
231
|
-
readonly pins: GlobalPinMap;
|
|
232
|
-
readonly states: GlobalStateMap;
|
|
233
|
-
/** Validation grants covering every instruction and memory of the module. */
|
|
234
|
-
readonly validation: IRValidationOptions;
|
|
235
|
-
/** Device ids in stable declaration order. */
|
|
236
|
-
readonly executionOrder: readonly string[];
|
|
237
|
-
/** Every generated function name, in definition order. */
|
|
238
|
-
readonly functions: readonly string[];
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** Generated entry points, both by name and as executable refs. */
|
|
242
|
-
declare interface CompiledEntryPoints {
|
|
243
|
-
readonly tick: string;
|
|
244
|
-
readonly initialize: string;
|
|
245
|
-
readonly batch: string;
|
|
246
|
-
readonly refs: {
|
|
247
|
-
readonly tick: FunctionRef<readonly [], readonly []>;
|
|
248
|
-
readonly initialize: FunctionRef<readonly [], readonly []>;
|
|
249
|
-
readonly batch: FunctionRef<readonly ['u32'], readonly []>;
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/** One pin-to-pin (or pin-to-rail) connection. */
|
|
254
|
-
export declare interface Connection {
|
|
255
|
-
/** `'mcu1.PA0'` or a rail name such as `'GND'`. */
|
|
256
|
-
readonly from: string;
|
|
257
|
-
readonly to: string;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export declare interface ContactDeclaration extends ResistorDeclaration {
|
|
261
|
-
readonly initial: 'open' | 'closed';
|
|
54
|
+
export declare interface ChannelMessage<T> {
|
|
55
|
+
readonly time: number;
|
|
56
|
+
readonly value: T;
|
|
262
57
|
}
|
|
263
58
|
|
|
264
|
-
|
|
265
|
-
* Compiles a schematic sheet into a circuit.
|
|
266
|
-
*
|
|
267
|
-
* Nets come from `deriveSchematicTopology`, so wires, junctions, labels and
|
|
268
|
-
* power symbols keep their usual meaning: a net that names a rail connects
|
|
269
|
-
* every member to that rail, and any other net joins its pins pairwise (the
|
|
270
|
-
* compiler merges transitively).
|
|
271
|
-
*
|
|
272
|
-
* ```ts
|
|
273
|
-
* const circuit = await createCircuitFromSchematic(schematic, {
|
|
274
|
-
* devices: symbolProvider,
|
|
275
|
-
* resolveDevice: (reference) => bindings.get(reference.deviceId),
|
|
276
|
-
* });
|
|
277
|
-
* ```
|
|
278
|
-
*
|
|
279
|
-
* @throws {CircuitError} with code `unresolved-device` when a component symbol
|
|
280
|
-
* has no binding; `SchematicError` for malformed sheets.
|
|
281
|
-
*/
|
|
282
|
-
export declare function createCircuitFromSchematic(schematic: SchematicDocument, options: SchematicCircuitOptions): Promise<Circuit>;
|
|
59
|
+
export declare function createBoard(library: DeviceLibrary, description: BoardDescription, options?: BoardOptions): Board;
|
|
283
60
|
|
|
284
|
-
|
|
285
|
-
* Builds the validation grants a module needs to run on the reference engine or
|
|
286
|
-
* the JIT: every instruction the model uses, authorized once, plus a grant for
|
|
287
|
-
* each declared memory.
|
|
288
|
-
*
|
|
289
|
-
* `@mica-js/ir` deliberately keeps its core instruction list internal, so the
|
|
290
|
-
* names are collected from the generated bodies instead of being restated here.
|
|
291
|
-
*
|
|
292
|
-
* @param module - Generated module whose bodies and memories are granted.
|
|
293
|
-
* @param updateResources - Read-only byte regions that opt into the host-only
|
|
294
|
-
* versioned update path (for example MCU firmware patching).
|
|
295
|
-
*/
|
|
296
|
-
export declare function createModuleValidation(module: IRModule, updateResources?: readonly BytesRef[]): IRValidationOptions;
|
|
61
|
+
export declare function createDeviceLibrary(entries: readonly DeviceLibraryEntry[]): DeviceLibrary;
|
|
297
62
|
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
*
|
|
301
|
-
* {@link createCircuitFromSchematic} returns only the circuit; the host needs
|
|
302
|
-
* the symbol-to-device mapping as well.
|
|
303
|
-
*/
|
|
304
|
-
export declare function createSchematicCircuit(schematic: SchematicDocument, options: SchematicCircuitOptions): Promise<SchematicCircuitResult>;
|
|
63
|
+
/** Runs self-contained SDK devices on an atomic, replaceable Board. */
|
|
64
|
+
export declare function createSimulationRuntime(options?: ISimulationRuntimeOptions): ISimulationRuntime;
|
|
305
65
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
*
|
|
309
|
-
* The host owns the circuit: `loadSchematic` reads, parses and compiles it, `tick` advances one
|
|
310
|
-
* circuit step and publishes the output topics that changed, and `deliver` queues widget payloads
|
|
311
|
-
* for the next step. Device models and their endpoints come from `resolveDevice`, so the host stays
|
|
312
|
-
* generic. Nothing here touches the DOM, so the sandbox guest and a Node test use the same
|
|
313
|
-
* implementation.
|
|
314
|
-
*/
|
|
315
|
-
export declare function createSchematicDeviceSimulationHost(options: SchematicDeviceSimulationHostOptions): DeviceSimulationHost;
|
|
316
|
-
|
|
317
|
-
/** Global pin addresses one device may own; enough for the largest packages. */
|
|
318
|
-
export declare const DEVICE_PIN_STRIDE = 512;
|
|
319
|
-
|
|
320
|
-
/** Build surface handed to one device behavior. */
|
|
321
|
-
export declare interface DeviceBehaviorApi {
|
|
322
|
-
readonly deviceId: string;
|
|
323
|
-
readonly builder: FunctionBuilder<readonly []>;
|
|
324
|
-
/**
|
|
325
|
-
* Module the phase is generated into. Complex devices use it to declare
|
|
326
|
-
* their own typed arrays (`module.array`, `module.bytes`) and providers;
|
|
327
|
-
* simple devices never need to touch it.
|
|
328
|
-
*/
|
|
329
|
-
readonly module: IRModule;
|
|
330
|
-
/** Instance configuration from {@link DeviceConfig.config}. */
|
|
331
|
-
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
332
|
-
/** Every declared pin of the device, in declaration order. */
|
|
333
|
-
readonly pins: readonly DevicePinHandle[];
|
|
334
|
-
/** Pins initialized with physical drive capability. */
|
|
335
|
-
readonly outputs: readonly DevicePinHandle[];
|
|
336
|
-
pin(name: string): DevicePinHandle;
|
|
337
|
-
resistor(name: string): DeviceResistorHandle;
|
|
338
|
-
writeDigitalGroup(names: readonly string[], levels: readonly Value<'bool'>[]): void;
|
|
339
|
-
applyResistors(names: readonly string[], ohms: readonly Value<'f64'>[]): void;
|
|
340
|
-
applyConnections(names: readonly string[], closed: readonly Value<'bool'>[]): void;
|
|
341
|
-
state<T extends ScalarType = ScalarType>(name: string): DeviceStateHandle<T>;
|
|
66
|
+
export declare interface DeviceAdapter<Batch extends DeviceBatch = DeviceBatch> extends Disposable {
|
|
67
|
+
sync(batch: Batch): void;
|
|
342
68
|
}
|
|
343
69
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
*/
|
|
349
|
-
export declare interface DeviceBehaviors {
|
|
350
|
-
readonly initialize?: (api: DeviceBehaviorApi) => void;
|
|
351
|
-
readonly tick?: (api: DeviceBehaviorApi) => void;
|
|
352
|
-
readonly update?: (api: DeviceBehaviorApi) => void;
|
|
70
|
+
export declare interface DeviceBatch<Outputs extends object = object> {
|
|
71
|
+
readonly from: number;
|
|
72
|
+
readonly to: number;
|
|
73
|
+
readonly outputs: Readonly<Outputs>;
|
|
353
74
|
}
|
|
354
75
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
readonly
|
|
76
|
+
/** 具体字段由生成模块或工厂泛型注解投影;这里不重复声明资源名称。 */
|
|
77
|
+
export declare interface DeviceContext<Props extends object = object, Inputs extends object = object, Memory extends object = object> extends JitHost {
|
|
78
|
+
readonly props: Readonly<Props>;
|
|
79
|
+
readonly inputs: Readonly<Inputs>;
|
|
80
|
+
readonly memory: Readonly<Memory>;
|
|
81
|
+
readonly topics: TopicBridge;
|
|
82
|
+
reportError(error: unknown): void;
|
|
358
83
|
}
|
|
359
84
|
|
|
360
|
-
|
|
361
|
-
export declare interface DeviceConfig {
|
|
362
|
-
/** Circuit-unique identity; prefix of every generated function name. */
|
|
363
|
-
readonly id: string;
|
|
364
|
-
/** Device type, e.g. `'push-pull-driver'`; free-form label of the device model. */
|
|
365
|
-
readonly type: string;
|
|
366
|
-
readonly description: DeviceDescription;
|
|
367
|
-
/** Persistent instance values resolved against the JSON property declarations. */
|
|
368
|
-
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
369
|
-
/** Instance configuration; reserved for device kernels that take parameters. */
|
|
370
|
-
readonly config?: Readonly<Record<string, unknown>>;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/** IR-level device description consumed by the compiler. */
|
|
374
|
-
export declare interface DeviceDescription extends DeviceBridgeHooks {
|
|
375
|
-
readonly name?: string;
|
|
376
|
-
readonly pins: DevicePinMap;
|
|
377
|
-
readonly properties?: Readonly<Record<string, unknown>>;
|
|
378
|
-
readonly resistors?: Readonly<Record<string, ResistorDeclaration>>;
|
|
379
|
-
readonly connections?: Readonly<Record<string, ContactDeclaration>>;
|
|
380
|
-
/** Paired synchronous JS factory, invoked once per instance before IR generation. */
|
|
381
|
-
readonly factory: (context: ElectricalFactoryContext) => DeviceImplementation | void;
|
|
382
|
-
readonly states?: Readonly<Record<string, DeviceStateDescription>>;
|
|
383
|
-
readonly behaviors?: DeviceBehaviors;
|
|
384
|
-
/**
|
|
385
|
-
* Complex-kernel hook. Runs once per module before phase generation so the
|
|
386
|
-
* kernel may declare typed arrays, byte memories and providers, then return
|
|
387
|
-
* the behaviour hooks the compiler should call inside each phase.
|
|
388
|
-
*/
|
|
389
|
-
readonly kernel?: DeviceKernelFactory;
|
|
390
|
-
/**
|
|
391
|
-
* Read-only byte regions the kernel wants host updates for. The compiler
|
|
392
|
-
* grants `update` access on top of the normal `read` grant so kernels can
|
|
393
|
-
* expose firmware patching without allowing guest stores.
|
|
394
|
-
*/
|
|
395
|
-
readonly updateResources?: readonly BytesRef[];
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export declare interface DeviceElectricalInitialization {
|
|
399
|
-
initializeResistor(id: string, initial: ResistorInitialState): void;
|
|
400
|
-
initializePin(id: string, initial: PinElectricalDescription): void;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/** Per-instance construction and boundary hooks returned by the paired factory. */
|
|
404
|
-
export declare interface DeviceImplementation extends DeviceBehaviors, DeviceBridgeHooks {
|
|
405
|
-
readonly kernel?: DeviceKernelFactory;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
export declare interface DeviceInput {
|
|
409
|
-
readonly port: string;
|
|
410
|
-
readonly payload: unknown;
|
|
411
|
-
}
|
|
85
|
+
export declare type DeviceFactory<Context extends DeviceContext = DeviceContext, Batch extends DeviceBatch = DeviceBatch> = (context: Context) => DeviceAdapter<Batch>;
|
|
412
86
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
writeState(name: string, value: unknown): void;
|
|
417
|
-
call(entry: EntryRef, args: readonly RuntimeScalar[]): void;
|
|
87
|
+
/** 已校验并捕获模型和登记关系的可复用库;没有运行中资源。 */
|
|
88
|
+
export declare interface DeviceLibrary {
|
|
89
|
+
readonly [libraryTag]: true;
|
|
418
90
|
}
|
|
419
91
|
|
|
420
|
-
/**
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
export declare interface DeviceKernelContext {
|
|
426
|
-
readonly deviceId: string;
|
|
427
|
-
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
428
|
-
readonly module: IRModule;
|
|
429
|
-
bind(builder: FunctionBuilder<readonly []>): DeviceBehaviorApi;
|
|
430
|
-
readonly pins: readonly DeviceKernelPin[];
|
|
92
|
+
/** 异构登记在库边界擦除器件泛型;工厂使用生成类型或精确的 SDK 泛型注解。 */
|
|
93
|
+
export declare interface DeviceLibraryEntry {
|
|
94
|
+
readonly id: string;
|
|
95
|
+
readonly model: DeviceIR;
|
|
96
|
+
readonly create: DeviceFactory<any, any>;
|
|
431
97
|
}
|
|
432
98
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
* providers is only legal here (never inside a function body).
|
|
437
|
-
*
|
|
438
|
-
* Returning {@link DeviceKernelRuntime} lets the kernel own its phase
|
|
439
|
-
* functions directly; returning {@link DeviceBehaviors} asks the compiler to
|
|
440
|
-
* generate `<id>_initialize` / `<id>_tick` / `<id>_update` wrappers.
|
|
441
|
-
*/
|
|
442
|
-
export declare type DeviceKernelFactory = (context: DeviceKernelContext) => DeviceBehaviors | DeviceKernelRuntime;
|
|
99
|
+
export { Disposable }
|
|
100
|
+
|
|
101
|
+
export { Event_2 as Event }
|
|
443
102
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
readonly name: string;
|
|
447
|
-
readonly globalPinId: number;
|
|
103
|
+
export declare interface InputChannel<T> {
|
|
104
|
+
send(value: T): void;
|
|
448
105
|
}
|
|
449
106
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
* The compiler then uses these functions as the device's loop entries, with
|
|
453
|
-
* no wrapper phase around them.
|
|
454
|
-
*/
|
|
455
|
-
export declare interface DeviceKernelRuntime {
|
|
456
|
-
readonly initialize?: FunctionRef<readonly [], readonly []>;
|
|
457
|
-
readonly tick?: FunctionRef<readonly [], readonly []>;
|
|
458
|
-
readonly update?: FunctionRef<readonly [], readonly []>;
|
|
107
|
+
export declare interface InputNotification {
|
|
108
|
+
notify(): void;
|
|
459
109
|
}
|
|
460
110
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
readonly deviceId: string;
|
|
464
|
-
readonly entries?: readonly EntryRef[];
|
|
111
|
+
export declare interface InstanceDescription {
|
|
112
|
+
readonly id: string;
|
|
465
113
|
readonly type: string;
|
|
466
|
-
|
|
467
|
-
readonly
|
|
468
|
-
/** First slot ordinal of the device in the global state space. */
|
|
469
|
-
readonly stateOffset: number;
|
|
470
|
-
readonly pins: ReadonlyMap<string, number>;
|
|
471
|
-
readonly states: ReadonlyMap<string, DeviceStateSlot>;
|
|
472
|
-
/** Every IR function generated for this device. */
|
|
473
|
-
readonly functions: readonly string[];
|
|
474
|
-
readonly initialize: string | undefined;
|
|
475
|
-
readonly tick: string | undefined;
|
|
476
|
-
readonly update: string | undefined;
|
|
114
|
+
readonly props?: Readonly<Record<string, PropertyInput>>;
|
|
115
|
+
readonly randomState?: RandomState;
|
|
477
116
|
}
|
|
478
117
|
|
|
479
|
-
export declare interface
|
|
480
|
-
|
|
481
|
-
|
|
118
|
+
export declare interface InstructionHook {
|
|
119
|
+
readonly when: string;
|
|
120
|
+
readonly call: string;
|
|
482
121
|
}
|
|
483
122
|
|
|
484
|
-
/**
|
|
485
|
-
declare interface
|
|
486
|
-
readonly
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
readonly
|
|
490
|
-
|
|
123
|
+
/** A prepared schematic and its separately resolved resource bytes. */
|
|
124
|
+
export declare interface IPreparedSimulation {
|
|
125
|
+
readonly schematic: SchematicDocument;
|
|
126
|
+
readonly devices: readonly IPreparedSimulationDevice[];
|
|
127
|
+
/** Fixed board voltages by exact schematic net name; ignored for empty sheets. Ground stays zero. */
|
|
128
|
+
readonly voltageReferences?: Readonly<Record<string, number>>;
|
|
129
|
+
/** assets[symbolId][src]; required for every effective image/binary resource reference. */
|
|
130
|
+
readonly assets?: Readonly<Record<string, Readonly<Record<string, Uint8Array>>>>;
|
|
491
131
|
}
|
|
492
132
|
|
|
493
|
-
/**
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
* a tick costs one interpreter/JIT call for the whole circuit.
|
|
500
|
-
*
|
|
501
|
-
* The shared constants (`UNIFIED_PIN_CAPACITY`, `DEVICE_PIN_STRIDE`, `PIN_MODE`)
|
|
502
|
-
* live in `../pin-space` and are reused here. The compiler ships no device
|
|
503
|
-
* models: every description is supplied by the caller.
|
|
504
|
-
*/
|
|
505
|
-
/** One pin declared by the paired electrical device definition. */
|
|
506
|
-
export declare interface DevicePinDescription {
|
|
507
|
-
readonly kind: 'signal' | 'power' | 'gnd';
|
|
508
|
-
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/** Pin operations a behavior may use; each call inlines into global memory. */
|
|
512
|
-
declare interface DevicePinHandle {
|
|
513
|
-
readonly name: string;
|
|
514
|
-
readonly globalId: number;
|
|
515
|
-
/** Selects the physical output configuration. */
|
|
516
|
-
configure(mode: number): void;
|
|
517
|
-
setOutputEnabled(enabled: Value<'bool'>): void;
|
|
518
|
-
setPull(pull: 'none' | 'up' | 'down'): void;
|
|
519
|
-
writeVoltage(voltage: Value<'f64'>): void;
|
|
520
|
-
/** Writes digital drive intent through the finite output impedance. */
|
|
521
|
-
writeDigital(level: Value<'bool'>): void;
|
|
522
|
-
/** Samples the solved voltage with the explicitly declared input thresholds. */
|
|
523
|
-
sampleDigital(): Value<'bool'>;
|
|
524
|
-
sampleVoltage(): Value<'f64'>;
|
|
525
|
-
/** Reads this pin's digital drive intent. */
|
|
526
|
-
readDrivenDigital(): Value<'bool'>;
|
|
133
|
+
/** A current SDK device: JSON metadata plus self-contained ESM with named model/create exports. */
|
|
134
|
+
export declare interface IPreparedSimulationDevice {
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly definition: DeviceMetadata;
|
|
137
|
+
/** Imported only by the runtime guest, never by the editor that prepares this DTO. */
|
|
138
|
+
readonly code: string;
|
|
527
139
|
}
|
|
528
140
|
|
|
529
|
-
|
|
530
|
-
* Declared pins of one device. A `Map` keeps duplicate names impossible and an
|
|
531
|
-
* object keeps authored descriptions terse; both preserve declaration order.
|
|
532
|
-
*/
|
|
533
|
-
declare type DevicePinMap = ReadonlyMap<string, DevicePinDescription> | Readonly<Record<string, DevicePinDescription>>;
|
|
141
|
+
export declare type ISimulationDeviceTopicDefinition = DevicePortMetadata;
|
|
534
142
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
|
|
143
|
+
/** Serializable projection of a board diagnostic or invalid device topic publication. */
|
|
144
|
+
export declare interface ISimulationDiagnostic {
|
|
145
|
+
readonly code: SimulationDiagnosticCode;
|
|
146
|
+
/** Empty only for a board-wide diagnostic with no associated instance. */
|
|
147
|
+
readonly symbol: string;
|
|
148
|
+
readonly port?: string;
|
|
149
|
+
readonly message: string;
|
|
150
|
+
readonly simTime: TimePs;
|
|
151
|
+
readonly runtimeCode?: RuntimeDiagnosticCode;
|
|
152
|
+
readonly phase?: RuntimePhase;
|
|
540
153
|
}
|
|
541
154
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
readonly executed: number;
|
|
548
|
-
/** Isolated device boundary-hook failures; absent when the step has none. */
|
|
549
|
-
readonly diagnostics?: readonly {
|
|
550
|
-
readonly code: 'device/input-failed' | 'device/output-failed';
|
|
551
|
-
readonly deviceId: string;
|
|
552
|
-
readonly message: string;
|
|
553
|
-
}[];
|
|
155
|
+
export declare interface ISimulationMessage {
|
|
156
|
+
readonly target: ISimulationMessageTarget;
|
|
157
|
+
readonly payload: unknown;
|
|
158
|
+
/** End of the tick that delivered this publication, in integer picoseconds. */
|
|
159
|
+
readonly simTime: TimePs;
|
|
554
160
|
}
|
|
555
161
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Reads and mounts the schematic behind `uri`; `undefined` clears the runtime.
|
|
567
|
-
*
|
|
568
|
-
* The implementation reads the bytes through its own `fs` and resolves the `image` / `binary`
|
|
569
|
-
* properties of every symbol against that schematic URI.
|
|
570
|
-
*/
|
|
571
|
-
loadSchematic(uri: string | undefined): Promise<void>;
|
|
572
|
-
/** Resets the loaded runtime to its initial state without unloading the schematic. */
|
|
162
|
+
export declare interface ISimulationMessageTarget {
|
|
163
|
+
readonly symbol: string;
|
|
164
|
+
readonly port: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Owns a Board; failed load/reset leaves the previous board and queued inputs intact. */
|
|
168
|
+
export declare interface ISimulationRuntime {
|
|
169
|
+
load(input: IPreparedSimulation): Promise<void>;
|
|
170
|
+
/** Recreates the captured board synchronously without re-importing modules. */
|
|
573
171
|
reset(): Promise<void>;
|
|
574
|
-
/** Advances
|
|
575
|
-
tick(dt:
|
|
576
|
-
/**
|
|
577
|
-
deliver(
|
|
578
|
-
|
|
579
|
-
readonly
|
|
580
|
-
/** Endpoints of the running devices, in schematic order. */
|
|
581
|
-
getTopics(): Promise<readonly DeviceTopic[]>;
|
|
582
|
-
/** Current simulation time, in picoseconds. */
|
|
583
|
-
getSimTime(): Promise<number>;
|
|
584
|
-
/** Schematic the runtime was built from. */
|
|
585
|
-
getSchematic(): Promise<SchematicDocument | undefined>;
|
|
586
|
-
/** Releases the runtime. */
|
|
172
|
+
/** Advances by a positive integer number of picoseconds, up to MAX_TIME_PS. */
|
|
173
|
+
tick(dt: TimePs): Promise<ISimulationTickReport>;
|
|
174
|
+
/** Snapshots a declared input; the next tick delivers it before Board.runUntil. */
|
|
175
|
+
deliver(message: ISimulationMessage): Promise<void>;
|
|
176
|
+
readonly onDidPublish: Event_2<ISimulationMessage>;
|
|
177
|
+
readonly onDidDiagnostic: Event_2<ISimulationDiagnostic>;
|
|
587
178
|
dispose(): Promise<void>;
|
|
588
179
|
}
|
|
589
180
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
181
|
+
export declare interface ISimulationRuntimeErrorOptions {
|
|
182
|
+
/** Device the failure belongs to, as the prepared simulation names it. */
|
|
183
|
+
readonly deviceId?: string;
|
|
184
|
+
readonly cause?: unknown;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Running runtime guest: where the typed service lives and which ports it owns. */
|
|
188
|
+
export declare interface ISimulationRuntimeGuest {
|
|
596
189
|
readonly rpc: RpcEndpoint;
|
|
597
|
-
/** Extra startup ports, in the order the worker received them. */
|
|
598
190
|
readonly ports: readonly MessagePort[];
|
|
599
|
-
|
|
191
|
+
readonly runtime: ISimulationRuntime;
|
|
600
192
|
dispose(): Promise<void>;
|
|
601
193
|
}
|
|
602
194
|
|
|
603
|
-
/**
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
* package that owns devices bundles its own worker script and supplies these.
|
|
608
|
-
*/
|
|
609
|
-
export declare interface DeviceSimulationHostGuestOptions {
|
|
610
|
-
/** Fixed electrical configuration supplied by the owning worker module. */
|
|
611
|
-
readonly electrical?: CircuitElectricalOptions;
|
|
612
|
-
/** Symbol geometry of the schematics this guest loads, or a factory called per load. */
|
|
613
|
-
readonly devices?: DeviceSymbolProvider | (() => DeviceSymbolProvider);
|
|
614
|
-
/** Resolves a schematic device reference; when omitted every reference stays unresolved. */
|
|
615
|
-
readonly resolveDevice?: (reference: DeviceReference) => SchematicDeviceBinding | undefined;
|
|
616
|
-
/**
|
|
617
|
-
* Awaited before the first schematic load, so a device library can be read through the host file
|
|
618
|
-
* system before anything compiles. Runs at most once.
|
|
619
|
-
*/
|
|
620
|
-
readonly prepare?: () => Promise<void>;
|
|
621
|
-
/**
|
|
622
|
-
* Extra ports the worker received in the first ordinary message. The RPC port comes first, so these are
|
|
623
|
-
* `event.ports` from index 1 onward, in the order the caller transferred them. The first one is
|
|
624
|
-
* the direct topic channel (RFC 0018): the widget guest holds the other end and talks to this
|
|
625
|
-
* guest without the host relaying.
|
|
626
|
-
*/
|
|
195
|
+
/** Startup options of the in-process runtime guest; none of them travel over RPC. */
|
|
196
|
+
export declare interface ISimulationRuntimeGuestOptions {
|
|
197
|
+
readonly importer?: SimulationModuleImporter;
|
|
198
|
+
/** Extra ports the worker received; the first one is the direct topic channel. */
|
|
627
199
|
readonly ports?: readonly MessagePort[];
|
|
628
200
|
}
|
|
629
201
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
readonly
|
|
633
|
-
readonly initial: boolean | number;
|
|
202
|
+
export declare interface ISimulationRuntimeOptions {
|
|
203
|
+
/** Defaults to a blob-URL dynamic import in the runtime worker. */
|
|
204
|
+
readonly importer?: SimulationModuleImporter;
|
|
634
205
|
}
|
|
635
206
|
|
|
636
|
-
/**
|
|
637
|
-
declare interface
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
207
|
+
/** Methods the runtime guest exposes over the primary sandbox RPC channel. */
|
|
208
|
+
export declare interface ISimulationRuntimeRpc {
|
|
209
|
+
load(input: IPreparedSimulation): Promise<void>;
|
|
210
|
+
reset(): Promise<void>;
|
|
211
|
+
tick(dt: TimePs): Promise<ISimulationTickReport>;
|
|
212
|
+
deliver(message: ISimulationMessage): Promise<void>;
|
|
213
|
+
onDidPublish(listener: (message: ISimulationMessage) => void): () => void;
|
|
214
|
+
onDidDiagnostic(listener: (diagnostic: ISimulationDiagnostic) => void): () => void;
|
|
215
|
+
dispose(): Promise<void>;
|
|
644
216
|
}
|
|
645
217
|
|
|
646
|
-
/**
|
|
647
|
-
declare interface
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
readonly type: ScalarType;
|
|
651
|
-
/** Generated array that holds the slot. */
|
|
652
|
-
readonly array: ArrayRef;
|
|
653
|
-
/** Index inside {@link array}. */
|
|
654
|
-
readonly index: number;
|
|
655
|
-
/** Ordinal in the whole state space, across scalar types. */
|
|
656
|
-
readonly slot: number;
|
|
218
|
+
/** The data plane the direct topic port exposes: deliveries in, publishes out. */
|
|
219
|
+
export declare interface ISimulationRuntimeTopicRpc {
|
|
220
|
+
deliver(message: ISimulationMessage): Promise<void>;
|
|
221
|
+
onDidPublish(listener: (message: ISimulationMessage) => void): () => void;
|
|
657
222
|
}
|
|
658
223
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
readonly designator?: string;
|
|
664
|
-
readonly port: string;
|
|
665
|
-
readonly direction: 'input' | 'output';
|
|
666
|
-
readonly type: PayloadType;
|
|
667
|
-
readonly title?: string;
|
|
224
|
+
export declare interface ISimulationTickReport {
|
|
225
|
+
readonly simTime: TimePs;
|
|
226
|
+
/** One successful Board.runUntil call, or zero when no board is loaded. */
|
|
227
|
+
readonly executed: number;
|
|
668
228
|
}
|
|
669
229
|
|
|
670
|
-
export
|
|
230
|
+
export declare interface JitHost {
|
|
231
|
+
attachJit(options: JitOptions): Disposable;
|
|
232
|
+
loadBytes(memory: string, bytes: Uint8Array, offset?: number): void;
|
|
233
|
+
}
|
|
671
234
|
|
|
672
|
-
export declare
|
|
673
|
-
readonly
|
|
674
|
-
readonly
|
|
675
|
-
|
|
235
|
+
export declare interface JitOptions {
|
|
236
|
+
readonly entry: string;
|
|
237
|
+
readonly code: string;
|
|
238
|
+
readonly pc: string;
|
|
239
|
+
readonly beforeInstruction?: InstructionHook;
|
|
240
|
+
readonly polling?: readonly {
|
|
241
|
+
readonly pc: number;
|
|
242
|
+
readonly predicate: string;
|
|
243
|
+
}[];
|
|
244
|
+
readonly translate: JitTranslate;
|
|
676
245
|
}
|
|
677
246
|
|
|
678
|
-
export declare type
|
|
247
|
+
export declare type JitTranslate = (input: JitTranslateInput, builder: JitBlockBuilder) => BlockIR;
|
|
679
248
|
|
|
680
|
-
export declare interface
|
|
681
|
-
readonly
|
|
682
|
-
|
|
249
|
+
export declare interface JitTranslateInput {
|
|
250
|
+
readonly pc: number;
|
|
251
|
+
/** 仅在本次同步 translate 回调内有效。 */
|
|
252
|
+
readonly code: BorrowedBytes;
|
|
683
253
|
}
|
|
684
254
|
|
|
685
|
-
|
|
686
|
-
readonly kind: 'signal' | 'power' | 'gnd';
|
|
687
|
-
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
688
|
-
}
|
|
255
|
+
declare const libraryTag: unique symbol;
|
|
689
256
|
|
|
690
|
-
export declare interface
|
|
691
|
-
readonly
|
|
257
|
+
export declare interface NetDescription {
|
|
258
|
+
readonly id: string;
|
|
259
|
+
readonly pins: readonly PinEndpoint[];
|
|
260
|
+
/** 有限对地电压,0 表示地;省略时不建立理想参考。 */
|
|
261
|
+
readonly voltage?: number;
|
|
692
262
|
}
|
|
693
263
|
|
|
694
|
-
|
|
264
|
+
declare interface Notification_2 {
|
|
265
|
+
readonly time: number;
|
|
266
|
+
}
|
|
267
|
+
export { Notification_2 as Notification }
|
|
695
268
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
readonly pins: ReadonlyMap<string, number>;
|
|
700
|
-
readonly devices: ReadonlyMap<string, DevicePinAllocation>;
|
|
701
|
-
readonly totalPins: number;
|
|
702
|
-
readonly capacity: number;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/** Result of the global state allocation. */
|
|
706
|
-
declare interface GlobalStateMap {
|
|
707
|
-
readonly devices: ReadonlyMap<string, ReadonlyMap<string, DeviceStateSlot>>;
|
|
708
|
-
/** One generated array per scalar type actually used. */
|
|
709
|
-
readonly arrays: ReadonlyMap<ScalarType, ArrayRef>;
|
|
710
|
-
/** Slot count per scalar type. */
|
|
711
|
-
readonly totals: ReadonlyMap<ScalarType, number>;
|
|
712
|
-
readonly totalStates: number;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/** Physical output configuration values. */
|
|
716
|
-
export declare const PIN_MODE: Readonly<{
|
|
717
|
-
readonly highZ: 0;
|
|
718
|
-
readonly pushPull: 1;
|
|
719
|
-
readonly openDrain: 2;
|
|
720
|
-
readonly analog: 3;
|
|
721
|
-
}>;
|
|
722
|
-
|
|
723
|
-
export declare interface PinElectricalDescription {
|
|
724
|
-
readonly drive?: {
|
|
725
|
-
readonly reference: ElectricalReference;
|
|
726
|
-
readonly highResistance: number;
|
|
727
|
-
readonly lowResistance: number;
|
|
728
|
-
readonly analogResistance?: number;
|
|
729
|
-
readonly maxAbsCurrent?: number;
|
|
730
|
-
};
|
|
731
|
-
readonly bias?: {
|
|
732
|
-
readonly reference: ElectricalReference;
|
|
733
|
-
readonly upResistance: number;
|
|
734
|
-
readonly downResistance: number;
|
|
735
|
-
};
|
|
736
|
-
readonly input?: {
|
|
737
|
-
readonly reference: ElectricalReference;
|
|
738
|
-
readonly low: number;
|
|
739
|
-
readonly high: number;
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/** One physical output configuration value. */
|
|
744
|
-
export declare type PinMode = (typeof PIN_MODE)[keyof typeof PIN_MODE];
|
|
745
|
-
|
|
746
|
-
export declare interface ResistorDeclaration {
|
|
747
|
-
readonly pins: readonly [string, string];
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
export declare interface ResistorInitialState {
|
|
751
|
-
readonly resistance: number;
|
|
752
|
-
readonly enabled: boolean;
|
|
753
|
-
readonly maxAbsCurrent?: number;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/** One resolved pin in the global pin space. */
|
|
757
|
-
declare interface ResolvedDevicePin {
|
|
758
|
-
readonly name: string;
|
|
759
|
-
readonly deviceId: string;
|
|
760
|
-
readonly globalPinId: number;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
/** One component symbol of a compiled schematic. */
|
|
764
|
-
export declare interface SchematicCircuitBinding {
|
|
765
|
-
/** Symbol id as written in the schematic. */
|
|
766
|
-
readonly symbolId: string;
|
|
767
|
-
/** Compiler-safe device id assigned to the symbol. */
|
|
768
|
-
readonly deviceId: string;
|
|
769
|
-
/** Parsed `"<packageId>:<deviceId>"` reference. */
|
|
770
|
-
readonly reference: DeviceReference;
|
|
771
|
-
/** Device type from the resolved runtime binding. */
|
|
772
|
-
readonly type: string;
|
|
269
|
+
export declare interface PinEndpoint {
|
|
270
|
+
readonly instance: string;
|
|
271
|
+
readonly pin: string;
|
|
773
272
|
}
|
|
774
273
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
readonly resolveDevice: (reference: DeviceReference) => SchematicDeviceBinding | undefined;
|
|
784
|
-
/** Coordinate tolerance used when matching pins to wires. */
|
|
785
|
-
readonly tolerance?: number;
|
|
274
|
+
export declare type PropertyInput = number | boolean | string | null | Uint8Array;
|
|
275
|
+
|
|
276
|
+
/** 四个 uint32,不能全零;精确数值合法性在创建前校验。 */
|
|
277
|
+
export declare type RandomState = readonly [number, number, number, number];
|
|
278
|
+
|
|
279
|
+
/** 可跨推进和销毁留存的自有只读快照;slice 返回调用方拥有的可变副本。 */
|
|
280
|
+
export declare interface ReadonlyBytes extends ByteReader {
|
|
281
|
+
readonly [snapshotTag]: true;
|
|
786
282
|
}
|
|
787
283
|
|
|
788
|
-
/**
|
|
789
|
-
declare interface
|
|
790
|
-
readonly
|
|
791
|
-
|
|
792
|
-
readonly
|
|
284
|
+
/** cause 保留原异常引用;只读约束不要求冻结宿主异常对象。 */
|
|
285
|
+
export declare interface RuntimeDiagnostic {
|
|
286
|
+
readonly code: RuntimeDiagnosticCode;
|
|
287
|
+
readonly message: string;
|
|
288
|
+
readonly phase: RuntimePhase;
|
|
289
|
+
readonly time: number | null;
|
|
290
|
+
readonly instanceId?: string;
|
|
291
|
+
readonly resource?: string;
|
|
292
|
+
readonly path?: InputPath;
|
|
293
|
+
readonly source?: SourceInfo;
|
|
294
|
+
readonly cause?: unknown;
|
|
295
|
+
readonly related: readonly RuntimeDiagnostic[];
|
|
793
296
|
}
|
|
794
297
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
readonly
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
* A host routes payloads through the description's `applyInputs` /
|
|
807
|
-
* `flushOutputs` hooks: topic names are host-facing, never a route into
|
|
808
|
-
* device state.
|
|
809
|
-
*/
|
|
810
|
-
readonly topics?: readonly SchematicDeviceTopic[];
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/** Reads the bytes of one schematic URI; the caller resolves relative references. */
|
|
814
|
-
export declare interface SchematicDeviceSimulationHostOptions {
|
|
815
|
-
/** Local startup configuration, not an RPC method or payload. */
|
|
816
|
-
readonly electrical?: CircuitElectricalOptions;
|
|
817
|
-
readonly read: (uri: string) => Promise<Uint8Array>;
|
|
818
|
-
/**
|
|
819
|
-
* Symbol geometry of the schematics this host loads. Pass the same provider the schematic was
|
|
820
|
-
* authored with; without it the derived topology contains no pins. A factory is called when a
|
|
821
|
-
* schematic loads, so a caller can read its device library first.
|
|
822
|
-
*/
|
|
823
|
-
readonly devices?: DeviceSymbolProvider | (() => DeviceSymbolProvider);
|
|
824
|
-
/**
|
|
825
|
-
* Resolves one schematic device reference to its runtime description and endpoints.
|
|
826
|
-
*
|
|
827
|
-
* The host ships no device models: the package that owns the devices decides which references
|
|
828
|
-
* exist, what they look like and which topics they expose.
|
|
829
|
-
*/
|
|
830
|
-
readonly resolveDevice: (reference: DeviceReference) => SchematicDeviceBinding | undefined;
|
|
298
|
+
export declare type RuntimeDiagnosticCode = 'INVALID_CONFIGURATION' | 'MODEL_VALIDATION_FAILED' | 'RESOURCE_ALLOCATION_FAILED' | 'INVALID_ELECTRICAL_PARAMETER' | 'CONFLICTING_REFERENCE' | 'ELECTRICAL_SOLVE_FAILED' | 'CHANNEL_CONSUMER_CONFLICT' | 'INVALID_CALL_STATE' | 'OBJECT_DISPOSED' | 'BOARD_FAULTED' | 'INVALID_BINDING' | 'MODEL_EXECUTION_FAILED' | 'JIT_FAILED' | 'DEVICE_CALLBACK_FAILED' | 'ASYNC_HOOK_RESULT' | 'CHANNEL_OVERFLOW' | 'REPORTED_ERROR' | 'CLEANUP_FAILED' | 'STALE_REPORT' | 'HOST_LISTENER_FAILED';
|
|
299
|
+
|
|
300
|
+
export declare type RuntimePhase = 'library' | 'assembly' | 'initialize' | 'execute' | 'translate' | 'sync' | 'topic' | 'dispose' | 'host' | 'report';
|
|
301
|
+
|
|
302
|
+
export declare type SimulationDiagnosticCode = 'device/input-failed' | 'device/output-failed' | 'board/error' | 'board/diagnostic';
|
|
303
|
+
|
|
304
|
+
export declare class SimulationError extends Error {
|
|
305
|
+
readonly code: RuntimeDiagnosticCode;
|
|
306
|
+
readonly diagnostic: RuntimeDiagnostic;
|
|
307
|
+
readonly related: readonly RuntimeDiagnostic[];
|
|
308
|
+
constructor(diagnostic: RuntimeDiagnostic);
|
|
831
309
|
}
|
|
832
310
|
|
|
311
|
+
export declare type SimulationModuleImporter = (code: string, deviceId: string) => Promise<unknown>;
|
|
312
|
+
|
|
833
313
|
/**
|
|
834
|
-
*
|
|
314
|
+
* Error raised while preparing or driving a prepared simulation.
|
|
835
315
|
*
|
|
836
|
-
* The
|
|
837
|
-
*
|
|
838
|
-
* publishes, in the same place it supplies the IR description.
|
|
316
|
+
* The code is stable and machine-checkable; the message names the offending device, symbol or
|
|
317
|
+
* asset so a caller can report it without parsing the cause chain.
|
|
839
318
|
*/
|
|
840
|
-
export declare
|
|
841
|
-
readonly
|
|
842
|
-
readonly
|
|
843
|
-
readonly
|
|
844
|
-
|
|
319
|
+
export declare class SimulationRuntimeError extends Error {
|
|
320
|
+
readonly name = "SimulationRuntimeError";
|
|
321
|
+
readonly code: SimulationRuntimeErrorCode;
|
|
322
|
+
readonly deviceId: string | undefined;
|
|
323
|
+
constructor(code: SimulationRuntimeErrorCode, message: string, options?: ISimulationRuntimeErrorOptions);
|
|
845
324
|
}
|
|
846
325
|
|
|
847
|
-
/**
|
|
848
|
-
export declare
|
|
849
|
-
readonly target: CanvasBindingTarget;
|
|
850
|
-
readonly payload: unknown;
|
|
851
|
-
readonly simTime: number;
|
|
852
|
-
}
|
|
326
|
+
/** Stable failure codes of the prepared-simulation runtime. */
|
|
327
|
+
export declare type SimulationRuntimeErrorCode = 'invalid-input' | 'invalid-device' | 'unresolved-device' | 'unresolved-asset' | 'not-loaded' | 'disposed';
|
|
853
328
|
|
|
854
329
|
/**
|
|
855
|
-
*
|
|
330
|
+
* Wire name of the prepared simulation runtime.
|
|
856
331
|
*
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
* self-contained script. The guest registers `deviceSimulationHostGuestService` and reads schematics
|
|
860
|
-
* through `deviceSimulationHostFileSystemService`, so schematic bytes never enter the guest's own
|
|
861
|
-
* message handling and every payload is a typed RPC DTO.
|
|
332
|
+
* The same id is registered on the primary sandbox RPC channel and on the direct topic port, so a
|
|
333
|
+
* widget guest reaches the running simulation without a second protocol.
|
|
862
334
|
*/
|
|
863
|
-
export declare
|
|
335
|
+
export declare const simulationRuntimeService: RpcServiceId<ISimulationRuntimeRpc>;
|
|
864
336
|
|
|
865
|
-
/**
|
|
866
|
-
export declare const
|
|
337
|
+
/** Topic-port view of the same wire service registered by the runtime guest. */
|
|
338
|
+
export declare const simulationRuntimeTopicService: RpcServiceId<ISimulationRuntimeTopicRpc>;
|
|
867
339
|
|
|
868
|
-
|
|
869
|
-
export declare class UnifiedIRCompilerError extends Error {
|
|
870
|
-
readonly name = "UnifiedIRCompilerError";
|
|
871
|
-
readonly code: UnifiedIRCompilerErrorCode;
|
|
872
|
-
readonly deviceId: string | undefined;
|
|
873
|
-
readonly pinName: string | undefined;
|
|
874
|
-
constructor(code: UnifiedIRCompilerErrorCode, message: string, options?: UnifiedIRCompilerErrorOptions);
|
|
875
|
-
}
|
|
340
|
+
declare const snapshotTag: unique symbol;
|
|
876
341
|
|
|
877
|
-
/**
|
|
878
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Starts the prepared simulation runtime on one sandbox RPC port.
|
|
344
|
+
*
|
|
345
|
+
* A worker script calls this after taking `event.ports[0]`; extra ports stay in order. The returned
|
|
346
|
+
* node owns the runtime and disposes it with the registrations.
|
|
347
|
+
*/
|
|
348
|
+
export declare function startSimulationRuntimeGuest(port: MessagePort, options?: ISimulationRuntimeGuestOptions): ISimulationRuntimeGuest;
|
|
879
349
|
|
|
880
|
-
export declare interface
|
|
881
|
-
readonly
|
|
882
|
-
|
|
883
|
-
|
|
350
|
+
export declare interface TopicBridge {
|
|
351
|
+
readonly onDidReceive: Event_2<TopicMessage>;
|
|
352
|
+
publish(topic: string, payload: unknown): void;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export declare interface TopicMessage {
|
|
356
|
+
readonly topic: string;
|
|
357
|
+
readonly payload: unknown;
|
|
884
358
|
}
|
|
885
359
|
|
|
886
360
|
export { }
|