Posted on

Evaluating an expression language: 1 * (2 - 3)

  • boxed pointer traversal
ExprBoxed::Mul {
    a: Box::new(ExprBoxed::LiteralInt { literal: 1 }),
    b: Box::new(ExprBoxed::Sub {
        a: Box::new(ExprBoxed::LiteralInt { literal: 2 }),
        b: Box::new(ExprBoxed::LiteralInt { literal: 3 }),
    }),
}
  • cache-local reverse topological fold
[
idx_0:    Mul(idx_1, idx_2)
idx_1:    LiteralInt(1)
idx_2:    Sub(idx_3, idx_4)
idx_3:    LiteralInt(2)
idx_4:    LiteralInt(3)
]

Link

Fully generic recursion in Rust