From 4e6acf70383f704818e281fe50f6ba198f9f6b69 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sun, 20 Mar 2022 20:25:31 +0700 Subject: [PATCH] cleanup --- crates/diagnostic/src/lib.rs | 3 +-- crates/hir/src/lib.rs | 20 +++++++++----------- example/factorial.hz | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/diagnostic/src/lib.rs b/crates/diagnostic/src/lib.rs index 947a6c8..3811794 100644 --- a/crates/diagnostic/src/lib.rs +++ b/crates/diagnostic/src/lib.rs @@ -47,7 +47,6 @@ impl Diagnostics { _ => None, }); - // TODO: Lowering error lex_error.into_iter() .map(|e| e.map(|e| e.to_string())) .chain(parse_error.into_iter().map(|e| e.map(|tok| tok.to_string()))) @@ -148,4 +147,4 @@ impl Diagnostics { } }); } -} \ No newline at end of file +} diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index e309fe6..ccc70ed 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -40,21 +40,19 @@ pub struct LoweringError { pub note: Option, } -impl IR { - pub fn new(kind: IRKind, span: Range) -> Self { - Self { kind, span } - } -} - pub fn ast_to_ir(ast: Vec<(Expr, Range)>) -> (Vec, Vec) { let mut irs = Vec::new(); let mut errors = Vec::new(); for expr in ast { let ir_kind = expr_to_ir(&expr.0); - if let Some(err) = ir_kind.1 { - errors.push(err); - } else { - irs.push(IR::new(ir_kind.0.unwrap(), expr.1)); + match ir_kind { + (Some(ir), None) => { + irs.push(IR { kind: ir, span: expr.1 }); + }, + (None, Some(err)) => { + errors.push(err); + }, + _ => unreachable!(), } } (irs, errors) @@ -351,4 +349,4 @@ fn closet_intrinsic(got: String) -> String { } } closest -} \ No newline at end of file +} diff --git a/example/factorial.hz b/example/factorial.hz index e8f98e5..834c8f5 100644 --- a/example/factorial.hz +++ b/example/factorial.hz @@ -7,4 +7,4 @@ end; fun main: void = do factorial(5) |> @write(_); -end; \ No newline at end of file +end;