vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
// Statement nodes — execute effects.
//
// Statements modify state: bind variables, write to buffers, branch, loop.
// A program's entry point is a sequence of statements.

use crate::ir::model::expr::Expr;

/// A statement that executes an effect.
///
/// Downstream crates should match exhaustively on this enum so new
/// statement kinds become compile-time updates rather than silent gaps.
///
/// # Examples
///
/// ```
/// use vyre::ir::{Expr, Node};
///
/// let let_stmt = Node::let_bind("x", Expr::u32(1));
/// let store = Node::store("out", Expr::u32(0), Expr::var("x"));
/// ```
#[derive(Debug, Clone, PartialEq)]
pub enum Node {
    /// Bind a new local variable: `let name = value;`
    Let {
        /// Variable name.
        name: String,
        /// Initial value.
        value: Expr,
    },

    /// Reassign an existing variable: `name = value;`
    Assign {
        /// Variable name (must have been bound by a prior `Let`).
        name: String,
        /// New value.
        value: Expr,
    },

    /// Write one element to a named buffer: `buffer[index] = value;`
    Store {
        /// Buffer name (must match a `BufferDecl::name` with `ReadWrite` access).
        buffer: String,
        /// Element index.
        index: Expr,
        /// Value to write.
        value: Expr,
    },

    /// Conditional branch.
    If {
        /// Branch condition.
        cond: Expr,
        /// Body when true.
        then: Vec<Node>,
        /// Body when false (may be empty).
        otherwise: Vec<Node>,
    },

    /// Bounded loop: `for var in from..to { body }`
    ///
    /// The loop variable is immutable within the body. The bound is
    /// exclusive. Unbounded loops are not representable — this is
    /// intentional. GPU compute must terminate.
    Loop {
        /// Induction variable name.
        var: String,
        /// Inclusive start.
        from: Expr,
        /// Exclusive end.
        to: Expr,
        /// Loop body.
        body: Vec<Node>,
    },

    /// Early return from the entry point.
    Return,

    /// Sequence of statements.
    Block(Vec<Node>),

    /// Workgroup barrier. All invocations in the workgroup must reach
    /// this point before any can proceed past it.
    Barrier,
}

mod impl_node;