use std::collections::VecDeque;
use std::rc::Rc;
#[derive(Debug)]
pub enum Cmd {
Asgn(Rc<Expr>, Rc<Expr>),
Seq(VecDeque<Rc<Cmd>>),
If(Rc<Expr>, Rc<Cmd>, Rc<Cmd>),
While(Rc<Expr>, Rc<Cmd>),
Expr(Rc<Expr>),
Continue,
Break,
Func(String, Rc<Expr>, Rc<Cmd>),
Class(String, Rc<Cmd>),
Return(Rc<Expr>),
Nop
}
#[derive(Debug)]
pub enum Expr {
ConstInt(String),
ConstFloat(String),
ConstString(String),
Tuple(VecDeque<Rc<Expr>>),
Var(String),
BinOp(BinOp, Rc<Expr>, Rc<Expr>),
UnOp(UnOp, Rc<Expr>),
Call(Rc<Expr>, Rc<Expr>),
GetItem(Rc<Expr>, Rc<Expr>),
GetAttr(Rc<Expr>, String),
}
#[derive(Debug)]
pub enum BinOp {
Plus,
Minus,
Mul,
Div,
Mod,
Lt,
Gt,
Le,
Ge,
Eq,
Ne,
And,
Or,
}
impl std::fmt::Display for BinOp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
BinOp::Plus => "add",
BinOp::Minus => "sub",
BinOp::Mul => "mul",
BinOp::Div => "div",
BinOp::Mod => "mod",
BinOp::Lt => "lt",
BinOp::Gt => "gt",
BinOp::Le => "le",
BinOp::Ge => "ge",
BinOp::Eq => "eq",
BinOp::Ne => "ne",
BinOp::And => "and",
BinOp::Or => "or",
})
}
}
#[derive(Debug)]
pub enum UnOp {
Negate,
Not,
Deref
}
impl std::fmt::Display for UnOp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
UnOp::Negate => "negate",
UnOp::Not => "not",
UnOp::Deref => "deref",
})
}
}