NEGA.TV

MODE SELECT

09 - December Adventure

A quiet day today, a bit more Ast typing.

You can now do something like this…

let arena = Arena::new();

let a = arena.alloc(Expr::Literal {
    literal: arena.alloc(Literal::Integer { value: 69 }),
});

let b = arena.alloc(Expr::Literal {
    literal: arena.alloc(Literal::Integer { value: 42 }),
});

let expr = arena.alloc(Expr::Binary {
    kind: BinaryOpKind::Add,
    lhs: a,
    rhs: b,
});

println!("{}", expr);

and it will output something like

(+ (69 42))

I rolled back on doing a more optimized ast structure for now, and just went with something straightforward. Can fix the design later. Going to need some helpers though, it’s very wordy trying to build the ast from that kind of arena allocation and enum soup.