wesl 0.6.0-pre10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index.js +4468 -0
- package/dist/index.js.map +1 -0
- package/dist/minified.js +3426 -0
- package/dist/minified.js.map +1 -0
- package/dist/tools/packages/wesl/src/AbstractElems.d.ts +322 -0
- package/dist/tools/packages/wesl/src/Assertions.d.ts +27 -0
- package/dist/tools/packages/wesl/src/BindIdents.d.ts +70 -0
- package/dist/tools/packages/wesl/src/Conditions.d.ts +6 -0
- package/dist/tools/packages/wesl/src/FlattenTreeImport.d.ts +11 -0
- package/dist/tools/packages/wesl/src/LinkedWesl.d.ts +50 -0
- package/dist/tools/packages/wesl/src/Linker.d.ts +87 -0
- package/dist/tools/packages/wesl/src/LinkerUtil.d.ts +3 -0
- package/dist/tools/packages/wesl/src/LiveDeclarations.d.ts +12 -0
- package/dist/tools/packages/wesl/src/LowerAndEmit.d.ts +31 -0
- package/dist/tools/packages/wesl/src/Mangler.d.ts +39 -0
- package/dist/tools/packages/wesl/src/ParseWESL.d.ts +60 -0
- package/dist/tools/packages/wesl/src/ParsedRegistry.d.ts +29 -0
- package/dist/tools/packages/wesl/src/PathUtil.d.ts +6 -0
- package/dist/tools/packages/wesl/src/RawEmit.d.ts +6 -0
- package/dist/tools/packages/wesl/src/Reflection.d.ts +45 -0
- package/dist/tools/packages/wesl/src/Scope.d.ts +81 -0
- package/dist/tools/packages/wesl/src/StandardTypes.d.ts +13 -0
- package/dist/tools/packages/wesl/src/TransformBindingStructs.d.ts +52 -0
- package/dist/tools/packages/wesl/src/Util.d.ts +43 -0
- package/dist/tools/packages/wesl/src/WESLCollect.d.ts +94 -0
- package/dist/tools/packages/wesl/src/WeslBundle.d.ts +13 -0
- package/dist/tools/packages/wesl/src/WeslDevice.d.ts +25 -0
- package/dist/tools/packages/wesl/src/debug/ASTtoString.d.ts +5 -0
- package/dist/tools/packages/wesl/src/debug/ImportToString.d.ts +2 -0
- package/dist/tools/packages/wesl/src/debug/LineWrapper.d.ts +21 -0
- package/dist/tools/packages/wesl/src/debug/ScopeToString.d.ts +6 -0
- package/dist/tools/packages/wesl/src/index.d.ts +11 -0
- package/dist/tools/packages/wesl/src/parse/ImportGrammar.d.ts +5 -0
- package/dist/tools/packages/wesl/src/parse/Keywords.d.ts +4 -0
- package/dist/tools/packages/wesl/src/parse/WeslBaseGrammar.d.ts +5 -0
- package/dist/tools/packages/wesl/src/parse/WeslExpression.d.ts +13 -0
- package/dist/tools/packages/wesl/src/parse/WeslGrammar.d.ts +80 -0
- package/dist/tools/packages/wesl/src/parse/WeslStream.d.ts +44 -0
- package/dist/tools/packages/wesl/src/test/BindWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ConditionLinking.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ConditionalTranslationCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ErrorLogging.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Expression.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/FlattenTreeImport.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ImportCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ImportSyntaxCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/LinkGlob.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/LinkPackage.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Linker.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Mangling.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseComments.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseConditions.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseError.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/PathUtil.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/PrettyGrammar.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Reflection.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ScopeWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TestLink.d.ts +21 -0
- package/dist/tools/packages/wesl/src/test/TestSetup.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TestUtil.d.ts +40 -0
- package/dist/tools/packages/wesl/src/test/Tokenizer.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TransformBindingStructs.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Util.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/VirtualModules.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/WeslDevice.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/WgslTests.d.ts +0 -0
- package/dist/tools/packages/wesl/src/vlq/vlq.d.ts +11 -0
- package/package.json +46 -0
- package/src/AbstractElems.ts +446 -0
- package/src/Assertions.ts +51 -0
- package/src/BindIdents.ts +523 -0
- package/src/Conditions.ts +74 -0
- package/src/FlattenTreeImport.ts +55 -0
- package/src/LinkedWesl.ts +184 -0
- package/src/Linker.ts +284 -0
- package/src/LinkerUtil.ts +29 -0
- package/src/LiveDeclarations.ts +31 -0
- package/src/LowerAndEmit.ts +413 -0
- package/src/Mangler.ts +94 -0
- package/src/ParseWESL.ts +157 -0
- package/src/ParsedRegistry.ts +120 -0
- package/src/PathUtil.ts +31 -0
- package/src/RawEmit.ts +102 -0
- package/src/Reflection.ts +334 -0
- package/src/Scope.ts +162 -0
- package/src/StandardTypes.ts +97 -0
- package/src/TransformBindingStructs.ts +319 -0
- package/src/Util.ts +194 -0
- package/src/WESLCollect.ts +614 -0
- package/src/WeslBundle.ts +16 -0
- package/src/WeslDevice.ts +209 -0
- package/src/debug/ASTtoString.ts +290 -0
- package/src/debug/ImportToString.ts +29 -0
- package/src/debug/LineWrapper.ts +70 -0
- package/src/debug/ScopeToString.ts +79 -0
- package/src/index.ts +11 -0
- package/src/parse/ImportGrammar.ts +157 -0
- package/src/parse/Keywords.ts +26 -0
- package/src/parse/WeslBaseGrammar.ts +8 -0
- package/src/parse/WeslExpression.ts +207 -0
- package/src/parse/WeslGrammar.ts +856 -0
- package/src/parse/WeslStream.ts +279 -0
- package/src/test/BindWESL.test.ts +57 -0
- package/src/test/ConditionLinking.test.ts +91 -0
- package/src/test/ConditionalTranslationCases.test.ts +56 -0
- package/src/test/ErrorLogging.test.ts +30 -0
- package/src/test/Expression.test.ts +22 -0
- package/src/test/FlattenTreeImport.test.ts +74 -0
- package/src/test/ImportCases.test.ts +56 -0
- package/src/test/ImportSyntaxCases.test.ts +24 -0
- package/src/test/LinkGlob.test.ts +25 -0
- package/src/test/LinkPackage.test.ts +26 -0
- package/src/test/Linker.test.ts +125 -0
- package/src/test/Mangling.test.ts +45 -0
- package/src/test/ParseComments.test.ts +36 -0
- package/src/test/ParseConditions.test.ts +183 -0
- package/src/test/ParseError.test.ts +36 -0
- package/src/test/ParseWESL.test.ts +1572 -0
- package/src/test/PathUtil.test.ts +34 -0
- package/src/test/PrettyGrammar.test.ts +20 -0
- package/src/test/Reflection.test.ts +172 -0
- package/src/test/ScopeWESL.test.ts +462 -0
- package/src/test/TestLink.ts +82 -0
- package/src/test/TestSetup.ts +4 -0
- package/src/test/TestUtil.ts +126 -0
- package/src/test/Tokenizer.test.ts +135 -0
- package/src/test/TransformBindingStructs.test.ts +230 -0
- package/src/test/Util.test.ts +22 -0
- package/src/test/VirtualModules.test.ts +37 -0
- package/src/test/WeslDevice.test.ts +265 -0
- package/src/test/WgslTests.ts +0 -0
- package/src/test/__snapshots__/ParseDirectives.test.ts.snap +25 -0
- package/src/test/__snapshots__/ParseWESL.test.ts.snap +119 -0
- package/src/test/__snapshots__/RustDirective.test.ts.snap +359 -0
- package/src/test/wgsl_1/main.wgsl +3 -0
- package/src/test/wgsl_1/util.wgsl +1 -0
- package/src/test/wgsl_2/main2.wgsl +3 -0
- package/src/test/wgsl_2/util2.wgsl +1 -0
- package/src/vlq/vlq.ts +94 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { Span } from "mini-parse";
|
|
2
|
+
import { DeclIdent, RefIdent, SrcModule } from "./Scope.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Structures to describe the 'interesting' parts of a WESL source file.
|
|
6
|
+
*
|
|
7
|
+
* The parts of the source that need to analyze further in the linker
|
|
8
|
+
* are pulled out into these structures.
|
|
9
|
+
*
|
|
10
|
+
* The parts that are uninteresting the the linker are recorded
|
|
11
|
+
* as 'TextElem' nodes, which are generally just copied to the output WGSL
|
|
12
|
+
* along with their containing element.
|
|
13
|
+
*/
|
|
14
|
+
export type AbstractElem = GrammarElem | SyntheticElem;
|
|
15
|
+
|
|
16
|
+
export type GrammarElem = ContainerElem | TerminalElem;
|
|
17
|
+
|
|
18
|
+
export type ContainerElem =
|
|
19
|
+
| AttributeElem
|
|
20
|
+
| AliasElem
|
|
21
|
+
| ConstAssertElem
|
|
22
|
+
| ConstElem
|
|
23
|
+
| UnknownExpressionElem
|
|
24
|
+
| SimpleMemberRef
|
|
25
|
+
| FnElem
|
|
26
|
+
| TypedDeclElem
|
|
27
|
+
| GlobalVarElem
|
|
28
|
+
| LetElem
|
|
29
|
+
| ModuleElem
|
|
30
|
+
| OverrideElem
|
|
31
|
+
| FnParamElem
|
|
32
|
+
| StructElem
|
|
33
|
+
| StructMemberElem
|
|
34
|
+
| StuffElem
|
|
35
|
+
| TypeRefElem
|
|
36
|
+
| VarElem
|
|
37
|
+
| StatementElem
|
|
38
|
+
| SwitchClauseElem;
|
|
39
|
+
|
|
40
|
+
/** Inspired by https://github.com/wgsl-tooling-wg/wesl-rs/blob/3b2434eac1b2ebda9eb8bfb25f43d8600d819872/crates/wgsl-parse/src/syntax.rs#L364 */
|
|
41
|
+
export type ExpressionElem =
|
|
42
|
+
| Literal
|
|
43
|
+
| TranslateTimeFeature
|
|
44
|
+
| RefIdentElem
|
|
45
|
+
| ParenthesizedExpression
|
|
46
|
+
| ComponentExpression
|
|
47
|
+
| ComponentMemberExpression
|
|
48
|
+
| UnaryExpression
|
|
49
|
+
| BinaryExpression
|
|
50
|
+
| FunctionCallExpression;
|
|
51
|
+
|
|
52
|
+
export type TerminalElem =
|
|
53
|
+
| DirectiveElem
|
|
54
|
+
| DeclIdentElem //
|
|
55
|
+
| NameElem
|
|
56
|
+
| RefIdentElem
|
|
57
|
+
| TextElem
|
|
58
|
+
| ImportElem;
|
|
59
|
+
|
|
60
|
+
export type GlobalDeclarationElem =
|
|
61
|
+
| AliasElem
|
|
62
|
+
| ConstElem
|
|
63
|
+
| FnElem
|
|
64
|
+
| GlobalVarElem
|
|
65
|
+
| OverrideElem
|
|
66
|
+
| StructElem;
|
|
67
|
+
|
|
68
|
+
export type DeclarationElem = GlobalDeclarationElem | FnParamElem | VarElem;
|
|
69
|
+
|
|
70
|
+
export type ElemWithAttributes = Extract<AbstractElem, HasAttributes>;
|
|
71
|
+
|
|
72
|
+
export interface AbstractElemBase {
|
|
73
|
+
kind: AbstractElem["kind"];
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ElemWithContentsBase extends AbstractElemBase {
|
|
79
|
+
contents: AbstractElem[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface HasAttributes {
|
|
83
|
+
attributes?: AttributeElem[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* ------ Terminal Elements (don't contain other elements) ------ */
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* a raw bit of text in WESL source that's typically copied to the linked WGSL.
|
|
90
|
+
* e.g. a keyword like 'var'
|
|
91
|
+
* or a phrase we needn't analyze further like '@diagnostic(off,derivative_uniformity)'
|
|
92
|
+
*/
|
|
93
|
+
export interface TextElem extends AbstractElemBase {
|
|
94
|
+
kind: "text";
|
|
95
|
+
srcModule: SrcModule;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** a name that doesn't need to be an Ident
|
|
99
|
+
* e.g.
|
|
100
|
+
* - a struct member name
|
|
101
|
+
* - a diagnostic rule name
|
|
102
|
+
* - an enable-extension name
|
|
103
|
+
* - an interpolation sampling name
|
|
104
|
+
*/
|
|
105
|
+
export interface NameElem extends AbstractElemBase {
|
|
106
|
+
kind: "name";
|
|
107
|
+
name: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** an identifier that 'refers to' a declaration (aka a symbol reference) */
|
|
111
|
+
export interface RefIdentElem extends AbstractElemBase {
|
|
112
|
+
kind: RefIdent["kind"];
|
|
113
|
+
ident: RefIdent;
|
|
114
|
+
srcModule: SrcModule;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** a declaration identifier (aka a symbol declaration) */
|
|
118
|
+
export interface DeclIdentElem extends AbstractElemBase {
|
|
119
|
+
kind: DeclIdent["kind"];
|
|
120
|
+
ident: DeclIdent;
|
|
121
|
+
srcModule: SrcModule;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Holds an import statement, and has a span */
|
|
125
|
+
export interface ImportElem extends AbstractElemBase {
|
|
126
|
+
kind: "import";
|
|
127
|
+
imports: ImportStatement;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* An import statement, which is tree shaped.
|
|
132
|
+
* `import foo::bar::{baz, cat as neko};
|
|
133
|
+
*/
|
|
134
|
+
export interface ImportStatement {
|
|
135
|
+
kind: "import-statement";
|
|
136
|
+
segments: ImportSegment[];
|
|
137
|
+
finalSegment: ImportCollection | ImportItem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A collection of import trees.
|
|
142
|
+
* `{baz, cat as neko}`
|
|
143
|
+
*/
|
|
144
|
+
export interface ImportSegment {
|
|
145
|
+
kind: "import-segment";
|
|
146
|
+
name: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A primitive segment in an import statement.
|
|
151
|
+
* `foo`
|
|
152
|
+
*/
|
|
153
|
+
export interface ImportCollection {
|
|
154
|
+
kind: "import-collection";
|
|
155
|
+
subtrees: ImportStatement[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A renamed item at the end of an import statement.
|
|
160
|
+
* `cat as neko`
|
|
161
|
+
*/
|
|
162
|
+
export interface ImportItem {
|
|
163
|
+
kind: "import-item";
|
|
164
|
+
name: string;
|
|
165
|
+
as?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* ------ Synthetic element (for transformations, not produced by grammar) ------ */
|
|
169
|
+
|
|
170
|
+
/** generated element, produced after parsing and binding */
|
|
171
|
+
export interface SyntheticElem {
|
|
172
|
+
kind: "synthetic";
|
|
173
|
+
text: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* ------ Container Elements (contain other elements) ------ */
|
|
177
|
+
|
|
178
|
+
/** a declaration identifer with a possible type */
|
|
179
|
+
export interface TypedDeclElem extends ElemWithContentsBase {
|
|
180
|
+
kind: "typeDecl";
|
|
181
|
+
decl: DeclIdentElem;
|
|
182
|
+
typeRef?: TypeRefElem; // TODO Consider a variant for fn params and alias where typeRef is required
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** an alias statement */
|
|
186
|
+
export interface AliasElem extends ElemWithContentsBase, HasAttributes {
|
|
187
|
+
kind: "alias";
|
|
188
|
+
name: DeclIdentElem;
|
|
189
|
+
typeRef: TypeRefElem;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** an attribute like '@compute' or '@binding(0)' */
|
|
193
|
+
export interface AttributeElem extends ElemWithContentsBase {
|
|
194
|
+
kind: "attribute";
|
|
195
|
+
attribute: Attribute;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type Attribute =
|
|
199
|
+
| StandardAttribute
|
|
200
|
+
| InterpolateAttribute
|
|
201
|
+
| BuiltinAttribute
|
|
202
|
+
| DiagnosticAttribute
|
|
203
|
+
| IfAttribute;
|
|
204
|
+
|
|
205
|
+
export interface StandardAttribute {
|
|
206
|
+
kind: "@attribute";
|
|
207
|
+
name: string;
|
|
208
|
+
params?: UnknownExpressionElem[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface InterpolateAttribute {
|
|
212
|
+
kind: "@interpolate";
|
|
213
|
+
params: NameElem[];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface BuiltinAttribute {
|
|
217
|
+
kind: "@builtin";
|
|
218
|
+
param: NameElem;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface DiagnosticAttribute {
|
|
222
|
+
kind: "@diagnostic";
|
|
223
|
+
severity: NameElem;
|
|
224
|
+
rule: [NameElem, NameElem | null];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface IfAttribute {
|
|
228
|
+
kind: "@if";
|
|
229
|
+
param: TranslateTimeExpressionElem;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** a const_assert statement */
|
|
233
|
+
export interface ConstAssertElem extends ElemWithContentsBase, HasAttributes {
|
|
234
|
+
kind: "assert";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** a const declaration */
|
|
238
|
+
export interface ConstElem extends ElemWithContentsBase, HasAttributes {
|
|
239
|
+
kind: "const";
|
|
240
|
+
name: TypedDeclElem;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** an expression w/o special handling, used inside attribute parameters */
|
|
244
|
+
export interface UnknownExpressionElem extends ElemWithContentsBase {
|
|
245
|
+
kind: "expression";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** an expression that can be safely evaluated at compile time */
|
|
249
|
+
export interface TranslateTimeExpressionElem {
|
|
250
|
+
kind: "translate-time-expression";
|
|
251
|
+
expression: ExpressionElem;
|
|
252
|
+
span: Span;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** A literal value in WESL source. A boolean or a number. */
|
|
256
|
+
export interface Literal {
|
|
257
|
+
kind: "literal";
|
|
258
|
+
value: string;
|
|
259
|
+
span: Span;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** `words`s inside `@if` */
|
|
263
|
+
export interface TranslateTimeFeature {
|
|
264
|
+
kind: "translate-time-feature";
|
|
265
|
+
name: string;
|
|
266
|
+
span: Span;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** (expr) */
|
|
270
|
+
export interface ParenthesizedExpression {
|
|
271
|
+
kind: "parenthesized-expression";
|
|
272
|
+
expression: ExpressionElem;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** `foo[expr]` */
|
|
276
|
+
export interface ComponentExpression {
|
|
277
|
+
kind: "component-expression";
|
|
278
|
+
base: ExpressionElem;
|
|
279
|
+
access: ExpressionElem;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** `foo.member` */
|
|
283
|
+
export interface ComponentMemberExpression {
|
|
284
|
+
kind: "component-member-expression";
|
|
285
|
+
base: ExpressionElem;
|
|
286
|
+
access: NameElem;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** `+foo` */
|
|
290
|
+
export interface UnaryExpression {
|
|
291
|
+
kind: "unary-expression";
|
|
292
|
+
operator: UnaryOperator;
|
|
293
|
+
expression: ExpressionElem;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** `foo + bar` */
|
|
297
|
+
export interface BinaryExpression {
|
|
298
|
+
kind: "binary-expression";
|
|
299
|
+
operator: BinaryOperator;
|
|
300
|
+
left: ExpressionElem;
|
|
301
|
+
right: ExpressionElem;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** `foo(arg, arg)` */
|
|
305
|
+
export interface FunctionCallExpression {
|
|
306
|
+
kind: "call-expression";
|
|
307
|
+
function: RefIdentElem;
|
|
308
|
+
arguments: ExpressionElem[];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface UnaryOperator {
|
|
312
|
+
value: "!" | "&" | "*" | "-" | "~";
|
|
313
|
+
span: Span;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface BinaryOperator {
|
|
317
|
+
value:
|
|
318
|
+
| ("||" | "&&" | "+" | "-" | "*" | "/" | "%" | "==")
|
|
319
|
+
| ("!=" | "<" | "<=" | ">" | ">=" | "|" | "&" | "^")
|
|
320
|
+
| ("<<" | ">>");
|
|
321
|
+
span: Span;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export type DirectiveVariant =
|
|
325
|
+
| DiagnosticDirective
|
|
326
|
+
| EnableDirective
|
|
327
|
+
| RequiresDirective;
|
|
328
|
+
|
|
329
|
+
export interface DirectiveElem extends AbstractElemBase, HasAttributes {
|
|
330
|
+
kind: "directive";
|
|
331
|
+
directive: DirectiveVariant;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface DiagnosticDirective {
|
|
335
|
+
kind: "diagnostic";
|
|
336
|
+
severity: NameElem;
|
|
337
|
+
rule: [NameElem, NameElem | null];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface EnableDirective {
|
|
341
|
+
kind: "enable";
|
|
342
|
+
extensions: NameElem[];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface RequiresDirective {
|
|
346
|
+
kind: "requires";
|
|
347
|
+
extensions: NameElem[];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** a function declaration */
|
|
351
|
+
export interface FnElem extends ElemWithContentsBase, HasAttributes {
|
|
352
|
+
// LATER doesn't need contents
|
|
353
|
+
kind: "fn";
|
|
354
|
+
name: DeclIdentElem;
|
|
355
|
+
params: FnParamElem[];
|
|
356
|
+
body: StatementElem;
|
|
357
|
+
returnAttributes?: AttributeElem[];
|
|
358
|
+
returnType?: TypeRefElem;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** a global variable declaration (at the root level) */
|
|
362
|
+
export interface GlobalVarElem extends ElemWithContentsBase, HasAttributes {
|
|
363
|
+
kind: "gvar";
|
|
364
|
+
name: TypedDeclElem;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** an entire file */
|
|
368
|
+
export interface ModuleElem extends ElemWithContentsBase {
|
|
369
|
+
kind: "module";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** an override declaration */
|
|
373
|
+
export interface OverrideElem extends ElemWithContentsBase, HasAttributes {
|
|
374
|
+
kind: "override";
|
|
375
|
+
name: TypedDeclElem;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** a parameter in a function declaration */
|
|
379
|
+
export interface FnParamElem extends ElemWithContentsBase, HasAttributes {
|
|
380
|
+
kind: "param";
|
|
381
|
+
name: TypedDeclElem;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** simple references to structures, like myStruct.bar
|
|
385
|
+
* (used for transforming refs to binding structs) */
|
|
386
|
+
export interface SimpleMemberRef extends ElemWithContentsBase {
|
|
387
|
+
kind: "memberRef";
|
|
388
|
+
name: RefIdentElem;
|
|
389
|
+
member: NameElem;
|
|
390
|
+
extraComponents?: StuffElem;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** a struct declaration */
|
|
394
|
+
export interface StructElem extends ElemWithContentsBase, HasAttributes {
|
|
395
|
+
kind: "struct";
|
|
396
|
+
name: DeclIdentElem;
|
|
397
|
+
members: StructMemberElem[];
|
|
398
|
+
bindingStruct?: true; // used later during binding struct transformation
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** generic container of other elements */
|
|
402
|
+
export interface StuffElem extends ElemWithContentsBase {
|
|
403
|
+
kind: "stuff";
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** a struct declaration that's been marked as a bindingStruct */
|
|
407
|
+
export interface BindingStructElem extends StructElem {
|
|
408
|
+
bindingStruct: true;
|
|
409
|
+
entryFn?: FnElem;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** a member of a struct declaration */
|
|
413
|
+
export interface StructMemberElem extends ElemWithContentsBase, HasAttributes {
|
|
414
|
+
kind: "member";
|
|
415
|
+
name: NameElem;
|
|
416
|
+
typeRef: TypeRefElem;
|
|
417
|
+
mangledVarName?: string; // root name if transformed to a var (for binding struct transformation)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export type TypeTemplateParameter = TypeRefElem | UnknownExpressionElem;
|
|
421
|
+
|
|
422
|
+
/** a reference to a type, like 'f32', or 'MyStruct', or 'ptr<storage, array<f32>, read_only>' */
|
|
423
|
+
export interface TypeRefElem extends ElemWithContentsBase {
|
|
424
|
+
kind: "type";
|
|
425
|
+
name: RefIdent;
|
|
426
|
+
templateParams?: TypeTemplateParameter[];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** a variable declaration */
|
|
430
|
+
export interface VarElem extends ElemWithContentsBase, HasAttributes {
|
|
431
|
+
kind: "var";
|
|
432
|
+
name: TypedDeclElem;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface LetElem extends ElemWithContentsBase, HasAttributes {
|
|
436
|
+
kind: "let";
|
|
437
|
+
name: TypedDeclElem;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface StatementElem extends ElemWithContentsBase, HasAttributes {
|
|
441
|
+
kind: "statement";
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface SwitchClauseElem extends ElemWithContentsBase, HasAttributes {
|
|
445
|
+
kind: "switch-clause";
|
|
446
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { tracing } from "mini-parse";
|
|
2
|
+
|
|
3
|
+
/** checks whether a condition is true, otherwise throws */
|
|
4
|
+
export function assertThat(condition: any, msg?: string): asserts condition {
|
|
5
|
+
if (!condition) {
|
|
6
|
+
throw new Error(msg);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** when debug testing is enabled, checks whether a condition is true, otherwise throws */
|
|
11
|
+
export function assertThatDebug(
|
|
12
|
+
condition: any,
|
|
13
|
+
msg?: string,
|
|
14
|
+
): asserts condition {
|
|
15
|
+
tracing && assertThat(condition, msg);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** when debug testing is enabled throw an error */
|
|
19
|
+
export function failDebug(msg = "FAIL"): void {
|
|
20
|
+
if (tracing) throw new Error(msg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Typescript will complain at compile time if it thinks this could be executed.
|
|
25
|
+
* Useful to validate that all cases are handled.
|
|
26
|
+
*
|
|
27
|
+
* Does nothing at runtime.
|
|
28
|
+
*/
|
|
29
|
+
export function assertUnreachableSilent(_value: never): void {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Useful to validate that all cases are handled,
|
|
33
|
+
* TypeScript should complain if this statement could possibly be executed.
|
|
34
|
+
*
|
|
35
|
+
* If this is somehow executed at runtime, throw an exception.
|
|
36
|
+
*/
|
|
37
|
+
export function assertUnreachable(value: never): never {
|
|
38
|
+
throw new ErrorWithData("Unreachable value", { data: value }); // LATER optimize code size by reporting less in non debug builds
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ErrorWithDataOptions extends ErrorOptions {
|
|
42
|
+
data: any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class ErrorWithData extends Error {
|
|
46
|
+
data: any;
|
|
47
|
+
constructor(message?: string, options?: ErrorWithDataOptions) {
|
|
48
|
+
super(message, options);
|
|
49
|
+
this.data = options?.data;
|
|
50
|
+
}
|
|
51
|
+
}
|