@luma.gl/shadertools 9.0.15 → 9.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +784 -173
- package/dist/dist.min.js +75 -75
- package/dist/index.cjs +15 -2832
- package/dist/index.cjs.map +4 -4
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +5 -5
- package/package.json +4 -3
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +5 -5
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.d.ts +0 -1112
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.d.ts.map +0 -1
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.js +0 -3389
- package/src/libs/wgsl-reflect/wgsl_reflect.module.js +0 -3394
- package/src/libs/wgsl-reflect/wgsl_reflect.module.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -355,8 +355,8 @@ ${moduleSource}
|
|
|
355
355
|
// Warn about deprecated uniforms or functions
|
|
356
356
|
checkDeprecations(shaderSource, log2) {
|
|
357
357
|
this.deprecations.forEach((def) => {
|
|
358
|
-
var
|
|
359
|
-
if ((
|
|
358
|
+
var _a;
|
|
359
|
+
if ((_a = def.regex) == null ? void 0 : _a.test(shaderSource)) {
|
|
360
360
|
if (def.deprecated) {
|
|
361
361
|
log2.deprecated(def.old, def.new)();
|
|
362
362
|
} else {
|
|
@@ -491,8 +491,8 @@ function getPlatformShaderDefines(platformInfo) {
|
|
|
491
491
|
|
|
492
492
|
// dist/lib/shader-transpiler/transpile-glsl-shader.js
|
|
493
493
|
function transpileGLSLShader(source, stage) {
|
|
494
|
-
var
|
|
495
|
-
const sourceGLSLVersion = Number(((
|
|
494
|
+
var _a;
|
|
495
|
+
const sourceGLSLVersion = Number(((_a = source.match(/^#version[ \t]+(\d+)/m)) == null ? void 0 : _a[1]) || 100);
|
|
496
496
|
if (sourceGLSLVersion !== 300) {
|
|
497
497
|
throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");
|
|
498
498
|
}
|
|
@@ -1162,2826 +1162,9 @@ function generateShaderForModule(module2, options) {
|
|
|
1162
1162
|
|
|
1163
1163
|
// dist/lib/wgsl/get-shader-layout-wgsl.js
|
|
1164
1164
|
var import_core = require("@luma.gl/core");
|
|
1165
|
-
|
|
1166
|
-
// dist/libs/wgsl-reflect/wgsl_reflect.module.js
|
|
1167
|
-
var ParseContext = class {
|
|
1168
|
-
constructor() {
|
|
1169
|
-
this.constants = /* @__PURE__ */ new Map();
|
|
1170
|
-
this.aliases = /* @__PURE__ */ new Map();
|
|
1171
|
-
this.structs = /* @__PURE__ */ new Map();
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
|
-
var Node = class {
|
|
1175
|
-
constructor() {
|
|
1176
|
-
}
|
|
1177
|
-
get isAstNode() {
|
|
1178
|
-
return true;
|
|
1179
|
-
}
|
|
1180
|
-
get astNodeType() {
|
|
1181
|
-
return "";
|
|
1182
|
-
}
|
|
1183
|
-
evaluate(context) {
|
|
1184
|
-
throw new Error("Cannot evaluate node");
|
|
1185
|
-
}
|
|
1186
|
-
evaluateString(context) {
|
|
1187
|
-
return this.evaluate(context).toString();
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
var Statement = class extends Node {
|
|
1191
|
-
constructor() {
|
|
1192
|
-
super();
|
|
1193
|
-
}
|
|
1194
|
-
};
|
|
1195
|
-
var Function = class extends Statement {
|
|
1196
|
-
constructor(name, args, returnType, body) {
|
|
1197
|
-
super();
|
|
1198
|
-
this.name = name;
|
|
1199
|
-
this.args = args;
|
|
1200
|
-
this.returnType = returnType;
|
|
1201
|
-
this.body = body;
|
|
1202
|
-
}
|
|
1203
|
-
get astNodeType() {
|
|
1204
|
-
return "function";
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
var StaticAssert = class extends Statement {
|
|
1208
|
-
constructor(expression) {
|
|
1209
|
-
super();
|
|
1210
|
-
this.expression = expression;
|
|
1211
|
-
}
|
|
1212
|
-
get astNodeType() {
|
|
1213
|
-
return "staticAssert";
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1216
|
-
var While = class extends Statement {
|
|
1217
|
-
constructor(condition, body) {
|
|
1218
|
-
super();
|
|
1219
|
-
this.condition = condition;
|
|
1220
|
-
this.body = body;
|
|
1221
|
-
}
|
|
1222
|
-
get astNodeType() {
|
|
1223
|
-
return "while";
|
|
1224
|
-
}
|
|
1225
|
-
};
|
|
1226
|
-
var Continuing = class extends Statement {
|
|
1227
|
-
constructor(body) {
|
|
1228
|
-
super();
|
|
1229
|
-
this.body = body;
|
|
1230
|
-
}
|
|
1231
|
-
get astNodeType() {
|
|
1232
|
-
return "continuing";
|
|
1233
|
-
}
|
|
1234
|
-
};
|
|
1235
|
-
var For = class extends Statement {
|
|
1236
|
-
constructor(init, condition, increment, body) {
|
|
1237
|
-
super();
|
|
1238
|
-
this.init = init;
|
|
1239
|
-
this.condition = condition;
|
|
1240
|
-
this.increment = increment;
|
|
1241
|
-
this.body = body;
|
|
1242
|
-
}
|
|
1243
|
-
get astNodeType() {
|
|
1244
|
-
return "for";
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
var Var = class extends Statement {
|
|
1248
|
-
constructor(name, type, storage, access, value) {
|
|
1249
|
-
super();
|
|
1250
|
-
this.name = name;
|
|
1251
|
-
this.type = type;
|
|
1252
|
-
this.storage = storage;
|
|
1253
|
-
this.access = access;
|
|
1254
|
-
this.value = value;
|
|
1255
|
-
}
|
|
1256
|
-
get astNodeType() {
|
|
1257
|
-
return "var";
|
|
1258
|
-
}
|
|
1259
|
-
};
|
|
1260
|
-
var Override = class extends Statement {
|
|
1261
|
-
constructor(name, type, value) {
|
|
1262
|
-
super();
|
|
1263
|
-
this.name = name;
|
|
1264
|
-
this.type = type;
|
|
1265
|
-
this.value = value;
|
|
1266
|
-
}
|
|
1267
|
-
get astNodeType() {
|
|
1268
|
-
return "override";
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
var Let = class extends Statement {
|
|
1272
|
-
constructor(name, type, storage, access, value) {
|
|
1273
|
-
super();
|
|
1274
|
-
this.name = name;
|
|
1275
|
-
this.type = type;
|
|
1276
|
-
this.storage = storage;
|
|
1277
|
-
this.access = access;
|
|
1278
|
-
this.value = value;
|
|
1279
|
-
}
|
|
1280
|
-
get astNodeType() {
|
|
1281
|
-
return "let";
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
var Const = class extends Statement {
|
|
1285
|
-
constructor(name, type, storage, access, value) {
|
|
1286
|
-
super();
|
|
1287
|
-
this.name = name;
|
|
1288
|
-
this.type = type;
|
|
1289
|
-
this.storage = storage;
|
|
1290
|
-
this.access = access;
|
|
1291
|
-
this.value = value;
|
|
1292
|
-
}
|
|
1293
|
-
get astNodeType() {
|
|
1294
|
-
return "const";
|
|
1295
|
-
}
|
|
1296
|
-
evaluate(context) {
|
|
1297
|
-
return this.value.evaluate(context);
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
var IncrementOperator;
|
|
1301
|
-
(function(IncrementOperator2) {
|
|
1302
|
-
IncrementOperator2["increment"] = "++";
|
|
1303
|
-
IncrementOperator2["decrement"] = "--";
|
|
1304
|
-
})(IncrementOperator || (IncrementOperator = {}));
|
|
1305
|
-
(function(IncrementOperator2) {
|
|
1306
|
-
function parse(val) {
|
|
1307
|
-
const key = val;
|
|
1308
|
-
if (key == "parse")
|
|
1309
|
-
throw new Error("Invalid value for IncrementOperator");
|
|
1310
|
-
return IncrementOperator2[key];
|
|
1311
|
-
}
|
|
1312
|
-
IncrementOperator2.parse = parse;
|
|
1313
|
-
})(IncrementOperator || (IncrementOperator = {}));
|
|
1314
|
-
var Increment = class extends Statement {
|
|
1315
|
-
constructor(operator, variable) {
|
|
1316
|
-
super();
|
|
1317
|
-
this.operator = operator;
|
|
1318
|
-
this.variable = variable;
|
|
1319
|
-
}
|
|
1320
|
-
get astNodeType() {
|
|
1321
|
-
return "increment";
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
var AssignOperator;
|
|
1325
|
-
(function(AssignOperator2) {
|
|
1326
|
-
AssignOperator2["assign"] = "=";
|
|
1327
|
-
AssignOperator2["addAssign"] = "+=";
|
|
1328
|
-
AssignOperator2["subtractAssin"] = "-=";
|
|
1329
|
-
AssignOperator2["multiplyAssign"] = "*=";
|
|
1330
|
-
AssignOperator2["divideAssign"] = "/=";
|
|
1331
|
-
AssignOperator2["moduloAssign"] = "%=";
|
|
1332
|
-
AssignOperator2["andAssign"] = "&=";
|
|
1333
|
-
AssignOperator2["orAssign"] = "|=";
|
|
1334
|
-
AssignOperator2["xorAssign"] = "^=";
|
|
1335
|
-
AssignOperator2["shiftLeftAssign"] = "<<=";
|
|
1336
|
-
AssignOperator2["shiftRightAssign"] = ">>=";
|
|
1337
|
-
})(AssignOperator || (AssignOperator = {}));
|
|
1338
|
-
(function(AssignOperator2) {
|
|
1339
|
-
function parse(val) {
|
|
1340
|
-
const key = val;
|
|
1341
|
-
if (key == "parse")
|
|
1342
|
-
throw new Error("Invalid value for AssignOperator");
|
|
1343
|
-
return AssignOperator2[key];
|
|
1344
|
-
}
|
|
1345
|
-
AssignOperator2.parse = parse;
|
|
1346
|
-
})(AssignOperator || (AssignOperator = {}));
|
|
1347
|
-
var Assign = class extends Statement {
|
|
1348
|
-
constructor(operator, variable, value) {
|
|
1349
|
-
super();
|
|
1350
|
-
this.operator = operator;
|
|
1351
|
-
this.variable = variable;
|
|
1352
|
-
this.value = value;
|
|
1353
|
-
}
|
|
1354
|
-
get astNodeType() {
|
|
1355
|
-
return "assign";
|
|
1356
|
-
}
|
|
1357
|
-
};
|
|
1358
|
-
var Call = class extends Statement {
|
|
1359
|
-
constructor(name, args) {
|
|
1360
|
-
super();
|
|
1361
|
-
this.name = name;
|
|
1362
|
-
this.args = args;
|
|
1363
|
-
}
|
|
1364
|
-
get astNodeType() {
|
|
1365
|
-
return "call";
|
|
1366
|
-
}
|
|
1367
|
-
};
|
|
1368
|
-
var Loop = class extends Statement {
|
|
1369
|
-
constructor(body, continuing) {
|
|
1370
|
-
super();
|
|
1371
|
-
this.body = body;
|
|
1372
|
-
this.continuing = continuing;
|
|
1373
|
-
}
|
|
1374
|
-
get astNodeType() {
|
|
1375
|
-
return "loop";
|
|
1376
|
-
}
|
|
1377
|
-
};
|
|
1378
|
-
var Switch = class extends Statement {
|
|
1379
|
-
constructor(condition, body) {
|
|
1380
|
-
super();
|
|
1381
|
-
this.condition = condition;
|
|
1382
|
-
this.body = body;
|
|
1383
|
-
}
|
|
1384
|
-
get astNodeType() {
|
|
1385
|
-
return "body";
|
|
1386
|
-
}
|
|
1387
|
-
};
|
|
1388
|
-
var If = class extends Statement {
|
|
1389
|
-
constructor(condition, body, elseif, _else) {
|
|
1390
|
-
super();
|
|
1391
|
-
this.condition = condition;
|
|
1392
|
-
this.body = body;
|
|
1393
|
-
this.elseif = elseif;
|
|
1394
|
-
this.else = _else;
|
|
1395
|
-
}
|
|
1396
|
-
get astNodeType() {
|
|
1397
|
-
return "if";
|
|
1398
|
-
}
|
|
1399
|
-
};
|
|
1400
|
-
var Return = class extends Statement {
|
|
1401
|
-
constructor(value) {
|
|
1402
|
-
super();
|
|
1403
|
-
this.value = value;
|
|
1404
|
-
}
|
|
1405
|
-
get astNodeType() {
|
|
1406
|
-
return "return";
|
|
1407
|
-
}
|
|
1408
|
-
};
|
|
1409
|
-
var Enable = class extends Statement {
|
|
1410
|
-
constructor(name) {
|
|
1411
|
-
super();
|
|
1412
|
-
this.name = name;
|
|
1413
|
-
}
|
|
1414
|
-
get astNodeType() {
|
|
1415
|
-
return "enable";
|
|
1416
|
-
}
|
|
1417
|
-
};
|
|
1418
|
-
var Alias = class extends Statement {
|
|
1419
|
-
constructor(name, type) {
|
|
1420
|
-
super();
|
|
1421
|
-
this.name = name;
|
|
1422
|
-
this.type = type;
|
|
1423
|
-
}
|
|
1424
|
-
get astNodeType() {
|
|
1425
|
-
return "alias";
|
|
1426
|
-
}
|
|
1427
|
-
};
|
|
1428
|
-
var Discard = class extends Statement {
|
|
1429
|
-
constructor() {
|
|
1430
|
-
super();
|
|
1431
|
-
}
|
|
1432
|
-
get astNodeType() {
|
|
1433
|
-
return "discard";
|
|
1434
|
-
}
|
|
1435
|
-
};
|
|
1436
|
-
var Break = class extends Statement {
|
|
1437
|
-
constructor() {
|
|
1438
|
-
super();
|
|
1439
|
-
}
|
|
1440
|
-
get astNodeType() {
|
|
1441
|
-
return "break";
|
|
1442
|
-
}
|
|
1443
|
-
};
|
|
1444
|
-
var Continue = class extends Statement {
|
|
1445
|
-
constructor() {
|
|
1446
|
-
super();
|
|
1447
|
-
}
|
|
1448
|
-
get astNodeType() {
|
|
1449
|
-
return "continue";
|
|
1450
|
-
}
|
|
1451
|
-
};
|
|
1452
|
-
var Type = class extends Statement {
|
|
1453
|
-
constructor(name) {
|
|
1454
|
-
super();
|
|
1455
|
-
this.name = name;
|
|
1456
|
-
}
|
|
1457
|
-
get astNodeType() {
|
|
1458
|
-
return "type";
|
|
1459
|
-
}
|
|
1460
|
-
get isStruct() {
|
|
1461
|
-
return false;
|
|
1462
|
-
}
|
|
1463
|
-
get isArray() {
|
|
1464
|
-
return false;
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
var Struct = class extends Type {
|
|
1468
|
-
constructor(name, members) {
|
|
1469
|
-
super(name);
|
|
1470
|
-
this.members = members;
|
|
1471
|
-
}
|
|
1472
|
-
get astNodeType() {
|
|
1473
|
-
return "struct";
|
|
1474
|
-
}
|
|
1475
|
-
get isStruct() {
|
|
1476
|
-
return true;
|
|
1477
|
-
}
|
|
1478
|
-
/// Return the index of the member with the given name, or -1 if not found.
|
|
1479
|
-
getMemberIndex(name) {
|
|
1480
|
-
for (let i = 0; i < this.members.length; i++) {
|
|
1481
|
-
if (this.members[i].name == name)
|
|
1482
|
-
return i;
|
|
1483
|
-
}
|
|
1484
|
-
return -1;
|
|
1485
|
-
}
|
|
1486
|
-
};
|
|
1487
|
-
var TemplateType = class extends Type {
|
|
1488
|
-
constructor(name, format, access) {
|
|
1489
|
-
super(name);
|
|
1490
|
-
this.format = format;
|
|
1491
|
-
this.access = access;
|
|
1492
|
-
}
|
|
1493
|
-
get astNodeType() {
|
|
1494
|
-
return "template";
|
|
1495
|
-
}
|
|
1496
|
-
};
|
|
1497
|
-
var PointerType = class extends Type {
|
|
1498
|
-
constructor(name, storage, type, access) {
|
|
1499
|
-
super(name);
|
|
1500
|
-
this.storage = storage;
|
|
1501
|
-
this.type = type;
|
|
1502
|
-
this.access = access;
|
|
1503
|
-
}
|
|
1504
|
-
get astNodeType() {
|
|
1505
|
-
return "pointer";
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
var ArrayType = class extends Type {
|
|
1509
|
-
constructor(name, attributes, format, count) {
|
|
1510
|
-
super(name);
|
|
1511
|
-
this.attributes = attributes;
|
|
1512
|
-
this.format = format;
|
|
1513
|
-
this.count = count;
|
|
1514
|
-
}
|
|
1515
|
-
get astNodeType() {
|
|
1516
|
-
return "array";
|
|
1517
|
-
}
|
|
1518
|
-
get isArray() {
|
|
1519
|
-
return true;
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
var SamplerType = class extends Type {
|
|
1523
|
-
constructor(name, format, access) {
|
|
1524
|
-
super(name);
|
|
1525
|
-
this.format = format;
|
|
1526
|
-
this.access = access;
|
|
1527
|
-
}
|
|
1528
|
-
get astNodeType() {
|
|
1529
|
-
return "sampler";
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
var Expression = class extends Node {
|
|
1533
|
-
constructor() {
|
|
1534
|
-
super();
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
var StringExpr = class extends Expression {
|
|
1538
|
-
constructor(value) {
|
|
1539
|
-
super();
|
|
1540
|
-
this.value = value;
|
|
1541
|
-
}
|
|
1542
|
-
get astNodeType() {
|
|
1543
|
-
return "stringExpr";
|
|
1544
|
-
}
|
|
1545
|
-
toString() {
|
|
1546
|
-
return this.value;
|
|
1547
|
-
}
|
|
1548
|
-
evaluateString() {
|
|
1549
|
-
return this.value;
|
|
1550
|
-
}
|
|
1551
|
-
};
|
|
1552
|
-
var CreateExpr = class extends Expression {
|
|
1553
|
-
constructor(type, args) {
|
|
1554
|
-
super();
|
|
1555
|
-
this.type = type;
|
|
1556
|
-
this.args = args;
|
|
1557
|
-
}
|
|
1558
|
-
get astNodeType() {
|
|
1559
|
-
return "createExpr";
|
|
1560
|
-
}
|
|
1561
|
-
};
|
|
1562
|
-
var CallExpr = class extends Expression {
|
|
1563
|
-
constructor(name, args) {
|
|
1564
|
-
super();
|
|
1565
|
-
this.name = name;
|
|
1566
|
-
this.args = args;
|
|
1567
|
-
}
|
|
1568
|
-
get astNodeType() {
|
|
1569
|
-
return "callExpr";
|
|
1570
|
-
}
|
|
1571
|
-
evaluate(context) {
|
|
1572
|
-
switch (this.name) {
|
|
1573
|
-
case "abs":
|
|
1574
|
-
return Math.abs(this.args[0].evaluate(context));
|
|
1575
|
-
case "acos":
|
|
1576
|
-
return Math.acos(this.args[0].evaluate(context));
|
|
1577
|
-
case "acosh":
|
|
1578
|
-
return Math.acosh(this.args[0].evaluate(context));
|
|
1579
|
-
case "asin":
|
|
1580
|
-
return Math.asin(this.args[0].evaluate(context));
|
|
1581
|
-
case "asinh":
|
|
1582
|
-
return Math.asinh(this.args[0].evaluate(context));
|
|
1583
|
-
case "atan":
|
|
1584
|
-
return Math.atan(this.args[0].evaluate(context));
|
|
1585
|
-
case "atan2":
|
|
1586
|
-
return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1587
|
-
case "atanh":
|
|
1588
|
-
return Math.atanh(this.args[0].evaluate(context));
|
|
1589
|
-
case "ceil":
|
|
1590
|
-
return Math.ceil(this.args[0].evaluate(context));
|
|
1591
|
-
case "clamp":
|
|
1592
|
-
return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
|
|
1593
|
-
case "cos":
|
|
1594
|
-
return Math.cos(this.args[0].evaluate(context));
|
|
1595
|
-
case "degrees":
|
|
1596
|
-
return this.args[0].evaluate(context) * 180 / Math.PI;
|
|
1597
|
-
case "distance":
|
|
1598
|
-
return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
|
|
1599
|
-
case "dot":
|
|
1600
|
-
case "exp":
|
|
1601
|
-
return Math.exp(this.args[0].evaluate(context));
|
|
1602
|
-
case "exp2":
|
|
1603
|
-
return Math.pow(2, this.args[0].evaluate(context));
|
|
1604
|
-
case "floor":
|
|
1605
|
-
return Math.floor(this.args[0].evaluate(context));
|
|
1606
|
-
case "fma":
|
|
1607
|
-
return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
|
|
1608
|
-
case "fract":
|
|
1609
|
-
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
1610
|
-
case "inverseSqrt":
|
|
1611
|
-
return 1 / Math.sqrt(this.args[0].evaluate(context));
|
|
1612
|
-
case "log":
|
|
1613
|
-
return Math.log(this.args[0].evaluate(context));
|
|
1614
|
-
case "log2":
|
|
1615
|
-
return Math.log2(this.args[0].evaluate(context));
|
|
1616
|
-
case "max":
|
|
1617
|
-
return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1618
|
-
case "min":
|
|
1619
|
-
return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1620
|
-
case "mix":
|
|
1621
|
-
return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
|
|
1622
|
-
case "modf":
|
|
1623
|
-
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
1624
|
-
case "pow":
|
|
1625
|
-
return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1626
|
-
case "radians":
|
|
1627
|
-
return this.args[0].evaluate(context) * Math.PI / 180;
|
|
1628
|
-
case "round":
|
|
1629
|
-
return Math.round(this.args[0].evaluate(context));
|
|
1630
|
-
case "sign":
|
|
1631
|
-
return Math.sign(this.args[0].evaluate(context));
|
|
1632
|
-
case "sin":
|
|
1633
|
-
return Math.sin(this.args[0].evaluate(context));
|
|
1634
|
-
case "sinh":
|
|
1635
|
-
return Math.sinh(this.args[0].evaluate(context));
|
|
1636
|
-
case "saturate":
|
|
1637
|
-
return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
|
|
1638
|
-
case "smoothstep":
|
|
1639
|
-
return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
|
|
1640
|
-
case "sqrt":
|
|
1641
|
-
return Math.sqrt(this.args[0].evaluate(context));
|
|
1642
|
-
case "step":
|
|
1643
|
-
return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
|
|
1644
|
-
case "tan":
|
|
1645
|
-
return Math.tan(this.args[0].evaluate(context));
|
|
1646
|
-
case "tanh":
|
|
1647
|
-
return Math.tanh(this.args[0].evaluate(context));
|
|
1648
|
-
case "trunc":
|
|
1649
|
-
return Math.trunc(this.args[0].evaluate(context));
|
|
1650
|
-
default:
|
|
1651
|
-
throw new Error("Non const function: " + this.name);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
};
|
|
1655
|
-
var VariableExpr = class extends Expression {
|
|
1656
|
-
constructor(name) {
|
|
1657
|
-
super();
|
|
1658
|
-
this.name = name;
|
|
1659
|
-
}
|
|
1660
|
-
get astNodeType() {
|
|
1661
|
-
return "varExpr";
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
var ConstExpr = class extends Expression {
|
|
1665
|
-
constructor(name, initializer) {
|
|
1666
|
-
super();
|
|
1667
|
-
this.name = name;
|
|
1668
|
-
this.initializer = initializer;
|
|
1669
|
-
}
|
|
1670
|
-
get astNodeType() {
|
|
1671
|
-
return "constExpr";
|
|
1672
|
-
}
|
|
1673
|
-
evaluate(context) {
|
|
1674
|
-
var _a2, _b;
|
|
1675
|
-
if (this.initializer instanceof CreateExpr) {
|
|
1676
|
-
const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
|
|
1677
|
-
const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
|
|
1678
|
-
const struct = context.structs.get(type);
|
|
1679
|
-
const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
|
|
1680
|
-
if (memberIndex != -1) {
|
|
1681
|
-
const value = this.initializer.args[memberIndex].evaluate(context);
|
|
1682
|
-
return value;
|
|
1683
|
-
}
|
|
1684
|
-
console.log(memberIndex);
|
|
1685
|
-
}
|
|
1686
|
-
return this.initializer.evaluate(context);
|
|
1687
|
-
}
|
|
1688
|
-
};
|
|
1689
|
-
var LiteralExpr = class extends Expression {
|
|
1690
|
-
constructor(value) {
|
|
1691
|
-
super();
|
|
1692
|
-
this.value = value;
|
|
1693
|
-
}
|
|
1694
|
-
get astNodeType() {
|
|
1695
|
-
return "literalExpr";
|
|
1696
|
-
}
|
|
1697
|
-
evaluate() {
|
|
1698
|
-
return this.value;
|
|
1699
|
-
}
|
|
1700
|
-
};
|
|
1701
|
-
var BitcastExpr = class extends Expression {
|
|
1702
|
-
constructor(type, value) {
|
|
1703
|
-
super();
|
|
1704
|
-
this.type = type;
|
|
1705
|
-
this.value = value;
|
|
1706
|
-
}
|
|
1707
|
-
get astNodeType() {
|
|
1708
|
-
return "bitcastExpr";
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
var TypecastExpr = class extends Expression {
|
|
1712
|
-
constructor(type, args) {
|
|
1713
|
-
super();
|
|
1714
|
-
this.type = type;
|
|
1715
|
-
this.args = args;
|
|
1716
|
-
}
|
|
1717
|
-
get astNodeType() {
|
|
1718
|
-
return "typecastExpr";
|
|
1719
|
-
}
|
|
1720
|
-
evaluate(context) {
|
|
1721
|
-
return this.args[0].evaluate(context);
|
|
1722
|
-
}
|
|
1723
|
-
};
|
|
1724
|
-
var GroupingExpr = class extends Expression {
|
|
1725
|
-
constructor(contents) {
|
|
1726
|
-
super();
|
|
1727
|
-
this.contents = contents;
|
|
1728
|
-
}
|
|
1729
|
-
get astNodeType() {
|
|
1730
|
-
return "groupExpr";
|
|
1731
|
-
}
|
|
1732
|
-
evaluate(context) {
|
|
1733
|
-
return this.contents[0].evaluate(context);
|
|
1734
|
-
}
|
|
1735
|
-
};
|
|
1736
|
-
var Operator = class extends Expression {
|
|
1737
|
-
constructor() {
|
|
1738
|
-
super();
|
|
1739
|
-
}
|
|
1740
|
-
};
|
|
1741
|
-
var UnaryOperator = class extends Operator {
|
|
1742
|
-
constructor(operator, right) {
|
|
1743
|
-
super();
|
|
1744
|
-
this.operator = operator;
|
|
1745
|
-
this.right = right;
|
|
1746
|
-
}
|
|
1747
|
-
get astNodeType() {
|
|
1748
|
-
return "unaryOp";
|
|
1749
|
-
}
|
|
1750
|
-
evaluate(context) {
|
|
1751
|
-
switch (this.operator) {
|
|
1752
|
-
case "+":
|
|
1753
|
-
return this.right.evaluate(context);
|
|
1754
|
-
case "-":
|
|
1755
|
-
return -this.right.evaluate(context);
|
|
1756
|
-
case "!":
|
|
1757
|
-
return this.right.evaluate(context) ? 0 : 1;
|
|
1758
|
-
case "~":
|
|
1759
|
-
return ~this.right.evaluate(context);
|
|
1760
|
-
default:
|
|
1761
|
-
throw new Error("Unknown unary operator: " + this.operator);
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
};
|
|
1765
|
-
var BinaryOperator = class extends Operator {
|
|
1766
|
-
constructor(operator, left, right) {
|
|
1767
|
-
super();
|
|
1768
|
-
this.operator = operator;
|
|
1769
|
-
this.left = left;
|
|
1770
|
-
this.right = right;
|
|
1771
|
-
}
|
|
1772
|
-
get astNodeType() {
|
|
1773
|
-
return "binaryOp";
|
|
1774
|
-
}
|
|
1775
|
-
evaluate(context) {
|
|
1776
|
-
switch (this.operator) {
|
|
1777
|
-
case "+":
|
|
1778
|
-
return this.left.evaluate(context) + this.right.evaluate(context);
|
|
1779
|
-
case "-":
|
|
1780
|
-
return this.left.evaluate(context) - this.right.evaluate(context);
|
|
1781
|
-
case "*":
|
|
1782
|
-
return this.left.evaluate(context) * this.right.evaluate(context);
|
|
1783
|
-
case "/":
|
|
1784
|
-
return this.left.evaluate(context) / this.right.evaluate(context);
|
|
1785
|
-
case "%":
|
|
1786
|
-
return this.left.evaluate(context) % this.right.evaluate(context);
|
|
1787
|
-
case "==":
|
|
1788
|
-
return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
|
|
1789
|
-
case "!=":
|
|
1790
|
-
return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
|
|
1791
|
-
case "<":
|
|
1792
|
-
return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
|
|
1793
|
-
case ">":
|
|
1794
|
-
return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
|
|
1795
|
-
case "<=":
|
|
1796
|
-
return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
|
|
1797
|
-
case ">=":
|
|
1798
|
-
return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
|
|
1799
|
-
case "&&":
|
|
1800
|
-
return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
|
|
1801
|
-
case "||":
|
|
1802
|
-
return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
|
|
1803
|
-
default:
|
|
1804
|
-
throw new Error(`Unknown operator ${this.operator}`);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
var SwitchCase = class extends Node {
|
|
1809
|
-
constructor() {
|
|
1810
|
-
super();
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
|
-
var Case = class extends SwitchCase {
|
|
1814
|
-
constructor(selector, body) {
|
|
1815
|
-
super();
|
|
1816
|
-
this.selector = selector;
|
|
1817
|
-
this.body = body;
|
|
1818
|
-
}
|
|
1819
|
-
get astNodeType() {
|
|
1820
|
-
return "case";
|
|
1821
|
-
}
|
|
1822
|
-
};
|
|
1823
|
-
var Default = class extends SwitchCase {
|
|
1824
|
-
constructor(body) {
|
|
1825
|
-
super();
|
|
1826
|
-
this.body = body;
|
|
1827
|
-
}
|
|
1828
|
-
get astNodeType() {
|
|
1829
|
-
return "default";
|
|
1830
|
-
}
|
|
1831
|
-
};
|
|
1832
|
-
var Argument = class extends Node {
|
|
1833
|
-
constructor(name, type, attributes) {
|
|
1834
|
-
super();
|
|
1835
|
-
this.name = name;
|
|
1836
|
-
this.type = type;
|
|
1837
|
-
this.attributes = attributes;
|
|
1838
|
-
}
|
|
1839
|
-
get astNodeType() {
|
|
1840
|
-
return "argument";
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
var ElseIf = class extends Node {
|
|
1844
|
-
constructor(condition, body) {
|
|
1845
|
-
super();
|
|
1846
|
-
this.condition = condition;
|
|
1847
|
-
this.body = body;
|
|
1848
|
-
}
|
|
1849
|
-
get astNodeType() {
|
|
1850
|
-
return "elseif";
|
|
1851
|
-
}
|
|
1852
|
-
};
|
|
1853
|
-
var Member = class extends Node {
|
|
1854
|
-
constructor(name, type, attributes) {
|
|
1855
|
-
super();
|
|
1856
|
-
this.name = name;
|
|
1857
|
-
this.type = type;
|
|
1858
|
-
this.attributes = attributes;
|
|
1859
|
-
}
|
|
1860
|
-
get astNodeType() {
|
|
1861
|
-
return "member";
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
var Attribute = class extends Node {
|
|
1865
|
-
constructor(name, value) {
|
|
1866
|
-
super();
|
|
1867
|
-
this.name = name;
|
|
1868
|
-
this.value = value;
|
|
1869
|
-
}
|
|
1870
|
-
get astNodeType() {
|
|
1871
|
-
return "attribute";
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
var _a;
|
|
1875
|
-
var TokenClass;
|
|
1876
|
-
(function(TokenClass2) {
|
|
1877
|
-
TokenClass2[TokenClass2["token"] = 0] = "token";
|
|
1878
|
-
TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
|
|
1879
|
-
TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
|
|
1880
|
-
})(TokenClass || (TokenClass = {}));
|
|
1881
|
-
var TokenType = class {
|
|
1882
|
-
constructor(name, type, rule) {
|
|
1883
|
-
this.name = name;
|
|
1884
|
-
this.type = type;
|
|
1885
|
-
this.rule = rule;
|
|
1886
|
-
}
|
|
1887
|
-
toString() {
|
|
1888
|
-
return this.name;
|
|
1889
|
-
}
|
|
1890
|
-
};
|
|
1891
|
-
var TokenTypes = class {
|
|
1892
|
-
};
|
|
1893
|
-
_a = TokenTypes;
|
|
1894
|
-
TokenTypes.none = new TokenType("", TokenClass.reserved, "");
|
|
1895
|
-
TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
|
|
1896
|
-
TokenTypes.reserved = {
|
|
1897
|
-
asm: new TokenType("asm", TokenClass.reserved, "asm"),
|
|
1898
|
-
bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
|
|
1899
|
-
do: new TokenType("do", TokenClass.reserved, "do"),
|
|
1900
|
-
enum: new TokenType("enum", TokenClass.reserved, "enum"),
|
|
1901
|
-
f16: new TokenType("f16", TokenClass.reserved, "f16"),
|
|
1902
|
-
f64: new TokenType("f64", TokenClass.reserved, "f64"),
|
|
1903
|
-
handle: new TokenType("handle", TokenClass.reserved, "handle"),
|
|
1904
|
-
i8: new TokenType("i8", TokenClass.reserved, "i8"),
|
|
1905
|
-
i16: new TokenType("i16", TokenClass.reserved, "i16"),
|
|
1906
|
-
i64: new TokenType("i64", TokenClass.reserved, "i64"),
|
|
1907
|
-
mat: new TokenType("mat", TokenClass.reserved, "mat"),
|
|
1908
|
-
premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
|
|
1909
|
-
regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
|
|
1910
|
-
typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
|
|
1911
|
-
u8: new TokenType("u8", TokenClass.reserved, "u8"),
|
|
1912
|
-
u16: new TokenType("u16", TokenClass.reserved, "u16"),
|
|
1913
|
-
u64: new TokenType("u64", TokenClass.reserved, "u64"),
|
|
1914
|
-
unless: new TokenType("unless", TokenClass.reserved, "unless"),
|
|
1915
|
-
using: new TokenType("using", TokenClass.reserved, "using"),
|
|
1916
|
-
vec: new TokenType("vec", TokenClass.reserved, "vec"),
|
|
1917
|
-
void: new TokenType("void", TokenClass.reserved, "void")
|
|
1918
|
-
};
|
|
1919
|
-
TokenTypes.keywords = {
|
|
1920
|
-
array: new TokenType("array", TokenClass.keyword, "array"),
|
|
1921
|
-
atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
|
|
1922
|
-
bool: new TokenType("bool", TokenClass.keyword, "bool"),
|
|
1923
|
-
f32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
1924
|
-
i32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
1925
|
-
mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
|
|
1926
|
-
mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
|
|
1927
|
-
mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
|
|
1928
|
-
mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
|
|
1929
|
-
mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
|
|
1930
|
-
mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
|
|
1931
|
-
mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
|
|
1932
|
-
mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
|
|
1933
|
-
mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
|
|
1934
|
-
ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
|
|
1935
|
-
sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
|
|
1936
|
-
sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
|
|
1937
|
-
struct: new TokenType("struct", TokenClass.keyword, "struct"),
|
|
1938
|
-
texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
|
|
1939
|
-
texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
|
|
1940
|
-
texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
|
|
1941
|
-
texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
|
|
1942
|
-
texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
|
|
1943
|
-
texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
|
|
1944
|
-
texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
|
|
1945
|
-
texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
|
|
1946
|
-
texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
|
|
1947
|
-
texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
|
|
1948
|
-
texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
|
|
1949
|
-
texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
|
|
1950
|
-
texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
|
|
1951
|
-
texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
|
|
1952
|
-
texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
|
|
1953
|
-
texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
|
|
1954
|
-
texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
|
|
1955
|
-
u32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
1956
|
-
vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
|
|
1957
|
-
vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
|
|
1958
|
-
vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
|
|
1959
|
-
bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
|
|
1960
|
-
block: new TokenType("block", TokenClass.keyword, "block"),
|
|
1961
|
-
break: new TokenType("break", TokenClass.keyword, "break"),
|
|
1962
|
-
case: new TokenType("case", TokenClass.keyword, "case"),
|
|
1963
|
-
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
1964
|
-
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
1965
|
-
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
1966
|
-
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
1967
|
-
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
1968
|
-
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
1969
|
-
fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
|
|
1970
|
-
false: new TokenType("false", TokenClass.keyword, "false"),
|
|
1971
|
-
fn: new TokenType("fn", TokenClass.keyword, "fn"),
|
|
1972
|
-
for: new TokenType("for", TokenClass.keyword, "for"),
|
|
1973
|
-
function: new TokenType("function", TokenClass.keyword, "function"),
|
|
1974
|
-
if: new TokenType("if", TokenClass.keyword, "if"),
|
|
1975
|
-
let: new TokenType("let", TokenClass.keyword, "let"),
|
|
1976
|
-
const: new TokenType("const", TokenClass.keyword, "const"),
|
|
1977
|
-
loop: new TokenType("loop", TokenClass.keyword, "loop"),
|
|
1978
|
-
while: new TokenType("while", TokenClass.keyword, "while"),
|
|
1979
|
-
private: new TokenType("private", TokenClass.keyword, "private"),
|
|
1980
|
-
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
1981
|
-
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
1982
|
-
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
1983
|
-
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
1984
|
-
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
1985
|
-
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
1986
|
-
alias: new TokenType("alias", TokenClass.keyword, "alias"),
|
|
1987
|
-
type: new TokenType("type", TokenClass.keyword, "type"),
|
|
1988
|
-
uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
|
|
1989
|
-
var: new TokenType("var", TokenClass.keyword, "var"),
|
|
1990
|
-
override: new TokenType("override", TokenClass.keyword, "override"),
|
|
1991
|
-
workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
|
|
1992
|
-
write: new TokenType("write", TokenClass.keyword, "write"),
|
|
1993
|
-
r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
|
|
1994
|
-
r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
|
|
1995
|
-
r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
|
|
1996
|
-
r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
|
|
1997
|
-
r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
|
|
1998
|
-
r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
|
|
1999
|
-
r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
|
|
2000
|
-
rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
|
|
2001
|
-
rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
|
|
2002
|
-
rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
|
|
2003
|
-
rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
|
|
2004
|
-
r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
|
|
2005
|
-
r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
|
|
2006
|
-
r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
|
|
2007
|
-
rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
|
|
2008
|
-
rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
|
|
2009
|
-
rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
|
|
2010
|
-
rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
|
|
2011
|
-
rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
|
|
2012
|
-
rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
|
|
2013
|
-
rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
|
|
2014
|
-
rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
|
|
2015
|
-
bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
|
|
2016
|
-
bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
|
|
2017
|
-
rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
|
|
2018
|
-
rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
|
|
2019
|
-
rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
|
|
2020
|
-
rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
|
|
2021
|
-
rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
|
|
2022
|
-
rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
|
|
2023
|
-
rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
|
|
2024
|
-
rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
|
|
2025
|
-
rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
|
|
2026
|
-
rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
|
|
2027
|
-
rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
|
|
2028
|
-
static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
|
|
2029
|
-
// WGSL grammar has a few keywords that have different token names than the strings they
|
|
2030
|
-
// represent. Aliasing them here.
|
|
2031
|
-
/*int32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
2032
|
-
uint32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
2033
|
-
float32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
2034
|
-
pointer: new TokenType("ptr", TokenClass.keyword, "ptr"),*/
|
|
2035
|
-
};
|
|
2036
|
-
TokenTypes.tokens = {
|
|
2037
|
-
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)/),
|
|
2038
|
-
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?))/),
|
|
2039
|
-
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
2040
|
-
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
2041
|
-
ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
|
|
2042
|
-
and: new TokenType("and", TokenClass.token, "&"),
|
|
2043
|
-
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
2044
|
-
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
2045
|
-
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
2046
|
-
attr_left: new TokenType("attr_left", TokenClass.token, "[["),
|
|
2047
|
-
attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
|
|
2048
|
-
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
2049
|
-
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
2050
|
-
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
2051
|
-
bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
|
|
2052
|
-
brace_left: new TokenType("brace_left", TokenClass.token, "{"),
|
|
2053
|
-
brace_right: new TokenType("brace_right", TokenClass.token, "}"),
|
|
2054
|
-
colon: new TokenType("colon", TokenClass.token, ":"),
|
|
2055
|
-
comma: new TokenType("comma", TokenClass.token, ","),
|
|
2056
|
-
equal: new TokenType("equal", TokenClass.token, "="),
|
|
2057
|
-
equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
|
|
2058
|
-
not_equal: new TokenType("not_equal", TokenClass.token, "!="),
|
|
2059
|
-
greater_than: new TokenType("greater_than", TokenClass.token, ">"),
|
|
2060
|
-
greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
|
|
2061
|
-
shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
|
|
2062
|
-
less_than: new TokenType("less_than", TokenClass.token, "<"),
|
|
2063
|
-
less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
|
|
2064
|
-
shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
|
|
2065
|
-
modulo: new TokenType("modulo", TokenClass.token, "%"),
|
|
2066
|
-
minus: new TokenType("minus", TokenClass.token, "-"),
|
|
2067
|
-
minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
|
|
2068
|
-
period: new TokenType("period", TokenClass.token, "."),
|
|
2069
|
-
plus: new TokenType("plus", TokenClass.token, "+"),
|
|
2070
|
-
plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
|
|
2071
|
-
or: new TokenType("or", TokenClass.token, "|"),
|
|
2072
|
-
or_or: new TokenType("or_or", TokenClass.token, "||"),
|
|
2073
|
-
paren_left: new TokenType("paren_left", TokenClass.token, "("),
|
|
2074
|
-
paren_right: new TokenType("paren_right", TokenClass.token, ")"),
|
|
2075
|
-
semicolon: new TokenType("semicolon", TokenClass.token, ";"),
|
|
2076
|
-
star: new TokenType("star", TokenClass.token, "*"),
|
|
2077
|
-
tilde: new TokenType("tilde", TokenClass.token, "~"),
|
|
2078
|
-
underscore: new TokenType("underscore", TokenClass.token, "_"),
|
|
2079
|
-
xor: new TokenType("xor", TokenClass.token, "^"),
|
|
2080
|
-
plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
|
|
2081
|
-
minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
|
|
2082
|
-
times_equal: new TokenType("times_equal", TokenClass.token, "*="),
|
|
2083
|
-
division_equal: new TokenType("division_equal", TokenClass.token, "/="),
|
|
2084
|
-
modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
|
|
2085
|
-
and_equal: new TokenType("and_equal", TokenClass.token, "&="),
|
|
2086
|
-
or_equal: new TokenType("or_equal", TokenClass.token, "|="),
|
|
2087
|
-
xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
|
|
2088
|
-
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
2089
|
-
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
|
|
2090
|
-
};
|
|
2091
|
-
TokenTypes.storage_class = [
|
|
2092
|
-
_a.keywords.function,
|
|
2093
|
-
_a.keywords.private,
|
|
2094
|
-
_a.keywords.workgroup,
|
|
2095
|
-
_a.keywords.uniform,
|
|
2096
|
-
_a.keywords.storage
|
|
2097
|
-
];
|
|
2098
|
-
TokenTypes.access_mode = [
|
|
2099
|
-
_a.keywords.read,
|
|
2100
|
-
_a.keywords.write,
|
|
2101
|
-
_a.keywords.read_write
|
|
2102
|
-
];
|
|
2103
|
-
TokenTypes.sampler_type = [
|
|
2104
|
-
_a.keywords.sampler,
|
|
2105
|
-
_a.keywords.sampler_comparison
|
|
2106
|
-
];
|
|
2107
|
-
TokenTypes.sampled_texture_type = [
|
|
2108
|
-
_a.keywords.texture_1d,
|
|
2109
|
-
_a.keywords.texture_2d,
|
|
2110
|
-
_a.keywords.texture_2d_array,
|
|
2111
|
-
_a.keywords.texture_3d,
|
|
2112
|
-
_a.keywords.texture_cube,
|
|
2113
|
-
_a.keywords.texture_cube_array
|
|
2114
|
-
];
|
|
2115
|
-
TokenTypes.multisampled_texture_type = [
|
|
2116
|
-
_a.keywords.texture_multisampled_2d
|
|
2117
|
-
];
|
|
2118
|
-
TokenTypes.storage_texture_type = [
|
|
2119
|
-
_a.keywords.texture_storage_1d,
|
|
2120
|
-
_a.keywords.texture_storage_2d,
|
|
2121
|
-
_a.keywords.texture_storage_2d_array,
|
|
2122
|
-
_a.keywords.texture_storage_3d
|
|
2123
|
-
];
|
|
2124
|
-
TokenTypes.depth_texture_type = [
|
|
2125
|
-
_a.keywords.texture_depth_2d,
|
|
2126
|
-
_a.keywords.texture_depth_2d_array,
|
|
2127
|
-
_a.keywords.texture_depth_cube,
|
|
2128
|
-
_a.keywords.texture_depth_cube_array,
|
|
2129
|
-
_a.keywords.texture_depth_multisampled_2d
|
|
2130
|
-
];
|
|
2131
|
-
TokenTypes.texture_external_type = [_a.keywords.texture_external];
|
|
2132
|
-
TokenTypes.any_texture_type = [
|
|
2133
|
-
..._a.sampled_texture_type,
|
|
2134
|
-
..._a.multisampled_texture_type,
|
|
2135
|
-
..._a.storage_texture_type,
|
|
2136
|
-
..._a.depth_texture_type,
|
|
2137
|
-
..._a.texture_external_type
|
|
2138
|
-
];
|
|
2139
|
-
TokenTypes.texel_format = [
|
|
2140
|
-
_a.keywords.r8unorm,
|
|
2141
|
-
_a.keywords.r8snorm,
|
|
2142
|
-
_a.keywords.r8uint,
|
|
2143
|
-
_a.keywords.r8sint,
|
|
2144
|
-
_a.keywords.r16uint,
|
|
2145
|
-
_a.keywords.r16sint,
|
|
2146
|
-
_a.keywords.r16float,
|
|
2147
|
-
_a.keywords.rg8unorm,
|
|
2148
|
-
_a.keywords.rg8snorm,
|
|
2149
|
-
_a.keywords.rg8uint,
|
|
2150
|
-
_a.keywords.rg8sint,
|
|
2151
|
-
_a.keywords.r32uint,
|
|
2152
|
-
_a.keywords.r32sint,
|
|
2153
|
-
_a.keywords.r32float,
|
|
2154
|
-
_a.keywords.rg16uint,
|
|
2155
|
-
_a.keywords.rg16sint,
|
|
2156
|
-
_a.keywords.rg16float,
|
|
2157
|
-
_a.keywords.rgba8unorm,
|
|
2158
|
-
_a.keywords.rgba8unorm_srgb,
|
|
2159
|
-
_a.keywords.rgba8snorm,
|
|
2160
|
-
_a.keywords.rgba8uint,
|
|
2161
|
-
_a.keywords.rgba8sint,
|
|
2162
|
-
_a.keywords.bgra8unorm,
|
|
2163
|
-
_a.keywords.bgra8unorm_srgb,
|
|
2164
|
-
_a.keywords.rgb10a2unorm,
|
|
2165
|
-
_a.keywords.rg11b10float,
|
|
2166
|
-
_a.keywords.rg32uint,
|
|
2167
|
-
_a.keywords.rg32sint,
|
|
2168
|
-
_a.keywords.rg32float,
|
|
2169
|
-
_a.keywords.rgba16uint,
|
|
2170
|
-
_a.keywords.rgba16sint,
|
|
2171
|
-
_a.keywords.rgba16float,
|
|
2172
|
-
_a.keywords.rgba32uint,
|
|
2173
|
-
_a.keywords.rgba32sint,
|
|
2174
|
-
_a.keywords.rgba32float
|
|
2175
|
-
];
|
|
2176
|
-
TokenTypes.const_literal = [
|
|
2177
|
-
_a.tokens.int_literal,
|
|
2178
|
-
_a.tokens.uint_literal,
|
|
2179
|
-
_a.tokens.decimal_float_literal,
|
|
2180
|
-
_a.tokens.hex_float_literal,
|
|
2181
|
-
_a.keywords.true,
|
|
2182
|
-
_a.keywords.false
|
|
2183
|
-
];
|
|
2184
|
-
TokenTypes.literal_or_ident = [
|
|
2185
|
-
_a.tokens.ident,
|
|
2186
|
-
_a.tokens.int_literal,
|
|
2187
|
-
_a.tokens.uint_literal,
|
|
2188
|
-
_a.tokens.decimal_float_literal,
|
|
2189
|
-
_a.tokens.hex_float_literal
|
|
2190
|
-
];
|
|
2191
|
-
TokenTypes.element_count_expression = [
|
|
2192
|
-
_a.tokens.int_literal,
|
|
2193
|
-
_a.tokens.uint_literal,
|
|
2194
|
-
_a.tokens.ident
|
|
2195
|
-
];
|
|
2196
|
-
TokenTypes.template_types = [
|
|
2197
|
-
_a.keywords.vec2,
|
|
2198
|
-
_a.keywords.vec3,
|
|
2199
|
-
_a.keywords.vec4,
|
|
2200
|
-
_a.keywords.mat2x2,
|
|
2201
|
-
_a.keywords.mat2x3,
|
|
2202
|
-
_a.keywords.mat2x4,
|
|
2203
|
-
_a.keywords.mat3x2,
|
|
2204
|
-
_a.keywords.mat3x3,
|
|
2205
|
-
_a.keywords.mat3x4,
|
|
2206
|
-
_a.keywords.mat4x2,
|
|
2207
|
-
_a.keywords.mat4x3,
|
|
2208
|
-
_a.keywords.mat4x4,
|
|
2209
|
-
_a.keywords.atomic,
|
|
2210
|
-
_a.keywords.bitcast,
|
|
2211
|
-
..._a.any_texture_type
|
|
2212
|
-
];
|
|
2213
|
-
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
|
|
2214
|
-
TokenTypes.assignment_operators = [
|
|
2215
|
-
_a.tokens.equal,
|
|
2216
|
-
_a.tokens.plus_equal,
|
|
2217
|
-
_a.tokens.minus_equal,
|
|
2218
|
-
_a.tokens.times_equal,
|
|
2219
|
-
_a.tokens.division_equal,
|
|
2220
|
-
_a.tokens.modulo_equal,
|
|
2221
|
-
_a.tokens.and_equal,
|
|
2222
|
-
_a.tokens.or_equal,
|
|
2223
|
-
_a.tokens.xor_equal,
|
|
2224
|
-
_a.tokens.shift_right_equal,
|
|
2225
|
-
_a.tokens.shift_left_equal
|
|
2226
|
-
];
|
|
2227
|
-
TokenTypes.increment_operators = [
|
|
2228
|
-
_a.tokens.plus_plus,
|
|
2229
|
-
_a.tokens.minus_minus
|
|
2230
|
-
];
|
|
2231
|
-
var Token = class {
|
|
2232
|
-
constructor(type, lexeme, line) {
|
|
2233
|
-
this.type = type;
|
|
2234
|
-
this.lexeme = lexeme;
|
|
2235
|
-
this.line = line;
|
|
2236
|
-
}
|
|
2237
|
-
toString() {
|
|
2238
|
-
return this.lexeme;
|
|
2239
|
-
}
|
|
2240
|
-
isTemplateType() {
|
|
2241
|
-
return TokenTypes.template_types.indexOf(this.type) != -1;
|
|
2242
|
-
}
|
|
2243
|
-
isArrayType() {
|
|
2244
|
-
return this.type == TokenTypes.keywords.array;
|
|
2245
|
-
}
|
|
2246
|
-
isArrayOrTemplateType() {
|
|
2247
|
-
return this.isArrayType() || this.isTemplateType();
|
|
2248
|
-
}
|
|
2249
|
-
};
|
|
2250
|
-
var WgslScanner = class {
|
|
2251
|
-
constructor(source) {
|
|
2252
|
-
this._tokens = [];
|
|
2253
|
-
this._start = 0;
|
|
2254
|
-
this._current = 0;
|
|
2255
|
-
this._line = 1;
|
|
2256
|
-
this._source = source !== null && source !== void 0 ? source : "";
|
|
2257
|
-
}
|
|
2258
|
-
/// Scan all tokens from the source.
|
|
2259
|
-
scanTokens() {
|
|
2260
|
-
while (!this._isAtEnd()) {
|
|
2261
|
-
this._start = this._current;
|
|
2262
|
-
if (!this.scanToken())
|
|
2263
|
-
throw `Invalid syntax at line ${this._line}`;
|
|
2264
|
-
}
|
|
2265
|
-
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
2266
|
-
return this._tokens;
|
|
2267
|
-
}
|
|
2268
|
-
/// Scan a single token from the source.
|
|
2269
|
-
scanToken() {
|
|
2270
|
-
let lexeme = this._advance();
|
|
2271
|
-
if (lexeme == "\n") {
|
|
2272
|
-
this._line++;
|
|
2273
|
-
return true;
|
|
2274
|
-
}
|
|
2275
|
-
if (this._isWhitespace(lexeme)) {
|
|
2276
|
-
return true;
|
|
2277
|
-
}
|
|
2278
|
-
if (lexeme == "/") {
|
|
2279
|
-
if (this._peekAhead() == "/") {
|
|
2280
|
-
while (lexeme != "\n") {
|
|
2281
|
-
if (this._isAtEnd())
|
|
2282
|
-
return true;
|
|
2283
|
-
lexeme = this._advance();
|
|
2284
|
-
}
|
|
2285
|
-
this._line++;
|
|
2286
|
-
return true;
|
|
2287
|
-
} else if (this._peekAhead() == "*") {
|
|
2288
|
-
this._advance();
|
|
2289
|
-
let commentLevel = 1;
|
|
2290
|
-
while (commentLevel > 0) {
|
|
2291
|
-
if (this._isAtEnd())
|
|
2292
|
-
return true;
|
|
2293
|
-
lexeme = this._advance();
|
|
2294
|
-
if (lexeme == "\n") {
|
|
2295
|
-
this._line++;
|
|
2296
|
-
} else if (lexeme == "*") {
|
|
2297
|
-
if (this._peekAhead() == "/") {
|
|
2298
|
-
this._advance();
|
|
2299
|
-
commentLevel--;
|
|
2300
|
-
if (commentLevel == 0) {
|
|
2301
|
-
return true;
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
} else if (lexeme == "/") {
|
|
2305
|
-
if (this._peekAhead() == "*") {
|
|
2306
|
-
this._advance();
|
|
2307
|
-
commentLevel++;
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
return true;
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
let matchType = TokenTypes.none;
|
|
2315
|
-
for (; ; ) {
|
|
2316
|
-
let matchedType = this._findType(lexeme);
|
|
2317
|
-
const nextLexeme = this._peekAhead();
|
|
2318
|
-
if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
|
|
2319
|
-
let foundLessThan = false;
|
|
2320
|
-
let ti = this._tokens.length - 1;
|
|
2321
|
-
for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
|
|
2322
|
-
if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
|
|
2323
|
-
if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
|
|
2324
|
-
foundLessThan = true;
|
|
2325
|
-
}
|
|
2326
|
-
break;
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
if (foundLessThan) {
|
|
2330
|
-
this._addToken(matchedType);
|
|
2331
|
-
return true;
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
if (matchedType === TokenTypes.none) {
|
|
2335
|
-
let lookAheadLexeme = lexeme;
|
|
2336
|
-
let lookAhead = 0;
|
|
2337
|
-
const maxLookAhead = 2;
|
|
2338
|
-
for (let li = 0; li < maxLookAhead; ++li) {
|
|
2339
|
-
lookAheadLexeme += this._peekAhead(li);
|
|
2340
|
-
matchedType = this._findType(lookAheadLexeme);
|
|
2341
|
-
if (matchedType !== TokenTypes.none) {
|
|
2342
|
-
lookAhead = li;
|
|
2343
|
-
break;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
if (matchedType === TokenTypes.none) {
|
|
2347
|
-
if (matchType === TokenTypes.none)
|
|
2348
|
-
return false;
|
|
2349
|
-
this._current--;
|
|
2350
|
-
this._addToken(matchType);
|
|
2351
|
-
return true;
|
|
2352
|
-
}
|
|
2353
|
-
lexeme = lookAheadLexeme;
|
|
2354
|
-
this._current += lookAhead + 1;
|
|
2355
|
-
}
|
|
2356
|
-
matchType = matchedType;
|
|
2357
|
-
if (this._isAtEnd())
|
|
2358
|
-
break;
|
|
2359
|
-
lexeme += this._advance();
|
|
2360
|
-
}
|
|
2361
|
-
if (matchType === TokenTypes.none)
|
|
2362
|
-
return false;
|
|
2363
|
-
this._addToken(matchType);
|
|
2364
|
-
return true;
|
|
2365
|
-
}
|
|
2366
|
-
_findType(lexeme) {
|
|
2367
|
-
for (const name in TokenTypes.keywords) {
|
|
2368
|
-
const type = TokenTypes.keywords[name];
|
|
2369
|
-
if (this._match(lexeme, type.rule)) {
|
|
2370
|
-
return type;
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
for (const name in TokenTypes.tokens) {
|
|
2374
|
-
const type = TokenTypes.tokens[name];
|
|
2375
|
-
if (this._match(lexeme, type.rule)) {
|
|
2376
|
-
return type;
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
return TokenTypes.none;
|
|
2380
|
-
}
|
|
2381
|
-
_match(lexeme, rule) {
|
|
2382
|
-
if (typeof rule === "string") {
|
|
2383
|
-
if (rule == lexeme) {
|
|
2384
|
-
return true;
|
|
2385
|
-
}
|
|
2386
|
-
} else {
|
|
2387
|
-
const match = rule.exec(lexeme);
|
|
2388
|
-
if (match && match.index == 0 && match[0] == lexeme)
|
|
2389
|
-
return true;
|
|
2390
|
-
}
|
|
2391
|
-
return false;
|
|
2392
|
-
}
|
|
2393
|
-
_isAtEnd() {
|
|
2394
|
-
return this._current >= this._source.length;
|
|
2395
|
-
}
|
|
2396
|
-
_isWhitespace(c) {
|
|
2397
|
-
return c == " " || c == " " || c == "\r";
|
|
2398
|
-
}
|
|
2399
|
-
_advance(amount = 0) {
|
|
2400
|
-
let c = this._source[this._current];
|
|
2401
|
-
amount = amount || 0;
|
|
2402
|
-
amount++;
|
|
2403
|
-
this._current += amount;
|
|
2404
|
-
return c;
|
|
2405
|
-
}
|
|
2406
|
-
_peekAhead(offset = 0) {
|
|
2407
|
-
offset = offset || 0;
|
|
2408
|
-
if (this._current + offset >= this._source.length)
|
|
2409
|
-
return "\0";
|
|
2410
|
-
return this._source[this._current + offset];
|
|
2411
|
-
}
|
|
2412
|
-
_addToken(type) {
|
|
2413
|
-
const text = this._source.substring(this._start, this._current);
|
|
2414
|
-
this._tokens.push(new Token(type, text, this._line));
|
|
2415
|
-
}
|
|
2416
|
-
};
|
|
2417
|
-
var WgslParser = class {
|
|
2418
|
-
constructor() {
|
|
2419
|
-
this._tokens = [];
|
|
2420
|
-
this._current = 0;
|
|
2421
|
-
this._context = new ParseContext();
|
|
2422
|
-
}
|
|
2423
|
-
parse(tokensOrCode) {
|
|
2424
|
-
this._initialize(tokensOrCode);
|
|
2425
|
-
let statements = [];
|
|
2426
|
-
while (!this._isAtEnd()) {
|
|
2427
|
-
const statement = this._global_decl_or_directive();
|
|
2428
|
-
if (!statement)
|
|
2429
|
-
break;
|
|
2430
|
-
statements.push(statement);
|
|
2431
|
-
}
|
|
2432
|
-
return statements;
|
|
2433
|
-
}
|
|
2434
|
-
_initialize(tokensOrCode) {
|
|
2435
|
-
if (tokensOrCode) {
|
|
2436
|
-
if (typeof tokensOrCode == "string") {
|
|
2437
|
-
const scanner = new WgslScanner(tokensOrCode);
|
|
2438
|
-
this._tokens = scanner.scanTokens();
|
|
2439
|
-
} else {
|
|
2440
|
-
this._tokens = tokensOrCode;
|
|
2441
|
-
}
|
|
2442
|
-
} else {
|
|
2443
|
-
this._tokens = [];
|
|
2444
|
-
}
|
|
2445
|
-
this._current = 0;
|
|
2446
|
-
}
|
|
2447
|
-
_error(token, message) {
|
|
2448
|
-
console.error(token, message);
|
|
2449
|
-
return {
|
|
2450
|
-
token,
|
|
2451
|
-
message,
|
|
2452
|
-
toString: function() {
|
|
2453
|
-
return `${message}`;
|
|
2454
|
-
}
|
|
2455
|
-
};
|
|
2456
|
-
}
|
|
2457
|
-
_isAtEnd() {
|
|
2458
|
-
return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
|
|
2459
|
-
}
|
|
2460
|
-
_match(types) {
|
|
2461
|
-
if (types instanceof TokenType) {
|
|
2462
|
-
if (this._check(types)) {
|
|
2463
|
-
this._advance();
|
|
2464
|
-
return true;
|
|
2465
|
-
}
|
|
2466
|
-
return false;
|
|
2467
|
-
}
|
|
2468
|
-
for (let i = 0, l = types.length; i < l; ++i) {
|
|
2469
|
-
const type = types[i];
|
|
2470
|
-
if (this._check(type)) {
|
|
2471
|
-
this._advance();
|
|
2472
|
-
return true;
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
return false;
|
|
2476
|
-
}
|
|
2477
|
-
_consume(types, message) {
|
|
2478
|
-
if (this._check(types))
|
|
2479
|
-
return this._advance();
|
|
2480
|
-
throw this._error(this._peek(), message);
|
|
2481
|
-
}
|
|
2482
|
-
_check(types) {
|
|
2483
|
-
if (this._isAtEnd())
|
|
2484
|
-
return false;
|
|
2485
|
-
const tk = this._peek();
|
|
2486
|
-
if (types instanceof Array) {
|
|
2487
|
-
let t = tk.type;
|
|
2488
|
-
let index2 = types.indexOf(t);
|
|
2489
|
-
return index2 != -1;
|
|
2490
|
-
}
|
|
2491
|
-
return tk.type == types;
|
|
2492
|
-
}
|
|
2493
|
-
_advance() {
|
|
2494
|
-
if (!this._isAtEnd())
|
|
2495
|
-
this._current++;
|
|
2496
|
-
return this._previous();
|
|
2497
|
-
}
|
|
2498
|
-
_peek() {
|
|
2499
|
-
return this._tokens[this._current];
|
|
2500
|
-
}
|
|
2501
|
-
_previous() {
|
|
2502
|
-
return this._tokens[this._current - 1];
|
|
2503
|
-
}
|
|
2504
|
-
_global_decl_or_directive() {
|
|
2505
|
-
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
2506
|
-
;
|
|
2507
|
-
if (this._match(TokenTypes.keywords.alias)) {
|
|
2508
|
-
const type = this._type_alias();
|
|
2509
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2510
|
-
return type;
|
|
2511
|
-
}
|
|
2512
|
-
if (this._match(TokenTypes.keywords.enable)) {
|
|
2513
|
-
const enable = this._enable_directive();
|
|
2514
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2515
|
-
return enable;
|
|
2516
|
-
}
|
|
2517
|
-
const attrs = this._attribute();
|
|
2518
|
-
if (this._check(TokenTypes.keywords.var)) {
|
|
2519
|
-
const _var = this._global_variable_decl();
|
|
2520
|
-
if (_var != null)
|
|
2521
|
-
_var.attributes = attrs;
|
|
2522
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2523
|
-
return _var;
|
|
2524
|
-
}
|
|
2525
|
-
if (this._check(TokenTypes.keywords.override)) {
|
|
2526
|
-
const _override = this._override_variable_decl();
|
|
2527
|
-
if (_override != null)
|
|
2528
|
-
_override.attributes = attrs;
|
|
2529
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2530
|
-
return _override;
|
|
2531
|
-
}
|
|
2532
|
-
if (this._check(TokenTypes.keywords.let)) {
|
|
2533
|
-
const _let = this._global_let_decl();
|
|
2534
|
-
if (_let != null)
|
|
2535
|
-
_let.attributes = attrs;
|
|
2536
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2537
|
-
return _let;
|
|
2538
|
-
}
|
|
2539
|
-
if (this._check(TokenTypes.keywords.const)) {
|
|
2540
|
-
const _const = this._global_const_decl();
|
|
2541
|
-
if (_const != null)
|
|
2542
|
-
_const.attributes = attrs;
|
|
2543
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2544
|
-
return _const;
|
|
2545
|
-
}
|
|
2546
|
-
if (this._check(TokenTypes.keywords.struct)) {
|
|
2547
|
-
const _struct = this._struct_decl();
|
|
2548
|
-
if (_struct != null)
|
|
2549
|
-
_struct.attributes = attrs;
|
|
2550
|
-
return _struct;
|
|
2551
|
-
}
|
|
2552
|
-
if (this._check(TokenTypes.keywords.fn)) {
|
|
2553
|
-
const _fn = this._function_decl();
|
|
2554
|
-
if (_fn != null)
|
|
2555
|
-
_fn.attributes = attrs;
|
|
2556
|
-
return _fn;
|
|
2557
|
-
}
|
|
2558
|
-
return null;
|
|
2559
|
-
}
|
|
2560
|
-
_function_decl() {
|
|
2561
|
-
if (!this._match(TokenTypes.keywords.fn))
|
|
2562
|
-
return null;
|
|
2563
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
2564
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
2565
|
-
const args = [];
|
|
2566
|
-
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
2567
|
-
do {
|
|
2568
|
-
if (this._check(TokenTypes.tokens.paren_right))
|
|
2569
|
-
break;
|
|
2570
|
-
const argAttrs = this._attribute();
|
|
2571
|
-
const name2 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
2572
|
-
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
2573
|
-
const typeAttrs = this._attribute();
|
|
2574
|
-
const type = this._type_decl();
|
|
2575
|
-
if (type != null) {
|
|
2576
|
-
type.attributes = typeAttrs;
|
|
2577
|
-
args.push(new Argument(name2, type, argAttrs));
|
|
2578
|
-
}
|
|
2579
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
2580
|
-
}
|
|
2581
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
|
|
2582
|
-
let _return = null;
|
|
2583
|
-
if (this._match(TokenTypes.tokens.arrow)) {
|
|
2584
|
-
const attrs = this._attribute();
|
|
2585
|
-
_return = this._type_decl();
|
|
2586
|
-
if (_return != null)
|
|
2587
|
-
_return.attributes = attrs;
|
|
2588
|
-
}
|
|
2589
|
-
const body = this._compound_statement();
|
|
2590
|
-
return new Function(name, args, _return, body);
|
|
2591
|
-
}
|
|
2592
|
-
_compound_statement() {
|
|
2593
|
-
const statements = [];
|
|
2594
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
2595
|
-
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
2596
|
-
const statement = this._statement();
|
|
2597
|
-
if (statement !== null)
|
|
2598
|
-
statements.push(statement);
|
|
2599
|
-
}
|
|
2600
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
2601
|
-
return statements;
|
|
2602
|
-
}
|
|
2603
|
-
_statement() {
|
|
2604
|
-
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
2605
|
-
;
|
|
2606
|
-
if (this._check(TokenTypes.keywords.if))
|
|
2607
|
-
return this._if_statement();
|
|
2608
|
-
if (this._check(TokenTypes.keywords.switch))
|
|
2609
|
-
return this._switch_statement();
|
|
2610
|
-
if (this._check(TokenTypes.keywords.loop))
|
|
2611
|
-
return this._loop_statement();
|
|
2612
|
-
if (this._check(TokenTypes.keywords.for))
|
|
2613
|
-
return this._for_statement();
|
|
2614
|
-
if (this._check(TokenTypes.keywords.while))
|
|
2615
|
-
return this._while_statement();
|
|
2616
|
-
if (this._check(TokenTypes.keywords.continuing))
|
|
2617
|
-
return this._continuing_statement();
|
|
2618
|
-
if (this._check(TokenTypes.keywords.static_assert))
|
|
2619
|
-
return this._static_assert_statement();
|
|
2620
|
-
if (this._check(TokenTypes.tokens.brace_left))
|
|
2621
|
-
return this._compound_statement();
|
|
2622
|
-
let result = null;
|
|
2623
|
-
if (this._check(TokenTypes.keywords.return))
|
|
2624
|
-
result = this._return_statement();
|
|
2625
|
-
else if (this._check([
|
|
2626
|
-
TokenTypes.keywords.var,
|
|
2627
|
-
TokenTypes.keywords.let,
|
|
2628
|
-
TokenTypes.keywords.const
|
|
2629
|
-
]))
|
|
2630
|
-
result = this._variable_statement();
|
|
2631
|
-
else if (this._match(TokenTypes.keywords.discard))
|
|
2632
|
-
result = new Discard();
|
|
2633
|
-
else if (this._match(TokenTypes.keywords.break))
|
|
2634
|
-
result = new Break();
|
|
2635
|
-
else if (this._match(TokenTypes.keywords.continue))
|
|
2636
|
-
result = new Continue();
|
|
2637
|
-
else
|
|
2638
|
-
result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
|
|
2639
|
-
if (result != null)
|
|
2640
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
2641
|
-
return result;
|
|
2642
|
-
}
|
|
2643
|
-
_static_assert_statement() {
|
|
2644
|
-
if (!this._match(TokenTypes.keywords.static_assert))
|
|
2645
|
-
return null;
|
|
2646
|
-
let expression = this._optional_paren_expression();
|
|
2647
|
-
return new StaticAssert(expression);
|
|
2648
|
-
}
|
|
2649
|
-
_while_statement() {
|
|
2650
|
-
if (!this._match(TokenTypes.keywords.while))
|
|
2651
|
-
return null;
|
|
2652
|
-
let condition = this._optional_paren_expression();
|
|
2653
|
-
const block = this._compound_statement();
|
|
2654
|
-
return new While(condition, block);
|
|
2655
|
-
}
|
|
2656
|
-
_continuing_statement() {
|
|
2657
|
-
if (!this._match(TokenTypes.keywords.continuing))
|
|
2658
|
-
return null;
|
|
2659
|
-
const block = this._compound_statement();
|
|
2660
|
-
return new Continuing(block);
|
|
2661
|
-
}
|
|
2662
|
-
_for_statement() {
|
|
2663
|
-
if (!this._match(TokenTypes.keywords.for))
|
|
2664
|
-
return null;
|
|
2665
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
2666
|
-
const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
|
|
2667
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2668
|
-
const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
|
|
2669
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2670
|
-
const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
|
|
2671
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
2672
|
-
const body = this._compound_statement();
|
|
2673
|
-
return new For(init, condition, increment, body);
|
|
2674
|
-
}
|
|
2675
|
-
_for_init() {
|
|
2676
|
-
return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
|
|
2677
|
-
}
|
|
2678
|
-
_for_increment() {
|
|
2679
|
-
return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
|
|
2680
|
-
}
|
|
2681
|
-
_variable_statement() {
|
|
2682
|
-
if (this._check(TokenTypes.keywords.var)) {
|
|
2683
|
-
const _var = this._variable_decl();
|
|
2684
|
-
if (_var === null)
|
|
2685
|
-
throw this._error(this._peek(), "Variable declaration expected.");
|
|
2686
|
-
let value = null;
|
|
2687
|
-
if (this._match(TokenTypes.tokens.equal))
|
|
2688
|
-
value = this._short_circuit_or_expression();
|
|
2689
|
-
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
2690
|
-
}
|
|
2691
|
-
if (this._match(TokenTypes.keywords.let)) {
|
|
2692
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
|
|
2693
|
-
let type = null;
|
|
2694
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
2695
|
-
const typeAttrs = this._attribute();
|
|
2696
|
-
type = this._type_decl();
|
|
2697
|
-
if (type != null)
|
|
2698
|
-
type.attributes = typeAttrs;
|
|
2699
|
-
}
|
|
2700
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
2701
|
-
const value = this._short_circuit_or_expression();
|
|
2702
|
-
return new Let(name, type, null, null, value);
|
|
2703
|
-
}
|
|
2704
|
-
if (this._match(TokenTypes.keywords.const)) {
|
|
2705
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
|
|
2706
|
-
let type = null;
|
|
2707
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
2708
|
-
const typeAttrs = this._attribute();
|
|
2709
|
-
type = this._type_decl();
|
|
2710
|
-
if (type != null)
|
|
2711
|
-
type.attributes = typeAttrs;
|
|
2712
|
-
}
|
|
2713
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
2714
|
-
const value = this._short_circuit_or_expression();
|
|
2715
|
-
return new Const(name, type, null, null, value);
|
|
2716
|
-
}
|
|
2717
|
-
return null;
|
|
2718
|
-
}
|
|
2719
|
-
_increment_decrement_statement() {
|
|
2720
|
-
const savedPos = this._current;
|
|
2721
|
-
const _var = this._unary_expression();
|
|
2722
|
-
if (_var == null)
|
|
2723
|
-
return null;
|
|
2724
|
-
if (!this._check(TokenTypes.increment_operators)) {
|
|
2725
|
-
this._current = savedPos;
|
|
2726
|
-
return null;
|
|
2727
|
-
}
|
|
2728
|
-
const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
|
|
2729
|
-
return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
|
|
2730
|
-
}
|
|
2731
|
-
_assignment_statement() {
|
|
2732
|
-
let _var = null;
|
|
2733
|
-
if (this._check(TokenTypes.tokens.brace_right))
|
|
2734
|
-
return null;
|
|
2735
|
-
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
2736
|
-
if (!isUnderscore)
|
|
2737
|
-
_var = this._unary_expression();
|
|
2738
|
-
if (!isUnderscore && _var == null)
|
|
2739
|
-
return null;
|
|
2740
|
-
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
2741
|
-
const value = this._short_circuit_or_expression();
|
|
2742
|
-
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
2743
|
-
}
|
|
2744
|
-
_func_call_statement() {
|
|
2745
|
-
if (!this._check(TokenTypes.tokens.ident))
|
|
2746
|
-
return null;
|
|
2747
|
-
const savedPos = this._current;
|
|
2748
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
2749
|
-
const args = this._argument_expression_list();
|
|
2750
|
-
if (args === null) {
|
|
2751
|
-
this._current = savedPos;
|
|
2752
|
-
return null;
|
|
2753
|
-
}
|
|
2754
|
-
return new Call(name.lexeme, args);
|
|
2755
|
-
}
|
|
2756
|
-
_loop_statement() {
|
|
2757
|
-
if (!this._match(TokenTypes.keywords.loop))
|
|
2758
|
-
return null;
|
|
2759
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
2760
|
-
const statements = [];
|
|
2761
|
-
let statement = this._statement();
|
|
2762
|
-
while (statement !== null) {
|
|
2763
|
-
if (Array.isArray(statement)) {
|
|
2764
|
-
for (let s of statement) {
|
|
2765
|
-
statements.push(s);
|
|
2766
|
-
}
|
|
2767
|
-
} else {
|
|
2768
|
-
statements.push(statement);
|
|
2769
|
-
}
|
|
2770
|
-
statement = this._statement();
|
|
2771
|
-
}
|
|
2772
|
-
let continuing = null;
|
|
2773
|
-
if (this._match(TokenTypes.keywords.continuing))
|
|
2774
|
-
continuing = this._compound_statement();
|
|
2775
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
2776
|
-
return new Loop(statements, continuing);
|
|
2777
|
-
}
|
|
2778
|
-
_switch_statement() {
|
|
2779
|
-
if (!this._match(TokenTypes.keywords.switch))
|
|
2780
|
-
return null;
|
|
2781
|
-
const condition = this._optional_paren_expression();
|
|
2782
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
2783
|
-
const body = this._switch_body();
|
|
2784
|
-
if (body == null || body.length == 0)
|
|
2785
|
-
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
2786
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
2787
|
-
return new Switch(condition, body);
|
|
2788
|
-
}
|
|
2789
|
-
_switch_body() {
|
|
2790
|
-
const cases = [];
|
|
2791
|
-
if (this._match(TokenTypes.keywords.case)) {
|
|
2792
|
-
const selector = this._case_selectors();
|
|
2793
|
-
this._match(TokenTypes.tokens.colon);
|
|
2794
|
-
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
2795
|
-
const body = this._case_body();
|
|
2796
|
-
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
2797
|
-
cases.push(new Case(selector, body));
|
|
2798
|
-
}
|
|
2799
|
-
if (this._match(TokenTypes.keywords.default)) {
|
|
2800
|
-
this._match(TokenTypes.tokens.colon);
|
|
2801
|
-
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
2802
|
-
const body = this._case_body();
|
|
2803
|
-
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
2804
|
-
cases.push(new Default(body));
|
|
2805
|
-
}
|
|
2806
|
-
if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
|
|
2807
|
-
const _cases = this._switch_body();
|
|
2808
|
-
cases.push(_cases[0]);
|
|
2809
|
-
}
|
|
2810
|
-
return cases;
|
|
2811
|
-
}
|
|
2812
|
-
_case_selectors() {
|
|
2813
|
-
var _a2, _b, _c, _d;
|
|
2814
|
-
const selectors = [
|
|
2815
|
-
(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""
|
|
2816
|
-
];
|
|
2817
|
-
while (this._match(TokenTypes.tokens.comma)) {
|
|
2818
|
-
selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
|
|
2819
|
-
}
|
|
2820
|
-
return selectors;
|
|
2821
|
-
}
|
|
2822
|
-
_case_body() {
|
|
2823
|
-
if (this._match(TokenTypes.keywords.fallthrough)) {
|
|
2824
|
-
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2825
|
-
return [];
|
|
2826
|
-
}
|
|
2827
|
-
let statement = this._statement();
|
|
2828
|
-
if (statement == null)
|
|
2829
|
-
return [];
|
|
2830
|
-
if (!(statement instanceof Array)) {
|
|
2831
|
-
statement = [statement];
|
|
2832
|
-
}
|
|
2833
|
-
const nextStatement = this._case_body();
|
|
2834
|
-
if (nextStatement.length == 0)
|
|
2835
|
-
return statement;
|
|
2836
|
-
return [...statement, nextStatement[0]];
|
|
2837
|
-
}
|
|
2838
|
-
_if_statement() {
|
|
2839
|
-
if (!this._match(TokenTypes.keywords.if))
|
|
2840
|
-
return null;
|
|
2841
|
-
const condition = this._optional_paren_expression();
|
|
2842
|
-
const block = this._compound_statement();
|
|
2843
|
-
let elseif = [];
|
|
2844
|
-
if (this._match_elseif()) {
|
|
2845
|
-
elseif = this._elseif_statement(elseif);
|
|
2846
|
-
}
|
|
2847
|
-
let _else = null;
|
|
2848
|
-
if (this._match(TokenTypes.keywords.else))
|
|
2849
|
-
_else = this._compound_statement();
|
|
2850
|
-
return new If(condition, block, elseif, _else);
|
|
2851
|
-
}
|
|
2852
|
-
_match_elseif() {
|
|
2853
|
-
if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
|
|
2854
|
-
this._advance();
|
|
2855
|
-
this._advance();
|
|
2856
|
-
return true;
|
|
2857
|
-
}
|
|
2858
|
-
return false;
|
|
2859
|
-
}
|
|
2860
|
-
_elseif_statement(elseif = []) {
|
|
2861
|
-
const condition = this._optional_paren_expression();
|
|
2862
|
-
const block = this._compound_statement();
|
|
2863
|
-
elseif.push(new ElseIf(condition, block));
|
|
2864
|
-
if (this._match_elseif()) {
|
|
2865
|
-
this._elseif_statement(elseif);
|
|
2866
|
-
}
|
|
2867
|
-
return elseif;
|
|
2868
|
-
}
|
|
2869
|
-
_return_statement() {
|
|
2870
|
-
if (!this._match(TokenTypes.keywords.return))
|
|
2871
|
-
return null;
|
|
2872
|
-
const value = this._short_circuit_or_expression();
|
|
2873
|
-
return new Return(value);
|
|
2874
|
-
}
|
|
2875
|
-
_short_circuit_or_expression() {
|
|
2876
|
-
let expr = this._short_circuit_and_expr();
|
|
2877
|
-
while (this._match(TokenTypes.tokens.or_or)) {
|
|
2878
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
|
|
2879
|
-
}
|
|
2880
|
-
return expr;
|
|
2881
|
-
}
|
|
2882
|
-
_short_circuit_and_expr() {
|
|
2883
|
-
let expr = this._inclusive_or_expression();
|
|
2884
|
-
while (this._match(TokenTypes.tokens.and_and)) {
|
|
2885
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
|
|
2886
|
-
}
|
|
2887
|
-
return expr;
|
|
2888
|
-
}
|
|
2889
|
-
_inclusive_or_expression() {
|
|
2890
|
-
let expr = this._exclusive_or_expression();
|
|
2891
|
-
while (this._match(TokenTypes.tokens.or)) {
|
|
2892
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
|
|
2893
|
-
}
|
|
2894
|
-
return expr;
|
|
2895
|
-
}
|
|
2896
|
-
_exclusive_or_expression() {
|
|
2897
|
-
let expr = this._and_expression();
|
|
2898
|
-
while (this._match(TokenTypes.tokens.xor)) {
|
|
2899
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
|
|
2900
|
-
}
|
|
2901
|
-
return expr;
|
|
2902
|
-
}
|
|
2903
|
-
_and_expression() {
|
|
2904
|
-
let expr = this._equality_expression();
|
|
2905
|
-
while (this._match(TokenTypes.tokens.and)) {
|
|
2906
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
|
|
2907
|
-
}
|
|
2908
|
-
return expr;
|
|
2909
|
-
}
|
|
2910
|
-
_equality_expression() {
|
|
2911
|
-
const expr = this._relational_expression();
|
|
2912
|
-
if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
|
|
2913
|
-
return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
|
|
2914
|
-
}
|
|
2915
|
-
return expr;
|
|
2916
|
-
}
|
|
2917
|
-
_relational_expression() {
|
|
2918
|
-
let expr = this._shift_expression();
|
|
2919
|
-
while (this._match([
|
|
2920
|
-
TokenTypes.tokens.less_than,
|
|
2921
|
-
TokenTypes.tokens.greater_than,
|
|
2922
|
-
TokenTypes.tokens.less_than_equal,
|
|
2923
|
-
TokenTypes.tokens.greater_than_equal
|
|
2924
|
-
])) {
|
|
2925
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
|
|
2926
|
-
}
|
|
2927
|
-
return expr;
|
|
2928
|
-
}
|
|
2929
|
-
_shift_expression() {
|
|
2930
|
-
let expr = this._additive_expression();
|
|
2931
|
-
while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
|
|
2932
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
|
|
2933
|
-
}
|
|
2934
|
-
return expr;
|
|
2935
|
-
}
|
|
2936
|
-
_additive_expression() {
|
|
2937
|
-
let expr = this._multiplicative_expression();
|
|
2938
|
-
while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
|
|
2939
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
|
|
2940
|
-
}
|
|
2941
|
-
return expr;
|
|
2942
|
-
}
|
|
2943
|
-
_multiplicative_expression() {
|
|
2944
|
-
let expr = this._unary_expression();
|
|
2945
|
-
while (this._match([
|
|
2946
|
-
TokenTypes.tokens.star,
|
|
2947
|
-
TokenTypes.tokens.forward_slash,
|
|
2948
|
-
TokenTypes.tokens.modulo
|
|
2949
|
-
])) {
|
|
2950
|
-
expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
|
|
2951
|
-
}
|
|
2952
|
-
return expr;
|
|
2953
|
-
}
|
|
2954
|
-
_unary_expression() {
|
|
2955
|
-
if (this._match([
|
|
2956
|
-
TokenTypes.tokens.minus,
|
|
2957
|
-
TokenTypes.tokens.bang,
|
|
2958
|
-
TokenTypes.tokens.tilde,
|
|
2959
|
-
TokenTypes.tokens.star,
|
|
2960
|
-
TokenTypes.tokens.and
|
|
2961
|
-
])) {
|
|
2962
|
-
return new UnaryOperator(this._previous().toString(), this._unary_expression());
|
|
2963
|
-
}
|
|
2964
|
-
return this._singular_expression();
|
|
2965
|
-
}
|
|
2966
|
-
_singular_expression() {
|
|
2967
|
-
const expr = this._primary_expression();
|
|
2968
|
-
const p = this._postfix_expression();
|
|
2969
|
-
if (p)
|
|
2970
|
-
expr.postfix = p;
|
|
2971
|
-
return expr;
|
|
2972
|
-
}
|
|
2973
|
-
_postfix_expression() {
|
|
2974
|
-
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
2975
|
-
const expr = this._short_circuit_or_expression();
|
|
2976
|
-
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
2977
|
-
const p = this._postfix_expression();
|
|
2978
|
-
if (p)
|
|
2979
|
-
expr.postfix = p;
|
|
2980
|
-
return expr;
|
|
2981
|
-
}
|
|
2982
|
-
if (this._match(TokenTypes.tokens.period)) {
|
|
2983
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
2984
|
-
const p = this._postfix_expression();
|
|
2985
|
-
const expr = new StringExpr(name.lexeme);
|
|
2986
|
-
if (p)
|
|
2987
|
-
expr.postfix = p;
|
|
2988
|
-
return expr;
|
|
2989
|
-
}
|
|
2990
|
-
return null;
|
|
2991
|
-
}
|
|
2992
|
-
_getStruct(name) {
|
|
2993
|
-
if (this._context.aliases.has(name)) {
|
|
2994
|
-
const alias = this._context.aliases.get(name).type;
|
|
2995
|
-
return alias;
|
|
2996
|
-
}
|
|
2997
|
-
if (this._context.structs.has(name)) {
|
|
2998
|
-
const struct = this._context.structs.get(name);
|
|
2999
|
-
return struct;
|
|
3000
|
-
}
|
|
3001
|
-
return null;
|
|
3002
|
-
}
|
|
3003
|
-
_primary_expression() {
|
|
3004
|
-
if (this._match(TokenTypes.tokens.ident)) {
|
|
3005
|
-
const name = this._previous().toString();
|
|
3006
|
-
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
3007
|
-
const args2 = this._argument_expression_list();
|
|
3008
|
-
const struct = this._getStruct(name);
|
|
3009
|
-
if (struct != null) {
|
|
3010
|
-
return new CreateExpr(struct, args2);
|
|
3011
|
-
}
|
|
3012
|
-
return new CallExpr(name, args2);
|
|
3013
|
-
}
|
|
3014
|
-
if (this._context.constants.has(name)) {
|
|
3015
|
-
const c = this._context.constants.get(name);
|
|
3016
|
-
return new ConstExpr(name, c.value);
|
|
3017
|
-
}
|
|
3018
|
-
return new VariableExpr(name);
|
|
3019
|
-
}
|
|
3020
|
-
if (this._match(TokenTypes.const_literal)) {
|
|
3021
|
-
return new LiteralExpr(parseFloat(this._previous().toString()));
|
|
3022
|
-
}
|
|
3023
|
-
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
3024
|
-
return this._paren_expression();
|
|
3025
|
-
}
|
|
3026
|
-
if (this._match(TokenTypes.keywords.bitcast)) {
|
|
3027
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
|
|
3028
|
-
const type2 = this._type_decl();
|
|
3029
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
3030
|
-
const value = this._paren_expression();
|
|
3031
|
-
return new BitcastExpr(type2, value);
|
|
3032
|
-
}
|
|
3033
|
-
const type = this._type_decl();
|
|
3034
|
-
const args = this._argument_expression_list();
|
|
3035
|
-
return new TypecastExpr(type, args);
|
|
3036
|
-
}
|
|
3037
|
-
_argument_expression_list() {
|
|
3038
|
-
if (!this._match(TokenTypes.tokens.paren_left))
|
|
3039
|
-
return null;
|
|
3040
|
-
const args = [];
|
|
3041
|
-
do {
|
|
3042
|
-
if (this._check(TokenTypes.tokens.paren_right))
|
|
3043
|
-
break;
|
|
3044
|
-
const arg = this._short_circuit_or_expression();
|
|
3045
|
-
args.push(arg);
|
|
3046
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
3047
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
|
|
3048
|
-
return args;
|
|
3049
|
-
}
|
|
3050
|
-
_optional_paren_expression() {
|
|
3051
|
-
this._match(TokenTypes.tokens.paren_left);
|
|
3052
|
-
const expr = this._short_circuit_or_expression();
|
|
3053
|
-
this._match(TokenTypes.tokens.paren_right);
|
|
3054
|
-
return new GroupingExpr([expr]);
|
|
3055
|
-
}
|
|
3056
|
-
_paren_expression() {
|
|
3057
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3058
|
-
const expr = this._short_circuit_or_expression();
|
|
3059
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3060
|
-
return new GroupingExpr([expr]);
|
|
3061
|
-
}
|
|
3062
|
-
_struct_decl() {
|
|
3063
|
-
if (!this._match(TokenTypes.keywords.struct))
|
|
3064
|
-
return null;
|
|
3065
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
3066
|
-
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
3067
|
-
const members = [];
|
|
3068
|
-
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
3069
|
-
const memberAttrs = this._attribute();
|
|
3070
|
-
const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
|
|
3071
|
-
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
3072
|
-
const typeAttrs = this._attribute();
|
|
3073
|
-
const memberType = this._type_decl();
|
|
3074
|
-
if (memberType != null)
|
|
3075
|
-
memberType.attributes = typeAttrs;
|
|
3076
|
-
if (!this._check(TokenTypes.tokens.brace_right))
|
|
3077
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
3078
|
-
else
|
|
3079
|
-
this._match(TokenTypes.tokens.comma);
|
|
3080
|
-
members.push(new Member(memberName, memberType, memberAttrs));
|
|
3081
|
-
}
|
|
3082
|
-
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
3083
|
-
const structNode = new Struct(name, members);
|
|
3084
|
-
this._context.structs.set(name, structNode);
|
|
3085
|
-
return structNode;
|
|
3086
|
-
}
|
|
3087
|
-
_global_variable_decl() {
|
|
3088
|
-
const _var = this._variable_decl();
|
|
3089
|
-
if (_var && this._match(TokenTypes.tokens.equal))
|
|
3090
|
-
_var.value = this._const_expression();
|
|
3091
|
-
return _var;
|
|
3092
|
-
}
|
|
3093
|
-
_override_variable_decl() {
|
|
3094
|
-
const _override = this._override_decl();
|
|
3095
|
-
if (_override && this._match(TokenTypes.tokens.equal))
|
|
3096
|
-
_override.value = this._const_expression();
|
|
3097
|
-
return _override;
|
|
3098
|
-
}
|
|
3099
|
-
_global_const_decl() {
|
|
3100
|
-
if (!this._match(TokenTypes.keywords.const))
|
|
3101
|
-
return null;
|
|
3102
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3103
|
-
let type = null;
|
|
3104
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
3105
|
-
const attrs = this._attribute();
|
|
3106
|
-
type = this._type_decl();
|
|
3107
|
-
if (type != null)
|
|
3108
|
-
type.attributes = attrs;
|
|
3109
|
-
}
|
|
3110
|
-
let value = null;
|
|
3111
|
-
if (this._match(TokenTypes.tokens.equal)) {
|
|
3112
|
-
const valueExpr = this._short_circuit_or_expression();
|
|
3113
|
-
if (valueExpr instanceof CreateExpr) {
|
|
3114
|
-
value = valueExpr;
|
|
3115
|
-
} else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
|
|
3116
|
-
value = valueExpr.initializer;
|
|
3117
|
-
} else {
|
|
3118
|
-
try {
|
|
3119
|
-
const constValue = valueExpr.evaluate(this._context);
|
|
3120
|
-
value = new LiteralExpr(constValue);
|
|
3121
|
-
} catch (_a2) {
|
|
3122
|
-
value = valueExpr;
|
|
3123
|
-
}
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
const c = new Const(name.toString(), type, "", "", value);
|
|
3127
|
-
this._context.constants.set(c.name, c);
|
|
3128
|
-
return c;
|
|
3129
|
-
}
|
|
3130
|
-
_global_let_decl() {
|
|
3131
|
-
if (!this._match(TokenTypes.keywords.let))
|
|
3132
|
-
return null;
|
|
3133
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3134
|
-
let type = null;
|
|
3135
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
3136
|
-
const attrs = this._attribute();
|
|
3137
|
-
type = this._type_decl();
|
|
3138
|
-
if (type != null)
|
|
3139
|
-
type.attributes = attrs;
|
|
3140
|
-
}
|
|
3141
|
-
let value = null;
|
|
3142
|
-
if (this._match(TokenTypes.tokens.equal)) {
|
|
3143
|
-
value = this._const_expression();
|
|
3144
|
-
}
|
|
3145
|
-
return new Let(name.toString(), type, "", "", value);
|
|
3146
|
-
}
|
|
3147
|
-
_const_expression() {
|
|
3148
|
-
if (this._match(TokenTypes.const_literal))
|
|
3149
|
-
return new StringExpr(this._previous().toString());
|
|
3150
|
-
const type = this._type_decl();
|
|
3151
|
-
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3152
|
-
let args = [];
|
|
3153
|
-
while (!this._check(TokenTypes.tokens.paren_right)) {
|
|
3154
|
-
args.push(this._const_expression());
|
|
3155
|
-
if (!this._check(TokenTypes.tokens.comma))
|
|
3156
|
-
break;
|
|
3157
|
-
this._advance();
|
|
3158
|
-
}
|
|
3159
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3160
|
-
return new CreateExpr(type, args);
|
|
3161
|
-
}
|
|
3162
|
-
_variable_decl() {
|
|
3163
|
-
if (!this._match(TokenTypes.keywords.var))
|
|
3164
|
-
return null;
|
|
3165
|
-
let storage = "";
|
|
3166
|
-
let access = "";
|
|
3167
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3168
|
-
storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
|
|
3169
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
3170
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
|
|
3171
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
3172
|
-
}
|
|
3173
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3174
|
-
let type = null;
|
|
3175
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
3176
|
-
const attrs = this._attribute();
|
|
3177
|
-
type = this._type_decl();
|
|
3178
|
-
if (type != null)
|
|
3179
|
-
type.attributes = attrs;
|
|
3180
|
-
}
|
|
3181
|
-
return new Var(name.toString(), type, storage, access, null);
|
|
3182
|
-
}
|
|
3183
|
-
_override_decl() {
|
|
3184
|
-
if (!this._match(TokenTypes.keywords.override))
|
|
3185
|
-
return null;
|
|
3186
|
-
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3187
|
-
let type = null;
|
|
3188
|
-
if (this._match(TokenTypes.tokens.colon)) {
|
|
3189
|
-
const attrs = this._attribute();
|
|
3190
|
-
type = this._type_decl();
|
|
3191
|
-
if (type != null)
|
|
3192
|
-
type.attributes = attrs;
|
|
3193
|
-
}
|
|
3194
|
-
return new Override(name.toString(), type, null);
|
|
3195
|
-
}
|
|
3196
|
-
_enable_directive() {
|
|
3197
|
-
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3198
|
-
return new Enable(name.toString());
|
|
3199
|
-
}
|
|
3200
|
-
_type_alias() {
|
|
3201
|
-
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3202
|
-
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
3203
|
-
let aliasType = this._type_decl();
|
|
3204
|
-
if (aliasType === null) {
|
|
3205
|
-
throw this._error(this._peek(), "Expected Type for Alias.");
|
|
3206
|
-
}
|
|
3207
|
-
if (this._context.aliases.has(aliasType.name)) {
|
|
3208
|
-
aliasType = this._context.aliases.get(aliasType.name).type;
|
|
3209
|
-
}
|
|
3210
|
-
const aliasNode = new Alias(name.toString(), aliasType);
|
|
3211
|
-
this._context.aliases.set(aliasNode.name, aliasNode);
|
|
3212
|
-
return aliasNode;
|
|
3213
|
-
}
|
|
3214
|
-
_type_decl() {
|
|
3215
|
-
if (this._check([
|
|
3216
|
-
TokenTypes.tokens.ident,
|
|
3217
|
-
...TokenTypes.texel_format,
|
|
3218
|
-
TokenTypes.keywords.bool,
|
|
3219
|
-
TokenTypes.keywords.f32,
|
|
3220
|
-
TokenTypes.keywords.i32,
|
|
3221
|
-
TokenTypes.keywords.u32
|
|
3222
|
-
])) {
|
|
3223
|
-
const type2 = this._advance();
|
|
3224
|
-
const typeName = type2.toString();
|
|
3225
|
-
if (this._context.structs.has(typeName)) {
|
|
3226
|
-
return this._context.structs.get(typeName);
|
|
3227
|
-
}
|
|
3228
|
-
if (this._context.aliases.has(typeName)) {
|
|
3229
|
-
return this._context.aliases.get(typeName).type;
|
|
3230
|
-
}
|
|
3231
|
-
return new Type(type2.toString());
|
|
3232
|
-
}
|
|
3233
|
-
let type = this._texture_sampler_types();
|
|
3234
|
-
if (type)
|
|
3235
|
-
return type;
|
|
3236
|
-
if (this._check(TokenTypes.template_types)) {
|
|
3237
|
-
let type2 = this._advance().toString();
|
|
3238
|
-
let format = null;
|
|
3239
|
-
let access = null;
|
|
3240
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3241
|
-
format = this._type_decl();
|
|
3242
|
-
access = null;
|
|
3243
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
3244
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
3245
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
3246
|
-
}
|
|
3247
|
-
return new TemplateType(type2, format, access);
|
|
3248
|
-
}
|
|
3249
|
-
if (this._match(TokenTypes.keywords.ptr)) {
|
|
3250
|
-
let pointer = this._previous().toString();
|
|
3251
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
|
|
3252
|
-
const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
|
|
3253
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
3254
|
-
const decl = this._type_decl();
|
|
3255
|
-
let access = null;
|
|
3256
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
3257
|
-
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
3258
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
3259
|
-
return new PointerType(pointer, storage.toString(), decl, access);
|
|
3260
|
-
}
|
|
3261
|
-
const attrs = this._attribute();
|
|
3262
|
-
if (this._match(TokenTypes.keywords.array)) {
|
|
3263
|
-
let format = null;
|
|
3264
|
-
let countInt = -1;
|
|
3265
|
-
const array = this._previous();
|
|
3266
|
-
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3267
|
-
format = this._type_decl();
|
|
3268
|
-
if (this._context.aliases.has(format.name)) {
|
|
3269
|
-
format = this._context.aliases.get(format.name).type;
|
|
3270
|
-
}
|
|
3271
|
-
let count = "";
|
|
3272
|
-
if (this._match(TokenTypes.tokens.comma)) {
|
|
3273
|
-
let c = this._shift_expression();
|
|
3274
|
-
count = c.evaluate(this._context).toString();
|
|
3275
|
-
}
|
|
3276
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
3277
|
-
countInt = count ? parseInt(count) : 0;
|
|
3278
|
-
}
|
|
3279
|
-
return new ArrayType(array.toString(), attrs, format, countInt);
|
|
3280
|
-
}
|
|
3281
|
-
return null;
|
|
3282
|
-
}
|
|
3283
|
-
_texture_sampler_types() {
|
|
3284
|
-
if (this._match(TokenTypes.sampler_type))
|
|
3285
|
-
return new SamplerType(this._previous().toString(), null, null);
|
|
3286
|
-
if (this._match(TokenTypes.depth_texture_type))
|
|
3287
|
-
return new SamplerType(this._previous().toString(), null, null);
|
|
3288
|
-
if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
|
|
3289
|
-
const sampler = this._previous();
|
|
3290
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
3291
|
-
const format = this._type_decl();
|
|
3292
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
3293
|
-
return new SamplerType(sampler.toString(), format, null);
|
|
3294
|
-
}
|
|
3295
|
-
if (this._match(TokenTypes.storage_texture_type)) {
|
|
3296
|
-
const sampler = this._previous();
|
|
3297
|
-
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
3298
|
-
const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
|
|
3299
|
-
this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
|
|
3300
|
-
const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
|
|
3301
|
-
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
3302
|
-
return new SamplerType(sampler.toString(), format, access);
|
|
3303
|
-
}
|
|
3304
|
-
return null;
|
|
3305
|
-
}
|
|
3306
|
-
_attribute() {
|
|
3307
|
-
let attributes = [];
|
|
3308
|
-
while (this._match(TokenTypes.tokens.attr)) {
|
|
3309
|
-
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
3310
|
-
const attr = new Attribute(name.toString(), null);
|
|
3311
|
-
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
3312
|
-
attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3313
|
-
if (this._check(TokenTypes.tokens.comma)) {
|
|
3314
|
-
this._advance();
|
|
3315
|
-
do {
|
|
3316
|
-
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3317
|
-
if (!(attr.value instanceof Array)) {
|
|
3318
|
-
attr.value = [attr.value];
|
|
3319
|
-
}
|
|
3320
|
-
attr.value.push(v);
|
|
3321
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
3322
|
-
}
|
|
3323
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
3324
|
-
}
|
|
3325
|
-
attributes.push(attr);
|
|
3326
|
-
}
|
|
3327
|
-
while (this._match(TokenTypes.tokens.attr_left)) {
|
|
3328
|
-
if (!this._check(TokenTypes.tokens.attr_right)) {
|
|
3329
|
-
do {
|
|
3330
|
-
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
3331
|
-
const attr = new Attribute(name.toString(), null);
|
|
3332
|
-
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
3333
|
-
attr.value = [
|
|
3334
|
-
this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()
|
|
3335
|
-
];
|
|
3336
|
-
if (this._check(TokenTypes.tokens.comma)) {
|
|
3337
|
-
this._advance();
|
|
3338
|
-
do {
|
|
3339
|
-
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3340
|
-
attr.value.push(v);
|
|
3341
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
3342
|
-
}
|
|
3343
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
3344
|
-
}
|
|
3345
|
-
attributes.push(attr);
|
|
3346
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
3347
|
-
}
|
|
3348
|
-
this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
|
|
3349
|
-
}
|
|
3350
|
-
if (attributes.length == 0)
|
|
3351
|
-
return null;
|
|
3352
|
-
return attributes;
|
|
3353
|
-
}
|
|
3354
|
-
};
|
|
3355
|
-
var TypeInfo = class {
|
|
3356
|
-
constructor(name, attributes) {
|
|
3357
|
-
this.name = name;
|
|
3358
|
-
this.attributes = attributes;
|
|
3359
|
-
this.size = 0;
|
|
3360
|
-
}
|
|
3361
|
-
get isArray() {
|
|
3362
|
-
return false;
|
|
3363
|
-
}
|
|
3364
|
-
get isStruct() {
|
|
3365
|
-
return false;
|
|
3366
|
-
}
|
|
3367
|
-
get isTemplate() {
|
|
3368
|
-
return false;
|
|
3369
|
-
}
|
|
3370
|
-
};
|
|
3371
|
-
var MemberInfo = class {
|
|
3372
|
-
constructor(name, type, attributes) {
|
|
3373
|
-
this.name = name;
|
|
3374
|
-
this.type = type;
|
|
3375
|
-
this.attributes = attributes;
|
|
3376
|
-
this.offset = 0;
|
|
3377
|
-
this.size = 0;
|
|
3378
|
-
}
|
|
3379
|
-
get isArray() {
|
|
3380
|
-
return this.type.isArray;
|
|
3381
|
-
}
|
|
3382
|
-
get isStruct() {
|
|
3383
|
-
return this.type.isStruct;
|
|
3384
|
-
}
|
|
3385
|
-
get isTemplate() {
|
|
3386
|
-
return this.type.isTemplate;
|
|
3387
|
-
}
|
|
3388
|
-
get align() {
|
|
3389
|
-
return this.type.isStruct ? this.type.align : 0;
|
|
3390
|
-
}
|
|
3391
|
-
get members() {
|
|
3392
|
-
return this.type.isStruct ? this.type.members : null;
|
|
3393
|
-
}
|
|
3394
|
-
get format() {
|
|
3395
|
-
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
3396
|
-
}
|
|
3397
|
-
get count() {
|
|
3398
|
-
return this.type.isArray ? this.type.count : 0;
|
|
3399
|
-
}
|
|
3400
|
-
get stride() {
|
|
3401
|
-
return this.type.isArray ? this.type.stride : this.size;
|
|
3402
|
-
}
|
|
3403
|
-
};
|
|
3404
|
-
var StructInfo = class extends TypeInfo {
|
|
3405
|
-
constructor(name, attributes) {
|
|
3406
|
-
super(name, attributes);
|
|
3407
|
-
this.members = [];
|
|
3408
|
-
this.align = 0;
|
|
3409
|
-
}
|
|
3410
|
-
get isStruct() {
|
|
3411
|
-
return true;
|
|
3412
|
-
}
|
|
3413
|
-
};
|
|
3414
|
-
var ArrayInfo = class extends TypeInfo {
|
|
3415
|
-
constructor(name, attributes) {
|
|
3416
|
-
super(name, attributes);
|
|
3417
|
-
this.count = 0;
|
|
3418
|
-
this.stride = 0;
|
|
3419
|
-
}
|
|
3420
|
-
get isArray() {
|
|
3421
|
-
return true;
|
|
3422
|
-
}
|
|
3423
|
-
};
|
|
3424
|
-
var TemplateInfo = class extends TypeInfo {
|
|
3425
|
-
constructor(name, format, attributes, access) {
|
|
3426
|
-
super(name, attributes);
|
|
3427
|
-
this.format = format;
|
|
3428
|
-
this.access = access;
|
|
3429
|
-
}
|
|
3430
|
-
get isTemplate() {
|
|
3431
|
-
return true;
|
|
3432
|
-
}
|
|
3433
|
-
};
|
|
3434
|
-
var ResourceType;
|
|
3435
|
-
(function(ResourceType2) {
|
|
3436
|
-
ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
|
|
3437
|
-
ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
|
|
3438
|
-
ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
|
|
3439
|
-
ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
|
|
3440
|
-
ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
|
|
3441
|
-
})(ResourceType || (ResourceType = {}));
|
|
3442
|
-
var VariableInfo = class {
|
|
3443
|
-
constructor(name, type, group, binding, attributes, resourceType, access) {
|
|
3444
|
-
this.name = name;
|
|
3445
|
-
this.type = type;
|
|
3446
|
-
this.group = group;
|
|
3447
|
-
this.binding = binding;
|
|
3448
|
-
this.attributes = attributes;
|
|
3449
|
-
this.resourceType = resourceType;
|
|
3450
|
-
this.access = access;
|
|
3451
|
-
}
|
|
3452
|
-
get isArray() {
|
|
3453
|
-
return this.type.isArray;
|
|
3454
|
-
}
|
|
3455
|
-
get isStruct() {
|
|
3456
|
-
return this.type.isStruct;
|
|
3457
|
-
}
|
|
3458
|
-
get isTemplate() {
|
|
3459
|
-
return this.type.isTemplate;
|
|
3460
|
-
}
|
|
3461
|
-
get size() {
|
|
3462
|
-
return this.type.size;
|
|
3463
|
-
}
|
|
3464
|
-
get align() {
|
|
3465
|
-
return this.type.isStruct ? this.type.align : 0;
|
|
3466
|
-
}
|
|
3467
|
-
get members() {
|
|
3468
|
-
return this.type.isStruct ? this.type.members : null;
|
|
3469
|
-
}
|
|
3470
|
-
get format() {
|
|
3471
|
-
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
3472
|
-
}
|
|
3473
|
-
get count() {
|
|
3474
|
-
return this.type.isArray ? this.type.count : 0;
|
|
3475
|
-
}
|
|
3476
|
-
get stride() {
|
|
3477
|
-
return this.type.isArray ? this.type.stride : this.size;
|
|
3478
|
-
}
|
|
3479
|
-
};
|
|
3480
|
-
var AliasInfo = class {
|
|
3481
|
-
constructor(name, type) {
|
|
3482
|
-
this.name = name;
|
|
3483
|
-
this.type = type;
|
|
3484
|
-
}
|
|
3485
|
-
};
|
|
3486
|
-
var _TypeSize = class {
|
|
3487
|
-
constructor(align, size) {
|
|
3488
|
-
this.align = align;
|
|
3489
|
-
this.size = size;
|
|
3490
|
-
}
|
|
3491
|
-
};
|
|
3492
|
-
var InputInfo = class {
|
|
3493
|
-
constructor(name, type, locationType, location) {
|
|
3494
|
-
this.name = name;
|
|
3495
|
-
this.type = type;
|
|
3496
|
-
this.locationType = locationType;
|
|
3497
|
-
this.location = location;
|
|
3498
|
-
this.interpolation = null;
|
|
3499
|
-
}
|
|
3500
|
-
};
|
|
3501
|
-
var OutputInfo = class {
|
|
3502
|
-
constructor(name, type, locationType, location) {
|
|
3503
|
-
this.name = name;
|
|
3504
|
-
this.type = type;
|
|
3505
|
-
this.locationType = locationType;
|
|
3506
|
-
this.location = location;
|
|
3507
|
-
}
|
|
3508
|
-
};
|
|
3509
|
-
var FunctionInfo = class {
|
|
3510
|
-
constructor(name, stage = null) {
|
|
3511
|
-
this.stage = null;
|
|
3512
|
-
this.inputs = [];
|
|
3513
|
-
this.outputs = [];
|
|
3514
|
-
this.name = name;
|
|
3515
|
-
this.stage = stage;
|
|
3516
|
-
}
|
|
3517
|
-
};
|
|
3518
|
-
var EntryFunctions = class {
|
|
3519
|
-
constructor() {
|
|
3520
|
-
this.vertex = [];
|
|
3521
|
-
this.fragment = [];
|
|
3522
|
-
this.compute = [];
|
|
3523
|
-
}
|
|
3524
|
-
};
|
|
3525
|
-
var OverrideInfo = class {
|
|
3526
|
-
constructor(name, type, attributes, id) {
|
|
3527
|
-
this.name = name;
|
|
3528
|
-
this.type = type;
|
|
3529
|
-
this.attributes = attributes;
|
|
3530
|
-
this.id = id;
|
|
3531
|
-
}
|
|
3532
|
-
};
|
|
3533
|
-
var WgslReflect = class {
|
|
3534
|
-
constructor(code) {
|
|
3535
|
-
this.uniforms = [];
|
|
3536
|
-
this.storage = [];
|
|
3537
|
-
this.textures = [];
|
|
3538
|
-
this.samplers = [];
|
|
3539
|
-
this.aliases = [];
|
|
3540
|
-
this.overrides = [];
|
|
3541
|
-
this.structs = [];
|
|
3542
|
-
this.entry = new EntryFunctions();
|
|
3543
|
-
this._types = /* @__PURE__ */ new Map();
|
|
3544
|
-
if (code) {
|
|
3545
|
-
this.update(code);
|
|
3546
|
-
}
|
|
3547
|
-
}
|
|
3548
|
-
_isStorageTexture(type) {
|
|
3549
|
-
return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
|
|
3550
|
-
}
|
|
3551
|
-
update(code) {
|
|
3552
|
-
const parser = new WgslParser();
|
|
3553
|
-
const ast = parser.parse(code);
|
|
3554
|
-
for (const node of ast) {
|
|
3555
|
-
if (node instanceof Struct) {
|
|
3556
|
-
const info = this._getTypeInfo(node, null);
|
|
3557
|
-
if (info instanceof StructInfo) {
|
|
3558
|
-
this.structs.push(info);
|
|
3559
|
-
}
|
|
3560
|
-
continue;
|
|
3561
|
-
}
|
|
3562
|
-
if (node instanceof Alias) {
|
|
3563
|
-
this.aliases.push(this._getAliasInfo(node));
|
|
3564
|
-
continue;
|
|
3565
|
-
}
|
|
3566
|
-
if (node instanceof Override) {
|
|
3567
|
-
const v = node;
|
|
3568
|
-
const id = this._getAttributeNum(v.attributes, "id", 0);
|
|
3569
|
-
const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
|
|
3570
|
-
this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
|
|
3571
|
-
continue;
|
|
3572
|
-
}
|
|
3573
|
-
if (this._isUniformVar(node)) {
|
|
3574
|
-
const v = node;
|
|
3575
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3576
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3577
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3578
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
|
|
3579
|
-
this.uniforms.push(varInfo);
|
|
3580
|
-
continue;
|
|
3581
|
-
}
|
|
3582
|
-
if (this._isStorageVar(node)) {
|
|
3583
|
-
const v = node;
|
|
3584
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3585
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3586
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3587
|
-
const isStorageTexture = this._isStorageTexture(type);
|
|
3588
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
|
|
3589
|
-
this.storage.push(varInfo);
|
|
3590
|
-
continue;
|
|
3591
|
-
}
|
|
3592
|
-
if (this._isTextureVar(node)) {
|
|
3593
|
-
const v = node;
|
|
3594
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3595
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3596
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3597
|
-
const isStorageTexture = this._isStorageTexture(type);
|
|
3598
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
|
|
3599
|
-
if (isStorageTexture) {
|
|
3600
|
-
this.storage.push(varInfo);
|
|
3601
|
-
} else {
|
|
3602
|
-
this.textures.push(varInfo);
|
|
3603
|
-
}
|
|
3604
|
-
continue;
|
|
3605
|
-
}
|
|
3606
|
-
if (this._isSamplerVar(node)) {
|
|
3607
|
-
const v = node;
|
|
3608
|
-
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3609
|
-
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3610
|
-
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3611
|
-
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
|
|
3612
|
-
this.samplers.push(varInfo);
|
|
3613
|
-
continue;
|
|
3614
|
-
}
|
|
3615
|
-
if (node instanceof Function) {
|
|
3616
|
-
const vertexStage = this._getAttribute(node, "vertex");
|
|
3617
|
-
const fragmentStage = this._getAttribute(node, "fragment");
|
|
3618
|
-
const computeStage = this._getAttribute(node, "compute");
|
|
3619
|
-
const stage = vertexStage || fragmentStage || computeStage;
|
|
3620
|
-
if (stage) {
|
|
3621
|
-
const fn = new FunctionInfo(node.name, stage.name);
|
|
3622
|
-
fn.inputs = this._getInputs(node.args);
|
|
3623
|
-
fn.outputs = this._getOutputs(node.returnType);
|
|
3624
|
-
this.entry[stage.name].push(fn);
|
|
3625
|
-
}
|
|
3626
|
-
continue;
|
|
3627
|
-
}
|
|
3628
|
-
}
|
|
3629
|
-
}
|
|
3630
|
-
getBindGroups() {
|
|
3631
|
-
const groups = [];
|
|
3632
|
-
function _makeRoom(group, binding) {
|
|
3633
|
-
if (group >= groups.length)
|
|
3634
|
-
groups.length = group + 1;
|
|
3635
|
-
if (groups[group] === void 0)
|
|
3636
|
-
groups[group] = [];
|
|
3637
|
-
if (binding >= groups[group].length)
|
|
3638
|
-
groups[group].length = binding + 1;
|
|
3639
|
-
}
|
|
3640
|
-
for (const u of this.uniforms) {
|
|
3641
|
-
_makeRoom(u.group, u.binding);
|
|
3642
|
-
const group = groups[u.group];
|
|
3643
|
-
group[u.binding] = u;
|
|
3644
|
-
}
|
|
3645
|
-
for (const u of this.storage) {
|
|
3646
|
-
_makeRoom(u.group, u.binding);
|
|
3647
|
-
const group = groups[u.group];
|
|
3648
|
-
group[u.binding] = u;
|
|
3649
|
-
}
|
|
3650
|
-
for (const t of this.textures) {
|
|
3651
|
-
_makeRoom(t.group, t.binding);
|
|
3652
|
-
const group = groups[t.group];
|
|
3653
|
-
group[t.binding] = t;
|
|
3654
|
-
}
|
|
3655
|
-
for (const t of this.samplers) {
|
|
3656
|
-
_makeRoom(t.group, t.binding);
|
|
3657
|
-
const group = groups[t.group];
|
|
3658
|
-
group[t.binding] = t;
|
|
3659
|
-
}
|
|
3660
|
-
return groups;
|
|
3661
|
-
}
|
|
3662
|
-
_getOutputs(type, outputs = void 0) {
|
|
3663
|
-
if (outputs === void 0)
|
|
3664
|
-
outputs = [];
|
|
3665
|
-
if (type instanceof Struct) {
|
|
3666
|
-
this._getStructOutputs(type, outputs);
|
|
3667
|
-
} else {
|
|
3668
|
-
const output = this._getOutputInfo(type);
|
|
3669
|
-
if (output !== null)
|
|
3670
|
-
outputs.push(output);
|
|
3671
|
-
}
|
|
3672
|
-
return outputs;
|
|
3673
|
-
}
|
|
3674
|
-
_getStructOutputs(struct, outputs) {
|
|
3675
|
-
for (const m of struct.members) {
|
|
3676
|
-
if (m.type instanceof Struct) {
|
|
3677
|
-
this._getStructOutputs(m.type, outputs);
|
|
3678
|
-
} else {
|
|
3679
|
-
const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
|
|
3680
|
-
if (location !== null) {
|
|
3681
|
-
const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
|
|
3682
|
-
const locationValue = this._parseInt(location.value);
|
|
3683
|
-
const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
|
|
3684
|
-
outputs.push(info);
|
|
3685
|
-
}
|
|
3686
|
-
}
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
_getOutputInfo(type) {
|
|
3690
|
-
const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
|
|
3691
|
-
if (location !== null) {
|
|
3692
|
-
const typeInfo = this._getTypeInfo(type, type.attributes);
|
|
3693
|
-
const locationValue = this._parseInt(location.value);
|
|
3694
|
-
const info = new OutputInfo("", typeInfo, location.name, locationValue);
|
|
3695
|
-
return info;
|
|
3696
|
-
}
|
|
3697
|
-
return null;
|
|
3698
|
-
}
|
|
3699
|
-
_getInputs(args, inputs = void 0) {
|
|
3700
|
-
if (inputs === void 0)
|
|
3701
|
-
inputs = [];
|
|
3702
|
-
for (const arg of args) {
|
|
3703
|
-
if (arg.type instanceof Struct) {
|
|
3704
|
-
this._getStructInputs(arg.type, inputs);
|
|
3705
|
-
} else {
|
|
3706
|
-
const input = this._getInputInfo(arg);
|
|
3707
|
-
if (input !== null)
|
|
3708
|
-
inputs.push(input);
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
return inputs;
|
|
3712
|
-
}
|
|
3713
|
-
_getStructInputs(struct, inputs) {
|
|
3714
|
-
for (const m of struct.members) {
|
|
3715
|
-
if (m.type instanceof Struct) {
|
|
3716
|
-
this._getStructInputs(m.type, inputs);
|
|
3717
|
-
} else {
|
|
3718
|
-
const input = this._getInputInfo(m);
|
|
3719
|
-
if (input !== null)
|
|
3720
|
-
inputs.push(input);
|
|
3721
|
-
}
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
_getInputInfo(node) {
|
|
3725
|
-
const location = this._getAttribute(node, "location") || this._getAttribute(node, "builtin");
|
|
3726
|
-
if (location !== null) {
|
|
3727
|
-
const interpolation = this._getAttribute(node, "interpolation");
|
|
3728
|
-
const type = this._getTypeInfo(node.type, node.attributes);
|
|
3729
|
-
const locationValue = this._parseInt(location.value);
|
|
3730
|
-
const info = new InputInfo(node.name, type, location.name, locationValue);
|
|
3731
|
-
if (interpolation !== null) {
|
|
3732
|
-
info.interpolation = this._parseString(interpolation.value);
|
|
3733
|
-
}
|
|
3734
|
-
return info;
|
|
3735
|
-
}
|
|
3736
|
-
return null;
|
|
3737
|
-
}
|
|
3738
|
-
_parseString(s) {
|
|
3739
|
-
if (s instanceof Array) {
|
|
3740
|
-
s = s[0];
|
|
3741
|
-
}
|
|
3742
|
-
return s;
|
|
3743
|
-
}
|
|
3744
|
-
_parseInt(s) {
|
|
3745
|
-
if (s instanceof Array) {
|
|
3746
|
-
s = s[0];
|
|
3747
|
-
}
|
|
3748
|
-
const n = parseInt(s);
|
|
3749
|
-
return isNaN(n) ? s : n;
|
|
3750
|
-
}
|
|
3751
|
-
_getAlias(name) {
|
|
3752
|
-
for (const a of this.aliases) {
|
|
3753
|
-
if (a.name == name)
|
|
3754
|
-
return a.type;
|
|
3755
|
-
}
|
|
3756
|
-
return null;
|
|
3757
|
-
}
|
|
3758
|
-
_getAliasInfo(node) {
|
|
3759
|
-
return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
|
|
3760
|
-
}
|
|
3761
|
-
_getTypeInfo(type, attributes) {
|
|
3762
|
-
if (this._types.has(type)) {
|
|
3763
|
-
return this._types.get(type);
|
|
3764
|
-
}
|
|
3765
|
-
if (type instanceof ArrayType) {
|
|
3766
|
-
const a = type;
|
|
3767
|
-
const t = this._getTypeInfo(a.format, a.attributes);
|
|
3768
|
-
const info2 = new ArrayInfo(a.name, attributes);
|
|
3769
|
-
info2.format = t;
|
|
3770
|
-
info2.count = a.count;
|
|
3771
|
-
this._types.set(type, info2);
|
|
3772
|
-
this._updateTypeInfo(info2);
|
|
3773
|
-
return info2;
|
|
3774
|
-
}
|
|
3775
|
-
if (type instanceof Struct) {
|
|
3776
|
-
const s = type;
|
|
3777
|
-
const info2 = new StructInfo(s.name, attributes);
|
|
3778
|
-
for (const m of s.members) {
|
|
3779
|
-
const t = this._getTypeInfo(m.type, m.attributes);
|
|
3780
|
-
info2.members.push(new MemberInfo(m.name, t, m.attributes));
|
|
3781
|
-
}
|
|
3782
|
-
this._types.set(type, info2);
|
|
3783
|
-
this._updateTypeInfo(info2);
|
|
3784
|
-
return info2;
|
|
3785
|
-
}
|
|
3786
|
-
if (type instanceof SamplerType) {
|
|
3787
|
-
const s = type;
|
|
3788
|
-
const formatIsType = s.format instanceof Type;
|
|
3789
|
-
const format = s.format ? formatIsType ? this._getTypeInfo(s.format, null) : new TypeInfo(s.format, null) : null;
|
|
3790
|
-
const info2 = new TemplateInfo(s.name, format, attributes, s.access);
|
|
3791
|
-
this._types.set(type, info2);
|
|
3792
|
-
this._updateTypeInfo(info2);
|
|
3793
|
-
return info2;
|
|
3794
|
-
}
|
|
3795
|
-
if (type instanceof TemplateType) {
|
|
3796
|
-
const t = type;
|
|
3797
|
-
const format = t.format ? this._getTypeInfo(t.format, null) : null;
|
|
3798
|
-
const info2 = new TemplateInfo(t.name, format, attributes, t.access);
|
|
3799
|
-
this._types.set(type, info2);
|
|
3800
|
-
this._updateTypeInfo(info2);
|
|
3801
|
-
return info2;
|
|
3802
|
-
}
|
|
3803
|
-
const info = new TypeInfo(type.name, attributes);
|
|
3804
|
-
this._types.set(type, info);
|
|
3805
|
-
this._updateTypeInfo(info);
|
|
3806
|
-
return info;
|
|
3807
|
-
}
|
|
3808
|
-
_updateTypeInfo(type) {
|
|
3809
|
-
var _a2, _b;
|
|
3810
|
-
const typeSize = this._getTypeSize(type);
|
|
3811
|
-
type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
|
|
3812
|
-
if (type instanceof ArrayInfo) {
|
|
3813
|
-
const formatInfo = this._getTypeSize(type["format"]);
|
|
3814
|
-
type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
|
|
3815
|
-
this._updateTypeInfo(type["format"]);
|
|
3816
|
-
}
|
|
3817
|
-
if (type instanceof StructInfo) {
|
|
3818
|
-
this._updateStructInfo(type);
|
|
3819
|
-
}
|
|
3820
|
-
}
|
|
3821
|
-
_updateStructInfo(struct) {
|
|
3822
|
-
var _a2;
|
|
3823
|
-
let offset = 0;
|
|
3824
|
-
let lastSize = 0;
|
|
3825
|
-
let lastOffset = 0;
|
|
3826
|
-
let structAlign = 0;
|
|
3827
|
-
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
3828
|
-
const member = struct.members[mi];
|
|
3829
|
-
const sizeInfo = this._getTypeSize(member);
|
|
3830
|
-
if (!sizeInfo)
|
|
3831
|
-
continue;
|
|
3832
|
-
(_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
|
|
3833
|
-
const align = sizeInfo.align;
|
|
3834
|
-
const size = sizeInfo.size;
|
|
3835
|
-
offset = this._roundUp(align, offset + lastSize);
|
|
3836
|
-
lastSize = size;
|
|
3837
|
-
lastOffset = offset;
|
|
3838
|
-
structAlign = Math.max(structAlign, align);
|
|
3839
|
-
member.offset = offset;
|
|
3840
|
-
member.size = size;
|
|
3841
|
-
this._updateTypeInfo(member.type);
|
|
3842
|
-
}
|
|
3843
|
-
struct.size = this._roundUp(structAlign, lastOffset + lastSize);
|
|
3844
|
-
struct.align = structAlign;
|
|
3845
|
-
}
|
|
3846
|
-
_getTypeSize(type) {
|
|
3847
|
-
var _a2;
|
|
3848
|
-
if (type === null || type === void 0)
|
|
3849
|
-
return null;
|
|
3850
|
-
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
3851
|
-
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
3852
|
-
if (type instanceof MemberInfo)
|
|
3853
|
-
type = type.type;
|
|
3854
|
-
if (type instanceof TypeInfo) {
|
|
3855
|
-
const alias = this._getAlias(type.name);
|
|
3856
|
-
if (alias !== null) {
|
|
3857
|
-
type = alias;
|
|
3858
|
-
}
|
|
3859
|
-
}
|
|
3860
|
-
{
|
|
3861
|
-
const info = WgslReflect._typeInfo[type.name];
|
|
3862
|
-
if (info !== void 0) {
|
|
3863
|
-
const divisor = type["format"] === "f16" ? 2 : 1;
|
|
3864
|
-
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
3865
|
-
}
|
|
3866
|
-
}
|
|
3867
|
-
{
|
|
3868
|
-
const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
|
|
3869
|
-
if (info) {
|
|
3870
|
-
const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
|
|
3871
|
-
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
3872
|
-
}
|
|
3873
|
-
}
|
|
3874
|
-
if (type instanceof ArrayInfo) {
|
|
3875
|
-
let arrayType = type;
|
|
3876
|
-
let align = 8;
|
|
3877
|
-
let size = 8;
|
|
3878
|
-
const E = this._getTypeSize(arrayType.format);
|
|
3879
|
-
if (E !== null) {
|
|
3880
|
-
size = E.size;
|
|
3881
|
-
align = E.align;
|
|
3882
|
-
}
|
|
3883
|
-
const N = arrayType.count;
|
|
3884
|
-
const stride = this._getAttributeNum((_a2 = type === null || type === void 0 ? void 0 : type.attributes) !== null && _a2 !== void 0 ? _a2 : null, "stride", this._roundUp(align, size));
|
|
3885
|
-
size = N * stride;
|
|
3886
|
-
if (explicitSize)
|
|
3887
|
-
size = explicitSize;
|
|
3888
|
-
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
3889
|
-
}
|
|
3890
|
-
if (type instanceof StructInfo) {
|
|
3891
|
-
let align = 0;
|
|
3892
|
-
let size = 0;
|
|
3893
|
-
let offset = 0;
|
|
3894
|
-
let lastSize = 0;
|
|
3895
|
-
let lastOffset = 0;
|
|
3896
|
-
for (const m of type.members) {
|
|
3897
|
-
const mi = this._getTypeSize(m.type);
|
|
3898
|
-
if (mi !== null) {
|
|
3899
|
-
align = Math.max(mi.align, align);
|
|
3900
|
-
offset = this._roundUp(mi.align, offset + lastSize);
|
|
3901
|
-
lastSize = mi.size;
|
|
3902
|
-
lastOffset = offset;
|
|
3903
|
-
}
|
|
3904
|
-
}
|
|
3905
|
-
size = this._roundUp(align, lastOffset + lastSize);
|
|
3906
|
-
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
3907
|
-
}
|
|
3908
|
-
return null;
|
|
3909
|
-
}
|
|
3910
|
-
_isUniformVar(node) {
|
|
3911
|
-
return node instanceof Var && node.storage == "uniform";
|
|
3912
|
-
}
|
|
3913
|
-
_isStorageVar(node) {
|
|
3914
|
-
return node instanceof Var && node.storage == "storage";
|
|
3915
|
-
}
|
|
3916
|
-
_isTextureVar(node) {
|
|
3917
|
-
return node instanceof Var && node.type !== null && WgslReflect._textureTypes.indexOf(node.type.name) != -1;
|
|
3918
|
-
}
|
|
3919
|
-
_isSamplerVar(node) {
|
|
3920
|
-
return node instanceof Var && node.type !== null && WgslReflect._samplerTypes.indexOf(node.type.name) != -1;
|
|
3921
|
-
}
|
|
3922
|
-
_getAttribute(node, name) {
|
|
3923
|
-
const obj = node;
|
|
3924
|
-
if (!obj || !obj["attributes"])
|
|
3925
|
-
return null;
|
|
3926
|
-
const attrs = obj["attributes"];
|
|
3927
|
-
for (let a of attrs) {
|
|
3928
|
-
if (a.name == name)
|
|
3929
|
-
return a;
|
|
3930
|
-
}
|
|
3931
|
-
return null;
|
|
3932
|
-
}
|
|
3933
|
-
_getAttributeNum(attributes, name, defaultValue) {
|
|
3934
|
-
if (attributes === null)
|
|
3935
|
-
return defaultValue;
|
|
3936
|
-
for (let a of attributes) {
|
|
3937
|
-
if (a.name == name) {
|
|
3938
|
-
let v = a !== null && a.value !== null ? a.value : defaultValue;
|
|
3939
|
-
if (v instanceof Array) {
|
|
3940
|
-
v = v[0];
|
|
3941
|
-
}
|
|
3942
|
-
if (typeof v === "number") {
|
|
3943
|
-
return v;
|
|
3944
|
-
}
|
|
3945
|
-
if (typeof v === "string") {
|
|
3946
|
-
return parseInt(v);
|
|
3947
|
-
}
|
|
3948
|
-
return defaultValue;
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
return defaultValue;
|
|
3952
|
-
}
|
|
3953
|
-
_roundUp(k, n) {
|
|
3954
|
-
return Math.ceil(n / k) * k;
|
|
3955
|
-
}
|
|
3956
|
-
};
|
|
3957
|
-
WgslReflect._typeInfo = {
|
|
3958
|
-
f16: { align: 2, size: 2 },
|
|
3959
|
-
i32: { align: 4, size: 4 },
|
|
3960
|
-
u32: { align: 4, size: 4 },
|
|
3961
|
-
f32: { align: 4, size: 4 },
|
|
3962
|
-
atomic: { align: 4, size: 4 },
|
|
3963
|
-
vec2: { align: 8, size: 8 },
|
|
3964
|
-
vec3: { align: 16, size: 12 },
|
|
3965
|
-
vec4: { align: 16, size: 16 },
|
|
3966
|
-
mat2x2: { align: 8, size: 16 },
|
|
3967
|
-
mat3x2: { align: 8, size: 24 },
|
|
3968
|
-
mat4x2: { align: 8, size: 32 },
|
|
3969
|
-
mat2x3: { align: 16, size: 32 },
|
|
3970
|
-
mat3x3: { align: 16, size: 48 },
|
|
3971
|
-
mat4x3: { align: 16, size: 64 },
|
|
3972
|
-
mat2x4: { align: 16, size: 32 },
|
|
3973
|
-
mat3x4: { align: 16, size: 48 },
|
|
3974
|
-
mat4x4: { align: 16, size: 64 }
|
|
3975
|
-
};
|
|
3976
|
-
WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
|
|
3977
|
-
return t.name;
|
|
3978
|
-
});
|
|
3979
|
-
WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
|
|
3980
|
-
return t.name;
|
|
3981
|
-
});
|
|
3982
|
-
|
|
3983
|
-
// dist/lib/wgsl/get-shader-layout-wgsl.js
|
|
1165
|
+
var import_wgsl_reflect = require("wgsl_reflect");
|
|
3984
1166
|
function getShaderLayoutFromWGSL(source) {
|
|
1167
|
+
var _a;
|
|
3985
1168
|
const shaderLayout = { attributes: [], bindings: [] };
|
|
3986
1169
|
let parsedWGSL;
|
|
3987
1170
|
try {
|
|
@@ -3992,10 +1175,10 @@ function getShaderLayoutFromWGSL(source) {
|
|
|
3992
1175
|
}
|
|
3993
1176
|
for (const uniform of parsedWGSL.uniforms) {
|
|
3994
1177
|
const members = [];
|
|
3995
|
-
for (const
|
|
1178
|
+
for (const attribute of ((_a = uniform.type) == null ? void 0 : _a.members) || []) {
|
|
3996
1179
|
members.push({
|
|
3997
|
-
name:
|
|
3998
|
-
type: getType(
|
|
1180
|
+
name: attribute.name,
|
|
1181
|
+
type: getType(attribute.type)
|
|
3999
1182
|
});
|
|
4000
1183
|
}
|
|
4001
1184
|
shaderLayout.bindings.push({
|
|
@@ -4015,7 +1198,7 @@ function getShaderLayoutFromWGSL(source) {
|
|
|
4015
1198
|
const type = getType(wgslAttribute.type);
|
|
4016
1199
|
shaderLayout.attributes.push({
|
|
4017
1200
|
name: wgslAttribute.name,
|
|
4018
|
-
location: wgslAttribute.location,
|
|
1201
|
+
location: Number(wgslAttribute.location),
|
|
4019
1202
|
type
|
|
4020
1203
|
});
|
|
4021
1204
|
}
|
|
@@ -4027,7 +1210,7 @@ function getType(type) {
|
|
|
4027
1210
|
}
|
|
4028
1211
|
function parseWGSL(source) {
|
|
4029
1212
|
try {
|
|
4030
|
-
return new WgslReflect(source);
|
|
1213
|
+
return new import_wgsl_reflect.WgslReflect(source);
|
|
4031
1214
|
} catch (error) {
|
|
4032
1215
|
if (error instanceof Error) {
|
|
4033
1216
|
throw error;
|
|
@@ -4460,7 +1643,7 @@ function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLig
|
|
|
4460
1643
|
return lightSourceUniforms;
|
|
4461
1644
|
}
|
|
4462
1645
|
function extractLightTypes(lights2) {
|
|
4463
|
-
var
|
|
1646
|
+
var _a, _b;
|
|
4464
1647
|
const lightSources = { pointLights: [], directionalLights: [] };
|
|
4465
1648
|
for (const light of lights2 || []) {
|
|
4466
1649
|
switch (light.type) {
|
|
@@ -4468,7 +1651,7 @@ function extractLightTypes(lights2) {
|
|
|
4468
1651
|
lightSources.ambientLight = light;
|
|
4469
1652
|
break;
|
|
4470
1653
|
case "directional":
|
|
4471
|
-
(
|
|
1654
|
+
(_a = lightSources.directionalLights) == null ? void 0 : _a.push(light);
|
|
4472
1655
|
break;
|
|
4473
1656
|
case "point":
|
|
4474
1657
|
(_b = lightSources.pointLights) == null ? void 0 : _b.push(light);
|
|
@@ -7330,7 +4513,7 @@ function getLightSourceUniforms2({ ambientLight, pointLights = [], directionalLi
|
|
|
7330
4513
|
return lightSourceUniforms;
|
|
7331
4514
|
}
|
|
7332
4515
|
function getUniforms6(opts = INITIAL_MODULE_OPTIONS) {
|
|
7333
|
-
var
|
|
4516
|
+
var _a, _b;
|
|
7334
4517
|
if ("lightSources" in opts) {
|
|
7335
4518
|
const { ambientLight, pointLights, directionalLights } = opts.lightSources || {};
|
|
7336
4519
|
const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
|
|
@@ -7349,7 +4532,7 @@ function getUniforms6(opts = INITIAL_MODULE_OPTIONS) {
|
|
|
7349
4532
|
lightSources.ambientLight = light;
|
|
7350
4533
|
break;
|
|
7351
4534
|
case "directional":
|
|
7352
|
-
(
|
|
4535
|
+
(_a = lightSources.directionalLights) == null ? void 0 : _a.push(light);
|
|
7353
4536
|
break;
|
|
7354
4537
|
case "point":
|
|
7355
4538
|
(_b = lightSources.pointLights) == null ? void 0 : _b.push(light);
|