1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

Implement all IRs

This commit is contained in:
azur 2023-06-29 19:51:43 +07:00
parent 21ad37e033
commit 23e399655d
2 changed files with 20 additions and 4 deletions

View file

@ -134,7 +134,12 @@ pub fn lower_expr(e: TExpr) -> Expr {
.collect::<Vec<_>>();
call!(vec![func].into_iter().chain(args).collect())
}
TExpr::If { cond, t, f, br_ty } => todo!(),
TExpr::If { cond, t, f, .. } => {
let cond = lower_expr(unbox!(cond));
let t = lower_expr(unbox!(t));
let f = lower_expr(unbox!(f));
call!(vec![var!("if"), cond, t, f])
}
TExpr::Let { name, value, body, .. } => {
let value = lower_expr(unbox!(value));
let body = lower_expr(unbox!(body));
@ -142,8 +147,17 @@ pub fn lower_expr(e: TExpr) -> Expr {
}
TExpr::Define { name, value, .. } => {
let value = lower_expr(unbox!(value));
call!(vec![var!("define"), str!(name), value])
call!(vec![var!("define"), var!(name), value])
}
TExpr::Block { exprs, void, .. } => {
let exprs = exprs.into_iter()
.map(|(e, _)| lower_expr(e))
.collect::<Vec<_>>();
if void {
call!(vec![var!("block"), call!(exprs)])
} else {
call!(vec![var!("block"), call!(exprs), var!("()")])
}
}
TExpr::Block { exprs, void, ret_ty } => todo!(),
}
}

View file

@ -1,5 +1,7 @@
let add = fun (x Int, y Int) Int -> x + y;
let succ = fun (x) -> x + 1;
let mul = fun (x, y) -> x * y;
add(33, 34)
|> fun (x) -> succ(x)
|> fun (x) -> mul(x, 10)