@u84u/gl 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1723 @@
1
+ import { S as SourceResolver } from './resolver-Fn4_IKEu.js';
2
+ export { M as MemorySourceResolver, a as SourceModule } from './resolver-Fn4_IKEu.js';
3
+
4
+ type TokenKind = "Fn" | "Struct" | "Return" | "If" | "Else" | "True" | "False" | "Let" | "Mut" | "Binding" | "Uniform" | "Import" | "Ident" | "Int" | "Float" | "String" | "Char" | "Color" | "LParen" | "RParen" | "LBrace" | "RBrace" | "LBracket" | "RBracket" | "Comma" | "Dot" | "Colon" | "Semicolon" | "Question" | "Assign" | "PlusEq" | "MinusEq" | "StarEq" | "SlashEq" | "PercentEq" | "AmpEq" | "PipeEq" | "CaretEq" | "LtLtEq" | "GtGtEq" | "Plus" | "Minus" | "Star" | "Slash" | "Percent" | "PlusPlus" | "MinusMinus" | "Eq" | "Neq" | "Lt" | "Gt" | "Lte" | "Gte" | "LtLt" | "GtGt" | "Spaceship" | "Range" | "And" | "Or" | "Not" | "Amp" | "Pipe" | "Caret" | "Tilde" | "NullCoalescing" | "Arrow" | "In" | "Opaque" | "Self" | "Ref" | "Deref" | "EOF" | "Illegal" | "While" | "For" | "Do" | "Loop" | "Break" | "Continue" | "Match" | "Panic" | "Unreachable" | "Discard" | "Kill" | "Enum" | "Impl" | "Trait" | "Type";
5
+ interface Token {
6
+ kind: TokenKind;
7
+ lexeme: string;
8
+ line: number;
9
+ column: number;
10
+ }
11
+ declare function tokenize(source: string): Token[];
12
+
13
+ type ScalarTypeName = "i8" | "u8" | "i16" | "u16" | "i32" | "u32" | "i64" | "u64" | "f16" | "f32" | "f64" | "bf16" | "bool";
14
+ type ShaderStage = "vertex" | "fragment" | "compute";
15
+ type ShaderTarget = "wgsl" | "glsl-es-300" | "glsl-450" | "glsl" | (string & {});
16
+ type ResourceKind = "uniformBuffer" | "storageBuffer" | "sampledTexture" | "storageTexture" | "sampler";
17
+ interface BackendCapabilities {
18
+ readonly id: string;
19
+ readonly version: string;
20
+ readonly shaderStages: ReadonlySet<ShaderStage>;
21
+ readonly scalarTypes: ReadonlySet<ScalarTypeName>;
22
+ readonly resourceKinds: ReadonlySet<ResourceKind>;
23
+ readonly supportsStorageBuffers: boolean;
24
+ readonly supportsCompute: boolean;
25
+ readonly supportsF16: boolean;
26
+ readonly supportsF64: boolean;
27
+ readonly supportsI64: boolean;
28
+ }
29
+ declare const WGSL_CAPABILITIES: BackendCapabilities;
30
+ declare const GLSL_ES_300_CAPABILITIES: BackendCapabilities;
31
+ declare const GLSL_450_CAPABILITIES: BackendCapabilities;
32
+ declare function capabilitiesFor(target: ShaderTarget): BackendCapabilities;
33
+ declare function scalarIsSupported(capabilities: BackendCapabilities, name: ScalarTypeName): boolean;
34
+
35
+ type Span = {
36
+ line: number;
37
+ column: number;
38
+ endLine?: number;
39
+ endColumn?: number;
40
+ };
41
+ type LiteralKind = "int" | "float" | "bool" | "char" | "color";
42
+ interface LiteralValueMap {
43
+ "int": number;
44
+ "float": number;
45
+ "bool": boolean;
46
+ "char": string;
47
+ "color": string;
48
+ }
49
+ interface LiteralBase<K extends LiteralKind> {
50
+ kind: "Literal";
51
+ literalKind: K;
52
+ value: LiteralValueMap[K];
53
+ span: Span;
54
+ }
55
+ type Literal = LiteralBase<LiteralKind>;
56
+ type PatternKind = "wildcard" | "binding" | "literal" | "struct" | "tuple" | "array" | "ref" | "deref";
57
+ interface PatternBase<K extends PatternKind> {
58
+ kind: K;
59
+ span: Span;
60
+ }
61
+ interface WildcardPattern extends PatternBase<"wildcard"> {
62
+ }
63
+ interface BindingPattern extends PatternBase<"binding"> {
64
+ binding: string;
65
+ }
66
+ interface LiteralPattern extends PatternBase<"literal"> {
67
+ value: number | string | boolean;
68
+ }
69
+ interface StructPattern extends PatternBase<"struct"> {
70
+ subPatterns: Pattern[];
71
+ }
72
+ interface TuplePattern extends PatternBase<"tuple"> {
73
+ subPatterns: Pattern[];
74
+ }
75
+ interface ArrayPattern extends PatternBase<"array"> {
76
+ subPatterns: Pattern[];
77
+ }
78
+ interface RefPattern extends PatternBase<"ref"> {
79
+ subPatterns: Pattern[];
80
+ }
81
+ interface DerefPattern extends PatternBase<"deref"> {
82
+ subPatterns: Pattern[];
83
+ }
84
+ type Pattern = WildcardPattern | BindingPattern | LiteralPattern | StructPattern | TuplePattern | ArrayPattern | RefPattern | DerefPattern;
85
+ type Type = {
86
+ kind: "abstractInt";
87
+ } | {
88
+ kind: "abstractFloat";
89
+ } | {
90
+ kind: "scalar";
91
+ name: "i8" | "u8" | "i16" | "u16" | "i32" | "u32" | "i64" | "u64" | "f16" | "f32" | "f64" | "bf16" | "bool";
92
+ } | {
93
+ kind: "vector";
94
+ element: "i8" | "u8" | "i16" | "u16" | "i32" | "u32" | "i64" | "u64" | "f16" | "f32" | "f64" | "bf16" | "bool";
95
+ size: 2 | 3 | 4;
96
+ } | {
97
+ kind: "matrix";
98
+ element: "i8" | "u8" | "i16" | "u16" | "i32" | "u32" | "i64" | "u64" | "f16" | "f32" | "f64" | "bf16" | "bool";
99
+ rows: 2 | 3 | 4;
100
+ columns: 2 | 3 | 4;
101
+ } | {
102
+ kind: "quaternion";
103
+ } | {
104
+ kind: "struct";
105
+ name: string;
106
+ } | {
107
+ kind: "enum";
108
+ name: string;
109
+ } | {
110
+ kind: "sampler";
111
+ name: "sampler2D" | "sampler3D" | "samplerCube" | "sampler2DArray" | "samplerCubeArray" | "sampler2DShadow" | "samplerCubeShadow" | "samplerBuffer";
112
+ } | {
113
+ kind: "array";
114
+ element: Type;
115
+ size: number;
116
+ } | {
117
+ kind: "tuple";
118
+ elements: Type[];
119
+ } | {
120
+ kind: "option";
121
+ element: Type;
122
+ } | {
123
+ kind: "result";
124
+ ok: Type;
125
+ err: Type;
126
+ } | {
127
+ kind: "alias";
128
+ name: string;
129
+ } | {
130
+ kind: "opaque";
131
+ name: string;
132
+ } | {
133
+ kind: "anonymousStruct";
134
+ fields: Field[];
135
+ } | {
136
+ kind: "union";
137
+ members: Type[];
138
+ };
139
+ interface Field {
140
+ name: string;
141
+ type: Type;
142
+ }
143
+ interface Param {
144
+ name: string;
145
+ type: Type;
146
+ }
147
+ interface StructDecl {
148
+ kind: "StructDecl";
149
+ name: string;
150
+ fields: Field[];
151
+ span: Span;
152
+ }
153
+ interface EnumDecl {
154
+ kind: "EnumDecl";
155
+ name: string;
156
+ variants: {
157
+ name: string;
158
+ type: Type | null;
159
+ span?: Span;
160
+ }[];
161
+ span: Span;
162
+ }
163
+ interface ImplBlock {
164
+ kind: "ImplBlock";
165
+ trait: string | null;
166
+ type: Type;
167
+ methods: FnDecl[];
168
+ span: Span;
169
+ }
170
+ interface TraitDecl {
171
+ kind: "TraitDecl";
172
+ name: string;
173
+ bounds: string[];
174
+ methods: {
175
+ name: string;
176
+ params: Param[];
177
+ returnType: Type;
178
+ }[];
179
+ span: Span;
180
+ }
181
+ interface TypeAlias {
182
+ kind: "TypeAlias";
183
+ name: string;
184
+ type: Type;
185
+ span: Span;
186
+ }
187
+ interface NewtypeDecl {
188
+ kind: "NewtypeDecl";
189
+ name: string;
190
+ innerType: Type;
191
+ span: Span;
192
+ }
193
+ interface OpaqueDecl {
194
+ kind: "OpaqueDecl";
195
+ name: string;
196
+ span: Span;
197
+ }
198
+ interface FnDecl {
199
+ kind: "FnDecl";
200
+ name: string;
201
+ params: Param[];
202
+ returnType: Type;
203
+ body: Block;
204
+ stage?: ShaderStage;
205
+ span: Span;
206
+ }
207
+ interface VarDecl {
208
+ kind: "VarDecl";
209
+ name: string;
210
+ type: Type;
211
+ initializer: Expression | null;
212
+ mutable: boolean;
213
+ span: Span;
214
+ }
215
+ interface ReturnStmt {
216
+ kind: "ReturnStmt";
217
+ value: Expression | null;
218
+ span: Span;
219
+ }
220
+ interface ExpressionStmt {
221
+ kind: "ExpressionStmt";
222
+ expression: Expression;
223
+ span: Span;
224
+ }
225
+ interface Block {
226
+ kind: "Block";
227
+ statements: Statement[];
228
+ span: Span;
229
+ }
230
+ interface IfStmt {
231
+ kind: "IfStmt";
232
+ condition: Expression;
233
+ thenBranch: Block;
234
+ elseBranch: Block | null;
235
+ span: Span;
236
+ }
237
+ interface WhileStmt {
238
+ kind: "WhileStmt";
239
+ condition: Expression;
240
+ body: Block;
241
+ span: Span;
242
+ }
243
+ interface ForStmt {
244
+ kind: "ForStmt";
245
+ init: VarDecl | ExpressionStmt | null;
246
+ condition: Expression | null;
247
+ increment: Expression | null;
248
+ range: {
249
+ variable: string;
250
+ start: Expression;
251
+ end: Expression;
252
+ inclusive: boolean;
253
+ span?: Span;
254
+ } | null;
255
+ body: Block;
256
+ span: Span;
257
+ }
258
+ interface DoWhileStmt {
259
+ kind: "DoWhileStmt";
260
+ body: Block;
261
+ condition: Expression;
262
+ span: Span;
263
+ }
264
+ interface LoopStmt {
265
+ kind: "LoopStmt";
266
+ body: Block;
267
+ label: string | null;
268
+ span: Span;
269
+ }
270
+ interface BreakStmt {
271
+ kind: "BreakStmt";
272
+ label: string | null;
273
+ span: Span;
274
+ }
275
+ interface ContinueStmt {
276
+ kind: "ContinueStmt";
277
+ label: string | null;
278
+ span: Span;
279
+ }
280
+ interface MatchArm {
281
+ pattern: Pattern;
282
+ guard: Expression | null;
283
+ body: Block;
284
+ span: Span;
285
+ }
286
+ interface MatchExpr {
287
+ kind: "MatchExpr";
288
+ subject: Expression;
289
+ arms: MatchArm[];
290
+ span: Span;
291
+ }
292
+ interface PanicStmt {
293
+ kind: "PanicStmt";
294
+ message: Expression | null;
295
+ span: Span;
296
+ }
297
+ interface UnreachableStmt {
298
+ kind: "UnreachableStmt";
299
+ span: Span;
300
+ }
301
+ interface DiscardStmt {
302
+ kind: "DiscardStmt";
303
+ span: Span;
304
+ }
305
+ interface BindingDecl {
306
+ kind: "BindingDecl";
307
+ binding: number;
308
+ name: string;
309
+ type: Type;
310
+ span: Span;
311
+ }
312
+ interface ImportDecl {
313
+ kind: "ImportDecl";
314
+ path: string;
315
+ span: Span;
316
+ }
317
+ interface Identifier {
318
+ kind: "Identifier";
319
+ name: string;
320
+ span: Span;
321
+ }
322
+ interface BinaryExpr {
323
+ kind: "BinaryExpr";
324
+ left: Expression;
325
+ operator: string;
326
+ right: Expression;
327
+ span: Span;
328
+ }
329
+ interface UnaryExpr {
330
+ kind: "UnaryExpr";
331
+ operator: string;
332
+ operand: Expression;
333
+ span: Span;
334
+ }
335
+ interface CallExpr {
336
+ kind: "CallExpr";
337
+ callee: Expression;
338
+ args: Expression[];
339
+ span: Span;
340
+ }
341
+ interface MemberExpr {
342
+ kind: "MemberExpr";
343
+ object: Expression;
344
+ property: string;
345
+ span: Span;
346
+ }
347
+ interface SwizzleExpr {
348
+ kind: "SwizzleExpr";
349
+ object: Expression;
350
+ components: string[];
351
+ span: Span;
352
+ }
353
+ interface IndexExpr {
354
+ kind: "IndexExpr";
355
+ object: Expression;
356
+ index: Expression;
357
+ span: Span;
358
+ }
359
+ interface StructLiteral {
360
+ kind: "StructLiteral";
361
+ typeName: string;
362
+ fields: {
363
+ name: string | null;
364
+ value: Expression;
365
+ }[];
366
+ span: Span;
367
+ }
368
+ interface ArrayLiteral {
369
+ kind: "ArrayLiteral";
370
+ elements: Expression[];
371
+ span: Span;
372
+ }
373
+ interface CompoundAssignExpr {
374
+ kind: "CompoundAssignExpr";
375
+ operator: "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=";
376
+ target: Expression;
377
+ value: Expression;
378
+ span: Span;
379
+ }
380
+ interface UpdateExpr {
381
+ kind: "UpdateExpr";
382
+ operator: "++" | "--";
383
+ operand: Expression;
384
+ prefix: boolean;
385
+ span: Span;
386
+ }
387
+ interface ConditionalExpr {
388
+ kind: "ConditionalExpr";
389
+ test: Expression;
390
+ consequent: Expression;
391
+ alternate: Expression;
392
+ span: Span;
393
+ }
394
+ interface NullCoalescingExpr {
395
+ kind: "NullCoalescingExpr";
396
+ left: Expression;
397
+ right: Expression;
398
+ span: Span;
399
+ }
400
+ interface BlockExpr {
401
+ kind: "BlockExpr";
402
+ block: Block;
403
+ span: Span;
404
+ }
405
+ type Statement = StructDecl | EnumDecl | ImplBlock | TraitDecl | TypeAlias | NewtypeDecl | OpaqueDecl | FnDecl | VarDecl | ReturnStmt | ExpressionStmt | Block | IfStmt | WhileStmt | ForStmt | DoWhileStmt | LoopStmt | BreakStmt | ContinueStmt | PanicStmt | UnreachableStmt | DiscardStmt | BindingDecl | ImportDecl;
406
+ type Expression = Identifier | Literal | BinaryExpr | UnaryExpr | CallExpr | MemberExpr | SwizzleExpr | IndexExpr | StructLiteral | ArrayLiteral | CompoundAssignExpr | UpdateExpr | ConditionalExpr | NullCoalescingExpr | MatchExpr | BlockExpr;
407
+ interface Program {
408
+ kind: "Program";
409
+ statements: Statement[];
410
+ span: Span;
411
+ }
412
+
413
+ declare function parse(tokens: Token[]): Program;
414
+
415
+ type DiagnosticSeverity = "error" | "warning" | "info" | "hint";
416
+ interface Diagnostic {
417
+ file: string;
418
+ code?: string;
419
+ severity?: DiagnosticSeverity;
420
+ message: string;
421
+ span: Span;
422
+ related?: Diagnostic[];
423
+ help?: string;
424
+ }
425
+ /**
426
+ * Type-checks a parsed program and returns diagnostics.
427
+ *
428
+ * @param program - The parsed Program AST to type-check.
429
+ * @param file - The source file name (used in diagnostic messages).
430
+ * @returns An object containing the collected diagnostics.
431
+ */
432
+ declare function typeCheck(program: Program, file: string, provenance?: Map<Statement, string>): {
433
+ diagnostics: Diagnostic[];
434
+ };
435
+
436
+ type IRScalarName = "i8" | "u8" | "i16" | "u16" | "i32" | "u32" | "i64" | "u64" | "f16" | "f32" | "f64" | "bf16" | "bool" | "abstractInt" | "abstractFloat";
437
+ type IRStage = "vertex" | "fragment" | "compute";
438
+ type IRResourceKind = "uniformBuffer" | "storageBuffer" | "sampledTexture" | "storageTexture" | "sampler";
439
+ /**
440
+ * Source location used for diagnostics after lowering/raising.
441
+ */
442
+ type IRSpan = {
443
+ line: number;
444
+ column: number;
445
+ endLine?: number;
446
+ endColumn?: number;
447
+ };
448
+ type IRType = IRScalar | IRVector | IRMatrix | IRArray | IRStructRef | IREnumRef | IRQuaternion | IRSampler | IRAlias | IROpaque | IRAnonymousStruct | IRUnion | IROption | IRResult | IRTuple;
449
+ interface IRScalar {
450
+ kind: "scalar";
451
+ name: IRScalarName;
452
+ span?: IRSpan;
453
+ }
454
+ interface IRVector {
455
+ kind: "vector";
456
+ element: IRScalarName;
457
+ size: 2 | 3 | 4;
458
+ span?: IRSpan;
459
+ }
460
+ interface IRMatrix {
461
+ kind: "matrix";
462
+ element: IRScalarName;
463
+ rows: 2 | 3 | 4;
464
+ columns: 2 | 3 | 4;
465
+ span?: IRSpan;
466
+ }
467
+ interface IRArray {
468
+ kind: "array";
469
+ element: IRType;
470
+ size: number;
471
+ span?: IRSpan;
472
+ }
473
+ interface IRStructRef {
474
+ kind: "struct";
475
+ name: string;
476
+ span?: IRSpan;
477
+ }
478
+ interface IREnumRef {
479
+ kind: "enum";
480
+ name: string;
481
+ span?: IRSpan;
482
+ }
483
+ interface IRQuaternion {
484
+ kind: "quaternion";
485
+ span?: IRSpan;
486
+ }
487
+ interface IRSampler {
488
+ kind: "sampler";
489
+ name: string;
490
+ span?: IRSpan;
491
+ }
492
+ interface IRAlias {
493
+ kind: "alias";
494
+ name: string;
495
+ span?: IRSpan;
496
+ }
497
+ interface IROpaque {
498
+ kind: "opaque";
499
+ name: string;
500
+ span?: IRSpan;
501
+ }
502
+ interface IRAnonymousStruct {
503
+ kind: "anonymousStruct";
504
+ fields: IRField[];
505
+ span?: IRSpan;
506
+ }
507
+ interface IRUnion {
508
+ kind: "union";
509
+ members: IRType[];
510
+ span?: IRSpan;
511
+ }
512
+ interface IROption {
513
+ kind: "option";
514
+ element: IRType;
515
+ span?: IRSpan;
516
+ }
517
+ interface IRResult {
518
+ kind: "result";
519
+ ok: IRType;
520
+ err: IRType;
521
+ span?: IRSpan;
522
+ }
523
+ interface IRTuple {
524
+ kind: "tuple";
525
+ elements: IRType[];
526
+ span?: IRSpan;
527
+ }
528
+ interface IRField {
529
+ name: string;
530
+ type: IRType;
531
+ span?: IRSpan;
532
+ }
533
+ type IRParam = IRField;
534
+ type IRLiteralKind = "int" | "float" | "bool" | "char" | "color";
535
+ type IRExpression = IRLiteral | IRIdentifier | IRBinary | IRUnary | IRCall | IRMember | IRSwizzle | IRIndex | IRStructLiteral | IRArrayLiteral | IRCompoundAssign | IRUpdate | IRConditional | IRNullCoalescing | IRMatch | IRBlockExpr;
536
+ interface IRLiteral {
537
+ kind: "literal";
538
+ literalKind: IRLiteralKind;
539
+ value: string | number | boolean;
540
+ span?: IRSpan;
541
+ }
542
+ interface IRIdentifier {
543
+ kind: "identifier";
544
+ name: string;
545
+ span?: IRSpan;
546
+ }
547
+ interface IRBinary {
548
+ kind: "binary";
549
+ operator: string;
550
+ left: IRExpression;
551
+ right: IRExpression;
552
+ span?: IRSpan;
553
+ }
554
+ interface IRUnary {
555
+ kind: "unary";
556
+ operator: string;
557
+ operand: IRExpression;
558
+ span?: IRSpan;
559
+ }
560
+ interface IRCall {
561
+ kind: "call";
562
+ callee: IRExpression;
563
+ args: IRExpression[];
564
+ span?: IRSpan;
565
+ }
566
+ interface IRMember {
567
+ kind: "member";
568
+ object: IRExpression;
569
+ property: string;
570
+ span?: IRSpan;
571
+ }
572
+ interface IRSwizzle {
573
+ kind: "swizzle";
574
+ object: IRExpression;
575
+ components: string[];
576
+ span?: IRSpan;
577
+ }
578
+ interface IRIndex {
579
+ kind: "index";
580
+ object: IRExpression;
581
+ index: IRExpression;
582
+ span?: IRSpan;
583
+ }
584
+ interface IRStructLiteral {
585
+ kind: "structLiteral";
586
+ typeName: string;
587
+ fields: {
588
+ name: string | null;
589
+ value: IRExpression;
590
+ }[];
591
+ span?: IRSpan;
592
+ }
593
+ interface IRArrayLiteral {
594
+ kind: "arrayLiteral";
595
+ elements: IRExpression[];
596
+ span?: IRSpan;
597
+ }
598
+ interface IRCompoundAssign {
599
+ kind: "compoundAssign";
600
+ operator: string;
601
+ target: IRExpression;
602
+ value: IRExpression;
603
+ span?: IRSpan;
604
+ }
605
+ interface IRUpdate {
606
+ kind: "update";
607
+ operator: "++" | "--";
608
+ operand: IRExpression;
609
+ prefix: boolean;
610
+ span?: IRSpan;
611
+ }
612
+ interface IRConditional {
613
+ kind: "conditional";
614
+ test: IRExpression;
615
+ consequent: IRExpression;
616
+ alternate: IRExpression;
617
+ span?: IRSpan;
618
+ }
619
+ interface IRNullCoalescing {
620
+ kind: "nullCoalescing";
621
+ left: IRExpression;
622
+ right: IRExpression;
623
+ span?: IRSpan;
624
+ }
625
+ interface IRMatch {
626
+ kind: "match";
627
+ subject: IRExpression;
628
+ arms: IRMatchArm[];
629
+ span?: IRSpan;
630
+ }
631
+ interface IRMatchArm {
632
+ pattern: IRPattern;
633
+ guard: IRExpression | null;
634
+ body: IRBlock;
635
+ span?: IRSpan;
636
+ }
637
+ type IRPattern = IRLiteralPattern | IRBindingPattern | IRWildcardPattern;
638
+ interface IRLiteralPattern {
639
+ kind: "literal";
640
+ value: string | number | boolean;
641
+ span?: IRSpan;
642
+ }
643
+ interface IRBindingPattern {
644
+ kind: "binding";
645
+ binding: string;
646
+ span?: IRSpan;
647
+ }
648
+ interface IRWildcardPattern {
649
+ kind: "wildcard";
650
+ span?: IRSpan;
651
+ }
652
+ interface IRBlockExpr {
653
+ kind: "blockExpr";
654
+ block: IRBlock;
655
+ span?: IRSpan;
656
+ }
657
+ type IRStatement = IRVarDecl | IRReturn | IRExpressionStmt | IRBlock | IRIf | IRWhile | IRFor | IRDoWhile | IRLoop | IRBreak | IRContinue | IRDiscard | IRPanic | IRUnreachable;
658
+ interface IRVarDecl {
659
+ kind: "varDecl";
660
+ name: string;
661
+ type: IRType;
662
+ initializer: IRExpression | null;
663
+ mutable: boolean;
664
+ span?: IRSpan;
665
+ }
666
+ interface IRReturn {
667
+ kind: "return";
668
+ value: IRExpression | null;
669
+ span?: IRSpan;
670
+ }
671
+ interface IRExpressionStmt {
672
+ kind: "expressionStmt";
673
+ expression: IRExpression;
674
+ span?: IRSpan;
675
+ }
676
+ interface IRBlock {
677
+ kind: "block";
678
+ statements: IRModuleItem[];
679
+ span?: IRSpan;
680
+ }
681
+ interface IRIf {
682
+ kind: "if";
683
+ condition: IRExpression;
684
+ thenBranch: IRBlock;
685
+ elseBranch: IRBlock | null;
686
+ span?: IRSpan;
687
+ }
688
+ interface IRWhile {
689
+ kind: "while";
690
+ condition: IRExpression;
691
+ body: IRBlock;
692
+ span?: IRSpan;
693
+ }
694
+ interface IRFor {
695
+ kind: "for";
696
+ init: IRVarDecl | IRExpressionStmt | null;
697
+ condition: IRExpression | null;
698
+ increment: IRExpression | null;
699
+ range: IRForRange | null;
700
+ body: IRBlock;
701
+ span?: IRSpan;
702
+ }
703
+ interface IRForRange {
704
+ variable: string;
705
+ start: IRExpression;
706
+ end: IRExpression;
707
+ inclusive: boolean;
708
+ span?: IRSpan;
709
+ }
710
+ interface IRDoWhile {
711
+ kind: "doWhile";
712
+ body: IRBlock;
713
+ condition: IRExpression;
714
+ span?: IRSpan;
715
+ }
716
+ interface IRLoop {
717
+ kind: "loop";
718
+ body: IRBlock;
719
+ label: string | null;
720
+ span?: IRSpan;
721
+ }
722
+ interface IRBreak {
723
+ kind: "break";
724
+ label: string | null;
725
+ span?: IRSpan;
726
+ }
727
+ interface IRContinue {
728
+ kind: "continue";
729
+ label: string | null;
730
+ span?: IRSpan;
731
+ }
732
+ interface IRDiscard {
733
+ kind: "discard";
734
+ span?: IRSpan;
735
+ }
736
+ interface IRPanic {
737
+ kind: "panic";
738
+ message: IRExpression | null;
739
+ span?: IRSpan;
740
+ }
741
+ interface IRUnreachable {
742
+ kind: "unreachable";
743
+ span?: IRSpan;
744
+ }
745
+ interface IRStructDecl {
746
+ kind: "struct";
747
+ name: string;
748
+ fields: IRField[];
749
+ span?: IRSpan;
750
+ }
751
+ interface IRBindingDecl {
752
+ kind: "binding";
753
+ binding: number;
754
+ name: string;
755
+ type: IRType;
756
+ span?: IRSpan;
757
+ }
758
+ interface IREnumDecl {
759
+ kind: "enum";
760
+ name: string;
761
+ variants: {
762
+ name: string;
763
+ type: IRType | null;
764
+ span?: IRSpan;
765
+ }[];
766
+ span?: IRSpan;
767
+ }
768
+ interface IRFnDecl {
769
+ kind: "fn";
770
+ name: string;
771
+ stage: IRStage;
772
+ params: IRParam[];
773
+ returnType: IRType;
774
+ body: IRBlock;
775
+ span?: IRSpan;
776
+ }
777
+ interface IRTypeAlias {
778
+ kind: "typeAlias";
779
+ name: string;
780
+ type: IRType;
781
+ span?: IRSpan;
782
+ }
783
+ interface IRNewtypeDecl {
784
+ kind: "newtype";
785
+ name: string;
786
+ innerType: IRType;
787
+ span?: IRSpan;
788
+ }
789
+ interface IROpaqueDecl {
790
+ kind: "opaqueDecl";
791
+ name: string;
792
+ span?: IRSpan;
793
+ }
794
+ interface IRTraitDecl {
795
+ kind: "trait";
796
+ name: string;
797
+ bounds: string[];
798
+ methods: {
799
+ name: string;
800
+ params: IRParam[];
801
+ returnType: IRType;
802
+ }[];
803
+ span?: IRSpan;
804
+ }
805
+ interface IRImplBlock {
806
+ kind: "implBlock";
807
+ trait: string | null;
808
+ type: IRType;
809
+ methods: IRFnDecl[];
810
+ span?: IRSpan;
811
+ }
812
+ interface IREntryPoint {
813
+ stage: IRStage;
814
+ name: string;
815
+ fn: IRFnDecl;
816
+ }
817
+ interface IRSourceFile {
818
+ id: string;
819
+ displayName?: string;
820
+ }
821
+ interface IRSourceAttribution {
822
+ /** Canonical identity of the source module that declared this item. */
823
+ sourceFile?: string;
824
+ }
825
+ type IRModuleItem = (IRStructDecl | IREnumDecl | IRFnDecl | IRBindingDecl | IRTypeAlias | IRNewtypeDecl | IROpaqueDecl | IRTraitDecl | IRImplBlock | IRStatement) & IRSourceAttribution;
826
+ interface IRModule {
827
+ items: IRModuleItem[];
828
+ functions: IRFnDecl[];
829
+ structs: IRStructDecl[];
830
+ enums: IREnumDecl[];
831
+ bindings: IRBindingDecl[];
832
+ typeAliases: IRTypeAlias[];
833
+ newtypes: IRNewtypeDecl[];
834
+ opaques: IROpaqueDecl[];
835
+ traits: IRTraitDecl[];
836
+ impls: IRImplBlock[];
837
+ entryPoints: IREntryPoint[];
838
+ sourceFiles: IRSourceFile[];
839
+ sourceId: string;
840
+ span?: IRSpan;
841
+ }
842
+
843
+ interface CodegenOptions {
844
+ /** Formatting style: "compact" or "pretty". Defaults to "pretty". */
845
+ format?: "compact" | "pretty";
846
+ }
847
+ interface ShaderArtifact {
848
+ stage: ShaderStage;
849
+ entryPoint: string;
850
+ code: string;
851
+ sourceMap?: ShaderSourceMap;
852
+ reflection: ShaderReflection;
853
+ }
854
+ interface ShaderSourceMap {
855
+ mappings: string;
856
+ sources: string[];
857
+ names: string[];
858
+ }
859
+ interface ShaderReflection {
860
+ entryPoints: ShaderEntryPointReflection[];
861
+ resources: ShaderResourceReflection[];
862
+ uniforms: ShaderUniformReflection[];
863
+ }
864
+ interface ShaderEntryPointReflection {
865
+ name: string;
866
+ stage: ShaderStage;
867
+ inputs: ShaderInterfaceVariable[];
868
+ outputs: ShaderInterfaceVariable[];
869
+ }
870
+ interface ShaderInterfaceVariable {
871
+ name: string;
872
+ type: string;
873
+ location?: number;
874
+ builtin?: string;
875
+ }
876
+ interface ShaderResourceReflection {
877
+ name: string;
878
+ kind: string;
879
+ binding: number;
880
+ set: number;
881
+ stageVisibility: ShaderStage[];
882
+ }
883
+ interface ShaderUniformReflection {
884
+ name: string;
885
+ type: string;
886
+ offset: number;
887
+ size: number;
888
+ }
889
+ interface BackendOutput {
890
+ target: ShaderTarget;
891
+ shaders: ShaderArtifact[];
892
+ diagnostics: Diagnostic[];
893
+ }
894
+ /**
895
+ * Contract for a shader code-generation backend. Each backend converts the
896
+ * lowered IR (raised to AST for compatibility) into target-specific shader
897
+ * source code, validates target capabilities, and reports structured
898
+ * diagnostics for unsupported constructs.
899
+ */
900
+ interface ShaderCodegenBackend {
901
+ readonly id: string;
902
+ readonly version: string;
903
+ readonly capabilities: BackendCapabilities;
904
+ validate(module: IRModule, file: string): Diagnostic[];
905
+ generate(module: IRModule, file: string, options?: CodegenOptions): BackendOutput;
906
+ }
907
+ /**
908
+ * Global backend registry. Backends register themselves here; consumers look
909
+ * them up by target ID. Prevents duplicate registrations.
910
+ */
911
+ declare class BackendRegistry {
912
+ private backends;
913
+ register(backend: ShaderCodegenBackend): void;
914
+ /** Replace an existing backend for a target. */
915
+ replace(backend: ShaderCodegenBackend): void;
916
+ get(id: string): ShaderCodegenBackend | undefined;
917
+ has(id: string): boolean;
918
+ ids(): string[];
919
+ }
920
+ declare function createDefaultBackendRegistry(): BackendRegistry;
921
+ declare const defaultRegistry: BackendRegistry;
922
+ declare function getBackend(id: ShaderTarget): ShaderCodegenBackend | undefined;
923
+
924
+ /**
925
+ * Backward-compatible wrapper: lowers a Program AST to IR and delegates to
926
+ * the IR-based generator.
927
+ */
928
+ declare function generateGLSL(program: Program, target?: "glsl-450" | "glsl-es-300"): string;
929
+
930
+ declare function generateWGSL(program: Program): string;
931
+
932
+ /**
933
+ * Creates a source span for AST nodes.
934
+ *
935
+ * @param line - The line number (1-based).
936
+ * @param column - The column number (1-based).
937
+ * @returns A span object.
938
+ */
939
+ declare function span(line?: number, column?: number): {
940
+ line: number;
941
+ column: number;
942
+ };
943
+ /**
944
+ * Builds a scalar type node.
945
+ *
946
+ * @param name - The scalar type name (e.g. "f32", "i32", "bool").
947
+ * @returns The scalar Type node.
948
+ */
949
+ declare function scalarType(name: Extract<Type, {
950
+ kind: "scalar";
951
+ }>["name"]): Type;
952
+ /**
953
+ * Builds an i8 scalar type.
954
+ * @returns The i8 Type node.
955
+ */
956
+ declare function i8(): Type;
957
+ /**
958
+ * Builds a u8 scalar type.
959
+ * @returns The u8 Type node.
960
+ */
961
+ declare function u8(): Type;
962
+ /**
963
+ * Builds an i16 scalar type.
964
+ * @returns The i16 Type node.
965
+ */
966
+ declare function i16(): Type;
967
+ /**
968
+ * Builds a u16 scalar type.
969
+ * @returns The u16 Type node.
970
+ */
971
+ declare function u16(): Type;
972
+ /**
973
+ * Builds an i32 scalar type.
974
+ * @returns The i32 Type node.
975
+ */
976
+ declare function i32(): Type;
977
+ /**
978
+ * Builds a u32 scalar type.
979
+ * @returns The u32 Type node.
980
+ */
981
+ declare function u32(): Type;
982
+ /**
983
+ * Builds an i64 scalar type.
984
+ * @returns The i64 Type node.
985
+ */
986
+ declare function i64(): Type;
987
+ /**
988
+ * Builds a u64 scalar type.
989
+ * @returns The u64 Type node.
990
+ */
991
+ declare function u64(): Type;
992
+ /**
993
+ * Builds an f16 scalar type.
994
+ * @returns The f16 Type node.
995
+ */
996
+ declare function f16(): Type;
997
+ /**
998
+ * Builds an f32 scalar type.
999
+ * @returns The f32 Type node.
1000
+ */
1001
+ declare function f32(): Type;
1002
+ /**
1003
+ * Builds an f64 scalar type.
1004
+ * @returns The f64 Type node.
1005
+ */
1006
+ declare function f64(): Type;
1007
+ /**
1008
+ * Builds a bf16 scalar type.
1009
+ * @returns The bf16 Type node.
1010
+ */
1011
+ declare function bf16(): Type;
1012
+ /**
1013
+ * Builds a bool scalar type.
1014
+ * @returns The bool Type node.
1015
+ */
1016
+ declare function boolType(): Type;
1017
+ /**
1018
+ * Builds a vector type node.
1019
+ *
1020
+ * @param element - The element type name (e.g. "f32", "i32").
1021
+ * @param size - The vector size (2, 3, or 4).
1022
+ * @returns The vector Type node.
1023
+ */
1024
+ declare function vectorType(element: string, size: 2 | 3 | 4): Type;
1025
+ /**
1026
+ * Builds a vec2 type.
1027
+ * @param element - The element type name (default "f32").
1028
+ * @returns The vec2 Type node.
1029
+ */
1030
+ declare function vec2(element?: string): Type;
1031
+ /**
1032
+ * Builds a vec3 type.
1033
+ * @param element - The element type name (default "f32").
1034
+ * @returns The vec3 Type node.
1035
+ */
1036
+ declare function vec3(element?: string): Type;
1037
+ /**
1038
+ * Builds a vec4 type.
1039
+ * @param element - The element type name (default "f32").
1040
+ * @returns The vec4 Type node.
1041
+ */
1042
+ declare function vec4(element?: string): Type;
1043
+ /**
1044
+ * Builds an ivec2 type.
1045
+ * @returns The ivec2 Type node.
1046
+ */
1047
+ declare function ivec2(): Type;
1048
+ /**
1049
+ * Builds an ivec3 type.
1050
+ * @returns The ivec3 Type node.
1051
+ */
1052
+ declare function ivec3(): Type;
1053
+ /**
1054
+ * Builds an ivec4 type.
1055
+ * @returns The ivec4 Type node.
1056
+ */
1057
+ declare function ivec4(): Type;
1058
+ /**
1059
+ * Builds a uvec2 type.
1060
+ * @returns The uvec2 Type node.
1061
+ */
1062
+ declare function uvec2(): Type;
1063
+ /**
1064
+ * Builds a uvec3 type.
1065
+ * @returns The uvec3 Type node.
1066
+ */
1067
+ declare function uvec3(): Type;
1068
+ /**
1069
+ * Builds a uvec4 type.
1070
+ * @returns The uvec4 Type node.
1071
+ */
1072
+ declare function uvec4(): Type;
1073
+ /**
1074
+ * Builds a bvec2 type.
1075
+ * @returns The bvec2 Type node.
1076
+ */
1077
+ declare function bvec2(): Type;
1078
+ /**
1079
+ * Builds a bvec3 type.
1080
+ * @returns The bvec3 Type node.
1081
+ */
1082
+ declare function bvec3(): Type;
1083
+ /**
1084
+ * Builds a bvec4 type.
1085
+ * @returns The bvec4 Type node.
1086
+ */
1087
+ declare function bvec4(): Type;
1088
+ /**
1089
+ * Builds a dvec2 type.
1090
+ * @returns The dvec2 Type node.
1091
+ */
1092
+ declare function dvec2(): Type;
1093
+ /**
1094
+ * Builds a dvec3 type.
1095
+ * @returns The dvec3 Type node.
1096
+ */
1097
+ declare function dvec3(): Type;
1098
+ /**
1099
+ * Builds a dvec4 type.
1100
+ * @returns The dvec4 Type node.
1101
+ */
1102
+ declare function dvec4(): Type;
1103
+ /**
1104
+ * Builds a matrix type node.
1105
+ *
1106
+ * @param element - The element type name.
1107
+ * @param rows - The number of rows (2, 3, or 4).
1108
+ * @param columns - The number of columns (2, 3, or 4).
1109
+ * @returns The matrix Type node.
1110
+ */
1111
+ declare function matrixType(element: string, rows: 2 | 3 | 4, columns: 2 | 3 | 4): Type;
1112
+ /**
1113
+ * Builds a mat2 type.
1114
+ * @returns The mat2 Type node.
1115
+ */
1116
+ declare function mat2(): Type;
1117
+ /**
1118
+ * Builds a mat3 type.
1119
+ * @returns The mat3 Type node.
1120
+ */
1121
+ declare function mat3(): Type;
1122
+ /**
1123
+ * Builds a mat4 type.
1124
+ * @returns The mat4 Type node.
1125
+ */
1126
+ declare function mat4(): Type;
1127
+ /**
1128
+ * Builds a mat2x3 type.
1129
+ * @returns The mat2x3 Type node.
1130
+ */
1131
+ declare function mat2x3(): Type;
1132
+ /**
1133
+ * Builds a mat3x2 type.
1134
+ * @returns The mat3x2 Type node.
1135
+ */
1136
+ declare function mat3x2(): Type;
1137
+ /**
1138
+ * Builds a dmat3 type.
1139
+ * @returns The dmat3 Type node.
1140
+ */
1141
+ declare function dmat3(): Type;
1142
+ /**
1143
+ * Builds a quaternion type node.
1144
+ * @returns The quaternion Type node.
1145
+ */
1146
+ declare function quatType(): Type;
1147
+ /**
1148
+ * Builds a struct type reference.
1149
+ *
1150
+ * @param name - The struct name.
1151
+ * @returns The struct Type node.
1152
+ */
1153
+ declare function structType(name: string): Type;
1154
+ /**
1155
+ * Builds an enum type reference.
1156
+ *
1157
+ * @param name - The enum name.
1158
+ * @returns The enum Type node.
1159
+ */
1160
+ declare function enumType(name: string): Type;
1161
+ /**
1162
+ * Builds a sampler type node.
1163
+ *
1164
+ * @param name - The sampler type name (e.g. "sampler2D").
1165
+ * @returns The sampler Type node.
1166
+ */
1167
+ declare function samplerType(name: Extract<Type, {
1168
+ kind: "sampler";
1169
+ }>["name"]): Type;
1170
+ /**
1171
+ * Builds a sampler2D type.
1172
+ * @returns The sampler2D Type node.
1173
+ */
1174
+ declare function sampler2D(): Type;
1175
+ /**
1176
+ * Builds a sampler3D type.
1177
+ * @returns The sampler3D Type node.
1178
+ */
1179
+ declare function sampler3D(): Type;
1180
+ /**
1181
+ * Builds a samplerCube type.
1182
+ * @returns The samplerCube Type node.
1183
+ */
1184
+ declare function samplerCube(): Type;
1185
+ /**
1186
+ * Builds an array type node.
1187
+ *
1188
+ * @param element - The element Type.
1189
+ * @param size - The array size.
1190
+ * @returns The array Type node.
1191
+ */
1192
+ declare function arrayType(element: Type, size: number): Type;
1193
+ /**
1194
+ * Builds a tuple type node.
1195
+ *
1196
+ * @param elements - The element Types.
1197
+ * @returns The tuple Type node.
1198
+ */
1199
+ declare function tupleType(elements: Type[]): Type;
1200
+ /**
1201
+ * Builds an option type node.
1202
+ *
1203
+ * @param element - The element Type.
1204
+ * @returns The option Type node.
1205
+ */
1206
+ declare function optionType(element: Type): Type;
1207
+ /**
1208
+ * Builds a result type node.
1209
+ *
1210
+ * @param ok - The ok Type.
1211
+ * @param err - The err Type.
1212
+ * @returns The result Type node.
1213
+ */
1214
+ declare function resultType(ok: Type, err: Type): Type;
1215
+ /**
1216
+ * Builds an alias type reference.
1217
+ *
1218
+ * @param name - The alias name.
1219
+ * @returns The alias Type node.
1220
+ */
1221
+ declare function aliasType(name: string): Type;
1222
+ /**
1223
+ * Builds an opaque type reference.
1224
+ *
1225
+ * @param name - The opaque type name.
1226
+ * @returns The opaque Type node.
1227
+ */
1228
+ declare function opaqueType(name: string): Type;
1229
+ /**
1230
+ * Builds an anonymous struct type node.
1231
+ *
1232
+ * @param fields - The struct fields.
1233
+ * @returns The anonymous struct Type node.
1234
+ */
1235
+ declare function anonymousStructType(fields: Field[]): Type;
1236
+ /**
1237
+ * Builds a union type node.
1238
+ *
1239
+ * @param members - The member Types.
1240
+ * @returns The union Type node.
1241
+ */
1242
+ declare function unionType(members: Type[]): Type;
1243
+ /**
1244
+ * Builds a struct field.
1245
+ *
1246
+ * @param name - The field name.
1247
+ * @param type - The field Type.
1248
+ * @returns The Field node.
1249
+ */
1250
+ declare function field(name: string, type: Type): Field;
1251
+ /**
1252
+ * Builds a function parameter.
1253
+ *
1254
+ * @param name - The parameter name.
1255
+ * @param type - The parameter Type.
1256
+ * @returns The Param node.
1257
+ */
1258
+ declare function param(name: string, type: Type): Param;
1259
+ /**
1260
+ * Builds a struct declaration.
1261
+ *
1262
+ * @param name - The struct name.
1263
+ * @param fields - The struct fields.
1264
+ * @returns The StructDecl node.
1265
+ */
1266
+ declare function structDecl(name: string, fields: Field[]): StructDecl;
1267
+ /**
1268
+ * Builds an enum declaration.
1269
+ *
1270
+ * @param name - The enum name.
1271
+ * @param variants - The enum variants (name + optional type).
1272
+ * @returns The EnumDecl node.
1273
+ */
1274
+ declare function enumDecl(name: string, variants: {
1275
+ name: string;
1276
+ type: Type | null;
1277
+ span?: Span;
1278
+ }[]): EnumDecl;
1279
+ /**
1280
+ * Builds a function declaration.
1281
+ *
1282
+ * @param name - The function name.
1283
+ * @param params - The function parameters.
1284
+ * @param returnType - The return Type.
1285
+ * @param body - The function body block.
1286
+ * @returns The FnDecl node.
1287
+ */
1288
+ declare function fnDecl(name: string, params: Param[], returnType: Type, body: Block, stage?: ShaderStage): FnDecl;
1289
+ /**
1290
+ * Builds a binding declaration (@binding).
1291
+ *
1292
+ * @param binding - The binding slot number.
1293
+ * @param name - The binding name.
1294
+ * @param type - The binding Type.
1295
+ * @returns The BindingDecl node.
1296
+ */
1297
+ declare function bindingDecl(binding: number, name: string, type: Type): BindingDecl;
1298
+ /**
1299
+ * Builds an import declaration.
1300
+ *
1301
+ * @param path - The import path.
1302
+ * @returns The ImportDecl node.
1303
+ */
1304
+ declare function importDecl(path: string): ImportDecl;
1305
+ /**
1306
+ * Builds a variable declaration.
1307
+ *
1308
+ * @param name - The variable name.
1309
+ * @param type - The variable Type.
1310
+ * @param initializer - The initializer expression, or null.
1311
+ * @param mutable - Whether the variable is mutable (var vs let).
1312
+ * @returns The VarDecl node.
1313
+ */
1314
+ declare function varDecl(name: string, type: Type, initializer?: Expression | null, mutable?: boolean): VarDecl;
1315
+ /**
1316
+ * Builds a return statement.
1317
+ *
1318
+ * @param value - The return value expression, or null.
1319
+ * @returns The ReturnStmt node.
1320
+ */
1321
+ declare function returnStmt(value?: Expression | null): ReturnStmt;
1322
+ /**
1323
+ * Builds an expression statement.
1324
+ *
1325
+ * @param expression - The expression to evaluate.
1326
+ * @returns The ExpressionStmt node.
1327
+ */
1328
+ declare function expressionStmt(expression: Expression): ExpressionStmt;
1329
+ /**
1330
+ * Builds a block statement.
1331
+ *
1332
+ * @param statements - The statements inside the block.
1333
+ * @returns The Block node.
1334
+ */
1335
+ declare function block(statements: Statement[]): Block;
1336
+ /**
1337
+ * Builds an if-else statement.
1338
+ *
1339
+ * @param condition - The condition expression.
1340
+ * @param thenBranch - The then-branch block.
1341
+ * @param elseBranch - The optional else-branch block.
1342
+ * @returns The IfStmt node.
1343
+ */
1344
+ declare function ifStmt(condition: Expression, thenBranch: Block, elseBranch?: Block | null): IfStmt;
1345
+ /**
1346
+ * Builds a while loop statement.
1347
+ *
1348
+ * @param condition - The loop condition expression.
1349
+ * @param body - The loop body block.
1350
+ * @returns The WhileStmt node.
1351
+ */
1352
+ declare function whileStmt(condition: Expression, body: Block): WhileStmt;
1353
+ /**
1354
+ * Builds a C-style for loop statement.
1355
+ *
1356
+ * @param init - The initializer (VarDecl, ExpressionStmt, or null).
1357
+ * @param condition - The loop condition, or null.
1358
+ * @param increment - The increment expression, or null.
1359
+ * @param body - The loop body block.
1360
+ * @returns The ForStmt node.
1361
+ */
1362
+ declare function forStmt(init: VarDecl | ExpressionStmt | null, condition: Expression | null, increment: Expression | null, body: Block): ForStmt;
1363
+ /**
1364
+ * Builds a range-based for loop statement (e.g. `for x in 0..3`).
1365
+ *
1366
+ * @param variable - The loop variable name.
1367
+ * @param start - The range start expression.
1368
+ * @param end - The range end expression.
1369
+ * @param inclusive - Whether the range is inclusive (`..=`).
1370
+ * @param body - The loop body block.
1371
+ * @returns The ForStmt node.
1372
+ */
1373
+ declare function rangeForStmt(variable: string, start: Expression, end: Expression, inclusive: boolean, body: Block): ForStmt;
1374
+ /**
1375
+ * Builds a do-while loop statement.
1376
+ *
1377
+ * @param body - The loop body block.
1378
+ * @param condition - The exit condition expression.
1379
+ * @returns The DoWhileStmt node.
1380
+ */
1381
+ declare function doWhileStmt(body: Block, condition: Expression): DoWhileStmt;
1382
+ /**
1383
+ * Builds a loop statement (infinite loop, lowered to `for (;;)`).
1384
+ *
1385
+ * @param body - The loop body block.
1386
+ * @returns The LoopStmt node.
1387
+ */
1388
+ declare function loopStmt(body: Block): LoopStmt;
1389
+ /**
1390
+ * Builds a break statement.
1391
+ * @returns The BreakStmt node.
1392
+ */
1393
+ declare function breakStmt(): BreakStmt;
1394
+ /**
1395
+ * Builds a continue statement.
1396
+ * @returns The ContinueStmt node.
1397
+ */
1398
+ declare function continueStmt(): ContinueStmt;
1399
+ /**
1400
+ * Builds a discard statement.
1401
+ * @returns The DiscardStmt node.
1402
+ */
1403
+ declare function discardStmt(): DiscardStmt;
1404
+ /**
1405
+ * Builds a panic statement.
1406
+ *
1407
+ * @param message - The optional panic message expression.
1408
+ * @returns The PanicStmt node.
1409
+ */
1410
+ declare function panicStmt(message?: Expression | null): PanicStmt;
1411
+ /**
1412
+ * Builds an unreachable statement.
1413
+ * @returns The UnreachableStmt node.
1414
+ */
1415
+ declare function unreachableStmt(): UnreachableStmt;
1416
+ /**
1417
+ * Builds an identifier expression.
1418
+ *
1419
+ * @param name - The identifier name.
1420
+ * @returns The Identifier expression node.
1421
+ */
1422
+ declare function ident(name: string): Identifier;
1423
+ /**
1424
+ * Builds an integer literal expression.
1425
+ *
1426
+ * @param value - The integer value.
1427
+ * @returns The Literal expression node with literalKind "int".
1428
+ */
1429
+ declare function int(value: number): LiteralBase<"int">;
1430
+ /**
1431
+ * Builds a float literal expression.
1432
+ *
1433
+ * @param value - The float value.
1434
+ * @returns The Literal expression node with literalKind "float".
1435
+ */
1436
+ declare function float(value: number): LiteralBase<"float">;
1437
+ /**
1438
+ * Builds a boolean literal expression.
1439
+ *
1440
+ * @param value - The boolean value.
1441
+ * @returns The Literal expression node with literalKind "bool".
1442
+ */
1443
+ declare function boolLiteral(value: boolean): LiteralBase<"bool">;
1444
+ /**
1445
+ * Builds a binary expression.
1446
+ *
1447
+ * @param left - The left operand.
1448
+ * @param operator - The binary operator.
1449
+ * @param right - The right operand.
1450
+ * @returns The BinaryExpr expression node.
1451
+ */
1452
+ declare function binary(left: Expression, operator: string, right: Expression): BinaryExpr;
1453
+ /**
1454
+ * Builds a unary expression.
1455
+ *
1456
+ * @param operator - The unary operator.
1457
+ * @param operand - The operand expression.
1458
+ * @returns The UnaryExpr expression node.
1459
+ */
1460
+ declare function unary(operator: string, operand: Expression): UnaryExpr;
1461
+ /**
1462
+ * Builds a function call expression.
1463
+ *
1464
+ * @param callee - The callee expression.
1465
+ * @param args - The call arguments (default empty).
1466
+ * @returns The CallExpr expression node.
1467
+ */
1468
+ declare function call(callee: Expression, args?: Expression[]): CallExpr;
1469
+ /**
1470
+ * Builds a member access expression.
1471
+ *
1472
+ * @param object - The object expression.
1473
+ * @param property - The property name.
1474
+ * @returns The MemberExpr expression node.
1475
+ */
1476
+ declare function member(object: Expression, property: string): MemberExpr;
1477
+ /**
1478
+ * Builds a swizzle expression.
1479
+ *
1480
+ * @param object - The object expression.
1481
+ * @param components - The swizzle components (e.g. ["r", "g", "b"]).
1482
+ * @returns The SwizzleExpr expression node.
1483
+ */
1484
+ declare function swizzle(object: Expression, components: string[]): SwizzleExpr;
1485
+ /**
1486
+ * Builds an index expression.
1487
+ *
1488
+ * @param object - The object expression.
1489
+ * @param indexExpr - The index expression.
1490
+ * @returns The IndexExpr expression node.
1491
+ */
1492
+ declare function index(object: Expression, indexExpr: Expression): IndexExpr;
1493
+ /**
1494
+ * Builds a struct literal expression.
1495
+ *
1496
+ * @param typeName - The struct type name.
1497
+ * @param fields - The field name/value pairs (name may be null for spread).
1498
+ * @returns The StructLiteral expression node.
1499
+ */
1500
+ declare function structLiteral(typeName: string, fields: {
1501
+ name: string | null;
1502
+ value: Expression;
1503
+ }[]): StructLiteral;
1504
+ /**
1505
+ * Builds an array literal expression.
1506
+ *
1507
+ * @param elements - The array elements (default empty).
1508
+ * @returns The ArrayLiteral expression node.
1509
+ */
1510
+ declare function arrayLiteral(elements?: Expression[]): ArrayLiteral;
1511
+ /**
1512
+ * Builds a compound assignment expression (e.g. `x += 2`).
1513
+ *
1514
+ * @param target - The target expression.
1515
+ * @param operator - The compound assignment operator.
1516
+ * @param value - The value expression.
1517
+ * @returns The CompoundAssignExpr expression node.
1518
+ */
1519
+ declare function compoundAssign(target: Expression, operator: "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=", value: Expression): CompoundAssignExpr;
1520
+ /**
1521
+ * Builds an increment/decrement expression (e.g. `++x` or `x--`).
1522
+ *
1523
+ * @param operator - The update operator ("++" or "--").
1524
+ * @param operand - The operand expression.
1525
+ * @param prefix - Whether the operator is prefix (default false).
1526
+ * @returns The UpdateExpr expression node.
1527
+ */
1528
+ declare function update(operator: "++" | "--", operand: Expression, prefix?: boolean): UpdateExpr;
1529
+ /**
1530
+ * Builds a ternary conditional expression (e.g. `b ? 1.0 : 2.0`).
1531
+ *
1532
+ * @param test - The test expression.
1533
+ * @param consequent - The consequent expression.
1534
+ * @param alternate - The alternate expression.
1535
+ * @returns The ConditionalExpr expression node.
1536
+ */
1537
+ declare function conditional(test: Expression, consequent: Expression, alternate: Expression): ConditionalExpr;
1538
+ /**
1539
+ * Builds a null coalescing expression (e.g. `x ?? 2`).
1540
+ *
1541
+ * @param left - The left expression.
1542
+ * @param right - The right expression.
1543
+ * @returns The NullCoalescingExpr expression node.
1544
+ */
1545
+ declare function nullCoalescing(left: Expression, right: Expression): NullCoalescingExpr;
1546
+ /**
1547
+ * Builds a match expression.
1548
+ *
1549
+ * @param subject - The subject expression.
1550
+ * @param arms - The match arms.
1551
+ * @returns The MatchExpr expression node.
1552
+ */
1553
+ declare function match(subject: Expression, arms: MatchArm[]): MatchExpr;
1554
+ /**
1555
+ * Builds a block expression.
1556
+ *
1557
+ * @param block - The block statement.
1558
+ * @returns The BlockExpr expression node.
1559
+ */
1560
+ declare function blockExpr(block: Block): BlockExpr;
1561
+ /**
1562
+ * Builds a literal match pattern.
1563
+ *
1564
+ * @param value - The literal value.
1565
+ * @returns The LiteralPattern node.
1566
+ */
1567
+ declare function literalPattern(value: number | string | boolean): LiteralPattern;
1568
+ /**
1569
+ * Builds a binding match pattern.
1570
+ *
1571
+ * @param name - The binding name.
1572
+ * @returns The BindingPattern node.
1573
+ */
1574
+ declare function bindingPattern(name: string): BindingPattern;
1575
+ /**
1576
+ * Builds a wildcard match pattern.
1577
+ * @returns The WildcardPattern node.
1578
+ */
1579
+ declare function wildcardPattern(): WildcardPattern;
1580
+ /**
1581
+ * Builds a match arm.
1582
+ *
1583
+ * @param pattern - The match pattern.
1584
+ * @param body - The arm body block.
1585
+ * @param guard - The optional guard expression.
1586
+ * @returns The MatchArm node.
1587
+ */
1588
+ declare function arm(pattern: Pattern, body: Block, guard?: Expression | null): MatchArm;
1589
+ /**
1590
+ * Builds a type alias declaration.
1591
+ *
1592
+ * @param name - The alias name.
1593
+ * @param type - The aliased Type.
1594
+ * @returns The TypeAlias node.
1595
+ */
1596
+ declare function typeAlias(name: string, type: Type): TypeAlias;
1597
+ /**
1598
+ * Builds a newtype declaration.
1599
+ *
1600
+ * @param name - The newtype name.
1601
+ * @param innerType - The inner Type.
1602
+ * @returns The NewtypeDecl node.
1603
+ */
1604
+ declare function newtypeDecl(name: string, innerType: Type): NewtypeDecl;
1605
+ /**
1606
+ * Builds an opaque type declaration.
1607
+ *
1608
+ * @param name - The opaque type name.
1609
+ * @returns The OpaqueDecl node.
1610
+ */
1611
+ declare function opaqueDecl(name: string): OpaqueDecl;
1612
+ /**
1613
+ * Builds a trait declaration.
1614
+ *
1615
+ * @param name - The trait name.
1616
+ * @param bounds - The trait bounds.
1617
+ * @param methods - The trait method signatures.
1618
+ * @returns The TraitDecl node.
1619
+ */
1620
+ declare function traitDecl(name: string, bounds: string[], methods: {
1621
+ name: string;
1622
+ params: Param[];
1623
+ returnType: Type;
1624
+ }[]): TraitDecl;
1625
+ /**
1626
+ * Builds an impl block declaration.
1627
+ *
1628
+ * @param trait - The trait name, or null for inherent impl.
1629
+ * @param type - The target Type.
1630
+ * @param methods - The impl method declarations.
1631
+ * @returns The ImplBlock node.
1632
+ */
1633
+ declare function implBlock(trait: string | null, type: Type, methods: FnDecl[]): ImplBlock;
1634
+ /**
1635
+ * Builds a Program node.
1636
+ *
1637
+ * @param statements - The top-level statements.
1638
+ * @returns The Program node.
1639
+ */
1640
+ declare function program(statements: Statement[]): Program;
1641
+ /**
1642
+ * Builds a `fn main(): vec4` entry point.
1643
+ *
1644
+ * @param body - The main function body block.
1645
+ * @returns The FnDecl node for main.
1646
+ */
1647
+ declare function mainFn(body: Block): FnDecl;
1648
+ /**
1649
+ * Builds a `fn main(): vec4` entry point from a list of statements.
1650
+ *
1651
+ * @param statements - The statements inside main's body.
1652
+ * @returns The FnDecl node for main.
1653
+ */
1654
+ declare function mainVec4(statements: Statement[]): FnDecl;
1655
+
1656
+ /**
1657
+ * Options for compiling a gl source file or AST.
1658
+ */
1659
+ interface CompileOptions {
1660
+ target: string;
1661
+ file?: string;
1662
+ /** Source text to parse and compile (mutually exclusive with `ast`). */
1663
+ source?: string;
1664
+ /** Pre-built AST to type-check and codegen (mutually exclusive with `source`). */
1665
+ ast?: Program;
1666
+ /** Source resolver for import resolution. Required when source contains imports. */
1667
+ resolver?: SourceResolver;
1668
+ /** Stable, canonical identity for the main source (used in diagnostics + module graph). */
1669
+ sourceId?: string;
1670
+ /** Optional backend registry (defaults to the shared default registry). */
1671
+ registry?: BackendRegistry;
1672
+ /** Provenance map from statement to source file (used for imported diagnostics). */
1673
+ provenance?: Map<Statement, string>;
1674
+ }
1675
+ interface CompileSyncOptions extends CompileOptions {
1676
+ target: string;
1677
+ }
1678
+ interface CompileAsyncOptions extends CompileOptions {
1679
+ target: string;
1680
+ resolver: SourceResolver;
1681
+ }
1682
+ /**
1683
+ * Result of compiling a gl source file or AST.
1684
+ */
1685
+ interface CompileResult {
1686
+ code: string | null;
1687
+ shaders: ShaderArtifact[];
1688
+ ast: Program;
1689
+ diagnostics: Diagnostic[];
1690
+ target: string;
1691
+ }
1692
+ /**
1693
+ * Compiles a pre-built Program AST or single-file source (no imports) to the target language.
1694
+ *
1695
+ * This is the synchronous entry point. Source containing imports requires
1696
+ * `compileAsync` with an injected `SourceResolver`.
1697
+ *
1698
+ * @param options - Compilation options (target, file, and either `source` or `ast`).
1699
+ * @returns CompileResult indexed by the target.
1700
+ */
1701
+ declare function compileSync(options: CompileSyncOptions): CompileResult;
1702
+ /**
1703
+ * Compiles a gl source file or pre-built AST to the target language with async
1704
+ * module resolution. Resolves imports through the injected `SourceResolver`.
1705
+ *
1706
+ * @param options - Compilation options (target, resolver, and either `source` or `ast`).
1707
+ * @returns CompileResult indexed by the target.
1708
+ */
1709
+ declare function compileAsync(options: CompileAsyncOptions): Promise<CompileResult>;
1710
+ /**
1711
+ * Compiles a gl source file or pre-built AST to the target language.
1712
+ *
1713
+ * When `source` is given without imports, compiles synchronously. When `source`
1714
+ * contains imports, returns a diagnostic directing the caller to `compileAsync`.
1715
+ * When `ast` is given, skips parsing and import resolution.
1716
+ *
1717
+ * @deprecated Use `compileSync` or `compileAsync` explicitly.
1718
+ * @param options - Compilation options (target, file, and either `source` or `ast`).
1719
+ * @returns CompileResult indexed by the target.
1720
+ */
1721
+ declare function compile(options: CompileOptions): CompileResult;
1722
+
1723
+ export { type BackendCapabilities, type BackendOutput, BackendRegistry, type CodegenOptions, type CompileAsyncOptions, type CompileOptions, type CompileResult, type CompileSyncOptions, type Diagnostic, GLSL_450_CAPABILITIES, GLSL_ES_300_CAPABILITIES, type IRAlias, type IRAnonymousStruct, type IRArray, type IRArrayLiteral, type IRBinary, type IRBindingDecl, type IRBindingPattern, type IRBlock, type IRBlockExpr, type IRBreak, type IRCall, type IRCompoundAssign, type IRConditional, type IRContinue, type IRDiscard, type IRDoWhile, type IREntryPoint, type IREnumDecl, type IREnumRef, type IRExpression, type IRExpressionStmt, type IRField, type IRFnDecl, type IRFor, type IRForRange, type IRIdentifier, type IRIf, type IRImplBlock, type IRIndex, type IRLiteral, type IRLiteralKind, type IRLiteralPattern, type IRLoop, type IRMatch, type IRMatchArm, type IRMatrix, type IRMember, type IRModule, type IRModuleItem, type IRNewtypeDecl, type IRNullCoalescing, type IROpaque, type IROpaqueDecl, type IROption, type IRPanic, type IRParam, type IRPattern, type IRQuaternion, type IRResourceKind, type IRResult, type IRReturn, type IRSampler, type IRScalar, type IRScalarName, type IRSourceAttribution, type IRSourceFile, type IRSpan, type IRStage, type IRStatement, type IRStructDecl, type IRStructLiteral, type IRStructRef, type IRSwizzle, type IRTraitDecl, type IRTuple, type IRType, type IRTypeAlias, type IRUnary, type IRUnion, type IRUnreachable, type IRUpdate, type IRVarDecl, type IRVector, type IRWhile, type IRWildcardPattern, type ResourceKind, type ScalarTypeName, type ShaderArtifact, type ShaderCodegenBackend, type ShaderEntryPointReflection, type ShaderInterfaceVariable, type ShaderReflection, type ShaderResourceReflection, type ShaderSourceMap, type ShaderStage, type ShaderTarget, type ShaderUniformReflection, SourceResolver, WGSL_CAPABILITIES, aliasType, anonymousStructType, arm, arrayLiteral, arrayType, bf16, binary, bindingDecl, bindingPattern, block, blockExpr, boolLiteral, boolType, breakStmt, bvec2, bvec3, bvec4, call, capabilitiesFor, compile, compileAsync, compileSync, compoundAssign, conditional, continueStmt, createDefaultBackendRegistry, defaultRegistry, discardStmt, dmat3, doWhileStmt, dvec2, dvec3, dvec4, enumDecl, enumType, expressionStmt, f16, f32, f64, field, float, fnDecl, forStmt, generateGLSL, generateWGSL, getBackend, i16, i32, i64, i8, ident, ifStmt, implBlock, importDecl, index, int, ivec2, ivec3, ivec4, literalPattern, loopStmt, mainFn, mainVec4, mat2, mat2x3, mat3, mat3x2, mat4, match, matrixType, member, newtypeDecl, nullCoalescing, opaqueDecl, opaqueType, optionType, panicStmt, param, parse, program, quatType, rangeForStmt, resultType, returnStmt, sampler2D, sampler3D, samplerCube, samplerType, scalarIsSupported, scalarType, span, structDecl, structLiteral, structType, swizzle, tokenize, traitDecl, tupleType, typeAlias, typeCheck, u16, u32, u64, u8, unary, unionType, unreachableStmt, update, uvec2, uvec3, uvec4, varDecl, vec2, vec3, vec4, vectorType, whileStmt, wildcardPattern };