@mica-js/simulator 0.4.0 → 1.0.0
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 +11 -1
- package/dist/index.d.ts +222 -144
- package/dist/index.js +2353 -681
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +6 -0
- package/dist/sandbox.js +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { CanvasBindingTarget } from '@mica-js/core/canvas';
|
|
|
4
4
|
import { DeviceReference } from '@mica-js/core/schematic';
|
|
5
5
|
import { DeviceSymbolProvider } from '@mica-js/core/schematic';
|
|
6
6
|
import { Disposable } from '@mica-js/core/lifecycle';
|
|
7
|
+
import { EntryRef } from '@mica-js/ir';
|
|
7
8
|
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
8
9
|
import { FunctionBuilder } from '@mica-js/ir';
|
|
9
10
|
import { FunctionRef } from '@mica-js/ir';
|
|
@@ -12,9 +13,12 @@ import { IRJITTuning } from '@mica-js/ir';
|
|
|
12
13
|
import { IRModule } from '@mica-js/ir';
|
|
13
14
|
import { IRValidationOptions } from '@mica-js/ir';
|
|
14
15
|
import { PayloadType } from '@mica-js/core/canvas';
|
|
16
|
+
import { PropertyValue } from '@mica-js/core/schematic';
|
|
15
17
|
import { RpcEndpoint } from '@mica-js/core/rpc';
|
|
18
|
+
import { RuntimeScalar } from '@mica-js/ir';
|
|
16
19
|
import { ScalarType } from '@mica-js/ir';
|
|
17
20
|
import { SchematicDocument } from '@mica-js/core/schematic';
|
|
21
|
+
import { StateRef } from '@mica-js/ir';
|
|
18
22
|
import { Value } from '@mica-js/ir';
|
|
19
23
|
|
|
20
24
|
/**
|
|
@@ -36,7 +40,6 @@ import { Value } from '@mica-js/ir';
|
|
|
36
40
|
* expect(circuit.tickCount).toBe(1_000_000n);
|
|
37
41
|
*
|
|
38
42
|
* circuit.reset();
|
|
39
|
-
* circuit.setPin('drive1.PA0', true); // host drives the pin
|
|
40
43
|
* circuit.step();
|
|
41
44
|
* expect(circuit.devices.sink1.getState('lamp')).toBe(true);
|
|
42
45
|
* ```
|
|
@@ -64,18 +67,18 @@ export declare class Circuit<I extends CircuitCompilationInput = CircuitCompilat
|
|
|
64
67
|
/**
|
|
65
68
|
* Runs `count` ticks inside one generated loop — the throughput path.
|
|
66
69
|
*
|
|
67
|
-
* The whole batch is one engine call
|
|
68
|
-
*
|
|
70
|
+
* The whole batch is one engine call. The clock advances by completed ticks,
|
|
71
|
+
* including the completed prefix of a failed batch.
|
|
69
72
|
*
|
|
70
73
|
* @throws {CircuitError} with code `invalid-count` unless `count` is a u32.
|
|
71
74
|
*/
|
|
72
|
-
runBatch(count: number): void;
|
|
75
|
+
runBatch(count: number, dt?: number): void;
|
|
73
76
|
/**
|
|
74
77
|
* Advances exactly one tick — the debugging path.
|
|
75
78
|
*
|
|
76
79
|
* Every call is one engine entry, so prefer `runBatch` for throughput.
|
|
77
80
|
*/
|
|
78
|
-
step(): void;
|
|
81
|
+
step(dt?: number): void;
|
|
79
82
|
/**
|
|
80
83
|
* Restores every memory to its declared initial value, re-runs `initialize`
|
|
81
84
|
* and resets `tickCount` to `0n`.
|
|
@@ -87,23 +90,18 @@ export declare class Circuit<I extends CircuitCompilationInput = CircuitCompilat
|
|
|
87
90
|
/**
|
|
88
91
|
* Reads the level one pin observes.
|
|
89
92
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* `false` unless it is configured push-pull.
|
|
93
|
+
* Requires an explicitly initialized digital input capability and applies
|
|
94
|
+
* the circuit interpretation to the solved physical voltage.
|
|
93
95
|
*
|
|
94
96
|
* @throws {CircuitError} with code `pin-not-found`.
|
|
95
97
|
*/
|
|
96
98
|
getPin(pinName: string): boolean;
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
* @throws {CircuitError} with code `pin-not-found`.
|
|
105
|
-
*/
|
|
106
|
-
setPin(pinName: string, value: boolean): void;
|
|
99
|
+
/** Physical pin voltage; floating results never contain a synthetic voltage. */
|
|
100
|
+
getVoltage(pinName: string): ElectricalReading;
|
|
101
|
+
/** Resistor/contact currents follow endpoint order; source and pin contributions flow outward. */
|
|
102
|
+
getCurrent(resource: string | ElectricalCurrentTarget): ElectricalReading;
|
|
103
|
+
/** Pull-based active diagnostics: one warning per resource; successful recovery removes it. */
|
|
104
|
+
getDiagnostics(): readonly ElectricalDiagnostic[];
|
|
107
105
|
/** Number of ticks completed since creation or the last `reset()`. */
|
|
108
106
|
get tickCount(): bigint;
|
|
109
107
|
/** Virtual tick time completed since creation or the last `reset()`. */
|
|
@@ -127,8 +125,13 @@ export declare interface CircuitCompilationInput {
|
|
|
127
125
|
|
|
128
126
|
/** Options for the compiler. */
|
|
129
127
|
export declare interface CircuitCompilationOptions {
|
|
130
|
-
/**
|
|
131
|
-
readonly
|
|
128
|
+
/** Explicit GND-referenced voltage sources; GND itself is always 0 V. */
|
|
129
|
+
readonly sources?: Readonly<Record<string, {
|
|
130
|
+
readonly voltage: number;
|
|
131
|
+
}>>;
|
|
132
|
+
readonly interpretation?: 'two-state' | 'retain-in-band';
|
|
133
|
+
/** Reproducible mica-floating-v2 input seed; defaults to 0. */
|
|
134
|
+
readonly floatingSeed?: number;
|
|
132
135
|
/** Runs `validateIR` over the generated module. Defaults to `true`. */
|
|
133
136
|
readonly validate?: boolean;
|
|
134
137
|
/** Overrides for the generated entry-point names. */
|
|
@@ -156,18 +159,11 @@ export declare interface CircuitDeviceSimulationHostOptions {
|
|
|
156
159
|
|
|
157
160
|
/** Electrical-solve options forwarded to `compileCircuit`. */
|
|
158
161
|
export declare interface CircuitElectricalOptions {
|
|
159
|
-
|
|
160
|
-
readonly
|
|
162
|
+
readonly sources?: CircuitCompilationOptions['sources'];
|
|
163
|
+
readonly interpretation?: CircuitCompilationOptions['interpretation'];
|
|
164
|
+
readonly floatingSeed?: CircuitCompilationOptions['floatingSeed'];
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
/**
|
|
164
|
-
* Types of the unified circuit runtime (U02).
|
|
165
|
-
*
|
|
166
|
-
* `Circuit` is the host-facing facade over one compiled unified IR module: it
|
|
167
|
-
* owns the engine instance, exposes typed per-device accessors and keeps the
|
|
168
|
-
* tick counter. Everything here is transport-neutral; no type mentions the
|
|
169
|
-
* device host or the schematic editor.
|
|
170
|
-
*/
|
|
171
167
|
/** Execution engine a `Circuit` runs on. */
|
|
172
168
|
export declare type CircuitEngine = 'jit' | 'reference';
|
|
173
169
|
|
|
@@ -187,7 +183,7 @@ export declare class CircuitError extends Error {
|
|
|
187
183
|
}
|
|
188
184
|
|
|
189
185
|
/** Error codes raised by `CircuitError`. */
|
|
190
|
-
export declare type CircuitErrorCode = 'invalid-options' | 'invalid-count' | '
|
|
186
|
+
export declare type CircuitErrorCode = 'invalid-options' | 'invalid-count' | 'unsupported-operation' | 'resource-not-found' | 'pin-not-found' | 'state-not-found' | 'invalid-state-value' | 'unresolved-device' | 'disposed';
|
|
191
187
|
|
|
192
188
|
export declare interface CircuitErrorOptions {
|
|
193
189
|
readonly deviceId?: string;
|
|
@@ -218,20 +214,6 @@ export declare interface CircuitRuntimeOptions {
|
|
|
218
214
|
readonly instanceId?: string;
|
|
219
215
|
}
|
|
220
216
|
|
|
221
|
-
/** One electrical-analysis finding; errors abort `compileCircuit`. */
|
|
222
|
-
export declare interface CompilationDiagnostic {
|
|
223
|
-
readonly code: CompilationDiagnosticCode;
|
|
224
|
-
readonly severity: CompilationDiagnosticSeverity;
|
|
225
|
-
readonly message: string;
|
|
226
|
-
readonly netId: number | undefined;
|
|
227
|
-
readonly endpoints: readonly string[];
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** Diagnostic codes produced by the compiler's electrical analysis. */
|
|
231
|
-
export declare type CompilationDiagnosticCode = 'power-short' | 'rail-conflict' | 'floating-net';
|
|
232
|
-
|
|
233
|
-
declare type CompilationDiagnosticSeverity = 'error' | 'warning';
|
|
234
|
-
|
|
235
217
|
/**
|
|
236
218
|
* Compiles several devices and their wiring into one unified IR module (U01).
|
|
237
219
|
*
|
|
@@ -257,7 +239,7 @@ declare type CompilationDiagnosticSeverity = 'error' | 'warning';
|
|
|
257
239
|
*
|
|
258
240
|
* The pipeline is: validate the input, allocate the global pin and state
|
|
259
241
|
* spaces, analyse the electrical topology, generate one function per device
|
|
260
|
-
* phase, generate
|
|
242
|
+
* phase, generate the resistive network solver and main loop, then validate the
|
|
261
243
|
* resulting module with `validateIR`.
|
|
262
244
|
*
|
|
263
245
|
* @throws {UnifiedIRCompilerError} for malformed input, duplicate ids, unknown
|
|
@@ -269,28 +251,21 @@ export declare function compileCircuit(input: CircuitCompilationInput, options?:
|
|
|
269
251
|
export declare interface CompiledCircuit {
|
|
270
252
|
readonly module: IRModule;
|
|
271
253
|
readonly entryPoints: CompiledEntryPoints;
|
|
254
|
+
/** Completed ticks in the most recent step/batch, including before a fault. */
|
|
255
|
+
readonly progress: StateRef<'u32'>;
|
|
272
256
|
/** `'mcu1.PA0'` -> global pin id. */
|
|
273
257
|
readonly pinMap: ReadonlyMap<string, number>;
|
|
274
258
|
readonly deviceMap: ReadonlyMap<string, DeviceMetadata>;
|
|
275
|
-
readonly netlist: CompiledNetlist;
|
|
276
259
|
readonly pins: GlobalPinMap;
|
|
277
260
|
readonly states: GlobalStateMap;
|
|
278
|
-
readonly memory: CompiledCircuitMemory;
|
|
279
261
|
/** Validation grants covering every instruction and memory of the module. */
|
|
280
262
|
readonly validation: IRValidationOptions;
|
|
281
|
-
/** Device ids in
|
|
263
|
+
/** Device ids in stable declaration order. */
|
|
282
264
|
readonly executionOrder: readonly string[];
|
|
283
265
|
/** Every generated function name, in definition order. */
|
|
284
266
|
readonly functions: readonly string[];
|
|
285
267
|
}
|
|
286
268
|
|
|
287
|
-
/** Pin memories every device and every net solver shares. */
|
|
288
|
-
declare interface CompiledCircuitMemory {
|
|
289
|
-
readonly mode: ArrayRef<'u8'>;
|
|
290
|
-
readonly output: ArrayRef<'bool'>;
|
|
291
|
-
readonly input: ArrayRef<'bool'>;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
269
|
/** Generated entry points, both by name and as executable refs. */
|
|
295
270
|
declare interface CompiledEntryPoints {
|
|
296
271
|
readonly tick: string;
|
|
@@ -303,50 +278,6 @@ declare interface CompiledEntryPoints {
|
|
|
303
278
|
};
|
|
304
279
|
}
|
|
305
280
|
|
|
306
|
-
/** One electrical net: a connected component of pins and rails. */
|
|
307
|
-
declare interface CompiledNet {
|
|
308
|
-
readonly netId: number;
|
|
309
|
-
readonly pins: readonly CompiledPinConnection[];
|
|
310
|
-
readonly rails: readonly CompiledRail[];
|
|
311
|
-
readonly drivers: readonly CompiledPinConnection[];
|
|
312
|
-
/** Pins whose role is `load`. */
|
|
313
|
-
readonly loads: readonly CompiledPinConnection[];
|
|
314
|
-
/** Every pin that reads the solved level, including bidirectional drivers. */
|
|
315
|
-
readonly sinks: readonly CompiledPinConnection[];
|
|
316
|
-
readonly source: CompiledNetSource;
|
|
317
|
-
/** Constant level of a driver-less net; unused when `source === 'driver'`. */
|
|
318
|
-
readonly level: boolean;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Result of the network topology analysis. */
|
|
322
|
-
declare interface CompiledNetlist {
|
|
323
|
-
readonly nets: readonly CompiledNet[];
|
|
324
|
-
readonly diagnostics: readonly CompilationDiagnostic[];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** Where a net's level comes from. */
|
|
328
|
-
declare type CompiledNetSource = 'driver' | 'rail' | 'floating';
|
|
329
|
-
|
|
330
|
-
/** One pin resolved onto a net. */
|
|
331
|
-
declare interface CompiledPinConnection {
|
|
332
|
-
/** `'mcu1.PA0'`. */
|
|
333
|
-
readonly endpoint: string;
|
|
334
|
-
readonly deviceId: string;
|
|
335
|
-
readonly pinName: string;
|
|
336
|
-
readonly globalPinId: number;
|
|
337
|
-
readonly role: CompiledPinRole;
|
|
338
|
-
readonly senses: boolean;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/** Role a pin plays on its net; v1 supports one driver per net. */
|
|
342
|
-
declare type CompiledPinRole = 'driver' | 'load';
|
|
343
|
-
|
|
344
|
-
/** One fixed-level rail on a net, e.g. `GND` (low) or `VCC` (high). */
|
|
345
|
-
declare interface CompiledRail {
|
|
346
|
-
readonly name: string;
|
|
347
|
-
readonly level: boolean;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
281
|
/** One pin-to-pin (or pin-to-rail) connection. */
|
|
351
282
|
export declare interface Connection {
|
|
352
283
|
/** `'mcu1.PA0'` or a rail name such as `'GND'`. */
|
|
@@ -354,6 +285,10 @@ export declare interface Connection {
|
|
|
354
285
|
readonly to: string;
|
|
355
286
|
}
|
|
356
287
|
|
|
288
|
+
export declare interface ContactDeclaration extends ResistorDeclaration {
|
|
289
|
+
readonly initial: 'open' | 'closed';
|
|
290
|
+
}
|
|
291
|
+
|
|
357
292
|
/**
|
|
358
293
|
* Adapts one already-loaded unified-IR circuit to the RFC 0018 device host.
|
|
359
294
|
*
|
|
@@ -416,9 +351,6 @@ export declare function createSchematicCircuit(schematic: SchematicDocument, opt
|
|
|
416
351
|
*/
|
|
417
352
|
export declare function createSchematicDeviceSimulationHost(options: SchematicDeviceSimulationHostOptions): DeviceSimulationHost;
|
|
418
353
|
|
|
419
|
-
/** Rails every circuit understands without declaring them. */
|
|
420
|
-
export declare const DEFAULT_RAILS: Readonly<Record<string, boolean>>;
|
|
421
|
-
|
|
422
354
|
/** Global pin addresses one device may own; enough for the largest packages. */
|
|
423
355
|
export declare const DEVICE_PIN_STRIDE = 512;
|
|
424
356
|
|
|
@@ -427,8 +359,8 @@ export declare const DEVICE_PIN_STRIDE = 512;
|
|
|
427
359
|
*
|
|
428
360
|
* `readPin` returns the level the *device* drives onto one of its pins (its
|
|
429
361
|
* output latch), while `Circuit.getPin('device.pin')` returns the level the pin
|
|
430
|
-
* *observes* after the electrical solve.
|
|
431
|
-
*
|
|
362
|
+
* *observes* after the electrical solve. Host changes use device state; there
|
|
363
|
+
* is no direct pin override API.
|
|
432
364
|
*/
|
|
433
365
|
export declare interface DeviceAccessor {
|
|
434
366
|
/** Circuit-unique device id. */
|
|
@@ -442,11 +374,14 @@ export declare interface DeviceAccessor {
|
|
|
442
374
|
/** Reads the level the device drives onto `pinName`. */
|
|
443
375
|
readPin(pinName: string): boolean;
|
|
444
376
|
/** Writes the level the device drives onto `pinName`. */
|
|
445
|
-
writePin(pinName: string, value: boolean): void;
|
|
446
377
|
/** Reads one declared internal state. */
|
|
447
378
|
getState(name: string): unknown;
|
|
448
379
|
/** Writes one declared internal state. */
|
|
449
380
|
setState(name: string, value: unknown): void;
|
|
381
|
+
/** Consumes inputs at a host step boundary, when declared by the paired factory. */
|
|
382
|
+
applyInputs?(inputs: readonly DeviceInput[]): void;
|
|
383
|
+
/** Publishes outputs after the host finishes evaluating the step. */
|
|
384
|
+
flushOutputs?(publish: (port: string, payload: unknown) => void): void;
|
|
450
385
|
}
|
|
451
386
|
|
|
452
387
|
/**
|
|
@@ -499,7 +434,6 @@ declare interface DeviceAccessorSurface {
|
|
|
499
434
|
readonly pinNames: readonly string[];
|
|
500
435
|
readonly stateNames: readonly string[];
|
|
501
436
|
readPin(pinName: string): boolean;
|
|
502
|
-
writePin(pinName: string, value: boolean): void;
|
|
503
437
|
getState(name: string): unknown;
|
|
504
438
|
setState(name: string, value: unknown): void;
|
|
505
439
|
}
|
|
@@ -514,15 +448,17 @@ export declare interface DeviceBehaviorApi {
|
|
|
514
448
|
* simple devices never need to touch it.
|
|
515
449
|
*/
|
|
516
450
|
readonly module: IRModule;
|
|
517
|
-
/** Shared `pin_mode` / `pin_output` / `pin_input` memories. */
|
|
518
|
-
readonly memory: CompiledCircuitMemory;
|
|
519
451
|
/** Instance configuration from {@link DeviceConfig.config}. */
|
|
520
452
|
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
521
453
|
/** Every declared pin of the device, in declaration order. */
|
|
522
454
|
readonly pins: readonly DevicePinHandle[];
|
|
523
|
-
/** Pins
|
|
455
|
+
/** Pins initialized with physical drive capability. */
|
|
524
456
|
readonly outputs: readonly DevicePinHandle[];
|
|
525
457
|
pin(name: string): DevicePinHandle;
|
|
458
|
+
resistor(name: string): DeviceResistorHandle;
|
|
459
|
+
writeDigitalGroup(names: readonly string[], levels: readonly Value<'bool'>[]): void;
|
|
460
|
+
applyResistors(names: readonly string[], ohms: readonly Value<'f64'>[]): void;
|
|
461
|
+
applyConnections(names: readonly string[], closed: readonly Value<'bool'>[]): void;
|
|
526
462
|
state<T extends ScalarType = ScalarType>(name: string): DeviceStateHandle<T>;
|
|
527
463
|
}
|
|
528
464
|
|
|
@@ -537,6 +473,11 @@ export declare interface DeviceBehaviors {
|
|
|
537
473
|
readonly update?: (api: DeviceBehaviorApi) => void;
|
|
538
474
|
}
|
|
539
475
|
|
|
476
|
+
export declare interface DeviceBridgeHooks {
|
|
477
|
+
readonly applyInputs?: (io: DeviceInputIo) => void;
|
|
478
|
+
readonly flushOutputs?: (io: DeviceOutputIo) => void;
|
|
479
|
+
}
|
|
480
|
+
|
|
540
481
|
/** One device instance of the circuit. */
|
|
541
482
|
export declare interface DeviceConfig {
|
|
542
483
|
/** Circuit-unique identity; prefix of every generated function name. */
|
|
@@ -544,14 +485,21 @@ export declare interface DeviceConfig {
|
|
|
544
485
|
/** Device type, e.g. `'push-pull-driver'`; free-form label of the device model. */
|
|
545
486
|
readonly type: string;
|
|
546
487
|
readonly description: DeviceDescription;
|
|
488
|
+
/** Persistent instance values resolved against the JSON property declarations. */
|
|
489
|
+
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
547
490
|
/** Instance configuration; reserved for device kernels that take parameters. */
|
|
548
491
|
readonly config?: Readonly<Record<string, unknown>>;
|
|
549
492
|
}
|
|
550
493
|
|
|
551
494
|
/** IR-level device description consumed by the compiler. */
|
|
552
|
-
export declare interface DeviceDescription {
|
|
495
|
+
export declare interface DeviceDescription extends DeviceBridgeHooks {
|
|
553
496
|
readonly name?: string;
|
|
554
497
|
readonly pins: DevicePinMap;
|
|
498
|
+
readonly properties?: Readonly<Record<string, unknown>>;
|
|
499
|
+
readonly resistors?: Readonly<Record<string, ResistorDeclaration>>;
|
|
500
|
+
readonly connections?: Readonly<Record<string, ContactDeclaration>>;
|
|
501
|
+
/** Paired synchronous JS factory, invoked once per instance before IR generation. */
|
|
502
|
+
readonly factory: (context: ElectricalFactoryContext) => DeviceImplementation | void;
|
|
555
503
|
readonly states?: Readonly<Record<string, DeviceStateDescription>>;
|
|
556
504
|
readonly behaviors?: DeviceBehaviors;
|
|
557
505
|
/**
|
|
@@ -573,16 +521,38 @@ export declare interface DeviceDescription {
|
|
|
573
521
|
readonly updateResources?: readonly BytesRef[];
|
|
574
522
|
}
|
|
575
523
|
|
|
524
|
+
export declare interface DeviceElectricalInitialization {
|
|
525
|
+
initializeResistor(id: string, initial: ResistorInitialState): void;
|
|
526
|
+
initializePin(id: string, initial: PinElectricalDescription): void;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Per-instance construction and boundary hooks returned by the paired factory. */
|
|
530
|
+
export declare interface DeviceImplementation extends DeviceBehaviors, DeviceBridgeHooks {
|
|
531
|
+
readonly kernel?: DeviceKernelFactory;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export declare interface DeviceInput {
|
|
535
|
+
readonly port: string;
|
|
536
|
+
readonly payload: unknown;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export declare interface DeviceInputIo {
|
|
540
|
+
takeInput(port: string): unknown;
|
|
541
|
+
takeInputs(port: string): readonly unknown[];
|
|
542
|
+
writeState(name: string, value: unknown): void;
|
|
543
|
+
call(entry: EntryRef, args: readonly RuntimeScalar[]): void;
|
|
544
|
+
}
|
|
545
|
+
|
|
576
546
|
/**
|
|
577
547
|
* Everything a complex device kernel needs to declare its own IR before any
|
|
578
548
|
* phase function body is opened: the module (for `array`/`bytes`/`provider`),
|
|
579
|
-
*
|
|
549
|
+
* typed operations through `bind(builder)` and the allocated pin ids.
|
|
580
550
|
*/
|
|
581
551
|
export declare interface DeviceKernelContext {
|
|
582
552
|
readonly deviceId: string;
|
|
583
553
|
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
584
554
|
readonly module: IRModule;
|
|
585
|
-
readonly
|
|
555
|
+
bind(builder: FunctionBuilder<readonly []>): DeviceBehaviorApi;
|
|
586
556
|
readonly pins: readonly DeviceKernelPin[];
|
|
587
557
|
}
|
|
588
558
|
|
|
@@ -601,7 +571,6 @@ export declare type DeviceKernelFactory = (context: DeviceKernelContext) => Devi
|
|
|
601
571
|
declare interface DeviceKernelPin {
|
|
602
572
|
readonly name: string;
|
|
603
573
|
readonly globalPinId: number;
|
|
604
|
-
readonly role: CompiledPinRole;
|
|
605
574
|
}
|
|
606
575
|
|
|
607
576
|
/**
|
|
@@ -616,8 +585,9 @@ export declare interface DeviceKernelRuntime {
|
|
|
616
585
|
}
|
|
617
586
|
|
|
618
587
|
/** Metadata of one compiled device. */
|
|
619
|
-
declare interface DeviceMetadata {
|
|
588
|
+
declare interface DeviceMetadata extends DeviceBridgeHooks {
|
|
620
589
|
readonly deviceId: string;
|
|
590
|
+
readonly entries?: readonly EntryRef[];
|
|
621
591
|
readonly type: string;
|
|
622
592
|
/** First global pin id of the device. */
|
|
623
593
|
readonly pinOffset: number;
|
|
@@ -632,8 +602,11 @@ declare interface DeviceMetadata {
|
|
|
632
602
|
readonly update: string | undefined;
|
|
633
603
|
/** Typed accessor factory supplied by the device description, if any. */
|
|
634
604
|
readonly accessor: DeviceAccessorFactory | undefined;
|
|
635
|
-
|
|
636
|
-
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export declare interface DeviceOutputIo {
|
|
608
|
+
readState(name: string): unknown;
|
|
609
|
+
publish(port: string, payload: unknown): void;
|
|
637
610
|
}
|
|
638
611
|
|
|
639
612
|
/** Pins of one device mapped into the global pin space. */
|
|
@@ -645,16 +618,6 @@ declare interface DevicePinAllocation {
|
|
|
645
618
|
readonly resolved: ReadonlyMap<string, ResolvedDevicePin>;
|
|
646
619
|
}
|
|
647
620
|
|
|
648
|
-
/** One pin declared by a device description. */
|
|
649
|
-
export declare interface DevicePinDescription {
|
|
650
|
-
/** Defaults to `'passive'`: the pin only senses the net. */
|
|
651
|
-
readonly direction?: DevicePinDirection;
|
|
652
|
-
/** Overrides the role derived from `direction`. */
|
|
653
|
-
readonly role?: CompiledPinRole;
|
|
654
|
-
/** Purely informational kind, e.g. `'signal'`, `'power'`, `'gnd'`. */
|
|
655
|
-
readonly kind?: string;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
621
|
/**
|
|
659
622
|
* Types for the unified IR compiler (U01).
|
|
660
623
|
*
|
|
@@ -667,20 +630,27 @@ export declare interface DevicePinDescription {
|
|
|
667
630
|
* live in `../pin-space` and are reused here. The compiler ships no device
|
|
668
631
|
* models: every description is supplied by the caller.
|
|
669
632
|
*/
|
|
670
|
-
/**
|
|
671
|
-
export declare
|
|
633
|
+
/** One pin declared by the paired electrical device definition. */
|
|
634
|
+
export declare interface DevicePinDescription {
|
|
635
|
+
readonly kind: 'signal' | 'power' | 'gnd';
|
|
636
|
+
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
637
|
+
}
|
|
672
638
|
|
|
673
639
|
/** Pin operations a behavior may use; each call inlines into global memory. */
|
|
674
640
|
declare interface DevicePinHandle {
|
|
675
641
|
readonly name: string;
|
|
676
642
|
readonly globalId: number;
|
|
677
|
-
/**
|
|
643
|
+
/** Selects the physical output configuration. */
|
|
678
644
|
configure(mode: number): void;
|
|
679
|
-
|
|
645
|
+
setOutputEnabled(enabled: Value<'bool'>): void;
|
|
646
|
+
setPull(pull: 'none' | 'up' | 'down'): void;
|
|
647
|
+
writeVoltage(voltage: Value<'f64'>): void;
|
|
648
|
+
/** Writes digital drive intent through the finite output impedance. */
|
|
680
649
|
writeDigital(level: Value<'bool'>): void;
|
|
681
|
-
/**
|
|
650
|
+
/** Samples the solved voltage with the explicitly declared input thresholds. */
|
|
682
651
|
sampleDigital(): Value<'bool'>;
|
|
683
|
-
|
|
652
|
+
sampleVoltage(): Value<'f64'>;
|
|
653
|
+
/** Reads this pin's digital drive intent. */
|
|
684
654
|
readDrivenDigital(): Value<'bool'>;
|
|
685
655
|
}
|
|
686
656
|
|
|
@@ -690,12 +660,25 @@ declare interface DevicePinHandle {
|
|
|
690
660
|
*/
|
|
691
661
|
declare type DevicePinMap = ReadonlyMap<string, DevicePinDescription> | Readonly<Record<string, DevicePinDescription>>;
|
|
692
662
|
|
|
663
|
+
declare interface DeviceResistorHandle {
|
|
664
|
+
setResistance(ohms: Value<'f64'>): void;
|
|
665
|
+
setEnabled(enabled: Value<'bool'>): void;
|
|
666
|
+
/** Solved current in amperes, positive from the first declared pin to the second. */
|
|
667
|
+
sampleCurrent(): Value<'f64'>;
|
|
668
|
+
}
|
|
669
|
+
|
|
693
670
|
/** What one {@link DeviceSimulationHost.tick} call executed. */
|
|
694
671
|
export declare interface DeviceSimTickReport {
|
|
695
672
|
/** Simulation time after the step, in picoseconds. */
|
|
696
673
|
readonly simTime: number;
|
|
697
674
|
/** Circuit steps executed by this call. */
|
|
698
675
|
readonly executed: number;
|
|
676
|
+
/** Isolated device boundary-hook failures; absent when the step has none. */
|
|
677
|
+
readonly diagnostics?: readonly {
|
|
678
|
+
readonly code: 'device/input-failed' | 'device/output-failed';
|
|
679
|
+
readonly deviceId: string;
|
|
680
|
+
readonly message: string;
|
|
681
|
+
}[];
|
|
699
682
|
}
|
|
700
683
|
|
|
701
684
|
/**
|
|
@@ -752,6 +735,8 @@ export declare interface DeviceSimulationHostGuest {
|
|
|
752
735
|
* package that owns devices bundles its own worker script and supplies these.
|
|
753
736
|
*/
|
|
754
737
|
export declare interface DeviceSimulationHostGuestOptions {
|
|
738
|
+
/** Fixed electrical configuration supplied by the owning worker module. */
|
|
739
|
+
readonly electrical?: CircuitElectricalOptions;
|
|
755
740
|
/** Symbol geometry of the schematics this guest loads, or a factory called per load. */
|
|
756
741
|
readonly devices?: DeviceSymbolProvider | (() => DeviceSymbolProvider);
|
|
757
742
|
/** Resolves a schematic device reference; when omitted every reference stays unresolved. */
|
|
@@ -812,6 +797,75 @@ export declare interface DeviceTopic {
|
|
|
812
797
|
|
|
813
798
|
export { Disposable }
|
|
814
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Types of the unified circuit runtime (U02).
|
|
802
|
+
*
|
|
803
|
+
* `Circuit` is the host-facing facade over one compiled unified IR module: it
|
|
804
|
+
* owns the engine instance, exposes typed per-device accessors and keeps the
|
|
805
|
+
* tick counter. Everything here is transport-neutral; no type mentions the
|
|
806
|
+
* device host or the schematic editor.
|
|
807
|
+
*/
|
|
808
|
+
export declare type ElectricalCurrentTarget = {
|
|
809
|
+
readonly kind: 'resistor' | 'contact';
|
|
810
|
+
readonly device: string;
|
|
811
|
+
readonly name: string;
|
|
812
|
+
} | {
|
|
813
|
+
readonly kind: 'drive' | 'pull-up' | 'pull-down';
|
|
814
|
+
readonly device: string;
|
|
815
|
+
readonly pin: string;
|
|
816
|
+
} | {
|
|
817
|
+
readonly kind: 'source';
|
|
818
|
+
readonly name: string;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
export declare class ElectricalDefinitionError extends Error {
|
|
822
|
+
readonly code: ElectricalDefinitionErrorCode;
|
|
823
|
+
readonly name = "ElectricalDefinitionError";
|
|
824
|
+
constructor(code: ElectricalDefinitionErrorCode, message: string);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export declare type ElectricalDefinitionErrorCode = 'electrical/invalid-definition' | 'electrical/invalid-parameter' | 'electrical/unknown-resource' | 'electrical/duplicate-initialization' | 'electrical/missing-initialization' | 'electrical/factory-closed';
|
|
828
|
+
|
|
829
|
+
/** Active diagnostics of the last published electrical snapshot, plus any latched solve fault. */
|
|
830
|
+
export declare type ElectricalDiagnostic = {
|
|
831
|
+
readonly code: 'electrical/overcurrent';
|
|
832
|
+
readonly severity: 'warning';
|
|
833
|
+
readonly target: ElectricalCurrentTarget;
|
|
834
|
+
readonly current: number;
|
|
835
|
+
readonly maxAbsCurrent: number;
|
|
836
|
+
} | {
|
|
837
|
+
readonly code: 'electrical/invalid-parameter' | 'electrical/source-conflict' | 'electrical/numerical-failure';
|
|
838
|
+
readonly severity: 'error';
|
|
839
|
+
/** Identifiable failed operation or resource; absent for a matrix-level failure. */
|
|
840
|
+
readonly target?: ElectricalCurrentTarget;
|
|
841
|
+
/** Resources associated with the affected network, not a list of proven culprits. */
|
|
842
|
+
readonly resources: readonly ElectricalCurrentTarget[];
|
|
843
|
+
readonly pins: readonly string[];
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
export declare interface ElectricalFactoryContext {
|
|
847
|
+
readonly properties: Readonly<Record<string, PropertyValue>>;
|
|
848
|
+
readonly electrical: DeviceElectricalInitialization;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
export declare interface ElectricalPinDeclaration {
|
|
852
|
+
readonly kind: 'signal' | 'power' | 'gnd';
|
|
853
|
+
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
declare type ElectricalReading = {
|
|
857
|
+
readonly state: 'determinate';
|
|
858
|
+
readonly value: number;
|
|
859
|
+
} | {
|
|
860
|
+
readonly state: 'floating';
|
|
861
|
+
} | {
|
|
862
|
+
readonly state: 'indeterminate';
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
export declare interface ElectricalReference {
|
|
866
|
+
readonly source: string;
|
|
867
|
+
}
|
|
868
|
+
|
|
815
869
|
export { Event_2 as Event }
|
|
816
870
|
|
|
817
871
|
/** Result of the global pin allocation. */
|
|
@@ -833,7 +887,7 @@ declare interface GlobalStateMap {
|
|
|
833
887
|
readonly totalStates: number;
|
|
834
888
|
}
|
|
835
889
|
|
|
836
|
-
/**
|
|
890
|
+
/** Physical output configuration values. */
|
|
837
891
|
export declare const PIN_MODE: Readonly<{
|
|
838
892
|
readonly highZ: 0;
|
|
839
893
|
readonly pushPull: 1;
|
|
@@ -841,18 +895,44 @@ export declare const PIN_MODE: Readonly<{
|
|
|
841
895
|
readonly analog: 3;
|
|
842
896
|
}>;
|
|
843
897
|
|
|
844
|
-
|
|
898
|
+
export declare interface PinElectricalDescription {
|
|
899
|
+
readonly drive?: {
|
|
900
|
+
readonly reference: ElectricalReference;
|
|
901
|
+
readonly highResistance: number;
|
|
902
|
+
readonly lowResistance: number;
|
|
903
|
+
readonly analogResistance?: number;
|
|
904
|
+
readonly maxAbsCurrent?: number;
|
|
905
|
+
};
|
|
906
|
+
readonly bias?: {
|
|
907
|
+
readonly reference: ElectricalReference;
|
|
908
|
+
readonly upResistance: number;
|
|
909
|
+
readonly downResistance: number;
|
|
910
|
+
};
|
|
911
|
+
readonly input?: {
|
|
912
|
+
readonly reference: ElectricalReference;
|
|
913
|
+
readonly low: number;
|
|
914
|
+
readonly high: number;
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/** One physical output configuration value. */
|
|
845
919
|
export declare type PinMode = (typeof PIN_MODE)[keyof typeof PIN_MODE];
|
|
846
920
|
|
|
921
|
+
export declare interface ResistorDeclaration {
|
|
922
|
+
readonly pins: readonly [string, string];
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
export declare interface ResistorInitialState {
|
|
926
|
+
readonly resistance: number;
|
|
927
|
+
readonly enabled: boolean;
|
|
928
|
+
readonly maxAbsCurrent?: number;
|
|
929
|
+
}
|
|
930
|
+
|
|
847
931
|
/** One resolved pin in the global pin space. */
|
|
848
932
|
declare interface ResolvedDevicePin {
|
|
849
933
|
readonly name: string;
|
|
850
934
|
readonly deviceId: string;
|
|
851
935
|
readonly globalPinId: number;
|
|
852
|
-
readonly direction: DevicePinDirection;
|
|
853
|
-
readonly role: CompiledPinRole;
|
|
854
|
-
/** Whether the device reads the solved value of this pin. */
|
|
855
|
-
readonly senses: boolean;
|
|
856
936
|
}
|
|
857
937
|
|
|
858
938
|
/** One component symbol of a compiled schematic. */
|
|
@@ -905,6 +985,8 @@ export declare interface SchematicDeviceBinding {
|
|
|
905
985
|
|
|
906
986
|
/** Reads the bytes of one schematic URI; the caller resolves relative references. */
|
|
907
987
|
export declare interface SchematicDeviceSimulationHostOptions {
|
|
988
|
+
/** Local startup configuration, not an RPC method or payload. */
|
|
989
|
+
readonly electrical?: CircuitElectricalOptions;
|
|
908
990
|
readonly read: (uri: string) => Promise<Uint8Array>;
|
|
909
991
|
/**
|
|
910
992
|
* Symbol geometry of the schematics this host loads. Pass the same provider the schematic was
|
|
@@ -962,19 +1044,15 @@ export declare class UnifiedIRCompilerError extends Error {
|
|
|
962
1044
|
readonly code: UnifiedIRCompilerErrorCode;
|
|
963
1045
|
readonly deviceId: string | undefined;
|
|
964
1046
|
readonly pinName: string | undefined;
|
|
965
|
-
readonly netId: number | undefined;
|
|
966
|
-
readonly diagnostics: readonly CompilationDiagnostic[];
|
|
967
1047
|
constructor(code: UnifiedIRCompilerErrorCode, message: string, options?: UnifiedIRCompilerErrorOptions);
|
|
968
1048
|
}
|
|
969
1049
|
|
|
970
1050
|
/** Error codes raised by {@link UnifiedIRCompilerError}. */
|
|
971
|
-
export declare type UnifiedIRCompilerErrorCode = 'invalid-input' | 'duplicate-device' | '
|
|
1051
|
+
export declare type UnifiedIRCompilerErrorCode = 'invalid-input' | 'duplicate-device' | 'state-not-found' | 'capacity-exceeded' | 'invalid-ir';
|
|
972
1052
|
|
|
973
1053
|
export declare interface UnifiedIRCompilerErrorOptions {
|
|
974
1054
|
readonly deviceId?: string;
|
|
975
1055
|
readonly pinName?: string;
|
|
976
|
-
readonly netId?: number;
|
|
977
|
-
readonly diagnostics?: readonly CompilationDiagnostic[];
|
|
978
1056
|
readonly cause?: unknown;
|
|
979
1057
|
}
|
|
980
1058
|
|