wesl 0.6.2 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -32
- package/dist/index.js.map +1 -1
- package/dist/minified.js +152 -157
- package/dist/minified.js.map +1 -1
- package/dist/tools/packages/wesl/src/ParseWESL.d.ts +2 -2
- package/package.json +6 -6
- package/src/BindIdents.ts +10 -10
- package/src/FlattenTreeImport.ts +1 -1
- package/src/LinkedWesl.ts +3 -3
- package/src/Linker.ts +4 -4
- package/src/LinkerUtil.ts +1 -1
- package/src/LowerAndEmit.ts +10 -12
- package/src/Mangler.ts +2 -2
- package/src/ParseWESL.ts +1 -2
- package/src/ParsedRegistry.ts +8 -7
- package/src/PathUtil.ts +2 -2
- package/src/RawEmit.ts +3 -3
- package/src/Reflection.ts +1 -1
- package/src/TransformBindingStructs.ts +15 -14
- package/src/Util.ts +4 -4
- package/src/WESLCollect.ts +2 -1
- package/src/WeslDevice.ts +4 -4
- package/src/debug/ASTtoString.ts +7 -7
- package/src/debug/ImportToString.ts +2 -2
- package/src/parse/ImportGrammar.ts +2 -2
- package/src/parse/WeslGrammar.ts +6 -12
- package/src/parse/WeslStream.ts +5 -3
- package/src/test/BindWESL.test.ts +1 -1
- package/src/test/ConditionalTranslationCases.test.ts +38 -38
- package/src/test/ImportCases.test.ts +38 -39
- package/src/test/ImportSyntaxCases.test.ts +1 -1
- package/src/test/ParseWESL.test.ts +15 -15
- package/src/test/Reflection.test.ts +8 -4
- package/src/test/TestLink.ts +3 -3
- package/src/test/TestUtil.ts +1 -1
- package/src/test/WeslDevice.test.ts +4 -4
- package/src/vlq/vlq.ts +7 -6
- package/dist/tools/packages/wesl/src/test/WgslTests.d.ts +0 -0
- package/src/test/WgslTests.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -437,7 +437,7 @@ function parserArg(arg) {
|
|
|
437
437
|
function fn(fn2) {
|
|
438
438
|
const parser2 = new Parser({
|
|
439
439
|
fn: function _fn(state) {
|
|
440
|
-
|
|
440
|
+
const generatedParser = fn2();
|
|
441
441
|
if (!fn2) {
|
|
442
442
|
const before = state.stream.checkpoint();
|
|
443
443
|
throw new ParseError(`fn parser called before definition`, [
|
|
@@ -1117,13 +1117,13 @@ function mapValues(obj, fn2) {
|
|
|
1117
1117
|
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn2(v)]));
|
|
1118
1118
|
}
|
|
1119
1119
|
function offsetToLineNumber(offset, text2) {
|
|
1120
|
-
|
|
1120
|
+
const safeOffset = Math.min(text2.length, Math.max(0, offset));
|
|
1121
1121
|
let lineStartOffset = 0;
|
|
1122
1122
|
let lineNum = 1;
|
|
1123
1123
|
while (true) {
|
|
1124
1124
|
const lineEnd = text2.indexOf("\n", lineStartOffset);
|
|
1125
|
-
if (lineEnd === -1 ||
|
|
1126
|
-
const linePos = 1 + (
|
|
1125
|
+
if (lineEnd === -1 || safeOffset <= lineEnd) {
|
|
1126
|
+
const linePos = 1 + (safeOffset - lineStartOffset);
|
|
1127
1127
|
return [lineNum, linePos];
|
|
1128
1128
|
} else {
|
|
1129
1129
|
lineStartOffset = lineEnd + 1;
|
|
@@ -1173,19 +1173,20 @@ function encodeVlq(value) {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
function encode_integer(num) {
|
|
1175
1175
|
let result = "";
|
|
1176
|
+
let enc;
|
|
1176
1177
|
if (num < 0) {
|
|
1177
|
-
|
|
1178
|
+
enc = -num << 1 | 1;
|
|
1178
1179
|
} else {
|
|
1179
|
-
num
|
|
1180
|
+
enc = num << 1;
|
|
1180
1181
|
}
|
|
1181
1182
|
do {
|
|
1182
|
-
let clamped =
|
|
1183
|
-
|
|
1184
|
-
if (
|
|
1183
|
+
let clamped = enc & 31;
|
|
1184
|
+
enc >>>= 5;
|
|
1185
|
+
if (enc > 0) {
|
|
1185
1186
|
clamped |= 32;
|
|
1186
1187
|
}
|
|
1187
1188
|
result += integer_to_char[clamped];
|
|
1188
|
-
} while (
|
|
1189
|
+
} while (enc > 0);
|
|
1189
1190
|
return result;
|
|
1190
1191
|
}
|
|
1191
1192
|
function throwClickableError(params) {
|
|
@@ -1889,7 +1890,7 @@ const memberRefCollect = collectElem(
|
|
|
1889
1890
|
}
|
|
1890
1891
|
);
|
|
1891
1892
|
function nameCollect(cc) {
|
|
1892
|
-
const { start, end, src
|
|
1893
|
+
const { start, end, src } = cc;
|
|
1893
1894
|
const name2 = src.slice(start, end);
|
|
1894
1895
|
const elem = { kind: "name", start, end, name: name2 };
|
|
1895
1896
|
addToOpenElem(cc, elem);
|
|
@@ -2109,6 +2110,7 @@ const weslMatcher = new RegexMatchers({
|
|
|
2109
2110
|
blankspaces,
|
|
2110
2111
|
commentStart,
|
|
2111
2112
|
symbol: matchOneOf(symbolSet),
|
|
2113
|
+
// biome-ignore lint/correctness/noEmptyCharacterClassInRegex: TODO
|
|
2112
2114
|
invalid: /[^]/
|
|
2113
2115
|
});
|
|
2114
2116
|
function weslExtension(combinator) {
|
|
@@ -2162,7 +2164,8 @@ class WeslStream {
|
|
|
2162
2164
|
return this.eolPattern.lastIndex;
|
|
2163
2165
|
}
|
|
2164
2166
|
}
|
|
2165
|
-
skipBlockComment(
|
|
2167
|
+
skipBlockComment(start) {
|
|
2168
|
+
let position = start;
|
|
2166
2169
|
while (true) {
|
|
2167
2170
|
this.blockCommentPattern.lastIndex = position;
|
|
2168
2171
|
const result = this.blockCommentPattern.exec(this.src);
|
|
@@ -2552,10 +2555,7 @@ const struct_member = tagScope(
|
|
|
2552
2555
|
).collect(collectStructMember)
|
|
2553
2556
|
).ctag("members");
|
|
2554
2557
|
const struct_decl = seq(
|
|
2555
|
-
weslExtension(opt_attributes).collect(
|
|
2556
|
-
(cc) => cc.tags.attribute,
|
|
2557
|
-
"attributes"
|
|
2558
|
-
),
|
|
2558
|
+
weslExtension(opt_attributes).collect((cc) => cc.tags.attribute, "attributes"),
|
|
2559
2559
|
"struct",
|
|
2560
2560
|
req(globalTypeNameDecl, "invalid struct, expected name"),
|
|
2561
2561
|
seq(
|
|
@@ -2860,10 +2860,7 @@ const global_value_decl = or(
|
|
|
2860
2860
|
).collect(collectVarLike("const"))
|
|
2861
2861
|
).collect(partialScopeCollect);
|
|
2862
2862
|
const global_alias = seq(
|
|
2863
|
-
weslExtension(opt_attributes).collect(
|
|
2864
|
-
(cc) => cc.tags.attribute,
|
|
2865
|
-
"attributes"
|
|
2866
|
-
),
|
|
2863
|
+
weslExtension(opt_attributes).collect((cc) => cc.tags.attribute, "attributes"),
|
|
2867
2864
|
"alias",
|
|
2868
2865
|
req(word, "invalid alias, expected name").collect(
|
|
2869
2866
|
globalDeclCollect,
|
|
@@ -3039,7 +3036,7 @@ class WeslParseError extends Error {
|
|
|
3039
3036
|
this.src = opts.src;
|
|
3040
3037
|
}
|
|
3041
3038
|
}
|
|
3042
|
-
function parseSrcModule(srcModule
|
|
3039
|
+
function parseSrcModule(srcModule) {
|
|
3043
3040
|
const stream = new WeslStream(srcModule.src);
|
|
3044
3041
|
const appState = blankWeslParseState(srcModule);
|
|
3045
3042
|
const init = { stream, appState };
|
|
@@ -3210,7 +3207,7 @@ function findUnboundIdents(registry) {
|
|
|
3210
3207
|
unbound: [],
|
|
3211
3208
|
dontFollowDecls: true
|
|
3212
3209
|
};
|
|
3213
|
-
Object.entries(registry.modules).map(([
|
|
3210
|
+
Object.entries(registry.modules).map(([_module, ast]) => {
|
|
3214
3211
|
const rootDecls = findValidRootDecls(ast.rootScope, {});
|
|
3215
3212
|
const declEntries = rootDecls.map((d) => [d.originalName, d]);
|
|
3216
3213
|
const liveDecls = { decls: new Map(declEntries), parent: null };
|
|
@@ -3551,9 +3548,7 @@ function emitAttributes(attributes, ctx) {
|
|
|
3551
3548
|
function emitStruct(e, ctx) {
|
|
3552
3549
|
const { name: name2, members, start, end } = e;
|
|
3553
3550
|
const { srcBuilder } = ctx;
|
|
3554
|
-
const validMembers = members.filter(
|
|
3555
|
-
(m) => conditionsValid(m, ctx.conditions)
|
|
3556
|
-
);
|
|
3551
|
+
const validMembers = members.filter((m) => conditionsValid(m, ctx.conditions));
|
|
3557
3552
|
const validLength = validMembers.length;
|
|
3558
3553
|
if (validLength === 0) {
|
|
3559
3554
|
warnEmptyStruct(e);
|
|
@@ -4147,15 +4142,16 @@ function selectModule(parsed, selectPath, packageName = "package") {
|
|
|
4147
4142
|
return parsed.modules[modulePath];
|
|
4148
4143
|
}
|
|
4149
4144
|
function parseIntoRegistry(srcFiles, registry, packageName = "package", debugWeslRoot) {
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4145
|
+
let weslRoot2 = debugWeslRoot;
|
|
4146
|
+
if (weslRoot2 === void 0) {
|
|
4147
|
+
weslRoot2 = "";
|
|
4148
|
+
} else if (!weslRoot2.endsWith("/")) {
|
|
4149
|
+
weslRoot2 += "/";
|
|
4154
4150
|
}
|
|
4155
4151
|
const srcModules = Object.entries(srcFiles).map(
|
|
4156
4152
|
([filePath, src]) => {
|
|
4157
4153
|
const modulePath = fileToModulePath(filePath, packageName);
|
|
4158
|
-
return { modulePath, debugFilePath:
|
|
4154
|
+
return { modulePath, debugFilePath: weslRoot2 + filePath, src };
|
|
4159
4155
|
}
|
|
4160
4156
|
);
|
|
4161
4157
|
srcModules.forEach((mod) => {
|
|
@@ -4424,7 +4420,7 @@ function transformBindingStruct(s, globalNames) {
|
|
|
4424
4420
|
member.mangledVarName = varName;
|
|
4425
4421
|
globalNames.add(varName);
|
|
4426
4422
|
const attributes = ((_a = member.attributes) == null ? void 0 : _a.map(attributeToString).join(" ")) ?? "";
|
|
4427
|
-
const varTypes = lowerPtrMember(
|
|
4423
|
+
const varTypes = lowerPtrMember(typeName, typeParameters) ?? lowerStdTypeMember(typeName, typeParameters) ?? lowerStorageTextureMember(typeName, typeParameters);
|
|
4428
4424
|
if (!varTypes) {
|
|
4429
4425
|
console.log("unhandled case transforming member", typeName);
|
|
4430
4426
|
return syntheticVar(attributes, varName, "", "??");
|
|
@@ -4433,7 +4429,7 @@ function transformBindingStruct(s, globalNames) {
|
|
|
4433
4429
|
return syntheticVar(attributes, varName, storageType, varType);
|
|
4434
4430
|
});
|
|
4435
4431
|
}
|
|
4436
|
-
function lowerPtrMember(
|
|
4432
|
+
function lowerPtrMember(typeName, typeParameters) {
|
|
4437
4433
|
if (typeName.originalName === "ptr") {
|
|
4438
4434
|
const origParams = typeParameters ?? [];
|
|
4439
4435
|
const newParams = [origParams[0]];
|