#[derive(Debug, Clone)]
pub struct FunctionIR {
pub name: String,
pub body: Vec<Statement>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Statement {
Let {
name: String,
mutable: bool,
value: Expr,
},
Assign {
target: Expr,
value: Expr,
},
Expr(Expr),
Return(Option<Expr>),
If {
condition: Expr,
then_body: Vec<Statement>,
else_body: Vec<Statement>,
},
While {
condition: Expr,
body: Vec<Statement>,
},
Loop {
body: Vec<Statement>,
},
ForEach {
var_name: String,
collection: Expr,
body: Vec<Statement>,
},
ForRange {
var_name: String,
bound: Expr,
body: Vec<Statement>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Literal(Literal),
Var(String),
HostCall {
module: String,
name: String,
args: Vec<Expr>,
},
MethodChain {
receiver: Box<Expr>,
calls: Vec<MethodCall>,
},
BinOp {
left: Box<Expr>,
op: BinOp,
right: Box<Expr>,
},
UnOp {
op: UnOp,
operand: Box<Expr>,
},
MacroCall {
name: String,
args: Vec<Expr>,
},
StructLiteral {
name: String,
fields: Vec<(String, Expr)>,
},
EnumVariant {
enum_name: String,
variant_name: String,
fields: Vec<Expr>,
},
Ref(Box<Expr>),
Raw(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct MethodCall {
pub name: String,
pub args: Vec<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
I32(i32),
I64(i64),
F32(f32),
F64(f64),
Bool(bool),
Str(String),
Unit,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Rem,
BitAnd,
BitOr,
BitXor,
Shl,
Shr,
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
AddAssign,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum UnOp {
Neg,
Not,
}