wesl 0.6.48 → 0.7.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/dist/index.d.ts +295 -214
- package/dist/index.js +2947 -1550
- package/package.json +6 -8
- package/src/AbstractElems.ts +81 -81
- package/src/Assertions.ts +5 -5
- package/src/BindIdents.ts +193 -319
- package/src/ClickableError.ts +3 -2
- package/src/Conditions.ts +2 -2
- package/src/LinkedWesl.ts +1 -1
- package/src/Linker.ts +4 -3
- package/src/LinkerUtil.ts +1 -1
- package/src/Logging.ts +165 -0
- package/src/LowerAndEmit.ts +278 -110
- package/src/ModulePathUtil.ts +59 -0
- package/src/ModuleResolver.ts +26 -62
- package/src/ParseError.ts +9 -0
- package/src/ParseWESL.ts +30 -94
- package/src/RawEmit.ts +1 -4
- package/src/Reflection.ts +1 -1
- package/src/Scope.ts +3 -0
- package/src/Span.ts +2 -0
- package/src/SrcMap.ts +208 -0
- package/src/Stream.ts +30 -0
- package/src/TransformBindingStructs.ts +2 -2
- package/src/Util.ts +1 -1
- package/src/debug/ASTtoString.ts +84 -135
- package/src/discovery/FindUnboundIdents.ts +14 -5
- package/src/index.ts +5 -0
- package/src/parse/ContentsHelpers.ts +70 -0
- package/src/parse/ExpressionUtil.ts +121 -0
- package/src/parse/Keywords.ts +12 -12
- package/src/parse/OperatorBinding.ts +146 -0
- package/src/parse/ParseAttribute.ts +272 -0
- package/src/parse/ParseCall.ts +77 -0
- package/src/parse/ParseControlFlow.ts +129 -0
- package/src/parse/ParseDirective.ts +105 -0
- package/src/parse/ParseExpression.ts +288 -0
- package/src/parse/ParseFn.ts +151 -0
- package/src/parse/ParseGlobalVar.ts +131 -0
- package/src/parse/ParseIdent.ts +77 -0
- package/src/parse/ParseImport.ts +160 -0
- package/src/parse/ParseLocalVar.ts +69 -0
- package/src/parse/ParseLoop.ts +112 -0
- package/src/parse/ParseModule.ts +116 -0
- package/src/parse/ParseSimpleStatement.ts +162 -0
- package/src/parse/ParseStatement.ts +215 -0
- package/src/parse/ParseStruct.ts +89 -0
- package/src/parse/ParseType.ts +71 -0
- package/src/parse/ParseUtil.ts +174 -0
- package/src/parse/ParseValueDeclaration.ts +130 -0
- package/src/parse/ParseWesl.ts +51 -0
- package/src/parse/ParsingContext.ts +93 -0
- package/src/parse/WeslStream.ts +63 -20
- package/src/parse/stream/CachingStream.ts +48 -0
- package/src/parse/stream/MatchersStream.ts +85 -0
- package/src/parse/stream/RegexHelpers.ts +38 -0
- package/src/test/BevyLink.test.ts +100 -0
- package/src/test/BindStdTypes.test.ts +110 -0
- package/src/test/{BindWESL.test.ts → BindWESLV2.test.ts} +21 -22
- package/src/test/BulkTests.test.ts +11 -12
- package/src/test/ConditionLinking.test.ts +107 -0
- package/src/test/ConditionalElif.test.ts +1 -13
- package/src/test/ConditionalTranslationCases.test.ts +5 -0
- package/src/test/ErrorLogging.test.ts +2 -2
- package/src/test/ImportCasesV2.test.ts +63 -0
- package/src/test/LinkFails.test.ts +69 -0
- package/src/test/LinkPackage.test.ts +1 -1
- package/src/test/Linker.test.ts +75 -2
- package/src/test/LogCatcher.ts +53 -0
- package/src/test/Mangling.test.ts +1 -1
- package/src/test/ParseComments.test.ts +1 -2
- package/src/test/{ParseConditions.test.ts → ParseConditionsV2.test.ts} +57 -49
- package/src/test/ParseErrorV2.test.ts +73 -0
- package/src/test/{ParseWESL.test.ts → ParseWeslV2.test.ts} +288 -370
- package/src/test/{ScopeWESL.test.ts → ScopeWESLV2.test.ts} +205 -176
- package/src/test/TestLink.ts +51 -51
- package/src/test/TestSetup.ts +9 -3
- package/src/test/TestUtil.ts +47 -77
- package/src/test/TrimmedMatch.ts +40 -0
- package/src/test/VirtualModules.test.ts +33 -2
- package/src/test/WeslDevice.test.ts +9 -2
- package/src/test/__snapshots__/ParseWeslV2.test.ts.snap +67 -0
- package/src/test-util.ts +7 -0
- package/src/WESLCollect.ts +0 -656
- package/src/parse/AttributeGrammar.ts +0 -232
- package/src/parse/ImportGrammar.ts +0 -195
- package/src/parse/WeslBaseGrammar.ts +0 -11
- package/src/parse/WeslExpression.ts +0 -231
- package/src/parse/WeslGrammar.ts +0 -739
- package/src/test/Expression.test.ts +0 -22
- package/src/test/ImportSyntaxCases.test.ts +0 -24
- package/src/test/ParseError.test.ts +0 -45
- package/src/test/Reflection.test.ts +0 -176
- package/src/test/TransformBindingStructs.test.ts +0 -238
- /package/src/test/{ParseElif.test.ts → ParseElifV2.test.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -17,11 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"mini-parse": "0.6.41"
|
|
22
|
-
},
|
|
23
20
|
"devDependencies": {
|
|
24
|
-
"@
|
|
21
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
25
22
|
"multi_pkg": "x",
|
|
26
23
|
"random_wgsl": "x",
|
|
27
24
|
"terser": "^5.43.1",
|
|
@@ -37,13 +34,14 @@
|
|
|
37
34
|
],
|
|
38
35
|
"scripts": {
|
|
39
36
|
"build": "tsdown",
|
|
40
|
-
"build:brotli-size": "./scripts/brotli.ts dist/sized.cjs",
|
|
41
37
|
"build:docs": "typedoc --plugin typedoc-theme-hierarchy --entryPoints ./src/index.ts --entryPointStrategy expand --out ./docs",
|
|
42
|
-
"build:
|
|
43
|
-
"build:
|
|
38
|
+
"build:nodebug": "vite build --config vite.nodebug.config.ts",
|
|
39
|
+
"build:size": "./scripts/size-check.ts",
|
|
44
40
|
"deploy:docsite": "run-s build:docs pages:deploy",
|
|
45
41
|
"pages:deploy": "wrangler pages deploy --project-name wesl-js docs",
|
|
46
42
|
"test": "vitest --hideSkippedTests",
|
|
43
|
+
"test:cts": "./scripts/test-cts.ts",
|
|
44
|
+
"test:nodebug": "vitest run --config vitest.nodebug.config.ts",
|
|
47
45
|
"test:once": "vitest run",
|
|
48
46
|
"typecheck": "tsgo"
|
|
49
47
|
},
|
package/src/AbstractElems.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type { Span } from "mini-parse";
|
|
2
1
|
import type { DeclIdent, RefIdent, Scope, SrcModule } from "./Scope.ts";
|
|
2
|
+
import type { Span } from "./Span.ts";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* AST structures describing 'interesting' parts of WESL source.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* are
|
|
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.
|
|
7
|
+
* Parts needing further analysis are pulled into these structures.
|
|
8
|
+
* Uninteresting parts are 'TextElem' nodes, copied to output WGSL.
|
|
13
9
|
*/
|
|
14
|
-
export type AbstractElem = GrammarElem | SyntheticElem;
|
|
10
|
+
export type AbstractElem = GrammarElem | SyntheticElem | ExpressionElem;
|
|
15
11
|
|
|
16
12
|
export type GrammarElem = ContainerElem | TerminalElem;
|
|
17
13
|
|
|
@@ -20,6 +16,7 @@ export type ContainerElem =
|
|
|
20
16
|
| AliasElem
|
|
21
17
|
| ConstAssertElem
|
|
22
18
|
| ConstElem
|
|
19
|
+
| ContinuingElem
|
|
23
20
|
| UnknownExpressionElem
|
|
24
21
|
| SimpleMemberRef
|
|
25
22
|
| FnElem
|
|
@@ -37,11 +34,29 @@ export type ContainerElem =
|
|
|
37
34
|
| StatementElem
|
|
38
35
|
| SwitchClauseElem;
|
|
39
36
|
|
|
37
|
+
/** Map from element kind string to element type, for type-safe element construction. */
|
|
38
|
+
export type ElemKindMap = {
|
|
39
|
+
alias: AliasElem;
|
|
40
|
+
assert: ConstAssertElem;
|
|
41
|
+
const: ConstElem;
|
|
42
|
+
continuing: ContinuingElem;
|
|
43
|
+
gvar: GlobalVarElem;
|
|
44
|
+
let: LetElem;
|
|
45
|
+
member: StructMemberElem;
|
|
46
|
+
override: OverrideElem;
|
|
47
|
+
param: FnParamElem;
|
|
48
|
+
statement: StatementElem;
|
|
49
|
+
struct: StructElem;
|
|
50
|
+
"switch-clause": SwitchClauseElem;
|
|
51
|
+
type: TypeRefElem;
|
|
52
|
+
var: VarElem;
|
|
53
|
+
};
|
|
54
|
+
|
|
40
55
|
/** Inspired by https://github.com/wgsl-tooling-wg/wesl-rs/blob/3b2434eac1b2ebda9eb8bfb25f43d8600d819872/crates/wgsl-parse/src/syntax.rs#L364 */
|
|
41
56
|
export type ExpressionElem =
|
|
42
57
|
| Literal
|
|
43
|
-
| TranslateTimeFeature
|
|
44
58
|
| RefIdentElem
|
|
59
|
+
| TypeRefElem // template_elaborated_ident is a primary_expression
|
|
45
60
|
| ParenthesizedExpression
|
|
46
61
|
| ComponentExpression
|
|
47
62
|
| ComponentMemberExpression
|
|
@@ -65,7 +80,11 @@ export type GlobalDeclarationElem =
|
|
|
65
80
|
| OverrideElem
|
|
66
81
|
| StructElem;
|
|
67
82
|
|
|
68
|
-
export type DeclarationElem =
|
|
83
|
+
export type DeclarationElem =
|
|
84
|
+
| GlobalDeclarationElem
|
|
85
|
+
| FnParamElem
|
|
86
|
+
| VarElem
|
|
87
|
+
| LetElem;
|
|
69
88
|
|
|
70
89
|
export type ElemWithAttributes = Extract<AbstractElem, HasAttributes>;
|
|
71
90
|
|
|
@@ -85,23 +104,13 @@ export interface HasAttributes {
|
|
|
85
104
|
|
|
86
105
|
/* ------ Terminal Elements (don't contain other elements) ------ */
|
|
87
106
|
|
|
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
|
-
*/
|
|
107
|
+
/** Raw text copied to linked WGSL (e.g., 'var' or '@diagnostic(off,derivative_uniformity)'). */
|
|
93
108
|
export interface TextElem extends AbstractElemBase {
|
|
94
109
|
kind: "text";
|
|
95
110
|
srcModule: SrcModule;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
|
-
/**
|
|
99
|
-
* e.g.
|
|
100
|
-
* - a struct member name
|
|
101
|
-
* - a diagnostic rule name
|
|
102
|
-
* - an enable-extension name
|
|
103
|
-
* - an interpolation sampling name
|
|
104
|
-
*/
|
|
113
|
+
/** A name that doesn't need to be an Ident (e.g., struct member, diagnostic rule). */
|
|
105
114
|
export interface NameElem extends AbstractElemBase {
|
|
106
115
|
kind: "name";
|
|
107
116
|
name: string;
|
|
@@ -127,47 +136,35 @@ export interface ImportElem extends AbstractElemBase, HasAttributes {
|
|
|
127
136
|
imports: ImportStatement;
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
/**
|
|
131
|
-
* An import statement, which is tree shaped.
|
|
132
|
-
* `import foo::bar::{baz, cat as neko};
|
|
133
|
-
*/
|
|
139
|
+
/** Tree-shaped import statement: `import foo::bar::{baz, cat as neko};` */
|
|
134
140
|
export interface ImportStatement {
|
|
135
141
|
kind: "import-statement";
|
|
136
142
|
segments: ImportSegment[];
|
|
137
143
|
finalSegment: ImportCollection | ImportItem;
|
|
138
144
|
}
|
|
139
145
|
|
|
140
|
-
/**
|
|
141
|
-
* A collection of import trees.
|
|
142
|
-
* `{baz, cat as neko}`
|
|
143
|
-
*/
|
|
146
|
+
/** A segment in an import path: `foo` in `foo::bar`. */
|
|
144
147
|
export interface ImportSegment {
|
|
145
148
|
kind: "import-segment";
|
|
146
149
|
name: string;
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
/**
|
|
150
|
-
* A primitive segment in an import statement.
|
|
151
|
-
* `foo`
|
|
152
|
-
*/
|
|
152
|
+
/** A collection of import trees: `{baz, cat as neko}`. */
|
|
153
153
|
export interface ImportCollection {
|
|
154
154
|
kind: "import-collection";
|
|
155
155
|
subtrees: ImportStatement[];
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
/**
|
|
159
|
-
* A renamed item at the end of an import statement.
|
|
160
|
-
* `cat as neko`
|
|
161
|
-
*/
|
|
158
|
+
/** A renamed item at the end of an import statement: `cat as neko`. */
|
|
162
159
|
export interface ImportItem {
|
|
163
160
|
kind: "import-item";
|
|
164
161
|
name: string;
|
|
165
162
|
as?: string;
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
/* ------ Synthetic element (for transformations, not
|
|
165
|
+
/* ------ Synthetic element (for transformations, not from grammar) ------ */
|
|
169
166
|
|
|
170
|
-
/**
|
|
167
|
+
/** Generated element produced after parsing and binding. */
|
|
171
168
|
export interface SyntheticElem {
|
|
172
169
|
kind: "synthetic";
|
|
173
170
|
text: string;
|
|
@@ -175,7 +172,7 @@ export interface SyntheticElem {
|
|
|
175
172
|
|
|
176
173
|
/* ------ Container Elements (contain other elements) ------ */
|
|
177
174
|
|
|
178
|
-
/**
|
|
175
|
+
/** A declaration identifier with an optional type. */
|
|
179
176
|
export interface TypedDeclElem extends ElemWithContentsBase {
|
|
180
177
|
kind: "typeDecl";
|
|
181
178
|
decl: DeclIdentElem;
|
|
@@ -183,14 +180,14 @@ export interface TypedDeclElem extends ElemWithContentsBase {
|
|
|
183
180
|
typeScope?: Scope;
|
|
184
181
|
}
|
|
185
182
|
|
|
186
|
-
/**
|
|
183
|
+
/** An alias statement. */
|
|
187
184
|
export interface AliasElem extends ElemWithContentsBase, HasAttributes {
|
|
188
185
|
kind: "alias";
|
|
189
186
|
name: DeclIdentElem;
|
|
190
187
|
typeRef: TypeRefElem;
|
|
191
188
|
}
|
|
192
189
|
|
|
193
|
-
/**
|
|
190
|
+
/** An attribute like '@compute' or '@binding(0)'. */
|
|
194
191
|
export interface AttributeElem extends ElemWithContentsBase {
|
|
195
192
|
kind: "attribute";
|
|
196
193
|
attribute: Attribute;
|
|
@@ -221,10 +218,12 @@ export interface BuiltinAttribute {
|
|
|
221
218
|
param: NameElem;
|
|
222
219
|
}
|
|
223
220
|
|
|
221
|
+
export type DiagnosticRule = [NameElem, NameElem | null];
|
|
222
|
+
|
|
224
223
|
export interface DiagnosticAttribute {
|
|
225
224
|
kind: "@diagnostic";
|
|
226
225
|
severity: NameElem;
|
|
227
|
-
rule:
|
|
226
|
+
rule: DiagnosticRule;
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
export interface IfAttribute {
|
|
@@ -241,82 +240,77 @@ export interface ElseAttribute {
|
|
|
241
240
|
kind: "@else";
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
|
|
243
|
+
export type ConditionalAttribute = IfAttribute | ElifAttribute | ElseAttribute;
|
|
244
|
+
|
|
245
|
+
/** A const_assert statement. */
|
|
245
246
|
export interface ConstAssertElem extends ElemWithContentsBase, HasAttributes {
|
|
246
247
|
kind: "assert";
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
/**
|
|
250
|
+
/** A const declaration. */
|
|
250
251
|
export interface ConstElem extends ElemWithContentsBase, HasAttributes {
|
|
251
252
|
kind: "const";
|
|
252
253
|
name: TypedDeclElem;
|
|
253
254
|
}
|
|
254
255
|
|
|
255
|
-
/**
|
|
256
|
+
/** An expression without special handling, used in attribute parameters. */
|
|
256
257
|
export interface UnknownExpressionElem extends ElemWithContentsBase {
|
|
257
258
|
kind: "expression";
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
/**
|
|
261
|
+
/** An expression that can be safely evaluated at compile time. */
|
|
261
262
|
export interface TranslateTimeExpressionElem {
|
|
262
263
|
kind: "translate-time-expression";
|
|
263
264
|
expression: ExpressionElem;
|
|
264
265
|
span: Span;
|
|
265
266
|
}
|
|
266
267
|
|
|
267
|
-
/** A literal value in WESL source.
|
|
268
|
-
export interface Literal {
|
|
268
|
+
/** A literal value (boolean or number) in WESL source. */
|
|
269
|
+
export interface Literal extends AbstractElemBase {
|
|
269
270
|
kind: "literal";
|
|
270
271
|
value: string;
|
|
271
|
-
span: Span;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/** `words`s inside `@if` */
|
|
275
|
-
export interface TranslateTimeFeature {
|
|
276
|
-
kind: "translate-time-feature";
|
|
277
|
-
name: string;
|
|
278
|
-
span: Span;
|
|
279
272
|
}
|
|
280
273
|
|
|
281
274
|
/** (expr) */
|
|
282
|
-
export interface ParenthesizedExpression {
|
|
275
|
+
export interface ParenthesizedExpression extends AbstractElemBase {
|
|
283
276
|
kind: "parenthesized-expression";
|
|
284
277
|
expression: ExpressionElem;
|
|
285
278
|
}
|
|
286
279
|
|
|
287
280
|
/** `foo[expr]` */
|
|
288
|
-
export interface ComponentExpression {
|
|
281
|
+
export interface ComponentExpression extends AbstractElemBase {
|
|
289
282
|
kind: "component-expression";
|
|
290
283
|
base: ExpressionElem;
|
|
291
284
|
access: ExpressionElem;
|
|
292
285
|
}
|
|
293
286
|
|
|
294
287
|
/** `foo.member` */
|
|
295
|
-
export interface ComponentMemberExpression {
|
|
288
|
+
export interface ComponentMemberExpression extends AbstractElemBase {
|
|
296
289
|
kind: "component-member-expression";
|
|
297
290
|
base: ExpressionElem;
|
|
298
291
|
access: NameElem;
|
|
299
292
|
}
|
|
300
293
|
|
|
301
294
|
/** `+foo` */
|
|
302
|
-
export interface UnaryExpression {
|
|
295
|
+
export interface UnaryExpression extends AbstractElemBase {
|
|
303
296
|
kind: "unary-expression";
|
|
304
297
|
operator: UnaryOperator;
|
|
305
298
|
expression: ExpressionElem;
|
|
306
299
|
}
|
|
307
300
|
|
|
308
301
|
/** `foo + bar` */
|
|
309
|
-
export interface BinaryExpression {
|
|
302
|
+
export interface BinaryExpression extends AbstractElemBase {
|
|
310
303
|
kind: "binary-expression";
|
|
311
304
|
operator: BinaryOperator;
|
|
312
305
|
left: ExpressionElem;
|
|
313
306
|
right: ExpressionElem;
|
|
314
307
|
}
|
|
315
308
|
|
|
316
|
-
/** `foo(arg, arg)` */
|
|
317
|
-
export interface FunctionCallExpression {
|
|
309
|
+
/** `foo<T>(arg, arg)` */
|
|
310
|
+
export interface FunctionCallExpression extends AbstractElemBase {
|
|
318
311
|
kind: "call-expression";
|
|
319
|
-
function: RefIdentElem;
|
|
312
|
+
function: RefIdentElem | TypeRefElem; // template_elaborated_ident
|
|
313
|
+
templateArgs?: TypeTemplateParameter[];
|
|
320
314
|
arguments: ExpressionElem[];
|
|
321
315
|
}
|
|
322
316
|
|
|
@@ -359,7 +353,7 @@ export interface RequiresDirective {
|
|
|
359
353
|
extensions: NameElem[];
|
|
360
354
|
}
|
|
361
355
|
|
|
362
|
-
/**
|
|
356
|
+
/** A function declaration. */
|
|
363
357
|
export interface FnElem extends ElemWithContentsBase, HasAttributes {
|
|
364
358
|
// LATER doesn't need contents
|
|
365
359
|
kind: "fn";
|
|
@@ -370,31 +364,30 @@ export interface FnElem extends ElemWithContentsBase, HasAttributes {
|
|
|
370
364
|
returnType?: TypeRefElem;
|
|
371
365
|
}
|
|
372
366
|
|
|
373
|
-
/**
|
|
367
|
+
/** A global variable declaration (at the root level). */
|
|
374
368
|
export interface GlobalVarElem extends ElemWithContentsBase, HasAttributes {
|
|
375
369
|
kind: "gvar";
|
|
376
370
|
name: TypedDeclElem;
|
|
377
371
|
}
|
|
378
372
|
|
|
379
|
-
/**
|
|
373
|
+
/** An entire file. */
|
|
380
374
|
export interface ModuleElem extends ElemWithContentsBase {
|
|
381
375
|
kind: "module";
|
|
382
376
|
}
|
|
383
377
|
|
|
384
|
-
/**
|
|
378
|
+
/** An override declaration. */
|
|
385
379
|
export interface OverrideElem extends ElemWithContentsBase, HasAttributes {
|
|
386
380
|
kind: "override";
|
|
387
381
|
name: TypedDeclElem;
|
|
388
382
|
}
|
|
389
383
|
|
|
390
|
-
/**
|
|
384
|
+
/** A parameter in a function declaration. */
|
|
391
385
|
export interface FnParamElem extends ElemWithContentsBase, HasAttributes {
|
|
392
386
|
kind: "param";
|
|
393
387
|
name: TypedDeclElem;
|
|
394
388
|
}
|
|
395
389
|
|
|
396
|
-
/**
|
|
397
|
-
* (used for transforming refs to binding structs) */
|
|
390
|
+
/** Simple struct references like `myStruct.bar` (for binding struct transforms). */
|
|
398
391
|
export interface SimpleMemberRef extends ElemWithContentsBase {
|
|
399
392
|
kind: "memberRef";
|
|
400
393
|
name: RefIdentElem;
|
|
@@ -402,7 +395,7 @@ export interface SimpleMemberRef extends ElemWithContentsBase {
|
|
|
402
395
|
extraComponents?: StuffElem;
|
|
403
396
|
}
|
|
404
397
|
|
|
405
|
-
/**
|
|
398
|
+
/** A struct declaration. */
|
|
406
399
|
export interface StructElem extends ElemWithContentsBase, HasAttributes {
|
|
407
400
|
kind: "struct";
|
|
408
401
|
name: DeclIdentElem;
|
|
@@ -410,18 +403,18 @@ export interface StructElem extends ElemWithContentsBase, HasAttributes {
|
|
|
410
403
|
bindingStruct?: true; // used later during binding struct transformation
|
|
411
404
|
}
|
|
412
405
|
|
|
413
|
-
/**
|
|
406
|
+
/** Generic container of other elements. */
|
|
414
407
|
export interface StuffElem extends ElemWithContentsBase {
|
|
415
408
|
kind: "stuff";
|
|
416
409
|
}
|
|
417
410
|
|
|
418
|
-
/**
|
|
411
|
+
/** A struct declaration marked as a binding struct. */
|
|
419
412
|
export interface BindingStructElem extends StructElem {
|
|
420
413
|
bindingStruct: true;
|
|
421
414
|
entryFn?: FnElem;
|
|
422
415
|
}
|
|
423
416
|
|
|
424
|
-
/**
|
|
417
|
+
/** A member of a struct declaration. */
|
|
425
418
|
export interface StructMemberElem extends ElemWithContentsBase, HasAttributes {
|
|
426
419
|
kind: "member";
|
|
427
420
|
name: NameElem;
|
|
@@ -429,16 +422,16 @@ export interface StructMemberElem extends ElemWithContentsBase, HasAttributes {
|
|
|
429
422
|
mangledVarName?: string; // root name if transformed to a var (for binding struct transformation)
|
|
430
423
|
}
|
|
431
424
|
|
|
432
|
-
export type TypeTemplateParameter =
|
|
425
|
+
export type TypeTemplateParameter = ExpressionElem;
|
|
433
426
|
|
|
434
|
-
/**
|
|
427
|
+
/** A type reference like 'f32', 'MyStruct', or 'ptr<storage, array<f32>, read_only>'. */
|
|
435
428
|
export interface TypeRefElem extends ElemWithContentsBase {
|
|
436
429
|
kind: "type";
|
|
437
430
|
name: RefIdent;
|
|
438
431
|
templateParams?: TypeTemplateParameter[];
|
|
439
432
|
}
|
|
440
433
|
|
|
441
|
-
/**
|
|
434
|
+
/** A variable declaration. */
|
|
442
435
|
export interface VarElem extends ElemWithContentsBase, HasAttributes {
|
|
443
436
|
kind: "var";
|
|
444
437
|
name: TypedDeclElem;
|
|
@@ -453,6 +446,13 @@ export interface StatementElem extends ElemWithContentsBase, HasAttributes {
|
|
|
453
446
|
kind: "statement";
|
|
454
447
|
}
|
|
455
448
|
|
|
449
|
+
export interface ContinuingElem extends ElemWithContentsBase, HasAttributes {
|
|
450
|
+
kind: "continuing";
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** Statement or continuing - used in loop body parsing. */
|
|
454
|
+
export type BlockStatement = StatementElem | ContinuingElem;
|
|
455
|
+
|
|
456
456
|
export interface SwitchClauseElem extends ElemWithContentsBase, HasAttributes {
|
|
457
457
|
kind: "switch-clause";
|
|
458
458
|
}
|
package/src/Assertions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { debug } from "./Logging.ts";
|
|
2
2
|
|
|
3
3
|
/** checks whether a condition is true, otherwise throws */
|
|
4
4
|
export function assertThat(condition: any, msg?: string): asserts condition {
|
|
@@ -7,17 +7,17 @@ export function assertThat(condition: any, msg?: string): asserts condition {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/** when debug
|
|
10
|
+
/** when debug is enabled, checks whether a condition is true, otherwise throws */
|
|
11
11
|
export function assertThatDebug(
|
|
12
12
|
condition: any,
|
|
13
13
|
msg?: string,
|
|
14
14
|
): asserts condition {
|
|
15
|
-
if (
|
|
15
|
+
if (debug) assertThat(condition, msg);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/** when debug
|
|
18
|
+
/** when debug is enabled throw an error */
|
|
19
19
|
export function failDebug(msg = "FAIL"): void {
|
|
20
|
-
if (
|
|
20
|
+
if (debug) throw new Error(msg);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|