2023-03-28 08:32:30 -05:00
|
|
|
use super::ty::Type;
|
|
|
|
use crate::parse::parser::{
|
|
|
|
BinaryOp,
|
|
|
|
UnaryOp,
|
|
|
|
Lit,
|
|
|
|
Spanned,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Typed version of the expression.
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum TExpr<'src> {
|
|
|
|
Lit(Lit<'src>),
|
2023-04-11 22:35:35 -05:00
|
|
|
Ident(&'src str),
|
2023-03-28 08:32:30 -05:00
|
|
|
|
|
|
|
Unary {
|
|
|
|
op: UnaryOp,
|
|
|
|
expr: Spanned<Box<Self>>,
|
|
|
|
ret_ty: Type,
|
|
|
|
},
|
|
|
|
Binary {
|
|
|
|
op: BinaryOp,
|
|
|
|
lhs: Spanned<Box<Self>>,
|
|
|
|
rhs: Spanned<Box<Self>>,
|
|
|
|
ret_ty: Type,
|
|
|
|
},
|
|
|
|
|
|
|
|
Lambda {
|
|
|
|
params: Vec<(&'src str, Type)>,
|
|
|
|
body: Spanned<Box<Self>>,
|
|
|
|
ret_ty: Type,
|
|
|
|
},
|
|
|
|
Call {
|
|
|
|
func: Spanned<Box<Self>>,
|
|
|
|
args: Vec<Spanned<Self>>,
|
|
|
|
},
|
|
|
|
If {
|
|
|
|
cond: Spanned<Box<Self>>,
|
|
|
|
t: Spanned<Box<Self>>,
|
|
|
|
f: Spanned<Box<Self>>,
|
|
|
|
br_ty: Type,
|
|
|
|
},
|
|
|
|
Let {
|
2023-04-11 22:35:35 -05:00
|
|
|
name: &'src str,
|
|
|
|
ty: Type,
|
|
|
|
value: Spanned<Box<Self>>,
|
2023-03-28 08:32:30 -05:00
|
|
|
body: Spanned<Box<Self>>,
|
|
|
|
},
|
2023-04-11 22:35:35 -05:00
|
|
|
Define {
|
|
|
|
name: &'src str,
|
|
|
|
ty: Type,
|
|
|
|
value: Spanned<Box<Self>>,
|
|
|
|
},
|
2023-03-28 08:32:30 -05:00
|
|
|
Block {
|
2023-03-29 08:47:48 -05:00
|
|
|
exprs: Vec<Spanned<Self>>,
|
|
|
|
void: bool,
|
2023-03-28 08:32:30 -05:00
|
|
|
ret_ty: Type,
|
|
|
|
},
|
|
|
|
}
|