Expressions

Making it easier to work with shaders


Expressions

Expressions are terms that are evaluated to produce values. Expressions are divided into atomic and operator expressions. Atomic expressions are indivisible, whereas operator expressions consist of an operator and one or more subexpressions.

Examples of atomic expressions (also called leaf expressions) are literal expressions, identifier expressions, and the this expression.

Operator expressions range from single-operand prefix and postfix expressions to binary expressions and ternary conditional expressions. The grouping of operators is determined by operator precedence.

Expressions may have side effects. That is, they produce observable effects beyond their resulting value. Notably, an assignment expression has the side effect of storing a value, and a function call expression may produce any number of side effects depending on the called function. When expressions access memory that is shared between threads, maintaining memory consistency is important in order to avoid undefined behavior. Slang also imposes additional constraints when calling functions with in/out/inout parameters.

In Slang, there are two primary value categories, called l-values and r-values. L-values may be used on the left-hand side of an assignment and as arguments for out/inout function parameters. L-values decay automatically to r-values when needed.

When the types of operands do not match the operator type requirements, a conversion is required. A conversion may be implicit, where the compiler injects it automatically, or explicit, where the program applies a conversion operator.

An expression may be evaluated at translation time or at runtime. Translation-time-evaluated values are generally called constants, as opposed to runtime values. This is discussed in more detail in evaluation of expressions.

Contents