@mica-js/device-model 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +39 -2
- package/dist/index.d.ts +1053 -0
- package/dist/index.js +3433 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
export declare type Argument = Operand<RuntimeValue> | PinRef | MemoryRef;
|
|
2
|
+
|
|
3
|
+
export declare type ArgumentIR = {
|
|
4
|
+
readonly kind: 'value';
|
|
5
|
+
readonly value: ResultId;
|
|
6
|
+
} | PinRefIR | MemoryRefIR;
|
|
7
|
+
|
|
8
|
+
/** 消息回调生成惰性区域,运行时只在条件为 false 时计算消息。 */
|
|
9
|
+
export declare interface Assertions<Compute extends ValueOps> {
|
|
10
|
+
assert(condition: Operand<boolean>, message?: (body: Compute) => ComputeResult<Compute, string>): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare type BinaryOperator = 'add' | 'subtract' | 'multiply' | 'divide' | 'remainder' | 'power' | 'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'concat' | 'bitAnd' | 'bitOr' | 'bitXor' | 'shiftLeft' | 'shiftRight' | 'shiftRightUnsigned';
|
|
14
|
+
|
|
15
|
+
export declare interface BlockIR extends Located {
|
|
16
|
+
readonly kind: 'block';
|
|
17
|
+
readonly instructions: readonly InstructionIR[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare class BuildError extends Error {
|
|
21
|
+
readonly diagnostics: readonly [Diagnostic, ...Diagnostic[]];
|
|
22
|
+
constructor(diagnostics: readonly [Diagnostic, ...Diagnostic[]]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const bytesTag: unique symbol;
|
|
26
|
+
|
|
27
|
+
export declare interface BytesValue {
|
|
28
|
+
readonly [bytesTag]: true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare interface ChannelOptions<T extends RuntimeValue> extends NamedOptions {
|
|
32
|
+
readonly direction: 'input' | 'output';
|
|
33
|
+
readonly type: Type<T>;
|
|
34
|
+
readonly capacity: CreationInput<number>;
|
|
35
|
+
readonly overflow?: CreationInput<EnumValue<'Overflow', 'drop_new' | 'drop_oldest' | 'error'>>;
|
|
36
|
+
readonly maxLength?: CreationInput<number>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare type ComparablePlainTypeIR = {
|
|
40
|
+
readonly kind: 'number' | 'bool' | 'string' | 'bytes' | 'sample';
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'enum' | 'record';
|
|
43
|
+
readonly name: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export declare type ComparableTypeIR = ComparablePlainTypeIR | {
|
|
47
|
+
readonly kind: 'optional';
|
|
48
|
+
readonly inner: ComparablePlainTypeIR;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export declare type ComparableValue = Exclude<RuntimeValue, IntentValue>;
|
|
52
|
+
|
|
53
|
+
/** 独立计算体使用 returnValue;创建期、derived 或 reaction capture 用途由声明决定。 */
|
|
54
|
+
export declare interface ComputationIR extends Located {
|
|
55
|
+
readonly type: ValueTypeIR;
|
|
56
|
+
readonly body: RegionIR;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 普通同步计算允许 void,但生成路径必须全部终结;纯与创建期计算仍须返回 Operand。 */
|
|
60
|
+
export declare type ComputeResult<Compute extends ValueOps, T extends RuntimeValue> = Compute extends RuntimeEffects ? Operand<T> | void : Operand<T>;
|
|
61
|
+
|
|
62
|
+
/** 记录接受目标类型的字段对象;bytes 输入会复制。sample 与 intent 不能伪造宿主常量。 */
|
|
63
|
+
export declare type Constant<T> = T extends IntentValue | SampleValue ? never : T extends BytesValue ? Uint8Array | readonly number[] : T extends RecordValue<string, infer F> ? Readonly<F> : T;
|
|
64
|
+
|
|
65
|
+
/** 常量保留内存 number 语义,包括 NaN、无穷大与负零;sample 和 intent 不由常量伪造。 */
|
|
66
|
+
export declare type ConstantIR = {
|
|
67
|
+
readonly kind: 'number';
|
|
68
|
+
readonly value: number;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: 'bool';
|
|
71
|
+
readonly value: boolean;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'string';
|
|
74
|
+
readonly value: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: 'none';
|
|
77
|
+
} | {
|
|
78
|
+
readonly kind: 'enum';
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly member: string;
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: 'record';
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly fields: readonly {
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly value: number | boolean;
|
|
87
|
+
}[];
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: 'bytes';
|
|
90
|
+
readonly value: readonly number[];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export declare interface ConstantOptions<T extends RuntimeValue> extends NamedOptions {
|
|
94
|
+
readonly type: Type<T>;
|
|
95
|
+
readonly value: NoInfer<CreationInput<T>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export declare interface ControlFlow<Self, Test extends ValueOps> extends SourceScope<Self> {
|
|
99
|
+
local<T extends RuntimeValue>(type: Type<T>, initial: NoInfer<Operand<T>>): Local<T>;
|
|
100
|
+
setLocal<T extends RuntimeValue>(local: Local<T>, value: NoInfer<Operand<T>>): void;
|
|
101
|
+
if(condition: Operand<boolean>, yes: (body: Self) => void, no?: (body: Self) => void): void;
|
|
102
|
+
match<T extends RuntimeValue>(value: Value<T>, arms: readonly NoInfer<MatchArm<T, Self>>[], otherwise?: (body: Self) => void): void;
|
|
103
|
+
/** 每轮重算条件;条件允许所在上下文合法的同步效果,但不能等待或跳转外层循环。 */
|
|
104
|
+
while(test: (body: Test) => ComputeResult<Test, boolean>, emit: (body: Self) => void): void;
|
|
105
|
+
loop(emit: (body: Self) => void): void;
|
|
106
|
+
break(): void;
|
|
107
|
+
continue(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export declare function createDeviceBuilder(options: NamedOptions): DeviceBuilder;
|
|
111
|
+
|
|
112
|
+
/** Runtime integration factory; only existing resources can be referenced by the returned view. */
|
|
113
|
+
export declare function createJitBlockBuilder(options?: JitBuilderOptions): JitBlockBuilder;
|
|
114
|
+
|
|
115
|
+
export declare interface CreationBody<T extends RuntimeValue> extends CreationStatements<CreationBody<T>> {
|
|
116
|
+
returnValue(value: Operand<T>): void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare interface CreationCompute extends CreationStatements<CreationCompute> {
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 构造回调产生创建期 IR,不是实例创建时执行的任意宿主 JS;正常路径须 returnValue。 */
|
|
123
|
+
export declare type CreationInput<T extends RuntimeValue> = Constant<T> | ((body: CreationBody<T>) => void);
|
|
124
|
+
|
|
125
|
+
export declare interface CreationStatements<Self> extends ValueOps, ControlFlow<Self, CreationCompute>, LazyOps<CreationCompute>, Assertions<CreationCompute> {
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 声明顺序用于稳定诊断与合同规定的初始化顺序;前向引用统一在完成阶段解析。 */
|
|
129
|
+
export declare type DeclarationIR = Located & ({
|
|
130
|
+
readonly kind: 'enum';
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly members: readonly string[];
|
|
133
|
+
} | {
|
|
134
|
+
readonly kind: 'record';
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly fields: readonly {
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly type: 'number' | 'bool';
|
|
139
|
+
}[];
|
|
140
|
+
} | {
|
|
141
|
+
readonly kind: 'property';
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly type: ValueTypeIR;
|
|
144
|
+
readonly default?: ComputationIR;
|
|
145
|
+
} | {
|
|
146
|
+
readonly kind: 'const';
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly type: ValueTypeIR;
|
|
149
|
+
readonly value: ComputationIR;
|
|
150
|
+
} | {
|
|
151
|
+
readonly kind: 'state';
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly type: ValueTypeIR;
|
|
154
|
+
readonly initial: ComputationIR;
|
|
155
|
+
} | {
|
|
156
|
+
readonly kind: 'derived';
|
|
157
|
+
readonly name: string;
|
|
158
|
+
readonly type: ValueTypeIR;
|
|
159
|
+
readonly value: ComputationIR;
|
|
160
|
+
} | ({
|
|
161
|
+
readonly kind: 'pin';
|
|
162
|
+
readonly name: string;
|
|
163
|
+
/** 创建期求值;省略为空意图,后续 writeIntent 完整替换。 */
|
|
164
|
+
readonly initial?: ComputationIR & {
|
|
165
|
+
readonly type: {
|
|
166
|
+
readonly kind: 'intent';
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
} & ({
|
|
170
|
+
readonly low?: never;
|
|
171
|
+
readonly high?: never;
|
|
172
|
+
} | {
|
|
173
|
+
readonly low: ComputationIR;
|
|
174
|
+
readonly high: ComputationIR;
|
|
175
|
+
})) | {
|
|
176
|
+
readonly kind: 'memory';
|
|
177
|
+
readonly name: string;
|
|
178
|
+
readonly public: boolean;
|
|
179
|
+
readonly length: ComputationIR;
|
|
180
|
+
} | {
|
|
181
|
+
readonly kind: 'channel';
|
|
182
|
+
readonly name: string;
|
|
183
|
+
readonly direction: 'input' | 'output';
|
|
184
|
+
readonly type: ValueTypeIR;
|
|
185
|
+
readonly capacity: ComputationIR;
|
|
186
|
+
readonly maxLength?: ComputationIR;
|
|
187
|
+
readonly overflow?: ComputationIR;
|
|
188
|
+
} | {
|
|
189
|
+
readonly kind: 'notification';
|
|
190
|
+
readonly name: string;
|
|
191
|
+
readonly direction: 'input' | 'output';
|
|
192
|
+
} | {
|
|
193
|
+
readonly kind: 'function';
|
|
194
|
+
readonly name: string;
|
|
195
|
+
readonly pure: boolean;
|
|
196
|
+
readonly params: readonly ParameterIR[];
|
|
197
|
+
readonly returns?: ValueTypeIR;
|
|
198
|
+
readonly body: RegionIR;
|
|
199
|
+
} | {
|
|
200
|
+
readonly kind: 'start';
|
|
201
|
+
readonly body: RegionIR;
|
|
202
|
+
} | {
|
|
203
|
+
readonly kind: 'reaction';
|
|
204
|
+
readonly name: string;
|
|
205
|
+
readonly sourcePath: readonly [string, ...string[]];
|
|
206
|
+
readonly sourceType: ComparableTypeIR;
|
|
207
|
+
readonly previous: string;
|
|
208
|
+
readonly current: string;
|
|
209
|
+
readonly captures: readonly ReactionCaptureIR[];
|
|
210
|
+
readonly body: RegionIR;
|
|
211
|
+
} | {
|
|
212
|
+
readonly kind: 'on';
|
|
213
|
+
readonly name: string;
|
|
214
|
+
readonly sourcePath: readonly string[];
|
|
215
|
+
readonly body: RegionIR;
|
|
216
|
+
} | {
|
|
217
|
+
readonly kind: 'assert';
|
|
218
|
+
readonly body: RegionIR;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
/** 静态声明可前向引用;回调结束即关闭其体 Builder,完成或失败后关闭整个定义 Builder。 */
|
|
222
|
+
export declare interface DeviceBuilder extends SourceScope<DeviceBuilder> {
|
|
223
|
+
enum<const N extends string, const M extends readonly [string, ...string[]]>(options: {
|
|
224
|
+
readonly name: N;
|
|
225
|
+
readonly members: M;
|
|
226
|
+
readonly source?: SourceInfo;
|
|
227
|
+
}): EnumType<N, M>;
|
|
228
|
+
record<const N extends string, const F extends RecordFields>(options: {
|
|
229
|
+
readonly name: N;
|
|
230
|
+
readonly fields: F;
|
|
231
|
+
readonly source?: SourceInfo;
|
|
232
|
+
}): RecordType<N, F>;
|
|
233
|
+
property<T extends RuntimeValue>(options: PropertyOptions<T>): void;
|
|
234
|
+
constant<T extends RuntimeValue>(options: ConstantOptions<T>): void;
|
|
235
|
+
state<T extends RuntimeValue>(options: InitialOptions<T>): void;
|
|
236
|
+
derived<T extends RuntimeValue>(options: NamedOptions & {
|
|
237
|
+
readonly type: Type<T>;
|
|
238
|
+
}, emit: (body: NoInfer<PureValueFunctionBody<T>>) => void): void;
|
|
239
|
+
pin(options: PinOptions): void;
|
|
240
|
+
memory(options: MemoryOptions): void;
|
|
241
|
+
channel<T extends RuntimeValue>(options: ChannelOptions<T>): void;
|
|
242
|
+
notification(options: NamedOptions & {
|
|
243
|
+
readonly direction: 'input' | 'output';
|
|
244
|
+
}): void;
|
|
245
|
+
fn<const P extends readonly Parameter[]>(options: FunctionOptions<P> & {
|
|
246
|
+
readonly returns?: never;
|
|
247
|
+
}, emit: (body: VoidFunctionBody, args: ParameterBindings<P>) => void): void;
|
|
248
|
+
fn<const P extends readonly Parameter[], T extends RuntimeValue>(options: FunctionOptions<P> & {
|
|
249
|
+
readonly returns: Type<T>;
|
|
250
|
+
}, emit: (body: ValueFunctionBody<T>, args: ParameterBindings<P>) => void): void;
|
|
251
|
+
pureFn<const P extends readonly Parameter[]>(options: FunctionOptions<P> & {
|
|
252
|
+
readonly returns?: never;
|
|
253
|
+
}, emit: (body: PureVoidFunctionBody, args: ParameterBindings<P>) => void): void;
|
|
254
|
+
pureFn<const P extends readonly Parameter[], T extends RuntimeValue>(options: FunctionOptions<P> & {
|
|
255
|
+
readonly returns: Type<T>;
|
|
256
|
+
}, emit: (body: PureValueFunctionBody<T>, args: ParameterBindings<P>) => void): void;
|
|
257
|
+
start(emit: (body: ProcessBody) => void): void;
|
|
258
|
+
on(options: NamedOptions & {
|
|
259
|
+
readonly sourcePath: readonly [string, ...string[]];
|
|
260
|
+
}, emit: (body: ProcessBody) => void): void;
|
|
261
|
+
/** capture 回调各自生成独立纯计算体;响应参数为生成的 IR 结果句柄。 */
|
|
262
|
+
reaction<T extends ComparableValue, const C extends readonly ReactionCapture[]>(options: ReactionOptions<T, C>, capture: NoInfer<ReactionCaptureEmitters<C>>, emit: (body: ReactionBody, bindings: NoInfer<ReactionBindings<T, C>>) => void): void;
|
|
263
|
+
assert(emit: (body: CreationCompute) => void): void;
|
|
264
|
+
finish(): DeviceIR;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export declare interface DeviceIR extends Located {
|
|
268
|
+
readonly kind: 'device';
|
|
269
|
+
readonly name: string;
|
|
270
|
+
readonly declarations: readonly DeclarationIR[];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** path 定位当前输入,source 定位原始来源;message 和相关说明使用英文。 */
|
|
274
|
+
export declare interface Diagnostic {
|
|
275
|
+
readonly code: DiagnosticCode;
|
|
276
|
+
readonly message: string;
|
|
277
|
+
readonly phase: DiagnosticPhase;
|
|
278
|
+
readonly path: InputPath;
|
|
279
|
+
readonly source?: SourceInfo;
|
|
280
|
+
readonly related: readonly RelatedDiagnostic[];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export declare type DiagnosticCode = 'IR_SCHEMA' | 'IR_TYPE' | 'IR_SCOPE' | 'IR_CONTROL_FLOW' | 'IR_EFFECT' | 'IR_REFERENCE' | 'IR_LIFECYCLE' | 'IR_DEPENDENCY' | 'IR_JIT_BOUNDARY';
|
|
284
|
+
|
|
285
|
+
export declare type DiagnosticPhase = 'construct' | 'finalize' | 'bind';
|
|
286
|
+
|
|
287
|
+
declare const enumTag: unique symbol;
|
|
288
|
+
|
|
289
|
+
export declare interface EnumType<N extends string, M extends readonly string[]> extends Type<EnumValue<N, M[number]>> {
|
|
290
|
+
readonly name: N;
|
|
291
|
+
readonly members: {
|
|
292
|
+
readonly [K in M[number]]: EnumValue<N, K>;
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export declare interface EnumValue<N extends string, M extends string = string> {
|
|
297
|
+
readonly [enumTag]: {
|
|
298
|
+
readonly name: N;
|
|
299
|
+
readonly member: M;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export declare type FieldShape = Readonly<Record<string, number | boolean>>;
|
|
304
|
+
|
|
305
|
+
export declare type FieldValues<F extends RecordFields> = {
|
|
306
|
+
readonly [K in keyof F]: Infer<F[K]>;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export declare interface FunctionOptions<P extends readonly Parameter[]> {
|
|
310
|
+
readonly name: string;
|
|
311
|
+
readonly params: P;
|
|
312
|
+
readonly source?: SourceInfo;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export declare type Infer<T> = T extends Type<infer V> ? V : never;
|
|
316
|
+
|
|
317
|
+
export declare interface InitialIntentBody extends InitialIntentStatements<InitialIntentBody> {
|
|
318
|
+
returnValue(value: Operand<IntentValue>): void;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export declare interface InitialIntentCompute extends InitialIntentStatements<InitialIntentCompute> {
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** pin.initial 专用能力;嵌套计算保持相同的创建期限制。 */
|
|
325
|
+
export declare interface InitialIntentStatements<Self> extends ValueOps, PinIntentOps, ControlFlow<Self, InitialIntentCompute>, LazyOps<InitialIntentCompute>, Assertions<InitialIntentCompute> {
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export declare interface InitialOptions<T extends RuntimeValue> extends NamedOptions {
|
|
329
|
+
readonly type: Type<T>;
|
|
330
|
+
readonly initial: NoInfer<CreationInput<T>>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export declare type InputPath = readonly (string | number)[];
|
|
334
|
+
|
|
335
|
+
export declare interface InstructionBoundary {
|
|
336
|
+
readonly pc: number;
|
|
337
|
+
readonly nextPc: number;
|
|
338
|
+
readonly source?: SourceInfo;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** pc / nextPc 是有限 number,不要求整数或递增;每条指令拥有独立局部编号空间。 */
|
|
342
|
+
export declare interface InstructionIR extends Located {
|
|
343
|
+
readonly pc: number;
|
|
344
|
+
readonly nextPc: number;
|
|
345
|
+
readonly body: RegionIR;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
declare const intentTag: unique symbol;
|
|
349
|
+
|
|
350
|
+
export declare interface IntentValue {
|
|
351
|
+
readonly [intentTag]: true;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** 仅由当前实例的翻译上下文提供,不能通过此视图新增资源或入口。 */
|
|
355
|
+
export declare interface JitBlockBuilder extends SourceScope<JitBlockBuilder> {
|
|
356
|
+
instruction(boundary: InstructionBoundary, emit: (body: JitInstructionBuilder) => void): void;
|
|
357
|
+
finish(): BlockIR;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
declare interface JitBuilderOptions {
|
|
361
|
+
readonly device?: DeviceIR;
|
|
362
|
+
readonly source?: SourceInfo;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export declare interface JitInstructionBuilder extends RuntimeStatements<JitInstructionBuilder, SyncCompute>, RedirectEffect {
|
|
366
|
+
/** 显式耗时阶段,执行到该处捕获动态时长,等待期间不随资源变化重新计算。 */
|
|
367
|
+
elapse(duration: Operand<number>): void;
|
|
368
|
+
/** 绑定无参 bool pure fn;仅指令及块的尾路径允许,循环内拒绝。 */
|
|
369
|
+
waitUntil(predicate: string): void;
|
|
370
|
+
/** 终结路径并停止当前注册;新板独立注册,不同于结束块构造的 finish。 */
|
|
371
|
+
stop(): void;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** 回调在构造期运行一次;生成的计算区域只在对应运行路径求值,不允许挂起。 */
|
|
375
|
+
export declare interface LazyOps<Compute extends ValueOps> {
|
|
376
|
+
and(left: Operand<boolean>, right: (body: Compute) => ComputeResult<Compute, boolean>): Value<boolean>;
|
|
377
|
+
or(left: Operand<boolean>, right: (body: Compute) => ComputeResult<Compute, boolean>): Value<boolean>;
|
|
378
|
+
select<T extends RuntimeValue>(type: Type<T>, condition: Operand<boolean>, yes: (body: Compute) => NoInfer<ComputeResult<Compute, T>>, no: (body: Compute) => NoInfer<ComputeResult<Compute, T>>): Value<T>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export declare type LoadKind = 'load8' | 'load16le' | 'load16be' | 'load32le' | 'load32be';
|
|
382
|
+
|
|
383
|
+
/** 可变局部槽显式读写;类型不变,且不得跨独立执行体或 JIT 指令使用。 */
|
|
384
|
+
export declare interface Local<T> {
|
|
385
|
+
readonly [localTag]: (value: T) => T;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** 与结果分开编号;编号相同不表示可以跨作用域共享局部槽。 */
|
|
389
|
+
export declare type LocalId = number;
|
|
390
|
+
|
|
391
|
+
declare const localTag: unique symbol;
|
|
392
|
+
|
|
393
|
+
export declare interface Located {
|
|
394
|
+
readonly source?: SourceInfo;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export declare interface MatchArm<T, Self> {
|
|
398
|
+
readonly pattern: MatchPattern<T>;
|
|
399
|
+
readonly emit: (body: Self) => void;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export declare interface MatchArmIR extends Located {
|
|
403
|
+
readonly pattern: MatchPatternIR;
|
|
404
|
+
readonly body: RegionIR;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export declare type MatchPattern<T> = T extends number | string | boolean | null | EnumValue<string> ? T : never;
|
|
408
|
+
|
|
409
|
+
export declare type MatchPatternIR = {
|
|
410
|
+
readonly kind: 'number';
|
|
411
|
+
readonly value: number;
|
|
412
|
+
} | {
|
|
413
|
+
readonly kind: 'string';
|
|
414
|
+
readonly value: string;
|
|
415
|
+
} | {
|
|
416
|
+
readonly kind: 'bool';
|
|
417
|
+
readonly value: boolean;
|
|
418
|
+
} | {
|
|
419
|
+
readonly kind: 'enum';
|
|
420
|
+
readonly name: string;
|
|
421
|
+
readonly member: string;
|
|
422
|
+
} | {
|
|
423
|
+
readonly kind: 'none';
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
export declare type MemoryInput = string | MemoryRef;
|
|
427
|
+
|
|
428
|
+
export declare interface MemoryOptions extends NamedOptions {
|
|
429
|
+
readonly public?: boolean;
|
|
430
|
+
readonly length: CreationInput<number>;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export declare interface MemoryParameterType {
|
|
434
|
+
readonly kind: 'memory';
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export declare interface MemoryRef {
|
|
438
|
+
readonly [refTag]: 'memory';
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export declare type MemoryRefIR = {
|
|
442
|
+
readonly kind: 'memory';
|
|
443
|
+
readonly name: string;
|
|
444
|
+
} | {
|
|
445
|
+
readonly kind: 'parameter';
|
|
446
|
+
readonly resource: 'memory';
|
|
447
|
+
readonly index: number;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
export declare interface NamedOptions {
|
|
451
|
+
readonly name: string;
|
|
452
|
+
readonly source?: SourceInfo;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export declare type NumericBuiltin = 'isNaN' | 'isFinite' | 'isInteger' | 'isSafeInteger' | 'abs' | 'floor' | 'ceil' | 'trunc' | 'round' | 'sqrt' | 'min' | 'max' | 'pow';
|
|
456
|
+
|
|
457
|
+
export declare type Operand<T> = Value<T> | Constant<T>;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* 普通值输入全部为 ResultId,资源与局部槽使用各自字段。
|
|
461
|
+
* 结果 type 和 call.pure 都是待核对信息,不能替代对实际节点及调用图的检查。
|
|
462
|
+
* wait / elapse / redirect 的时间值均在执行到操作时读取,单位为整数皮秒。
|
|
463
|
+
*/
|
|
464
|
+
export declare type OperationIR = Located & ((ResultIR & {
|
|
465
|
+
readonly kind: 'constant';
|
|
466
|
+
readonly constant: ConstantIR;
|
|
467
|
+
}) | (ResultIR & {
|
|
468
|
+
readonly kind: 'read';
|
|
469
|
+
readonly resource: 'property' | 'const' | 'state' | 'derived';
|
|
470
|
+
readonly name: string;
|
|
471
|
+
}) | (ResultIR & {
|
|
472
|
+
readonly kind: 'parameter';
|
|
473
|
+
readonly index: number;
|
|
474
|
+
}) | (ResultIR & {
|
|
475
|
+
readonly kind: 'reactionValue';
|
|
476
|
+
readonly binding: 'previous' | 'current';
|
|
477
|
+
}) | (ResultIR & {
|
|
478
|
+
readonly kind: 'reactionCapture';
|
|
479
|
+
readonly index: number;
|
|
480
|
+
}) | (ResultIR & {
|
|
481
|
+
readonly kind: 'unary';
|
|
482
|
+
readonly operator: UnaryOperator;
|
|
483
|
+
readonly value: ResultId;
|
|
484
|
+
}) | (ResultIR & {
|
|
485
|
+
readonly kind: 'binary';
|
|
486
|
+
readonly operator: BinaryOperator;
|
|
487
|
+
readonly left: ResultId;
|
|
488
|
+
readonly right: ResultId;
|
|
489
|
+
}) | (ResultIR & {
|
|
490
|
+
readonly kind: 'numeric';
|
|
491
|
+
readonly builtin: NumericBuiltin;
|
|
492
|
+
readonly args: readonly ResultId[];
|
|
493
|
+
}) | (ResultIR & {
|
|
494
|
+
readonly kind: 'record';
|
|
495
|
+
readonly fields: readonly {
|
|
496
|
+
readonly name: string;
|
|
497
|
+
readonly value: ResultId;
|
|
498
|
+
}[];
|
|
499
|
+
}) | (ResultIR & {
|
|
500
|
+
readonly kind: 'field';
|
|
501
|
+
readonly value: ResultId;
|
|
502
|
+
readonly field: string;
|
|
503
|
+
}) | (ResultIR & {
|
|
504
|
+
readonly kind: 'bytes';
|
|
505
|
+
readonly elements: readonly ResultId[];
|
|
506
|
+
}) | (ResultIR & {
|
|
507
|
+
readonly kind: 'length';
|
|
508
|
+
readonly value: ResultId;
|
|
509
|
+
}) | (ResultIR & {
|
|
510
|
+
readonly kind: 'index';
|
|
511
|
+
readonly value: ResultId;
|
|
512
|
+
readonly index: ResultId;
|
|
513
|
+
}) | (ResultIR & {
|
|
514
|
+
readonly kind: 'optional';
|
|
515
|
+
readonly value: ResultId;
|
|
516
|
+
}) | (ResultIR & {
|
|
517
|
+
readonly kind: 'isNone';
|
|
518
|
+
readonly value: ResultId;
|
|
519
|
+
}) | (ResultIR & {
|
|
520
|
+
readonly kind: 'nonNull';
|
|
521
|
+
readonly value: ResultId;
|
|
522
|
+
}) | (ResultIR & {
|
|
523
|
+
readonly kind: 'localRead';
|
|
524
|
+
readonly local: LocalId;
|
|
525
|
+
})
|
|
526
|
+
/** 声明执行时初始化;localRead 捕获一次值,localWrite 不会刷新已保存的旧结果。 */
|
|
527
|
+
| {
|
|
528
|
+
readonly kind: 'local';
|
|
529
|
+
readonly local: LocalId;
|
|
530
|
+
readonly type: ValueTypeIR;
|
|
531
|
+
readonly initial: ResultId;
|
|
532
|
+
} | {
|
|
533
|
+
readonly kind: 'localWrite';
|
|
534
|
+
readonly local: LocalId;
|
|
535
|
+
readonly value: ResultId;
|
|
536
|
+
}
|
|
537
|
+
/** 执行处立即更新状态,后续 read 可见;不改变先前已捕获的结果。 */
|
|
538
|
+
| {
|
|
539
|
+
readonly kind: 'write';
|
|
540
|
+
readonly resource: 'state';
|
|
541
|
+
readonly name: string;
|
|
542
|
+
readonly value: ResultId;
|
|
543
|
+
} | (ResultIR & {
|
|
544
|
+
readonly kind: 'memoryLength';
|
|
545
|
+
readonly memory: MemoryRefIR;
|
|
546
|
+
}) | (ResultIR & {
|
|
547
|
+
readonly kind: LoadKind;
|
|
548
|
+
readonly memory: MemoryRefIR;
|
|
549
|
+
readonly offset: ResultId;
|
|
550
|
+
}) | {
|
|
551
|
+
readonly kind: StoreKind;
|
|
552
|
+
readonly memory: MemoryRefIR;
|
|
553
|
+
readonly offset: ResultId;
|
|
554
|
+
readonly value: ResultId;
|
|
555
|
+
} | (ResultIR & {
|
|
556
|
+
readonly kind: 'copyBytes';
|
|
557
|
+
readonly memory: MemoryRefIR;
|
|
558
|
+
readonly offset: ResultId;
|
|
559
|
+
readonly length: ResultId;
|
|
560
|
+
}) | (ResultIR & {
|
|
561
|
+
readonly kind: 'readSample';
|
|
562
|
+
readonly pin: PinRefIR;
|
|
563
|
+
}) | (ResultIR & {
|
|
564
|
+
readonly kind: 'resistor';
|
|
565
|
+
readonly to: TargetRefIR;
|
|
566
|
+
readonly resistance: ResultId;
|
|
567
|
+
}) | (ResultIR & {
|
|
568
|
+
readonly kind: 'combineIntents';
|
|
569
|
+
readonly values: readonly ResultId[];
|
|
570
|
+
}) | (ResultIR & {
|
|
571
|
+
readonly kind: 'refEqual';
|
|
572
|
+
readonly left: PinRefIR | MemoryRefIR;
|
|
573
|
+
readonly right: PinRefIR | MemoryRefIR;
|
|
574
|
+
}) | {
|
|
575
|
+
readonly kind: 'writeIntent';
|
|
576
|
+
readonly pin: PinRefIR;
|
|
577
|
+
readonly value: ResultId;
|
|
578
|
+
}
|
|
579
|
+
/** args 按形参顺序引用已求得结果;值的求值顺序由前序操作决定,pure 要核对实际目标。 */
|
|
580
|
+
| {
|
|
581
|
+
readonly kind: 'call';
|
|
582
|
+
readonly name: string;
|
|
583
|
+
readonly pure: boolean;
|
|
584
|
+
readonly args: readonly ArgumentIR[];
|
|
585
|
+
} | (ResultIR & {
|
|
586
|
+
readonly kind: 'callValue';
|
|
587
|
+
readonly name: string;
|
|
588
|
+
readonly pure: boolean;
|
|
589
|
+
readonly args: readonly ArgumentIR[];
|
|
590
|
+
}) | {
|
|
591
|
+
readonly kind: 'send';
|
|
592
|
+
readonly channel: string;
|
|
593
|
+
readonly value: ResultId;
|
|
594
|
+
} | {
|
|
595
|
+
readonly kind: 'notify';
|
|
596
|
+
readonly notification: string;
|
|
597
|
+
} | (ResultIR & {
|
|
598
|
+
readonly kind: 'receive';
|
|
599
|
+
readonly channel: string;
|
|
600
|
+
}) | (ResultIR & {
|
|
601
|
+
readonly kind: 'now' | 'random';
|
|
602
|
+
}) | {
|
|
603
|
+
readonly kind: 'if';
|
|
604
|
+
readonly condition: ResultId;
|
|
605
|
+
readonly yes: RegionIR;
|
|
606
|
+
readonly no?: RegionIR;
|
|
607
|
+
} | {
|
|
608
|
+
readonly kind: 'match';
|
|
609
|
+
readonly value: ResultId;
|
|
610
|
+
readonly arms: readonly MatchArmIR[];
|
|
611
|
+
readonly otherwise?: RegionIR;
|
|
612
|
+
}
|
|
613
|
+
/** 条件每轮重算,允许当前上下文合法同步效果;continue 回到 test,条件不能挂起。 */
|
|
614
|
+
| {
|
|
615
|
+
readonly kind: 'while';
|
|
616
|
+
readonly test: ValueRegionIR;
|
|
617
|
+
readonly body: RegionIR;
|
|
618
|
+
} | {
|
|
619
|
+
readonly kind: 'loop';
|
|
620
|
+
readonly body: RegionIR;
|
|
621
|
+
} | (ResultIR & {
|
|
622
|
+
readonly kind: 'and' | 'or';
|
|
623
|
+
readonly left: ResultId;
|
|
624
|
+
readonly right: ValueRegionIR;
|
|
625
|
+
}) | (ResultIR & {
|
|
626
|
+
readonly kind: 'select';
|
|
627
|
+
readonly condition: ResultId;
|
|
628
|
+
readonly yes: ValueRegionIR;
|
|
629
|
+
readonly no: ValueRegionIR;
|
|
630
|
+
}) | {
|
|
631
|
+
readonly kind: 'assert';
|
|
632
|
+
readonly condition: ResultId;
|
|
633
|
+
readonly message?: ValueRegionIR;
|
|
634
|
+
} | {
|
|
635
|
+
readonly kind: 'wait' | 'elapse';
|
|
636
|
+
readonly duration: ResultId;
|
|
637
|
+
}
|
|
638
|
+
/** 只在末条 JIT 指令尾路径出现;if / match 外层无后缀,循环或计算区域内拒绝。 */
|
|
639
|
+
| {
|
|
640
|
+
readonly kind: 'waitUntil';
|
|
641
|
+
readonly predicate: string;
|
|
642
|
+
} | {
|
|
643
|
+
readonly kind: 'redirect';
|
|
644
|
+
readonly target: ResultId;
|
|
645
|
+
readonly delay: ResultId;
|
|
646
|
+
} | {
|
|
647
|
+
readonly kind: 'return' | 'break' | 'continue' | 'stop';
|
|
648
|
+
} | {
|
|
649
|
+
readonly kind: 'returnValue' | 'yield';
|
|
650
|
+
readonly value: ResultId;
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
export declare interface Parameter {
|
|
654
|
+
readonly name: string;
|
|
655
|
+
readonly type: ParameterType;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** 数组顺序决定调用位置,回调按参数名取得句柄;重名、遮蔽及归属另由完成检查验证。 */
|
|
659
|
+
export declare type ParameterBindings<P extends readonly Parameter[]> = {
|
|
660
|
+
readonly [K in P[number] as K['name']]: K['type'] extends Type<infer V> ? Value<V> : K['type'] extends PinParameterType ? PinRef : MemoryRef;
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
export declare interface ParameterIR extends Located {
|
|
664
|
+
readonly name: string;
|
|
665
|
+
readonly type: ParameterTypeIR;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export declare type ParameterType = Type<RuntimeValue> | PinParameterType | MemoryParameterType;
|
|
669
|
+
|
|
670
|
+
export declare type ParameterTypeIR = ValueTypeIR | {
|
|
671
|
+
readonly kind: 'pin' | 'memory';
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
export declare type PinInput = string | PinRef;
|
|
675
|
+
|
|
676
|
+
/** 引用按名称延迟解析,允许指向同一定义中后声明的 pin。 */
|
|
677
|
+
export declare interface PinIntentOps {
|
|
678
|
+
pin(name: string): PinRef;
|
|
679
|
+
/** 生成引脚间电阻构造;执行时校验闭区间 [0.001, 1e9] Ω。 */
|
|
680
|
+
resistor(to: TargetInput, resistance: Operand<number>): Value<IntentValue>;
|
|
681
|
+
combineIntents(...values: Operand<IntentValue>[]): Value<IntentValue>;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
export declare type PinOptions = NamedOptions & {
|
|
685
|
+
readonly initial?: (body: InitialIntentBody) => void;
|
|
686
|
+
} & ({
|
|
687
|
+
readonly low?: never;
|
|
688
|
+
readonly high?: never;
|
|
689
|
+
} | {
|
|
690
|
+
readonly low: CreationInput<number>;
|
|
691
|
+
readonly high: CreationInput<number>;
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
export declare interface PinParameterType {
|
|
695
|
+
readonly kind: 'pin';
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** 引用仅标识本实例资源,不是普通值;不能保存到 Local、记录或作为返回值。 */
|
|
699
|
+
export declare interface PinRef {
|
|
700
|
+
readonly [refTag]: 'pin';
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** parameter.index 指向当前函数参数表,必须核对资源类别;不会产生资源别名值。 */
|
|
704
|
+
export declare type PinRefIR = {
|
|
705
|
+
readonly kind: 'pin';
|
|
706
|
+
readonly name: string;
|
|
707
|
+
} | {
|
|
708
|
+
readonly kind: 'parameter';
|
|
709
|
+
readonly resource: 'pin';
|
|
710
|
+
readonly index: number;
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
export declare type PlainTypeIR = ComparablePlainTypeIR | {
|
|
714
|
+
readonly kind: 'intent';
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/** 共享 IR 的内存合同;可解析的结构仍须经过类型、作用域、效果与绑定检查。 */
|
|
718
|
+
/** 行列从 1 开始,列按 UTF-16 代码单元计数。 */
|
|
719
|
+
export declare interface Position {
|
|
720
|
+
readonly line: number;
|
|
721
|
+
readonly column: number;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
export declare interface ProcessBody extends RuntimeStatements<ProcessBody, ProcessCompute> {
|
|
725
|
+
/** 在执行处捕获时长并按整数皮秒校验;实际挂起才结束当前同步片段。 */
|
|
726
|
+
wait(duration: Operand<number>): void;
|
|
727
|
+
/** 只绑定 input channel;非空立即完成,空队列才挂起。 */
|
|
728
|
+
receive<T extends RuntimeValue>(channel: string, type: Type<T>): Value<T>;
|
|
729
|
+
return(): void;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
export declare interface ProcessCompute extends RuntimeStatements<ProcessCompute, ProcessCompute> {
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export declare interface PropertyOptions<T extends RuntimeValue> extends NamedOptions {
|
|
736
|
+
readonly type: Type<T>;
|
|
737
|
+
readonly default?: NoInfer<CreationInput<T>>;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export declare interface PureCompute extends PureStatements<PureCompute> {
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export declare interface PureStatements<Self> extends ReadOps, ControlFlow<Self, PureCompute>, LazyOps<PureCompute>, Assertions<PureCompute> {
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export declare interface PureValueFunctionBody<T extends RuntimeValue> extends PureStatements<PureValueFunctionBody<T>> {
|
|
747
|
+
returnValue(value: Operand<T>): void;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
export declare interface PureVoidFunctionBody extends PureStatements<PureVoidFunctionBody> {
|
|
751
|
+
return(): void;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export declare interface ReactionBindings<T extends ComparableValue, C extends readonly ReactionCapture[]> {
|
|
755
|
+
readonly previous: Value<T>;
|
|
756
|
+
readonly current: Value<T>;
|
|
757
|
+
readonly captures: {
|
|
758
|
+
readonly [P in C[number] as P['name']]: Value<Infer<P['type']>>;
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** 同步响应体可产生普通效果;不提供等待、接收或控制转向。 */
|
|
763
|
+
export declare interface ReactionBody extends RuntimeStatements<ReactionBody, ReactionCompute> {
|
|
764
|
+
return(): void;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export declare interface ReactionCapture {
|
|
768
|
+
readonly name: string;
|
|
769
|
+
readonly type: Type<ComparableValue>;
|
|
770
|
+
readonly source?: SourceInfo;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export declare interface ReactionCaptureBody<T extends ComparableValue> extends PureStatements<ReactionCaptureBody<T>> {
|
|
774
|
+
returnValue(value: Operand<T>): void;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
export declare type ReactionCaptureEmitters<C extends readonly ReactionCapture[]> = {
|
|
778
|
+
readonly [P in C[number] as P['name']]: (body: ReactionCaptureBody<Infer<P['type']>>) => void;
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
/** 每个 capture 是独立纯计算体;只在响应体内按声明索引读取其结果。 */
|
|
782
|
+
export declare interface ReactionCaptureIR extends Located {
|
|
783
|
+
readonly name: string;
|
|
784
|
+
readonly value: ComputationIR & {
|
|
785
|
+
readonly type: ComparableTypeIR;
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
export declare interface ReactionCompute extends RuntimeStatements<ReactionCompute, ReactionCompute> {
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export declare interface ReactionOptions<T extends ComparableValue, C extends readonly ReactionCapture[]> extends NamedOptions {
|
|
793
|
+
readonly sourcePath: readonly [string, ...string[]];
|
|
794
|
+
readonly sourceType: Type<T>;
|
|
795
|
+
readonly previous: string;
|
|
796
|
+
readonly current: string;
|
|
797
|
+
readonly captures: C;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
export declare interface ReadOps extends ValueOps, PinIntentOps {
|
|
801
|
+
/** 捕获执行处的当前状态值;此前的 writeState 已即时生效。 */
|
|
802
|
+
readState<T extends RuntimeValue>(name: string, type: Type<T>): Value<T>;
|
|
803
|
+
readDerived<T extends RuntimeValue>(name: string, type: Type<T>): Value<T>;
|
|
804
|
+
memory(name: string): MemoryRef;
|
|
805
|
+
memoryLength(memory: MemoryInput): Value<number>;
|
|
806
|
+
load8(memory: MemoryInput, offset: Operand<number>): Value<number>;
|
|
807
|
+
load16le(memory: MemoryInput, offset: Operand<number>): Value<number>;
|
|
808
|
+
load16be(memory: MemoryInput, offset: Operand<number>): Value<number>;
|
|
809
|
+
load32le(memory: MemoryInput, offset: Operand<number>): Value<number>;
|
|
810
|
+
load32be(memory: MemoryInput, offset: Operand<number>): Value<number>;
|
|
811
|
+
copyBytes(memory: MemoryInput, offset: Operand<number>, length: Operand<number>): Value<BytesValue>;
|
|
812
|
+
readSample(pin: PinInput): Value<SampleValue>;
|
|
813
|
+
refEqual(left: PinRef, right: PinRef): Value<boolean>;
|
|
814
|
+
refEqual(left: MemoryRef, right: MemoryRef): Value<boolean>;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
export declare type RecordFields = Readonly<Record<string, Type<number> | Type<boolean>>>;
|
|
818
|
+
|
|
819
|
+
declare const recordTag: unique symbol;
|
|
820
|
+
|
|
821
|
+
export declare interface RecordType<N extends string, F extends RecordFields> extends Type<RecordValue<N, FieldValues<F>>> {
|
|
822
|
+
readonly name: N;
|
|
823
|
+
readonly fields: F;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
export declare type RecordValue<N extends string, F extends FieldShape> = Readonly<F> & {
|
|
827
|
+
readonly [recordTag]: {
|
|
828
|
+
readonly name: N;
|
|
829
|
+
readonly fields: F;
|
|
830
|
+
};
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
export declare interface RedirectEffect {
|
|
834
|
+
/** 终结当前路径并跨辅助调用层转向;delay 默认零,单位皮秒,目标须为有限数值。 */
|
|
835
|
+
redirect(target: Operand<number>, delay?: Operand<number>): void;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
declare const refTag: unique symbol;
|
|
839
|
+
|
|
840
|
+
/** 操作数组的顺序就是执行顺序;子区域不能向外泄露其临时结果编号。 */
|
|
841
|
+
export declare interface RegionIR extends Located {
|
|
842
|
+
readonly operations: readonly OperationIR[];
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
export declare interface RelatedDiagnostic {
|
|
846
|
+
readonly message: string;
|
|
847
|
+
readonly path: InputPath;
|
|
848
|
+
readonly source?: SourceInfo;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/** 非负安全整数;在独立执行体或单条 JIT 指令内唯一,不是实例资源编号。 */
|
|
852
|
+
export declare type ResultId = number;
|
|
853
|
+
|
|
854
|
+
export declare interface ResultIR {
|
|
855
|
+
readonly result: ResultId;
|
|
856
|
+
readonly type: ValueTypeIR;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/** 字符串目标无法静态推断声明类型;绑定时核对实际资源、消息负载与调用签名。 */
|
|
860
|
+
export declare interface RuntimeEffects {
|
|
861
|
+
/** 执行处立即更新状态,不等待同步片段结束或延迟提交。 */
|
|
862
|
+
writeState<T extends RuntimeValue>(name: string, value: Operand<T>): void;
|
|
863
|
+
store8(memory: MemoryInput, offset: Operand<number>, value: Operand<number>): void;
|
|
864
|
+
store16le(memory: MemoryInput, offset: Operand<number>, value: Operand<number>): void;
|
|
865
|
+
store16be(memory: MemoryInput, offset: Operand<number>, value: Operand<number>): void;
|
|
866
|
+
store32le(memory: MemoryInput, offset: Operand<number>, value: Operand<number>): void;
|
|
867
|
+
store32be(memory: MemoryInput, offset: Operand<number>, value: Operand<number>): void;
|
|
868
|
+
writeIntent(pin: PinInput, value: Operand<IntentValue>): void;
|
|
869
|
+
call(name: string, ...args: Argument[]): void;
|
|
870
|
+
callValue<T extends RuntimeValue>(name: string, result: Type<T>, ...args: Argument[]): Value<T>;
|
|
871
|
+
send<T extends RuntimeValue>(channel: string, value: Operand<T>): void;
|
|
872
|
+
notify(notification: string): void;
|
|
873
|
+
/** 执行处读取板级整数皮秒,不推进时间;不能跨挂起复用旧读取。 */
|
|
874
|
+
now(): Value<number>;
|
|
875
|
+
/** 消耗本实例随机序列;不能消除、提前执行或重排调用。 */
|
|
876
|
+
random(): Value<number>;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export declare interface RuntimeStatements<Self, Compute extends ValueOps> extends ReadOps, ControlFlow<Self, Compute>, LazyOps<Compute>, Assertions<Compute>, RuntimeEffects {
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export declare type RuntimeValue = number | boolean | string | null | EnumValue<string> | RecordValue<string, FieldShape> | BytesValue | IntentValue | SampleValue;
|
|
883
|
+
|
|
884
|
+
/** 电气合同规定的完整采样状态集合。 */
|
|
885
|
+
export declare type SampleStatusMember = 'valid' | 'floating';
|
|
886
|
+
|
|
887
|
+
declare const sampleTag: unique symbol;
|
|
888
|
+
|
|
889
|
+
export declare interface SampleValue {
|
|
890
|
+
readonly [sampleTag]: true;
|
|
891
|
+
readonly voltage: number | null;
|
|
892
|
+
readonly level: EnumValue<'Logic', 'low' | 'high' | 'unknown'>;
|
|
893
|
+
readonly status: EnumValue<'SampleStatus', SampleStatusMember>;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** 无源文件的生成代码可只提供标签;有源码位置时 URI 与范围必须同时存在。 */
|
|
897
|
+
export declare type SourceInfo = {
|
|
898
|
+
readonly uri: string;
|
|
899
|
+
readonly range: SourceRange;
|
|
900
|
+
readonly label?: string;
|
|
901
|
+
} | {
|
|
902
|
+
readonly label: string;
|
|
903
|
+
readonly uri?: never;
|
|
904
|
+
readonly range?: never;
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
/** 左闭右开范围;结束位置不得早于开始位置。 */
|
|
908
|
+
export declare interface SourceRange {
|
|
909
|
+
readonly start: Position;
|
|
910
|
+
readonly end: Position;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/** 仅设置默认来源,不新增 IR 操作或局部作用域;退出后恢复外层来源。 */
|
|
914
|
+
export declare interface SourceScope<Self> {
|
|
915
|
+
withSource(source: SourceInfo, emit: (body: Self) => void): void;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
export declare type StoreKind = 'store8' | 'store16le' | 'store16be' | 'store32le' | 'store32be';
|
|
919
|
+
|
|
920
|
+
export declare interface SyncCompute extends RuntimeStatements<SyncCompute, SyncCompute>, RedirectEffect {
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export declare type TargetInput = PinInput;
|
|
924
|
+
|
|
925
|
+
export declare type TargetRefIR = PinRefIR;
|
|
926
|
+
|
|
927
|
+
/** 类型描述辅助 TS 推导;具名身份、定义归属及适用位置仍须由 IR 校验。 */
|
|
928
|
+
export declare interface Type<T> {
|
|
929
|
+
readonly [typeTag]: T;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
export declare interface TypeFactory {
|
|
933
|
+
readonly number: Type<number>;
|
|
934
|
+
readonly bool: Type<boolean>;
|
|
935
|
+
readonly string: Type<string>;
|
|
936
|
+
readonly bytes: Type<BytesValue>;
|
|
937
|
+
readonly intent: Type<IntentValue>;
|
|
938
|
+
readonly sample: Type<SampleValue>;
|
|
939
|
+
readonly pin: PinParameterType;
|
|
940
|
+
readonly memory: MemoryParameterType;
|
|
941
|
+
readonly logic: EnumType<'Logic', readonly ['low', 'high', 'unknown']>;
|
|
942
|
+
/** 浮空为正常采样状态;数值求解失败通过板级故障报告。 */
|
|
943
|
+
readonly sampleStatus: EnumType<'SampleStatus', readonly ['valid', 'floating']>;
|
|
944
|
+
readonly overflow: EnumType<'Overflow', readonly ['drop_new', 'drop_oldest', 'error']>;
|
|
945
|
+
/** 单层可空;null 常量必须有此类目标类型,不能独立推断具名类型。 */
|
|
946
|
+
optional<T extends Exclude<RuntimeValue, null>>(type: Type<T>): Type<T | null>;
|
|
947
|
+
/** 前向引用携带预期结构,完成时核对实际声明及定义归属。 */
|
|
948
|
+
namedEnum<const N extends string, const M extends readonly [string, ...string[]]>(name: N, members: M): EnumType<N, M>;
|
|
949
|
+
namedRecord<const N extends string, const F extends RecordFields>(name: N, fields: F): RecordType<N, F>;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
export declare const types: TypeFactory;
|
|
953
|
+
|
|
954
|
+
declare const typeTag: unique symbol;
|
|
955
|
+
|
|
956
|
+
export declare type UnaryOperator = 'positive' | 'negate' | 'not' | 'bitNot';
|
|
957
|
+
|
|
958
|
+
export declare function validateBlockIR(input: unknown): BlockIR;
|
|
959
|
+
|
|
960
|
+
/** Adds instance-definition reference and function-signature checks to a structurally valid block. */
|
|
961
|
+
export declare function validateBoundBlockIR(input: unknown, device: DeviceIR): BlockIR;
|
|
962
|
+
|
|
963
|
+
export declare function validateDeviceIR(input: unknown): DeviceIR;
|
|
964
|
+
|
|
965
|
+
/** 一次执行结果的句柄,而非以后每次使用都会重新求值的表达式。 */
|
|
966
|
+
export declare interface Value<T> {
|
|
967
|
+
readonly [valueTag]: T;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
export declare interface ValueFunctionBody<T extends RuntimeValue> extends RuntimeStatements<ValueFunctionBody<T>, SyncCompute>, RedirectEffect {
|
|
971
|
+
returnValue(value: Operand<T>): void;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/** 所有操作按生成位置执行;普通数值运算保留语言规范的 binary64 和 32 位位运算语义。 */
|
|
975
|
+
export declare interface ValueOps {
|
|
976
|
+
constant<T extends RuntimeValue>(type: Type<T>, value: NoInfer<Constant<T>>): Value<T>;
|
|
977
|
+
readProperty<T extends RuntimeValue>(name: string, type: Type<T>): Value<T>;
|
|
978
|
+
readConst<T extends RuntimeValue>(name: string, type: Type<T>): Value<T>;
|
|
979
|
+
getLocal<T extends RuntimeValue>(local: Local<T>): Value<T>;
|
|
980
|
+
positive(value: Operand<number>): Value<number>;
|
|
981
|
+
negate(value: Operand<number>): Value<number>;
|
|
982
|
+
not(value: Operand<boolean>): Value<boolean>;
|
|
983
|
+
bitNot(value: Operand<number>): Value<number>;
|
|
984
|
+
add(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
985
|
+
subtract(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
986
|
+
multiply(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
987
|
+
divide(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
988
|
+
remainder(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
989
|
+
power(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
990
|
+
lessThan(left: Operand<number>, right: Operand<number>): Value<boolean>;
|
|
991
|
+
lessThanOrEqual(left: Operand<number>, right: Operand<number>): Value<boolean>;
|
|
992
|
+
greaterThan(left: Operand<number>, right: Operand<number>): Value<boolean>;
|
|
993
|
+
greaterThanOrEqual(left: Operand<number>, right: Operand<number>): Value<boolean>;
|
|
994
|
+
/** 按目标类型比较,intent 拒绝内容相等;具名记录、枚举及可空值另做语义校验。 */
|
|
995
|
+
equal<T extends RuntimeValue>(type: Type<T>, left: NoInfer<Operand<T>>, right: NoInfer<Operand<T>>): Value<boolean>;
|
|
996
|
+
notEqual<T extends RuntimeValue>(type: Type<T>, left: NoInfer<Operand<T>>, right: NoInfer<Operand<T>>): Value<boolean>;
|
|
997
|
+
concat(left: Operand<string>, right: Operand<string>): Value<string>;
|
|
998
|
+
bitAnd(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
999
|
+
bitOr(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1000
|
+
bitXor(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1001
|
+
shiftLeft(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1002
|
+
shiftRight(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1003
|
+
shiftRightUnsigned(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1004
|
+
isNaN(value: Operand<number>): Value<boolean>;
|
|
1005
|
+
isFinite(value: Operand<number>): Value<boolean>;
|
|
1006
|
+
isInteger(value: Operand<number>): Value<boolean>;
|
|
1007
|
+
isSafeInteger(value: Operand<number>): Value<boolean>;
|
|
1008
|
+
abs(value: Operand<number>): Value<number>;
|
|
1009
|
+
floor(value: Operand<number>): Value<number>;
|
|
1010
|
+
ceil(value: Operand<number>): Value<number>;
|
|
1011
|
+
trunc(value: Operand<number>): Value<number>;
|
|
1012
|
+
round(value: Operand<number>): Value<number>;
|
|
1013
|
+
sqrt(value: Operand<number>): Value<number>;
|
|
1014
|
+
min(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1015
|
+
max(left: Operand<number>, right: Operand<number>): Value<number>;
|
|
1016
|
+
pow(base: Operand<number>, exponent: Operand<number>): Value<number>;
|
|
1017
|
+
record<const N extends string, const F extends RecordFields>(type: RecordType<N, F>, fields: {
|
|
1018
|
+
readonly [K in keyof F]: Operand<Infer<F[K]>>;
|
|
1019
|
+
}): Value<RecordValue<N, FieldValues<F>>>;
|
|
1020
|
+
field<T extends SampleValue | RecordValue<string, FieldShape>, K extends Exclude<keyof T, symbol>>(value: Value<T>, field: K): Value<T[K]>;
|
|
1021
|
+
bytes(...elements: Operand<number>[]): Value<BytesValue>;
|
|
1022
|
+
length(value: Value<string | BytesValue>): Value<number>;
|
|
1023
|
+
index(value: Value<string>, index: Operand<number>): Value<string>;
|
|
1024
|
+
index(value: Value<BytesValue>, index: Operand<number>): Value<number>;
|
|
1025
|
+
optional<T extends Exclude<RuntimeValue, null>>(value: Value<T>): Value<T | null>;
|
|
1026
|
+
isNone<T extends RuntimeValue>(value: Value<T | null>): Value<boolean>;
|
|
1027
|
+
/** 仅接受当前路径已证明非空的值;无证明时拒绝构造,不插入强制解包检查。 */
|
|
1028
|
+
nonNull<T extends Exclude<RuntimeValue, null>>(value: Value<T | null>): Value<T>;
|
|
1029
|
+
/** 目标必须显式声明 pure fn;创建期还要验证调用链不读取运行资源。 */
|
|
1030
|
+
callPure(name: string, ...args: Argument[]): void;
|
|
1031
|
+
callPureValue<T extends RuntimeValue>(name: string, result: Type<T>, ...args: Argument[]): Value<T>;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/** 每条正常结束路径以 yield 交付结果;yield 不结束外层函数,也不让出调度。 */
|
|
1035
|
+
export declare interface ValueRegionIR {
|
|
1036
|
+
readonly type: ValueTypeIR;
|
|
1037
|
+
readonly body: RegionIR;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
declare const valueTag: unique symbol;
|
|
1041
|
+
|
|
1042
|
+
/** 可空只嵌套一层;具体声明位置还须遵守 DDL 的类型适用范围。 */
|
|
1043
|
+
export declare type ValueTypeIR = PlainTypeIR | {
|
|
1044
|
+
readonly kind: 'optional';
|
|
1045
|
+
readonly inner: PlainTypeIR;
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
/** 无值函数仅提供 return,有值函数仅提供 returnValue;JS 自身 return 不生成该操作。 */
|
|
1049
|
+
export declare interface VoidFunctionBody extends RuntimeStatements<VoidFunctionBody, SyncCompute>, RedirectEffect {
|
|
1050
|
+
return(): void;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export { }
|