ShaderLang
ShaderLang copied to clipboard
[Syntax] Allow more type deduction cases
Currently, type deduction only occurs for variable declarations:
let x = 42.0;
is equivalent to
let x: f32 = 42.0;
It would be great to allow type deduction for other cases:
let x: f32;
let v = vec3(x, x, x); // no need to write vec3[f32](x, x, x)
Other examples:
let x: mat4[f32];
let y = mat3(x); //< okay, y is a mat3[f32]
let x: f32;
let a = array(x, x, x); // a is an array[f32, 3]
const vertPos = array[vec2[f32]](
vec2(-1.0, 1.0), //< no need to write vec2[f32] for every value
vec2(-1.0, -3.0),
vec2( 3.0, 1.0)
);
It should also be pretty easy to add return type deduction (but i'm not sure it should be done):
fn foo() {} //< returns nothing
fn bar() { return 42; } //< return i32
fn foobar() { return vec3(1.0, 2.0, 3.0); } //< return vec3[f32]