From 23e399655d74916d7b9bc4914afc2dc780f1c9a3 Mon Sep 17 00:00:00 2001 From: azur Date: Thu, 29 Jun 2023 19:51:43 +0700 Subject: [PATCH] Implement all IRs --- ir/src/lib.rs | 20 +++++++++++++++++--- simple.hlm | 4 +++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ir/src/lib.rs b/ir/src/lib.rs index 92fde2b..760bb01 100644 --- a/ir/src/lib.rs +++ b/ir/src/lib.rs @@ -134,7 +134,12 @@ pub fn lower_expr(e: TExpr) -> Expr { .collect::>(); 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::>(); + if void { + call!(vec![var!("block"), call!(exprs)]) + } else { + call!(vec![var!("block"), call!(exprs), var!("()")]) + } } - TExpr::Block { exprs, void, ret_ty } => todo!(), } } \ No newline at end of file diff --git a/simple.hlm b/simple.hlm index 6df56a2..4bb2408 100644 --- a/simple.hlm +++ b/simple.hlm @@ -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) \ No newline at end of file +|> fun (x) -> succ(x) +|> fun (x) -> mul(x, 10) \ No newline at end of file