bobbylisp/src/asts/past.rs

54 lines
1.1 KiB
Rust
Raw Normal View History

2023-03-04 15:34:12 +00:00
use crate::trans::ty::*;
2023-03-03 09:31:11 +00:00
use crate::read::parse::Spanned;
2023-02-28 19:23:45 +00:00
2023-03-04 15:34:12 +00:00
#[derive(Clone, Debug)]
pub enum PUnaryOp {
Neg,
Not,
}
#[derive(Clone, Debug)]
pub enum PBinaryOp {
Add, Sub, Mul, Div, Mod,
Eq, Neq, Lt, Gt, Lte, Gte,
And, Or,
}
#[derive(Clone, Debug)]
2023-03-04 16:20:43 +00:00
pub enum PLiteral { Num(i64), Str(String), Bool(bool), Unit }
2023-03-04 15:34:12 +00:00
#[derive(Clone, Debug)]
pub enum PExpr {
2023-02-28 19:23:45 +00:00
Error,
2023-03-04 15:34:12 +00:00
Lit(PLiteral),
Sym(String),
2023-02-28 19:23:45 +00:00
Vec(Vec<Spanned<Self>>),
2023-03-04 15:34:12 +00:00
2023-02-28 19:23:45 +00:00
Unary(Spanned<PUnaryOp>, Box<Spanned<Self>>),
Binary(Spanned<PBinaryOp>, Box<Spanned<Self>>, Box<Spanned<Self>>),
2023-03-04 15:34:12 +00:00
2023-02-28 19:23:45 +00:00
Call(Box<Spanned<Self>>, Vec<Spanned<Self>>),
2023-03-04 15:34:12 +00:00
Lambda {
args: Vec<(String, Type)>,
2023-02-28 19:23:45 +00:00
body: Box<Spanned<Self>>,
2023-03-04 15:34:12 +00:00
},
Let {
2023-02-28 19:57:02 +00:00
vars: Vec<(String, Type, Spanned<Self>)>,
2023-03-04 16:20:43 +00:00
body: Option<Box<Spanned<Self>>>,
2023-02-28 19:23:45 +00:00
},
2023-03-02 20:31:52 +00:00
Block(Vec<Spanned<Self>>),
Return(Box<Spanned<Self>>),
}
#[derive(Clone, Debug)]
pub enum PStmt {
Expr(Spanned<PExpr>),
Func {
name: String,
args: Vec<(String, Type)>,
2023-03-03 23:52:57 +00:00
ret: Type,
2023-03-02 20:31:52 +00:00
body: Box<Spanned<PExpr>>,
},
2023-03-04 15:34:12 +00:00
}