SymbolTable

Struct SymbolTable 

Source
pub struct SymbolTable {
    pub locals: HashMap<String, WgslType>,
}
Expand description

Maps locally-declared identifier → its WGSL type. Pre-seeded with the uniforms and helper-function bindings the codegen wrapper exposes inside fs_main (so that texsize, q1..q32, aspect, etc. resolve to known types).

Fields§

§locals: HashMap<String, WgslType>

Implementations§

Source§

impl SymbolTable

Source

pub fn from_source(src: &str) -> Self

Build a symbol table by scanning var NAME: TYPE / let NAME: TYPE declarations in the translated source. Pre-seeded with the wrapper preamble’s bindings so user code can be analysed in isolation.

Source

pub fn lookup(&self, name: &str) -> Option<WgslType>

Source

pub fn infer_expr_type(&self, expr: &str) -> WgslType

Best-effort type inference for an expression text. Returns a confident type for the dominant patterns, WgslType::Unknown otherwise — callers must treat Unknown as “do not modify”.

Recognised:

  • A numeric literal (with or without f/i/u suffix) → F32.
  • A bare identifier in the symbol table → that type.
  • A constructor call vec3<f32>(...) etc. → that type.
  • A call to a known helper (GetPixel, GetBlur1..3, lum, textureSample, etc.) → its return type.
  • A swizzle access <expr>.<comp> where the prefix is a vec type — narrowed to F32 for .x/.y/.z/.w/.r/.g/.b/.a of length 1, Vec2F for 2, Vec3F for 3, Vec4F for 4.
  • A binary op (+, -, *, /) where one side is vec → the widest vec type. Falls back to F32 when both sides are scalar.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.