puyo-3/src/ast.rs
2026-01-02 21:07:26 -05:00

48 lines
922 B
Rust

use crate::{symbol::Symbol, val::Val};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Ident {
/// `x`
Local(Symbol),
/// `^x`
Return(Symbol),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Mod,
Pow,
Eq,
Lt,
Le,
}
// TODO: great display repr for this for testing (yes it's allowed)
#[derive(Debug, Clone)]
pub enum Ast {
/// `x`, `^x`
Var(Ident),
/// `x := y; #=> y`
Set(Ident, Box<Ast>),
/// `fn ([a b] [c d]) ( ... )`
Fn {
inputs: Vec<Symbol>,
outputs: Vec<Symbol>,
body: Vec<Ast>,
},
/// `{^x; ^y := z}`
Map(Vec<Ast>),
/// `f x`
App(Box<Ast>, Box<Ast>),
/// `x + y` (only builtins, sorry)
BinOp(Box<Ast>, BinOp, Box<Ast>),
/// `3`
Num(f64),
/// `(println bla; 3) #=> 3`
Block(Vec<Ast>),
}