@vizabi/bubblechart 5.4.2 → 5.4.3
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/build/bubblechart.css +8 -4
- package/build/bubblechart.js +12 -4081
- package/build/bubblechart.js.map +1 -1
- package/build/stats.html +2540 -1625
- package/package.json +1 -1
package/build/bubblechart.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// https://github.com/vizabi/bubblechart#readme v5.4.
|
|
1
|
+
// https://github.com/vizabi/bubblechart#readme v5.4.3 build 1763849734772 Copyright 2025 Gapminder Foundation and contributors
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@vizabi/shared-components'), require('d3'), require('mobx')) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports', '@vizabi/shared-components', 'd3', 'mobx'], factory) :
|
|
@@ -1826,7 +1826,7 @@ in a later version. Use \`${newUsage}\` instead`);
|
|
|
1826
1826
|
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
1827
1827
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
1828
1828
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
1829
|
-
const VERSION$4 = "4.3.
|
|
1829
|
+
const VERSION$4 = "4.3.3" ;
|
|
1830
1830
|
const version = VERSION$4[0] >= '0' && VERSION$4[0] <= '9' ? `v${VERSION$4}` : '';
|
|
1831
1831
|
// Make sure we set the global variable
|
|
1832
1832
|
function createLog() {
|
|
@@ -1884,7 +1884,7 @@ in a later version. Use \`${newUsage}\` instead`);
|
|
|
1884
1884
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
1885
1885
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
1886
1886
|
{
|
|
1887
|
-
globalThis._loadersgl_.version = "4.3.
|
|
1887
|
+
globalThis._loadersgl_.version = "4.3.3";
|
|
1888
1888
|
}
|
|
1889
1889
|
}
|
|
1890
1890
|
return globalThis._loadersgl_.version;
|
|
@@ -4331,7 +4331,7 @@ try {
|
|
|
4331
4331
|
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
4332
4332
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
4333
4333
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4334
|
-
const VERSION$2 = "4.3.
|
|
4334
|
+
const VERSION$2 = "4.3.3" ;
|
|
4335
4335
|
|
|
4336
4336
|
// @ts-ignore TS2339: Property does not exist on type
|
|
4337
4337
|
const parseImageNode = globalThis.loaders?.parseImageNode;
|
|
@@ -9112,4079 +9112,7 @@ ${htmlLog}
|
|
|
9112
9112
|
: clearTimeout(timerId);
|
|
9113
9113
|
}
|
|
9114
9114
|
|
|
9115
|
-
class ParseContext {
|
|
9116
|
-
constructor() {
|
|
9117
|
-
this.constants = new Map();
|
|
9118
|
-
this.aliases = new Map();
|
|
9119
|
-
this.structs = new Map();
|
|
9120
|
-
}
|
|
9121
|
-
}
|
|
9122
|
-
/**
|
|
9123
|
-
* @class Node
|
|
9124
|
-
* @category AST
|
|
9125
|
-
* Base class for AST nodes parsed from a WGSL shader.
|
|
9126
|
-
*/
|
|
9127
|
-
class Node {
|
|
9128
|
-
constructor() { }
|
|
9129
|
-
get isAstNode() {
|
|
9130
|
-
return true;
|
|
9131
|
-
}
|
|
9132
|
-
get astNodeType() {
|
|
9133
|
-
return "";
|
|
9134
|
-
}
|
|
9135
|
-
evaluate(context) {
|
|
9136
|
-
throw new Error("Cannot evaluate node");
|
|
9137
|
-
}
|
|
9138
|
-
evaluateString(context) {
|
|
9139
|
-
return this.evaluate(context).toString();
|
|
9140
|
-
}
|
|
9141
|
-
search(callback) { }
|
|
9142
|
-
searchBlock(block, callback) {
|
|
9143
|
-
if (block) {
|
|
9144
|
-
callback(_BlockStart.instance);
|
|
9145
|
-
for (const node of block) {
|
|
9146
|
-
if (node instanceof Array) {
|
|
9147
|
-
this.searchBlock(node, callback);
|
|
9148
|
-
}
|
|
9149
|
-
else {
|
|
9150
|
-
node.search(callback);
|
|
9151
|
-
}
|
|
9152
|
-
}
|
|
9153
|
-
callback(_BlockEnd.instance);
|
|
9154
|
-
}
|
|
9155
|
-
}
|
|
9156
|
-
}
|
|
9157
|
-
// For internal use only
|
|
9158
|
-
class _BlockStart extends Node {
|
|
9159
|
-
}
|
|
9160
|
-
_BlockStart.instance = new _BlockStart();
|
|
9161
|
-
// For internal use only
|
|
9162
|
-
class _BlockEnd extends Node {
|
|
9163
|
-
}
|
|
9164
|
-
_BlockEnd.instance = new _BlockEnd();
|
|
9165
|
-
/**
|
|
9166
|
-
* @class Statement
|
|
9167
|
-
* @extends Node
|
|
9168
|
-
* @category AST
|
|
9169
|
-
*/
|
|
9170
|
-
class Statement extends Node {
|
|
9171
|
-
constructor() {
|
|
9172
|
-
super();
|
|
9173
|
-
}
|
|
9174
|
-
}
|
|
9175
|
-
/**
|
|
9176
|
-
* @class Function
|
|
9177
|
-
* @extends Statement
|
|
9178
|
-
* @category AST
|
|
9179
|
-
*/
|
|
9180
|
-
class Function extends Statement {
|
|
9181
|
-
constructor(name, args, returnType, body, startLine, endLine) {
|
|
9182
|
-
super();
|
|
9183
|
-
this.calls = new Set();
|
|
9184
|
-
this.name = name;
|
|
9185
|
-
this.args = args;
|
|
9186
|
-
this.returnType = returnType;
|
|
9187
|
-
this.body = body;
|
|
9188
|
-
this.startLine = startLine;
|
|
9189
|
-
this.endLine = endLine;
|
|
9190
|
-
}
|
|
9191
|
-
get astNodeType() {
|
|
9192
|
-
return "function";
|
|
9193
|
-
}
|
|
9194
|
-
search(callback) {
|
|
9195
|
-
this.searchBlock(this.body, callback);
|
|
9196
|
-
}
|
|
9197
|
-
}
|
|
9198
|
-
/**
|
|
9199
|
-
* @class StaticAssert
|
|
9200
|
-
* @extends Statement
|
|
9201
|
-
* @category AST
|
|
9202
|
-
*/
|
|
9203
|
-
class StaticAssert extends Statement {
|
|
9204
|
-
constructor(expression) {
|
|
9205
|
-
super();
|
|
9206
|
-
this.expression = expression;
|
|
9207
|
-
}
|
|
9208
|
-
get astNodeType() {
|
|
9209
|
-
return "staticAssert";
|
|
9210
|
-
}
|
|
9211
|
-
search(callback) {
|
|
9212
|
-
this.expression.search(callback);
|
|
9213
|
-
}
|
|
9214
|
-
}
|
|
9215
|
-
/**
|
|
9216
|
-
* @class While
|
|
9217
|
-
* @extends Statement
|
|
9218
|
-
* @category AST
|
|
9219
|
-
*/
|
|
9220
|
-
class While extends Statement {
|
|
9221
|
-
constructor(condition, body) {
|
|
9222
|
-
super();
|
|
9223
|
-
this.condition = condition;
|
|
9224
|
-
this.body = body;
|
|
9225
|
-
}
|
|
9226
|
-
get astNodeType() {
|
|
9227
|
-
return "while";
|
|
9228
|
-
}
|
|
9229
|
-
search(callback) {
|
|
9230
|
-
this.condition.search(callback);
|
|
9231
|
-
this.searchBlock(this.body, callback);
|
|
9232
|
-
}
|
|
9233
|
-
}
|
|
9234
|
-
/**
|
|
9235
|
-
* @class Continuing
|
|
9236
|
-
* @extends Statement
|
|
9237
|
-
* @category AST
|
|
9238
|
-
*/
|
|
9239
|
-
class Continuing extends Statement {
|
|
9240
|
-
constructor(body) {
|
|
9241
|
-
super();
|
|
9242
|
-
this.body = body;
|
|
9243
|
-
}
|
|
9244
|
-
get astNodeType() {
|
|
9245
|
-
return "continuing";
|
|
9246
|
-
}
|
|
9247
|
-
search(callback) {
|
|
9248
|
-
this.searchBlock(this.body, callback);
|
|
9249
|
-
}
|
|
9250
|
-
}
|
|
9251
|
-
/**
|
|
9252
|
-
* @class For
|
|
9253
|
-
* @extends Statement
|
|
9254
|
-
* @category AST
|
|
9255
|
-
*/
|
|
9256
|
-
class For extends Statement {
|
|
9257
|
-
constructor(init, condition, increment, body) {
|
|
9258
|
-
super();
|
|
9259
|
-
this.init = init;
|
|
9260
|
-
this.condition = condition;
|
|
9261
|
-
this.increment = increment;
|
|
9262
|
-
this.body = body;
|
|
9263
|
-
}
|
|
9264
|
-
get astNodeType() {
|
|
9265
|
-
return "for";
|
|
9266
|
-
}
|
|
9267
|
-
search(callback) {
|
|
9268
|
-
var _a, _b, _c;
|
|
9269
|
-
(_a = this.init) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9270
|
-
(_b = this.condition) === null || _b === void 0 ? void 0 : _b.search(callback);
|
|
9271
|
-
(_c = this.increment) === null || _c === void 0 ? void 0 : _c.search(callback);
|
|
9272
|
-
this.searchBlock(this.body, callback);
|
|
9273
|
-
}
|
|
9274
|
-
}
|
|
9275
|
-
/**
|
|
9276
|
-
* @class Var
|
|
9277
|
-
* @extends Statement
|
|
9278
|
-
* @category AST
|
|
9279
|
-
*/
|
|
9280
|
-
class Var extends Statement {
|
|
9281
|
-
constructor(name, type, storage, access, value) {
|
|
9282
|
-
super();
|
|
9283
|
-
this.name = name;
|
|
9284
|
-
this.type = type;
|
|
9285
|
-
this.storage = storage;
|
|
9286
|
-
this.access = access;
|
|
9287
|
-
this.value = value;
|
|
9288
|
-
}
|
|
9289
|
-
get astNodeType() {
|
|
9290
|
-
return "var";
|
|
9291
|
-
}
|
|
9292
|
-
search(callback) {
|
|
9293
|
-
var _a;
|
|
9294
|
-
callback(this);
|
|
9295
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9296
|
-
}
|
|
9297
|
-
}
|
|
9298
|
-
/**
|
|
9299
|
-
* @class Override
|
|
9300
|
-
* @extends Statement
|
|
9301
|
-
* @category AST
|
|
9302
|
-
*/
|
|
9303
|
-
class Override extends Statement {
|
|
9304
|
-
constructor(name, type, value) {
|
|
9305
|
-
super();
|
|
9306
|
-
this.name = name;
|
|
9307
|
-
this.type = type;
|
|
9308
|
-
this.value = value;
|
|
9309
|
-
}
|
|
9310
|
-
get astNodeType() {
|
|
9311
|
-
return "override";
|
|
9312
|
-
}
|
|
9313
|
-
search(callback) {
|
|
9314
|
-
var _a;
|
|
9315
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9316
|
-
}
|
|
9317
|
-
}
|
|
9318
|
-
/**
|
|
9319
|
-
* @class Let
|
|
9320
|
-
* @extends Statement
|
|
9321
|
-
* @category AST
|
|
9322
|
-
*/
|
|
9323
|
-
class Let extends Statement {
|
|
9324
|
-
constructor(name, type, storage, access, value) {
|
|
9325
|
-
super();
|
|
9326
|
-
this.name = name;
|
|
9327
|
-
this.type = type;
|
|
9328
|
-
this.storage = storage;
|
|
9329
|
-
this.access = access;
|
|
9330
|
-
this.value = value;
|
|
9331
|
-
}
|
|
9332
|
-
get astNodeType() {
|
|
9333
|
-
return "let";
|
|
9334
|
-
}
|
|
9335
|
-
search(callback) {
|
|
9336
|
-
var _a;
|
|
9337
|
-
callback(this);
|
|
9338
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9339
|
-
}
|
|
9340
|
-
}
|
|
9341
|
-
/**
|
|
9342
|
-
* @class Const
|
|
9343
|
-
* @extends Statement
|
|
9344
|
-
* @category AST
|
|
9345
|
-
*/
|
|
9346
|
-
class Const extends Statement {
|
|
9347
|
-
constructor(name, type, storage, access, value) {
|
|
9348
|
-
super();
|
|
9349
|
-
this.name = name;
|
|
9350
|
-
this.type = type;
|
|
9351
|
-
this.storage = storage;
|
|
9352
|
-
this.access = access;
|
|
9353
|
-
this.value = value;
|
|
9354
|
-
}
|
|
9355
|
-
get astNodeType() {
|
|
9356
|
-
return "const";
|
|
9357
|
-
}
|
|
9358
|
-
evaluate(context) {
|
|
9359
|
-
return this.value.evaluate(context);
|
|
9360
|
-
}
|
|
9361
|
-
search(callback) {
|
|
9362
|
-
var _a;
|
|
9363
|
-
callback(this);
|
|
9364
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9365
|
-
}
|
|
9366
|
-
}
|
|
9367
|
-
var IncrementOperator;
|
|
9368
|
-
(function (IncrementOperator) {
|
|
9369
|
-
IncrementOperator["increment"] = "++";
|
|
9370
|
-
IncrementOperator["decrement"] = "--";
|
|
9371
|
-
})(IncrementOperator || (IncrementOperator = {}));
|
|
9372
|
-
(function (IncrementOperator) {
|
|
9373
|
-
function parse(val) {
|
|
9374
|
-
const key = val;
|
|
9375
|
-
if (key == "parse")
|
|
9376
|
-
throw new Error("Invalid value for IncrementOperator");
|
|
9377
|
-
return IncrementOperator[key];
|
|
9378
|
-
}
|
|
9379
|
-
IncrementOperator.parse = parse;
|
|
9380
|
-
})(IncrementOperator || (IncrementOperator = {}));
|
|
9381
|
-
/**
|
|
9382
|
-
* @class Increment
|
|
9383
|
-
* @extends Statement
|
|
9384
|
-
* @category AST
|
|
9385
|
-
*/
|
|
9386
|
-
class Increment extends Statement {
|
|
9387
|
-
constructor(operator, variable) {
|
|
9388
|
-
super();
|
|
9389
|
-
this.operator = operator;
|
|
9390
|
-
this.variable = variable;
|
|
9391
|
-
}
|
|
9392
|
-
get astNodeType() {
|
|
9393
|
-
return "increment";
|
|
9394
|
-
}
|
|
9395
|
-
search(callback) {
|
|
9396
|
-
this.variable.search(callback);
|
|
9397
|
-
}
|
|
9398
|
-
}
|
|
9399
|
-
var AssignOperator;
|
|
9400
|
-
(function (AssignOperator) {
|
|
9401
|
-
AssignOperator["assign"] = "=";
|
|
9402
|
-
AssignOperator["addAssign"] = "+=";
|
|
9403
|
-
AssignOperator["subtractAssin"] = "-=";
|
|
9404
|
-
AssignOperator["multiplyAssign"] = "*=";
|
|
9405
|
-
AssignOperator["divideAssign"] = "/=";
|
|
9406
|
-
AssignOperator["moduloAssign"] = "%=";
|
|
9407
|
-
AssignOperator["andAssign"] = "&=";
|
|
9408
|
-
AssignOperator["orAssign"] = "|=";
|
|
9409
|
-
AssignOperator["xorAssign"] = "^=";
|
|
9410
|
-
AssignOperator["shiftLeftAssign"] = "<<=";
|
|
9411
|
-
AssignOperator["shiftRightAssign"] = ">>=";
|
|
9412
|
-
})(AssignOperator || (AssignOperator = {}));
|
|
9413
|
-
(function (AssignOperator) {
|
|
9414
|
-
function parse(val) {
|
|
9415
|
-
const key = val;
|
|
9416
|
-
if (key == "parse") {
|
|
9417
|
-
throw new Error("Invalid value for AssignOperator");
|
|
9418
|
-
}
|
|
9419
|
-
//return AssignOperator[key];
|
|
9420
|
-
return key;
|
|
9421
|
-
}
|
|
9422
|
-
AssignOperator.parse = parse;
|
|
9423
|
-
})(AssignOperator || (AssignOperator = {}));
|
|
9424
|
-
/**
|
|
9425
|
-
* @class Assign
|
|
9426
|
-
* @extends Statement
|
|
9427
|
-
* @category AST
|
|
9428
|
-
*/
|
|
9429
|
-
class Assign extends Statement {
|
|
9430
|
-
constructor(operator, variable, value) {
|
|
9431
|
-
super();
|
|
9432
|
-
this.operator = operator;
|
|
9433
|
-
this.variable = variable;
|
|
9434
|
-
this.value = value;
|
|
9435
|
-
}
|
|
9436
|
-
get astNodeType() {
|
|
9437
|
-
return "assign";
|
|
9438
|
-
}
|
|
9439
|
-
search(callback) {
|
|
9440
|
-
this.variable.search(callback);
|
|
9441
|
-
this.value.search(callback);
|
|
9442
|
-
}
|
|
9443
|
-
}
|
|
9444
|
-
/**
|
|
9445
|
-
* @class Call
|
|
9446
|
-
* @extends Statement
|
|
9447
|
-
* @category AST
|
|
9448
|
-
*/
|
|
9449
|
-
class Call extends Statement {
|
|
9450
|
-
constructor(name, args) {
|
|
9451
|
-
super();
|
|
9452
|
-
this.name = name;
|
|
9453
|
-
this.args = args;
|
|
9454
|
-
}
|
|
9455
|
-
get astNodeType() {
|
|
9456
|
-
return "call";
|
|
9457
|
-
}
|
|
9458
|
-
search(callback) {
|
|
9459
|
-
for (const node of this.args) {
|
|
9460
|
-
node.search(callback);
|
|
9461
|
-
}
|
|
9462
|
-
callback(this);
|
|
9463
|
-
}
|
|
9464
|
-
}
|
|
9465
|
-
/**
|
|
9466
|
-
* @class Loop
|
|
9467
|
-
* @extends Statement
|
|
9468
|
-
* @category AST
|
|
9469
|
-
*/
|
|
9470
|
-
class Loop extends Statement {
|
|
9471
|
-
constructor(body, continuing) {
|
|
9472
|
-
super();
|
|
9473
|
-
this.body = body;
|
|
9474
|
-
this.continuing = continuing;
|
|
9475
|
-
}
|
|
9476
|
-
get astNodeType() {
|
|
9477
|
-
return "loop";
|
|
9478
|
-
}
|
|
9479
|
-
}
|
|
9480
|
-
/**
|
|
9481
|
-
* @class Switch
|
|
9482
|
-
* @extends Statement
|
|
9483
|
-
* @category AST
|
|
9484
|
-
*/
|
|
9485
|
-
class Switch extends Statement {
|
|
9486
|
-
constructor(condition, body) {
|
|
9487
|
-
super();
|
|
9488
|
-
this.condition = condition;
|
|
9489
|
-
this.body = body;
|
|
9490
|
-
}
|
|
9491
|
-
get astNodeType() {
|
|
9492
|
-
return "body";
|
|
9493
|
-
}
|
|
9494
|
-
}
|
|
9495
|
-
/**
|
|
9496
|
-
* @class If
|
|
9497
|
-
* @extends Statement
|
|
9498
|
-
* @category AST
|
|
9499
|
-
*/
|
|
9500
|
-
class If extends Statement {
|
|
9501
|
-
constructor(condition, body, elseif, _else) {
|
|
9502
|
-
super();
|
|
9503
|
-
this.condition = condition;
|
|
9504
|
-
this.body = body;
|
|
9505
|
-
this.elseif = elseif;
|
|
9506
|
-
this.else = _else;
|
|
9507
|
-
}
|
|
9508
|
-
get astNodeType() {
|
|
9509
|
-
return "if";
|
|
9510
|
-
}
|
|
9511
|
-
search(callback) {
|
|
9512
|
-
this.condition.search(callback);
|
|
9513
|
-
this.searchBlock(this.body, callback);
|
|
9514
|
-
this.searchBlock(this.elseif, callback);
|
|
9515
|
-
this.searchBlock(this.else, callback);
|
|
9516
|
-
}
|
|
9517
|
-
}
|
|
9518
|
-
/**
|
|
9519
|
-
* @class Return
|
|
9520
|
-
* @extends Statement
|
|
9521
|
-
* @category AST
|
|
9522
|
-
*/
|
|
9523
|
-
class Return extends Statement {
|
|
9524
|
-
constructor(value) {
|
|
9525
|
-
super();
|
|
9526
|
-
this.value = value;
|
|
9527
|
-
}
|
|
9528
|
-
get astNodeType() {
|
|
9529
|
-
return "return";
|
|
9530
|
-
}
|
|
9531
|
-
search(callback) {
|
|
9532
|
-
var _a;
|
|
9533
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.search(callback);
|
|
9534
|
-
}
|
|
9535
|
-
}
|
|
9536
|
-
/**
|
|
9537
|
-
* @class Enable
|
|
9538
|
-
* @extends Statement
|
|
9539
|
-
* @category AST
|
|
9540
|
-
*/
|
|
9541
|
-
class Enable extends Statement {
|
|
9542
|
-
constructor(name) {
|
|
9543
|
-
super();
|
|
9544
|
-
this.name = name;
|
|
9545
|
-
}
|
|
9546
|
-
get astNodeType() {
|
|
9547
|
-
return "enable";
|
|
9548
|
-
}
|
|
9549
|
-
}
|
|
9550
|
-
/**
|
|
9551
|
-
* @class Requires
|
|
9552
|
-
* @extends Statement
|
|
9553
|
-
* @category AST
|
|
9554
|
-
*/
|
|
9555
|
-
class Requires extends Statement {
|
|
9556
|
-
constructor(extensions) {
|
|
9557
|
-
super();
|
|
9558
|
-
this.extensions = extensions;
|
|
9559
|
-
}
|
|
9560
|
-
get astNodeType() {
|
|
9561
|
-
return "requires";
|
|
9562
|
-
}
|
|
9563
|
-
}
|
|
9564
|
-
/**
|
|
9565
|
-
* @class Diagnostic
|
|
9566
|
-
* @extends Statement
|
|
9567
|
-
* @category AST
|
|
9568
|
-
*/
|
|
9569
|
-
class Diagnostic extends Statement {
|
|
9570
|
-
constructor(severity, rule) {
|
|
9571
|
-
super();
|
|
9572
|
-
this.severity = severity;
|
|
9573
|
-
this.rule = rule;
|
|
9574
|
-
}
|
|
9575
|
-
get astNodeType() {
|
|
9576
|
-
return "diagnostic";
|
|
9577
|
-
}
|
|
9578
|
-
}
|
|
9579
|
-
/**
|
|
9580
|
-
* @class Alias
|
|
9581
|
-
* @extends Statement
|
|
9582
|
-
* @category AST
|
|
9583
|
-
*/
|
|
9584
|
-
class Alias extends Statement {
|
|
9585
|
-
constructor(name, type) {
|
|
9586
|
-
super();
|
|
9587
|
-
this.name = name;
|
|
9588
|
-
this.type = type;
|
|
9589
|
-
}
|
|
9590
|
-
get astNodeType() {
|
|
9591
|
-
return "alias";
|
|
9592
|
-
}
|
|
9593
|
-
}
|
|
9594
|
-
/**
|
|
9595
|
-
* @class Discard
|
|
9596
|
-
* @extends Statement
|
|
9597
|
-
* @category AST
|
|
9598
|
-
*/
|
|
9599
|
-
class Discard extends Statement {
|
|
9600
|
-
constructor() {
|
|
9601
|
-
super();
|
|
9602
|
-
}
|
|
9603
|
-
get astNodeType() {
|
|
9604
|
-
return "discard";
|
|
9605
|
-
}
|
|
9606
|
-
}
|
|
9607
|
-
/**
|
|
9608
|
-
* @class Break
|
|
9609
|
-
* @extends Statement
|
|
9610
|
-
* @category AST
|
|
9611
|
-
*/
|
|
9612
|
-
class Break extends Statement {
|
|
9613
|
-
constructor() {
|
|
9614
|
-
super();
|
|
9615
|
-
}
|
|
9616
|
-
get astNodeType() {
|
|
9617
|
-
return "break";
|
|
9618
|
-
}
|
|
9619
|
-
}
|
|
9620
|
-
/**
|
|
9621
|
-
* @class Continue
|
|
9622
|
-
* @extends Statement
|
|
9623
|
-
* @category AST
|
|
9624
|
-
*/
|
|
9625
|
-
class Continue extends Statement {
|
|
9626
|
-
constructor() {
|
|
9627
|
-
super();
|
|
9628
|
-
}
|
|
9629
|
-
get astNodeType() {
|
|
9630
|
-
return "continue";
|
|
9631
|
-
}
|
|
9632
|
-
}
|
|
9633
|
-
/**
|
|
9634
|
-
* @class Type
|
|
9635
|
-
* @extends Statement
|
|
9636
|
-
* @category AST
|
|
9637
|
-
*/
|
|
9638
|
-
class Type extends Statement {
|
|
9639
|
-
constructor(name) {
|
|
9640
|
-
super();
|
|
9641
|
-
this.name = name;
|
|
9642
|
-
}
|
|
9643
|
-
get astNodeType() {
|
|
9644
|
-
return "type";
|
|
9645
|
-
}
|
|
9646
|
-
get isStruct() {
|
|
9647
|
-
return false;
|
|
9648
|
-
}
|
|
9649
|
-
get isArray() {
|
|
9650
|
-
return false;
|
|
9651
|
-
}
|
|
9652
|
-
}
|
|
9653
|
-
/**
|
|
9654
|
-
* @class StructType
|
|
9655
|
-
* @extends Type
|
|
9656
|
-
* @category AST
|
|
9657
|
-
*/
|
|
9658
|
-
class Struct extends Type {
|
|
9659
|
-
constructor(name, members, startLine, endLine) {
|
|
9660
|
-
super(name);
|
|
9661
|
-
this.members = members;
|
|
9662
|
-
this.startLine = startLine;
|
|
9663
|
-
this.endLine = endLine;
|
|
9664
|
-
}
|
|
9665
|
-
get astNodeType() {
|
|
9666
|
-
return "struct";
|
|
9667
|
-
}
|
|
9668
|
-
get isStruct() {
|
|
9669
|
-
return true;
|
|
9670
|
-
}
|
|
9671
|
-
/// Return the index of the member with the given name, or -1 if not found.
|
|
9672
|
-
getMemberIndex(name) {
|
|
9673
|
-
for (let i = 0; i < this.members.length; i++) {
|
|
9674
|
-
if (this.members[i].name == name)
|
|
9675
|
-
return i;
|
|
9676
|
-
}
|
|
9677
|
-
return -1;
|
|
9678
|
-
}
|
|
9679
|
-
}
|
|
9680
|
-
/**
|
|
9681
|
-
* @class TemplateType
|
|
9682
|
-
* @extends Type
|
|
9683
|
-
* @category AST
|
|
9684
|
-
*/
|
|
9685
|
-
class TemplateType extends Type {
|
|
9686
|
-
constructor(name, format, access) {
|
|
9687
|
-
super(name);
|
|
9688
|
-
this.format = format;
|
|
9689
|
-
this.access = access;
|
|
9690
|
-
}
|
|
9691
|
-
get astNodeType() {
|
|
9692
|
-
return "template";
|
|
9693
|
-
}
|
|
9694
|
-
}
|
|
9695
|
-
/**
|
|
9696
|
-
* @class PointerType
|
|
9697
|
-
* @extends Type
|
|
9698
|
-
* @category AST
|
|
9699
|
-
*/
|
|
9700
|
-
class PointerType extends Type {
|
|
9701
|
-
constructor(name, storage, type, access) {
|
|
9702
|
-
super(name);
|
|
9703
|
-
this.storage = storage;
|
|
9704
|
-
this.type = type;
|
|
9705
|
-
this.access = access;
|
|
9706
|
-
}
|
|
9707
|
-
get astNodeType() {
|
|
9708
|
-
return "pointer";
|
|
9709
|
-
}
|
|
9710
|
-
}
|
|
9711
|
-
/**
|
|
9712
|
-
* @class ArrayType
|
|
9713
|
-
* @extends Type
|
|
9714
|
-
* @category AST
|
|
9715
|
-
*/
|
|
9716
|
-
class ArrayType extends Type {
|
|
9717
|
-
constructor(name, attributes, format, count) {
|
|
9718
|
-
super(name);
|
|
9719
|
-
this.attributes = attributes;
|
|
9720
|
-
this.format = format;
|
|
9721
|
-
this.count = count;
|
|
9722
|
-
}
|
|
9723
|
-
get astNodeType() {
|
|
9724
|
-
return "array";
|
|
9725
|
-
}
|
|
9726
|
-
get isArray() {
|
|
9727
|
-
return true;
|
|
9728
|
-
}
|
|
9729
|
-
}
|
|
9730
|
-
/**
|
|
9731
|
-
* @class SamplerType
|
|
9732
|
-
* @extends Type
|
|
9733
|
-
* @category AST
|
|
9734
|
-
*/
|
|
9735
|
-
class SamplerType extends Type {
|
|
9736
|
-
constructor(name, format, access) {
|
|
9737
|
-
super(name);
|
|
9738
|
-
this.format = format;
|
|
9739
|
-
this.access = access;
|
|
9740
|
-
}
|
|
9741
|
-
get astNodeType() {
|
|
9742
|
-
return "sampler";
|
|
9743
|
-
}
|
|
9744
|
-
}
|
|
9745
|
-
/**
|
|
9746
|
-
* @class Expression
|
|
9747
|
-
* @extends Node
|
|
9748
|
-
* @category AST
|
|
9749
|
-
*/
|
|
9750
|
-
class Expression extends Node {
|
|
9751
|
-
constructor() {
|
|
9752
|
-
super();
|
|
9753
|
-
}
|
|
9754
|
-
}
|
|
9755
|
-
/**
|
|
9756
|
-
* @class StringExpr
|
|
9757
|
-
* @extends Expression
|
|
9758
|
-
* @category AST
|
|
9759
|
-
*/
|
|
9760
|
-
class StringExpr extends Expression {
|
|
9761
|
-
constructor(value) {
|
|
9762
|
-
super();
|
|
9763
|
-
this.value = value;
|
|
9764
|
-
}
|
|
9765
|
-
get astNodeType() {
|
|
9766
|
-
return "stringExpr";
|
|
9767
|
-
}
|
|
9768
|
-
toString() {
|
|
9769
|
-
return this.value;
|
|
9770
|
-
}
|
|
9771
|
-
evaluateString() {
|
|
9772
|
-
return this.value;
|
|
9773
|
-
}
|
|
9774
|
-
}
|
|
9775
|
-
/**
|
|
9776
|
-
* @class CreateExpr
|
|
9777
|
-
* @extends Expression
|
|
9778
|
-
* @category AST
|
|
9779
|
-
*/
|
|
9780
|
-
class CreateExpr extends Expression {
|
|
9781
|
-
constructor(type, args) {
|
|
9782
|
-
super();
|
|
9783
|
-
this.type = type;
|
|
9784
|
-
this.args = args;
|
|
9785
|
-
}
|
|
9786
|
-
get astNodeType() {
|
|
9787
|
-
return "createExpr";
|
|
9788
|
-
}
|
|
9789
|
-
search(callback) {
|
|
9790
|
-
callback(this);
|
|
9791
|
-
if (this.args) {
|
|
9792
|
-
for (const node of this.args) {
|
|
9793
|
-
node.search(callback);
|
|
9794
|
-
}
|
|
9795
|
-
}
|
|
9796
|
-
}
|
|
9797
|
-
evaluate(context) {
|
|
9798
|
-
return this.args[0].evaluate(context);
|
|
9799
|
-
}
|
|
9800
|
-
}
|
|
9801
|
-
/**
|
|
9802
|
-
* @class CallExpr
|
|
9803
|
-
* @extends Expression
|
|
9804
|
-
* @category AST
|
|
9805
|
-
*/
|
|
9806
|
-
class CallExpr extends Expression {
|
|
9807
|
-
constructor(name, args) {
|
|
9808
|
-
super();
|
|
9809
|
-
this.name = name;
|
|
9810
|
-
this.args = args;
|
|
9811
|
-
}
|
|
9812
|
-
get astNodeType() {
|
|
9813
|
-
return "callExpr";
|
|
9814
|
-
}
|
|
9815
|
-
evaluate(context) {
|
|
9816
|
-
switch (this.name) {
|
|
9817
|
-
case "abs":
|
|
9818
|
-
return Math.abs(this.args[0].evaluate(context));
|
|
9819
|
-
case "acos":
|
|
9820
|
-
return Math.acos(this.args[0].evaluate(context));
|
|
9821
|
-
case "acosh":
|
|
9822
|
-
return Math.acosh(this.args[0].evaluate(context));
|
|
9823
|
-
case "asin":
|
|
9824
|
-
return Math.asin(this.args[0].evaluate(context));
|
|
9825
|
-
case "asinh":
|
|
9826
|
-
return Math.asinh(this.args[0].evaluate(context));
|
|
9827
|
-
case "atan":
|
|
9828
|
-
return Math.atan(this.args[0].evaluate(context));
|
|
9829
|
-
case "atan2":
|
|
9830
|
-
return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
9831
|
-
case "atanh":
|
|
9832
|
-
return Math.atanh(this.args[0].evaluate(context));
|
|
9833
|
-
case "ceil":
|
|
9834
|
-
return Math.ceil(this.args[0].evaluate(context));
|
|
9835
|
-
case "clamp":
|
|
9836
|
-
return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
|
|
9837
|
-
case "cos":
|
|
9838
|
-
return Math.cos(this.args[0].evaluate(context));
|
|
9839
|
-
//case "cross":
|
|
9840
|
-
//TODO: (x[i] * y[j] - x[j] * y[i])
|
|
9841
|
-
case "degrees":
|
|
9842
|
-
return (this.args[0].evaluate(context) * 180) / Math.PI;
|
|
9843
|
-
//case "determinant":
|
|
9844
|
-
//TODO implement
|
|
9845
|
-
case "distance":
|
|
9846
|
-
return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
|
|
9847
|
-
case "dot":
|
|
9848
|
-
//TODO: (x[i] * y[i])
|
|
9849
|
-
case "exp":
|
|
9850
|
-
return Math.exp(this.args[0].evaluate(context));
|
|
9851
|
-
case "exp2":
|
|
9852
|
-
return Math.pow(2, this.args[0].evaluate(context));
|
|
9853
|
-
//case "extractBits":
|
|
9854
|
-
//TODO: implement
|
|
9855
|
-
//case "firstLeadingBit":
|
|
9856
|
-
//TODO: implement
|
|
9857
|
-
case "floor":
|
|
9858
|
-
return Math.floor(this.args[0].evaluate(context));
|
|
9859
|
-
case "fma":
|
|
9860
|
-
return (this.args[0].evaluate(context) * this.args[1].evaluate(context) +
|
|
9861
|
-
this.args[2].evaluate(context));
|
|
9862
|
-
case "fract":
|
|
9863
|
-
return (this.args[0].evaluate(context) -
|
|
9864
|
-
Math.floor(this.args[0].evaluate(context)));
|
|
9865
|
-
//case "frexp":
|
|
9866
|
-
//TODO: implement
|
|
9867
|
-
case "inverseSqrt":
|
|
9868
|
-
return 1 / Math.sqrt(this.args[0].evaluate(context));
|
|
9869
|
-
//case "length":
|
|
9870
|
-
//TODO: implement
|
|
9871
|
-
case "log":
|
|
9872
|
-
return Math.log(this.args[0].evaluate(context));
|
|
9873
|
-
case "log2":
|
|
9874
|
-
return Math.log2(this.args[0].evaluate(context));
|
|
9875
|
-
case "max":
|
|
9876
|
-
return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
9877
|
-
case "min":
|
|
9878
|
-
return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
9879
|
-
case "mix":
|
|
9880
|
-
return (this.args[0].evaluate(context) *
|
|
9881
|
-
(1 - this.args[2].evaluate(context)) +
|
|
9882
|
-
this.args[1].evaluate(context) * this.args[2].evaluate(context));
|
|
9883
|
-
case "modf":
|
|
9884
|
-
return (this.args[0].evaluate(context) -
|
|
9885
|
-
Math.floor(this.args[0].evaluate(context)));
|
|
9886
|
-
case "pow":
|
|
9887
|
-
return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
9888
|
-
case "radians":
|
|
9889
|
-
return (this.args[0].evaluate(context) * Math.PI) / 180;
|
|
9890
|
-
case "round":
|
|
9891
|
-
return Math.round(this.args[0].evaluate(context));
|
|
9892
|
-
case "sign":
|
|
9893
|
-
return Math.sign(this.args[0].evaluate(context));
|
|
9894
|
-
case "sin":
|
|
9895
|
-
return Math.sin(this.args[0].evaluate(context));
|
|
9896
|
-
case "sinh":
|
|
9897
|
-
return Math.sinh(this.args[0].evaluate(context));
|
|
9898
|
-
case "saturate":
|
|
9899
|
-
return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
|
|
9900
|
-
case "smoothstep":
|
|
9901
|
-
return (this.args[0].evaluate(context) *
|
|
9902
|
-
this.args[0].evaluate(context) *
|
|
9903
|
-
(3 - 2 * this.args[0].evaluate(context)));
|
|
9904
|
-
case "sqrt":
|
|
9905
|
-
return Math.sqrt(this.args[0].evaluate(context));
|
|
9906
|
-
case "step":
|
|
9907
|
-
return this.args[0].evaluate(context) < this.args[1].evaluate(context)
|
|
9908
|
-
? 0
|
|
9909
|
-
: 1;
|
|
9910
|
-
case "tan":
|
|
9911
|
-
return Math.tan(this.args[0].evaluate(context));
|
|
9912
|
-
case "tanh":
|
|
9913
|
-
return Math.tanh(this.args[0].evaluate(context));
|
|
9914
|
-
case "trunc":
|
|
9915
|
-
return Math.trunc(this.args[0].evaluate(context));
|
|
9916
|
-
default:
|
|
9917
|
-
throw new Error("Non const function: " + this.name);
|
|
9918
|
-
}
|
|
9919
|
-
}
|
|
9920
|
-
search(callback) {
|
|
9921
|
-
for (const node of this.args) {
|
|
9922
|
-
node.search(callback);
|
|
9923
|
-
}
|
|
9924
|
-
callback(this);
|
|
9925
|
-
}
|
|
9926
|
-
}
|
|
9927
|
-
/**
|
|
9928
|
-
* @class VariableExpr
|
|
9929
|
-
* @extends Expression
|
|
9930
|
-
* @category AST
|
|
9931
|
-
*/
|
|
9932
|
-
class VariableExpr extends Expression {
|
|
9933
|
-
constructor(name) {
|
|
9934
|
-
super();
|
|
9935
|
-
this.name = name;
|
|
9936
|
-
}
|
|
9937
|
-
get astNodeType() {
|
|
9938
|
-
return "varExpr";
|
|
9939
|
-
}
|
|
9940
|
-
search(callback) {
|
|
9941
|
-
callback(this);
|
|
9942
|
-
if (this.postfix) {
|
|
9943
|
-
this.postfix.search(callback);
|
|
9944
|
-
}
|
|
9945
|
-
}
|
|
9946
|
-
evaluate(context) {
|
|
9947
|
-
const constant = context.constants.get(this.name);
|
|
9948
|
-
if (!constant) {
|
|
9949
|
-
throw new Error("Cannot evaluate node");
|
|
9950
|
-
}
|
|
9951
|
-
return constant.evaluate(context);
|
|
9952
|
-
}
|
|
9953
|
-
}
|
|
9954
|
-
/**
|
|
9955
|
-
* @class ConstExpr
|
|
9956
|
-
* @extends Expression
|
|
9957
|
-
* @category AST
|
|
9958
|
-
*/
|
|
9959
|
-
class ConstExpr extends Expression {
|
|
9960
|
-
constructor(name, initializer) {
|
|
9961
|
-
super();
|
|
9962
|
-
this.name = name;
|
|
9963
|
-
this.initializer = initializer;
|
|
9964
|
-
}
|
|
9965
|
-
get astNodeType() {
|
|
9966
|
-
return "constExpr";
|
|
9967
|
-
}
|
|
9968
|
-
evaluate(context) {
|
|
9969
|
-
var _a, _b;
|
|
9970
|
-
if (this.initializer instanceof CreateExpr) {
|
|
9971
|
-
// This is a struct constant
|
|
9972
|
-
const property = (_a = this.postfix) === null || _a === void 0 ? void 0 : _a.evaluateString(context);
|
|
9973
|
-
const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
|
|
9974
|
-
const struct = context.structs.get(type);
|
|
9975
|
-
const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
|
|
9976
|
-
if (memberIndex !== undefined && memberIndex != -1) {
|
|
9977
|
-
const value = this.initializer.args[memberIndex].evaluate(context);
|
|
9978
|
-
return value;
|
|
9979
|
-
}
|
|
9980
|
-
else {
|
|
9981
|
-
return this.initializer.evaluate(context);
|
|
9982
|
-
}
|
|
9983
|
-
}
|
|
9984
|
-
return this.initializer.evaluate(context);
|
|
9985
|
-
}
|
|
9986
|
-
search(callback) {
|
|
9987
|
-
this.initializer.search(callback);
|
|
9988
|
-
}
|
|
9989
|
-
}
|
|
9990
|
-
/**
|
|
9991
|
-
* @class LiteralExpr
|
|
9992
|
-
* @extends Expression
|
|
9993
|
-
* @category AST
|
|
9994
|
-
*/
|
|
9995
|
-
class LiteralExpr extends Expression {
|
|
9996
|
-
constructor(value) {
|
|
9997
|
-
super();
|
|
9998
|
-
this.value = value;
|
|
9999
|
-
}
|
|
10000
|
-
get astNodeType() {
|
|
10001
|
-
return "literalExpr";
|
|
10002
|
-
}
|
|
10003
|
-
evaluate() {
|
|
10004
|
-
return this.value;
|
|
10005
|
-
}
|
|
10006
|
-
}
|
|
10007
|
-
/**
|
|
10008
|
-
* @class BitcastExpr
|
|
10009
|
-
* @extends Expression
|
|
10010
|
-
* @category AST
|
|
10011
|
-
*/
|
|
10012
|
-
class BitcastExpr extends Expression {
|
|
10013
|
-
constructor(type, value) {
|
|
10014
|
-
super();
|
|
10015
|
-
this.type = type;
|
|
10016
|
-
this.value = value;
|
|
10017
|
-
}
|
|
10018
|
-
get astNodeType() {
|
|
10019
|
-
return "bitcastExpr";
|
|
10020
|
-
}
|
|
10021
|
-
search(callback) {
|
|
10022
|
-
this.value.search(callback);
|
|
10023
|
-
}
|
|
10024
|
-
}
|
|
10025
|
-
/**
|
|
10026
|
-
* @class GroupingExpr
|
|
10027
|
-
* @extends Expression
|
|
10028
|
-
* @category AST
|
|
10029
|
-
*/
|
|
10030
|
-
class GroupingExpr extends Expression {
|
|
10031
|
-
constructor(contents) {
|
|
10032
|
-
super();
|
|
10033
|
-
this.contents = contents;
|
|
10034
|
-
}
|
|
10035
|
-
get astNodeType() {
|
|
10036
|
-
return "groupExpr";
|
|
10037
|
-
}
|
|
10038
|
-
evaluate(context) {
|
|
10039
|
-
return this.contents[0].evaluate(context);
|
|
10040
|
-
}
|
|
10041
|
-
search(callback) {
|
|
10042
|
-
this.searchBlock(this.contents, callback);
|
|
10043
|
-
}
|
|
10044
|
-
}
|
|
10045
|
-
/**
|
|
10046
|
-
* @class ArrayIndex
|
|
10047
|
-
* @extends Expression
|
|
10048
|
-
* @category AST
|
|
10049
|
-
*/
|
|
10050
|
-
class ArrayIndex extends Expression {
|
|
10051
|
-
constructor(index) {
|
|
10052
|
-
super();
|
|
10053
|
-
this.index = index;
|
|
10054
|
-
}
|
|
10055
|
-
search(callback) {
|
|
10056
|
-
this.index.search(callback);
|
|
10057
|
-
}
|
|
10058
|
-
}
|
|
10059
|
-
/**
|
|
10060
|
-
* @class Operator
|
|
10061
|
-
* @extends Expression
|
|
10062
|
-
* @category AST
|
|
10063
|
-
*/
|
|
10064
|
-
class Operator extends Expression {
|
|
10065
|
-
constructor() {
|
|
10066
|
-
super();
|
|
10067
|
-
}
|
|
10068
|
-
}
|
|
10069
|
-
/**
|
|
10070
|
-
* @class UnaryOperator
|
|
10071
|
-
* @extends Operator
|
|
10072
|
-
* @category AST
|
|
10073
|
-
* @property {string} operator +, -, !, ~
|
|
10074
|
-
*/
|
|
10075
|
-
class UnaryOperator extends Operator {
|
|
10076
|
-
constructor(operator, right) {
|
|
10077
|
-
super();
|
|
10078
|
-
this.operator = operator;
|
|
10079
|
-
this.right = right;
|
|
10080
|
-
}
|
|
10081
|
-
get astNodeType() {
|
|
10082
|
-
return "unaryOp";
|
|
10083
|
-
}
|
|
10084
|
-
evaluate(context) {
|
|
10085
|
-
switch (this.operator) {
|
|
10086
|
-
case "+":
|
|
10087
|
-
return this.right.evaluate(context);
|
|
10088
|
-
case "-":
|
|
10089
|
-
return -this.right.evaluate(context);
|
|
10090
|
-
case "!":
|
|
10091
|
-
return this.right.evaluate(context) ? 0 : 1;
|
|
10092
|
-
case "~":
|
|
10093
|
-
return ~this.right.evaluate(context);
|
|
10094
|
-
default:
|
|
10095
|
-
throw new Error("Unknown unary operator: " + this.operator);
|
|
10096
|
-
}
|
|
10097
|
-
}
|
|
10098
|
-
search(callback) {
|
|
10099
|
-
this.right.search(callback);
|
|
10100
|
-
}
|
|
10101
|
-
}
|
|
10102
|
-
/**
|
|
10103
|
-
* @class BinaryOperator
|
|
10104
|
-
* @extends Operator
|
|
10105
|
-
* @category AST
|
|
10106
|
-
* @property {string} operator +, -, *, /, %, ==, !=, <, >, <=, >=, &&, ||
|
|
10107
|
-
*/
|
|
10108
|
-
class BinaryOperator extends Operator {
|
|
10109
|
-
constructor(operator, left, right) {
|
|
10110
|
-
super();
|
|
10111
|
-
this.operator = operator;
|
|
10112
|
-
this.left = left;
|
|
10113
|
-
this.right = right;
|
|
10114
|
-
}
|
|
10115
|
-
get astNodeType() {
|
|
10116
|
-
return "binaryOp";
|
|
10117
|
-
}
|
|
10118
|
-
evaluate(context) {
|
|
10119
|
-
switch (this.operator) {
|
|
10120
|
-
case "+":
|
|
10121
|
-
return this.left.evaluate(context) + this.right.evaluate(context);
|
|
10122
|
-
case "-":
|
|
10123
|
-
return this.left.evaluate(context) - this.right.evaluate(context);
|
|
10124
|
-
case "*":
|
|
10125
|
-
return this.left.evaluate(context) * this.right.evaluate(context);
|
|
10126
|
-
case "/":
|
|
10127
|
-
return this.left.evaluate(context) / this.right.evaluate(context);
|
|
10128
|
-
case "%":
|
|
10129
|
-
return this.left.evaluate(context) % this.right.evaluate(context);
|
|
10130
|
-
case "==":
|
|
10131
|
-
return this.left.evaluate(context) == this.right.evaluate(context)
|
|
10132
|
-
? 1
|
|
10133
|
-
: 0;
|
|
10134
|
-
case "!=":
|
|
10135
|
-
return this.left.evaluate(context) != this.right.evaluate(context)
|
|
10136
|
-
? 1
|
|
10137
|
-
: 0;
|
|
10138
|
-
case "<":
|
|
10139
|
-
return this.left.evaluate(context) < this.right.evaluate(context)
|
|
10140
|
-
? 1
|
|
10141
|
-
: 0;
|
|
10142
|
-
case ">":
|
|
10143
|
-
return this.left.evaluate(context) > this.right.evaluate(context)
|
|
10144
|
-
? 1
|
|
10145
|
-
: 0;
|
|
10146
|
-
case "<=":
|
|
10147
|
-
return this.left.evaluate(context) <= this.right.evaluate(context)
|
|
10148
|
-
? 1
|
|
10149
|
-
: 0;
|
|
10150
|
-
case ">=":
|
|
10151
|
-
return this.left.evaluate(context) >= this.right.evaluate(context)
|
|
10152
|
-
? 1
|
|
10153
|
-
: 0;
|
|
10154
|
-
case "&&":
|
|
10155
|
-
return this.left.evaluate(context) && this.right.evaluate(context)
|
|
10156
|
-
? 1
|
|
10157
|
-
: 0;
|
|
10158
|
-
case "||":
|
|
10159
|
-
return this.left.evaluate(context) || this.right.evaluate(context)
|
|
10160
|
-
? 1
|
|
10161
|
-
: 0;
|
|
10162
|
-
default:
|
|
10163
|
-
throw new Error(`Unknown operator ${this.operator}`);
|
|
10164
|
-
}
|
|
10165
|
-
}
|
|
10166
|
-
search(callback) {
|
|
10167
|
-
this.left.search(callback);
|
|
10168
|
-
this.right.search(callback);
|
|
10169
|
-
}
|
|
10170
|
-
}
|
|
10171
|
-
/**
|
|
10172
|
-
* @class SwitchCase
|
|
10173
|
-
* @extends Node
|
|
10174
|
-
* @category AST
|
|
10175
|
-
*/
|
|
10176
|
-
class SwitchCase extends Node {
|
|
10177
|
-
constructor() {
|
|
10178
|
-
super();
|
|
10179
|
-
}
|
|
10180
|
-
}
|
|
10181
|
-
/**
|
|
10182
|
-
* @class Case
|
|
10183
|
-
* @extends SwitchCase
|
|
10184
|
-
* @category AST
|
|
10185
|
-
*/
|
|
10186
|
-
class Case extends SwitchCase {
|
|
10187
|
-
constructor(selector, body) {
|
|
10188
|
-
super();
|
|
10189
|
-
this.selector = selector;
|
|
10190
|
-
this.body = body;
|
|
10191
|
-
}
|
|
10192
|
-
get astNodeType() {
|
|
10193
|
-
return "case";
|
|
10194
|
-
}
|
|
10195
|
-
search(callback) {
|
|
10196
|
-
this.searchBlock(this.body, callback);
|
|
10197
|
-
}
|
|
10198
|
-
}
|
|
10199
|
-
/**
|
|
10200
|
-
* @class Default
|
|
10201
|
-
* @extends SwitchCase
|
|
10202
|
-
* @category AST
|
|
10203
|
-
*/
|
|
10204
|
-
class Default extends SwitchCase {
|
|
10205
|
-
constructor(body) {
|
|
10206
|
-
super();
|
|
10207
|
-
this.body = body;
|
|
10208
|
-
}
|
|
10209
|
-
get astNodeType() {
|
|
10210
|
-
return "default";
|
|
10211
|
-
}
|
|
10212
|
-
search(callback) {
|
|
10213
|
-
this.searchBlock(this.body, callback);
|
|
10214
|
-
}
|
|
10215
|
-
}
|
|
10216
|
-
/**
|
|
10217
|
-
* @class Argument
|
|
10218
|
-
* @extends Node
|
|
10219
|
-
* @category AST
|
|
10220
|
-
*/
|
|
10221
|
-
class Argument extends Node {
|
|
10222
|
-
constructor(name, type, attributes) {
|
|
10223
|
-
super();
|
|
10224
|
-
this.name = name;
|
|
10225
|
-
this.type = type;
|
|
10226
|
-
this.attributes = attributes;
|
|
10227
|
-
}
|
|
10228
|
-
get astNodeType() {
|
|
10229
|
-
return "argument";
|
|
10230
|
-
}
|
|
10231
|
-
}
|
|
10232
|
-
/**
|
|
10233
|
-
* @class ElseIf
|
|
10234
|
-
* @extends Node
|
|
10235
|
-
* @category AST
|
|
10236
|
-
*/
|
|
10237
|
-
class ElseIf extends Node {
|
|
10238
|
-
constructor(condition, body) {
|
|
10239
|
-
super();
|
|
10240
|
-
this.condition = condition;
|
|
10241
|
-
this.body = body;
|
|
10242
|
-
}
|
|
10243
|
-
get astNodeType() {
|
|
10244
|
-
return "elseif";
|
|
10245
|
-
}
|
|
10246
|
-
search(callback) {
|
|
10247
|
-
this.condition.search(callback);
|
|
10248
|
-
this.searchBlock(this.body, callback);
|
|
10249
|
-
}
|
|
10250
|
-
}
|
|
10251
|
-
/**
|
|
10252
|
-
* @class Member
|
|
10253
|
-
* @extends Node
|
|
10254
|
-
* @category AST
|
|
10255
|
-
*/
|
|
10256
|
-
class Member extends Node {
|
|
10257
|
-
constructor(name, type, attributes) {
|
|
10258
|
-
super();
|
|
10259
|
-
this.name = name;
|
|
10260
|
-
this.type = type;
|
|
10261
|
-
this.attributes = attributes;
|
|
10262
|
-
}
|
|
10263
|
-
get astNodeType() {
|
|
10264
|
-
return "member";
|
|
10265
|
-
}
|
|
10266
|
-
}
|
|
10267
|
-
/**
|
|
10268
|
-
* @class Attribute
|
|
10269
|
-
* @extends Node
|
|
10270
|
-
* @category AST
|
|
10271
|
-
*/
|
|
10272
|
-
class Attribute$1 extends Node {
|
|
10273
|
-
constructor(name, value) {
|
|
10274
|
-
super();
|
|
10275
|
-
this.name = name;
|
|
10276
|
-
this.value = value;
|
|
10277
|
-
}
|
|
10278
|
-
get astNodeType() {
|
|
10279
|
-
return "attribute";
|
|
10280
|
-
}
|
|
10281
|
-
}
|
|
10282
|
-
|
|
10283
|
-
var _a;
|
|
10284
|
-
var TokenClass;
|
|
10285
|
-
(function (TokenClass) {
|
|
10286
|
-
TokenClass[TokenClass["token"] = 0] = "token";
|
|
10287
|
-
TokenClass[TokenClass["keyword"] = 1] = "keyword";
|
|
10288
|
-
TokenClass[TokenClass["reserved"] = 2] = "reserved";
|
|
10289
|
-
})(TokenClass || (TokenClass = {}));
|
|
10290
|
-
class TokenType {
|
|
10291
|
-
constructor(name, type, rule) {
|
|
10292
|
-
this.name = name;
|
|
10293
|
-
this.type = type;
|
|
10294
|
-
this.rule = rule;
|
|
10295
|
-
}
|
|
10296
|
-
toString() {
|
|
10297
|
-
return this.name;
|
|
10298
|
-
}
|
|
10299
|
-
}
|
|
10300
|
-
/// Catalog of defined token types, keywords, and reserved words.
|
|
10301
|
-
class TokenTypes {
|
|
10302
|
-
}
|
|
10303
|
-
_a = TokenTypes;
|
|
10304
|
-
TokenTypes.none = new TokenType("", TokenClass.reserved, "");
|
|
10305
|
-
TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
|
|
10306
|
-
TokenTypes.reserved = {
|
|
10307
|
-
asm: new TokenType("asm", TokenClass.reserved, "asm"),
|
|
10308
|
-
bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
|
|
10309
|
-
do: new TokenType("do", TokenClass.reserved, "do"),
|
|
10310
|
-
enum: new TokenType("enum", TokenClass.reserved, "enum"),
|
|
10311
|
-
f16: new TokenType("f16", TokenClass.reserved, "f16"),
|
|
10312
|
-
f64: new TokenType("f64", TokenClass.reserved, "f64"),
|
|
10313
|
-
handle: new TokenType("handle", TokenClass.reserved, "handle"),
|
|
10314
|
-
i8: new TokenType("i8", TokenClass.reserved, "i8"),
|
|
10315
|
-
i16: new TokenType("i16", TokenClass.reserved, "i16"),
|
|
10316
|
-
i64: new TokenType("i64", TokenClass.reserved, "i64"),
|
|
10317
|
-
mat: new TokenType("mat", TokenClass.reserved, "mat"),
|
|
10318
|
-
premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
|
|
10319
|
-
regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
|
|
10320
|
-
typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
|
|
10321
|
-
u8: new TokenType("u8", TokenClass.reserved, "u8"),
|
|
10322
|
-
u16: new TokenType("u16", TokenClass.reserved, "u16"),
|
|
10323
|
-
u64: new TokenType("u64", TokenClass.reserved, "u64"),
|
|
10324
|
-
unless: new TokenType("unless", TokenClass.reserved, "unless"),
|
|
10325
|
-
using: new TokenType("using", TokenClass.reserved, "using"),
|
|
10326
|
-
vec: new TokenType("vec", TokenClass.reserved, "vec"),
|
|
10327
|
-
void: new TokenType("void", TokenClass.reserved, "void"),
|
|
10328
|
-
};
|
|
10329
|
-
TokenTypes.keywords = {
|
|
10330
|
-
array: new TokenType("array", TokenClass.keyword, "array"),
|
|
10331
|
-
atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
|
|
10332
|
-
bool: new TokenType("bool", TokenClass.keyword, "bool"),
|
|
10333
|
-
f32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
10334
|
-
i32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
10335
|
-
mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
|
|
10336
|
-
mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
|
|
10337
|
-
mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
|
|
10338
|
-
mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
|
|
10339
|
-
mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
|
|
10340
|
-
mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
|
|
10341
|
-
mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
|
|
10342
|
-
mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
|
|
10343
|
-
mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
|
|
10344
|
-
ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
|
|
10345
|
-
sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
|
|
10346
|
-
sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
|
|
10347
|
-
struct: new TokenType("struct", TokenClass.keyword, "struct"),
|
|
10348
|
-
texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
|
|
10349
|
-
texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
|
|
10350
|
-
texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
|
|
10351
|
-
texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
|
|
10352
|
-
texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
|
|
10353
|
-
texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
|
|
10354
|
-
texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
|
|
10355
|
-
texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
|
|
10356
|
-
texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
|
|
10357
|
-
texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
|
|
10358
|
-
texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
|
|
10359
|
-
texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
|
|
10360
|
-
texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
|
|
10361
|
-
texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
|
|
10362
|
-
texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
|
|
10363
|
-
texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
|
|
10364
|
-
texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
|
|
10365
|
-
u32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
10366
|
-
vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
|
|
10367
|
-
vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
|
|
10368
|
-
vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
|
|
10369
|
-
bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
|
|
10370
|
-
block: new TokenType("block", TokenClass.keyword, "block"),
|
|
10371
|
-
break: new TokenType("break", TokenClass.keyword, "break"),
|
|
10372
|
-
case: new TokenType("case", TokenClass.keyword, "case"),
|
|
10373
|
-
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
10374
|
-
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
10375
|
-
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
10376
|
-
diagnostic: new TokenType("diagnostic", TokenClass.keyword, "diagnostic"),
|
|
10377
|
-
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
10378
|
-
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
10379
|
-
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
10380
|
-
fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
|
|
10381
|
-
false: new TokenType("false", TokenClass.keyword, "false"),
|
|
10382
|
-
fn: new TokenType("fn", TokenClass.keyword, "fn"),
|
|
10383
|
-
for: new TokenType("for", TokenClass.keyword, "for"),
|
|
10384
|
-
function: new TokenType("function", TokenClass.keyword, "function"),
|
|
10385
|
-
if: new TokenType("if", TokenClass.keyword, "if"),
|
|
10386
|
-
let: new TokenType("let", TokenClass.keyword, "let"),
|
|
10387
|
-
const: new TokenType("const", TokenClass.keyword, "const"),
|
|
10388
|
-
loop: new TokenType("loop", TokenClass.keyword, "loop"),
|
|
10389
|
-
while: new TokenType("while", TokenClass.keyword, "while"),
|
|
10390
|
-
private: new TokenType("private", TokenClass.keyword, "private"),
|
|
10391
|
-
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
10392
|
-
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
10393
|
-
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
10394
|
-
requires: new TokenType("requires", TokenClass.keyword, "requires"),
|
|
10395
|
-
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
10396
|
-
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
10397
|
-
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
10398
|
-
alias: new TokenType("alias", TokenClass.keyword, "alias"),
|
|
10399
|
-
type: new TokenType("type", TokenClass.keyword, "type"),
|
|
10400
|
-
uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
|
|
10401
|
-
var: new TokenType("var", TokenClass.keyword, "var"),
|
|
10402
|
-
override: new TokenType("override", TokenClass.keyword, "override"),
|
|
10403
|
-
workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
|
|
10404
|
-
write: new TokenType("write", TokenClass.keyword, "write"),
|
|
10405
|
-
r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
|
|
10406
|
-
r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
|
|
10407
|
-
r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
|
|
10408
|
-
r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
|
|
10409
|
-
r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
|
|
10410
|
-
r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
|
|
10411
|
-
r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
|
|
10412
|
-
rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
|
|
10413
|
-
rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
|
|
10414
|
-
rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
|
|
10415
|
-
rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
|
|
10416
|
-
r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
|
|
10417
|
-
r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
|
|
10418
|
-
r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
|
|
10419
|
-
rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
|
|
10420
|
-
rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
|
|
10421
|
-
rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
|
|
10422
|
-
rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
|
|
10423
|
-
rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
|
|
10424
|
-
rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
|
|
10425
|
-
rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
|
|
10426
|
-
rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
|
|
10427
|
-
bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
|
|
10428
|
-
bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
|
|
10429
|
-
rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
|
|
10430
|
-
rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
|
|
10431
|
-
rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
|
|
10432
|
-
rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
|
|
10433
|
-
rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
|
|
10434
|
-
rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
|
|
10435
|
-
rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
|
|
10436
|
-
rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
|
|
10437
|
-
rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
|
|
10438
|
-
rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
|
|
10439
|
-
rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
|
|
10440
|
-
static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert"),
|
|
10441
|
-
// WGSL grammar has a few keywords that have different token names than the strings they
|
|
10442
|
-
// represent. Aliasing them here.
|
|
10443
|
-
/*int32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
10444
|
-
uint32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
10445
|
-
float32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
10446
|
-
pointer: new TokenType("ptr", TokenClass.keyword, "ptr"),*/
|
|
10447
|
-
};
|
|
10448
|
-
TokenTypes.tokens = {
|
|
10449
|
-
decimal_float_literal: new TokenType("decimal_float_literal", TokenClass.token, /((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),
|
|
10450
|
-
hex_float_literal: new TokenType("hex_float_literal", TokenClass.token, /-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),
|
|
10451
|
-
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
10452
|
-
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
10453
|
-
ident: new TokenType("ident", TokenClass.token, /[_a-zA-Z][0-9a-zA-Z_]*/),
|
|
10454
|
-
and: new TokenType("and", TokenClass.token, "&"),
|
|
10455
|
-
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
10456
|
-
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
10457
|
-
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
10458
|
-
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
10459
|
-
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
10460
|
-
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
10461
|
-
bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
|
|
10462
|
-
brace_left: new TokenType("brace_left", TokenClass.token, "{"),
|
|
10463
|
-
brace_right: new TokenType("brace_right", TokenClass.token, "}"),
|
|
10464
|
-
colon: new TokenType("colon", TokenClass.token, ":"),
|
|
10465
|
-
comma: new TokenType("comma", TokenClass.token, ","),
|
|
10466
|
-
equal: new TokenType("equal", TokenClass.token, "="),
|
|
10467
|
-
equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
|
|
10468
|
-
not_equal: new TokenType("not_equal", TokenClass.token, "!="),
|
|
10469
|
-
greater_than: new TokenType("greater_than", TokenClass.token, ">"),
|
|
10470
|
-
greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
|
|
10471
|
-
shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
|
|
10472
|
-
less_than: new TokenType("less_than", TokenClass.token, "<"),
|
|
10473
|
-
less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
|
|
10474
|
-
shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
|
|
10475
|
-
modulo: new TokenType("modulo", TokenClass.token, "%"),
|
|
10476
|
-
minus: new TokenType("minus", TokenClass.token, "-"),
|
|
10477
|
-
minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
|
|
10478
|
-
period: new TokenType("period", TokenClass.token, "."),
|
|
10479
|
-
plus: new TokenType("plus", TokenClass.token, "+"),
|
|
10480
|
-
plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
|
|
10481
|
-
or: new TokenType("or", TokenClass.token, "|"),
|
|
10482
|
-
or_or: new TokenType("or_or", TokenClass.token, "||"),
|
|
10483
|
-
paren_left: new TokenType("paren_left", TokenClass.token, "("),
|
|
10484
|
-
paren_right: new TokenType("paren_right", TokenClass.token, ")"),
|
|
10485
|
-
semicolon: new TokenType("semicolon", TokenClass.token, ";"),
|
|
10486
|
-
star: new TokenType("star", TokenClass.token, "*"),
|
|
10487
|
-
tilde: new TokenType("tilde", TokenClass.token, "~"),
|
|
10488
|
-
underscore: new TokenType("underscore", TokenClass.token, "_"),
|
|
10489
|
-
xor: new TokenType("xor", TokenClass.token, "^"),
|
|
10490
|
-
plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
|
|
10491
|
-
minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
|
|
10492
|
-
times_equal: new TokenType("times_equal", TokenClass.token, "*="),
|
|
10493
|
-
division_equal: new TokenType("division_equal", TokenClass.token, "/="),
|
|
10494
|
-
modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
|
|
10495
|
-
and_equal: new TokenType("and_equal", TokenClass.token, "&="),
|
|
10496
|
-
or_equal: new TokenType("or_equal", TokenClass.token, "|="),
|
|
10497
|
-
xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
|
|
10498
|
-
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
10499
|
-
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<="),
|
|
10500
|
-
};
|
|
10501
|
-
TokenTypes.simpleTokens = {
|
|
10502
|
-
"@": _a.tokens.attr,
|
|
10503
|
-
"{": _a.tokens.brace_left,
|
|
10504
|
-
"}": _a.tokens.brace_right,
|
|
10505
|
-
":": _a.tokens.colon,
|
|
10506
|
-
",": _a.tokens.comma,
|
|
10507
|
-
"(": _a.tokens.paren_left,
|
|
10508
|
-
")": _a.tokens.paren_right,
|
|
10509
|
-
";": _a.tokens.semicolon,
|
|
10510
|
-
};
|
|
10511
|
-
TokenTypes.literalTokens = {
|
|
10512
|
-
"&": _a.tokens.and,
|
|
10513
|
-
"&&": _a.tokens.and_and,
|
|
10514
|
-
"->": _a.tokens.arrow,
|
|
10515
|
-
"/": _a.tokens.forward_slash,
|
|
10516
|
-
"!": _a.tokens.bang,
|
|
10517
|
-
"[": _a.tokens.bracket_left,
|
|
10518
|
-
"]": _a.tokens.bracket_right,
|
|
10519
|
-
"=": _a.tokens.equal,
|
|
10520
|
-
"==": _a.tokens.equal_equal,
|
|
10521
|
-
"!=": _a.tokens.not_equal,
|
|
10522
|
-
">": _a.tokens.greater_than,
|
|
10523
|
-
">=": _a.tokens.greater_than_equal,
|
|
10524
|
-
">>": _a.tokens.shift_right,
|
|
10525
|
-
"<": _a.tokens.less_than,
|
|
10526
|
-
"<=": _a.tokens.less_than_equal,
|
|
10527
|
-
"<<": _a.tokens.shift_left,
|
|
10528
|
-
"%": _a.tokens.modulo,
|
|
10529
|
-
"-": _a.tokens.minus,
|
|
10530
|
-
"--": _a.tokens.minus_minus,
|
|
10531
|
-
".": _a.tokens.period,
|
|
10532
|
-
"+": _a.tokens.plus,
|
|
10533
|
-
"++": _a.tokens.plus_plus,
|
|
10534
|
-
"|": _a.tokens.or,
|
|
10535
|
-
"||": _a.tokens.or_or,
|
|
10536
|
-
"*": _a.tokens.star,
|
|
10537
|
-
"~": _a.tokens.tilde,
|
|
10538
|
-
"_": _a.tokens.underscore,
|
|
10539
|
-
"^": _a.tokens.xor,
|
|
10540
|
-
"+=": _a.tokens.plus_equal,
|
|
10541
|
-
"-=": _a.tokens.minus_equal,
|
|
10542
|
-
"*=": _a.tokens.times_equal,
|
|
10543
|
-
"/=": _a.tokens.division_equal,
|
|
10544
|
-
"%=": _a.tokens.modulo_equal,
|
|
10545
|
-
"&=": _a.tokens.and_equal,
|
|
10546
|
-
"|=": _a.tokens.or_equal,
|
|
10547
|
-
"^=": _a.tokens.xor_equal,
|
|
10548
|
-
">>=": _a.tokens.shift_right_equal,
|
|
10549
|
-
"<<=": _a.tokens.shift_left_equal,
|
|
10550
|
-
};
|
|
10551
|
-
TokenTypes.regexTokens = {
|
|
10552
|
-
decimal_float_literal: _a.tokens.decimal_float_literal,
|
|
10553
|
-
hex_float_literal: _a.tokens.hex_float_literal,
|
|
10554
|
-
int_literal: _a.tokens.int_literal,
|
|
10555
|
-
uint_literal: _a.tokens.uint_literal,
|
|
10556
|
-
ident: _a.tokens.ident,
|
|
10557
|
-
};
|
|
10558
|
-
TokenTypes.storage_class = [
|
|
10559
|
-
_a.keywords.function,
|
|
10560
|
-
_a.keywords.private,
|
|
10561
|
-
_a.keywords.workgroup,
|
|
10562
|
-
_a.keywords.uniform,
|
|
10563
|
-
_a.keywords.storage,
|
|
10564
|
-
];
|
|
10565
|
-
TokenTypes.access_mode = [
|
|
10566
|
-
_a.keywords.read,
|
|
10567
|
-
_a.keywords.write,
|
|
10568
|
-
_a.keywords.read_write,
|
|
10569
|
-
];
|
|
10570
|
-
TokenTypes.sampler_type = [
|
|
10571
|
-
_a.keywords.sampler,
|
|
10572
|
-
_a.keywords.sampler_comparison,
|
|
10573
|
-
];
|
|
10574
|
-
TokenTypes.sampled_texture_type = [
|
|
10575
|
-
_a.keywords.texture_1d,
|
|
10576
|
-
_a.keywords.texture_2d,
|
|
10577
|
-
_a.keywords.texture_2d_array,
|
|
10578
|
-
_a.keywords.texture_3d,
|
|
10579
|
-
_a.keywords.texture_cube,
|
|
10580
|
-
_a.keywords.texture_cube_array,
|
|
10581
|
-
];
|
|
10582
|
-
TokenTypes.multisampled_texture_type = [
|
|
10583
|
-
_a.keywords.texture_multisampled_2d,
|
|
10584
|
-
];
|
|
10585
|
-
TokenTypes.storage_texture_type = [
|
|
10586
|
-
_a.keywords.texture_storage_1d,
|
|
10587
|
-
_a.keywords.texture_storage_2d,
|
|
10588
|
-
_a.keywords.texture_storage_2d_array,
|
|
10589
|
-
_a.keywords.texture_storage_3d,
|
|
10590
|
-
];
|
|
10591
|
-
TokenTypes.depth_texture_type = [
|
|
10592
|
-
_a.keywords.texture_depth_2d,
|
|
10593
|
-
_a.keywords.texture_depth_2d_array,
|
|
10594
|
-
_a.keywords.texture_depth_cube,
|
|
10595
|
-
_a.keywords.texture_depth_cube_array,
|
|
10596
|
-
_a.keywords.texture_depth_multisampled_2d,
|
|
10597
|
-
];
|
|
10598
|
-
TokenTypes.texture_external_type = [_a.keywords.texture_external];
|
|
10599
|
-
TokenTypes.any_texture_type = [
|
|
10600
|
-
..._a.sampled_texture_type,
|
|
10601
|
-
..._a.multisampled_texture_type,
|
|
10602
|
-
..._a.storage_texture_type,
|
|
10603
|
-
..._a.depth_texture_type,
|
|
10604
|
-
..._a.texture_external_type,
|
|
10605
|
-
];
|
|
10606
|
-
TokenTypes.texel_format = [
|
|
10607
|
-
_a.keywords.r8unorm,
|
|
10608
|
-
_a.keywords.r8snorm,
|
|
10609
|
-
_a.keywords.r8uint,
|
|
10610
|
-
_a.keywords.r8sint,
|
|
10611
|
-
_a.keywords.r16uint,
|
|
10612
|
-
_a.keywords.r16sint,
|
|
10613
|
-
_a.keywords.r16float,
|
|
10614
|
-
_a.keywords.rg8unorm,
|
|
10615
|
-
_a.keywords.rg8snorm,
|
|
10616
|
-
_a.keywords.rg8uint,
|
|
10617
|
-
_a.keywords.rg8sint,
|
|
10618
|
-
_a.keywords.r32uint,
|
|
10619
|
-
_a.keywords.r32sint,
|
|
10620
|
-
_a.keywords.r32float,
|
|
10621
|
-
_a.keywords.rg16uint,
|
|
10622
|
-
_a.keywords.rg16sint,
|
|
10623
|
-
_a.keywords.rg16float,
|
|
10624
|
-
_a.keywords.rgba8unorm,
|
|
10625
|
-
_a.keywords.rgba8unorm_srgb,
|
|
10626
|
-
_a.keywords.rgba8snorm,
|
|
10627
|
-
_a.keywords.rgba8uint,
|
|
10628
|
-
_a.keywords.rgba8sint,
|
|
10629
|
-
_a.keywords.bgra8unorm,
|
|
10630
|
-
_a.keywords.bgra8unorm_srgb,
|
|
10631
|
-
_a.keywords.rgb10a2unorm,
|
|
10632
|
-
_a.keywords.rg11b10float,
|
|
10633
|
-
_a.keywords.rg32uint,
|
|
10634
|
-
_a.keywords.rg32sint,
|
|
10635
|
-
_a.keywords.rg32float,
|
|
10636
|
-
_a.keywords.rgba16uint,
|
|
10637
|
-
_a.keywords.rgba16sint,
|
|
10638
|
-
_a.keywords.rgba16float,
|
|
10639
|
-
_a.keywords.rgba32uint,
|
|
10640
|
-
_a.keywords.rgba32sint,
|
|
10641
|
-
_a.keywords.rgba32float,
|
|
10642
|
-
];
|
|
10643
|
-
TokenTypes.const_literal = [
|
|
10644
|
-
_a.tokens.int_literal,
|
|
10645
|
-
_a.tokens.uint_literal,
|
|
10646
|
-
_a.tokens.decimal_float_literal,
|
|
10647
|
-
_a.tokens.hex_float_literal,
|
|
10648
|
-
_a.keywords.true,
|
|
10649
|
-
_a.keywords.false,
|
|
10650
|
-
];
|
|
10651
|
-
TokenTypes.literal_or_ident = [
|
|
10652
|
-
_a.tokens.ident,
|
|
10653
|
-
_a.tokens.int_literal,
|
|
10654
|
-
_a.tokens.uint_literal,
|
|
10655
|
-
_a.tokens.decimal_float_literal,
|
|
10656
|
-
_a.tokens.hex_float_literal,
|
|
10657
|
-
];
|
|
10658
|
-
TokenTypes.element_count_expression = [
|
|
10659
|
-
_a.tokens.int_literal,
|
|
10660
|
-
_a.tokens.uint_literal,
|
|
10661
|
-
_a.tokens.ident,
|
|
10662
|
-
];
|
|
10663
|
-
TokenTypes.template_types = [
|
|
10664
|
-
_a.keywords.vec2,
|
|
10665
|
-
_a.keywords.vec3,
|
|
10666
|
-
_a.keywords.vec4,
|
|
10667
|
-
_a.keywords.mat2x2,
|
|
10668
|
-
_a.keywords.mat2x3,
|
|
10669
|
-
_a.keywords.mat2x4,
|
|
10670
|
-
_a.keywords.mat3x2,
|
|
10671
|
-
_a.keywords.mat3x3,
|
|
10672
|
-
_a.keywords.mat3x4,
|
|
10673
|
-
_a.keywords.mat4x2,
|
|
10674
|
-
_a.keywords.mat4x3,
|
|
10675
|
-
_a.keywords.mat4x4,
|
|
10676
|
-
_a.keywords.atomic,
|
|
10677
|
-
_a.keywords.bitcast,
|
|
10678
|
-
..._a.any_texture_type,
|
|
10679
|
-
];
|
|
10680
|
-
// The grammar calls out 'block', but attribute grammar is defined to use a 'ident'.
|
|
10681
|
-
// The attribute grammar should be ident | block.
|
|
10682
|
-
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block, _a.keywords.diagnostic];
|
|
10683
|
-
TokenTypes.assignment_operators = [
|
|
10684
|
-
_a.tokens.equal,
|
|
10685
|
-
_a.tokens.plus_equal,
|
|
10686
|
-
_a.tokens.minus_equal,
|
|
10687
|
-
_a.tokens.times_equal,
|
|
10688
|
-
_a.tokens.division_equal,
|
|
10689
|
-
_a.tokens.modulo_equal,
|
|
10690
|
-
_a.tokens.and_equal,
|
|
10691
|
-
_a.tokens.or_equal,
|
|
10692
|
-
_a.tokens.xor_equal,
|
|
10693
|
-
_a.tokens.shift_right_equal,
|
|
10694
|
-
_a.tokens.shift_left_equal,
|
|
10695
|
-
];
|
|
10696
|
-
TokenTypes.increment_operators = [
|
|
10697
|
-
_a.tokens.plus_plus,
|
|
10698
|
-
_a.tokens.minus_minus,
|
|
10699
|
-
];
|
|
10700
|
-
/// A token parsed by the WgslScanner.
|
|
10701
|
-
class Token {
|
|
10702
|
-
constructor(type, lexeme, line) {
|
|
10703
|
-
this.type = type;
|
|
10704
|
-
this.lexeme = lexeme;
|
|
10705
|
-
this.line = line;
|
|
10706
|
-
}
|
|
10707
|
-
toString() {
|
|
10708
|
-
return this.lexeme;
|
|
10709
|
-
}
|
|
10710
|
-
isTemplateType() {
|
|
10711
|
-
return TokenTypes.template_types.indexOf(this.type) != -1;
|
|
10712
|
-
}
|
|
10713
|
-
isArrayType() {
|
|
10714
|
-
return this.type == TokenTypes.keywords.array;
|
|
10715
|
-
}
|
|
10716
|
-
isArrayOrTemplateType() {
|
|
10717
|
-
return this.isArrayType() || this.isTemplateType();
|
|
10718
|
-
}
|
|
10719
|
-
}
|
|
10720
|
-
/// Lexical scanner for the WGSL language. This takes an input source text and generates a list
|
|
10721
|
-
/// of Token objects, which can then be fed into the WgslParser to generate an AST.
|
|
10722
|
-
class WgslScanner {
|
|
10723
|
-
constructor(source) {
|
|
10724
|
-
this._tokens = [];
|
|
10725
|
-
this._start = 0;
|
|
10726
|
-
this._current = 0;
|
|
10727
|
-
this._line = 1;
|
|
10728
|
-
this._source = source !== null && source !== void 0 ? source : "";
|
|
10729
|
-
}
|
|
10730
|
-
/// Scan all tokens from the source.
|
|
10731
|
-
scanTokens() {
|
|
10732
|
-
while (!this._isAtEnd()) {
|
|
10733
|
-
this._start = this._current;
|
|
10734
|
-
if (!this.scanToken()) {
|
|
10735
|
-
throw `Invalid syntax at line ${this._line}`;
|
|
10736
|
-
}
|
|
10737
|
-
}
|
|
10738
|
-
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
10739
|
-
return this._tokens;
|
|
10740
|
-
}
|
|
10741
|
-
/// Scan a single token from the source.
|
|
10742
|
-
scanToken() {
|
|
10743
|
-
// Find the longest consecutive set of characters that match a rule.
|
|
10744
|
-
let lexeme = this._advance();
|
|
10745
|
-
// Skip line-feed, adding to the line counter.
|
|
10746
|
-
if (lexeme == "\n") {
|
|
10747
|
-
this._line++;
|
|
10748
|
-
return true;
|
|
10749
|
-
}
|
|
10750
|
-
// Skip whitespace
|
|
10751
|
-
if (this._isWhitespace(lexeme)) {
|
|
10752
|
-
return true;
|
|
10753
|
-
}
|
|
10754
|
-
if (lexeme == "/") {
|
|
10755
|
-
// If it's a // comment, skip everything until the next line-feed.
|
|
10756
|
-
if (this._peekAhead() == "/") {
|
|
10757
|
-
while (lexeme != "\n") {
|
|
10758
|
-
if (this._isAtEnd()) {
|
|
10759
|
-
return true;
|
|
10760
|
-
}
|
|
10761
|
-
lexeme = this._advance();
|
|
10762
|
-
}
|
|
10763
|
-
// skip the linefeed
|
|
10764
|
-
this._line++;
|
|
10765
|
-
return true;
|
|
10766
|
-
}
|
|
10767
|
-
else if (this._peekAhead() == "*") {
|
|
10768
|
-
// If it's a / * block comment, skip everything until the matching * /,
|
|
10769
|
-
// allowing for nested block comments.
|
|
10770
|
-
this._advance();
|
|
10771
|
-
let commentLevel = 1;
|
|
10772
|
-
while (commentLevel > 0) {
|
|
10773
|
-
if (this._isAtEnd()) {
|
|
10774
|
-
return true;
|
|
10775
|
-
}
|
|
10776
|
-
lexeme = this._advance();
|
|
10777
|
-
if (lexeme == "\n") {
|
|
10778
|
-
this._line++;
|
|
10779
|
-
}
|
|
10780
|
-
else if (lexeme == "*") {
|
|
10781
|
-
if (this._peekAhead() == "/") {
|
|
10782
|
-
this._advance();
|
|
10783
|
-
commentLevel--;
|
|
10784
|
-
if (commentLevel == 0) {
|
|
10785
|
-
return true;
|
|
10786
|
-
}
|
|
10787
|
-
}
|
|
10788
|
-
}
|
|
10789
|
-
else if (lexeme == "/") {
|
|
10790
|
-
if (this._peekAhead() == "*") {
|
|
10791
|
-
this._advance();
|
|
10792
|
-
commentLevel++;
|
|
10793
|
-
}
|
|
10794
|
-
}
|
|
10795
|
-
}
|
|
10796
|
-
return true;
|
|
10797
|
-
}
|
|
10798
|
-
}
|
|
10799
|
-
// Shortcut single character tokens
|
|
10800
|
-
const simpleToken = TokenTypes.simpleTokens[lexeme];
|
|
10801
|
-
if (simpleToken) {
|
|
10802
|
-
this._addToken(simpleToken);
|
|
10803
|
-
return true;
|
|
10804
|
-
}
|
|
10805
|
-
// Shortcut keywords and identifiers
|
|
10806
|
-
let matchType = TokenTypes.none;
|
|
10807
|
-
const isAlpha = this._isAlpha(lexeme);
|
|
10808
|
-
const isUnderscore = lexeme === "_";
|
|
10809
|
-
if (this._isAlphaNumeric(lexeme)) {
|
|
10810
|
-
let nextChar = this._peekAhead();
|
|
10811
|
-
while (this._isAlphaNumeric(nextChar)) {
|
|
10812
|
-
lexeme += this._advance();
|
|
10813
|
-
nextChar = this._peekAhead();
|
|
10814
|
-
}
|
|
10815
|
-
}
|
|
10816
|
-
if (isAlpha) {
|
|
10817
|
-
const matchedType = TokenTypes.keywords[lexeme];
|
|
10818
|
-
if (matchedType) {
|
|
10819
|
-
this._addToken(matchedType);
|
|
10820
|
-
return true;
|
|
10821
|
-
}
|
|
10822
|
-
}
|
|
10823
|
-
if (isAlpha || isUnderscore) {
|
|
10824
|
-
this._addToken(TokenTypes.tokens.ident);
|
|
10825
|
-
return true;
|
|
10826
|
-
}
|
|
10827
|
-
// Scan for the next valid token type
|
|
10828
|
-
for (;;) {
|
|
10829
|
-
let matchedType = this._findType(lexeme);
|
|
10830
|
-
// An exception to "longest lexeme" rule is '>>'. In the case of 1>>2, it's a
|
|
10831
|
-
// shift_right.
|
|
10832
|
-
// In the case of array<vec4<f32>>, it's two greater_than's (one to close the vec4,
|
|
10833
|
-
// and one to close the array).
|
|
10834
|
-
// Another ambiguity is '>='. In the case of vec2<i32>=vec2(1,2),
|
|
10835
|
-
// it's a greather_than and an equal, not a greater_than_equal.
|
|
10836
|
-
// Another ambiguity is '-'. In the case of a-2, it's a minus; in the case of a*-2, it's a -2;
|
|
10837
|
-
// in the case of foo()->int, it's a ->; in the case of foo-- or --foo, it's a -- decrement.
|
|
10838
|
-
// WGSL requires context sensitive parsing to resolve these ambiguities. Both of these cases
|
|
10839
|
-
// are predicated on it the > either closing a template, or being part of an operator.
|
|
10840
|
-
// The solution here is to check if there was a less_than up to some number of tokens
|
|
10841
|
-
// previously, and the token prior to that is a keyword that requires a '<', then it will be
|
|
10842
|
-
// split into two operators; otherwise it's a single operator.
|
|
10843
|
-
const nextLexeme = this._peekAhead();
|
|
10844
|
-
if (lexeme == "-" && this._tokens.length > 0) {
|
|
10845
|
-
if (nextLexeme == "=") {
|
|
10846
|
-
this._current++;
|
|
10847
|
-
lexeme += nextLexeme;
|
|
10848
|
-
this._addToken(TokenTypes.tokens.minus_equal);
|
|
10849
|
-
return true;
|
|
10850
|
-
}
|
|
10851
|
-
if (nextLexeme == "-") {
|
|
10852
|
-
this._current++;
|
|
10853
|
-
lexeme += nextLexeme;
|
|
10854
|
-
this._addToken(TokenTypes.tokens.minus_minus);
|
|
10855
|
-
return true;
|
|
10856
|
-
}
|
|
10857
|
-
const ti = this._tokens.length - 1;
|
|
10858
|
-
const isIdentOrLiteral = TokenTypes.literal_or_ident.indexOf(this._tokens[ti].type) != -1;
|
|
10859
|
-
if ((isIdentOrLiteral || this._tokens[ti].type == TokenTypes.tokens.paren_right) && nextLexeme != ">") {
|
|
10860
|
-
this._addToken(matchedType);
|
|
10861
|
-
return true;
|
|
10862
|
-
}
|
|
10863
|
-
}
|
|
10864
|
-
if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
|
|
10865
|
-
let foundLessThan = false;
|
|
10866
|
-
let ti = this._tokens.length - 1;
|
|
10867
|
-
for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
|
|
10868
|
-
if (TokenTypes.assignment_operators.indexOf(this._tokens[ti].type) !== -1) {
|
|
10869
|
-
break;
|
|
10870
|
-
}
|
|
10871
|
-
if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
|
|
10872
|
-
if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
|
|
10873
|
-
foundLessThan = true;
|
|
10874
|
-
}
|
|
10875
|
-
break;
|
|
10876
|
-
}
|
|
10877
|
-
}
|
|
10878
|
-
// If there was a less_than in the recent token history, then this is probably a
|
|
10879
|
-
// greater_than.
|
|
10880
|
-
if (foundLessThan) {
|
|
10881
|
-
this._addToken(matchedType);
|
|
10882
|
-
return true;
|
|
10883
|
-
}
|
|
10884
|
-
}
|
|
10885
|
-
// The current lexeme may not match any rule, but some token types may be invalid for
|
|
10886
|
-
// part of the string but valid after a few more characters.
|
|
10887
|
-
// For example, 0x.5 is a hex_float_literal. But as it's being scanned,
|
|
10888
|
-
// "0" is a int_literal, then "0x" is invalid. If we stopped there, it would return
|
|
10889
|
-
// the int_literal "0", but that's incorrect. So if we look forward a few characters,
|
|
10890
|
-
// we'd get "0x.", which is still invalid, followed by "0x.5" which is the correct
|
|
10891
|
-
// hex_float_literal. So that means if we hit an non-matching string, we should look
|
|
10892
|
-
// ahead up to two characters to see if the string starts matching a valid rule again.
|
|
10893
|
-
if (matchedType === TokenTypes.none) {
|
|
10894
|
-
let lookAheadLexeme = lexeme;
|
|
10895
|
-
let lookAhead = 0;
|
|
10896
|
-
const maxLookAhead = 2;
|
|
10897
|
-
for (let li = 0; li < maxLookAhead; ++li) {
|
|
10898
|
-
lookAheadLexeme += this._peekAhead(li);
|
|
10899
|
-
matchedType = this._findType(lookAheadLexeme);
|
|
10900
|
-
if (matchedType !== TokenTypes.none) {
|
|
10901
|
-
lookAhead = li;
|
|
10902
|
-
break;
|
|
10903
|
-
}
|
|
10904
|
-
}
|
|
10905
|
-
if (matchedType === TokenTypes.none) {
|
|
10906
|
-
if (matchType === TokenTypes.none) {
|
|
10907
|
-
return false;
|
|
10908
|
-
}
|
|
10909
|
-
this._current--;
|
|
10910
|
-
this._addToken(matchType);
|
|
10911
|
-
return true;
|
|
10912
|
-
}
|
|
10913
|
-
lexeme = lookAheadLexeme;
|
|
10914
|
-
this._current += lookAhead + 1;
|
|
10915
|
-
}
|
|
10916
|
-
matchType = matchedType;
|
|
10917
|
-
if (this._isAtEnd()) {
|
|
10918
|
-
break;
|
|
10919
|
-
}
|
|
10920
|
-
lexeme += this._advance();
|
|
10921
|
-
}
|
|
10922
|
-
// We got to the end of the input stream. Then the token we've ready so far is it.
|
|
10923
|
-
if (matchType === TokenTypes.none) {
|
|
10924
|
-
return false;
|
|
10925
|
-
}
|
|
10926
|
-
this._addToken(matchType);
|
|
10927
|
-
return true;
|
|
10928
|
-
}
|
|
10929
|
-
_findType(lexeme) {
|
|
10930
|
-
for (const name in TokenTypes.regexTokens) {
|
|
10931
|
-
const type = TokenTypes.regexTokens[name];
|
|
10932
|
-
if (this._match(lexeme, type.rule)) {
|
|
10933
|
-
return type;
|
|
10934
|
-
}
|
|
10935
|
-
}
|
|
10936
|
-
const type = TokenTypes.literalTokens[lexeme];
|
|
10937
|
-
if (type) {
|
|
10938
|
-
return type;
|
|
10939
|
-
}
|
|
10940
|
-
return TokenTypes.none;
|
|
10941
|
-
}
|
|
10942
|
-
_match(lexeme, rule) {
|
|
10943
|
-
const match = rule.exec(lexeme);
|
|
10944
|
-
return match && match.index == 0 && match[0] == lexeme;
|
|
10945
|
-
}
|
|
10946
|
-
_isAtEnd() {
|
|
10947
|
-
return this._current >= this._source.length;
|
|
10948
|
-
}
|
|
10949
|
-
_isAlpha(c) {
|
|
10950
|
-
return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z");
|
|
10951
|
-
}
|
|
10952
|
-
_isAlphaNumeric(c) {
|
|
10953
|
-
return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z") || c == "_" || (c >= "0" && c <= "9");
|
|
10954
|
-
}
|
|
10955
|
-
_isWhitespace(c) {
|
|
10956
|
-
return c == " " || c == "\t" || c == "\r";
|
|
10957
|
-
}
|
|
10958
|
-
_advance(amount = 0) {
|
|
10959
|
-
let c = this._source[this._current];
|
|
10960
|
-
amount = amount || 0;
|
|
10961
|
-
amount++;
|
|
10962
|
-
this._current += amount;
|
|
10963
|
-
return c;
|
|
10964
|
-
}
|
|
10965
|
-
_peekAhead(offset = 0) {
|
|
10966
|
-
offset = offset || 0;
|
|
10967
|
-
if (this._current + offset >= this._source.length) {
|
|
10968
|
-
return "\0";
|
|
10969
|
-
}
|
|
10970
|
-
return this._source[this._current + offset];
|
|
10971
|
-
}
|
|
10972
|
-
_addToken(type) {
|
|
10973
|
-
const text = this._source.substring(this._start, this._current);
|
|
10974
|
-
this._tokens.push(new Token(type, text, this._line));
|
|
10975
|
-
}
|
|
10976
|
-
}
|
|
10977
|
-
|
|
10978
|
-
/**
|
|
10979
|
-
* @author Brendan Duncan / https://github.com/brendan-duncan
|
|
10980
|
-
*/
|
|
10981
|
-
/// Parse a sequence of tokens from the WgslScanner into an Abstract Syntax Tree (AST).
|
|
10982
|
-
class WgslParser {
|
|
10983
|
-
constructor() {
|
|
10984
|
-
this._tokens = [];
|
|
10985
|
-
this._current = 0;
|
|
10986
|
-
this._currentLine = 0;
|
|
10987
|
-
this._context = new ParseContext();
|
|
10988
|
-
this._deferArrayCountEval = [];
|
|
10989
|
-
}
|
|
10990
|
-
parse(tokensOrCode) {
|
|
10991
|
-
this._initialize(tokensOrCode);
|
|
10992
|
-
this._deferArrayCountEval.length = 0;
|
|
10993
|
-
const statements = [];
|
|
10994
|
-
while (!this._isAtEnd()) {
|
|
10995
|
-
const statement = this._global_decl_or_directive();
|
|
10996
|
-
if (!statement) {
|
|
10997
|
-
break;
|
|
10998
|
-
}
|
|
10999
|
-
statements.push(statement);
|
|
11000
|
-
}
|
|
11001
|
-
// Since constants can be declared after they are used, and
|
|
11002
|
-
// constants can be used to size arrays, defer calculating the
|
|
11003
|
-
// size until after the shader has finished parsing.
|
|
11004
|
-
if (this._deferArrayCountEval.length > 0) {
|
|
11005
|
-
for (const arrayDecl of this._deferArrayCountEval) {
|
|
11006
|
-
const arrayType = arrayDecl["arrayType"];
|
|
11007
|
-
const countNode = arrayDecl["countNode"];
|
|
11008
|
-
if (countNode instanceof VariableExpr) {
|
|
11009
|
-
const variable = countNode;
|
|
11010
|
-
const name = variable.name;
|
|
11011
|
-
const constant = this._context.constants.get(name);
|
|
11012
|
-
if (constant) {
|
|
11013
|
-
try {
|
|
11014
|
-
const count = constant.evaluate(this._context);
|
|
11015
|
-
arrayType.count = count;
|
|
11016
|
-
}
|
|
11017
|
-
catch (e) {
|
|
11018
|
-
}
|
|
11019
|
-
}
|
|
11020
|
-
}
|
|
11021
|
-
}
|
|
11022
|
-
this._deferArrayCountEval.length = 0;
|
|
11023
|
-
}
|
|
11024
|
-
return statements;
|
|
11025
|
-
}
|
|
11026
|
-
_initialize(tokensOrCode) {
|
|
11027
|
-
if (tokensOrCode) {
|
|
11028
|
-
if (typeof tokensOrCode == "string") {
|
|
11029
|
-
const scanner = new WgslScanner(tokensOrCode);
|
|
11030
|
-
this._tokens = scanner.scanTokens();
|
|
11031
|
-
}
|
|
11032
|
-
else {
|
|
11033
|
-
this._tokens = tokensOrCode;
|
|
11034
|
-
}
|
|
11035
|
-
}
|
|
11036
|
-
else {
|
|
11037
|
-
this._tokens = [];
|
|
11038
|
-
}
|
|
11039
|
-
this._current = 0;
|
|
11040
|
-
}
|
|
11041
|
-
_error(token, message) {
|
|
11042
|
-
return {
|
|
11043
|
-
token,
|
|
11044
|
-
message,
|
|
11045
|
-
toString: function () {
|
|
11046
|
-
return `${message}`;
|
|
11047
|
-
},
|
|
11048
|
-
};
|
|
11049
|
-
}
|
|
11050
|
-
_isAtEnd() {
|
|
11051
|
-
return (this._current >= this._tokens.length ||
|
|
11052
|
-
this._peek().type == TokenTypes.eof);
|
|
11053
|
-
}
|
|
11054
|
-
_match(types) {
|
|
11055
|
-
if (types instanceof TokenType) {
|
|
11056
|
-
if (this._check(types)) {
|
|
11057
|
-
this._advance();
|
|
11058
|
-
return true;
|
|
11059
|
-
}
|
|
11060
|
-
return false;
|
|
11061
|
-
}
|
|
11062
|
-
for (let i = 0, l = types.length; i < l; ++i) {
|
|
11063
|
-
const type = types[i];
|
|
11064
|
-
if (this._check(type)) {
|
|
11065
|
-
this._advance();
|
|
11066
|
-
return true;
|
|
11067
|
-
}
|
|
11068
|
-
}
|
|
11069
|
-
return false;
|
|
11070
|
-
}
|
|
11071
|
-
_consume(types, message) {
|
|
11072
|
-
if (this._check(types)) {
|
|
11073
|
-
return this._advance();
|
|
11074
|
-
}
|
|
11075
|
-
throw this._error(this._peek(), message);
|
|
11076
|
-
}
|
|
11077
|
-
_check(types) {
|
|
11078
|
-
if (this._isAtEnd()) {
|
|
11079
|
-
return false;
|
|
11080
|
-
}
|
|
11081
|
-
const tk = this._peek();
|
|
11082
|
-
if (types instanceof Array) {
|
|
11083
|
-
const t = tk.type;
|
|
11084
|
-
const index = types.indexOf(t);
|
|
11085
|
-
return index != -1;
|
|
11086
|
-
}
|
|
11087
|
-
return tk.type == types;
|
|
11088
|
-
}
|
|
11089
|
-
_advance() {
|
|
11090
|
-
var _a, _b;
|
|
11091
|
-
this._currentLine = (_b = (_a = this._peek()) === null || _a === void 0 ? void 0 : _a.line) !== null && _b !== void 0 ? _b : -1;
|
|
11092
|
-
if (!this._isAtEnd()) {
|
|
11093
|
-
this._current++;
|
|
11094
|
-
}
|
|
11095
|
-
return this._previous();
|
|
11096
|
-
}
|
|
11097
|
-
_peek() {
|
|
11098
|
-
return this._tokens[this._current];
|
|
11099
|
-
}
|
|
11100
|
-
_previous() {
|
|
11101
|
-
return this._tokens[this._current - 1];
|
|
11102
|
-
}
|
|
11103
|
-
_global_decl_or_directive() {
|
|
11104
|
-
// semicolon
|
|
11105
|
-
// global_variable_decl semicolon
|
|
11106
|
-
// global_constant_decl semicolon
|
|
11107
|
-
// type_alias semicolon
|
|
11108
|
-
// struct_decl
|
|
11109
|
-
// function_decl
|
|
11110
|
-
// enable_directive
|
|
11111
|
-
// Ignore any stand-alone semicolons
|
|
11112
|
-
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
11113
|
-
;
|
|
11114
|
-
if (this._match(TokenTypes.keywords.alias)) {
|
|
11115
|
-
const type = this._type_alias();
|
|
11116
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
11117
|
-
return type;
|
|
11118
|
-
}
|
|
11119
|
-
if (this._match(TokenTypes.keywords.diagnostic)) {
|
|
11120
|
-
const directive = this._diagnostic();
|
|
11121
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
11122
|
-
return directive;
|
|
11123
|
-
}
|
|
11124
|
-
if (this._match(TokenTypes.keywords.requires)) {
|
|
11125
|
-
const requires = this._requires_directive();
|
|
11126
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
11127
|
-
return requires;
|
|
11128
|
-
}
|
|
11129
|
-
if (this._match(TokenTypes.keywords.enable)) {
|
|
11130
|
-
const enable = this._enable_directive();
|
|
11131
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
11132
|
-
return enable;
|
|
11133
|
-
}
|
|
11134
|
-
// The following statements have an optional attribute*
|
|
11135
|
-
const attrs = this._attribute();
|
|
11136
|
-
if (this._check(TokenTypes.keywords.var)) {
|
|
11137
|
-
const _var = this._global_variable_decl();
|
|
11138
|
-
if (_var != null) {
|
|
11139
|
-
_var.attributes = attrs;
|
|
11140
|
-
}
|
|
11141
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11142
|
-
return _var;
|
|
11143
|
-
}
|
|
11144
|
-
if (this._check(TokenTypes.keywords.override)) {
|
|
11145
|
-
const _override = this._override_variable_decl();
|
|
11146
|
-
if (_override != null) {
|
|
11147
|
-
_override.attributes = attrs;
|
|
11148
|
-
}
|
|
11149
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11150
|
-
return _override;
|
|
11151
|
-
}
|
|
11152
|
-
if (this._check(TokenTypes.keywords.let)) {
|
|
11153
|
-
const _let = this._global_let_decl();
|
|
11154
|
-
if (_let != null) {
|
|
11155
|
-
_let.attributes = attrs;
|
|
11156
|
-
}
|
|
11157
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11158
|
-
return _let;
|
|
11159
|
-
}
|
|
11160
|
-
if (this._check(TokenTypes.keywords.const)) {
|
|
11161
|
-
const _const = this._global_const_decl();
|
|
11162
|
-
if (_const != null) {
|
|
11163
|
-
_const.attributes = attrs;
|
|
11164
|
-
}
|
|
11165
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11166
|
-
return _const;
|
|
11167
|
-
}
|
|
11168
|
-
if (this._check(TokenTypes.keywords.struct)) {
|
|
11169
|
-
const _struct = this._struct_decl();
|
|
11170
|
-
if (_struct != null) {
|
|
11171
|
-
_struct.attributes = attrs;
|
|
11172
|
-
}
|
|
11173
|
-
return _struct;
|
|
11174
|
-
}
|
|
11175
|
-
if (this._check(TokenTypes.keywords.fn)) {
|
|
11176
|
-
const _fn = this._function_decl();
|
|
11177
|
-
if (_fn != null) {
|
|
11178
|
-
_fn.attributes = attrs;
|
|
11179
|
-
}
|
|
11180
|
-
return _fn;
|
|
11181
|
-
}
|
|
11182
|
-
return null;
|
|
11183
|
-
}
|
|
11184
|
-
_function_decl() {
|
|
11185
|
-
// attribute* function_header compound_statement
|
|
11186
|
-
// function_header: fn ident paren_left param_list? paren_right (arrow attribute* type_decl)?
|
|
11187
|
-
if (!this._match(TokenTypes.keywords.fn)) {
|
|
11188
|
-
return null;
|
|
11189
|
-
}
|
|
11190
|
-
const startLine = this._currentLine;
|
|
11191
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
11192
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
11193
|
-
const args = [];
|
|
11194
|
-
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
11195
|
-
do {
|
|
11196
|
-
if (this._check(TokenTypes.tokens.paren_right)) {
|
|
11197
|
-
break;
|
|
11198
|
-
}
|
|
11199
|
-
const argAttrs = this._attribute();
|
|
11200
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
11201
|
-
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
11202
|
-
const typeAttrs = this._attribute();
|
|
11203
|
-
const type = this._type_decl();
|
|
11204
|
-
if (type != null) {
|
|
11205
|
-
type.attributes = typeAttrs;
|
|
11206
|
-
args.push(new Argument(name, type, argAttrs));
|
|
11207
|
-
}
|
|
11208
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
11209
|
-
}
|
|
11210
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
|
|
11211
|
-
let _return = null;
|
|
11212
|
-
if (this._match(TokenTypes.tokens.arrow)) {
|
|
11213
|
-
const attrs = this._attribute();
|
|
11214
|
-
_return = this._type_decl();
|
|
11215
|
-
if (_return != null) {
|
|
11216
|
-
_return.attributes = attrs;
|
|
11217
|
-
}
|
|
11218
|
-
}
|
|
11219
|
-
const body = this._compound_statement();
|
|
11220
|
-
const endLine = this._currentLine;
|
|
11221
|
-
return new Function(name, args, _return, body, startLine, endLine);
|
|
11222
|
-
}
|
|
11223
|
-
_compound_statement() {
|
|
11224
|
-
// brace_left statement* brace_right
|
|
11225
|
-
const statements = [];
|
|
11226
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
11227
|
-
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
11228
|
-
const statement = this._statement();
|
|
11229
|
-
if (statement !== null) {
|
|
11230
|
-
statements.push(statement);
|
|
11231
|
-
}
|
|
11232
|
-
}
|
|
11233
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
11234
|
-
return statements;
|
|
11235
|
-
}
|
|
11236
|
-
_statement() {
|
|
11237
|
-
// semicolon
|
|
11238
|
-
// return_statement semicolon
|
|
11239
|
-
// if_statement
|
|
11240
|
-
// switch_statement
|
|
11241
|
-
// loop_statement
|
|
11242
|
-
// for_statement
|
|
11243
|
-
// func_call_statement semicolon
|
|
11244
|
-
// variable_statement semicolon
|
|
11245
|
-
// break_statement semicolon
|
|
11246
|
-
// continue_statement semicolon
|
|
11247
|
-
// continuing_statement compound_statement
|
|
11248
|
-
// discard semicolon
|
|
11249
|
-
// assignment_statement semicolon
|
|
11250
|
-
// compound_statement
|
|
11251
|
-
// increment_statement semicolon
|
|
11252
|
-
// decrement_statement semicolon
|
|
11253
|
-
// static_assert_statement semicolon
|
|
11254
|
-
// Ignore any stand-alone semicolons
|
|
11255
|
-
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
11256
|
-
;
|
|
11257
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11258
|
-
this._attribute();
|
|
11259
|
-
}
|
|
11260
|
-
if (this._check(TokenTypes.keywords.if)) {
|
|
11261
|
-
return this._if_statement();
|
|
11262
|
-
}
|
|
11263
|
-
if (this._check(TokenTypes.keywords.switch)) {
|
|
11264
|
-
return this._switch_statement();
|
|
11265
|
-
}
|
|
11266
|
-
if (this._check(TokenTypes.keywords.loop)) {
|
|
11267
|
-
return this._loop_statement();
|
|
11268
|
-
}
|
|
11269
|
-
if (this._check(TokenTypes.keywords.for)) {
|
|
11270
|
-
return this._for_statement();
|
|
11271
|
-
}
|
|
11272
|
-
if (this._check(TokenTypes.keywords.while)) {
|
|
11273
|
-
return this._while_statement();
|
|
11274
|
-
}
|
|
11275
|
-
if (this._check(TokenTypes.keywords.continuing)) {
|
|
11276
|
-
return this._continuing_statement();
|
|
11277
|
-
}
|
|
11278
|
-
if (this._check(TokenTypes.keywords.static_assert)) {
|
|
11279
|
-
return this._static_assert_statement();
|
|
11280
|
-
}
|
|
11281
|
-
if (this._check(TokenTypes.tokens.brace_left)) {
|
|
11282
|
-
return this._compound_statement();
|
|
11283
|
-
}
|
|
11284
|
-
let result = null;
|
|
11285
|
-
if (this._check(TokenTypes.keywords.return)) {
|
|
11286
|
-
result = this._return_statement();
|
|
11287
|
-
}
|
|
11288
|
-
else if (this._check([
|
|
11289
|
-
TokenTypes.keywords.var,
|
|
11290
|
-
TokenTypes.keywords.let,
|
|
11291
|
-
TokenTypes.keywords.const,
|
|
11292
|
-
])) {
|
|
11293
|
-
result = this._variable_statement();
|
|
11294
|
-
}
|
|
11295
|
-
else if (this._match(TokenTypes.keywords.discard)) {
|
|
11296
|
-
result = new Discard();
|
|
11297
|
-
}
|
|
11298
|
-
else if (this._match(TokenTypes.keywords.break)) {
|
|
11299
|
-
result = new Break();
|
|
11300
|
-
}
|
|
11301
|
-
else if (this._match(TokenTypes.keywords.continue)) {
|
|
11302
|
-
result = new Continue();
|
|
11303
|
-
}
|
|
11304
|
-
else {
|
|
11305
|
-
result =
|
|
11306
|
-
this._increment_decrement_statement() ||
|
|
11307
|
-
this._func_call_statement() ||
|
|
11308
|
-
this._assignment_statement();
|
|
11309
|
-
}
|
|
11310
|
-
if (result != null) {
|
|
11311
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
11312
|
-
}
|
|
11313
|
-
return result;
|
|
11314
|
-
}
|
|
11315
|
-
_static_assert_statement() {
|
|
11316
|
-
if (!this._match(TokenTypes.keywords.static_assert)) {
|
|
11317
|
-
return null;
|
|
11318
|
-
}
|
|
11319
|
-
const expression = this._optional_paren_expression();
|
|
11320
|
-
return new StaticAssert(expression);
|
|
11321
|
-
}
|
|
11322
|
-
_while_statement() {
|
|
11323
|
-
if (!this._match(TokenTypes.keywords.while)) {
|
|
11324
|
-
return null;
|
|
11325
|
-
}
|
|
11326
|
-
const condition = this._optional_paren_expression();
|
|
11327
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11328
|
-
this._attribute();
|
|
11329
|
-
}
|
|
11330
|
-
const block = this._compound_statement();
|
|
11331
|
-
return new While(condition, block);
|
|
11332
|
-
}
|
|
11333
|
-
_continuing_statement() {
|
|
11334
|
-
if (!this._match(TokenTypes.keywords.continuing)) {
|
|
11335
|
-
return null;
|
|
11336
|
-
}
|
|
11337
|
-
const block = this._compound_statement();
|
|
11338
|
-
return new Continuing(block);
|
|
11339
|
-
}
|
|
11340
|
-
_for_statement() {
|
|
11341
|
-
// for paren_left for_header paren_right compound_statement
|
|
11342
|
-
if (!this._match(TokenTypes.keywords.for)) {
|
|
11343
|
-
return null;
|
|
11344
|
-
}
|
|
11345
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
11346
|
-
// for_header: (variable_statement assignment_statement func_call_statement)? semicolon short_circuit_or_expression? semicolon (assignment_statement func_call_statement)?
|
|
11347
|
-
const init = !this._check(TokenTypes.tokens.semicolon)
|
|
11348
|
-
? this._for_init()
|
|
11349
|
-
: null;
|
|
11350
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11351
|
-
const condition = !this._check(TokenTypes.tokens.semicolon)
|
|
11352
|
-
? this._short_circuit_or_expression()
|
|
11353
|
-
: null;
|
|
11354
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
11355
|
-
const increment = !this._check(TokenTypes.tokens.paren_right)
|
|
11356
|
-
? this._for_increment()
|
|
11357
|
-
: null;
|
|
11358
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
11359
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11360
|
-
this._attribute();
|
|
11361
|
-
}
|
|
11362
|
-
const body = this._compound_statement();
|
|
11363
|
-
return new For(init, condition, increment, body);
|
|
11364
|
-
}
|
|
11365
|
-
_for_init() {
|
|
11366
|
-
// (variable_statement assignment_statement func_call_statement)?
|
|
11367
|
-
return (this._variable_statement() ||
|
|
11368
|
-
this._func_call_statement() ||
|
|
11369
|
-
this._assignment_statement());
|
|
11370
|
-
}
|
|
11371
|
-
_for_increment() {
|
|
11372
|
-
// (assignment_statement func_call_statement increment_statement)?
|
|
11373
|
-
return (this._func_call_statement() ||
|
|
11374
|
-
this._increment_decrement_statement() ||
|
|
11375
|
-
this._assignment_statement());
|
|
11376
|
-
}
|
|
11377
|
-
_variable_statement() {
|
|
11378
|
-
// variable_decl
|
|
11379
|
-
// variable_decl equal short_circuit_or_expression
|
|
11380
|
-
// let (ident variable_ident_decl) equal short_circuit_or_expression
|
|
11381
|
-
// const (ident variable_ident_decl) equal short_circuit_or_expression
|
|
11382
|
-
if (this._check(TokenTypes.keywords.var)) {
|
|
11383
|
-
const _var = this._variable_decl();
|
|
11384
|
-
if (_var === null) {
|
|
11385
|
-
throw this._error(this._peek(), "Variable declaration expected.");
|
|
11386
|
-
}
|
|
11387
|
-
let value = null;
|
|
11388
|
-
if (this._match(TokenTypes.tokens.equal)) {
|
|
11389
|
-
value = this._short_circuit_or_expression();
|
|
11390
|
-
}
|
|
11391
|
-
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
11392
|
-
}
|
|
11393
|
-
if (this._match(TokenTypes.keywords.let)) {
|
|
11394
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
|
|
11395
|
-
let type = null;
|
|
11396
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
11397
|
-
const typeAttrs = this._attribute();
|
|
11398
|
-
type = this._type_decl();
|
|
11399
|
-
if (type != null) {
|
|
11400
|
-
type.attributes = typeAttrs;
|
|
11401
|
-
}
|
|
11402
|
-
}
|
|
11403
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
11404
|
-
const value = this._short_circuit_or_expression();
|
|
11405
|
-
return new Let(name, type, null, null, value);
|
|
11406
|
-
}
|
|
11407
|
-
if (this._match(TokenTypes.keywords.const)) {
|
|
11408
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
|
|
11409
|
-
let type = null;
|
|
11410
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
11411
|
-
const typeAttrs = this._attribute();
|
|
11412
|
-
type = this._type_decl();
|
|
11413
|
-
if (type != null) {
|
|
11414
|
-
type.attributes = typeAttrs;
|
|
11415
|
-
}
|
|
11416
|
-
}
|
|
11417
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
11418
|
-
const value = this._short_circuit_or_expression();
|
|
11419
|
-
return new Const(name, type, null, null, value);
|
|
11420
|
-
}
|
|
11421
|
-
return null;
|
|
11422
|
-
}
|
|
11423
|
-
_increment_decrement_statement() {
|
|
11424
|
-
const savedPos = this._current;
|
|
11425
|
-
const _var = this._unary_expression();
|
|
11426
|
-
if (_var == null) {
|
|
11427
|
-
return null;
|
|
11428
|
-
}
|
|
11429
|
-
if (!this._check(TokenTypes.increment_operators)) {
|
|
11430
|
-
this._current = savedPos;
|
|
11431
|
-
return null;
|
|
11432
|
-
}
|
|
11433
|
-
const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
|
|
11434
|
-
return new Increment(token.type === TokenTypes.tokens.plus_plus
|
|
11435
|
-
? IncrementOperator.increment
|
|
11436
|
-
: IncrementOperator.decrement, _var);
|
|
11437
|
-
}
|
|
11438
|
-
_assignment_statement() {
|
|
11439
|
-
// (unary_expression underscore) equal short_circuit_or_expression
|
|
11440
|
-
let _var = null;
|
|
11441
|
-
if (this._check(TokenTypes.tokens.brace_right)) {
|
|
11442
|
-
return null;
|
|
11443
|
-
}
|
|
11444
|
-
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
11445
|
-
if (!isUnderscore) {
|
|
11446
|
-
_var = this._unary_expression();
|
|
11447
|
-
}
|
|
11448
|
-
if (!isUnderscore && _var == null) {
|
|
11449
|
-
return null;
|
|
11450
|
-
}
|
|
11451
|
-
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
11452
|
-
const value = this._short_circuit_or_expression();
|
|
11453
|
-
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
11454
|
-
}
|
|
11455
|
-
_func_call_statement() {
|
|
11456
|
-
// ident argument_expression_list
|
|
11457
|
-
if (!this._check(TokenTypes.tokens.ident)) {
|
|
11458
|
-
return null;
|
|
11459
|
-
}
|
|
11460
|
-
const savedPos = this._current;
|
|
11461
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
11462
|
-
const args = this._argument_expression_list();
|
|
11463
|
-
if (args === null) {
|
|
11464
|
-
this._current = savedPos;
|
|
11465
|
-
return null;
|
|
11466
|
-
}
|
|
11467
|
-
return new Call(name.lexeme, args);
|
|
11468
|
-
}
|
|
11469
|
-
_loop_statement() {
|
|
11470
|
-
// loop brace_left statement* continuing_statement? brace_right
|
|
11471
|
-
if (!this._match(TokenTypes.keywords.loop)) {
|
|
11472
|
-
return null;
|
|
11473
|
-
}
|
|
11474
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11475
|
-
this._attribute();
|
|
11476
|
-
}
|
|
11477
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
11478
|
-
// statement*
|
|
11479
|
-
const statements = [];
|
|
11480
|
-
let statement = this._statement();
|
|
11481
|
-
while (statement !== null) {
|
|
11482
|
-
if (Array.isArray(statement)) {
|
|
11483
|
-
for (let s of statement) {
|
|
11484
|
-
statements.push(s);
|
|
11485
|
-
}
|
|
11486
|
-
}
|
|
11487
|
-
else {
|
|
11488
|
-
statements.push(statement);
|
|
11489
|
-
}
|
|
11490
|
-
statement = this._statement();
|
|
11491
|
-
}
|
|
11492
|
-
// continuing_statement: continuing compound_statement
|
|
11493
|
-
let continuing = null;
|
|
11494
|
-
if (this._match(TokenTypes.keywords.continuing)) {
|
|
11495
|
-
continuing = this._compound_statement();
|
|
11496
|
-
}
|
|
11497
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
11498
|
-
return new Loop(statements, continuing);
|
|
11499
|
-
}
|
|
11500
|
-
_switch_statement() {
|
|
11501
|
-
// switch optional_paren_expression brace_left switch_body+ brace_right
|
|
11502
|
-
if (!this._match(TokenTypes.keywords.switch)) {
|
|
11503
|
-
return null;
|
|
11504
|
-
}
|
|
11505
|
-
const condition = this._optional_paren_expression();
|
|
11506
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11507
|
-
this._attribute();
|
|
11508
|
-
}
|
|
11509
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
11510
|
-
const body = this._switch_body();
|
|
11511
|
-
if (body == null || body.length == 0) {
|
|
11512
|
-
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
11513
|
-
}
|
|
11514
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
11515
|
-
return new Switch(condition, body);
|
|
11516
|
-
}
|
|
11517
|
-
_switch_body() {
|
|
11518
|
-
// case case_selectors colon brace_left case_body? brace_right
|
|
11519
|
-
// default colon brace_left case_body? brace_right
|
|
11520
|
-
const cases = [];
|
|
11521
|
-
if (this._match(TokenTypes.keywords.case)) {
|
|
11522
|
-
const selector = this._case_selectors();
|
|
11523
|
-
this._match(TokenTypes.tokens.colon); // colon is optional
|
|
11524
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11525
|
-
this._attribute();
|
|
11526
|
-
}
|
|
11527
|
-
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
11528
|
-
const body = this._case_body();
|
|
11529
|
-
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
11530
|
-
cases.push(new Case(selector, body));
|
|
11531
|
-
}
|
|
11532
|
-
if (this._match(TokenTypes.keywords.default)) {
|
|
11533
|
-
this._match(TokenTypes.tokens.colon); // colon is optional
|
|
11534
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11535
|
-
this._attribute();
|
|
11536
|
-
}
|
|
11537
|
-
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
11538
|
-
const body = this._case_body();
|
|
11539
|
-
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
11540
|
-
cases.push(new Default(body));
|
|
11541
|
-
}
|
|
11542
|
-
if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
|
|
11543
|
-
const _cases = this._switch_body();
|
|
11544
|
-
cases.push(_cases[0]);
|
|
11545
|
-
}
|
|
11546
|
-
return cases;
|
|
11547
|
-
}
|
|
11548
|
-
_case_selectors() {
|
|
11549
|
-
// const_literal (comma const_literal)* comma?
|
|
11550
|
-
const selectors = [
|
|
11551
|
-
this._shift_expression(), //?.evaluate(this._context).toString() ?? "",
|
|
11552
|
-
];
|
|
11553
|
-
while (this._match(TokenTypes.tokens.comma)) {
|
|
11554
|
-
selectors.push(this._shift_expression());
|
|
11555
|
-
}
|
|
11556
|
-
return selectors;
|
|
11557
|
-
}
|
|
11558
|
-
_case_body() {
|
|
11559
|
-
// statement case_body?
|
|
11560
|
-
// fallthrough semicolon
|
|
11561
|
-
if (this._match(TokenTypes.keywords.fallthrough)) {
|
|
11562
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
11563
|
-
return [];
|
|
11564
|
-
}
|
|
11565
|
-
let statement = this._statement();
|
|
11566
|
-
if (statement == null) {
|
|
11567
|
-
return [];
|
|
11568
|
-
}
|
|
11569
|
-
if (!(statement instanceof Array)) {
|
|
11570
|
-
statement = [statement];
|
|
11571
|
-
}
|
|
11572
|
-
const nextStatement = this._case_body();
|
|
11573
|
-
if (nextStatement.length == 0) {
|
|
11574
|
-
return statement;
|
|
11575
|
-
}
|
|
11576
|
-
return [...statement, nextStatement[0]];
|
|
11577
|
-
}
|
|
11578
|
-
_if_statement() {
|
|
11579
|
-
// if optional_paren_expression compound_statement elseif_statement? else_statement?
|
|
11580
|
-
if (!this._match(TokenTypes.keywords.if)) {
|
|
11581
|
-
return null;
|
|
11582
|
-
}
|
|
11583
|
-
const condition = this._optional_paren_expression();
|
|
11584
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11585
|
-
this._attribute();
|
|
11586
|
-
}
|
|
11587
|
-
const block = this._compound_statement();
|
|
11588
|
-
let elseif = [];
|
|
11589
|
-
if (this._match_elseif()) {
|
|
11590
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11591
|
-
this._attribute();
|
|
11592
|
-
}
|
|
11593
|
-
elseif = this._elseif_statement(elseif);
|
|
11594
|
-
}
|
|
11595
|
-
let _else = null;
|
|
11596
|
-
if (this._match(TokenTypes.keywords.else)) {
|
|
11597
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11598
|
-
this._attribute();
|
|
11599
|
-
}
|
|
11600
|
-
_else = this._compound_statement();
|
|
11601
|
-
}
|
|
11602
|
-
return new If(condition, block, elseif, _else);
|
|
11603
|
-
}
|
|
11604
|
-
_match_elseif() {
|
|
11605
|
-
if (this._tokens[this._current].type === TokenTypes.keywords.else &&
|
|
11606
|
-
this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
|
|
11607
|
-
this._advance();
|
|
11608
|
-
this._advance();
|
|
11609
|
-
return true;
|
|
11610
|
-
}
|
|
11611
|
-
return false;
|
|
11612
|
-
}
|
|
11613
|
-
_elseif_statement(elseif = []) {
|
|
11614
|
-
// else_if optional_paren_expression compound_statement elseif_statement?
|
|
11615
|
-
const condition = this._optional_paren_expression();
|
|
11616
|
-
const block = this._compound_statement();
|
|
11617
|
-
elseif.push(new ElseIf(condition, block));
|
|
11618
|
-
if (this._match_elseif()) {
|
|
11619
|
-
if (this._check(TokenTypes.tokens.attr)) {
|
|
11620
|
-
this._attribute();
|
|
11621
|
-
}
|
|
11622
|
-
this._elseif_statement(elseif);
|
|
11623
|
-
}
|
|
11624
|
-
return elseif;
|
|
11625
|
-
}
|
|
11626
|
-
_return_statement() {
|
|
11627
|
-
// return short_circuit_or_expression?
|
|
11628
|
-
if (!this._match(TokenTypes.keywords.return)) {
|
|
11629
|
-
return null;
|
|
11630
|
-
}
|
|
11631
|
-
const value = this._short_circuit_or_expression();
|
|
11632
|
-
return new Return(value);
|
|
11633
|
-
}
|
|
11634
|
-
_short_circuit_or_expression() {
|
|
11635
|
-
// short_circuit_and_expression
|
|
11636
|
-
// short_circuit_or_expression or_or short_circuit_and_expression
|
|
11637
|
-
let expr = this._short_circuit_and_expr();
|
|
11638
|
-
while (this._match(TokenTypes.tokens.or_or)) {
|
|
11639
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
|
|
11640
|
-
}
|
|
11641
|
-
return expr;
|
|
11642
|
-
}
|
|
11643
|
-
_short_circuit_and_expr() {
|
|
11644
|
-
// inclusive_or_expression
|
|
11645
|
-
// short_circuit_and_expression and_and inclusive_or_expression
|
|
11646
|
-
let expr = this._inclusive_or_expression();
|
|
11647
|
-
while (this._match(TokenTypes.tokens.and_and)) {
|
|
11648
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
|
|
11649
|
-
}
|
|
11650
|
-
return expr;
|
|
11651
|
-
}
|
|
11652
|
-
_inclusive_or_expression() {
|
|
11653
|
-
// exclusive_or_expression
|
|
11654
|
-
// inclusive_or_expression or exclusive_or_expression
|
|
11655
|
-
let expr = this._exclusive_or_expression();
|
|
11656
|
-
while (this._match(TokenTypes.tokens.or)) {
|
|
11657
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
|
|
11658
|
-
}
|
|
11659
|
-
return expr;
|
|
11660
|
-
}
|
|
11661
|
-
_exclusive_or_expression() {
|
|
11662
|
-
// and_expression
|
|
11663
|
-
// exclusive_or_expression xor and_expression
|
|
11664
|
-
let expr = this._and_expression();
|
|
11665
|
-
while (this._match(TokenTypes.tokens.xor)) {
|
|
11666
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
|
|
11667
|
-
}
|
|
11668
|
-
return expr;
|
|
11669
|
-
}
|
|
11670
|
-
_and_expression() {
|
|
11671
|
-
// equality_expression
|
|
11672
|
-
// and_expression and equality_expression
|
|
11673
|
-
let expr = this._equality_expression();
|
|
11674
|
-
while (this._match(TokenTypes.tokens.and)) {
|
|
11675
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
|
|
11676
|
-
}
|
|
11677
|
-
return expr;
|
|
11678
|
-
}
|
|
11679
|
-
_equality_expression() {
|
|
11680
|
-
// relational_expression
|
|
11681
|
-
// relational_expression equal_equal relational_expression
|
|
11682
|
-
// relational_expression not_equal relational_expression
|
|
11683
|
-
const expr = this._relational_expression();
|
|
11684
|
-
if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
|
|
11685
|
-
return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
|
|
11686
|
-
}
|
|
11687
|
-
return expr;
|
|
11688
|
-
}
|
|
11689
|
-
_relational_expression() {
|
|
11690
|
-
// shift_expression
|
|
11691
|
-
// relational_expression less_than shift_expression
|
|
11692
|
-
// relational_expression greater_than shift_expression
|
|
11693
|
-
// relational_expression less_than_equal shift_expression
|
|
11694
|
-
// relational_expression greater_than_equal shift_expression
|
|
11695
|
-
let expr = this._shift_expression();
|
|
11696
|
-
while (this._match([
|
|
11697
|
-
TokenTypes.tokens.less_than,
|
|
11698
|
-
TokenTypes.tokens.greater_than,
|
|
11699
|
-
TokenTypes.tokens.less_than_equal,
|
|
11700
|
-
TokenTypes.tokens.greater_than_equal,
|
|
11701
|
-
])) {
|
|
11702
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
|
|
11703
|
-
}
|
|
11704
|
-
return expr;
|
|
11705
|
-
}
|
|
11706
|
-
_shift_expression() {
|
|
11707
|
-
// additive_expression
|
|
11708
|
-
// shift_expression shift_left additive_expression
|
|
11709
|
-
// shift_expression shift_right additive_expression
|
|
11710
|
-
let expr = this._additive_expression();
|
|
11711
|
-
while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
|
|
11712
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
|
|
11713
|
-
}
|
|
11714
|
-
return expr;
|
|
11715
|
-
}
|
|
11716
|
-
_additive_expression() {
|
|
11717
|
-
// multiplicative_expression
|
|
11718
|
-
// additive_expression plus multiplicative_expression
|
|
11719
|
-
// additive_expression minus multiplicative_expression
|
|
11720
|
-
let expr = this._multiplicative_expression();
|
|
11721
|
-
while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
|
|
11722
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
|
|
11723
|
-
}
|
|
11724
|
-
return expr;
|
|
11725
|
-
}
|
|
11726
|
-
_multiplicative_expression() {
|
|
11727
|
-
// unary_expression
|
|
11728
|
-
// multiplicative_expression star unary_expression
|
|
11729
|
-
// multiplicative_expression forward_slash unary_expression
|
|
11730
|
-
// multiplicative_expression modulo unary_expression
|
|
11731
|
-
let expr = this._unary_expression();
|
|
11732
|
-
while (this._match([
|
|
11733
|
-
TokenTypes.tokens.star,
|
|
11734
|
-
TokenTypes.tokens.forward_slash,
|
|
11735
|
-
TokenTypes.tokens.modulo,
|
|
11736
|
-
])) {
|
|
11737
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
|
|
11738
|
-
}
|
|
11739
|
-
return expr;
|
|
11740
|
-
}
|
|
11741
|
-
_unary_expression() {
|
|
11742
|
-
// singular_expression
|
|
11743
|
-
// minus unary_expression
|
|
11744
|
-
// bang unary_expression
|
|
11745
|
-
// tilde unary_expression
|
|
11746
|
-
// star unary_expression
|
|
11747
|
-
// and unary_expression
|
|
11748
|
-
if (this._match([
|
|
11749
|
-
TokenTypes.tokens.minus,
|
|
11750
|
-
TokenTypes.tokens.bang,
|
|
11751
|
-
TokenTypes.tokens.tilde,
|
|
11752
|
-
TokenTypes.tokens.star,
|
|
11753
|
-
TokenTypes.tokens.and,
|
|
11754
|
-
])) {
|
|
11755
|
-
return new UnaryOperator(this._previous().toString(), this._unary_expression());
|
|
11756
|
-
}
|
|
11757
|
-
return this._singular_expression();
|
|
11758
|
-
}
|
|
11759
|
-
_singular_expression() {
|
|
11760
|
-
// primary_expression postfix_expression ?
|
|
11761
|
-
const expr = this._primary_expression();
|
|
11762
|
-
const p = this._postfix_expression();
|
|
11763
|
-
if (p) {
|
|
11764
|
-
expr.postfix = p;
|
|
11765
|
-
}
|
|
11766
|
-
return expr;
|
|
11767
|
-
}
|
|
11768
|
-
_postfix_expression() {
|
|
11769
|
-
// bracket_left short_circuit_or_expression bracket_right postfix_expression?
|
|
11770
|
-
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
11771
|
-
const expr = this._short_circuit_or_expression();
|
|
11772
|
-
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
11773
|
-
const arrayIndex = new ArrayIndex(expr);
|
|
11774
|
-
const p = this._postfix_expression();
|
|
11775
|
-
if (p) {
|
|
11776
|
-
arrayIndex.postfix = p;
|
|
11777
|
-
}
|
|
11778
|
-
return arrayIndex;
|
|
11779
|
-
}
|
|
11780
|
-
// period ident postfix_expression?
|
|
11781
|
-
if (this._match(TokenTypes.tokens.period)) {
|
|
11782
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
11783
|
-
const p = this._postfix_expression();
|
|
11784
|
-
const expr = new StringExpr(name.lexeme);
|
|
11785
|
-
if (p) {
|
|
11786
|
-
expr.postfix = p;
|
|
11787
|
-
}
|
|
11788
|
-
return expr;
|
|
11789
|
-
}
|
|
11790
|
-
return null;
|
|
11791
|
-
}
|
|
11792
|
-
_getStruct(name) {
|
|
11793
|
-
if (this._context.aliases.has(name)) {
|
|
11794
|
-
const alias = this._context.aliases.get(name).type;
|
|
11795
|
-
return alias;
|
|
11796
|
-
}
|
|
11797
|
-
if (this._context.structs.has(name)) {
|
|
11798
|
-
const struct = this._context.structs.get(name);
|
|
11799
|
-
return struct;
|
|
11800
|
-
}
|
|
11801
|
-
return null;
|
|
11802
|
-
}
|
|
11803
|
-
_primary_expression() {
|
|
11804
|
-
// ident argument_expression_list?
|
|
11805
|
-
if (this._match(TokenTypes.tokens.ident)) {
|
|
11806
|
-
const name = this._previous().toString();
|
|
11807
|
-
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
11808
|
-
const args = this._argument_expression_list();
|
|
11809
|
-
const struct = this._getStruct(name);
|
|
11810
|
-
if (struct != null) {
|
|
11811
|
-
return new CreateExpr(struct, args);
|
|
11812
|
-
}
|
|
11813
|
-
return new CallExpr(name, args);
|
|
11814
|
-
}
|
|
11815
|
-
if (this._context.constants.has(name)) {
|
|
11816
|
-
const c = this._context.constants.get(name);
|
|
11817
|
-
return new ConstExpr(name, c.value);
|
|
11818
|
-
}
|
|
11819
|
-
return new VariableExpr(name);
|
|
11820
|
-
}
|
|
11821
|
-
// const_literal
|
|
11822
|
-
if (this._match(TokenTypes.const_literal)) {
|
|
11823
|
-
return new LiteralExpr(parseFloat(this._previous().toString()));
|
|
11824
|
-
}
|
|
11825
|
-
// paren_expression
|
|
11826
|
-
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
11827
|
-
return this._paren_expression();
|
|
11828
|
-
}
|
|
11829
|
-
// bitcast less_than type_decl greater_than paren_expression
|
|
11830
|
-
if (this._match(TokenTypes.keywords.bitcast)) {
|
|
11831
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
|
|
11832
|
-
const type = this._type_decl();
|
|
11833
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
11834
|
-
const value = this._paren_expression();
|
|
11835
|
-
return new BitcastExpr(type, value);
|
|
11836
|
-
}
|
|
11837
|
-
// type_decl argument_expression_list
|
|
11838
|
-
const type = this._type_decl();
|
|
11839
|
-
const args = this._argument_expression_list();
|
|
11840
|
-
return new CreateExpr(type, args);
|
|
11841
|
-
}
|
|
11842
|
-
_argument_expression_list() {
|
|
11843
|
-
// paren_left ((short_circuit_or_expression comma)* short_circuit_or_expression comma?)? paren_right
|
|
11844
|
-
if (!this._match(TokenTypes.tokens.paren_left)) {
|
|
11845
|
-
return null;
|
|
11846
|
-
}
|
|
11847
|
-
const args = [];
|
|
11848
|
-
do {
|
|
11849
|
-
if (this._check(TokenTypes.tokens.paren_right)) {
|
|
11850
|
-
break;
|
|
11851
|
-
}
|
|
11852
|
-
const arg = this._short_circuit_or_expression();
|
|
11853
|
-
args.push(arg);
|
|
11854
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
11855
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
|
|
11856
|
-
return args;
|
|
11857
|
-
}
|
|
11858
|
-
_optional_paren_expression() {
|
|
11859
|
-
// [paren_left] short_circuit_or_expression [paren_right]
|
|
11860
|
-
this._match(TokenTypes.tokens.paren_left);
|
|
11861
|
-
const expr = this._short_circuit_or_expression();
|
|
11862
|
-
this._match(TokenTypes.tokens.paren_right);
|
|
11863
|
-
return new GroupingExpr([expr]);
|
|
11864
|
-
}
|
|
11865
|
-
_paren_expression() {
|
|
11866
|
-
// paren_left short_circuit_or_expression paren_right
|
|
11867
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
11868
|
-
const expr = this._short_circuit_or_expression();
|
|
11869
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
11870
|
-
return new GroupingExpr([expr]);
|
|
11871
|
-
}
|
|
11872
|
-
_struct_decl() {
|
|
11873
|
-
// attribute* struct ident struct_body_decl
|
|
11874
|
-
if (!this._match(TokenTypes.keywords.struct)) {
|
|
11875
|
-
return null;
|
|
11876
|
-
}
|
|
11877
|
-
const startLine = this._currentLine;
|
|
11878
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
11879
|
-
// struct_body_decl: brace_left (struct_member comma)* struct_member comma? brace_right
|
|
11880
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
11881
|
-
const members = [];
|
|
11882
|
-
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
11883
|
-
// struct_member: attribute* variable_ident_decl
|
|
11884
|
-
const memberAttrs = this._attribute();
|
|
11885
|
-
const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
|
|
11886
|
-
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
11887
|
-
const typeAttrs = this._attribute();
|
|
11888
|
-
const memberType = this._type_decl();
|
|
11889
|
-
if (memberType != null) {
|
|
11890
|
-
memberType.attributes = typeAttrs;
|
|
11891
|
-
}
|
|
11892
|
-
if (!this._check(TokenTypes.tokens.brace_right))
|
|
11893
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
11894
|
-
else
|
|
11895
|
-
this._match(TokenTypes.tokens.comma); // trailing comma optional.
|
|
11896
|
-
members.push(new Member(memberName, memberType, memberAttrs));
|
|
11897
|
-
}
|
|
11898
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
11899
|
-
const endLine = this._currentLine;
|
|
11900
|
-
const structNode = new Struct(name, members, startLine, endLine);
|
|
11901
|
-
this._context.structs.set(name, structNode);
|
|
11902
|
-
return structNode;
|
|
11903
|
-
}
|
|
11904
|
-
_global_variable_decl() {
|
|
11905
|
-
// attribute* variable_decl (equal const_expression)?
|
|
11906
|
-
const _var = this._variable_decl();
|
|
11907
|
-
if (_var && this._match(TokenTypes.tokens.equal)) {
|
|
11908
|
-
_var.value = this._const_expression();
|
|
11909
|
-
}
|
|
11910
|
-
return _var;
|
|
11911
|
-
}
|
|
11912
|
-
_override_variable_decl() {
|
|
11913
|
-
// attribute* override_decl (equal const_expression)?
|
|
11914
|
-
const _override = this._override_decl();
|
|
11915
|
-
if (_override && this._match(TokenTypes.tokens.equal)) {
|
|
11916
|
-
_override.value = this._const_expression();
|
|
11917
|
-
}
|
|
11918
|
-
return _override;
|
|
11919
|
-
}
|
|
11920
|
-
_global_const_decl() {
|
|
11921
|
-
// attribute* const (ident variable_ident_decl) global_const_initializer?
|
|
11922
|
-
if (!this._match(TokenTypes.keywords.const)) {
|
|
11923
|
-
return null;
|
|
11924
|
-
}
|
|
11925
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
11926
|
-
let type = null;
|
|
11927
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
11928
|
-
const attrs = this._attribute();
|
|
11929
|
-
type = this._type_decl();
|
|
11930
|
-
if (type != null) {
|
|
11931
|
-
type.attributes = attrs;
|
|
11932
|
-
}
|
|
11933
|
-
}
|
|
11934
|
-
let value = null;
|
|
11935
|
-
if (this._match(TokenTypes.tokens.equal)) {
|
|
11936
|
-
const valueExpr = this._short_circuit_or_expression();
|
|
11937
|
-
if (valueExpr instanceof CreateExpr) {
|
|
11938
|
-
value = valueExpr;
|
|
11939
|
-
}
|
|
11940
|
-
else if (valueExpr instanceof ConstExpr &&
|
|
11941
|
-
valueExpr.initializer instanceof CreateExpr) {
|
|
11942
|
-
value = valueExpr.initializer;
|
|
11943
|
-
}
|
|
11944
|
-
else {
|
|
11945
|
-
try {
|
|
11946
|
-
const constValue = valueExpr.evaluate(this._context);
|
|
11947
|
-
value = new LiteralExpr(constValue);
|
|
11948
|
-
}
|
|
11949
|
-
catch (_a) {
|
|
11950
|
-
value = valueExpr;
|
|
11951
|
-
}
|
|
11952
|
-
}
|
|
11953
|
-
}
|
|
11954
|
-
const c = new Const(name.toString(), type, "", "", value);
|
|
11955
|
-
this._context.constants.set(c.name, c);
|
|
11956
|
-
return c;
|
|
11957
|
-
}
|
|
11958
|
-
_global_let_decl() {
|
|
11959
|
-
// attribute* let (ident variable_ident_decl) global_const_initializer?
|
|
11960
|
-
if (!this._match(TokenTypes.keywords.let)) {
|
|
11961
|
-
return null;
|
|
11962
|
-
}
|
|
11963
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
11964
|
-
let type = null;
|
|
11965
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
11966
|
-
const attrs = this._attribute();
|
|
11967
|
-
type = this._type_decl();
|
|
11968
|
-
if (type != null) {
|
|
11969
|
-
type.attributes = attrs;
|
|
11970
|
-
}
|
|
11971
|
-
}
|
|
11972
|
-
let value = null;
|
|
11973
|
-
if (this._match(TokenTypes.tokens.equal)) {
|
|
11974
|
-
value = this._const_expression();
|
|
11975
|
-
}
|
|
11976
|
-
return new Let(name.toString(), type, "", "", value);
|
|
11977
|
-
}
|
|
11978
|
-
_const_expression() {
|
|
11979
|
-
// type_decl paren_left ((const_expression comma)* const_expression comma?)? paren_right
|
|
11980
|
-
// const_literal
|
|
11981
|
-
return this._short_circuit_or_expression();
|
|
11982
|
-
}
|
|
11983
|
-
_variable_decl() {
|
|
11984
|
-
// var variable_qualifier? (ident variable_ident_decl)
|
|
11985
|
-
if (!this._match(TokenTypes.keywords.var)) {
|
|
11986
|
-
return null;
|
|
11987
|
-
}
|
|
11988
|
-
// variable_qualifier: less_than storage_class (comma access_mode)? greater_than
|
|
11989
|
-
let storage = "";
|
|
11990
|
-
let access = "";
|
|
11991
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
11992
|
-
storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
|
|
11993
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
11994
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
|
|
11995
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
11996
|
-
}
|
|
11997
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
11998
|
-
let type = null;
|
|
11999
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
12000
|
-
const attrs = this._attribute();
|
|
12001
|
-
type = this._type_decl();
|
|
12002
|
-
if (type != null) {
|
|
12003
|
-
type.attributes = attrs;
|
|
12004
|
-
}
|
|
12005
|
-
}
|
|
12006
|
-
return new Var(name.toString(), type, storage, access, null);
|
|
12007
|
-
}
|
|
12008
|
-
_override_decl() {
|
|
12009
|
-
// override (ident variable_ident_decl)
|
|
12010
|
-
if (!this._match(TokenTypes.keywords.override)) {
|
|
12011
|
-
return null;
|
|
12012
|
-
}
|
|
12013
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
12014
|
-
let type = null;
|
|
12015
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
12016
|
-
const attrs = this._attribute();
|
|
12017
|
-
type = this._type_decl();
|
|
12018
|
-
if (type != null) {
|
|
12019
|
-
type.attributes = attrs;
|
|
12020
|
-
}
|
|
12021
|
-
}
|
|
12022
|
-
return new Override(name.toString(), type, null);
|
|
12023
|
-
}
|
|
12024
|
-
_diagnostic() {
|
|
12025
|
-
// diagnostic(severity_control_name, diagnostic_rule_name)
|
|
12026
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('");
|
|
12027
|
-
const severity = this._consume(TokenTypes.tokens.ident, "Expected severity control name.");
|
|
12028
|
-
this._consume(TokenTypes.tokens.comma, "Expected ','");
|
|
12029
|
-
const rule = this._consume(TokenTypes.tokens.ident, "Expected diagnostic rule name.");
|
|
12030
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
12031
|
-
return new Diagnostic(severity.toString(), rule.toString());
|
|
12032
|
-
}
|
|
12033
|
-
_enable_directive() {
|
|
12034
|
-
// enable ident semicolon
|
|
12035
|
-
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
12036
|
-
return new Enable(name.toString());
|
|
12037
|
-
}
|
|
12038
|
-
_requires_directive() {
|
|
12039
|
-
// requires extension [, extension]* semicolon
|
|
12040
|
-
const extensions = [this._consume(TokenTypes.tokens.ident, "identity expected.").toString()];
|
|
12041
|
-
while (this._match(TokenTypes.tokens.comma)) {
|
|
12042
|
-
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
12043
|
-
extensions.push(name.toString());
|
|
12044
|
-
}
|
|
12045
|
-
return new Requires(extensions);
|
|
12046
|
-
}
|
|
12047
|
-
_type_alias() {
|
|
12048
|
-
// type ident equal type_decl
|
|
12049
|
-
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
12050
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
12051
|
-
let aliasType = this._type_decl();
|
|
12052
|
-
if (aliasType === null) {
|
|
12053
|
-
throw this._error(this._peek(), "Expected Type for Alias.");
|
|
12054
|
-
}
|
|
12055
|
-
if (this._context.aliases.has(aliasType.name)) {
|
|
12056
|
-
aliasType = this._context.aliases.get(aliasType.name).type;
|
|
12057
|
-
}
|
|
12058
|
-
const aliasNode = new Alias(name.toString(), aliasType);
|
|
12059
|
-
this._context.aliases.set(aliasNode.name, aliasNode);
|
|
12060
|
-
return aliasNode;
|
|
12061
|
-
}
|
|
12062
|
-
_type_decl() {
|
|
12063
|
-
// ident
|
|
12064
|
-
// bool
|
|
12065
|
-
// float32
|
|
12066
|
-
// int32
|
|
12067
|
-
// uint32
|
|
12068
|
-
// vec2 less_than type_decl greater_than
|
|
12069
|
-
// vec3 less_than type_decl greater_than
|
|
12070
|
-
// vec4 less_than type_decl greater_than
|
|
12071
|
-
// mat2x2 less_than type_decl greater_than
|
|
12072
|
-
// mat2x3 less_than type_decl greater_than
|
|
12073
|
-
// mat2x4 less_than type_decl greater_than
|
|
12074
|
-
// mat3x2 less_than type_decl greater_than
|
|
12075
|
-
// mat3x3 less_than type_decl greater_than
|
|
12076
|
-
// mat3x4 less_than type_decl greater_than
|
|
12077
|
-
// mat4x2 less_than type_decl greater_than
|
|
12078
|
-
// mat4x3 less_than type_decl greater_than
|
|
12079
|
-
// mat4x4 less_than type_decl greater_than
|
|
12080
|
-
// atomic less_than type_decl greater_than
|
|
12081
|
-
// pointer less_than storage_class comma type_decl (comma access_mode)? greater_than
|
|
12082
|
-
// array_type_decl
|
|
12083
|
-
// texture_sampler_types
|
|
12084
|
-
if (this._check([
|
|
12085
|
-
TokenTypes.tokens.ident,
|
|
12086
|
-
...TokenTypes.texel_format,
|
|
12087
|
-
TokenTypes.keywords.bool,
|
|
12088
|
-
TokenTypes.keywords.f32,
|
|
12089
|
-
TokenTypes.keywords.i32,
|
|
12090
|
-
TokenTypes.keywords.u32,
|
|
12091
|
-
])) {
|
|
12092
|
-
const type = this._advance();
|
|
12093
|
-
const typeName = type.toString();
|
|
12094
|
-
if (this._context.structs.has(typeName)) {
|
|
12095
|
-
return this._context.structs.get(typeName);
|
|
12096
|
-
}
|
|
12097
|
-
if (this._context.aliases.has(typeName)) {
|
|
12098
|
-
return this._context.aliases.get(typeName).type;
|
|
12099
|
-
}
|
|
12100
|
-
return new Type(type.toString());
|
|
12101
|
-
}
|
|
12102
|
-
// texture_sampler_types
|
|
12103
|
-
let type = this._texture_sampler_types();
|
|
12104
|
-
if (type) {
|
|
12105
|
-
return type;
|
|
12106
|
-
}
|
|
12107
|
-
if (this._check(TokenTypes.template_types)) {
|
|
12108
|
-
let type = this._advance().toString();
|
|
12109
|
-
let format = null;
|
|
12110
|
-
let access = null;
|
|
12111
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
12112
|
-
format = this._type_decl();
|
|
12113
|
-
access = null;
|
|
12114
|
-
if (this._match(TokenTypes.tokens.comma)) {
|
|
12115
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
12116
|
-
}
|
|
12117
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
12118
|
-
}
|
|
12119
|
-
return new TemplateType(type, format, access);
|
|
12120
|
-
}
|
|
12121
|
-
// pointer less_than storage_class comma type_decl (comma access_mode)? greater_than
|
|
12122
|
-
if (this._match(TokenTypes.keywords.ptr)) {
|
|
12123
|
-
let pointer = this._previous().toString();
|
|
12124
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
|
|
12125
|
-
const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
|
|
12126
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
12127
|
-
const decl = this._type_decl();
|
|
12128
|
-
let access = null;
|
|
12129
|
-
if (this._match(TokenTypes.tokens.comma)) {
|
|
12130
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
12131
|
-
}
|
|
12132
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
12133
|
-
return new PointerType(pointer, storage.toString(), decl, access);
|
|
12134
|
-
}
|
|
12135
|
-
// The following type_decl's have an optional attribyte_list*
|
|
12136
|
-
const attrs = this._attribute();
|
|
12137
|
-
// attribute* array
|
|
12138
|
-
// attribute* array less_than type_decl (comma element_count_expression)? greater_than
|
|
12139
|
-
if (this._match(TokenTypes.keywords.array)) {
|
|
12140
|
-
let format = null;
|
|
12141
|
-
let countInt = -1;
|
|
12142
|
-
const array = this._previous();
|
|
12143
|
-
let countNode = null;
|
|
12144
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
12145
|
-
format = this._type_decl();
|
|
12146
|
-
if (this._context.aliases.has(format.name)) {
|
|
12147
|
-
format = this._context.aliases.get(format.name).type;
|
|
12148
|
-
}
|
|
12149
|
-
let count = "";
|
|
12150
|
-
if (this._match(TokenTypes.tokens.comma)) {
|
|
12151
|
-
countNode = this._shift_expression();
|
|
12152
|
-
// If we can't evaluate the node, defer evaluating it until after the shader has
|
|
12153
|
-
// finished being parsed, because const statements can be declared **after** they
|
|
12154
|
-
// are used.
|
|
12155
|
-
try {
|
|
12156
|
-
count = countNode.evaluate(this._context).toString();
|
|
12157
|
-
countNode = null;
|
|
12158
|
-
}
|
|
12159
|
-
catch (e) {
|
|
12160
|
-
count = "1";
|
|
12161
|
-
}
|
|
12162
|
-
}
|
|
12163
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
12164
|
-
countInt = count ? parseInt(count) : 0;
|
|
12165
|
-
}
|
|
12166
|
-
const arrayType = new ArrayType(array.toString(), attrs, format, countInt);
|
|
12167
|
-
if (countNode) {
|
|
12168
|
-
this._deferArrayCountEval.push({ arrayType, countNode });
|
|
12169
|
-
}
|
|
12170
|
-
return arrayType;
|
|
12171
|
-
}
|
|
12172
|
-
return null;
|
|
12173
|
-
}
|
|
12174
|
-
_texture_sampler_types() {
|
|
12175
|
-
// sampler_type
|
|
12176
|
-
if (this._match(TokenTypes.sampler_type)) {
|
|
12177
|
-
return new SamplerType(this._previous().toString(), null, null);
|
|
12178
|
-
}
|
|
12179
|
-
// depth_texture_type
|
|
12180
|
-
if (this._match(TokenTypes.depth_texture_type)) {
|
|
12181
|
-
return new SamplerType(this._previous().toString(), null, null);
|
|
12182
|
-
}
|
|
12183
|
-
// sampled_texture_type less_than type_decl greater_than
|
|
12184
|
-
// multisampled_texture_type less_than type_decl greater_than
|
|
12185
|
-
if (this._match(TokenTypes.sampled_texture_type) ||
|
|
12186
|
-
this._match(TokenTypes.multisampled_texture_type)) {
|
|
12187
|
-
const sampler = this._previous();
|
|
12188
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
12189
|
-
const format = this._type_decl();
|
|
12190
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
12191
|
-
return new SamplerType(sampler.toString(), format, null);
|
|
12192
|
-
}
|
|
12193
|
-
// storage_texture_type less_than texel_format comma access_mode greater_than
|
|
12194
|
-
if (this._match(TokenTypes.storage_texture_type)) {
|
|
12195
|
-
const sampler = this._previous();
|
|
12196
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
12197
|
-
const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
|
|
12198
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
|
|
12199
|
-
const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
|
|
12200
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
12201
|
-
return new SamplerType(sampler.toString(), format, access);
|
|
12202
|
-
}
|
|
12203
|
-
return null;
|
|
12204
|
-
}
|
|
12205
|
-
_attribute() {
|
|
12206
|
-
// attr ident paren_left (literal_or_ident comma)* literal_or_ident paren_right
|
|
12207
|
-
// attr ident
|
|
12208
|
-
let attributes = [];
|
|
12209
|
-
while (this._match(TokenTypes.tokens.attr)) {
|
|
12210
|
-
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
12211
|
-
const attr = new Attribute$1(name.toString(), null);
|
|
12212
|
-
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
12213
|
-
// literal_or_ident
|
|
12214
|
-
attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
12215
|
-
if (this._check(TokenTypes.tokens.comma)) {
|
|
12216
|
-
this._advance();
|
|
12217
|
-
do {
|
|
12218
|
-
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
12219
|
-
if (!(attr.value instanceof Array)) {
|
|
12220
|
-
attr.value = [attr.value];
|
|
12221
|
-
}
|
|
12222
|
-
attr.value.push(v);
|
|
12223
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
12224
|
-
}
|
|
12225
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
12226
|
-
}
|
|
12227
|
-
attributes.push(attr);
|
|
12228
|
-
}
|
|
12229
|
-
if (attributes.length == 0) {
|
|
12230
|
-
return null;
|
|
12231
|
-
}
|
|
12232
|
-
return attributes;
|
|
12233
|
-
}
|
|
12234
|
-
}
|
|
12235
|
-
|
|
12236
|
-
/**
|
|
12237
|
-
* @author Brendan Duncan / https://github.com/brendan-duncan
|
|
12238
|
-
*/
|
|
12239
|
-
class TypeInfo {
|
|
12240
|
-
constructor(name, attributes) {
|
|
12241
|
-
this.name = name;
|
|
12242
|
-
this.attributes = attributes;
|
|
12243
|
-
this.size = 0;
|
|
12244
|
-
}
|
|
12245
|
-
get isArray() {
|
|
12246
|
-
return false;
|
|
12247
|
-
}
|
|
12248
|
-
get isStruct() {
|
|
12249
|
-
return false;
|
|
12250
|
-
}
|
|
12251
|
-
get isTemplate() {
|
|
12252
|
-
return false;
|
|
12253
|
-
}
|
|
12254
|
-
}
|
|
12255
|
-
class MemberInfo {
|
|
12256
|
-
constructor(name, type, attributes) {
|
|
12257
|
-
this.name = name;
|
|
12258
|
-
this.type = type;
|
|
12259
|
-
this.attributes = attributes;
|
|
12260
|
-
this.offset = 0;
|
|
12261
|
-
this.size = 0;
|
|
12262
|
-
}
|
|
12263
|
-
get isArray() {
|
|
12264
|
-
return this.type.isArray;
|
|
12265
|
-
}
|
|
12266
|
-
get isStruct() {
|
|
12267
|
-
return this.type.isStruct;
|
|
12268
|
-
}
|
|
12269
|
-
get isTemplate() {
|
|
12270
|
-
return this.type.isTemplate;
|
|
12271
|
-
}
|
|
12272
|
-
get align() {
|
|
12273
|
-
return this.type.isStruct ? this.type.align : 0;
|
|
12274
|
-
}
|
|
12275
|
-
get members() {
|
|
12276
|
-
return this.type.isStruct ? this.type.members : null;
|
|
12277
|
-
}
|
|
12278
|
-
get format() {
|
|
12279
|
-
return this.type.isArray
|
|
12280
|
-
? this.type.format
|
|
12281
|
-
: this.type.isTemplate
|
|
12282
|
-
? this.type.format
|
|
12283
|
-
: null;
|
|
12284
|
-
}
|
|
12285
|
-
get count() {
|
|
12286
|
-
return this.type.isArray ? this.type.count : 0;
|
|
12287
|
-
}
|
|
12288
|
-
get stride() {
|
|
12289
|
-
return this.type.isArray ? this.type.stride : this.size;
|
|
12290
|
-
}
|
|
12291
|
-
}
|
|
12292
|
-
class StructInfo extends TypeInfo {
|
|
12293
|
-
constructor(name, attributes) {
|
|
12294
|
-
super(name, attributes);
|
|
12295
|
-
this.members = [];
|
|
12296
|
-
this.align = 0;
|
|
12297
|
-
this.startLine = -1;
|
|
12298
|
-
this.endLine = -1;
|
|
12299
|
-
this.inUse = false;
|
|
12300
|
-
}
|
|
12301
|
-
get isStruct() {
|
|
12302
|
-
return true;
|
|
12303
|
-
}
|
|
12304
|
-
}
|
|
12305
|
-
class ArrayInfo extends TypeInfo {
|
|
12306
|
-
constructor(name, attributes) {
|
|
12307
|
-
super(name, attributes);
|
|
12308
|
-
this.count = 0;
|
|
12309
|
-
this.stride = 0;
|
|
12310
|
-
}
|
|
12311
|
-
get isArray() {
|
|
12312
|
-
return true;
|
|
12313
|
-
}
|
|
12314
|
-
}
|
|
12315
|
-
class TemplateInfo extends TypeInfo {
|
|
12316
|
-
constructor(name, format, attributes, access) {
|
|
12317
|
-
super(name, attributes);
|
|
12318
|
-
this.format = format;
|
|
12319
|
-
this.access = access;
|
|
12320
|
-
}
|
|
12321
|
-
get isTemplate() {
|
|
12322
|
-
return true;
|
|
12323
|
-
}
|
|
12324
|
-
}
|
|
12325
|
-
var ResourceType;
|
|
12326
|
-
(function (ResourceType) {
|
|
12327
|
-
ResourceType[ResourceType["Uniform"] = 0] = "Uniform";
|
|
12328
|
-
ResourceType[ResourceType["Storage"] = 1] = "Storage";
|
|
12329
|
-
ResourceType[ResourceType["Texture"] = 2] = "Texture";
|
|
12330
|
-
ResourceType[ResourceType["Sampler"] = 3] = "Sampler";
|
|
12331
|
-
ResourceType[ResourceType["StorageTexture"] = 4] = "StorageTexture";
|
|
12332
|
-
})(ResourceType || (ResourceType = {}));
|
|
12333
|
-
class VariableInfo {
|
|
12334
|
-
constructor(name, type, group, binding, attributes, resourceType, access) {
|
|
12335
|
-
this.name = name;
|
|
12336
|
-
this.type = type;
|
|
12337
|
-
this.group = group;
|
|
12338
|
-
this.binding = binding;
|
|
12339
|
-
this.attributes = attributes;
|
|
12340
|
-
this.resourceType = resourceType;
|
|
12341
|
-
this.access = access;
|
|
12342
|
-
}
|
|
12343
|
-
get isArray() {
|
|
12344
|
-
return this.type.isArray;
|
|
12345
|
-
}
|
|
12346
|
-
get isStruct() {
|
|
12347
|
-
return this.type.isStruct;
|
|
12348
|
-
}
|
|
12349
|
-
get isTemplate() {
|
|
12350
|
-
return this.type.isTemplate;
|
|
12351
|
-
}
|
|
12352
|
-
get size() {
|
|
12353
|
-
return this.type.size;
|
|
12354
|
-
}
|
|
12355
|
-
get align() {
|
|
12356
|
-
return this.type.isStruct ? this.type.align : 0;
|
|
12357
|
-
}
|
|
12358
|
-
get members() {
|
|
12359
|
-
return this.type.isStruct ? this.type.members : null;
|
|
12360
|
-
}
|
|
12361
|
-
get format() {
|
|
12362
|
-
return this.type.isArray
|
|
12363
|
-
? this.type.format
|
|
12364
|
-
: this.type.isTemplate
|
|
12365
|
-
? this.type.format
|
|
12366
|
-
: null;
|
|
12367
|
-
}
|
|
12368
|
-
get count() {
|
|
12369
|
-
return this.type.isArray ? this.type.count : 0;
|
|
12370
|
-
}
|
|
12371
|
-
get stride() {
|
|
12372
|
-
return this.type.isArray ? this.type.stride : this.size;
|
|
12373
|
-
}
|
|
12374
|
-
}
|
|
12375
|
-
class AliasInfo {
|
|
12376
|
-
constructor(name, type) {
|
|
12377
|
-
this.name = name;
|
|
12378
|
-
this.type = type;
|
|
12379
|
-
}
|
|
12380
|
-
}
|
|
12381
|
-
class _TypeSize {
|
|
12382
|
-
constructor(align, size) {
|
|
12383
|
-
this.align = align;
|
|
12384
|
-
this.size = size;
|
|
12385
|
-
}
|
|
12386
|
-
}
|
|
12387
|
-
class InputInfo {
|
|
12388
|
-
constructor(name, type, locationType, location) {
|
|
12389
|
-
this.name = name;
|
|
12390
|
-
this.type = type;
|
|
12391
|
-
this.locationType = locationType;
|
|
12392
|
-
this.location = location;
|
|
12393
|
-
this.interpolation = null;
|
|
12394
|
-
}
|
|
12395
|
-
}
|
|
12396
|
-
class OutputInfo {
|
|
12397
|
-
constructor(name, type, locationType, location) {
|
|
12398
|
-
this.name = name;
|
|
12399
|
-
this.type = type;
|
|
12400
|
-
this.locationType = locationType;
|
|
12401
|
-
this.location = location;
|
|
12402
|
-
}
|
|
12403
|
-
}
|
|
12404
|
-
class OverrideInfo {
|
|
12405
|
-
constructor(name, type, attributes, id) {
|
|
12406
|
-
this.name = name;
|
|
12407
|
-
this.type = type;
|
|
12408
|
-
this.attributes = attributes;
|
|
12409
|
-
this.id = id;
|
|
12410
|
-
}
|
|
12411
|
-
}
|
|
12412
|
-
class ArgumentInfo {
|
|
12413
|
-
constructor(name, type) {
|
|
12414
|
-
this.name = name;
|
|
12415
|
-
this.type = type;
|
|
12416
|
-
}
|
|
12417
|
-
}
|
|
12418
|
-
class FunctionInfo {
|
|
12419
|
-
constructor(name, stage = null) {
|
|
12420
|
-
this.stage = null;
|
|
12421
|
-
this.inputs = [];
|
|
12422
|
-
this.outputs = [];
|
|
12423
|
-
this.arguments = [];
|
|
12424
|
-
this.returnType = null;
|
|
12425
|
-
this.resources = [];
|
|
12426
|
-
this.overrides = [];
|
|
12427
|
-
this.startLine = -1;
|
|
12428
|
-
this.endLine = -1;
|
|
12429
|
-
this.inUse = false;
|
|
12430
|
-
this.calls = new Set();
|
|
12431
|
-
this.name = name;
|
|
12432
|
-
this.stage = stage;
|
|
12433
|
-
}
|
|
12434
|
-
}
|
|
12435
|
-
class EntryFunctions {
|
|
12436
|
-
constructor() {
|
|
12437
|
-
this.vertex = [];
|
|
12438
|
-
this.fragment = [];
|
|
12439
|
-
this.compute = [];
|
|
12440
|
-
}
|
|
12441
|
-
}
|
|
12442
|
-
class _FunctionResources {
|
|
12443
|
-
constructor(node) {
|
|
12444
|
-
this.resources = null;
|
|
12445
|
-
this.inUse = false;
|
|
12446
|
-
this.info = null;
|
|
12447
|
-
this.node = node;
|
|
12448
|
-
}
|
|
12449
|
-
}
|
|
12450
|
-
class WgslReflect {
|
|
12451
|
-
constructor(code) {
|
|
12452
|
-
/// All top-level uniform vars in the shader.
|
|
12453
|
-
this.uniforms = [];
|
|
12454
|
-
/// All top-level storage vars in the shader.
|
|
12455
|
-
this.storage = [];
|
|
12456
|
-
/// All top-level texture vars in the shader;
|
|
12457
|
-
this.textures = [];
|
|
12458
|
-
// All top-level sampler vars in the shader.
|
|
12459
|
-
this.samplers = [];
|
|
12460
|
-
/// All top-level type aliases in the shader.
|
|
12461
|
-
this.aliases = [];
|
|
12462
|
-
/// All top-level overrides in the shader.
|
|
12463
|
-
this.overrides = [];
|
|
12464
|
-
/// All top-level structs in the shader.
|
|
12465
|
-
this.structs = [];
|
|
12466
|
-
/// All entry functions in the shader: vertex, fragment, and/or compute.
|
|
12467
|
-
this.entry = new EntryFunctions();
|
|
12468
|
-
/// All functions in the shader, including entry functions.
|
|
12469
|
-
this.functions = [];
|
|
12470
|
-
this._types = new Map();
|
|
12471
|
-
this._functions = new Map();
|
|
12472
|
-
if (code) {
|
|
12473
|
-
this.update(code);
|
|
12474
|
-
}
|
|
12475
|
-
}
|
|
12476
|
-
_isStorageTexture(type) {
|
|
12477
|
-
return (type.name == "texture_storage_1d" ||
|
|
12478
|
-
type.name == "texture_storage_2d" ||
|
|
12479
|
-
type.name == "texture_storage_2d_array" ||
|
|
12480
|
-
type.name == "texture_storage_3d");
|
|
12481
|
-
}
|
|
12482
|
-
update(code) {
|
|
12483
|
-
const parser = new WgslParser();
|
|
12484
|
-
const ast = parser.parse(code);
|
|
12485
|
-
for (const node of ast) {
|
|
12486
|
-
if (node instanceof Function) {
|
|
12487
|
-
this._functions.set(node.name, new _FunctionResources(node));
|
|
12488
|
-
}
|
|
12489
|
-
}
|
|
12490
|
-
for (const node of ast) {
|
|
12491
|
-
if (node instanceof Struct) {
|
|
12492
|
-
const info = this._getTypeInfo(node, null);
|
|
12493
|
-
if (info instanceof StructInfo) {
|
|
12494
|
-
this.structs.push(info);
|
|
12495
|
-
}
|
|
12496
|
-
}
|
|
12497
|
-
}
|
|
12498
|
-
for (const node of ast) {
|
|
12499
|
-
if (node instanceof Alias) {
|
|
12500
|
-
this.aliases.push(this._getAliasInfo(node));
|
|
12501
|
-
continue;
|
|
12502
|
-
}
|
|
12503
|
-
if (node instanceof Override) {
|
|
12504
|
-
const v = node;
|
|
12505
|
-
const id = this._getAttributeNum(v.attributes, "id", 0);
|
|
12506
|
-
const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
|
|
12507
|
-
this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
|
|
12508
|
-
continue;
|
|
12509
|
-
}
|
|
12510
|
-
if (this._isUniformVar(node)) {
|
|
12511
|
-
const v = node;
|
|
12512
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
12513
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
12514
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
12515
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
|
|
12516
|
-
this.uniforms.push(varInfo);
|
|
12517
|
-
continue;
|
|
12518
|
-
}
|
|
12519
|
-
if (this._isStorageVar(node)) {
|
|
12520
|
-
const v = node;
|
|
12521
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
12522
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
12523
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
12524
|
-
const isStorageTexture = this._isStorageTexture(type);
|
|
12525
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
|
|
12526
|
-
this.storage.push(varInfo);
|
|
12527
|
-
continue;
|
|
12528
|
-
}
|
|
12529
|
-
if (this._isTextureVar(node)) {
|
|
12530
|
-
const v = node;
|
|
12531
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
12532
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
12533
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
12534
|
-
const isStorageTexture = this._isStorageTexture(type);
|
|
12535
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
|
|
12536
|
-
if (isStorageTexture) {
|
|
12537
|
-
this.storage.push(varInfo);
|
|
12538
|
-
}
|
|
12539
|
-
else {
|
|
12540
|
-
this.textures.push(varInfo);
|
|
12541
|
-
}
|
|
12542
|
-
continue;
|
|
12543
|
-
}
|
|
12544
|
-
if (this._isSamplerVar(node)) {
|
|
12545
|
-
const v = node;
|
|
12546
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
12547
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
12548
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
12549
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
|
|
12550
|
-
this.samplers.push(varInfo);
|
|
12551
|
-
continue;
|
|
12552
|
-
}
|
|
12553
|
-
if (node instanceof Function) {
|
|
12554
|
-
const vertexStage = this._getAttribute(node, "vertex");
|
|
12555
|
-
const fragmentStage = this._getAttribute(node, "fragment");
|
|
12556
|
-
const computeStage = this._getAttribute(node, "compute");
|
|
12557
|
-
const stage = vertexStage || fragmentStage || computeStage;
|
|
12558
|
-
const fn = new FunctionInfo(node.name, stage === null || stage === void 0 ? void 0 : stage.name);
|
|
12559
|
-
fn.startLine = node.startLine;
|
|
12560
|
-
fn.endLine = node.endLine;
|
|
12561
|
-
this.functions.push(fn);
|
|
12562
|
-
this._functions.get(node.name).info = fn;
|
|
12563
|
-
if (stage) {
|
|
12564
|
-
this._functions.get(node.name).inUse = true;
|
|
12565
|
-
fn.inUse = true;
|
|
12566
|
-
fn.resources = this._findResources(node, !!stage);
|
|
12567
|
-
fn.inputs = this._getInputs(node.args);
|
|
12568
|
-
fn.outputs = this._getOutputs(node.returnType);
|
|
12569
|
-
this.entry[stage.name].push(fn);
|
|
12570
|
-
}
|
|
12571
|
-
else {
|
|
12572
|
-
fn.arguments = node.args.map((arg) => new ArgumentInfo(arg.name, this._getTypeInfo(arg.type, arg.attributes)));
|
|
12573
|
-
fn.returnType = node.returnType
|
|
12574
|
-
? this._getTypeInfo(node.returnType, node.attributes)
|
|
12575
|
-
: null;
|
|
12576
|
-
}
|
|
12577
|
-
continue;
|
|
12578
|
-
}
|
|
12579
|
-
}
|
|
12580
|
-
for (const fn of this._functions.values()) {
|
|
12581
|
-
if (fn.info) {
|
|
12582
|
-
fn.info.inUse = fn.inUse;
|
|
12583
|
-
this._addCalls(fn.node, fn.info.calls);
|
|
12584
|
-
}
|
|
12585
|
-
}
|
|
12586
|
-
for (const fn of this._functions.values()) {
|
|
12587
|
-
fn.node.search((node) => {
|
|
12588
|
-
var _a;
|
|
12589
|
-
if (node.astNodeType === "varExpr") {
|
|
12590
|
-
const v = node;
|
|
12591
|
-
for (const override of this.overrides) {
|
|
12592
|
-
if (v.name == override.name) {
|
|
12593
|
-
(_a = fn.info) === null || _a === void 0 ? void 0 : _a.overrides.push(override);
|
|
12594
|
-
}
|
|
12595
|
-
}
|
|
12596
|
-
}
|
|
12597
|
-
});
|
|
12598
|
-
}
|
|
12599
|
-
for (const u of this.uniforms) {
|
|
12600
|
-
this._markStructsInUse(u.type);
|
|
12601
|
-
}
|
|
12602
|
-
for (const s of this.storage) {
|
|
12603
|
-
this._markStructsInUse(s.type);
|
|
12604
|
-
}
|
|
12605
|
-
}
|
|
12606
|
-
_markStructsInUse(type) {
|
|
12607
|
-
if (!type) {
|
|
12608
|
-
return;
|
|
12609
|
-
}
|
|
12610
|
-
if (type.isStruct) {
|
|
12611
|
-
type.inUse = true;
|
|
12612
|
-
if (type.members) {
|
|
12613
|
-
for (const m of type.members) {
|
|
12614
|
-
this._markStructsInUse(m.type);
|
|
12615
|
-
}
|
|
12616
|
-
}
|
|
12617
|
-
}
|
|
12618
|
-
else if (type.isArray) {
|
|
12619
|
-
this._markStructsInUse(type.format);
|
|
12620
|
-
}
|
|
12621
|
-
else if (type.isTemplate) {
|
|
12622
|
-
if (type.format) {
|
|
12623
|
-
this._markStructsInUse(type.format);
|
|
12624
|
-
}
|
|
12625
|
-
}
|
|
12626
|
-
else {
|
|
12627
|
-
const alias = this._getAlias(type.name);
|
|
12628
|
-
if (alias) {
|
|
12629
|
-
this._markStructsInUse(alias);
|
|
12630
|
-
}
|
|
12631
|
-
}
|
|
12632
|
-
}
|
|
12633
|
-
_addCalls(fn, calls) {
|
|
12634
|
-
var _a;
|
|
12635
|
-
for (const call of fn.calls) {
|
|
12636
|
-
const info = (_a = this._functions.get(call.name)) === null || _a === void 0 ? void 0 : _a.info;
|
|
12637
|
-
if (info) {
|
|
12638
|
-
calls.add(info);
|
|
12639
|
-
}
|
|
12640
|
-
}
|
|
12641
|
-
}
|
|
12642
|
-
/// Find a resource by its group and binding.
|
|
12643
|
-
findResource(group, binding) {
|
|
12644
|
-
for (const u of this.uniforms) {
|
|
12645
|
-
if (u.group == group && u.binding == binding) {
|
|
12646
|
-
return u;
|
|
12647
|
-
}
|
|
12648
|
-
}
|
|
12649
|
-
for (const s of this.storage) {
|
|
12650
|
-
if (s.group == group && s.binding == binding) {
|
|
12651
|
-
return s;
|
|
12652
|
-
}
|
|
12653
|
-
}
|
|
12654
|
-
for (const t of this.textures) {
|
|
12655
|
-
if (t.group == group && t.binding == binding) {
|
|
12656
|
-
return t;
|
|
12657
|
-
}
|
|
12658
|
-
}
|
|
12659
|
-
for (const s of this.samplers) {
|
|
12660
|
-
if (s.group == group && s.binding == binding) {
|
|
12661
|
-
return s;
|
|
12662
|
-
}
|
|
12663
|
-
}
|
|
12664
|
-
return null;
|
|
12665
|
-
}
|
|
12666
|
-
_findResource(name) {
|
|
12667
|
-
for (const u of this.uniforms) {
|
|
12668
|
-
if (u.name == name) {
|
|
12669
|
-
return u;
|
|
12670
|
-
}
|
|
12671
|
-
}
|
|
12672
|
-
for (const s of this.storage) {
|
|
12673
|
-
if (s.name == name) {
|
|
12674
|
-
return s;
|
|
12675
|
-
}
|
|
12676
|
-
}
|
|
12677
|
-
for (const t of this.textures) {
|
|
12678
|
-
if (t.name == name) {
|
|
12679
|
-
return t;
|
|
12680
|
-
}
|
|
12681
|
-
}
|
|
12682
|
-
for (const s of this.samplers) {
|
|
12683
|
-
if (s.name == name) {
|
|
12684
|
-
return s;
|
|
12685
|
-
}
|
|
12686
|
-
}
|
|
12687
|
-
return null;
|
|
12688
|
-
}
|
|
12689
|
-
_markStructsFromAST(type) {
|
|
12690
|
-
const info = this._getTypeInfo(type, null);
|
|
12691
|
-
this._markStructsInUse(info);
|
|
12692
|
-
}
|
|
12693
|
-
_findResources(fn, isEntry) {
|
|
12694
|
-
const resources = [];
|
|
12695
|
-
const self = this;
|
|
12696
|
-
const varStack = [];
|
|
12697
|
-
fn.search((node) => {
|
|
12698
|
-
if (node instanceof _BlockStart) {
|
|
12699
|
-
varStack.push({});
|
|
12700
|
-
}
|
|
12701
|
-
else if (node instanceof _BlockEnd) {
|
|
12702
|
-
varStack.pop();
|
|
12703
|
-
}
|
|
12704
|
-
else if (node instanceof Var) {
|
|
12705
|
-
const v = node;
|
|
12706
|
-
if (isEntry && v.type !== null) {
|
|
12707
|
-
this._markStructsFromAST(v.type);
|
|
12708
|
-
}
|
|
12709
|
-
if (varStack.length > 0) {
|
|
12710
|
-
varStack[varStack.length - 1][v.name] = v;
|
|
12711
|
-
}
|
|
12712
|
-
}
|
|
12713
|
-
else if (node instanceof CreateExpr) {
|
|
12714
|
-
const c = node;
|
|
12715
|
-
if (isEntry && c.type !== null) {
|
|
12716
|
-
this._markStructsFromAST(c.type);
|
|
12717
|
-
}
|
|
12718
|
-
}
|
|
12719
|
-
else if (node instanceof Let) {
|
|
12720
|
-
const v = node;
|
|
12721
|
-
if (isEntry && v.type !== null) {
|
|
12722
|
-
this._markStructsFromAST(v.type);
|
|
12723
|
-
}
|
|
12724
|
-
if (varStack.length > 0) {
|
|
12725
|
-
varStack[varStack.length - 1][v.name] = v;
|
|
12726
|
-
}
|
|
12727
|
-
}
|
|
12728
|
-
else if (node instanceof VariableExpr) {
|
|
12729
|
-
const v = node;
|
|
12730
|
-
// Check to see if the variable is a local variable before checking to see if it's
|
|
12731
|
-
// a resource.
|
|
12732
|
-
if (varStack.length > 0) {
|
|
12733
|
-
const varInfo = varStack[varStack.length - 1][v.name];
|
|
12734
|
-
if (varInfo) {
|
|
12735
|
-
return;
|
|
12736
|
-
}
|
|
12737
|
-
}
|
|
12738
|
-
const varInfo = self._findResource(v.name);
|
|
12739
|
-
if (varInfo) {
|
|
12740
|
-
resources.push(varInfo);
|
|
12741
|
-
}
|
|
12742
|
-
}
|
|
12743
|
-
else if (node instanceof CallExpr) {
|
|
12744
|
-
const c = node;
|
|
12745
|
-
const callFn = self._functions.get(c.name);
|
|
12746
|
-
if (callFn) {
|
|
12747
|
-
if (isEntry) {
|
|
12748
|
-
callFn.inUse = true;
|
|
12749
|
-
}
|
|
12750
|
-
fn.calls.add(callFn.node);
|
|
12751
|
-
if (callFn.resources === null) {
|
|
12752
|
-
callFn.resources = self._findResources(callFn.node, isEntry);
|
|
12753
|
-
}
|
|
12754
|
-
resources.push(...callFn.resources);
|
|
12755
|
-
}
|
|
12756
|
-
}
|
|
12757
|
-
else if (node instanceof Call) {
|
|
12758
|
-
const c = node;
|
|
12759
|
-
const callFn = self._functions.get(c.name);
|
|
12760
|
-
if (callFn) {
|
|
12761
|
-
if (isEntry) {
|
|
12762
|
-
callFn.inUse = true;
|
|
12763
|
-
}
|
|
12764
|
-
fn.calls.add(callFn.node);
|
|
12765
|
-
if (callFn.resources === null) {
|
|
12766
|
-
callFn.resources = self._findResources(callFn.node, isEntry);
|
|
12767
|
-
}
|
|
12768
|
-
resources.push(...callFn.resources);
|
|
12769
|
-
}
|
|
12770
|
-
}
|
|
12771
|
-
});
|
|
12772
|
-
return [...new Map(resources.map(r => [r.name, r])).values()];
|
|
12773
|
-
}
|
|
12774
|
-
getBindGroups() {
|
|
12775
|
-
const groups = [];
|
|
12776
|
-
function _makeRoom(group, binding) {
|
|
12777
|
-
if (group >= groups.length) {
|
|
12778
|
-
groups.length = group + 1;
|
|
12779
|
-
}
|
|
12780
|
-
if (groups[group] === undefined) {
|
|
12781
|
-
groups[group] = [];
|
|
12782
|
-
}
|
|
12783
|
-
if (binding >= groups[group].length) {
|
|
12784
|
-
groups[group].length = binding + 1;
|
|
12785
|
-
}
|
|
12786
|
-
}
|
|
12787
|
-
for (const u of this.uniforms) {
|
|
12788
|
-
_makeRoom(u.group, u.binding);
|
|
12789
|
-
const group = groups[u.group];
|
|
12790
|
-
group[u.binding] = u;
|
|
12791
|
-
}
|
|
12792
|
-
for (const u of this.storage) {
|
|
12793
|
-
_makeRoom(u.group, u.binding);
|
|
12794
|
-
const group = groups[u.group];
|
|
12795
|
-
group[u.binding] = u;
|
|
12796
|
-
}
|
|
12797
|
-
for (const t of this.textures) {
|
|
12798
|
-
_makeRoom(t.group, t.binding);
|
|
12799
|
-
const group = groups[t.group];
|
|
12800
|
-
group[t.binding] = t;
|
|
12801
|
-
}
|
|
12802
|
-
for (const t of this.samplers) {
|
|
12803
|
-
_makeRoom(t.group, t.binding);
|
|
12804
|
-
const group = groups[t.group];
|
|
12805
|
-
group[t.binding] = t;
|
|
12806
|
-
}
|
|
12807
|
-
return groups;
|
|
12808
|
-
}
|
|
12809
|
-
_getOutputs(type, outputs = undefined) {
|
|
12810
|
-
if (outputs === undefined) {
|
|
12811
|
-
outputs = [];
|
|
12812
|
-
}
|
|
12813
|
-
if (type instanceof Struct) {
|
|
12814
|
-
this._getStructOutputs(type, outputs);
|
|
12815
|
-
}
|
|
12816
|
-
else {
|
|
12817
|
-
const output = this._getOutputInfo(type);
|
|
12818
|
-
if (output !== null) {
|
|
12819
|
-
outputs.push(output);
|
|
12820
|
-
}
|
|
12821
|
-
}
|
|
12822
|
-
return outputs;
|
|
12823
|
-
}
|
|
12824
|
-
_getStructOutputs(struct, outputs) {
|
|
12825
|
-
for (const m of struct.members) {
|
|
12826
|
-
if (m.type instanceof Struct) {
|
|
12827
|
-
this._getStructOutputs(m.type, outputs);
|
|
12828
|
-
}
|
|
12829
|
-
else {
|
|
12830
|
-
const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
|
|
12831
|
-
if (location !== null) {
|
|
12832
|
-
const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
|
|
12833
|
-
const locationValue = this._parseInt(location.value);
|
|
12834
|
-
const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
|
|
12835
|
-
outputs.push(info);
|
|
12836
|
-
}
|
|
12837
|
-
}
|
|
12838
|
-
}
|
|
12839
|
-
}
|
|
12840
|
-
_getOutputInfo(type) {
|
|
12841
|
-
const location = this._getAttribute(type, "location") ||
|
|
12842
|
-
this._getAttribute(type, "builtin");
|
|
12843
|
-
if (location !== null) {
|
|
12844
|
-
const typeInfo = this._getTypeInfo(type, type.attributes);
|
|
12845
|
-
const locationValue = this._parseInt(location.value);
|
|
12846
|
-
const info = new OutputInfo("", typeInfo, location.name, locationValue);
|
|
12847
|
-
return info;
|
|
12848
|
-
}
|
|
12849
|
-
return null;
|
|
12850
|
-
}
|
|
12851
|
-
_getInputs(args, inputs = undefined) {
|
|
12852
|
-
if (inputs === undefined) {
|
|
12853
|
-
inputs = [];
|
|
12854
|
-
}
|
|
12855
|
-
for (const arg of args) {
|
|
12856
|
-
if (arg.type instanceof Struct) {
|
|
12857
|
-
this._getStructInputs(arg.type, inputs);
|
|
12858
|
-
}
|
|
12859
|
-
else {
|
|
12860
|
-
const input = this._getInputInfo(arg);
|
|
12861
|
-
if (input !== null) {
|
|
12862
|
-
inputs.push(input);
|
|
12863
|
-
}
|
|
12864
|
-
}
|
|
12865
|
-
}
|
|
12866
|
-
return inputs;
|
|
12867
|
-
}
|
|
12868
|
-
_getStructInputs(struct, inputs) {
|
|
12869
|
-
for (const m of struct.members) {
|
|
12870
|
-
if (m.type instanceof Struct) {
|
|
12871
|
-
this._getStructInputs(m.type, inputs);
|
|
12872
|
-
}
|
|
12873
|
-
else {
|
|
12874
|
-
const input = this._getInputInfo(m);
|
|
12875
|
-
if (input !== null) {
|
|
12876
|
-
inputs.push(input);
|
|
12877
|
-
}
|
|
12878
|
-
}
|
|
12879
|
-
}
|
|
12880
|
-
}
|
|
12881
|
-
_getInputInfo(node) {
|
|
12882
|
-
const location = this._getAttribute(node, "location") ||
|
|
12883
|
-
this._getAttribute(node, "builtin");
|
|
12884
|
-
if (location !== null) {
|
|
12885
|
-
const interpolation = this._getAttribute(node, "interpolation");
|
|
12886
|
-
const type = this._getTypeInfo(node.type, node.attributes);
|
|
12887
|
-
const locationValue = this._parseInt(location.value);
|
|
12888
|
-
const info = new InputInfo(node.name, type, location.name, locationValue);
|
|
12889
|
-
if (interpolation !== null) {
|
|
12890
|
-
info.interpolation = this._parseString(interpolation.value);
|
|
12891
|
-
}
|
|
12892
|
-
return info;
|
|
12893
|
-
}
|
|
12894
|
-
return null;
|
|
12895
|
-
}
|
|
12896
|
-
_parseString(s) {
|
|
12897
|
-
if (s instanceof Array) {
|
|
12898
|
-
s = s[0];
|
|
12899
|
-
}
|
|
12900
|
-
return s;
|
|
12901
|
-
}
|
|
12902
|
-
_parseInt(s) {
|
|
12903
|
-
if (s instanceof Array) {
|
|
12904
|
-
s = s[0];
|
|
12905
|
-
}
|
|
12906
|
-
const n = parseInt(s);
|
|
12907
|
-
return isNaN(n) ? s : n;
|
|
12908
|
-
}
|
|
12909
|
-
_getAlias(name) {
|
|
12910
|
-
for (const a of this.aliases) {
|
|
12911
|
-
if (a.name == name) {
|
|
12912
|
-
return a.type;
|
|
12913
|
-
}
|
|
12914
|
-
}
|
|
12915
|
-
return null;
|
|
12916
|
-
}
|
|
12917
|
-
_getAliasInfo(node) {
|
|
12918
|
-
return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
|
|
12919
|
-
}
|
|
12920
|
-
_getTypeInfo(type, attributes) {
|
|
12921
|
-
if (this._types.has(type)) {
|
|
12922
|
-
return this._types.get(type);
|
|
12923
|
-
}
|
|
12924
|
-
if (type instanceof ArrayType) {
|
|
12925
|
-
const a = type;
|
|
12926
|
-
const t = a.format ? this._getTypeInfo(a.format, a.attributes) : null;
|
|
12927
|
-
const info = new ArrayInfo(a.name, attributes);
|
|
12928
|
-
info.format = t;
|
|
12929
|
-
info.count = a.count;
|
|
12930
|
-
this._types.set(type, info);
|
|
12931
|
-
this._updateTypeInfo(info);
|
|
12932
|
-
return info;
|
|
12933
|
-
}
|
|
12934
|
-
if (type instanceof Struct) {
|
|
12935
|
-
const s = type;
|
|
12936
|
-
const info = new StructInfo(s.name, attributes);
|
|
12937
|
-
info.startLine = s.startLine;
|
|
12938
|
-
info.endLine = s.endLine;
|
|
12939
|
-
for (const m of s.members) {
|
|
12940
|
-
const t = this._getTypeInfo(m.type, m.attributes);
|
|
12941
|
-
info.members.push(new MemberInfo(m.name, t, m.attributes));
|
|
12942
|
-
}
|
|
12943
|
-
this._types.set(type, info);
|
|
12944
|
-
this._updateTypeInfo(info);
|
|
12945
|
-
return info;
|
|
12946
|
-
}
|
|
12947
|
-
if (type instanceof SamplerType) {
|
|
12948
|
-
const s = type;
|
|
12949
|
-
const formatIsType = s.format instanceof Type;
|
|
12950
|
-
const format = s.format
|
|
12951
|
-
? formatIsType
|
|
12952
|
-
? this._getTypeInfo(s.format, null)
|
|
12953
|
-
: new TypeInfo(s.format, null)
|
|
12954
|
-
: null;
|
|
12955
|
-
const info = new TemplateInfo(s.name, format, attributes, s.access);
|
|
12956
|
-
this._types.set(type, info);
|
|
12957
|
-
this._updateTypeInfo(info);
|
|
12958
|
-
return info;
|
|
12959
|
-
}
|
|
12960
|
-
if (type instanceof TemplateType) {
|
|
12961
|
-
const t = type;
|
|
12962
|
-
const format = t.format ? this._getTypeInfo(t.format, null) : null;
|
|
12963
|
-
const info = new TemplateInfo(t.name, format, attributes, t.access);
|
|
12964
|
-
this._types.set(type, info);
|
|
12965
|
-
this._updateTypeInfo(info);
|
|
12966
|
-
return info;
|
|
12967
|
-
}
|
|
12968
|
-
const info = new TypeInfo(type.name, attributes);
|
|
12969
|
-
this._types.set(type, info);
|
|
12970
|
-
this._updateTypeInfo(info);
|
|
12971
|
-
return info;
|
|
12972
|
-
}
|
|
12973
|
-
_updateTypeInfo(type) {
|
|
12974
|
-
var _a, _b;
|
|
12975
|
-
const typeSize = this._getTypeSize(type);
|
|
12976
|
-
type.size = (_a = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a !== void 0 ? _a : 0;
|
|
12977
|
-
if (type instanceof ArrayInfo) {
|
|
12978
|
-
if (type["format"]) {
|
|
12979
|
-
const formatInfo = this._getTypeSize(type["format"]);
|
|
12980
|
-
type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
|
|
12981
|
-
this._updateTypeInfo(type["format"]);
|
|
12982
|
-
}
|
|
12983
|
-
}
|
|
12984
|
-
if (type instanceof StructInfo) {
|
|
12985
|
-
this._updateStructInfo(type);
|
|
12986
|
-
}
|
|
12987
|
-
}
|
|
12988
|
-
_updateStructInfo(struct) {
|
|
12989
|
-
var _a;
|
|
12990
|
-
let offset = 0;
|
|
12991
|
-
let lastSize = 0;
|
|
12992
|
-
let lastOffset = 0;
|
|
12993
|
-
let structAlign = 0;
|
|
12994
|
-
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
12995
|
-
const member = struct.members[mi];
|
|
12996
|
-
const sizeInfo = this._getTypeSize(member);
|
|
12997
|
-
if (!sizeInfo) {
|
|
12998
|
-
continue;
|
|
12999
|
-
}
|
|
13000
|
-
(_a = this._getAlias(member.type.name)) !== null && _a !== void 0 ? _a : member.type;
|
|
13001
|
-
const align = sizeInfo.align;
|
|
13002
|
-
const size = sizeInfo.size;
|
|
13003
|
-
offset = this._roundUp(align, offset + lastSize);
|
|
13004
|
-
lastSize = size;
|
|
13005
|
-
lastOffset = offset;
|
|
13006
|
-
structAlign = Math.max(structAlign, align);
|
|
13007
|
-
member.offset = offset;
|
|
13008
|
-
member.size = size;
|
|
13009
|
-
this._updateTypeInfo(member.type);
|
|
13010
|
-
}
|
|
13011
|
-
struct.size = this._roundUp(structAlign, lastOffset + lastSize);
|
|
13012
|
-
struct.align = structAlign;
|
|
13013
|
-
}
|
|
13014
|
-
_getTypeSize(type) {
|
|
13015
|
-
var _a, _b;
|
|
13016
|
-
if (type === null || type === undefined) {
|
|
13017
|
-
return null;
|
|
13018
|
-
}
|
|
13019
|
-
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
13020
|
-
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
13021
|
-
if (type instanceof MemberInfo) {
|
|
13022
|
-
type = type.type;
|
|
13023
|
-
}
|
|
13024
|
-
if (type instanceof TypeInfo) {
|
|
13025
|
-
const alias = this._getAlias(type.name);
|
|
13026
|
-
if (alias !== null) {
|
|
13027
|
-
type = alias;
|
|
13028
|
-
}
|
|
13029
|
-
}
|
|
13030
|
-
{
|
|
13031
|
-
const info = WgslReflect._typeInfo[type.name];
|
|
13032
|
-
if (info !== undefined) {
|
|
13033
|
-
const divisor = ((_a = type["format"]) === null || _a === void 0 ? void 0 : _a.name) === "f16" ? 2 : 1;
|
|
13034
|
-
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
13035
|
-
}
|
|
13036
|
-
}
|
|
13037
|
-
{
|
|
13038
|
-
const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
|
|
13039
|
-
if (info) {
|
|
13040
|
-
const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
|
|
13041
|
-
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
13042
|
-
}
|
|
13043
|
-
}
|
|
13044
|
-
if (type instanceof ArrayInfo) {
|
|
13045
|
-
let arrayType = type;
|
|
13046
|
-
let align = 8;
|
|
13047
|
-
let size = 8;
|
|
13048
|
-
// Type AlignOf(T) Sizeof(T)
|
|
13049
|
-
// array<E, N> AlignOf(E) N * roundUp(AlignOf(E), SizeOf(E))
|
|
13050
|
-
// array<E> AlignOf(E) N * roundUp(AlignOf(E), SizeOf(E)) (N determined at runtime)
|
|
13051
|
-
//
|
|
13052
|
-
// @stride(Q)
|
|
13053
|
-
// array<E, N> AlignOf(E) N * Q
|
|
13054
|
-
//
|
|
13055
|
-
// @stride(Q)
|
|
13056
|
-
// array<E> AlignOf(E) Nruntime * Q
|
|
13057
|
-
//const E = type.format.name;
|
|
13058
|
-
const E = this._getTypeSize(arrayType.format);
|
|
13059
|
-
if (E !== null) {
|
|
13060
|
-
size = E.size;
|
|
13061
|
-
align = E.align;
|
|
13062
|
-
}
|
|
13063
|
-
const N = arrayType.count;
|
|
13064
|
-
const stride = this._getAttributeNum((_b = type === null || type === void 0 ? void 0 : type.attributes) !== null && _b !== void 0 ? _b : null, "stride", this._roundUp(align, size));
|
|
13065
|
-
size = N * stride;
|
|
13066
|
-
if (explicitSize) {
|
|
13067
|
-
size = explicitSize;
|
|
13068
|
-
}
|
|
13069
|
-
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
13070
|
-
}
|
|
13071
|
-
if (type instanceof StructInfo) {
|
|
13072
|
-
let align = 0;
|
|
13073
|
-
let size = 0;
|
|
13074
|
-
// struct S AlignOf: max(AlignOfMember(S, M1), ... , AlignOfMember(S, MN))
|
|
13075
|
-
// SizeOf: roundUp(AlignOf(S), OffsetOfMember(S, L) + SizeOfMember(S, L))
|
|
13076
|
-
// Where L is the last member of the structure
|
|
13077
|
-
let offset = 0;
|
|
13078
|
-
let lastSize = 0;
|
|
13079
|
-
let lastOffset = 0;
|
|
13080
|
-
for (const m of type.members) {
|
|
13081
|
-
const mi = this._getTypeSize(m.type);
|
|
13082
|
-
if (mi !== null) {
|
|
13083
|
-
align = Math.max(mi.align, align);
|
|
13084
|
-
offset = this._roundUp(mi.align, offset + lastSize);
|
|
13085
|
-
lastSize = mi.size;
|
|
13086
|
-
lastOffset = offset;
|
|
13087
|
-
}
|
|
13088
|
-
}
|
|
13089
|
-
size = this._roundUp(align, lastOffset + lastSize);
|
|
13090
|
-
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
13091
|
-
}
|
|
13092
|
-
return null;
|
|
13093
|
-
}
|
|
13094
|
-
_isUniformVar(node) {
|
|
13095
|
-
return node instanceof Var && node.storage == "uniform";
|
|
13096
|
-
}
|
|
13097
|
-
_isStorageVar(node) {
|
|
13098
|
-
return node instanceof Var && node.storage == "storage";
|
|
13099
|
-
}
|
|
13100
|
-
_isTextureVar(node) {
|
|
13101
|
-
return (node instanceof Var &&
|
|
13102
|
-
node.type !== null &&
|
|
13103
|
-
WgslReflect._textureTypes.indexOf(node.type.name) != -1);
|
|
13104
|
-
}
|
|
13105
|
-
_isSamplerVar(node) {
|
|
13106
|
-
return (node instanceof Var &&
|
|
13107
|
-
node.type !== null &&
|
|
13108
|
-
WgslReflect._samplerTypes.indexOf(node.type.name) != -1);
|
|
13109
|
-
}
|
|
13110
|
-
_getAttribute(node, name) {
|
|
13111
|
-
const obj = node;
|
|
13112
|
-
if (!obj || !obj["attributes"]) {
|
|
13113
|
-
return null;
|
|
13114
|
-
}
|
|
13115
|
-
const attrs = obj["attributes"];
|
|
13116
|
-
for (let a of attrs) {
|
|
13117
|
-
if (a.name == name) {
|
|
13118
|
-
return a;
|
|
13119
|
-
}
|
|
13120
|
-
}
|
|
13121
|
-
return null;
|
|
13122
|
-
}
|
|
13123
|
-
_getAttributeNum(attributes, name, defaultValue) {
|
|
13124
|
-
if (attributes === null) {
|
|
13125
|
-
return defaultValue;
|
|
13126
|
-
}
|
|
13127
|
-
for (let a of attributes) {
|
|
13128
|
-
if (a.name == name) {
|
|
13129
|
-
let v = a !== null && a.value !== null ? a.value : defaultValue;
|
|
13130
|
-
if (v instanceof Array) {
|
|
13131
|
-
v = v[0];
|
|
13132
|
-
}
|
|
13133
|
-
if (typeof v === "number") {
|
|
13134
|
-
return v;
|
|
13135
|
-
}
|
|
13136
|
-
if (typeof v === "string") {
|
|
13137
|
-
return parseInt(v);
|
|
13138
|
-
}
|
|
13139
|
-
return defaultValue;
|
|
13140
|
-
}
|
|
13141
|
-
}
|
|
13142
|
-
return defaultValue;
|
|
13143
|
-
}
|
|
13144
|
-
_roundUp(k, n) {
|
|
13145
|
-
return Math.ceil(n / k) * k;
|
|
13146
|
-
}
|
|
13147
|
-
}
|
|
13148
|
-
// Type AlignOf(T) Sizeof(T)
|
|
13149
|
-
// i32, u32, or f32 4 4
|
|
13150
|
-
// atomic<T> 4 4
|
|
13151
|
-
// vec2<T> 8 8
|
|
13152
|
-
// vec3<T> 16 12
|
|
13153
|
-
// vec4<T> 16 16
|
|
13154
|
-
// mat2x2<f32> 8 16
|
|
13155
|
-
// mat3x2<f32> 8 24
|
|
13156
|
-
// mat4x2<f32> 8 32
|
|
13157
|
-
// mat2x3<f32> 16 32
|
|
13158
|
-
// mat3x3<f32> 16 48
|
|
13159
|
-
// mat4x3<f32> 16 64
|
|
13160
|
-
// mat2x4<f32> 16 32
|
|
13161
|
-
// mat3x4<f32> 16 48
|
|
13162
|
-
// mat4x4<f32> 16 64
|
|
13163
|
-
WgslReflect._typeInfo = {
|
|
13164
|
-
f16: { align: 2, size: 2 },
|
|
13165
|
-
i32: { align: 4, size: 4 },
|
|
13166
|
-
u32: { align: 4, size: 4 },
|
|
13167
|
-
f32: { align: 4, size: 4 },
|
|
13168
|
-
atomic: { align: 4, size: 4 },
|
|
13169
|
-
vec2: { align: 8, size: 8 },
|
|
13170
|
-
vec3: { align: 16, size: 12 },
|
|
13171
|
-
vec4: { align: 16, size: 16 },
|
|
13172
|
-
mat2x2: { align: 8, size: 16 },
|
|
13173
|
-
mat3x2: { align: 8, size: 24 },
|
|
13174
|
-
mat4x2: { align: 8, size: 32 },
|
|
13175
|
-
mat2x3: { align: 16, size: 32 },
|
|
13176
|
-
mat3x3: { align: 16, size: 48 },
|
|
13177
|
-
mat4x3: { align: 16, size: 64 },
|
|
13178
|
-
mat2x4: { align: 16, size: 32 },
|
|
13179
|
-
mat3x4: { align: 16, size: 48 },
|
|
13180
|
-
mat4x4: { align: 16, size: 64 },
|
|
13181
|
-
};
|
|
13182
|
-
WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
|
|
13183
|
-
return t.name;
|
|
13184
|
-
});
|
|
13185
|
-
WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
|
|
13186
|
-
return t.name;
|
|
13187
|
-
});
|
|
9115
|
+
class e{constructor(e,t){this.name=e,this.attributes=t,this.size=0;}get isArray(){return !1}get isStruct(){return !1}get isTemplate(){return !1}get isPointer(){return !1}getTypeName(){return this.name}}class t{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0;}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class n extends e{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1;}get isStruct(){return !0}}class s extends e{constructor(e,t){super(e,t),this.count=0,this.stride=0;}get isArray(){return !0}getTypeName(){return `array<${this.format.getTypeName()}, ${this.count}>`}}class r extends e{constructor(e,t,n){super(e,n),this.format=t;}get isPointer(){return !0}getTypeName(){return `&${this.format.getTypeName()}`}}class a extends e{constructor(e,t,n,s){super(e,n),this.format=t,this.access=s;}get isTemplate(){return !0}getTypeName(){let e=this.name;if(null!==this.format){if('vec2'===e||'vec3'===e||'vec4'===e||'mat2x2'===e||'mat2x3'===e||'mat2x4'===e||'mat3x2'===e||'mat3x3'===e||'mat3x4'===e||'mat4x2'===e||'mat4x3'===e||'mat4x4'===e){if('f32'===this.format.name)return e+='f',e;if('i32'===this.format.name)return e+='i',e;if('u32'===this.format.name)return e+='u',e;if('bool'===this.format.name)return e+='b',e;if('f16'===this.format.name)return e+='h',e}e+=`<${this.format.name}>`;}else if('vec2'===e||'vec3'===e||'vec4'===e)return e;return e}}var i;(e=>{e[e.Uniform=0]='Uniform',e[e.Storage=1]='Storage',e[e.Texture=2]='Texture',e[e.Sampler=3]='Sampler',e[e.StorageTexture=4]='StorageTexture';})(i||(i={}));class o{constructor(e,t,n,s,r,a,i){this.name=e,this.type=t,this.group=n,this.binding=s,this.attributes=r,this.resourceType=a,this.access=i;}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}}class c{constructor(e,t){this.name=e,this.type=t;}}class l{constructor(e,t,n,s){this.name=e,this.type=t,this.locationType=n,this.location=s,this.interpolation=null;}}class u{constructor(e,t,n,s){this.name=e,this.type=t,this.locationType=n,this.location=s;}}class h{constructor(e,t,n,s){this.name=e,this.type=t,this.attributes=n,this.id=s;}}class f{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n;}}class p{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n;}}class d{constructor(){this.vertex=[],this.fragment=[],this.compute=[];}}function m(e){var t=(32768&e)>>15,n=(31744&e)>>10,s=1023&e;return 0==n?(t?-1:1)*Math.pow(2,-14)*(s/Math.pow(2,10)):31==n?s?NaN:1/0*(t?-1:1):(t?-1:1)*Math.pow(2,n-15)*(1+s/Math.pow(2,10))}const g=new Float32Array(1),_=new Int32Array(g.buffer),x=new Uint16Array(1);function y(e){g[0]=e;const t=_[0],n=t>>31&1;let s=t>>23&255,r=8388607&t;if(255===s)return x[0]=n<<15|31744|(0!==r?512:0),x[0];if(0===s){if(0===r)return x[0]=n<<15,x[0];r|=8388608;let e=113;for(;!(8388608&r);)r<<=1,e--;return s=127-e,r&=8388607,s>0?(r=(r>>126-s)+(r>>127-s&1),x[0]=n<<15|s<<10|r>>13,x[0]):(x[0]=n<<15,x[0])}return s=s-127+15,s>=31?(x[0]=n<<15|31744,x[0]):s<=0?s<-10?(x[0]=n<<15,x[0]):(r=(8388608|r)>>1-s,x[0]=n<<15|r>>13,x[0]):(r>>=13,x[0]=n<<15|s<<10|r,x[0])}const b=new Uint32Array(1),v=new Float32Array(b.buffer,0,1);function w(e){const t=112+(e>>6&31)<<23|(63&e)<<17;return b[0]=t,v[0]}function k(e,t,n,s,r,a,i,o,c){const l=s*(i>>=r)*(a>>=r)+n*i+t*o;switch(c){case'r8unorm':return [I(e,l,'8unorm',1)[0]];case'r8snorm':return [I(e,l,'8snorm',1)[0]];case'r8uint':return [I(e,l,'8uint',1)[0]];case'r8sint':return [I(e,l,'8sint',1)[0]];case'rg8unorm':{const t=I(e,l,'8unorm',2);return [t[0],t[1]]}case'rg8snorm':{const t=I(e,l,'8snorm',2);return [t[0],t[1]]}case'rg8uint':{const t=I(e,l,'8uint',2);return [t[0],t[1]]}case'rg8sint':{const t=I(e,l,'8sint',2);return [t[0],t[1]]}case'rgba8unorm-srgb':case'rgba8unorm':{const t=I(e,l,'8unorm',4);return [t[0],t[1],t[2],t[3]]}case'rgba8snorm':{const t=I(e,l,'8snorm',4);return [t[0],t[1],t[2],t[3]]}case'rgba8uint':{const t=I(e,l,'8uint',4);return [t[0],t[1],t[2],t[3]]}case'rgba8sint':{const t=I(e,l,'8sint',4);return [t[0],t[1],t[2],t[3]]}case'bgra8unorm-srgb':case'bgra8unorm':{const t=I(e,l,'8unorm',4);return [t[2],t[1],t[0],t[3]]}case'r16uint':return [I(e,l,'16uint',1)[0]];case'r16sint':return [I(e,l,'16sint',1)[0]];case'r16float':return [I(e,l,'16float',1)[0]];case'rg16uint':{const t=I(e,l,'16uint',2);return [t[0],t[1]]}case'rg16sint':{const t=I(e,l,'16sint',2);return [t[0],t[1]]}case'rg16float':{const t=I(e,l,'16float',2);return [t[0],t[1]]}case'rgba16uint':{const t=I(e,l,'16uint',4);return [t[0],t[1],t[2],t[3]]}case'rgba16sint':{const t=I(e,l,'16sint',4);return [t[0],t[1],t[2],t[3]]}case'rgba16float':{const t=I(e,l,'16float',4);return [t[0],t[1],t[2],t[3]]}case'r32uint':return [I(e,l,'32uint',1)[0]];case'r32sint':return [I(e,l,'32sint',1)[0]];case'depth16unorm':case'depth24plus':case'depth24plus-stencil8':case'depth32float':case'depth32float-stencil8':case'r32float':return [I(e,l,'32float',1)[0]];case'rg32uint':{const t=I(e,l,'32uint',2);return [t[0],t[1]]}case'rg32sint':{const t=I(e,l,'32sint',2);return [t[0],t[1]]}case'rg32float':{const t=I(e,l,'32float',2);return [t[0],t[1]]}case'rgba32uint':{const t=I(e,l,'32uint',4);return [t[0],t[1],t[2],t[3]]}case'rgba32sint':{const t=I(e,l,'32sint',4);return [t[0],t[1],t[2],t[3]]}case'rgba32float':{const t=I(e,l,'32float',4);return [t[0],t[1],t[2],t[3]]}case'rg11b10ufloat':{const t=new Uint32Array(e.buffer,l,1)[0],n=(4192256&t)>>11,s=(4290772992&t)>>22;return [w(2047&t),w(n),function(e){const t=112+(e>>5&31)<<23|(31&e)<<18;return b[0]=t,v[0]}(s),1]}}return null}function I(e,t,n,s){const r=[0,0,0,0];for(let a=0;a<s;++a)switch(n){case'8unorm':r[a]=e[t]/255,t++;break;case'8snorm':r[a]=e[t]/255*2-1,t++;break;case'8uint':r[a]=e[t],t++;break;case'8sint':r[a]=e[t]-127,t++;break;case'16uint':r[a]=e[t]|e[t+1]<<8,t+=2;break;case'16sint':r[a]=(e[t]|e[t+1]<<8)-32768,t+=2;break;case'16float':r[a]=m(e[t]|e[t+1]<<8),t+=2;break;case'32uint':case'32sint':r[a]=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,t+=4;break;case'32float':r[a]=new Float32Array(e.buffer,t,1)[0],t+=4;}return r}function T(e,t,n,s,r){for(let a=0;a<s;++a)switch(n){case'8unorm':e[t]=255*r[a],t++;break;case'8snorm':e[t]=.5*(r[a]+1)*255,t++;break;case'8uint':e[t]=r[a],t++;break;case'8sint':e[t]=r[a]+127,t++;break;case'16uint':new Uint16Array(e.buffer,t,1)[0]=r[a],t+=2;break;case'16sint':new Int16Array(e.buffer,t,1)[0]=r[a],t+=2;break;case'16float':{const n=y(r[a]);new Uint16Array(e.buffer,t,1)[0]=n,t+=2;break}case'32uint':new Uint32Array(e.buffer,t,1)[0]=r[a],t+=4;break;case'32sint':new Int32Array(e.buffer,t,1)[0]=r[a],t+=4;break;case'32float':new Float32Array(e.buffer,t,1)[0]=r[a],t+=4;}return r}const S={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'rgba8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bgra8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:'depth32float',channels:1},'depth24plus-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:'depth32float',channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},'depth32float-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:'depth32float',channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bc1-rgba-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc1-rgba-unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc4-r-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc4-r-snorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc5-rg-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc5-rg-snorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc6h-rgb-ufloat':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc6h-rgb-float':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'eac-r11unorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-r11snorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-rg11unorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'eac-rg11snorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'astc-4x4-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-4x4-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x5-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-5x5-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x6-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-6x6-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-8x5-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x5-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x6-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x6-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x8-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-8x8-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-10x5-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x5-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x6-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x6-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x8-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x8-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x10-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-10x10-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x12-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},'astc-12x12-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class A{constructor(){this.id=A._id++,this.line=0;}get isAstNode(){return !0}get astNodeType(){return ''}search(e){e(this);}searchBlock(e,t){if(e){t(E.instance);for(const n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t($.instance);}}constEvaluate(e,t){throw new Error('Cannot evaluate node')}constEvaluateString(e){return this.constEvaluate(e).toString()}}A._id=0;class E extends A{}E.instance=new E;class $ extends A{}$.instance=new $;const L=new Set(['all','all','any','select','arrayLength','abs','acos','acosh','asin','asinh','atan','atanh','atan2','ceil','clamp','cos','cosh','countLeadingZeros','countOneBits','countTrailingZeros','cross','degrees','determinant','distance','dot','dot4U8Packed','dot4I8Packed','exp','exp2','extractBits','faceForward','firstLeadingBit','firstTrailingBit','floor','fma','fract','frexp','insertBits','inverseSqrt','ldexp','length','log','log2','max','min','mix','modf','normalize','pow','quantizeToF16','radians','reflect','refract','reverseBits','round','saturate','sign','sin','sinh','smoothStep','sqrt','step','tan','tanh','transpose','trunc','dpdx','dpdxCoarse','dpdxFine','dpdy','dpdyCoarse','dpdyFine','fwidth','fwidthCoarse','fwidthFine','textureDimensions','textureGather','textureGatherCompare','textureLoad','textureNumLayers','textureNumLevels','textureNumSamples','textureSample','textureSampleBias','textureSampleCompare','textureSampleCompareLevel','textureSampleGrad','textureSampleLevel','textureSampleBaseClampToEdge','textureStore','atomicLoad','atomicStore','atomicAdd','atomicSub','atomicMax','atomicMin','atomicAnd','atomicOr','atomicXor','atomicExchange','atomicCompareExchangeWeak','pack4x8snorm','pack4x8unorm','pack4xI8','pack4xU8','pack4x8Clamp','pack4xU8Clamp','pack2x16snorm','pack2x16unorm','pack2x16float','unpack4x8snorm','unpack4x8unorm','unpack4xI8','unpack4xU8','unpack2x16snorm','unpack2x16unorm','unpack2x16float','storageBarrier','textureBarrier','workgroupBarrier','workgroupUniformLoad','subgroupAdd','subgroupExclusiveAdd','subgroupInclusiveAdd','subgroupAll','subgroupAnd','subgroupAny','subgroupBallot','subgroupBroadcast','subgroupBroadcastFirst','subgroupElect','subgroupMax','subgroupMin','subgroupMul','subgroupExclusiveMul','subgroupInclusiveMul','subgroupOr','subgroupShuffle','subgroupShuffleDown','subgroupShuffleUp','subgroupShuffleXor','subgroupXor','quadBroadcast','quadSwapDiagonal','quadSwapX','quadSwapY']);class C extends A{constructor(){super();}}class D extends C{constructor(e,t,n,s,r,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=s,this.startLine=r,this.endLine=a;}get astNodeType(){return 'function'}search(e){if(this.attributes)for(const t of this.attributes)e(t);e(this);for(const t of this.args)e(t);this.searchBlock(this.body,e);}}class N extends C{constructor(e){super(),this.expression=e;}get astNodeType(){return 'staticAssert'}search(e){this.expression.search(e);}}class V extends C{constructor(e,t){super(),this.condition=e,this.body=t;}get astNodeType(){return 'while'}search(e){this.condition.search(e),this.searchBlock(this.body,e);}}class O extends C{constructor(e,t){super(),this.body=e,this.loopId=t;}get astNodeType(){return 'continuing'}search(e){this.searchBlock(this.body,e);}}class B extends C{constructor(e,t,n,s){super(),this.init=e,this.condition=t,this.increment=n,this.body=s;}get astNodeType(){return 'for'}search(e){var t,n,s;null===(t=this.init)||void 0===t||t.search(e),null===(n=this.condition)||void 0===n||n.search(e),null===(s=this.increment)||void 0===s||s.search(e),this.searchBlock(this.body,e);}}class F extends C{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r;}get astNodeType(){return 'var'}search(e){var t;e(this),null===(t=this.value)||void 0===t||t.search(e);}}class M extends C{constructor(e,t,n){super(),this.attributes=null,this.name=e,this.type=t,this.value=n;}get astNodeType(){return 'override'}search(e){var t;null===(t=this.value)||void 0===t||t.search(e);}}class U extends C{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r;}get astNodeType(){return 'let'}search(e){var t;e(this),null===(t=this.value)||void 0===t||t.search(e);}}class P extends C{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r;}get astNodeType(){return 'const'}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),null===(t=this.value)||void 0===t||t.search(e);}}var W,q,H,z;(e=>{e.increment='++',e.decrement='--';})(W||(W={})),(e=>{e.parse=function(t){const n=t;if('parse'==n)throw new Error('Invalid value for IncrementOperator');return e[n]};})(W||(W={}));class R extends C{constructor(e,t){super(),this.operator=e,this.variable=t;}get astNodeType(){return 'increment'}search(e){this.variable.search(e);}}(e=>{e.assign='=',e.addAssign='+=',e.subtractAssin='-=',e.multiplyAssign='*=',e.divideAssign='/=',e.moduloAssign='%=',e.andAssign='&=',e.orAssign='|=',e.xorAssign='^=',e.shiftLeftAssign='<<=',e.shiftRightAssign='>>=';})(q||(q={})),(e=>{e.parse=function(e){const t=e;if('parse'==t)throw new Error('Invalid value for AssignOperator');return t};})(q||(q={}));class G extends C{constructor(e,t,n){super(),this.operator=e,this.variable=t,this.value=n;}get astNodeType(){return 'assign'}search(e){this.variable.search(e),this.value.search(e);}}class X extends C{constructor(e,t){super(),this.name=e,this.args=t;}get astNodeType(){return 'call'}isBuiltin(){return L.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this);}}class j extends C{constructor(e,t){super(),this.body=e,this.continuing=t;}get astNodeType(){return 'loop'}search(e){var t;this.searchBlock(this.body,e),null===(t=this.continuing)||void 0===t||t.search(e);}}class Z extends C{constructor(e,t){super(),this.condition=e,this.cases=t;}get astNodeType(){return 'switch'}search(e){e(this);for(const t of this.cases)t.search(e);}}class Q extends C{constructor(e,t,n,s){super(),this.condition=e,this.body=t,this.elseif=n,this.else=s;}get astNodeType(){return 'if'}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e);}}class Y extends C{constructor(e){super(),this.value=e;}get astNodeType(){return 'return'}search(e){var t;null===(t=this.value)||void 0===t||t.search(e);}}class K extends C{constructor(e){super(),this.name=e;}get astNodeType(){return 'enable'}}class J extends C{constructor(e){super(),this.extensions=e;}get astNodeType(){return 'requires'}}class ee extends C{constructor(e,t){super(),this.severity=e,this.rule=t;}get astNodeType(){return 'diagnostic'}}class te extends C{constructor(e,t){super(),this.name=e,this.type=t;}get astNodeType(){return 'alias'}}class ne extends C{constructor(){super();}get astNodeType(){return 'discard'}}class se extends C{constructor(){super(),this.condition=null,this.loopId=-1;}get astNodeType(){return 'break'}}class re extends C{constructor(){super(),this.loopId=-1;}get astNodeType(){return 'continue'}}class ae extends C{constructor(e){super(),this.attributes=null,this.name=e;}get astNodeType(){return 'type'}get isStruct(){return !1}get isArray(){return !1}static maxFormatType(e){let t=e[0];if('f32'===t.name)return t;for(let n=1;n<e.length;++n){const s=ae._priority.get(t.name);ae._priority.get(e[n].name)<s&&(t=e[n]);}return 'x32'===t.name?ae.i32:t}getTypeName(){return this.name}}ae.x32=new ae('x32'),ae.f32=new ae('f32'),ae.i32=new ae('i32'),ae.u32=new ae('u32'),ae.f16=new ae('f16'),ae.bool=new ae('bool'),ae.void=new ae('void'),ae._priority=new Map([['f32',0],['f16',1],['u32',2],['i32',3],['x32',3]]);class ie extends ae{constructor(e){super(e);}}class oe extends ae{constructor(e,t,n,s){super(e),this.members=t,this.startLine=n,this.endLine=s;}get astNodeType(){return 'struct'}get isStruct(){return !0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return -1}search(e){for(const t of this.members)e(t);}}class ce extends ae{constructor(e,t,n){super(e),this.format=t,this.access=n;}get astNodeType(){return 'template'}getTypeName(){let e=this.name;if(null!==this.format){if('vec2'===e||'vec3'===e||'vec4'===e||'mat2x2'===e||'mat2x3'===e||'mat2x4'===e||'mat3x2'===e||'mat3x3'===e||'mat3x4'===e||'mat4x2'===e||'mat4x3'===e||'mat4x4'===e){if('f32'===this.format.name)return e+='f',e;if('i32'===this.format.name)return e+='i',e;if('u32'===this.format.name)return e+='u',e;if('bool'===this.format.name)return e+='b',e;if('f16'===this.format.name)return e+='h',e}e+=`<${this.format.name}>`;}else if('vec2'===e||'vec3'===e||'vec4'===e)return e;return e}}ce.vec2f=new ce('vec2',ae.f32,null),ce.vec3f=new ce('vec3',ae.f32,null),ce.vec4f=new ce('vec4',ae.f32,null),ce.vec2i=new ce('vec2',ae.i32,null),ce.vec3i=new ce('vec3',ae.i32,null),ce.vec4i=new ce('vec4',ae.i32,null),ce.vec2u=new ce('vec2',ae.u32,null),ce.vec3u=new ce('vec3',ae.u32,null),ce.vec4u=new ce('vec4',ae.u32,null),ce.vec2h=new ce('vec2',ae.f16,null),ce.vec3h=new ce('vec3',ae.f16,null),ce.vec4h=new ce('vec4',ae.f16,null),ce.vec2b=new ce('vec2',ae.bool,null),ce.vec3b=new ce('vec3',ae.bool,null),ce.vec4b=new ce('vec4',ae.bool,null),ce.mat2x2f=new ce('mat2x2',ae.f32,null),ce.mat2x3f=new ce('mat2x3',ae.f32,null),ce.mat2x4f=new ce('mat2x4',ae.f32,null),ce.mat3x2f=new ce('mat3x2',ae.f32,null),ce.mat3x3f=new ce('mat3x3',ae.f32,null),ce.mat3x4f=new ce('mat3x4',ae.f32,null),ce.mat4x2f=new ce('mat4x2',ae.f32,null),ce.mat4x3f=new ce('mat4x3',ae.f32,null),ce.mat4x4f=new ce('mat4x4',ae.f32,null),ce.mat2x2h=new ce('mat2x2',ae.f16,null),ce.mat2x3h=new ce('mat2x3',ae.f16,null),ce.mat2x4h=new ce('mat2x4',ae.f16,null),ce.mat3x2h=new ce('mat3x2',ae.f16,null),ce.mat3x3h=new ce('mat3x3',ae.f16,null),ce.mat3x4h=new ce('mat3x4',ae.f16,null),ce.mat4x2h=new ce('mat4x2',ae.f16,null),ce.mat4x3h=new ce('mat4x3',ae.f16,null),ce.mat4x4h=new ce('mat4x4',ae.f16,null),ce.mat2x2i=new ce('mat2x2',ae.i32,null),ce.mat2x3i=new ce('mat2x3',ae.i32,null),ce.mat2x4i=new ce('mat2x4',ae.i32,null),ce.mat3x2i=new ce('mat3x2',ae.i32,null),ce.mat3x3i=new ce('mat3x3',ae.i32,null),ce.mat3x4i=new ce('mat3x4',ae.i32,null),ce.mat4x2i=new ce('mat4x2',ae.i32,null),ce.mat4x3i=new ce('mat4x3',ae.i32,null),ce.mat4x4i=new ce('mat4x4',ae.i32,null),ce.mat2x2u=new ce('mat2x2',ae.u32,null),ce.mat2x3u=new ce('mat2x3',ae.u32,null),ce.mat2x4u=new ce('mat2x4',ae.u32,null),ce.mat3x2u=new ce('mat3x2',ae.u32,null),ce.mat3x3u=new ce('mat3x3',ae.u32,null),ce.mat3x4u=new ce('mat3x4',ae.u32,null),ce.mat4x2u=new ce('mat4x2',ae.u32,null),ce.mat4x3u=new ce('mat4x3',ae.u32,null),ce.mat4x4u=new ce('mat4x4',ae.u32,null);class le extends ae{constructor(e,t,n,s){super(e),this.storage=t,this.type=n,this.access=s;}get astNodeType(){return 'pointer'}}class ue extends ae{constructor(e,t,n,s){super(e),this.attributes=t,this.format=n,this.count=s;}get astNodeType(){return 'array'}get isArray(){return !0}}class he extends ae{constructor(e,t,n){super(e),this.format=t,this.access=n;}get astNodeType(){return 'sampler'}}class fe extends A{constructor(){super(),this.postfix=null;}}class pe extends fe{constructor(e){super(),this.value=e;}get astNodeType(){return 'stringExpr'}toString(){return this.value}constEvaluateString(){return this.value}}class de extends fe{constructor(e,t){super(),this.type=e,this.args=t;}get astNodeType(){return 'createExpr'}search(e){if(e(this),this.args)for(const t of this.args)t.search(e);}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}}class me extends fe{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t;}get astNodeType(){return 'callExpr'}setCachedReturnValue(e){this.cachedReturnValue=e;}get isBuiltin(){return L.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(const t of this.args)t.search(e);e(this);}}class ge extends fe{constructor(e){super(),this.name=e;}get astNodeType(){return 'varExpr'}search(e){e(this),this.postfix&&this.postfix.search(e);}constEvaluate(e,t){return e.evalExpression(this,e.context)}}class _e extends fe{constructor(e,t){super(),this.name=e,this.initializer=t;}get astNodeType(){return 'constExpr'}constEvaluate(e,t){if(this.initializer){const t=e.evalExpression(this.initializer,e.context);return null!==t&&this.postfix?t.getSubData(e,this.postfix,e.context):t}return null}search(e){this.initializer.search(e);}}class xe extends fe{constructor(e,t){super(),this.value=e,this.type=t;}get astNodeType(){return 'literalExpr'}constEvaluate(e,t){return void 0!==t&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof Be}get isVector(){return this.value instanceof Me||this.value instanceof Ue}get scalarValue(){return this.value instanceof Be?this.value.value:(console.error('Value is not scalar.'),0)}get vectorValue(){return this.value instanceof Me||this.value instanceof Ue?this.value.data:(console.error('Value is not a vector or matrix.'),new Float32Array(0))}}class ye extends fe{constructor(e,t){super(),this.type=e,this.value=t;}get astNodeType(){return 'bitcastExpr'}search(e){this.value.search(e);}}class ve extends fe{constructor(e){super(),this.index=e;}search(e){this.index.search(e);}}class we extends fe{constructor(){super();}}class ke extends we{constructor(e,t){super(),this.operator=e,this.right=t;}get astNodeType(){return 'unaryOp'}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e);}}class Ie extends we{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n;}get astNodeType(){return 'binaryOp'}_getPromotedType(e,t){return e.name===t.name?e:'f32'===e.name||'f32'===t.name?ae.f32:'u32'===e.name||'u32'===t.name?ae.u32:ae.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e);}}class Te extends A{constructor(e){super(),this.body=e;}search(e){e(this),this.searchBlock(this.body,e);}}class Se extends fe{constructor(){super();}get astNodeType(){return 'default'}}class Ae extends Te{constructor(e,t){super(t),this.selectors=e;}get astNodeType(){return 'case'}search(e){this.searchBlock(this.body,e);}}class Ee extends Te{constructor(e){super(e);}get astNodeType(){return 'default'}search(e){this.searchBlock(this.body,e);}}class $e extends A{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n;}get astNodeType(){return 'argument'}}class Le extends A{constructor(e,t){super(),this.condition=e,this.body=t;}get astNodeType(){return 'elseif'}search(e){this.condition.search(e),this.searchBlock(this.body,e);}}class Ce extends A{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n;}get astNodeType(){return 'member'}}class De extends A{constructor(e,t){super(),this.name=e,this.value=t;}get astNodeType(){return 'attribute'}}class Ne{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=Ne._id++;}clone(){throw `Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,s){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`);}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return `<${this.typeInfo.getTypeName()}>`}}Ne._id=0;class Ve extends Ne{constructor(){super(new e('void',null),null);}toString(){return 'void'}}Ve.void=new Ve;class Oe extends Ne{constructor(e){super(new r('pointer',e.typeInfo,null),null),this.reference=e;}clone(){return this}setDataValue(e,t,n,s){this.reference.setDataValue(e,t,n,s);}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}toString(){return `&${this.reference.toString()}`}}class Be extends Ne{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:'x32'===this.typeInfo.name?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):'i32'===this.typeInfo.name||'bool'===this.typeInfo.name?this.data=new Int32Array([e]):'u32'===this.typeInfo.name?this.data=new Uint32Array([e]):'f32'===this.typeInfo.name||'f16'===this.typeInfo.name?this.data=new Float32Array([e]):console.error('ScalarData2: Invalid type',t);}clone(){if(this.data instanceof Float32Array)return new Be(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new Be(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new Be(new Uint32Array(this.data),this.typeInfo,null);throw 'ScalarData: Invalid data type'}get value(){return this.data[0]}set value(e){this.data[0]=e;}setDataValue(e,t,n,s){if(n)return void console.error('SetDataValue: Scalar data does not support postfix',n);if(!(t instanceof Be))return void console.error('SetDataValue: Invalid value',t);let r=t.data[0];'i32'===this.typeInfo.name||'u32'===this.typeInfo.name?r=Math.floor(r):'bool'===this.typeInfo.name&&(r=r?1:0),this.data[0]=r;}getSubData(e,t,n){return t?(console.error('getSubData: Scalar data does not support postfix',t),null):this}toString(){return `${this.value}`}}function Fe(e,t,n){const s=t.length;return 2===s?'f32'===n?new Me(new Float32Array(t),e.getTypeInfo('vec2f')):'i32'===n||'bool'===n?new Me(new Int32Array(t),e.getTypeInfo('vec2i')):'u32'===n?new Me(new Uint32Array(t),e.getTypeInfo('vec2u')):'f16'===n?new Me(new Float32Array(t),e.getTypeInfo('vec2h')):(console.error(`getSubData: Unknown format ${n}`),null):3===s?'f32'===n?new Me(new Float32Array(t),e.getTypeInfo('vec3f')):'i32'===n||'bool'===n?new Me(new Int32Array(t),e.getTypeInfo('vec3i')):'u32'===n?new Me(new Uint32Array(t),e.getTypeInfo('vec3u')):'f16'===n?new Me(new Float32Array(t),e.getTypeInfo('vec3h')):(console.error(`getSubData: Unknown format ${n}`),null):4===s?'f32'===n?new Me(new Float32Array(t),e.getTypeInfo('vec4f')):'i32'===n||'bool'===n?new Me(new Int32Array(t),e.getTypeInfo('vec4i')):'u32'===n?new Me(new Uint32Array(t),e.getTypeInfo('vec4u')):'f16'===n?new Me(new Float32Array(t),e.getTypeInfo('vec4h')):(console.error(`getSubData: Unknown format ${n}`),null):(console.error(`getSubData: Invalid vector size ${t.length}`),null)}class Me extends Ne{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else {const t=this.typeInfo.name;'vec2f'===t||'vec3f'===t||'vec4f'===t?this.data=new Float32Array(e):'vec2i'===t||'vec3i'===t||'vec4i'===t?this.data=new Int32Array(e):'vec2u'===t||'vec3u'===t||'vec4u'===t?this.data=new Uint32Array(e):'vec2h'===t||'vec3h'===t||'vec4h'===t?this.data=new Float32Array(e):'vec2b'===t||'vec3b'===t||'vec4b'===t?this.data=new Int32Array(e):'vec2'===t||'vec3'===t||'vec4'===t?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${t}`);}}clone(){if(this.data instanceof Float32Array)return new Me(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new Me(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new Me(new Uint32Array(this.data),this.typeInfo,null);throw 'VectorData: Invalid data type'}setDataValue(e,t,n,s){n instanceof pe?console.error('TODO: Set vector postfix'):t instanceof Me?this.data=t.data:console.error('SetDataValue: Invalid value',t);}getSubData(e,t,n){if(null===t)return this;let s=e.getTypeInfo('f32');if(this.typeInfo instanceof a)s=this.typeInfo.format||s;else {const t=this.typeInfo.name;'vec2f'===t||'vec3f'===t||'vec4f'===t?s=e.getTypeInfo('f32'):'vec2i'===t||'vec3i'===t||'vec4i'===t?s=e.getTypeInfo('i32'):'vec2b'===t||'vec3b'===t||'vec4b'===t?s=e.getTypeInfo('bool'):'vec2u'===t||'vec3u'===t||'vec4u'===t?s=e.getTypeInfo('u32'):'vec2h'===t||'vec3h'===t||'vec4h'===t?s=e.getTypeInfo('f16'):console.error(`GetSubData: Unknown type ${t}`);}let r=this;for(;null!==t&&null!==r;){if(t instanceof ve){const a=t.index;let i=-1;if(a instanceof xe){if(!(a.value instanceof Be))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value;}else {const t=e.evalExpression(a,n);if(!(t instanceof Be))return console.error('GetSubData: Unknown index type',a),null;i=t.value;}if(i<0||i>=r.data.length)return console.error('GetSubData: Index out of range',i),null;if(r.data instanceof Float32Array){const e=new Float32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new Be(e,s)}if(r.data instanceof Int32Array){const e=new Int32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new Be(e,s)}if(r.data instanceof Uint32Array){const e=new Uint32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new Be(e,s)}throw 'GetSubData: Invalid data type'}if(!(t instanceof pe))return console.error('GetSubData: Unknown postfix',t),null;{const n=t.value.toLowerCase();if(1===n.length){let e=0;if('x'===n||'r'===n)e=0;else if('y'===n||'g'===n)e=1;else if('z'===n||'b'===n)e=2;else {if('w'!==n&&'a'!==n)return console.error(`GetSubData: Unknown member ${n}`),null;e=3;}if(this.data instanceof Float32Array){let t=new Float32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new Be(t,s,this)}if(this.data instanceof Int32Array){let t=new Int32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new Be(t,s,this)}if(this.data instanceof Uint32Array){let t=new Uint32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new Be(t,s,this)}}const a=[];for(const e of n)'x'===e||'r'===e?a.push(this.data[0]):'y'===e||'g'===e?a.push(this.data[1]):'z'===e||'b'===e?a.push(this.data[2]):'w'===e||'a'===e?a.push(this.data[3]):console.error(`GetDataValue: Unknown member ${e}`);r=Fe(e,a,s.name);}t=t.postfix;}return r}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class Ue extends Ne{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e);}clone(){return new Ue(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,s){n instanceof pe?console.error('TODO: Set matrix postfix'):t instanceof Ue?this.data=t.data:console.error('SetDataValue: Invalid value',t);}getSubData(e,t,n){if(null===t)return this;const s=this.typeInfo.name;if(e.getTypeInfo('f32'),this.typeInfo instanceof a)this.typeInfo.format;else if(s.endsWith('f'))e.getTypeInfo('f32');else if(s.endsWith('i'))e.getTypeInfo('i32');else if(s.endsWith('u'))e.getTypeInfo('u32');else {if(!s.endsWith('h'))return console.error(`GetDataValue: Unknown type ${s}`),null;e.getTypeInfo('f16');}if(t instanceof ve){const r=t.index;let a=-1;if(r instanceof xe){if(!(r.value instanceof Be))return console.error(`GetDataValue: Invalid array index ${r.value}`),null;a=r.value.value;}else {const t=e.evalExpression(r,n);if(!(t instanceof Be))return console.error('GetDataValue: Unknown index type',r),null;a=t.value;}if(a<0||a>=this.data.length)return console.error('GetDataValue: Index out of range',a),null;const i=s.endsWith('h')?'h':'f';let o;if('mat2x2'===s||'mat2x2f'===s||'mat2x2h'===s||'mat3x2'===s||'mat3x2f'===s||'mat3x2h'===s||'mat4x2'===s||'mat4x2f'===s||'mat4x2h'===s)o=new Me(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${i}`));else if('mat2x3'===s||'mat2x3f'===s||'mat2x3h'===s||'mat3x3'===s||'mat3x3f'===s||'mat3x3h'===s||'mat4x3'===s||'mat4x3f'===s||'mat4x3h'===s)o=new Me(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${i}`));else {if('mat2x4'!==s&&'mat2x4f'!==s&&'mat2x4h'!==s&&'mat3x4'!==s&&'mat3x4f'!==s&&'mat3x4h'!==s&&'mat4x4'!==s&&'mat4x4f'!==s&&'mat4x4h'!==s)return console.error(`GetDataValue: Unknown type ${s}`),null;o=new Me(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${i}`));}return t.postfix?o.getSubData(e,t.postfix,n):o}return console.error('GetDataValue: Invalid postfix',t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class Pe extends Ne{constructor(e,t,n=0,s=null){super(t,s),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n;}clone(){const e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new Pe(e.buffer,this.typeInfo,0,null)}setDataValue(t,r,a,i){if(null===r)return void console.log('setDataValue: NULL data.');let o=this.offset,c=this.typeInfo;for(;a;){if(a instanceof ve)if(c instanceof s){const e=a.index;if(e instanceof xe){if(!(e.value instanceof Be))return void console.error(`SetDataValue: Invalid index type ${e.value}`);o+=e.value.value*c.stride;}else {const n=t.evalExpression(e,i);if(!(n instanceof Be))return void console.error('SetDataValue: Unknown index type',e);o+=n.value*c.stride;}c=c.format;}else console.error(`SetDataValue: Type ${c.getTypeName()} is not an array`);else {if(!(a instanceof pe))return void console.error('SetDataValue: Unknown postfix type',a);{const t=a.value;if(c instanceof n){let e=!1;for(const n of c.members)if(n.name===t){o+=n.offset,c=n.type,e=!0;break}if(!e)return void console.error(`SetDataValue: Member ${t} not found`)}else if(c instanceof e){const e=c.getTypeName();let n=0;if('x'===t||'r'===t)n=0;else if('y'===t||'g'===t)n=1;else if('z'===t||'b'===t)n=2;else {if('w'!==t&&'a'!==t)return void console.error(`SetDataValue: Unknown member ${t}`);n=3;}if(!(r instanceof Be))return void console.error('SetDataValue: Invalid value',r);const s=r.value;return 'vec2f'===e?void(new Float32Array(this.buffer,o,2)[n]=s):'vec3f'===e?void(new Float32Array(this.buffer,o,3)[n]=s):'vec4f'===e?void(new Float32Array(this.buffer,o,4)[n]=s):'vec2i'===e?void(new Int32Array(this.buffer,o,2)[n]=s):'vec3i'===e?void(new Int32Array(this.buffer,o,3)[n]=s):'vec4i'===e?void(new Int32Array(this.buffer,o,4)[n]=s):'vec2u'===e?void(new Uint32Array(this.buffer,o,2)[n]=s):'vec3u'===e?void(new Uint32Array(this.buffer,o,3)[n]=s):'vec4u'===e?void(new Uint32Array(this.buffer,o,4)[n]=s):void console.error(`SetDataValue: Type ${e} is not a struct`)}}}a=a.postfix;}this.setData(t,r,c,o,i);}setData(e,t,n,s,r){const a=n.getTypeName();if('f32'!==a&&'f16'!==a)if('i32'!==a&&'atomic<i32>'!==a&&'x32'!==a)if('u32'!==a&&'atomic<u32>'!==a)if('bool'!==a){if('vec2f'===a||'vec2h'===a){const e=new Float32Array(this.buffer,s,2);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if('vec3f'===a||'vec3h'===a){const e=new Float32Array(this.buffer,s,3);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if('vec4f'===a||'vec4h'===a){const e=new Float32Array(this.buffer,s,4);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if('vec2i'===a){const e=new Int32Array(this.buffer,s,2);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if('vec3i'===a){const e=new Int32Array(this.buffer,s,3);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if('vec4i'===a){const e=new Int32Array(this.buffer,s,4);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if('vec2u'===a){const e=new Uint32Array(this.buffer,s,2);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if('vec3u'===a){const e=new Uint32Array(this.buffer,s,3);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if('vec4u'===a){const e=new Uint32Array(this.buffer,s,4);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if('vec2b'===a){const e=new Uint32Array(this.buffer,s,2);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if('vec3b'===a){const e=new Uint32Array(this.buffer,s,3);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if('vec4b'===a){const e=new Uint32Array(this.buffer,s,4);return void(t instanceof Me?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if('mat2x2f'===a||'mat2x2h'===a){const e=new Float32Array(this.buffer,s,4);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if('mat2x3f'===a||'mat2x3h'===a){const e=new Float32Array(this.buffer,s,6);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5]))}if('mat2x4f'===a||'mat2x4h'===a){const e=new Float32Array(this.buffer,s,8);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7]))}if('mat3x2f'===a||'mat3x2h'===a){const e=new Float32Array(this.buffer,s,6);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5]))}if('mat3x3f'===a||'mat3x3h'===a){const e=new Float32Array(this.buffer,s,9);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8]))}if('mat3x4f'===a||'mat3x4h'===a){const e=new Float32Array(this.buffer,s,12);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11]))}if('mat4x2f'===a||'mat4x2h'===a){const e=new Float32Array(this.buffer,s,8);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7]))}if('mat4x3f'===a||'mat4x3h'===a){const e=new Float32Array(this.buffer,s,12);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11]))}if('mat4x4f'===a||'mat4x4h'===a){const e=new Float32Array(this.buffer,s,16);return void(t instanceof Ue?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11],e[12]=t.data[12],e[13]=t.data[13],e[14]=t.data[14],e[15]=t.data[15]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]))}if(t instanceof Pe){if(n===t.typeInfo){return void new Uint8Array(this.buffer,s,t.buffer.byteLength).set(new Uint8Array(t.buffer))}console.error('SetDataValue: Type mismatch',a,t.typeInfo.getTypeName());}else console.error(`SetData: Unknown type ${a}`);}else t instanceof Be&&(new Int32Array(this.buffer,s,1)[0]=t.value);else t instanceof Be&&(new Uint32Array(this.buffer,s,1)[0]=t.value);else t instanceof Be&&(new Int32Array(this.buffer,s,1)[0]=t.value);else t instanceof Be&&(new Float32Array(this.buffer,s,1)[0]=t.value);}getSubData(t,r,i){var o,c,l;if(null===r)return this;let u=this.offset,h=this.typeInfo;for(;r;){if(r instanceof ve){const e=r.index,n=e instanceof fe?t.evalExpression(e,i):e;let a=0;if(n instanceof Be?a=n.value:'number'==typeof n?a=n:console.error('GetDataValue: Invalid index type',e),h instanceof s)u+=a*h.stride,h=h.format;else {const e=h.getTypeName();'mat4x4'===e||'mat4x4f'===e||'mat4x4h'===e?(u+=16*a,h=t.getTypeInfo('vec4f')):console.error(`getDataValue: Type ${h.getTypeName()} is not an array`);}}else {if(!(r instanceof pe))return console.error('GetDataValue: Unknown postfix type',r),null;{const s=r.value;if(h instanceof n){let e=!1;for(const t of h.members)if(t.name===s){u+=t.offset,h=t.type,e=!0;break}if(!e)return console.error(`GetDataValue: Member ${s} not found`),null}else if(h instanceof e){const e=h.getTypeName();if('vec2f'===e||'vec3f'===e||'vec4f'===e||'vec2i'===e||'vec3i'===e||'vec4i'===e||'vec2u'===e||'vec3u'===e||'vec4u'===e||'vec2b'===e||'vec3b'===e||'vec4b'===e||'vec2h'===e||'vec3h'===e||'vec4h'===e||'vec2'===e||'vec3'===e||'vec4'===e){if(s.length>0&&s.length<5){let n='f';const r=[];for(let a=0;a<s.length;++a){const i=s[a].toLowerCase();let o=0;if('x'===i||'r'===i)o=0;else if('y'===i||'g'===i)o=1;else if('z'===i||'b'===i)o=2;else {if('w'!==i&&'a'!==i)return console.error(`Unknown member ${s}`),null;o=3;}if(1===s.length){if(e.endsWith('f'))return this.buffer.byteLength<u+4*o+4?(console.log('Insufficient buffer data'),null):new Be(new Float32Array(this.buffer,u+4*o,1),t.getTypeInfo('f32'),this);if(e.endsWith('h'))return new Be(new Float32Array(this.buffer,u+4*o,1),t.getTypeInfo('f16'),this);if(e.endsWith('i'))return new Be(new Int32Array(this.buffer,u+4*o,1),t.getTypeInfo('i32'),this);if(e.endsWith('b'))return new Be(new Int32Array(this.buffer,u+4*o,1),t.getTypeInfo('bool'),this);if(e.endsWith('u'))return new Be(new Uint32Array(this.buffer,u+4*o,1),t.getTypeInfo('i32'),this)}if('vec2f'===e)r.push(new Float32Array(this.buffer,u,2)[o]);else if('vec3f'===e){if(u+12>=this.buffer.byteLength)return console.log('Insufficient buffer data'),null;const e=new Float32Array(this.buffer,u,3);r.push(e[o]);}else if('vec4f'===e)r.push(new Float32Array(this.buffer,u,4)[o]);else if('vec2i'===e)n='i',r.push(new Int32Array(this.buffer,u,2)[o]);else if('vec3i'===e)n='i',r.push(new Int32Array(this.buffer,u,3)[o]);else if('vec4i'===e)n='i',r.push(new Int32Array(this.buffer,u,4)[o]);else if('vec2u'===e){n='u';const e=new Uint32Array(this.buffer,u,2);r.push(e[o]);}else 'vec3u'===e?(n='u',r.push(new Uint32Array(this.buffer,u,3)[o])):'vec4u'===e&&(n='u',r.push(new Uint32Array(this.buffer,u,4)[o]));}return 2===r.length?h=t.getTypeInfo(`vec2${n}`):3===r.length?h=t.getTypeInfo(`vec3${n}`):4===r.length?h=t.getTypeInfo(`vec4${n}`):console.error(`GetDataValue: Invalid vector length ${r.length}`),new Me(r,h,null)}return console.error(`GetDataValue: Unknown member ${s}`),null}return console.error(`GetDataValue: Type ${e} is not a struct`),null}}}r=r.postfix;}const f=h.getTypeName();return 'f32'===f?new Be(new Float32Array(this.buffer,u,1),h,this):'i32'===f?new Be(new Int32Array(this.buffer,u,1),h,this):'u32'===f?new Be(new Uint32Array(this.buffer,u,1),h,this):'vec2f'===f?new Me(new Float32Array(this.buffer,u,2),h,this):'vec3f'===f?new Me(new Float32Array(this.buffer,u,3),h,this):'vec4f'===f?new Me(new Float32Array(this.buffer,u,4),h,this):'vec2i'===f?new Me(new Int32Array(this.buffer,u,2),h,this):'vec3i'===f?new Me(new Int32Array(this.buffer,u,3),h,this):'vec4i'===f?new Me(new Int32Array(this.buffer,u,4),h,this):'vec2u'===f?new Me(new Uint32Array(this.buffer,u,2),h,this):'vec3u'===f?new Me(new Uint32Array(this.buffer,u,3),h,this):'vec4u'===f?new Me(new Uint32Array(this.buffer,u,4),h,this):h instanceof a&&'atomic'===h.name?'u32'===(null===(o=h.format)||void 0===o?void 0:o.name)?new Be(new Uint32Array(this.buffer,u,1)[0],h.format,this):'i32'===(null===(c=h.format)||void 0===c?void 0:c.name)?new Be(new Int32Array(this.buffer,u,1)[0],h.format,this):(console.error(`GetDataValue: Invalid atomic format ${null===(l=h.format)||void 0===l?void 0:l.name}`),null):new Pe(this.buffer,h,u,this)}toString(){let e='';if(this.typeInfo instanceof s)if('f32'===this.typeInfo.format.name){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`;}else if('i32'===this.typeInfo.format.name){const t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`;}else if('u32'===this.typeInfo.format.name){const t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`;}else if('vec2f'===this.typeInfo.format.name){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`;}else if('vec3f'===this.typeInfo.format.name){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`;}else if('vec4f'===this.typeInfo.format.name){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`;}else e='[...]';else this.typeInfo instanceof n?e+='{...}':e='[...]';return e}}class We extends Ne{constructor(e,t,n,s){super(t,null),this.data=e,this.descriptor=n,this.view=s;}clone(){return new We(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>0?null!==(e=n[0])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.width)&&void 0!==t?t:0}get height(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>1?null!==(e=n[1])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.height)&&void 0!==t?t:0}get depthOrArrayLayers(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>2?null!==(e=n[2])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.depthOrArrayLayers)&&void 0!==t?t:0}get format(){var e;return this.descriptor&&null!==(e=this.descriptor.format)&&void 0!==e?e:'rgba8unorm'}get sampleCount(){var e;return this.descriptor&&null!==(e=this.descriptor.sampleCount)&&void 0!==e?e:1}get mipLevelCount(){var e;return this.descriptor&&null!==(e=this.descriptor.mipLevelCount)&&void 0!==e?e:1}get dimension(){var e;return this.descriptor&&null!==(e=this.descriptor.dimension)&&void 0!==e?e:'2d'}getMipLevelSize(e){if(e>=this.mipLevelCount)return [0,0,0];const t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){const e=this.format,t=S[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=S[e];return !!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=S[e],n=this.width;if(!e||n<=0||!t)return -1;const s=this.height,r=this.depthOrArrayLayers,a=this.dimension;return n/t.blockWidth*('1d'===a?1:s/t.blockHeight)*t.bytesPerBlock*r}getPixel(e,t,n=0,s=0){const r=this.texelByteSize,a=this.bytesPerRow,i=this.height,o=this.data[s];return k(new Uint8Array(o),e,t,n,s,i,a,r,this.format)}setPixel(e,t,n,s,r){const a=this.texelByteSize,i=this.bytesPerRow,o=this.height,c=this.data[s];!function(e,t,n,s,r,a,i,o,c,l){const u=s*(i>>=r)*(a>>=r)+n*i+t*o;switch(c){case'r8unorm':return void T(e,u,'8unorm',1,l);case'r8snorm':return void T(e,u,'8snorm',1,l);case'r8uint':return void T(e,u,'8uint',1,l);case'r8sint':return void T(e,u,'8sint',1,l);case'rg8unorm':return void T(e,u,'8unorm',2,l);case'rg8snorm':return void T(e,u,'8snorm',2,l);case'rg8uint':return void T(e,u,'8uint',2,l);case'rg8sint':return void T(e,u,'8sint',2,l);case'rgba8unorm-srgb':case'rgba8unorm':case'bgra8unorm-srgb':case'bgra8unorm':return void T(e,u,'8unorm',4,l);case'rgba8snorm':return void T(e,u,'8snorm',4,l);case'rgba8uint':return void T(e,u,'8uint',4,l);case'rgba8sint':return void T(e,u,'8sint',4,l);case'r16uint':return void T(e,u,'16uint',1,l);case'r16sint':return void T(e,u,'16sint',1,l);case'r16float':return void T(e,u,'16float',1,l);case'rg16uint':return void T(e,u,'16uint',2,l);case'rg16sint':return void T(e,u,'16sint',2,l);case'rg16float':return void T(e,u,'16float',2,l);case'rgba16uint':return void T(e,u,'16uint',4,l);case'rgba16sint':return void T(e,u,'16sint',4,l);case'rgba16float':return void T(e,u,'16float',4,l);case'r32uint':return void T(e,u,'32uint',1,l);case'r32sint':return void T(e,u,'32sint',1,l);case'depth16unorm':case'depth24plus':case'depth24plus-stencil8':case'depth32float':case'depth32float-stencil8':case'r32float':return void T(e,u,'32float',1,l);case'rg32uint':return void T(e,u,'32uint',2,l);case'rg32sint':return void T(e,u,'32sint',2,l);case'rg32float':return void T(e,u,'32float',2,l);case'rgba32uint':return void T(e,u,'32uint',4,l);case'rgba32sint':return void T(e,u,'32sint',4,l);case'rgba32float':return void T(e,u,'32float',4,l);case'rg11b10ufloat':console.error('TODO: rg11b10ufloat not supported for writing');}}(new Uint8Array(c),e,t,n,s,o,i,a,this.format,r);}}(e=>{e[e.token=0]='token',e[e.keyword=1]='keyword',e[e.reserved=2]='reserved';})(z||(z={}));class qe{constructor(e,t,n){this.name=e,this.type=t,this.rule=n;}toString(){return this.name}}class He{}H=He,He.none=new qe('',z.reserved,''),He.eof=new qe('EOF',z.token,''),He.reserved={asm:new qe('asm',z.reserved,'asm'),bf16:new qe('bf16',z.reserved,'bf16'),do:new qe('do',z.reserved,'do'),enum:new qe('enum',z.reserved,'enum'),f16:new qe('f16',z.reserved,'f16'),f64:new qe('f64',z.reserved,'f64'),handle:new qe('handle',z.reserved,'handle'),i8:new qe('i8',z.reserved,'i8'),i16:new qe('i16',z.reserved,'i16'),i64:new qe('i64',z.reserved,'i64'),mat:new qe('mat',z.reserved,'mat'),premerge:new qe('premerge',z.reserved,'premerge'),regardless:new qe('regardless',z.reserved,'regardless'),typedef:new qe('typedef',z.reserved,'typedef'),u8:new qe('u8',z.reserved,'u8'),u16:new qe('u16',z.reserved,'u16'),u64:new qe('u64',z.reserved,'u64'),unless:new qe('unless',z.reserved,'unless'),using:new qe('using',z.reserved,'using'),vec:new qe('vec',z.reserved,'vec'),void:new qe('void',z.reserved,'void')},He.keywords={array:new qe('array',z.keyword,'array'),atomic:new qe('atomic',z.keyword,'atomic'),bool:new qe('bool',z.keyword,'bool'),f32:new qe('f32',z.keyword,'f32'),i32:new qe('i32',z.keyword,'i32'),mat2x2:new qe('mat2x2',z.keyword,'mat2x2'),mat2x3:new qe('mat2x3',z.keyword,'mat2x3'),mat2x4:new qe('mat2x4',z.keyword,'mat2x4'),mat3x2:new qe('mat3x2',z.keyword,'mat3x2'),mat3x3:new qe('mat3x3',z.keyword,'mat3x3'),mat3x4:new qe('mat3x4',z.keyword,'mat3x4'),mat4x2:new qe('mat4x2',z.keyword,'mat4x2'),mat4x3:new qe('mat4x3',z.keyword,'mat4x3'),mat4x4:new qe('mat4x4',z.keyword,'mat4x4'),ptr:new qe('ptr',z.keyword,'ptr'),sampler:new qe('sampler',z.keyword,'sampler'),sampler_comparison:new qe('sampler_comparison',z.keyword,'sampler_comparison'),struct:new qe('struct',z.keyword,'struct'),texture_1d:new qe('texture_1d',z.keyword,'texture_1d'),texture_2d:new qe('texture_2d',z.keyword,'texture_2d'),texture_2d_array:new qe('texture_2d_array',z.keyword,'texture_2d_array'),texture_3d:new qe('texture_3d',z.keyword,'texture_3d'),texture_cube:new qe('texture_cube',z.keyword,'texture_cube'),texture_cube_array:new qe('texture_cube_array',z.keyword,'texture_cube_array'),texture_multisampled_2d:new qe('texture_multisampled_2d',z.keyword,'texture_multisampled_2d'),texture_storage_1d:new qe('texture_storage_1d',z.keyword,'texture_storage_1d'),texture_storage_2d:new qe('texture_storage_2d',z.keyword,'texture_storage_2d'),texture_storage_2d_array:new qe('texture_storage_2d_array',z.keyword,'texture_storage_2d_array'),texture_storage_3d:new qe('texture_storage_3d',z.keyword,'texture_storage_3d'),texture_depth_2d:new qe('texture_depth_2d',z.keyword,'texture_depth_2d'),texture_depth_2d_array:new qe('texture_depth_2d_array',z.keyword,'texture_depth_2d_array'),texture_depth_cube:new qe('texture_depth_cube',z.keyword,'texture_depth_cube'),texture_depth_cube_array:new qe('texture_depth_cube_array',z.keyword,'texture_depth_cube_array'),texture_depth_multisampled_2d:new qe('texture_depth_multisampled_2d',z.keyword,'texture_depth_multisampled_2d'),texture_external:new qe('texture_external',z.keyword,'texture_external'),u32:new qe('u32',z.keyword,'u32'),vec2:new qe('vec2',z.keyword,'vec2'),vec3:new qe('vec3',z.keyword,'vec3'),vec4:new qe('vec4',z.keyword,'vec4'),bitcast:new qe('bitcast',z.keyword,'bitcast'),block:new qe('block',z.keyword,'block'),break:new qe('break',z.keyword,'break'),case:new qe('case',z.keyword,'case'),continue:new qe('continue',z.keyword,'continue'),continuing:new qe('continuing',z.keyword,'continuing'),default:new qe('default',z.keyword,'default'),diagnostic:new qe('diagnostic',z.keyword,'diagnostic'),discard:new qe('discard',z.keyword,'discard'),else:new qe('else',z.keyword,'else'),enable:new qe('enable',z.keyword,'enable'),fallthrough:new qe('fallthrough',z.keyword,'fallthrough'),false:new qe('false',z.keyword,'false'),fn:new qe('fn',z.keyword,'fn'),for:new qe('for',z.keyword,'for'),function:new qe('function',z.keyword,'function'),if:new qe('if',z.keyword,'if'),let:new qe('let',z.keyword,'let'),const:new qe('const',z.keyword,'const'),loop:new qe('loop',z.keyword,'loop'),while:new qe('while',z.keyword,'while'),private:new qe('private',z.keyword,'private'),read:new qe('read',z.keyword,'read'),read_write:new qe('read_write',z.keyword,'read_write'),return:new qe('return',z.keyword,'return'),requires:new qe('requires',z.keyword,'requires'),storage:new qe('storage',z.keyword,'storage'),switch:new qe('switch',z.keyword,'switch'),true:new qe('true',z.keyword,'true'),alias:new qe('alias',z.keyword,'alias'),type:new qe('type',z.keyword,'type'),uniform:new qe('uniform',z.keyword,'uniform'),var:new qe('var',z.keyword,'var'),override:new qe('override',z.keyword,'override'),workgroup:new qe('workgroup',z.keyword,'workgroup'),write:new qe('write',z.keyword,'write'),r8unorm:new qe('r8unorm',z.keyword,'r8unorm'),r8snorm:new qe('r8snorm',z.keyword,'r8snorm'),r8uint:new qe('r8uint',z.keyword,'r8uint'),r8sint:new qe('r8sint',z.keyword,'r8sint'),r16uint:new qe('r16uint',z.keyword,'r16uint'),r16sint:new qe('r16sint',z.keyword,'r16sint'),r16float:new qe('r16float',z.keyword,'r16float'),rg8unorm:new qe('rg8unorm',z.keyword,'rg8unorm'),rg8snorm:new qe('rg8snorm',z.keyword,'rg8snorm'),rg8uint:new qe('rg8uint',z.keyword,'rg8uint'),rg8sint:new qe('rg8sint',z.keyword,'rg8sint'),r32uint:new qe('r32uint',z.keyword,'r32uint'),r32sint:new qe('r32sint',z.keyword,'r32sint'),r32float:new qe('r32float',z.keyword,'r32float'),rg16uint:new qe('rg16uint',z.keyword,'rg16uint'),rg16sint:new qe('rg16sint',z.keyword,'rg16sint'),rg16float:new qe('rg16float',z.keyword,'rg16float'),rgba8unorm:new qe('rgba8unorm',z.keyword,'rgba8unorm'),rgba8unorm_srgb:new qe('rgba8unorm_srgb',z.keyword,'rgba8unorm_srgb'),rgba8snorm:new qe('rgba8snorm',z.keyword,'rgba8snorm'),rgba8uint:new qe('rgba8uint',z.keyword,'rgba8uint'),rgba8sint:new qe('rgba8sint',z.keyword,'rgba8sint'),bgra8unorm:new qe('bgra8unorm',z.keyword,'bgra8unorm'),bgra8unorm_srgb:new qe('bgra8unorm_srgb',z.keyword,'bgra8unorm_srgb'),rgb10a2unorm:new qe('rgb10a2unorm',z.keyword,'rgb10a2unorm'),rg11b10float:new qe('rg11b10float',z.keyword,'rg11b10float'),rg32uint:new qe('rg32uint',z.keyword,'rg32uint'),rg32sint:new qe('rg32sint',z.keyword,'rg32sint'),rg32float:new qe('rg32float',z.keyword,'rg32float'),rgba16uint:new qe('rgba16uint',z.keyword,'rgba16uint'),rgba16sint:new qe('rgba16sint',z.keyword,'rgba16sint'),rgba16float:new qe('rgba16float',z.keyword,'rgba16float'),rgba32uint:new qe('rgba32uint',z.keyword,'rgba32uint'),rgba32sint:new qe('rgba32sint',z.keyword,'rgba32sint'),rgba32float:new qe('rgba32float',z.keyword,'rgba32float'),static_assert:new qe('static_assert',z.keyword,'static_assert')},He.tokens={decimal_float_literal:new qe('decimal_float_literal',z.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new qe('hex_float_literal',z.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new qe('int_literal',z.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new qe('uint_literal',z.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new qe('name',z.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new qe('ident',z.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new qe('and',z.token,'&'),and_and:new qe('and_and',z.token,'&&'),arrow:new qe('arrow ',z.token,'->'),attr:new qe('attr',z.token,'@'),forward_slash:new qe('forward_slash',z.token,'/'),bang:new qe('bang',z.token,'!'),bracket_left:new qe('bracket_left',z.token,'['),bracket_right:new qe('bracket_right',z.token,']'),brace_left:new qe('brace_left',z.token,'{'),brace_right:new qe('brace_right',z.token,'}'),colon:new qe('colon',z.token,':'),comma:new qe('comma',z.token,','),equal:new qe('equal',z.token,'='),equal_equal:new qe('equal_equal',z.token,'=='),not_equal:new qe('not_equal',z.token,'!='),greater_than:new qe('greater_than',z.token,'>'),greater_than_equal:new qe('greater_than_equal',z.token,'>='),shift_right:new qe('shift_right',z.token,'>>'),less_than:new qe('less_than',z.token,'<'),less_than_equal:new qe('less_than_equal',z.token,'<='),shift_left:new qe('shift_left',z.token,'<<'),modulo:new qe('modulo',z.token,'%'),minus:new qe('minus',z.token,'-'),minus_minus:new qe('minus_minus',z.token,'--'),period:new qe('period',z.token,'.'),plus:new qe('plus',z.token,'+'),plus_plus:new qe('plus_plus',z.token,'++'),or:new qe('or',z.token,'|'),or_or:new qe('or_or',z.token,'||'),paren_left:new qe('paren_left',z.token,'('),paren_right:new qe('paren_right',z.token,')'),semicolon:new qe('semicolon',z.token,';'),star:new qe('star',z.token,'*'),tilde:new qe('tilde',z.token,'~'),underscore:new qe('underscore',z.token,'_'),xor:new qe('xor',z.token,'^'),plus_equal:new qe('plus_equal',z.token,'+='),minus_equal:new qe('minus_equal',z.token,'-='),times_equal:new qe('times_equal',z.token,'*='),division_equal:new qe('division_equal',z.token,'/='),modulo_equal:new qe('modulo_equal',z.token,'%='),and_equal:new qe('and_equal',z.token,'&='),or_equal:new qe('or_equal',z.token,'|='),xor_equal:new qe('xor_equal',z.token,'^='),shift_right_equal:new qe('shift_right_equal',z.token,'>>='),shift_left_equal:new qe('shift_left_equal',z.token,'<<=')},He.simpleTokens={'@':H.tokens.attr,'{':H.tokens.brace_left,'}':H.tokens.brace_right,':':H.tokens.colon,',':H.tokens.comma,'(':H.tokens.paren_left,')':H.tokens.paren_right,';':H.tokens.semicolon},He.literalTokens={'&':H.tokens.and,'&&':H.tokens.and_and,'->':H.tokens.arrow,'/':H.tokens.forward_slash,'!':H.tokens.bang,'[':H.tokens.bracket_left,']':H.tokens.bracket_right,'=':H.tokens.equal,'==':H.tokens.equal_equal,'!=':H.tokens.not_equal,'>':H.tokens.greater_than,'>=':H.tokens.greater_than_equal,'>>':H.tokens.shift_right,'<':H.tokens.less_than,'<=':H.tokens.less_than_equal,'<<':H.tokens.shift_left,'%':H.tokens.modulo,'-':H.tokens.minus,'--':H.tokens.minus_minus,'.':H.tokens.period,'+':H.tokens.plus,'++':H.tokens.plus_plus,'|':H.tokens.or,'||':H.tokens.or_or,'*':H.tokens.star,'~':H.tokens.tilde,_:H.tokens.underscore,'^':H.tokens.xor,'+=':H.tokens.plus_equal,'-=':H.tokens.minus_equal,'*=':H.tokens.times_equal,'/=':H.tokens.division_equal,'%=':H.tokens.modulo_equal,'&=':H.tokens.and_equal,'|=':H.tokens.or_equal,'^=':H.tokens.xor_equal,'>>=':H.tokens.shift_right_equal,'<<=':H.tokens.shift_left_equal},He.regexTokens={decimal_float_literal:H.tokens.decimal_float_literal,hex_float_literal:H.tokens.hex_float_literal,int_literal:H.tokens.int_literal,uint_literal:H.tokens.uint_literal,ident:H.tokens.ident},He.storage_class=[H.keywords.function,H.keywords.private,H.keywords.workgroup,H.keywords.uniform,H.keywords.storage],He.access_mode=[H.keywords.read,H.keywords.write,H.keywords.read_write],He.sampler_type=[H.keywords.sampler,H.keywords.sampler_comparison],He.sampled_texture_type=[H.keywords.texture_1d,H.keywords.texture_2d,H.keywords.texture_2d_array,H.keywords.texture_3d,H.keywords.texture_cube,H.keywords.texture_cube_array],He.multisampled_texture_type=[H.keywords.texture_multisampled_2d],He.storage_texture_type=[H.keywords.texture_storage_1d,H.keywords.texture_storage_2d,H.keywords.texture_storage_2d_array,H.keywords.texture_storage_3d],He.depth_texture_type=[H.keywords.texture_depth_2d,H.keywords.texture_depth_2d_array,H.keywords.texture_depth_cube,H.keywords.texture_depth_cube_array,H.keywords.texture_depth_multisampled_2d],He.texture_external_type=[H.keywords.texture_external],He.any_texture_type=[...H.sampled_texture_type,...H.multisampled_texture_type,...H.storage_texture_type,...H.depth_texture_type,...H.texture_external_type],He.texel_format=[H.keywords.r8unorm,H.keywords.r8snorm,H.keywords.r8uint,H.keywords.r8sint,H.keywords.r16uint,H.keywords.r16sint,H.keywords.r16float,H.keywords.rg8unorm,H.keywords.rg8snorm,H.keywords.rg8uint,H.keywords.rg8sint,H.keywords.r32uint,H.keywords.r32sint,H.keywords.r32float,H.keywords.rg16uint,H.keywords.rg16sint,H.keywords.rg16float,H.keywords.rgba8unorm,H.keywords.rgba8unorm_srgb,H.keywords.rgba8snorm,H.keywords.rgba8uint,H.keywords.rgba8sint,H.keywords.bgra8unorm,H.keywords.bgra8unorm_srgb,H.keywords.rgb10a2unorm,H.keywords.rg11b10float,H.keywords.rg32uint,H.keywords.rg32sint,H.keywords.rg32float,H.keywords.rgba16uint,H.keywords.rgba16sint,H.keywords.rgba16float,H.keywords.rgba32uint,H.keywords.rgba32sint,H.keywords.rgba32float],He.const_literal=[H.tokens.int_literal,H.tokens.uint_literal,H.tokens.decimal_float_literal,H.tokens.hex_float_literal,H.keywords.true,H.keywords.false],He.literal_or_ident=[H.tokens.ident,H.tokens.int_literal,H.tokens.uint_literal,H.tokens.decimal_float_literal,H.tokens.hex_float_literal,H.tokens.name],He.element_count_expression=[H.tokens.int_literal,H.tokens.uint_literal,H.tokens.ident],He.template_types=[H.keywords.vec2,H.keywords.vec3,H.keywords.vec4,H.keywords.mat2x2,H.keywords.mat2x3,H.keywords.mat2x4,H.keywords.mat3x2,H.keywords.mat3x3,H.keywords.mat3x4,H.keywords.mat4x2,H.keywords.mat4x3,H.keywords.mat4x4,H.keywords.atomic,H.keywords.bitcast,...H.any_texture_type],He.attribute_name=[H.tokens.ident,H.keywords.block,H.keywords.diagnostic],He.assignment_operators=[H.tokens.equal,H.tokens.plus_equal,H.tokens.minus_equal,H.tokens.times_equal,H.tokens.division_equal,H.tokens.modulo_equal,H.tokens.and_equal,H.tokens.or_equal,H.tokens.xor_equal,H.tokens.shift_right_equal,H.tokens.shift_left_equal],He.increment_operators=[H.tokens.plus_plus,H.tokens.minus_minus];class ze{constructor(e,t,n,s,r){this.type=e,this.lexeme=t,this.line=n,this.start=s,this.end=r;}toString(){return this.lexeme}isTemplateType(){return -1!=He.template_types.indexOf(this.type)}isArrayType(){return this.type==He.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class Re{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=null!=e?e:'';}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw `Invalid syntax at line ${this._line}`;return this._tokens.push(new ze(He.eof,'',this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if('\n'==e)return this._line++,!0;if(this._isWhitespace(e))return !0;if('/'==e){if('/'==this._peekAhead()){for(;'\n'!=e;){if(this._isAtEnd())return !0;e=this._advance();}return this._line++,!0}if('*'==this._peekAhead()){this._advance();let t=1;for(;t>0;){if(this._isAtEnd())return !0;if(e=this._advance(),'\n'==e)this._line++;else if('*'==e){if('/'==this._peekAhead()&&(this._advance(),t--,0==t))return !0}else '/'==e&&'*'==this._peekAhead()&&(this._advance(),t++);}return !0}}const t=He.simpleTokens[e];if(t)return this._addToken(t),!0;let n=He.none;const s=this._isAlpha(e),r='_'===e;if(this._isAlphaNumeric(e)){let t=this._peekAhead();for(;this._isAlphaNumeric(t);)e+=this._advance(),t=this._peekAhead();}if(s){const t=He.keywords[e];if(t)return this._addToken(t),!0}if(s||r)return this._addToken(He.tokens.ident),!0;for(;;){let t=this._findType(e);const s=this._peekAhead();if('-'==e&&this._tokens.length>0){if('='==s)return this._current++,e+=s,this._addToken(He.tokens.minus_equal),!0;if('-'==s)return this._current++,e+=s,this._addToken(He.tokens.minus_minus),!0;const n=this._tokens.length-1;if((-1!=He.literal_or_ident.indexOf(this._tokens[n].type)||this._tokens[n].type==He.tokens.paren_right)&&'>'!=s)return this._addToken(t),!0}if('>'==e&&('>'==s||'='==s)){let e=!1,n=this._tokens.length-1;for(let t=0;t<5&&n>=0&&-1===He.assignment_operators.indexOf(this._tokens[n].type);++t,--n)if(this._tokens[n].type===He.tokens.less_than){n>0&&this._tokens[n-1].isArrayOrTemplateType()&&(e=!0);break}if(e)return this._addToken(t),!0}if(t===He.none){let s=e,r=0;const a=2;for(let e=0;e<a;++e)if(s+=this._peekAhead(e),t=this._findType(s),t!==He.none){r=e;break}if(t===He.none)return n!==He.none&&(this._current--,this._addToken(n),!0);e=s,this._current+=r+1;}if(n=t,this._isAtEnd())break;e+=this._advance();}return n!==He.none&&(this._addToken(n),!0)}_findType(e){for(const t in He.regexTokens){const n=He.regexTokens[t];if(this._match(e,n.rule))return n}const t=He.literalTokens[e];return t||He.none}_match(e,t){const n=t.exec(e);return n&&0==n.index&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return !this._isNumeric(e)&&!this._isWhitespace(e)&&'_'!==e&&'.'!==e&&'('!==e&&')'!==e&&'['!==e&&']'!==e&&'{'!==e&&'}'!==e&&','!==e&&';'!==e&&':'!==e&&'='!==e&&'!'!==e&&'<'!==e&&'>'!==e&&'+'!==e&&'-'!==e&&'*'!==e&&'/'!==e&&'%'!==e&&'&'!==e&&'|'!==e&&'^'!==e&&'~'!==e&&'@'!==e&&'#'!==e&&'?'!==e&&'\''!==e&&'`'!==e&&'"'!==e&&'\\'!==e&&'\n'!==e&&'\r'!==e&&'\t'!==e&&'\0'!==e}_isNumeric(e){return e>='0'&&e<='9'}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||'_'===e}_isWhitespace(e){return ' '==e||'\t'==e||'\r'==e}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?'\0':this._source[this._current+e]}_addToken(e){const t=this._source.substring(this._start,this._current);this._tokens.push(new ze(e,t,this._line,this._start,this._current));}}function Ge(e){return Array.isArray(e)||(null==e?void 0:e.buffer)instanceof ArrayBuffer}const Xe=new Float32Array(1),je=new Uint32Array(Xe.buffer),Ze=new Uint32Array(Xe.buffer),Qe=new Int32Array(1),Ye=new Float32Array(Qe.buffer),Ke=new Uint32Array(Qe.buffer),Je=new Uint32Array(1),et=new Float32Array(Je.buffer),tt=new Int32Array(Je.buffer);function nt(e,t,n){if(t===n)return e;if('f32'===t){if('i32'===n||'x32'===n)return Xe[0]=e,je[0];if('u32'===n)return Xe[0]=e,Ze[0]}else if('i32'===t||'x32'===t){if('f32'===n)return Qe[0]=e,Ye[0];if('u32'===n)return Qe[0]=e,Ke[0]}else if('u32'===t){if('f32'===n)return Je[0]=e,et[0];if('i32'===n||'x32'===n)return Je[0]=e,tt[0]}return console.error(`Unsupported cast from ${t} to ${n}`),e}class st{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e;}}class rt{constructor(e,t){this.align=e,this.size=t;}}class at{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new d,this.functions=[],this._types=new Map,this._functions=new Map;}_isStorageTexture(e){return 'texture_storage_1d'==e.name||'texture_storage_2d'==e.name||'texture_storage_2d_array'==e.name||'texture_storage_3d'==e.name}updateAST(e){for(const t of e)t instanceof D&&this._functions.set(t.name,new st(t));for(const t of e)if(t instanceof oe){const e=this.getTypeInfo(t,null);e instanceof n&&this.structs.push(e);}for(const t of e)if(t instanceof te)this.aliases.push(this._getAliasInfo(t));else {if(t instanceof M){const e=t,n=this._getAttributeNum(e.attributes,'id',0),s=null!=e.type?this.getTypeInfo(e.type,e.attributes):null;this.overrides.push(new h(e.name,s,e.attributes,n));continue}if(this._isUniformVar(t)){const e=t,n=this._getAttributeNum(e.attributes,'group',0),s=this._getAttributeNum(e.attributes,'binding',0),r=this.getTypeInfo(e.type,e.attributes),a=new o(e.name,r,n,s,e.attributes,i.Uniform,e.access);a.access||(a.access='read'),this.uniforms.push(a);continue}if(this._isStorageVar(t)){const e=t,n=this._getAttributeNum(e.attributes,'group',0),s=this._getAttributeNum(e.attributes,'binding',0),r=this.getTypeInfo(e.type,e.attributes),a=this._isStorageTexture(r),c=new o(e.name,r,n,s,e.attributes,a?i.StorageTexture:i.Storage,e.access);c.access||(c.access='read'),this.storage.push(c);continue}if(this._isTextureVar(t)){const e=t,n=this._getAttributeNum(e.attributes,'group',0),s=this._getAttributeNum(e.attributes,'binding',0),r=this.getTypeInfo(e.type,e.attributes),a=this._isStorageTexture(r),c=new o(e.name,r,n,s,e.attributes,a?i.StorageTexture:i.Texture,e.access);c.access||(c.access='read'),a?this.storage.push(c):this.textures.push(c);continue}if(this._isSamplerVar(t)){const e=t,n=this._getAttributeNum(e.attributes,'group',0),s=this._getAttributeNum(e.attributes,'binding',0),r=this.getTypeInfo(e.type,e.attributes),a=new o(e.name,r,n,s,e.attributes,i.Sampler,e.access);this.samplers.push(a);continue}}for(const t of e)if(t instanceof D){const e=this._getAttribute(t,'vertex'),n=this._getAttribute(t,'fragment'),s=this._getAttribute(t,'compute'),r=e||n||s,a=new p(t.name,null==r?void 0:r.name,t.attributes);a.attributes=t.attributes,a.startLine=t.startLine,a.endLine=t.endLine,this.functions.push(a),this._functions.get(t.name).info=a,r&&(this._functions.get(t.name).inUse=!0,a.inUse=!0,a.resources=this._findResources(t,!!r),a.inputs=this._getInputs(t.args),a.outputs=this._getOutputs(t.returnType),this.entry[r.name].push(a)),a.arguments=t.args.map(e=>new f(e.name,this.getTypeInfo(e.type,e.attributes),e.attributes)),a.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}for(const e of this._functions.values())e.info&&(e.info.inUse=e.inUse,this._addCalls(e.node,e.info.calls));for(const e of this._functions.values())e.node.search(t=>{var n,s,r;if(t instanceof De){if(t.value)if(Ge(t.value))for(const s of t.value)for(const t of this.overrides)s===t.name&&(null===(n=e.info)||void 0===n||n.overrides.push(t));else for(const n of this.overrides)t.value===n.name&&(null===(s=e.info)||void 0===s||s.overrides.push(n));}else if(t instanceof ge)for(const n of this.overrides)t.name===n.name&&(null===(r=e.info)||void 0===r||r.overrides.push(n));});for(const e of this.uniforms)this._markStructsInUse(e.type);for(const e of this.storage)this._markStructsInUse(e.type);}getFunctionInfo(e){for(const t of this.functions)if(t.name==e)return t;return null}getStructInfo(e){for(const t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(const t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(const t of e.members)this._markStructsInUse(t.type);}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else {const t=this._getAlias(e.name);t&&this._markStructsInUse(t);}}_addCalls(e,t){var n;for(const s of e.calls){const e=null===(n=this._functions.get(s.name))||void 0===n?void 0:n.info;e&&t.add(e);}}findResource(e,t,n){if(n){for(const s of this.entry.compute)if(s.name===n)for(const n of s.resources)if(n.group==e&&n.binding==t)return n;for(const s of this.entry.vertex)if(s.name===n)for(const n of s.resources)if(n.group==e&&n.binding==t)return n;for(const s of this.entry.fragment)if(s.name===n)for(const n of s.resources)if(n.group==e&&n.binding==t)return n}for(const n of this.uniforms)if(n.group==e&&n.binding==t)return n;for(const n of this.storage)if(n.group==e&&n.binding==t)return n;for(const n of this.textures)if(n.group==e&&n.binding==t)return n;for(const n of this.samplers)if(n.group==e&&n.binding==t)return n;return null}_findResource(e){for(const t of this.uniforms)if(t.name==e)return t;for(const t of this.storage)if(t.name==e)return t;for(const t of this.textures)if(t.name==e)return t;for(const t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){const t=this.getTypeInfo(e,null);this._markStructsInUse(t);}_findResources(e,t){const n=[],s=this,r=[];return e.search(a=>{if(a instanceof E)r.push({});else if(a instanceof $)r.pop();else if(a instanceof F){const e=a;t&&null!==e.type&&this._markStructsFromAST(e.type),r.length>0&&(r[r.length-1][e.name]=e);}else if(a instanceof de){const e=a;t&&null!==e.type&&this._markStructsFromAST(e.type);}else if(a instanceof U){const e=a;t&&null!==e.type&&this._markStructsFromAST(e.type),r.length>0&&(r[r.length-1][e.name]=e);}else if(a instanceof ge){const e=a;if(r.length>0){if(r[r.length-1][e.name])return}const t=s._findResource(e.name);t&&n.push(t);}else if(a instanceof me){const r=a,i=s._functions.get(r.name);i&&(t&&(i.inUse=!0),e.calls.add(i.node),null===i.resources&&(i.resources=s._findResources(i.node,t)),n.push(...i.resources));}else if(a instanceof X){const r=a,i=s._functions.get(r.name);i&&(t&&(i.inUse=!0),e.calls.add(i.node),null===i.resources&&(i.resources=s._findResources(i.node,t)),n.push(...i.resources));}}),[...new Map(n.map(e=>[e.name,e])).values()]}getBindGroups(){const e=[];function t(t,n){t>=e.length&&(e.length=t+1),void 0===e[t]&&(e[t]=[]),n>=e[t].length&&(e[t].length=n+1);}for(const n of this.uniforms){t(n.group,n.binding);e[n.group][n.binding]=n;}for(const n of this.storage){t(n.group,n.binding);e[n.group][n.binding]=n;}for(const n of this.textures){t(n.group,n.binding);e[n.group][n.binding]=n;}for(const n of this.samplers){t(n.group,n.binding);e[n.group][n.binding]=n;}return e}_getOutputs(e,t=void 0){if(void 0===t&&(t=[]),e instanceof oe)this._getStructOutputs(e,t);else {const n=this._getOutputInfo(e);null!==n&&t.push(n);}return t}_getStructOutputs(e,t){for(const n of e.members)if(n.type instanceof oe)this._getStructOutputs(n.type,t);else {const e=this._getAttribute(n,'location')||this._getAttribute(n,'builtin');if(null!==e){const s=this.getTypeInfo(n.type,n.type.attributes),r=this._parseInt(e.value),a=new u(n.name,s,e.name,r);t.push(a);}}}_getOutputInfo(e){const t=this._getAttribute(e,'location')||this._getAttribute(e,'builtin');if(null!==t){const n=this.getTypeInfo(e,e.attributes),s=this._parseInt(t.value);return new u('',n,t.name,s)}return null}_getInputs(e,t=void 0){void 0===t&&(t=[]);for(const n of e)if(n.type instanceof oe)this._getStructInputs(n.type,t);else {const e=this._getInputInfo(n);null!==e&&t.push(e);}return t}_getStructInputs(e,t){for(const n of e.members)if(n.type instanceof oe)this._getStructInputs(n.type,t);else {const e=this._getInputInfo(n);null!==e&&t.push(e);}}_getInputInfo(e){const t=this._getAttribute(e,'location')||this._getAttribute(e,'builtin');if(null!==t){const n=this._getAttribute(e,'interpolation'),s=this.getTypeInfo(e.type,e.attributes),r=this._parseInt(t.value),a=new l(e.name,s,t.name,r);return null!==n&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);const t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(const t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new c(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(const t of this.structs)if(t.name==e)return t;for(const t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(i,o=null){if(this._types.has(i))return this._types.get(i);if(i instanceof le){const e=i.type?this.getTypeInfo(i.type,i.attributes):null,t=new r(i.name,e,o);return this._types.set(i,t),this._updateTypeInfo(t),t}if(i instanceof ue){const e=i,t=e.format?this.getTypeInfo(e.format,e.attributes):null,n=new s(e.name,o);return n.format=t,n.count=e.count,this._types.set(i,n),this._updateTypeInfo(n),n}if(i instanceof oe){const e=i,s=new n(e.name,o);s.startLine=e.startLine,s.endLine=e.endLine;for(const n of e.members){const e=this.getTypeInfo(n.type,n.attributes);s.members.push(new t(n.name,e,n.attributes));}return this._types.set(i,s),this._updateTypeInfo(s),s}if(i instanceof he){const t=i,n=t.format instanceof ae,s=t.format?n?this.getTypeInfo(t.format,null):new e(t.format,null):null,r=new a(t.name,s,o,t.access);return this._types.set(i,r),this._updateTypeInfo(r),r}if(i instanceof ce){const e=i,t=e.format?this.getTypeInfo(e.format,null):null,n=new a(e.name,t,o,e.access);return this._types.set(i,n),this._updateTypeInfo(n),n}const c=new e(i.name,o);return this._types.set(i,c),this._updateTypeInfo(c),c}_updateTypeInfo(e){var t,a,i;const o=this._getTypeSize(e);if(e.size=null!==(t=null==o?void 0:o.size)&&void 0!==t?t:0,e instanceof s&&e.format){const t=this._getTypeSize(e.format);e.stride=Math.max(null!==(a=null==t?void 0:t.size)&&void 0!==a?a:0,null!==(i=null==t?void 0:t.align)&&void 0!==i?i:0),this._updateTypeInfo(e.format);}e instanceof r&&this._updateTypeInfo(e.format),e instanceof n&&this._updateStructInfo(e);}_updateStructInfo(e){var t;let n=0,s=0,r=0,a=0;for(let i=0,o=e.members.length;i<o;++i){const o=e.members[i],c=this._getTypeSize(o);if(!c)continue;null!==(t=this._getAlias(o.type.name))&&void 0!==t||o.type;const l=c.align,u=c.size;n=this._roundUp(l,n+s),s=u,r=n,a=Math.max(a,l),o.offset=n,o.size=u,this._updateTypeInfo(o.type);}e.size=this._roundUp(a,r+s),e.align=a;}_getTypeSize(r){var a,i;if(null==r)return null;const o=this._getAttributeNum(r.attributes,'size',0),c=this._getAttributeNum(r.attributes,'align',0);if(r instanceof t&&(r=r.type),r instanceof e){const e=this._getAlias(r.name);null!==e&&(r=e);}{const e=at._typeInfo[r.name];if(void 0!==e){const t='f16'===(null===(a=r.format)||void 0===a?void 0:a.name)?2:1;return new rt(Math.max(c,e.align/t),Math.max(o,e.size/t))}}{const e=at._typeInfo[r.name.substring(0,r.name.length-1)];if(e){const t='h'===r.name[r.name.length-1]?2:1;return new rt(Math.max(c,e.align/t),Math.max(o,e.size/t))}}if(r instanceof s){let e=r,t=8,n=8;const s=this._getTypeSize(e.format);null!==s&&(n=s.size,t=s.align);return n=e.count*this._getAttributeNum(null!==(i=null==r?void 0:r.attributes)&&void 0!==i?i:null,'stride',this._roundUp(t,n)),o&&(n=o),new rt(Math.max(c,t),Math.max(o,n))}if(r instanceof n){let e=0,t=0,n=0,s=0,a=0;for(const t of r.members){const r=this._getTypeSize(t.type);null!==r&&(e=Math.max(r.align,e),n=this._roundUp(r.align,n+s),s=r.size,a=n);}return t=this._roundUp(e,a+s),new rt(Math.max(c,e),Math.max(o,t))}return null}_isUniformVar(e){return e instanceof F&&'uniform'==e.storage}_isStorageVar(e){return e instanceof F&&'storage'==e.storage}_isTextureVar(e){return e instanceof F&&null!==e.type&&-1!=at._textureTypes.indexOf(e.type.name)}_isSamplerVar(e){return e instanceof F&&null!==e.type&&-1!=at._samplerTypes.indexOf(e.type.name)}_getAttribute(e,t){const n=e;if(!n||!n.attributes)return null;const s=n.attributes;for(let e of s)if(e.name==t)return e;return null}_getAttributeNum(e,t,n){if(null===e)return n;for(let s of e)if(s.name==t){let e=null!==s&&null!==s.value?s.value:n;return e instanceof Array&&(e=e[0]),'number'==typeof e?e:'string'==typeof e?parseInt(e):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}}at._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},at._textureTypes=He.any_texture_type.map(e=>e.name),at._samplerTypes=He.sampler_type.map(e=>e.name);let it=0;class ot{constructor(e,t,n){this.id=it++,this.name=e,this.value=t,this.node=n;}clone(){return new ot(this.name,this.value,this.node)}}class ct{constructor(e){this.id=it++,this.name=e.name,this.node=e;}clone(){return new ct(this.node)}}class lt{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName='',this.id=it++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName);}getVariable(e){var t;return this.variables.has(e)?null!==(t=this.variables.get(e))&&void 0!==t?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?null!==(t=this.functions.get(e))&&void 0!==t?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,n){this.variables.set(e,new ot(e,t,null!=n?n:null));}setVariable(e,t,n){const s=this.getVariable(e);null!==s?s.value=t:this.createVariable(e,t,n);}getVariableValue(e){var t;const n=this.getVariable(e);return null!==(t=null==n?void 0:n.value)&&void 0!==t?t:null}clone(){return new lt(this)}}class ut{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return ''}}class ht{constructor(e){this.exec=e;}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const n=this.exec.evalExpression(e.args[0],t);let s=!0;if(n instanceof Me)return n.data.forEach(e=>{e||(s=!1);}),new Be(s?1:0,this.getTypeInfo('bool'));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me){const e=n.data.some(e=>e);return new Be(e?1:0,this.getTypeInfo('bool'))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){const n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof Be))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.evalExpression(n,t);if(s instanceof Pe&&0===s.typeInfo.size){const e=s.typeInfo,t=s.buffer.byteLength/e.stride;return new Be(t,this.getTypeInfo('u32'))}return new Be(s.typeInfo.size,this.getTypeInfo('u32'))}Abs(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.abs(e)),n.typeInfo);const s=n;return new Be(Math.abs(s.value),s.typeInfo)}Acos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.acos(e)),n.typeInfo);const s=n;return new Be(Math.acos(s.value),n.typeInfo)}Acosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.acosh(e)),n.typeInfo);const s=n;return new Be(Math.acosh(s.value),n.typeInfo)}Asin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.asin(e)),n.typeInfo);const s=n;return new Be(Math.asin(s.value),n.typeInfo)}Asinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.asinh(e)),n.typeInfo);const s=n;return new Be(Math.asinh(s.value),n.typeInfo)}Atan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.atan(e)),n.typeInfo);const s=n;return new Be(Math.atan(s.value),n.typeInfo)}Atanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.atanh(e)),n.typeInfo);const s=n;return new Be(Math.atanh(s.value),n.typeInfo)}Atan2(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>Math.atan2(e,s.data[t])),n.typeInfo);const r=n,a=s;return new Be(Math.atan2(r.value,a.value),n.typeInfo)}Ceil(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.ceil(e)),n.typeInfo);const s=n;return new Be(Math.ceil(s.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof Me&&s instanceof Me&&r instanceof Me)return new Me(n.data.map((e,t)=>this._clamp(e,s.data[t],r.data[t])),n.typeInfo);const a=n,i=s,o=r;return new Be(this._clamp(a.value,i.value,o.value),n.typeInfo)}Cos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.cos(e)),n.typeInfo);const s=n;return new Be(Math.cos(s.value),n.typeInfo)}Cosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.cosh(e)),n.typeInfo);const s=n;return new Be(Math.cos(s.value),n.typeInfo)}CountLeadingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.clz32(e)),n.typeInfo);const s=n;return new Be(Math.clz32(s.value),n.typeInfo)}_countOneBits(e){let t=0;for(;0!==e;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>this._countOneBits(e)),n.typeInfo);const s=n;return new Be(this._countOneBits(s.value),n.typeInfo)}_countTrailingZeros(e){if(0===e)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>this._countTrailingZeros(e)),n.typeInfo);const s=n;return new Be(this._countTrailingZeros(s.value),n.typeInfo)}Cross(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me){if(3!==n.data.length||3!==s.data.length)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;const t=n.data,r=s.data;return new Me([t[1]*r[2]-r[1]*t[2],t[2]*r[0]-r[2]*t[0],t[0]*r[1]-r[0]*t[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){const n=this.exec.evalExpression(e.args[0],t),s=180/Math.PI;if(n instanceof Me)return new Me(n.data.map(e=>e*s),n.typeInfo);return new Be(n.value*s,this.getTypeInfo('f32'))}Determinant(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Ue){const e=n.data,t=n.typeInfo.getTypeName(),s=t.endsWith('h')?this.getTypeInfo('f16'):this.getTypeInfo('f32');if('mat2x2'===t||'mat2x2f'===t||'mat2x2h'===t)return new Be(e[0]*e[3]-e[1]*e[2],s);if('mat2x3'===t||'mat2x3f'===t||'mat2x3h'===t)return new Be(e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6]),s);if('mat2x4'===t||'mat2x4f'===t||'mat2x4h'===t)console.error(`TODO: Determinant for ${t}`);else if('mat3x2'===t||'mat3x2f'===t||'mat3x2h'===t)console.error(`TODO: Determinant for ${t}`);else {if('mat3x3'===t||'mat3x3f'===t||'mat3x3h'===t)return new Be(e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6]),s);'mat3x4'===t||'mat3x4f'===t||'mat3x4h'===t||'mat4x2'===t||'mat4x2f'===t||'mat4x2h'===t||'mat4x3'===t||'mat4x3f'===t||'mat4x3h'===t?console.error(`TODO: Determinant for ${t}`):'mat4x4'!==t&&'mat4x4f'!==t&&'mat4x4h'!==t||console.error(`TODO: Determinant for ${t}`);}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me){let e=0;for(let t=0;t<n.data.length;++t)e+=(n.data[t]-s.data[t])*(n.data[t]-s.data[t]);return new Be(Math.sqrt(e),this.getTypeInfo('f32'))}const r=n,a=s;return new Be(Math.abs(r.value-a.value),n.typeInfo)}_dot(e,t){let n=0;for(let s=0;s<e.length;++s)n+=t[s]*e[s];return n}Dot(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);return n instanceof Me&&s instanceof Me?new Be(this._dot(n.data,s.data),this.getTypeInfo('f32')):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.exp(e)),n.typeInfo);const s=n;return new Be(Math.exp(s.value),n.typeInfo)}Exp2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.pow(2,e)),n.typeInfo);const s=n;return new Be(Math.pow(2,s.value),n.typeInfo)}ExtractBits(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if('u32'!==s.typeInfo.name&&'x32'!==s.typeInfo.name)return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if('u32'!==r.typeInfo.name&&'x32'!==r.typeInfo.name)return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;const a=s.value,i=r.value;if(n instanceof Me)return new Me(n.data.map(e=>e>>a&(1<<i)-1),n.typeInfo);if('i32'!==n.typeInfo.name&&'x32'!==n.typeInfo.name)return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;const o=n.value;return new Be(o>>a&(1<<i)-1,this.getTypeInfo('i32'))}FaceForward(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof Me&&s instanceof Me&&r instanceof Me){const e=this._dot(s.data,r.data);return new Me(e<0?Array.from(n.data):n.data.map(e=>-e),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return 0===e?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>this._firstLeadingBit(e)),n.typeInfo);const s=n;return new Be(this._firstLeadingBit(s.value),n.typeInfo)}_firstTrailingBit(e){return 0===e?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>this._firstTrailingBit(e)),n.typeInfo);const s=n;return new Be(this._firstTrailingBit(s.value),n.typeInfo)}Floor(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.floor(e)),n.typeInfo);const s=n;return new Be(Math.floor(s.value),n.typeInfo)}Fma(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof Me&&s instanceof Me&&r instanceof Me)return n.data.length!==s.data.length||n.data.length!==r.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new Me(n.data.map((e,t)=>e*s.data[t]+r.data[t]),n.typeInfo);const a=n,i=s,o=r;return new Be(a.value*i.value+o.value,a.typeInfo)}Fract(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>e-Math.floor(e)),n.typeInfo);const s=n;return new Be(s.value-Math.floor(s.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t),a=this.exec.evalExpression(e.args[3],t);if('u32'!==r.typeInfo.name&&'x32'!==r.typeInfo.name)return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;const i=r.value,o=(1<<a.value)-1<<i,c=~o;if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>e&c|s.data[t]<<i&o),n.typeInfo);const l=n.value,u=s.value;return new Be(l&c|u<<i&o,n.typeInfo)}InverseSqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>1/Math.sqrt(e)),n.typeInfo);const s=n;return new Be(1/Math.sqrt(s.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me){let e=0;return n.data.forEach(t=>{e+=t*t;}),new Be(Math.sqrt(e),this.getTypeInfo('f32'))}const s=n;return new Be(Math.abs(s.value),n.typeInfo)}Log(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.log(e)),n.typeInfo);const s=n;return new Be(Math.log(s.value),n.typeInfo)}Log2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.log2(e)),n.typeInfo);const s=n;return new Be(Math.log2(s.value),n.typeInfo)}Max(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>Math.max(e,s.data[t])),n.typeInfo);const r=n,a=s;return new Be(Math.max(r.value,a.value),n.typeInfo)}Min(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>Math.min(e,s.data[t])),n.typeInfo);const r=n,a=s;return new Be(Math.min(r.value,a.value),n.typeInfo)}Mix(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof Me&&s instanceof Me&&r instanceof Me)return new Me(n.data.map((e,t)=>n.data[t]*(1-r.data[t])+s.data[t]*r.data[t]),n.typeInfo);const a=s,i=r;return new Be(n.value*(1-i.value)+a.value*i.value,n.typeInfo)}Modf(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>e%s.data[t]),n.typeInfo);const r=s;return new Be(n.value%r.value,n.typeInfo)}Normalize(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me){const s=this.Length(e,t).value;return new Me(n.data.map(e=>e/s),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me)return new Me(n.data.map((e,t)=>Math.pow(e,s.data[t])),n.typeInfo);const r=n,a=s;return new Be(Math.pow(r.value,a.value),n.typeInfo)}QuantizeToF16(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>e),n.typeInfo);return new Be(n.value,n.typeInfo)}Radians(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>e*Math.PI/180),n.typeInfo);return new Be(n.value*Math.PI/180,this.getTypeInfo('f32'))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof Me&&s instanceof Me){const e=this._dot(n.data,s.data);return new Me(n.data.map((t,n)=>t-2*e*s.data[n]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof Me&&s instanceof Me&&r instanceof Be){const e=this._dot(s.data,n.data);return new Me(n.data.map((t,n)=>{const a=1-r.value*r.value*(1-e*e);if(a<0)return 0;const i=Math.sqrt(a);return r.value*t-(r.value*e+i)*s.data[n]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.round(e)),n.typeInfo);const s=n;return new Be(Math.round(s.value),n.typeInfo)}Saturate(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.min(Math.max(e,0),1)),n.typeInfo);const s=n;return new Be(Math.min(Math.max(s.value,0),1),n.typeInfo)}Sign(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.sign(e)),n.typeInfo);const s=n;return new Be(Math.sign(s.value),n.typeInfo)}Sin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.sin(e)),n.typeInfo);const s=n;return new Be(Math.sin(s.value),n.typeInfo)}Sinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.sinh(e)),n.typeInfo);const s=n;return new Be(Math.sinh(s.value),n.typeInfo)}_smoothstep(e,t,n){const s=Math.min(Math.max((n-e)/(t-e),0),1);return s*s*(3-2*s)}SmoothStep(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(r instanceof Me&&n instanceof Me&&s instanceof Me)return new Me(r.data.map((e,t)=>this._smoothstep(n.data[t],s.data[t],e)),r.typeInfo);const a=n,i=s,o=r;return new Be(this._smoothstep(a.value,i.value,o.value),r.typeInfo)}Sqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.sqrt(e)),n.typeInfo);const s=n;return new Be(Math.sqrt(s.value),n.typeInfo)}Step(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(s instanceof Me&&n instanceof Me)return new Me(s.data.map((e,t)=>e<n.data[t]?0:1),s.typeInfo);const r=n;return new Be(s.value<r.value?0:1,r.typeInfo)}Tan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.tan(e)),n.typeInfo);const s=n;return new Be(Math.tan(s.value),n.typeInfo)}Tanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.tanh(e)),n.typeInfo);const s=n;return new Be(Math.tanh(s.value),n.typeInfo)}_getTransposeType(e){const t=e.getTypeName();return 'mat2x2f'===t||'mat2x2h'===t?e:'mat2x3f'===t?this.getTypeInfo('mat3x2f'):'mat2x3h'===t?this.getTypeInfo('mat3x2h'):'mat2x4f'===t?this.getTypeInfo('mat4x2f'):'mat2x4h'===t?this.getTypeInfo('mat4x2h'):'mat3x2f'===t?this.getTypeInfo('mat2x3f'):'mat3x2h'===t?this.getTypeInfo('mat2x3h'):'mat3x3f'===t||'mat3x3h'===t?e:'mat3x4f'===t?this.getTypeInfo('mat4x3f'):'mat3x4h'===t?this.getTypeInfo('mat4x3h'):'mat4x2f'===t?this.getTypeInfo('mat2x4f'):'mat4x2h'===t?this.getTypeInfo('mat2x4h'):'mat4x3f'===t?this.getTypeInfo('mat3x4f'):'mat4x3h'===t?this.getTypeInfo('mat3x4h'):('mat4x4f'===t||'mat4x4h'===t||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){const n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof Ue))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;const s=this._getTransposeType(n.typeInfo);if('mat2x2'===n.typeInfo.name||'mat2x2f'===n.typeInfo.name||'mat2x2h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[2],e[1],e[3]],s)}if('mat2x3'===n.typeInfo.name||'mat2x3f'===n.typeInfo.name||'mat2x3h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[3],e[6],e[1],e[4],e[7]],s)}if('mat2x4'===n.typeInfo.name||'mat2x4f'===n.typeInfo.name||'mat2x4h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13]],s)}if('mat3x2'===n.typeInfo.name||'mat3x2f'===n.typeInfo.name||'mat3x2h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[3],e[1],e[4],e[2],e[5]],s)}if('mat3x3'===n.typeInfo.name||'mat3x3f'===n.typeInfo.name||'mat3x3h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[3],e[6],e[1],e[4],e[7],e[2],e[5],e[8]],s)}if('mat3x4'===n.typeInfo.name||'mat3x4f'===n.typeInfo.name||'mat3x4h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14]],s)}if('mat4x2'===n.typeInfo.name||'mat4x2f'===n.typeInfo.name||'mat4x2h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[4],e[1],e[5],e[2],e[6]],s)}if('mat4x3'===n.typeInfo.name||'mat4x3f'===n.typeInfo.name||'mat4x3h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]],s)}if('mat4x4'===n.typeInfo.name||'mat4x4f'===n.typeInfo.name||'mat4x4h'===n.typeInfo.name){const e=n.data;return new Ue([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15]],s)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Me)return new Me(n.data.map(e=>Math.trunc(e)),n.typeInfo);const s=n;return new Be(Math.trunc(s.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error('TODO: dpdxFine'),null}Dpdy(e,t){return console.error('TODO: dpdy'),null}DpdyCoarse(e,t){return console.error('TODO: dpdyCoarse'),null}DpdyFine(e,t){return console.error('TODO: dpdyFine'),null}Fwidth(e,t){return console.error('TODO: fwidth'),null}FwidthCoarse(e,t){return console.error('TODO: fwidthCoarse'),null}FwidthFine(e,t){return console.error('TODO: fwidthFine'),null}TextureDimensions(e,t){const n=e.args[0],s=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof ge){const r=n.name,a=t.getVariableValue(r);if(a instanceof We){if(s<0||s>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;const t=a.getMipLevelSize(s),n=a.dimension;return '1d'===n?new Be(t[0],this.getTypeInfo('u32')):'3d'===n?new Me(t,this.getTypeInfo('vec3u')):'2d'===n?new Me(t.slice(0,2),this.getTypeInfo('vec2u')):(console.error(`Invalid texture dimension ${n} not found. Line ${e.line}`),null)}return console.error(`Texture ${r} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error('TODO: textureGather'),null}TextureGatherCompare(e,t){return console.error('TODO: textureGatherCompare'),null}TextureLoad(e,t){const n=e.args[0],s=this.exec.evalExpression(e.args[1],t),r=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(s instanceof Me)||2!==s.data.length)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof ge){const a=n.name,i=t.getVariableValue(a);if(i instanceof We){const t=Math.floor(s.data[0]),n=Math.floor(s.data[1]);if(t<0||t>=i.width||n<0||n>=i.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;const o=i.getPixel(t,n,0,r);return null===o?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new Me(o,this.getTypeInfo('vec4f'))}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){const n=e.args[0];if(n instanceof ge){const s=n.name,r=t.getVariableValue(s);return r instanceof We?new Be(r.depthOrArrayLayers,this.getTypeInfo('u32')):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){const n=e.args[0];if(n instanceof ge){const s=n.name,r=t.getVariableValue(s);return r instanceof We?new Be(r.mipLevelCount,this.getTypeInfo('u32')):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){const n=e.args[0];if(n instanceof ge){const s=n.name,r=t.getVariableValue(s);return r instanceof We?new Be(r.sampleCount,this.getTypeInfo('u32')):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error('TODO: textureSample'),null}TextureSampleBias(e,t){return console.error('TODO: textureSampleBias'),null}TextureSampleCompare(e,t){return console.error('TODO: textureSampleCompare'),null}TextureSampleCompareLevel(e,t){return console.error('TODO: textureSampleCompareLevel'),null}TextureSampleGrad(e,t){return console.error('TODO: textureSampleGrad'),null}TextureSampleLevel(e,t){return console.error('TODO: textureSampleLevel'),null}TextureSampleBaseClampToEdge(e,t){return console.error('TODO: textureSampleBaseClampToEdge'),null}TextureStore(e,t){const n=e.args[0],s=this.exec.evalExpression(e.args[1],t),r=4===e.args.length?this.exec.evalExpression(e.args[2],t).value:0,a=4===e.args.length?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(4!==a.length)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(s instanceof Me)||2!==s.data.length)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof ge){const i=n.name,o=t.getVariableValue(i);if(o instanceof We){const t=o.getMipLevelSize(0),n=Math.floor(s.data[0]),c=Math.floor(s.data[1]);return n<0||n>=t[0]||c<0||c>=t[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(o.setPixel(n,c,0,r,Array.from(a)),null)}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t);return t.getVariable(s).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t);return o instanceof Be&&i instanceof Be&&(o.value=i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value+=i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value-=i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=Math.max(o.value,i.value)),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=Math.min(o.value,i.value)),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=o.value&i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=o.value|i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=o.value^i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof ke&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new Be(o.value,o.typeInfo);return o instanceof Be&&i instanceof Be&&(o.value=i.value),r.value instanceof Pe&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error('TODO: atomicCompareExchangeWeak'),null}Pack4x8snorm(e,t){return console.error('TODO: pack4x8snorm'),null}Pack4x8unorm(e,t){return console.error('TODO: pack4x8unorm'),null}Pack4xI8(e,t){return console.error('TODO: pack4xI8'),null}Pack4xU8(e,t){return console.error('TODO: pack4xU8'),null}Pack4x8Clamp(e,t){return console.error('TODO: pack4x8Clamp'),null}Pack4xU8Clamp(e,t){return console.error('TODO: pack4xU8Clamp'),null}Pack2x16snorm(e,t){return console.error('TODO: pack2x16snorm'),null}Pack2x16unorm(e,t){return console.error('TODO: pack2x16unorm'),null}Pack2x16float(e,t){return console.error('TODO: pack2x16float'),null}Unpack4x8snorm(e,t){return console.error('TODO: unpack4x8snorm'),null}Unpack4x8unorm(e,t){return console.error('TODO: unpack4x8unorm'),null}Unpack4xI8(e,t){return console.error('TODO: unpack4xI8'),null}Unpack4xU8(e,t){return console.error('TODO: unpack4xU8'),null}Unpack2x16snorm(e,t){return console.error('TODO: unpack2x16snorm'),null}Unpack2x16unorm(e,t){return console.error('TODO: unpack2x16unorm'),null}Unpack2x16float(e,t){return console.error('TODO: unpack2x16float'),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error('TODO: subgroupAdd'),null}SubgroupExclusiveAdd(e,t){return console.error('TODO: subgroupExclusiveAdd'),null}SubgroupInclusiveAdd(e,t){return console.error('TODO: subgroupInclusiveAdd'),null}SubgroupAll(e,t){return console.error('TODO: subgroupAll'),null}SubgroupAnd(e,t){return console.error('TODO: subgroupAnd'),null}SubgroupAny(e,t){return console.error('TODO: subgroupAny'),null}SubgroupBallot(e,t){return console.error('TODO: subgroupBallot'),null}SubgroupBroadcast(e,t){return console.error('TODO: subgroupBroadcast'),null}SubgroupBroadcastFirst(e,t){return console.error('TODO: subgroupBroadcastFirst'),null}SubgroupElect(e,t){return console.error('TODO: subgroupElect'),null}SubgroupMax(e,t){return console.error('TODO: subgroupMax'),null}SubgroupMin(e,t){return console.error('TODO: subgroupMin'),null}SubgroupMul(e,t){return console.error('TODO: subgroupMul'),null}SubgroupExclusiveMul(e,t){return console.error('TODO: subgroupExclusiveMul'),null}SubgroupInclusiveMul(e,t){return console.error('TODO: subgroupInclusiveMul'),null}SubgroupOr(e,t){return console.error('TODO: subgroupOr'),null}SubgroupShuffle(e,t){return console.error('TODO: subgroupShuffle'),null}SubgroupShuffleDown(e,t){return console.error('TODO: subgroupShuffleDown'),null}SubgroupShuffleUp(e,t){return console.error('TODO: subgroupShuffleUp'),null}SubgroupShuffleXor(e,t){return console.error('TODO: subgroupShuffleXor'),null}SubgroupXor(e,t){return console.error('TODO: subgroupXor'),null}QuadBroadcast(e,t){return console.error('TODO: quadBroadcast'),null}QuadSwapDiagonal(e,t){return console.error('TODO: quadSwapDiagonal'),null}QuadSwapX(e,t){return console.error('TODO: quadSwapX'),null}QuadSwapY(e,t){return console.error('TODO: quadSwapY'),null}}const ft={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},pt={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]};class dt extends ut{constructor(e,t){var n;super(),this.ast=null!=e?e:[],this.reflection=new at,this.reflection.updateAST(this.ast),this.context=null!==(n=null==t?void 0:t.clone())&&void 0!==n?n:new lt,this.builtins=new ht(this),this.typeInfo={bool:this.getTypeInfo(ae.bool),i32:this.getTypeInfo(ae.i32),u32:this.getTypeInfo(ae.u32),f32:this.getTypeInfo(ae.f32),f16:this.getTypeInfo(ae.f16),vec2f:this.getTypeInfo(ce.vec2f),vec2u:this.getTypeInfo(ce.vec2u),vec2i:this.getTypeInfo(ce.vec2i),vec2h:this.getTypeInfo(ce.vec2h),vec3f:this.getTypeInfo(ce.vec3f),vec3u:this.getTypeInfo(ce.vec3u),vec3i:this.getTypeInfo(ce.vec3i),vec3h:this.getTypeInfo(ce.vec3h),vec4f:this.getTypeInfo(ce.vec4f),vec4u:this.getTypeInfo(ce.vec4u),vec4i:this.getTypeInfo(ce.vec4i),vec4h:this.getTypeInfo(ce.vec4h),mat2x2f:this.getTypeInfo(ce.mat2x2f),mat2x3f:this.getTypeInfo(ce.mat2x3f),mat2x4f:this.getTypeInfo(ce.mat2x4f),mat3x2f:this.getTypeInfo(ce.mat3x2f),mat3x3f:this.getTypeInfo(ce.mat3x3f),mat3x4f:this.getTypeInfo(ce.mat3x4f),mat4x2f:this.getTypeInfo(ce.mat4x2f),mat4x3f:this.getTypeInfo(ce.mat4x3f),mat4x4f:this.getTypeInfo(ce.mat4x4f)};}getVariableValue(e){var t,n;const r=null!==(n=null===(t=this.context.getVariable(e))||void 0===t?void 0:t.value)&&void 0!==n?n:null;if(null===r)return null;if(r instanceof Be)return r.value;if(r instanceof Me)return Array.from(r.data);if(r instanceof Ue)return Array.from(r.data);if(r instanceof Pe&&r.typeInfo instanceof s){if('u32'===r.typeInfo.format.name)return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if('i32'===r.typeInfo.format.name)return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if('f32'===r.typeInfo.format.name)return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=null!=e?e:{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context);}dispatchWorkgroups(e,t,n,s){const r=this.context.clone();(s=null!=s?s:{}).constants&&this._setOverrides(s.constants,r),this._execStatements(this.ast,r);const a=r.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if('number'==typeof t)t=[t,1,1];else {if(0===t.length)return void console.error('Invalid dispatch count');1===t.length?t=[t[0],1,1]:2===t.length?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]]);}const i=t[0],o=t[1],c=t[2],l=this.getTypeInfo('vec3u');r.setVariable('@num_workgroups',new Me(t,l));const u=this.reflection.getFunctionInfo(e);null===u&&console.error(`Function ${e} not found in reflection data`);for(const e in n)for(const t in n[e]){const s=n[e][t];r.variables.forEach(n=>{var r;const a=n.node;if(null==a?void 0:a.attributes){let i=null,o=null;for(const e of a.attributes)'binding'===e.name?i=e.value:'group'===e.name&&(o=e.value);if(t==i&&e==o){let i=!1;for(const s of u.resources)if(s.name===n.name&&s.group===parseInt(e)&&s.binding===parseInt(t)){i=!0;break}if(i)if(void 0!==s.texture&&void 0!==s.descriptor){const e=new We(s.texture,this.getTypeInfo(a.type),s.descriptor,null!==(r=s.texture.view)&&void 0!==r?r:null);n.value=e;}else void 0!==s.uniform?n.value=new Pe(s.uniform,this.getTypeInfo(a.type)):n.value=new Pe(s,this.getTypeInfo(a.type));}}});}for(let e=0;e<c;++e)for(let t=0;t<o;++t)for(let n=0;n<i;++n)r.setVariable('@workgroup_id',new Me([n,t,e],this.getTypeInfo('vec3u'))),this._dispatchWorkgroup(a,[n,t,e],r);}execStatement(e,t){if(e instanceof Y)return this.evalExpression(e.value,t);if(e instanceof se){if(e.condition){const n=this.evalExpression(e.condition,t);if(!(n instanceof Be))throw new Error('Invalid break-if condition');if(!n.value)return null}return dt._breakObj}if(e instanceof re)return dt._continueObj;if(e instanceof U)this._let(e,t);else if(e instanceof F)this._var(e,t);else if(e instanceof P)this._const(e,t);else if(e instanceof D)this._function(e,t);else {if(e instanceof Q)return this._if(e,t);if(e instanceof Z)return this._switch(e,t);if(e instanceof B)return this._for(e,t);if(e instanceof V)return this._while(e,t);if(e instanceof j)return this._loop(e,t);if(e instanceof O){const n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof G)this._assign(e,t);else if(e instanceof R)this._increment(e,t);else {if(e instanceof oe)return null;if(e instanceof M){const n=e.name;null===t.getVariable(n)&&t.setVariable(n,new Be(0,this.getTypeInfo('u32')));}else if(e instanceof X)this._call(e,t);else {if(e instanceof ee)return null;if(e instanceof te)return null;console.error('Invalid statement type.',e,`Line ${e.line}`);}}}return null}evalExpression(e,t){return e instanceof Ie?this._evalBinaryOp(e,t):e instanceof xe?this._evalLiteral(e,t):e instanceof ge?this._evalVariable(e,t):e instanceof me?this._evalCall(e,t):e instanceof de?this._evalCreate(e,t):e instanceof _e?this._evalConst(e,t):e instanceof ye?this._evalBitcast(e,t):e instanceof ke?this._evalUnaryOp(e,t):(console.error('Invalid expression type',e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof ae){const t=this.reflection.getTypeInfo(e);if(null!==t)return t}let n=null!==(t=this.typeInfo[e])&&void 0!==t?t:null;return null!==n||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(const n in e){const s=e[n],r=this.reflection.getOverrideInfo(n);null!==r?(null===r.type&&(r.type=this.getTypeInfo('u32')),'u32'===r.type.name||'i32'===r.type.name||'f32'===r.type.name||'f16'===r.type.name?t.setVariable(n,new Be(s,r.type)):'bool'===r.type.name?t.setVariable(n,new Be(s?1:0,r.type)):'vec2'===r.type.name||'vec3'===r.type.name||'vec4'===r.type.name||'vec2f'===r.type.name||'vec3f'===r.type.name||'vec4f'===r.type.name||'vec2i'===r.type.name||'vec3i'===r.type.name||'vec4i'===r.type.name||'vec2u'===r.type.name||'vec3u'===r.type.name||'vec4u'===r.type.name||'vec2h'===r.type.name||'vec3h'===r.type.name||'vec4h'===r.type.name?t.setVariable(n,new Me(s,r.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`);}}_dispatchWorkgroup(e,t,n){const s=[1,1,1];for(const t of e.node.attributes)if('workgroup_size'===t.name){if(t.value.length>0){const e=n.getVariableValue(t.value[0]);s[0]=e instanceof Be?e.value:parseInt(t.value[0]);}if(t.value.length>1){const e=n.getVariableValue(t.value[1]);s[1]=e instanceof Be?e.value:parseInt(t.value[1]);}if(t.value.length>2){const e=n.getVariableValue(t.value[2]);s[2]=e instanceof Be?e.value:parseInt(t.value[2]);}}const r=this.getTypeInfo('vec3u'),a=this.getTypeInfo('u32');n.setVariable('@workgroup_size',new Me(s,r));const i=s[0],o=s[1],c=s[2];for(let l=0,u=0;l<c;++l)for(let c=0;c<o;++c)for(let o=0;o<i;++o,++u){const i=[o,c,l],h=[o+t[0]*s[0],c+t[1]*s[1],l+t[2]*s[2]];n.setVariable('@local_invocation_id',new Me(i,r)),n.setVariable('@global_invocation_id',new Me(h,r)),n.setVariable('@local_invocation_index',new Be(u,a)),this._dispatchExec(e,n);}}_dispatchExec(e,t){for(const n of e.node.args)for(const e of n.attributes)if('builtin'===e.name){const s=`@${e.value}`,r=t.getVariable(s);void 0!==r&&t.variables.set(n.name,r);}this._execStatements(e.node.body,t);}getVariableName(e,t){for(;e instanceof ke;)e=e.right;return e instanceof ge?e.name:(console.error('Unknown variable type',e,'Line',e.line),null)}_execStatements(e,t){for(const n of e){if(n instanceof Array){const e=t.clone(),s=this._execStatements(n,e);if(s)return s;continue}const e=this.execStatement(n,t);if(e)return e}return null}_call(e,t){const n=t.clone();n.currentFunctionName=e.name;const s=t.getFunction(e.name);if(s){for(let t=0;t<s.node.args.length;++t){const r=s.node.args[t],a=this.evalExpression(e.args[t],n);n.setVariable(r.name,a,r);}this._execStatements(s.node.body,n);}else if(e.isBuiltin)this._callBuiltinFunction(e,n);else {this.getTypeInfo(e.name)&&this._evalCreate(e,t);}}_increment(e,t){const n=this.getVariableName(e.variable,t),s=t.getVariable(n);s?'++'===e.operator?s.value instanceof Be?s.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):'--'===e.operator?s.value instanceof Be?s.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`);}_getVariableData(e,t){if(e instanceof ge){const n=this.getVariableName(e,t),s=t.getVariable(n);return null===s?(console.error(`Variable ${n} not found. Line ${e.line}`),null):s.value.getSubData(this,e.postfix,t)}if(e instanceof ke){if('*'===e.operator){const n=this._getVariableData(e.right,t);return n instanceof Oe?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if('&'===e.operator){const n=this._getVariableData(e.right,t);return new Oe(n)}}return null}_assign(e,t){let n=null,s='<var>',r=null;if(e.variable instanceof ke){const n=this._getVariableData(e.variable,t),s=this.evalExpression(e.value,t),r=e.operator;if('='===r){if(n instanceof Be||n instanceof Me||n instanceof Ue){if(s instanceof Be||s instanceof Me||s instanceof Ue&&n.data.length===s.data.length)return void n.data.set(s.data);console.error(`Invalid assignment. Line ${e.line}`);}else if(n instanceof Pe&&s instanceof Pe&&n.buffer.byteLength-n.offset>=s.buffer.byteLength-s.offset)return void(n.buffer.byteLength%4==0?new Uint32Array(n.buffer,n.offset,n.typeInfo.size/4).set(new Uint32Array(s.buffer,s.offset,s.typeInfo.size/4)):new Uint8Array(n.buffer,n.offset,n.typeInfo.size).set(new Uint8Array(s.buffer,s.offset,s.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if('+='===r)return n instanceof Be||n instanceof Me||n instanceof Ue?s instanceof Be||s instanceof Me||s instanceof Ue?void n.data.set(s.data.map((e,t)=>n.data[t]+e)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if('-='===r)return (n instanceof Be||n instanceof Me||n instanceof Ue)&&(s instanceof Be||s instanceof Me||s instanceof Ue)?void n.data.set(s.data.map((e,t)=>n.data[t]-e)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof ke){if('*'===e.variable.operator){s=this.getVariableName(e.variable.right,t);const r=t.getVariable(s);if(!(r&&r.value instanceof Oe))return void console.error(`Variable ${s} is not a pointer. Line ${e.line}`);n=r.value.reference;let a=e.variable.postfix;if(!a){let t=e.variable.right;for(;t instanceof ke;){if(t.postfix){a=t.postfix;break}t=t.right;}}a&&(n=n.getSubData(this,a,t));}}else {r=e.variable.postfix,s=this.getVariableName(e.variable,t);const a=t.getVariable(s);if(null===a)return void console.error(`Variable ${s} not found. Line ${e.line}`);n=a.value;}if(n instanceof Oe&&(n=n.reference),null===n)return void console.error(`Variable ${s} not found. Line ${e.line}`);const a=this.evalExpression(e.value,t),i=e.operator;if('='!==i){const s=n.getSubData(this,r,t);if(s instanceof Me&&a instanceof Be){const t=s.data,n=a.value;if('+='===i)for(let e=0;e<t.length;++e)t[e]+=n;else if('-='===i)for(let e=0;e<t.length;++e)t[e]-=n;else if('*='===i)for(let e=0;e<t.length;++e)t[e]*=n;else if('/='===i)for(let e=0;e<t.length;++e)t[e]/=n;else if('%='===i)for(let e=0;e<t.length;++e)t[e]%=n;else if('&='===i)for(let e=0;e<t.length;++e)t[e]&=n;else if('|='===i)for(let e=0;e<t.length;++e)t[e]|=n;else if('^='===i)for(let e=0;e<t.length;++e)t[e]^=n;else if('<<='===i)for(let e=0;e<t.length;++e)t[e]<<=n;else if('>>='===i)for(let e=0;e<t.length;++e)t[e]>>=n;else console.error(`Invalid operator ${i}. Line ${e.line}`);}else if(s instanceof Me&&a instanceof Me){const t=s.data,n=a.data;if(t.length!==n.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if('+='===i)for(let e=0;e<t.length;++e)t[e]+=n[e];else if('-='===i)for(let e=0;e<t.length;++e)t[e]-=n[e];else if('*='===i)for(let e=0;e<t.length;++e)t[e]*=n[e];else if('/='===i)for(let e=0;e<t.length;++e)t[e]/=n[e];else if('%='===i)for(let e=0;e<t.length;++e)t[e]%=n[e];else if('&='===i)for(let e=0;e<t.length;++e)t[e]&=n[e];else if('|='===i)for(let e=0;e<t.length;++e)t[e]|=n[e];else if('^='===i)for(let e=0;e<t.length;++e)t[e]^=n[e];else if('<<='===i)for(let e=0;e<t.length;++e)t[e]<<=n[e];else if('>>='===i)for(let e=0;e<t.length;++e)t[e]>>=n[e];else console.error(`Invalid operator ${i}. Line ${e.line}`);}else {if(!(s instanceof Be&&a instanceof Be))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);'+='===i?s.value+=a.value:'-='===i?s.value-=a.value:'*='===i?s.value*=a.value:'/='===i?s.value/=a.value:'%='===i?s.value%=a.value:'&='===i?s.value&=a.value:'|='===i?s.value|=a.value:'^='===i?s.value^=a.value:'<<='===i?s.value<<=a.value:'>>='===i?s.value>>=a.value:console.error(`Invalid operator ${i}. Line ${e.line}`);}return void(n instanceof Pe&&n.setDataValue(this,s,r,t))}if(n instanceof Pe)n.setDataValue(this,a,r,t);else if(r){if(!(n instanceof Me||n instanceof Ue))return void console.error(`Variable ${s} is not a vector or matrix. Line ${e.line}`);if(r instanceof ve){const i=this.evalExpression(r.index,t).value;if(n instanceof Me){if(!(a instanceof Be))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[i]=a.value;}else {if(!(n instanceof Ue))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{const i=this.evalExpression(r.index,t).value;if(i<0)return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(a instanceof Me))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{const t=n.typeInfo.getTypeName();if('mat2x2'===t||'mat2x2f'===t||'mat2x2h'===t){if(!(i<2&&2===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*i]=a.data[0],n.data[2*i+1]=a.data[1];}else if('mat2x3'===t||'mat2x3f'===t||'mat2x3h'===t){if(!(i<2&&3===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*i]=a.data[0],n.data[3*i+1]=a.data[1],n.data[3*i+2]=a.data[2];}else if('mat2x4'===t||'mat2x4f'===t||'mat2x4h'===t){if(!(i<2&&4===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*i]=a.data[0],n.data[4*i+1]=a.data[1],n.data[4*i+2]=a.data[2],n.data[4*i+3]=a.data[3];}else if('mat3x2'===t||'mat3x2f'===t||'mat3x2h'===t){if(!(i<3&&2===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*i]=a.data[0],n.data[2*i+1]=a.data[1];}else if('mat3x3'===t||'mat3x3f'===t||'mat3x3h'===t){if(!(i<3&&3===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*i]=a.data[0],n.data[3*i+1]=a.data[1],n.data[3*i+2]=a.data[2];}else if('mat3x4'===t||'mat3x4f'===t||'mat3x4h'===t){if(!(i<3&&4===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*i]=a.data[0],n.data[4*i+1]=a.data[1],n.data[4*i+2]=a.data[2],n.data[4*i+3]=a.data[3];}else if('mat4x2'===t||'mat4x2f'===t||'mat4x2h'===t){if(!(i<4&&2===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*i]=a.data[0],n.data[2*i+1]=a.data[1];}else if('mat4x3'===t||'mat4x3f'===t||'mat4x3h'===t){if(!(i<4&&3===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*i]=a.data[0],n.data[3*i+1]=a.data[1],n.data[3*i+2]=a.data[2];}else {if('mat4x4'!==t&&'mat4x4f'!==t&&'mat4x4h'!==t)return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(i<4&&4===a.data.length))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*i]=a.data[0],n.data[4*i+1]=a.data[1],n.data[4*i+2]=a.data[2],n.data[4*i+3]=a.data[3];}}}}}else if(r instanceof pe){const t=r.value;if(!(n instanceof Me))return void console.error(`Invalid assignment to ${t}. Variable ${s} is not a vector. Line ${e.line}`);if(a instanceof Be){if(t.length>1)return void console.error(`Invalid assignment to ${t} for variable ${s}. Line ${e.line}`);if('x'===t)n.data[0]=a.value;else if('y'===t){if(n.data.length<2)return void console.error(`Invalid assignment to ${t} for variable ${s}. Line ${e.line}`);n.data[1]=a.value;}else if('z'===t){if(n.data.length<3)return void console.error(`Invalid assignment to ${t} for variable ${s}. Line ${e.line}`);n.data[2]=a.value;}else if('w'===t){if(n.data.length<4)return void console.error(`Invalid assignment to ${t} for variable ${s}. Line ${e.line}`);n.data[3]=a.value;}}else {if(!(a instanceof Me))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(t.length!==a.data.length)return void console.error(`Invalid assignment to ${t} for variable ${s}. Line ${e.line}`);for(let r=0;r<t.length;++r){const i=t[r];if('x'===i||'r'===i)n.data[0]=a.data[r];else if('y'===i||'g'===i){if(a.data.length<2)return void console.error(`Invalid assignment to ${i} for variable ${s}. Line ${e.line}`);n.data[1]=a.data[r];}else if('z'===i||'b'===i){if(a.data.length<3)return void console.error(`Invalid assignment to ${i} for variable ${s}. Line ${e.line}`);n.data[2]=a.data[r];}else {if('w'!==i&&'a'!==i)return void console.error(`Invalid assignment to ${i} for variable ${s}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${i} for variable ${s}. Line ${e.line}`);n.data[3]=a.data[r];}}}}}else n instanceof Be&&a instanceof Be?n.value=a.value:n instanceof Me&&a instanceof Me||n instanceof Ue&&a instanceof Ue?n.data.set(a.data):console.error(`Invalid assignment to ${s}. Line ${e.line}`);}_function(e,t){const n=new ct(e);t.functions.set(e.name,n);}_const(e,t){let n=null;null!==e.value&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e);}_let(e,t){let n=null;if(null!==e.value){if(n=this.evalExpression(e.value,t),null===n)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof ke||(n=n.clone());}else {const s=e.type.name;if('f32'===s||'i32'===s||'u32'===s||'bool'===s||'f16'===s||'vec2'===s||'vec3'===s||'vec4'===s||'vec2f'===s||'vec3f'===s||'vec4f'===s||'vec2i'===s||'vec3i'===s||'vec4i'===s||'vec2u'===s||'vec3u'===s||'vec4u'===s||'vec2h'===s||'vec3h'===s||'vec4h'===s||'vec2b'===s||'vec3b'===s||'vec4b'===s||'mat2x2'===s||'mat2x3'===s||'mat2x4'===s||'mat3x2'===s||'mat3x3'===s||'mat3x4'===s||'mat4x2'===s||'mat4x3'===s||'mat4x4'===s||'mat2x2f'===s||'mat2x3f'===s||'mat2x4f'===s||'mat3x2f'===s||'mat3x3f'===s||'mat3x4f'===s||'mat4x2f'===s||'mat4x3f'===s||'mat4x4f'===s||'mat2x2h'===s||'mat2x3h'===s||'mat2x4h'===s||'mat3x2h'===s||'mat3x3h'===s||'mat3x4h'===s||'mat4x2h'===s||'mat4x3h'===s||'mat4x4h'===s||'array'===s){const s=new de(e.type,[]);n=this._evalCreate(s,t);}}t.createVariable(e.name,n,e);}_var(e,t){let n=null;if(null!==e.value){if(n=this.evalExpression(e.value,t),null===n)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof ke||(n=n.clone());}else {if(null===e.type)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);const s=e.type.name;if('f32'===s||'i32'===s||'u32'===s||'bool'===s||'f16'===s||'vec2'===s||'vec3'===s||'vec4'===s||'vec2f'===s||'vec3f'===s||'vec4f'===s||'vec2i'===s||'vec3i'===s||'vec4i'===s||'vec2u'===s||'vec3u'===s||'vec4u'===s||'vec2h'===s||'vec3h'===s||'vec4h'===s||'vec2b'===s||'vec3b'===s||'vec4b'===s||'mat2x2'===s||'mat2x3'===s||'mat2x4'===s||'mat3x2'===s||'mat3x3'===s||'mat3x4'===s||'mat4x2'===s||'mat4x3'===s||'mat4x4'===s||'mat2x2f'===s||'mat2x3f'===s||'mat2x4f'===s||'mat3x2f'===s||'mat3x3f'===s||'mat3x4f'===s||'mat4x2f'===s||'mat4x3f'===s||'mat4x4f'===s||'mat2x2h'===s||'mat2x3h'===s||'mat2x4h'===s||'mat3x2h'===s||'mat3x3h'===s||'mat3x4h'===s||'mat4x2h'===s||'mat4x3h'===s||'mat4x4h'===s||e.type instanceof ue||e.type instanceof oe||e.type instanceof ce){const s=new de(e.type,[]);n=this._evalCreate(s,t);}}t.createVariable(e.name,n,e);}_switch(e,t){t=t.clone();const n=this.evalExpression(e.condition,t);if(!(n instanceof Be))return console.error(`Invalid if condition. Line ${e.line}`),null;let s=null;for(const r of e.cases)if(r instanceof Ae)for(const a of r.selectors){if(a instanceof Se){s=r;continue}const i=this.evalExpression(a,t);if(!(i instanceof Be))return console.error(`Invalid case selector. Line ${e.line}`),null;if(i.value===n.value)return this._execStatements(r.body,t)}else r instanceof Ee&&(s=r);return s?this._execStatements(s.body,t):null}_if(e,t){t=t.clone();const n=this.evalExpression(e.condition,t);if(!(n instanceof Be))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(const n of e.elseif){const s=this.evalExpression(n.condition,t);if(!(s instanceof Be))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(n.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof Be?e.value:(console.error('Expected scalar value.',e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){const n=this._execStatements(e.body,t);if(n===dt._breakObj)break;if(null!==n&&n!==dt._continueObj)return n;this.execStatement(e.increment,t);}return null}_loop(e,t){for(t=t.clone();;){const n=this._execStatements(e.body,t);if(n===dt._breakObj)break;if(n===dt._continueObj){if(e.continuing){if(this._execStatements(e.continuing.body,t)===dt._breakObj)break}}else if(null!==n)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){const n=this._execStatements(e.body,t);if(n===dt._breakObj)break;if(n!==dt._continueObj&&null!==n)return n}return null}_evalBitcast(e,t){const n=this.evalExpression(e.value,t),s=e.type;if(n instanceof Be){const e=nt(n.value,n.typeInfo.name,s.name);return new Be(e,this.getTypeInfo(s))}if(n instanceof Me){const t=n.typeInfo.getTypeName();let r='';if(t.endsWith('f'))r='f32';else if(t.endsWith('i'))r='i32';else if(t.endsWith('u'))r='u32';else if(t.endsWith('b'))r='bool';else {if(!t.endsWith('h'))return console.error(`Unknown vector type ${t}. Line ${e.line}`),null;r='f16';}const a=s.getTypeName();let i='';if(a.endsWith('f'))i='f32';else if(a.endsWith('i'))i='i32';else if(a.endsWith('u'))i='u32';else if(a.endsWith('b'))i='bool';else {if(!a.endsWith('h'))return console.error(`Unknown vector type ${i}. Line ${e.line}`),null;i='f16';}const o=function(e,t,n){if(t===n)return e;const s=new Array(e.length);for(let r=0;r<e.length;r++)s[r]=nt(e[r],t,n);return s}(Array.from(n.data),r,i);return new Me(o,this.getTypeInfo(s))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var r;if(e instanceof de){if(null===e.type)return Ve.void;switch(e.type.getTypeName()){case'bool':case'i32':case'u32':case'f32':case'f16':return this._callConstructorValue(e,t);case'vec2':case'vec3':case'vec4':case'vec2f':case'vec3f':case'vec4f':case'vec2h':case'vec3h':case'vec4h':case'vec2i':case'vec3i':case'vec4i':case'vec2u':case'vec3u':case'vec4u':case'vec2b':case'vec3b':case'vec4b':return this._callConstructorVec(e,t);case'mat2x2':case'mat2x2f':case'mat2x2h':case'mat2x3':case'mat2x3f':case'mat2x3h':case'mat2x4':case'mat2x4f':case'mat2x4h':case'mat3x2':case'mat3x2f':case'mat3x2h':case'mat3x3':case'mat3x3f':case'mat3x3h':case'mat3x4':case'mat3x4f':case'mat3x4h':case'mat4x2':case'mat4x2f':case'mat4x2h':case'mat4x3':case'mat4x3f':case'mat4x3h':case'mat4x4':case'mat4x4f':case'mat4x4h':return this._callConstructorMatrix(e,t)}}const a=e instanceof de?e.type.name:e.name,i=e instanceof de?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(null===i)return console.error(`Unknown type ${a}. Line ${e.line}`),null;if(0===i.size)return null;const o=new Pe(new ArrayBuffer(i.size),i,0);if(i instanceof n){if(e.args)for(let n=0;n<e.args.length;++n){const s=i.members[n],r=e.args[n],a=this.evalExpression(r,t);o.setData(this,a,s.type,s.offset,t);}}else if(i instanceof s){let n=0;if(e.args)for(let s=0;s<e.args.length;++s){const a=e.args[s],c=this.evalExpression(a,t);null===i.format&&('x32'===(null===(r=c.typeInfo)||void 0===r?void 0:r.name)?i.format=this.getTypeInfo('i32'):i.format=c.typeInfo),o.setData(this,c,i.format,n,t),n+=i.stride;}}else console.error(`Unknown type "${a}". Line ${e.line}`);return e instanceof de?o.getSubData(this,e.postfix,t):o}_evalLiteral(e,t){const n=this.getTypeInfo(e.type),s=n.name;if('x32'===s||'u32'===s||'f32'===s||'f16'===s||'i32'===s||'bool'===s){return new Be(e.scalarValue,n)}return 'vec2'===s||'vec3'===s||'vec4'===s||'vec2f'===s||'vec3f'===s||'vec4f'===s||'vec2h'===s||'vec3h'===s||'vec4h'===s||'vec2i'===s||'vec3i'===s||'vec4i'===s||'vec2u'===s||'vec3u'===s||'vec4u'===s?this._callConstructorVec(e,t):'mat2x2'===s||'mat2x3'===s||'mat2x4'===s||'mat3x2'===s||'mat3x3'===s||'mat3x4'===s||'mat4x2'===s||'mat4x3'===s||'mat4x4'===s||'mat2x2f'===s||'mat2x3f'===s||'mat2x4f'===s||'mat3x2f'===s||'mat3x3f'===s||'mat3x4f'===s||'mat4x2f'===s||'mat4x3f'===s||'mat4x4f'===s||'mat2x2h'===s||'mat2x3h'===s||'mat2x4h'===s||'mat3x2h'===s||'mat3x3h'===s||'mat3x4h'===s||'mat4x2h'===s||'mat4x3h'===s||'mat4x4h'===s?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){const n=t.getVariableValue(e.name);return null===n?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if('f32'===t.name)return t;for(let n=1;n<e.length;++n){const s=dt._priority.get(t.name);dt._priority.get(e[n].name)<s&&(t=e[n]);}return 'x32'===t.name?this.getTypeInfo('i32'):t}_evalUnaryOp(e,t){const n=this.evalExpression(e.right,t);if('&'===e.operator)return new Oe(n);if('*'===e.operator)return n instanceof Oe?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);const s=n instanceof Be?n.value:n instanceof Me?Array.from(n.data):null;switch(e.operator){case'+':{if(Ge(s)){const e=s.map((e,t)=>+e);return new Me(e,n.typeInfo)}const e=s,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new Be(+e,t)}case'-':{if(Ge(s)){const e=s.map((e,t)=>-e);return new Me(e,n.typeInfo)}const e=s,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new Be(-e,t)}case'!':{if(Ge(s)){const e=s.map((e,t)=>e?0:1);return new Me(e,n.typeInfo)}const e=s,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new Be(e?0:1,t)}case'~':{if(Ge(s)){const e=s.map((e,t)=>~e);return new Me(e,n.typeInfo)}const e=s,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new Be(~e,t)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){const n=this.evalExpression(e.left,t),s=this.evalExpression(e.right,t),r=n instanceof Be?n.value:n instanceof Me||n instanceof Ue?Array.from(n.data):null,a=s instanceof Be?s.value:s instanceof Me||s instanceof Ue?Array.from(s.data):null;switch(e.operator){case'+':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e+s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t+e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e+t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t+i,o)}case'-':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e-s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t-e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e-t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t-i,o)}case'*':{if(Ge(r)&&Ge(a)){const t=r,i=a;if(n instanceof Ue&&s instanceof Ue){const r=function(e,t,n,s){if(void 0===pt[t.name]||void 0===pt[s.name])return null;const r=pt[t.name][0],a=pt[t.name][1],i=pt[s.name][0];if(r!==pt[s.name][1])return null;const o=new Array(i*a);for(let t=0;t<a;t++)for(let s=0;s<i;s++){let c=0;for(let i=0;i<r;i++)c+=e[i*a+t]*n[s*r+i];o[t*i+s]=c;}return o}(t,n.typeInfo,i,s.typeInfo);if(null===r)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;const a=pt[s.typeInfo.name][0],o=pt[n.typeInfo.name][1],c=this.getTypeInfo(`mat${a}x${o}f`);return new Ue(r,c)}if(n instanceof Ue&&s instanceof Me){const r=function(e,t,n,s){if(void 0===pt[t.name]||void 0===ft[s.name])return null;const r=pt[t.name][0],a=pt[t.name][1];if(r!==n.length)return null;const i=new Array(a);for(let t=0;t<a;t++){let s=0;for(let i=0;i<r;i++)s+=e[i*a+t]*n[i];i[t]=s;}return i}(t,n.typeInfo,i,s.typeInfo);return null===r?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new Me(r,s.typeInfo)}if(n instanceof Me&&s instanceof Ue){const r=function(e,t,n,s){if(void 0===ft[t.name]||void 0===pt[s.name])return null;const r=pt[s.name][0],a=pt[s.name][1];if(a!==e.length)return null;const i=[];for(let t=0;t<r;t++){let s=0;for(let i=0;i<a;i++)s+=e[i]*n[i*r+t];i[t]=s;}return i}(t,n.typeInfo,i,s.typeInfo);return null===r?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new Me(r,n.typeInfo)}{if(t.length!==i.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const s=t.map((e,t)=>e*i[t]);return new Me(s,n.typeInfo)}}if(Ge(r)){const e=a,t=r.map((t,n)=>t*e);return n instanceof Ue?new Ue(t,n.typeInfo):new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e*t);return s instanceof Ue?new Ue(t,s.typeInfo):new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t*i,o)}case'%':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e%s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t%e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e%t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t%i,o)}case'/':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e/s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t/e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e/t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t/i,o)}case'&':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e&s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t&e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e&t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t&i,o)}case'|':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e|s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t|e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e|t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t|i,o)}case'^':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e^s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t^e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e^t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t^i,o)}case'<<':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e<<s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t<<e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e<<t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t<<i,o)}case'>>':{if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e>>s[t]);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t>>e);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e>>t);return new Me(t,s.typeInfo)}const t=r,i=a,o=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new Be(t>>i,o)}case'>':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e>s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t>e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e>t?1:0);return new Me(t,s.typeInfo)}return new Be(r>a?1:0,this.getTypeInfo('bool'));case'<':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e<s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t<e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e<t?1:0);return new Me(t,s.typeInfo)}return new Be(r<a?1:0,this.getTypeInfo('bool'));case'==':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e===s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t==e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e==t?1:0);return new Me(t,s.typeInfo)}return new Be(r===a?1:0,this.getTypeInfo('bool'));case'!=':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e!==s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t!==e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e!==t?1:0);return new Me(t,s.typeInfo)}return new Be(r!==a?1:0,this.getTypeInfo('bool'));case'>=':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e>=s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t>=e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e>=t?1:0);return new Me(t,s.typeInfo)}return new Be(r>=a?1:0,this.getTypeInfo('bool'));case'<=':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e<=s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t<=e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e<=t?1:0);return new Me(t,s.typeInfo)}return new Be(r<=a?1:0,this.getTypeInfo('bool'));case'&&':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e&&s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t&&e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e&&t?1:0);return new Me(t,s.typeInfo)}return new Be(r&&a?1:0,this.getTypeInfo('bool'));case'||':if(Ge(r)&&Ge(a)){const t=r,s=a;if(t.length!==s.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const i=t.map((e,t)=>e||s[t]?1:0);return new Me(i,n.typeInfo)}if(Ge(r)){const e=a,t=r.map((t,n)=>t||e?1:0);return new Me(t,n.typeInfo)}if(Ge(a)){const e=r,t=a.map((t,n)=>e||t?1:0);return new Me(t,s.typeInfo)}return new Be(r||a?1:0,this.getTypeInfo('bool'))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(null!==e.cachedReturnValue)return e.cachedReturnValue;const n=t.clone();n.currentFunctionName=e.name;const s=t.getFunction(e.name);if(!s){if(e.isBuiltin)return this._callBuiltinFunction(e,n);return this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null)}for(let t=0;t<s.node.args.length;++t){const r=s.node.args[t],a=this.evalExpression(e.args[t],n);n.createVariable(r.name,a,r);}return this._execStatements(s.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case'all':return this.builtins.All(e,t);case'any':return this.builtins.Any(e,t);case'select':return this.builtins.Select(e,t);case'arrayLength':return this.builtins.ArrayLength(e,t);case'abs':return this.builtins.Abs(e,t);case'acos':return this.builtins.Acos(e,t);case'acosh':return this.builtins.Acosh(e,t);case'asin':return this.builtins.Asin(e,t);case'asinh':return this.builtins.Asinh(e,t);case'atan':return this.builtins.Atan(e,t);case'atanh':return this.builtins.Atanh(e,t);case'atan2':return this.builtins.Atan2(e,t);case'ceil':return this.builtins.Ceil(e,t);case'clamp':return this.builtins.Clamp(e,t);case'cos':return this.builtins.Cos(e,t);case'cosh':return this.builtins.Cosh(e,t);case'countLeadingZeros':return this.builtins.CountLeadingZeros(e,t);case'countOneBits':return this.builtins.CountOneBits(e,t);case'countTrailingZeros':return this.builtins.CountTrailingZeros(e,t);case'cross':return this.builtins.Cross(e,t);case'degrees':return this.builtins.Degrees(e,t);case'determinant':return this.builtins.Determinant(e,t);case'distance':return this.builtins.Distance(e,t);case'dot':return this.builtins.Dot(e,t);case'dot4U8Packed':return this.builtins.Dot4U8Packed(e,t);case'dot4I8Packed':return this.builtins.Dot4I8Packed(e,t);case'exp':return this.builtins.Exp(e,t);case'exp2':return this.builtins.Exp2(e,t);case'extractBits':return this.builtins.ExtractBits(e,t);case'faceForward':return this.builtins.FaceForward(e,t);case'firstLeadingBit':return this.builtins.FirstLeadingBit(e,t);case'firstTrailingBit':return this.builtins.FirstTrailingBit(e,t);case'floor':return this.builtins.Floor(e,t);case'fma':return this.builtins.Fma(e,t);case'fract':return this.builtins.Fract(e,t);case'frexp':return this.builtins.Frexp(e,t);case'insertBits':return this.builtins.InsertBits(e,t);case'inverseSqrt':return this.builtins.InverseSqrt(e,t);case'ldexp':return this.builtins.Ldexp(e,t);case'length':return this.builtins.Length(e,t);case'log':return this.builtins.Log(e,t);case'log2':return this.builtins.Log2(e,t);case'max':return this.builtins.Max(e,t);case'min':return this.builtins.Min(e,t);case'mix':return this.builtins.Mix(e,t);case'modf':return this.builtins.Modf(e,t);case'normalize':return this.builtins.Normalize(e,t);case'pow':return this.builtins.Pow(e,t);case'quantizeToF16':return this.builtins.QuantizeToF16(e,t);case'radians':return this.builtins.Radians(e,t);case'reflect':return this.builtins.Reflect(e,t);case'refract':return this.builtins.Refract(e,t);case'reverseBits':return this.builtins.ReverseBits(e,t);case'round':return this.builtins.Round(e,t);case'saturate':return this.builtins.Saturate(e,t);case'sign':return this.builtins.Sign(e,t);case'sin':return this.builtins.Sin(e,t);case'sinh':return this.builtins.Sinh(e,t);case'smoothstep':return this.builtins.SmoothStep(e,t);case'sqrt':return this.builtins.Sqrt(e,t);case'step':return this.builtins.Step(e,t);case'tan':return this.builtins.Tan(e,t);case'tanh':return this.builtins.Tanh(e,t);case'transpose':return this.builtins.Transpose(e,t);case'trunc':return this.builtins.Trunc(e,t);case'dpdx':return this.builtins.Dpdx(e,t);case'dpdxCoarse':return this.builtins.DpdxCoarse(e,t);case'dpdxFine':return this.builtins.DpdxFine(e,t);case'dpdy':return this.builtins.Dpdy(e,t);case'dpdyCoarse':return this.builtins.DpdyCoarse(e,t);case'dpdyFine':return this.builtins.DpdyFine(e,t);case'fwidth':return this.builtins.Fwidth(e,t);case'fwidthCoarse':return this.builtins.FwidthCoarse(e,t);case'fwidthFine':return this.builtins.FwidthFine(e,t);case'textureDimensions':return this.builtins.TextureDimensions(e,t);case'textureGather':return this.builtins.TextureGather(e,t);case'textureGatherCompare':return this.builtins.TextureGatherCompare(e,t);case'textureLoad':return this.builtins.TextureLoad(e,t);case'textureNumLayers':return this.builtins.TextureNumLayers(e,t);case'textureNumLevels':return this.builtins.TextureNumLevels(e,t);case'textureNumSamples':return this.builtins.TextureNumSamples(e,t);case'textureSample':return this.builtins.TextureSample(e,t);case'textureSampleBias':return this.builtins.TextureSampleBias(e,t);case'textureSampleCompare':return this.builtins.TextureSampleCompare(e,t);case'textureSampleCompareLevel':return this.builtins.TextureSampleCompareLevel(e,t);case'textureSampleGrad':return this.builtins.TextureSampleGrad(e,t);case'textureSampleLevel':return this.builtins.TextureSampleLevel(e,t);case'textureSampleBaseClampToEdge':return this.builtins.TextureSampleBaseClampToEdge(e,t);case'textureStore':return this.builtins.TextureStore(e,t);case'atomicLoad':return this.builtins.AtomicLoad(e,t);case'atomicStore':return this.builtins.AtomicStore(e,t);case'atomicAdd':return this.builtins.AtomicAdd(e,t);case'atomicSub':return this.builtins.AtomicSub(e,t);case'atomicMax':return this.builtins.AtomicMax(e,t);case'atomicMin':return this.builtins.AtomicMin(e,t);case'atomicAnd':return this.builtins.AtomicAnd(e,t);case'atomicOr':return this.builtins.AtomicOr(e,t);case'atomicXor':return this.builtins.AtomicXor(e,t);case'atomicExchange':return this.builtins.AtomicExchange(e,t);case'atomicCompareExchangeWeak':return this.builtins.AtomicCompareExchangeWeak(e,t);case'pack4x8snorm':return this.builtins.Pack4x8snorm(e,t);case'pack4x8unorm':return this.builtins.Pack4x8unorm(e,t);case'pack4xI8':return this.builtins.Pack4xI8(e,t);case'pack4xU8':return this.builtins.Pack4xU8(e,t);case'pack4x8Clamp':return this.builtins.Pack4x8Clamp(e,t);case'pack4xU8Clamp':return this.builtins.Pack4xU8Clamp(e,t);case'pack2x16snorm':return this.builtins.Pack2x16snorm(e,t);case'pack2x16unorm':return this.builtins.Pack2x16unorm(e,t);case'pack2x16float':return this.builtins.Pack2x16float(e,t);case'unpack4x8snorm':return this.builtins.Unpack4x8snorm(e,t);case'unpack4x8unorm':return this.builtins.Unpack4x8unorm(e,t);case'unpack4xI8':return this.builtins.Unpack4xI8(e,t);case'unpack4xU8':return this.builtins.Unpack4xU8(e,t);case'unpack2x16snorm':return this.builtins.Unpack2x16snorm(e,t);case'unpack2x16unorm':return this.builtins.Unpack2x16unorm(e,t);case'unpack2x16float':return this.builtins.Unpack2x16float(e,t);case'storageBarrier':return this.builtins.StorageBarrier(e,t);case'textureBarrier':return this.builtins.TextureBarrier(e,t);case'workgroupBarrier':return this.builtins.WorkgroupBarrier(e,t);case'workgroupUniformLoad':return this.builtins.WorkgroupUniformLoad(e,t);case'subgroupAdd':return this.builtins.SubgroupAdd(e,t);case'subgroupExclusiveAdd':return this.builtins.SubgroupExclusiveAdd(e,t);case'subgroupInclusiveAdd':return this.builtins.SubgroupInclusiveAdd(e,t);case'subgroupAll':return this.builtins.SubgroupAll(e,t);case'subgroupAnd':return this.builtins.SubgroupAnd(e,t);case'subgroupAny':return this.builtins.SubgroupAny(e,t);case'subgroupBallot':return this.builtins.SubgroupBallot(e,t);case'subgroupBroadcast':return this.builtins.SubgroupBroadcast(e,t);case'subgroupBroadcastFirst':return this.builtins.SubgroupBroadcastFirst(e,t);case'subgroupElect':return this.builtins.SubgroupElect(e,t);case'subgroupMax':return this.builtins.SubgroupMax(e,t);case'subgroupMin':return this.builtins.SubgroupMin(e,t);case'subgroupMul':return this.builtins.SubgroupMul(e,t);case'subgroupExclusiveMul':return this.builtins.SubgroupExclusiveMul(e,t);case'subgroupInclusiveMul':return this.builtins.SubgroupInclusiveMul(e,t);case'subgroupOr':return this.builtins.SubgroupOr(e,t);case'subgroupShuffle':return this.builtins.SubgroupShuffle(e,t);case'subgroupShuffleDown':return this.builtins.SubgroupShuffleDown(e,t);case'subgroupShuffleUp':return this.builtins.SubgroupShuffleUp(e,t);case'subgroupShuffleXor':return this.builtins.SubgroupShuffleXor(e,t);case'subgroupXor':return this.builtins.SubgroupXor(e,t);case'quadBroadcast':return this.builtins.QuadBroadcast(e,t);case'quadSwapDiagonal':return this.builtins.QuadSwapDiagonal(e,t);case'quadSwapX':return this.builtins.QuadSwapX(e,t);case'quadSwapY':return this.builtins.QuadSwapY(e,t)}const n=t.getFunction(e.name);if(n){const s=t.clone();for(let t=0;t<n.node.args.length;++t){const r=n.node.args[t],a=this.evalExpression(e.args[t],s);s.setVariable(r.name,a,r);}return this._execStatements(n.node.body,s)}return null}_callConstructorValue(e,t){if(!e.args||0===e.args.length)return new Be(0,this.getTypeInfo(e.type));const n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){const n=this.getTypeInfo(e.type),s=e.type.getTypeName(),r=ft[s];if(void 0===r)return console.error(`Invalid vec constructor ${s}. Line ${e.line}`),null;const a=[];if(e instanceof xe)if(e.isVector){const t=e.vectorValue;for(const e of t)a.push(e);}else a.push(e.scalarValue);else if(e.args)for(const n of e.args){const e=this.evalExpression(n,t);if(e instanceof Me){const t=e.data;for(let e=0;e<t.length;++e){let n=t[e];a.push(n);}}else if(e instanceof Be){let t=e.value;a.push(t);}}if(e.type instanceof ce&&null===e.type.format&&(e.type.format=ce.f32),0===a.length){const s=new Array(r).fill(0);return new Me(s,n).getSubData(this,e.postfix,t)}if(1===a.length)for(;a.length<r;)a.push(a[0]);if(a.length<r)return console.error(`Invalid vec constructor. Line ${e.line}`),null;return new Me(a.length>r?a.slice(0,r):a,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const n=this.getTypeInfo(e.type),s=e.type.getTypeName(),r=pt[s];if(void 0===r)return console.error(`Invalid matrix constructor ${s}. Line ${e.line}`),null;const i=[];if(e instanceof xe)if(e.isVector){const t=e.vectorValue;for(const e of t)i.push(e);}else i.push(e.scalarValue);else if(e.args)for(const n of e.args){const e=this.evalExpression(n,t);e instanceof Me?i.push(...e.data):e instanceof Be?i.push(e.value):e instanceof Ue&&i.push(...e.data);}if(n instanceof a&&null===n.format&&(n.format=this.getTypeInfo('f32')),0===i.length){const s=new Array(r[2]).fill(0);return new Ue(s,n).getSubData(this,e.postfix,t)}return i.length!==r[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new Ue(i,n).getSubData(this,e.postfix,t)}}dt._breakObj=new Ne(new e('BREAK',null),null),dt._continueObj=new Ne(new e('CONTINUE',null),null),dt._priority=new Map([['f32',0],['f16',1],['u32',2],['i32',3],['x32',3]]);class mt{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map;}}class gt{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new mt,this._exec=new dt,this._forwardTypeCount=0;}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const e=this._global_decl_or_directive();if(!e)break;t.push(e);}if(this._deferArrayCountEval.length>0){for(const e of this._deferArrayCountEval){const t=e.arrayType,n=e.countNode;if(n instanceof ge){const e=n.name,s=this._context.constants.get(e);if(s)try{const e=s.constEvaluate(this._exec);t.count=e;}catch(e){}}}this._deferArrayCountEval.length=0;}if(this._forwardTypeCount>0)for(const e of t)e.search(e=>{e instanceof Ce||e instanceof le?e.type=this._forwardType(e.type):e instanceof ue?e.format=this._forwardType(e.format):e instanceof F||e instanceof U||e instanceof P?e.type=this._forwardType(e.type):e instanceof D?e.returnType=this._forwardType(e.returnType):e instanceof $e&&(e.type=this._forwardType(e.type));});return t}_forwardType(e){if(e instanceof ie){const t=this._getType(e.name);if(t)return t}else e instanceof le?e.type=this._forwardType(e.type):e instanceof ue&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if('string'==typeof e){const t=new Re(e);this._tokens=t.scanTokens();}else this._tokens=e;else this._tokens=[];this._current=0;}_updateNode(e,t){return e.line=null!=t?t:this._currentLine,e}_error(e,t){return {token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==He.eof}_match(e){if(e instanceof qe)return !!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){const n=e[t];if(this._check(n))return this._advance(),!0}return !1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return !1;const t=this._peek();if(e instanceof Array){const n=t.type;let s=!1;for(const t of e){if(n===t)return !0;t===He.tokens.name&&(s=!0);}if(s){const e=He.tokens.name.rule.exec(t.lexeme);if(e&&0==e.index&&e[0]==t.lexeme)return !0}return !1}if(t.type===e)return !0;if(e===He.tokens.name){const e=He.tokens.name.rule.exec(t.lexeme);return e&&0==e.index&&e[0]==t.lexeme}return !1}_advance(){var e,t;return this._currentLine=null!==(t=null===(e=this._peek())||void 0===e?void 0:e.line)&&void 0!==t?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(He.tokens.semicolon)&&!this._isAtEnd(););if(this._match(He.keywords.alias)){const e=this._type_alias();return this._consume(He.tokens.semicolon,'Expected \';\''),this._exec.reflection.updateAST([e]),e}if(this._match(He.keywords.diagnostic)){const e=this._diagnostic();return this._consume(He.tokens.semicolon,'Expected \';\''),this._exec.reflection.updateAST([e]),e}if(this._match(He.keywords.requires)){const e=this._requires_directive();return this._consume(He.tokens.semicolon,'Expected \';\''),this._exec.reflection.updateAST([e]),e}if(this._match(He.keywords.enable)){const e=this._enable_directive();return this._consume(He.tokens.semicolon,'Expected \';\''),this._exec.reflection.updateAST([e]),e}const e=this._attribute();if(this._check(He.keywords.var)){const t=this._global_variable_decl();return null!=t&&(t.attributes=e),this._consume(He.tokens.semicolon,'Expected \';\'.'),this._exec.reflection.updateAST([t]),t}if(this._check(He.keywords.override)){const t=this._override_variable_decl();return null!=t&&(t.attributes=e),this._consume(He.tokens.semicolon,'Expected \';\'.'),this._exec.reflection.updateAST([t]),t}if(this._check(He.keywords.let)){const t=this._global_let_decl();return null!=t&&(t.attributes=e),this._consume(He.tokens.semicolon,'Expected \';\'.'),this._exec.reflection.updateAST([t]),t}if(this._check(He.keywords.const)){const t=this._global_const_decl();return null!=t&&(t.attributes=e),this._consume(He.tokens.semicolon,'Expected \';\'.'),this._exec.reflection.updateAST([t]),t}if(this._check(He.keywords.struct)){const t=this._struct_decl();return null!=t&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(He.keywords.fn)){const t=this._function_decl();return null!=t&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(He.keywords.fn))return null;const e=this._currentLine,t=this._consume(He.tokens.ident,'Expected function name.').toString();this._consume(He.tokens.paren_left,'Expected \'(\' for function arguments.');const n=[];if(!this._check(He.tokens.paren_right))do{if(this._check(He.tokens.paren_right))break;const e=this._attribute(),t=this._consume(He.tokens.name,'Expected argument name.').toString();this._consume(He.tokens.colon,'Expected \':\' for argument type.');const s=this._attribute(),r=this._type_decl();null!=r&&(r.attributes=s,n.push(this._updateNode(new $e(t,r,e))));}while(this._match(He.tokens.comma));this._consume(He.tokens.paren_right,'Expected \')\' after function arguments.');let s=null;if(this._match(He.tokens.arrow)){const e=this._attribute();s=this._type_decl(),null!=s&&(s.attributes=e);}const r=this._compound_statement(),a=this._currentLine;return this._updateNode(new D(t,n,s,r,e,a),e)}_compound_statement(){const e=[];for(this._consume(He.tokens.brace_left,'Expected \'{\' for block.');!this._check(He.tokens.brace_right);){const t=this._statement();null!==t&&e.push(t);}return this._consume(He.tokens.brace_right,'Expected \'}\' for block.'),e}_statement(){for(;this._match(He.tokens.semicolon)&&!this._isAtEnd(););if(this._check(He.tokens.attr)&&this._attribute(),this._check(He.keywords.if))return this._if_statement();if(this._check(He.keywords.switch))return this._switch_statement();if(this._check(He.keywords.loop))return this._loop_statement();if(this._check(He.keywords.for))return this._for_statement();if(this._check(He.keywords.while))return this._while_statement();if(this._check(He.keywords.continuing))return this._continuing_statement();if(this._check(He.keywords.static_assert))return this._static_assert_statement();if(this._check(He.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(He.keywords.return))e=this._return_statement();else if(this._check([He.keywords.var,He.keywords.let,He.keywords.const]))e=this._variable_statement();else if(this._match(He.keywords.discard))e=this._updateNode(new ne);else if(this._match(He.keywords.break)){const t=this._updateNode(new se);if(this._currentLoop.length>0){const e=this._currentLoop[this._currentLoop.length-1];t.loopId=e.id;}e=t,this._check(He.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression());}else if(this._match(He.keywords.continue)){const t=this._updateNode(new re);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const e=this._currentLoop[this._currentLoop.length-1];t.loopId=e.id;}e=t;}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return null!=e&&this._consume(He.tokens.semicolon,'Expected \';\' after statement.'),e}_static_assert_statement(){if(!this._match(He.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new N(t),e)}_while_statement(){if(!this._match(He.keywords.while))return null;const e=this._updateNode(new V(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(He.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){const e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(He.keywords.continuing))return null;const t=this._currentLine,n=this._compound_statement();return this._updateNode(new O(n,e),t)}_for_statement(){if(!this._match(He.keywords.for))return null;this._consume(He.tokens.paren_left,'Expected \'(\'.');const e=this._updateNode(new B(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(He.tokens.semicolon)?null:this._for_init(),this._consume(He.tokens.semicolon,'Expected \';\'.'),e.condition=this._check(He.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(He.tokens.semicolon,'Expected \';\'.'),e.increment=this._check(He.tokens.paren_right)?null:this._for_increment(),this._consume(He.tokens.paren_right,'Expected \')\'.'),this._check(He.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(He.keywords.var)){const e=this._variable_decl();if(null===e)throw this._error(this._peek(),'Variable declaration expected.');let t=null;return this._match(He.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new F(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(He.keywords.let)){const e=this._currentLine,t=this._consume(He.tokens.name,'Expected name for let.').toString();let n=null;if(this._match(He.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e);}this._consume(He.tokens.equal,'Expected \'=\' for let.');const s=this._short_circuit_or_expression();return this._updateNode(new U(t,n,null,null,s),e)}if(this._match(He.keywords.const)){const e=this._currentLine,t=this._consume(He.tokens.name,'Expected name for const.').toString();let n=null;if(this._match(He.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e);}this._consume(He.tokens.equal,'Expected \'=\' for const.');const s=this._short_circuit_or_expression();return null===n&&s instanceof xe&&(n=s.type),this._updateNode(new P(t,n,null,null,s),e)}return null}_increment_decrement_statement(){const e=this._current,t=this._unary_expression();if(null==t)return null;if(!this._check(He.increment_operators))return this._current=e,null;const n=this._consume(He.increment_operators,'Expected increment operator');return this._updateNode(new R(n.type===He.tokens.plus_plus?W.increment:W.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(He.tokens.brace_right))return null;let n=this._match(He.tokens.underscore);if(n||(e=this._unary_expression()),!n&&null==e)return null;const s=this._consume(He.assignment_operators,'Expected assignment operator.'),r=this._short_circuit_or_expression();return this._updateNode(new G(q.parse(s.lexeme),e,r),t)}_func_call_statement(){if(!this._check(He.tokens.ident))return null;const e=this._currentLine,t=this._current,n=this._consume(He.tokens.ident,'Expected function name.'),s=this._argument_expression_list();return null===s?(this._current=t,null):this._updateNode(new X(n.lexeme,s),e)}_loop_statement(){if(!this._match(He.keywords.loop))return null;this._check(He.tokens.attr)&&this._attribute(),this._consume(He.tokens.brace_left,'Expected \'{\' for loop.');const e=this._updateNode(new j([],null));this._currentLoop.push(e);let t=this._statement();for(;null!==t;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof O){e.continuing=t;break}t=this._statement();}return this._currentLoop.pop(),this._consume(He.tokens.brace_right,'Expected \'}\' for loop.'),e}_switch_statement(){if(!this._match(He.keywords.switch))return null;const e=this._updateNode(new Z(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(He.tokens.attr)&&this._attribute(),this._consume(He.tokens.brace_left,'Expected \'{\' for switch.'),e.cases=this._switch_body(),null==e.cases||0==e.cases.length)throw this._error(this._previous(),'Expected \'case\' or \'default\'.');return this._consume(He.tokens.brace_right,'Expected \'}\' for switch.'),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([He.keywords.default,He.keywords.case]);){if(this._match(He.keywords.case)){const n=this._case_selectors();for(const e of n)if(e instanceof Se){if(t)throw this._error(this._previous(),'Multiple default cases in switch statement.');t=!0;break}this._match(He.tokens.colon),this._check(He.tokens.attr)&&this._attribute(),this._consume(He.tokens.brace_left,'Exected \'{\' for switch case.');const s=this._case_body();this._consume(He.tokens.brace_right,'Exected \'}\' for switch case.'),e.push(this._updateNode(new Ae(n,s)));}if(this._match(He.keywords.default)){if(t)throw this._error(this._previous(),'Multiple default cases in switch statement.');this._match(He.tokens.colon),this._check(He.tokens.attr)&&this._attribute(),this._consume(He.tokens.brace_left,'Exected \'{\' for switch default.');const n=this._case_body();this._consume(He.tokens.brace_right,'Exected \'}\' for switch default.'),e.push(this._updateNode(new Ee(n)));}}return e}_case_selectors(){const e=[];for(this._match(He.keywords.default)?e.push(this._updateNode(new Se)):e.push(this._shift_expression());this._match(He.tokens.comma);)this._match(He.keywords.default)?e.push(this._updateNode(new Se)):e.push(this._shift_expression());return e}_case_body(){if(this._match(He.keywords.fallthrough))return this._consume(He.tokens.semicolon,'Expected \';\''),[];let e=this._statement();if(null==e)return [];e instanceof Array||(e=[e]);const t=this._case_body();return 0==t.length?e:[...e,t[0]]}_if_statement(){if(!this._match(He.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(He.tokens.attr)&&this._attribute();const n=this._compound_statement();let s=[];this._match_elseif()&&(this._check(He.tokens.attr)&&this._attribute(),s=this._elseif_statement(s));let r=null;return this._match(He.keywords.else)&&(this._check(He.tokens.attr)&&this._attribute(),r=this._compound_statement()),this._updateNode(new Q(t,n,s,r),e)}_match_elseif(){return this._tokens[this._current].type===He.keywords.else&&this._tokens[this._current+1].type===He.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){const t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new Le(t,n))),this._match_elseif()&&(this._check(He.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(He.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new Y(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(He.tokens.or_or);)e=this._updateNode(new Ie(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(He.tokens.and_and);)e=this._updateNode(new Ie(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(He.tokens.or);)e=this._updateNode(new Ie(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(He.tokens.xor);)e=this._updateNode(new Ie(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(He.tokens.and);)e=this._updateNode(new Ie(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([He.tokens.equal_equal,He.tokens.not_equal])?this._updateNode(new Ie(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([He.tokens.less_than,He.tokens.greater_than,He.tokens.less_than_equal,He.tokens.greater_than_equal]);)e=this._updateNode(new Ie(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([He.tokens.shift_left,He.tokens.shift_right]);)e=this._updateNode(new Ie(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([He.tokens.plus,He.tokens.minus]);)e=this._updateNode(new Ie(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([He.tokens.star,He.tokens.forward_slash,He.tokens.modulo]);)e=this._updateNode(new Ie(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([He.tokens.minus,He.tokens.bang,He.tokens.tilde,He.tokens.star,He.tokens.and])?this._updateNode(new ke(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){const e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(He.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(He.tokens.bracket_right,'Expected \']\'.');const t=this._updateNode(new ve(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(He.tokens.period)){const e=this._consume(He.tokens.name,'Expected member name.'),t=this._postfix_expression(),n=this._updateNode(new pe(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){if(this._context.aliases.has(e)){return this._context.aliases.get(e).type}if(this._context.structs.has(e)){return this._context.structs.get(e)}return null}_getType(e){const t=this._getStruct(e);if(null!==t)return t;switch(e){case'void':return ae.void;case'bool':return ae.bool;case'i32':return ae.i32;case'u32':return ae.u32;case'f32':return ae.f32;case'f16':return ae.f16;case'vec2f':return ce.vec2f;case'vec3f':return ce.vec3f;case'vec4f':return ce.vec4f;case'vec2i':return ce.vec2i;case'vec3i':return ce.vec3i;case'vec4i':return ce.vec4i;case'vec2u':return ce.vec2u;case'vec3u':return ce.vec3u;case'vec4u':return ce.vec4u;case'vec2h':return ce.vec2h;case'vec3h':return ce.vec3h;case'vec4h':return ce.vec4h;case'mat2x2f':return ce.mat2x2f;case'mat2x3f':return ce.mat2x3f;case'mat2x4f':return ce.mat2x4f;case'mat3x2f':return ce.mat3x2f;case'mat3x3f':return ce.mat3x3f;case'mat3x4f':return ce.mat3x4f;case'mat4x2f':return ce.mat4x2f;case'mat4x3f':return ce.mat4x3f;case'mat4x4f':return ce.mat4x4f;case'mat2x2h':return ce.mat2x2h;case'mat2x3h':return ce.mat2x3h;case'mat2x4h':return ce.mat2x4h;case'mat3x2h':return ce.mat3x2h;case'mat3x3h':return ce.mat3x3h;case'mat3x4h':return ce.mat3x4h;case'mat4x2h':return ce.mat4x2h;case'mat4x3h':return ce.mat4x3h;case'mat4x4h':return ce.mat4x4h;case'mat2x2i':return ce.mat2x2i;case'mat2x3i':return ce.mat2x3i;case'mat2x4i':return ce.mat2x4i;case'mat3x2i':return ce.mat3x2i;case'mat3x3i':return ce.mat3x3i;case'mat3x4i':return ce.mat3x4i;case'mat4x2i':return ce.mat4x2i;case'mat4x3i':return ce.mat4x3i;case'mat4x4i':return ce.mat4x4i;case'mat2x2u':return ce.mat2x2u;case'mat2x3u':return ce.mat2x3u;case'mat2x4u':return ce.mat2x4u;case'mat3x2u':return ce.mat3x2u;case'mat3x3u':return ce.mat3x3u;case'mat3x4u':return ce.mat3x4u;case'mat4x2u':return ce.mat4x2u;case'mat4x3u':return ce.mat4x3u;case'mat4x4u':return ce.mat4x4u}return null}_validateTypeRange(e,t){if('i32'===t.name){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if('u32'===t.name&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(He.tokens.ident)){const e=this._previous().toString();if(this._check(He.tokens.paren_left)){const t=this._argument_expression_list(),n=this._getType(e);return null!==n?this._updateNode(new de(n,t)):this._updateNode(new me(e,t))}if(this._context.constants.has(e)){const t=this._context.constants.get(e);return this._updateNode(new _e(e,t.value))}return this._updateNode(new ge(e))}if(this._match(He.tokens.int_literal)){const e=this._previous().toString();let t=e.endsWith('i')||e.endsWith('i')?ae.i32:e.endsWith('u')||e.endsWith('U')?ae.u32:ae.x32;const n=parseInt(e);return this._validateTypeRange(n,t),this._updateNode(new xe(new Be(n,this._exec.getTypeInfo(t)),t))}if(this._match(He.tokens.uint_literal)){const e=parseInt(this._previous().toString());return this._validateTypeRange(e,ae.u32),this._updateNode(new xe(new Be(e,this._exec.getTypeInfo(ae.u32)),ae.u32))}if(this._match([He.tokens.decimal_float_literal,He.tokens.hex_float_literal])){let e=this._previous().toString(),t=e.endsWith('h');t&&(e=e.substring(0,e.length-1));const n=parseFloat(e);this._validateTypeRange(n,t?ae.f16:ae.f32);const s=t?ae.f16:ae.f32;return this._updateNode(new xe(new Be(n,this._exec.getTypeInfo(s)),s))}if(this._match([He.keywords.true,He.keywords.false])){let e=this._previous().toString()===He.keywords.true.rule;return this._updateNode(new xe(new Be(e?1:0,this._exec.getTypeInfo(ae.bool)),ae.bool))}if(this._check(He.tokens.paren_left))return this._paren_expression();if(this._match(He.keywords.bitcast)){this._consume(He.tokens.less_than,'Expected \'<\'.');const e=this._type_decl();this._consume(He.tokens.greater_than,'Expected \'>\'.');const t=this._paren_expression();return this._updateNode(new ye(e,t))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new de(e,t))}_argument_expression_list(){if(!this._match(He.tokens.paren_left))return null;const e=[];do{if(this._check(He.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t);}while(this._match(He.tokens.comma));return this._consume(He.tokens.paren_right,'Expected \')\' for agument list'),e}_optional_paren_expression(){this._match(He.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(He.tokens.paren_right),e}_paren_expression(){this._consume(He.tokens.paren_left,'Expected \'(\'.');const e=this._short_circuit_or_expression();return this._consume(He.tokens.paren_right,'Expected \')\'.'),e}_struct_decl(){if(!this._match(He.keywords.struct))return null;const e=this._currentLine,t=this._consume(He.tokens.ident,'Expected name for struct.').toString();this._consume(He.tokens.brace_left,'Expected \'{\' for struct body.');const n=[];for(;!this._check(He.tokens.brace_right);){const e=this._attribute(),t=this._consume(He.tokens.name,'Expected variable name.').toString();this._consume(He.tokens.colon,'Expected \':\' for struct member type.');const s=this._attribute(),r=this._type_decl();null!=r&&(r.attributes=s),this._check(He.tokens.brace_right)?this._match(He.tokens.comma):this._consume(He.tokens.comma,'Expected \',\' for struct member.'),n.push(this._updateNode(new Ce(t,r,e)));}this._consume(He.tokens.brace_right,'Expected \'}\' after struct body.');const s=this._currentLine,r=this._updateNode(new oe(t,n,e,s),e);return this._context.structs.set(t,r),r}_global_variable_decl(){const e=this._variable_decl();if(!e)return null;if(this._match(He.tokens.equal)){const t=this._const_expression();e.value=t;}if(null!==e.type&&e.value instanceof xe){if('x32'!==e.value.type.name){if(e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`)}e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type;}else null===e.type&&e.value instanceof xe&&(e.type='x32'===e.value.type.name?ae.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){const e=this._override_decl();return e&&this._match(He.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(He.keywords.const))return null;const t=this._consume(He.tokens.name,'Expected variable name'),n=this._currentLine;let s=null;if(this._match(He.tokens.colon)){const e=this._attribute();s=this._type_decl(),null!=s&&(s.attributes=e);}let r=null;this._consume(He.tokens.equal,'const declarations require an assignment');const i=this._short_circuit_or_expression();try{let e=[ae.f32],n=i.constEvaluate(this._exec,e);n instanceof Be&&this._validateTypeRange(n.value,e[0]),e[0]instanceof ce&&null===e[0].format&&n.typeInfo instanceof a&&null!==n.typeInfo.format&&('f16'===n.typeInfo.format.name?e[0].format=ae.f16:'f32'===n.typeInfo.format.name?e[0].format=ae.f32:'i32'===n.typeInfo.format.name?e[0].format=ae.i32:'u32'===n.typeInfo.format.name?e[0].format=ae.u32:'bool'===n.typeInfo.format.name?e[0].format=ae.bool:console.error(`TODO: impelement template format type ${n.typeInfo.format.name}`)),r=this._updateNode(new xe(n,e[0])),this._exec.context.setVariable(t.toString(),n);}catch(e){r=i;}if(null!==s&&r instanceof xe){if('x32'!==r.type.name){if(s.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${s.name}. Line:${this._currentLine}`)}r.type=s,r.isScalar&&this._validateTypeRange(r.scalarValue,r.type);}else null===s&&r instanceof xe&&(s=null!==(e=null==r?void 0:r.type)&&void 0!==e?e:ae.f32,s===ae.x32&&(s=ae.i32));const o=this._updateNode(new P(t.toString(),s,'','',r),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(He.keywords.let))return null;const e=this._currentLine,t=this._consume(He.tokens.name,'Expected variable name');let n=null;if(this._match(He.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e);}let s=null;if(this._match(He.tokens.equal)&&(s=this._const_expression()),null!==n&&s instanceof xe){if('x32'!==s.type.name){if(n.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${n.name}. Line:${this._currentLine}`)}s.type=n;}else null===n&&s instanceof xe&&(n='x32'===s.type.name?ae.i32:s.type);return s instanceof xe&&s.isScalar&&this._validateTypeRange(s.scalarValue,n),this._updateNode(new U(t.toString(),n,'','',s),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(He.keywords.var))return null;const e=this._currentLine;let t='',n='';this._match(He.tokens.less_than)&&(t=this._consume(He.storage_class,'Expected storage_class.').toString(),this._match(He.tokens.comma)&&(n=this._consume(He.access_mode,'Expected access_mode.').toString()),this._consume(He.tokens.greater_than,'Expected \'>\'.'));const s=this._consume(He.tokens.name,'Expected variable name');let r=null;if(this._match(He.tokens.colon)){const e=this._attribute();r=this._type_decl(),null!=r&&(r.attributes=e);}return this._updateNode(new F(s.toString(),r,t,n,null),e)}_override_decl(){if(!this._match(He.keywords.override))return null;const e=this._consume(He.tokens.name,'Expected variable name');let t=null;if(this._match(He.tokens.colon)){const e=this._attribute();t=this._type_decl(),null!=t&&(t.attributes=e);}return this._updateNode(new M(e.toString(),t,null))}_diagnostic(){this._consume(He.tokens.paren_left,'Expected \'(\'');const e=this._consume(He.tokens.ident,'Expected severity control name.');this._consume(He.tokens.comma,'Expected \',\'');let t=this._consume(He.tokens.ident,'Expected diagnostic rule name.').toString();if(this._match(He.tokens.period)){t+=`.${this._consume(He.tokens.ident,'Expected diagnostic message.').toString()}`;}return this._consume(He.tokens.paren_right,'Expected \')\''),this._updateNode(new ee(e.toString(),t))}_enable_directive(){const e=this._consume(He.tokens.ident,'identity expected.');return this._updateNode(new K(e.toString()))}_requires_directive(){const e=[this._consume(He.tokens.ident,'identity expected.').toString()];for(;this._match(He.tokens.comma);){const t=this._consume(He.tokens.ident,'identity expected.');e.push(t.toString());}return this._updateNode(new J(e))}_type_alias(){const e=this._consume(He.tokens.ident,'identity expected.');this._consume(He.tokens.equal,'Expected \'=\' for type alias.');let t=this._type_decl();if(null===t)throw this._error(this._peek(),'Expected Type for Alias.');this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);const n=this._updateNode(new te(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([He.tokens.ident,...He.texel_format,He.keywords.bool,He.keywords.f32,He.keywords.i32,He.keywords.u32])){const e=this._advance().toString();if(this._context.structs.has(e))return this._context.structs.get(e);if(this._context.aliases.has(e))return this._context.aliases.get(e).type;if(!this._getType(e)){const t=this._updateNode(new ie(e));return this._forwardTypeCount++,t}return this._updateNode(new ae(e))}let e=this._texture_sampler_types();if(e)return e;if(this._check(He.template_types)){let e=this._advance().toString(),t=null,n=null;this._match(He.tokens.less_than)&&(t=this._type_decl(),n=null,this._match(He.tokens.comma)&&(n=this._consume(He.access_mode,'Expected access_mode for pointer').toString()),this._consume(He.tokens.greater_than,'Expected \'>\' for type.'));return this._updateNode(new ce(e,t,n))}if(this._match(He.keywords.ptr)){let e=this._previous().toString();this._consume(He.tokens.less_than,'Expected \'<\' for pointer.');const t=this._consume(He.storage_class,'Expected storage_class for pointer');this._consume(He.tokens.comma,'Expected \',\' for pointer.');const n=this._type_decl();let s=null;this._match(He.tokens.comma)&&(s=this._consume(He.access_mode,'Expected access_mode for pointer').toString()),this._consume(He.tokens.greater_than,'Expected \'>\' for pointer.');return this._updateNode(new le(e,t.toString(),n,s))}const t=this._attribute();if(this._match(He.keywords.array)){let e=null,n=-1;const s=this._previous();let r=null;if(this._match(He.tokens.less_than)){e=this._type_decl(),this._context.aliases.has(e.name)&&(e=this._context.aliases.get(e.name).type);let t='';if(this._match(He.tokens.comma)){r=this._shift_expression();try{t=r.constEvaluate(this._exec).toString(),r=null;}catch(e){t='1';}}this._consume(He.tokens.greater_than,'Expected \'>\' for array.'),n=t?parseInt(t):0;}const a=this._updateNode(new ue(s.toString(),t,e,n));return r&&this._deferArrayCountEval.push({arrayType:a,countNode:r}),a}return null}_texture_sampler_types(){if(this._match(He.sampler_type))return this._updateNode(new he(this._previous().toString(),null,null));if(this._match(He.depth_texture_type))return this._updateNode(new he(this._previous().toString(),null,null));if(this._match(He.sampled_texture_type)||this._match(He.multisampled_texture_type)){const e=this._previous();this._consume(He.tokens.less_than,'Expected \'<\' for sampler type.');const t=this._type_decl();return this._consume(He.tokens.greater_than,'Expected \'>\' for sampler type.'),this._updateNode(new he(e.toString(),t,null))}if(this._match(He.storage_texture_type)){const e=this._previous();this._consume(He.tokens.less_than,'Expected \'<\' for sampler type.');const t=this._consume(He.texel_format,'Invalid texel format.').toString();this._consume(He.tokens.comma,'Expected \',\' after texel format.');const n=this._consume(He.access_mode,'Expected access mode for storage texture type.').toString();return this._consume(He.tokens.greater_than,'Expected \'>\' for sampler type.'),this._updateNode(new he(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(He.tokens.attr);){const t=this._consume(He.attribute_name,'Expected attribute name'),n=this._updateNode(new De(t.toString(),null));if(this._match(He.tokens.paren_left)){if(n.value=this._consume(He.literal_or_ident,'Expected attribute value').toString(),this._check(He.tokens.comma)){this._advance();do{const e=this._consume(He.literal_or_ident,'Expected attribute value').toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(e);}while(this._match(He.tokens.comma))}this._consume(He.tokens.paren_right,'Expected \')\'');}e.push(n);}return 0==e.length?null:e}}class _t extends at{constructor(e){super(),e&&this.update(e);}update(e){const t=(new gt).parse(e);this.updateAST(t);}}
|
|
13188
9116
|
|
|
13189
9117
|
// luma.gl
|
|
13190
9118
|
/**
|
|
@@ -13242,7 +9170,7 @@ ${htmlLog}
|
|
|
13242
9170
|
}
|
|
13243
9171
|
function parseWGSL(source) {
|
|
13244
9172
|
try {
|
|
13245
|
-
return new
|
|
9173
|
+
return new _t(source);
|
|
13246
9174
|
}
|
|
13247
9175
|
catch (error) {
|
|
13248
9176
|
if (error instanceof Error) {
|
|
@@ -42290,11 +38218,13 @@ DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
|
42290
38218
|
cutoff = 0.25,
|
|
42291
38219
|
fontFamily = 'sans-serif',
|
|
42292
38220
|
fontWeight = 'normal',
|
|
42293
|
-
fontStyle = 'normal'
|
|
38221
|
+
fontStyle = 'normal',
|
|
38222
|
+
lang = null
|
|
42294
38223
|
} = {}) {
|
|
42295
38224
|
this.buffer = buffer;
|
|
42296
38225
|
this.cutoff = cutoff;
|
|
42297
38226
|
this.radius = radius;
|
|
38227
|
+
this.lang = lang;
|
|
42298
38228
|
|
|
42299
38229
|
// make the canvas size big enough to both have the specified buffer around the glyph
|
|
42300
38230
|
// for "halo", and account for some glyphs possibly being larger than their font size
|
|
@@ -42349,6 +38279,7 @@ DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
|
42349
38279
|
if (glyphWidth === 0 || glyphHeight === 0) return glyph;
|
|
42350
38280
|
|
|
42351
38281
|
const {ctx, buffer, gridInner, gridOuter} = this;
|
|
38282
|
+
if (this.lang) ctx.lang = this.lang;
|
|
42352
38283
|
ctx.clearRect(buffer, buffer, glyphWidth, glyphHeight);
|
|
42353
38284
|
ctx.fillText(char, buffer, buffer + glyphTop);
|
|
42354
38285
|
const imgData = ctx.getImageData(buffer, buffer, glyphWidth, glyphHeight);
|
|
@@ -46137,7 +42068,7 @@ void main(void) {
|
|
|
46137
42068
|
|
|
46138
42069
|
const fullMarker = config.model.markers?.bubble;
|
|
46139
42070
|
const fullMarkerLegend = config.model.markers?.legend;
|
|
46140
|
-
config.Vizabi.utils.applyDefaults(fullMarker?.config, BubbleChart.DEFAULT_MODEL.bubble);
|
|
42071
|
+
config.Vizabi.utils.applyDefaults(fullMarker?.config || {}, BubbleChart.DEFAULT_MODEL.bubble);
|
|
46141
42072
|
config.Vizabi.utils.applyDefaults(fullMarkerLegend?.config || {}, BubbleChart.DEFAULT_MODEL.legend);
|
|
46142
42073
|
|
|
46143
42074
|
const frameType = config.Vizabi.stores.encodings.modelTypes.frame;
|
|
@@ -46430,7 +42361,7 @@ void main(void) {
|
|
|
46430
42361
|
},
|
|
46431
42362
|
};
|
|
46432
42363
|
|
|
46433
|
-
BubbleChart.versionInfo = { version: "5.4.
|
|
42364
|
+
BubbleChart.versionInfo = { version: "5.4.3", build: 1763849734772, package: {"homepage":"https://github.com/vizabi/bubblechart#readme","name":"@vizabi/bubblechart","description":"Vizabi bubble chart"}, sharedComponents: sharedComponents.versionInfo};
|
|
46434
42365
|
|
|
46435
42366
|
exports.Base = BubbleChart;
|
|
46436
42367
|
|