toasty_core/stmt/expr_let.rs
1use super::Expr;
2
3/// A scoped binding expression with one or more bindings.
4///
5/// Evaluates each binding in order, pushes all results into a new scope, then
6/// evaluates `body` in that scope. The body references binding `i` via
7/// `Arg(position=i, nesting=0)`.
8///
9/// `ExprLet` is transient scaffolding used during lowering. It is always
10/// inlined away (by substituting the bindings into the body) before the
11/// planner sees the expression tree.
12///
13/// # Examples
14///
15/// ```text
16/// let [x = 5, y = 10] in (arg(0) + arg(1))
17/// // bindings: [5, 10], body: arg(0) + arg(1)
18/// // after inlining: 5 + 10
19/// ```
20#[derive(Debug, Clone, PartialEq)]
21pub struct ExprLet {
22 /// Expressions whose results are bound as `arg(0)`, `arg(1)`, etc. in a
23 /// new scope.
24 pub bindings: Vec<Expr>,
25
26 /// The body expression evaluated in the new scope.
27 pub body: Box<Expr>,
28}
29
30impl From<ExprLet> for Expr {
31 fn from(value: ExprLet) -> Self {
32 Self::Let(value)
33 }
34}