use std::{ops::Range, path::PathBuf}; type Span = Range; #[derive(Debug, Clone, PartialEq)] pub struct File { pub name: PathBuf, pub items: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct Ty { pub span: Span, pub kind: TyKind, } #[derive(Debug, Clone, PartialEq)] pub enum TyKind { U64, Ptr(Box), Name(String), } #[derive(Debug, Clone, PartialEq)] pub enum Item { FnDecl(FnDecl), StructDecl(StructDecl), } #[derive(Debug, Clone, PartialEq)] pub struct FnDecl { pub name: String, pub params: Vec, pub ret_ty: Option, pub span: Span, pub body: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct NameTyPair { pub name: String, pub ty: Ty, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub struct StructDecl { pub name: String, pub fields: Vec, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub enum Stmt { VarDecl(VarDecl), Assignment(Assignment), IfStmt(IfStmt), WhileStmt(WhileStmt), LoopStmt(LoopStmt), Item(Item), Expr(Expr), } #[derive(Debug, Clone, PartialEq)] pub struct VarDecl { pub name: String, pub ty: Ty, pub rhs: Option, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub struct Assignment { pub place: Expr, pub rhs: Expr, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub struct IfStmt { pub cond: Expr, pub body: Vec, pub else_part: Option, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub enum ElsePart { Else(Vec, Span), ElseIf(Box), } #[derive(Debug, Clone, PartialEq)] pub struct WhileStmt { pub cond: Expr, pub body: Vec, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub struct LoopStmt { pub body: Vec, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub enum Expr { BinOp(BinOp), FieldAccess(FieldAccess), Call(Call), Deref(Box), Literal(Literal), Name(String), Array(Vec), } #[derive(Debug, Clone, PartialEq)] pub struct BinOp { pub kind: BinOpKind, pub lhs: Box, pub rhs: Box, pub span: Span, } #[derive(Debug, Clone, PartialEq)] pub enum BinOpKind { Eq, Neq, Gt, Lt, GtEq, LtEq, Add, Sub, Mul, Div, Mod, Shr, Shl, And, Or, BitAnd, BitOr, Xor, } #[derive(Debug, Clone, PartialEq)] pub struct FieldAccess { pub expr: Box, pub field_name: String, } #[derive(Debug, Clone, PartialEq)] pub struct Call { pub callee: Box, pub args: Vec, } #[derive(Debug, Clone, PartialEq)] pub enum Literal { String(String, Span), Integer(u64, Span), }