mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-12-03 20:23:40 +00:00
d64d78ff0b
Previously the wgsl frontend wasn't aware of lexical scopes causing all variables and named expressions to share a single function scope, this meant that if a variable was defined in a block with the same name as a variable in the function body, the variable in the function body would be lost and exiting the block all references to the variable in the function body would be replaced with the variable of the block. This commit fixes that by using the previously introduced `SymbolTable` to track the lexical and perform the variable lookups, scopes are pushed and popped as defined in the wgsl specification.
59 lines
903 B
WebGPU Shading Language
59 lines
903 B
WebGPU Shading Language
fn blockLexicalScope(a: bool) {
|
|
let a = 1.0;
|
|
{
|
|
let a = 2;
|
|
{
|
|
let a = true;
|
|
}
|
|
let test = a == 3;
|
|
}
|
|
let test = a == 2.0;
|
|
}
|
|
|
|
fn ifLexicalScope(a: bool) {
|
|
let a = 1.0;
|
|
if (a == 1.0) {
|
|
let a = true;
|
|
}
|
|
let test = a == 2.0;
|
|
}
|
|
|
|
|
|
fn loopLexicalScope(a: bool) {
|
|
let a = 1.0;
|
|
loop {
|
|
let a = true;
|
|
}
|
|
let test = a == 2.0;
|
|
}
|
|
|
|
fn forLexicalScope(a: f32) {
|
|
let a = false;
|
|
for (var a = 0; a < 1; a++) {
|
|
let a = 3.0;
|
|
}
|
|
let test = a == true;
|
|
}
|
|
|
|
fn whileLexicalScope(a: i32) {
|
|
while (a > 2) {
|
|
let a = false;
|
|
}
|
|
let test = a == 1;
|
|
}
|
|
|
|
fn switchLexicalScope(a: i32) {
|
|
switch (a) {
|
|
case 0 {
|
|
let a = false;
|
|
}
|
|
case 1 {
|
|
let a = 2.0;
|
|
}
|
|
default {
|
|
let a = true;
|
|
}
|
|
}
|
|
let test = a == 2;
|
|
}
|