diff --git a/crates/codegen/src/ts.rs b/crates/codegen/src/ts.rs index 544612e..0f82b2b 100644 --- a/crates/codegen/src/ts.rs +++ b/crates/codegen/src/ts.rs @@ -6,6 +6,12 @@ pub struct Codegen { pub emitted: String, } +impl Default for Codegen { + fn default() -> Self { + Self::new() + } +} + impl Codegen { pub fn new() -> Self { Self { emitted: String::new() } @@ -63,11 +69,11 @@ impl Codegen { "write_file" => { format!("writeFile({}, {}){}\n", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false), semicolon!()) }, "read" => { format!("read({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) }, "read_file" => { format!("readFile({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) }, - "emit" => { format!("{}", self.gen_ir(&args[0], false).trim_start_matches('"').trim_end_matches('"')) }, - + "emit" => { self.gen_ir(&args[0], false).trim_start_matches('"').trim_end_matches('"').to_string() }, + "get" => { format!("{}[{}]", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) }, "len" => { format!("{}.length", self.gen_ir(&args[0], false)) }, - + "throw" => { format!("throw new Error({}){}", self.gen_ir(&args[0], false), semicolon!()) }, _ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering } @@ -99,7 +105,7 @@ impl Codegen { IRKind::Do { body, .. } => { let mut out = "{\n".to_string(); for expr in body { - out.push_str(&self.gen_ir(&expr, true)); + out.push_str(&self.gen_ir(expr, true)); } out.push_str("}\n"); out diff --git a/crates/diagnostic/src/lib.rs b/crates/diagnostic/src/lib.rs index eb02dd0..0ed7f74 100644 --- a/crates/diagnostic/src/lib.rs +++ b/crates/diagnostic/src/lib.rs @@ -15,6 +15,12 @@ pub enum Kind { TypecheckError(typecheck::TypecheckError), } +impl Default for Diagnostics { + fn default() -> Self { + Self::new() + } +} + impl Diagnostics { pub fn new() -> Self { Self { @@ -126,7 +132,7 @@ impl Diagnostics { _ => None, }); let typecheck_error = self.errors.iter().filter_map(|kind| match kind { - Kind::TypecheckError(error) => Some(error.clone()), + Kind::TypecheckError(error) => Some(<&typecheck::TypecheckError>::clone(&error)), _ => None, }); // TODO: so many .iter(), maybe collapse them into one? @@ -138,12 +144,12 @@ impl Diagnostics { let report = Report::build(ReportKind::Error, (), span.start) .with_message( - format!("{}", message) + message.to_string() ) .with_label( Label::new(span.clone()) .with_message( - format!("{}", message) + message.to_string() ) .with_color(Color::Red) ); diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 79f226c..380cee0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -94,7 +94,7 @@ pub struct IR { pub span: Range } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct LoweringError { pub span: Range, pub message: String, diff --git a/crates/lexer/src/lib.rs b/crates/lexer/src/lib.rs index 16210c8..dd8b9e9 100644 --- a/crates/lexer/src/lib.rs +++ b/crates/lexer/src/lib.rs @@ -165,9 +165,10 @@ pub fn lexer() -> impl Parser, Error = Simple> { .repeated() } +#[allow(clippy::type_complexity)] pub fn lex(src: String) -> (Option)>>, Vec>) { let (tokens, lex_error) = lexer().parse_recovery(src.as_str()); - return (tokens, lex_error); + (tokens, lex_error) } #[cfg(test)] diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 3a1dfe6..262eb05 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -286,7 +286,7 @@ fn expr_parser() -> impl Parser>, Error = Simple .map_with_span(|body, span| { ( Expr::Do { - body: (body.clone(), span.clone()), + body: (body, span.clone()), }, span, ) @@ -366,13 +366,14 @@ fn expr_parser() -> impl Parser>, Error = Simple .then_ignore(end()) } +#[allow(clippy::type_complexity)] // We are going to use this once anyway, why we need to make a type? pub fn parse(tokens: Vec<(Token, std::ops::Range)>, len: usize) -> (Option)>>, Vec>) { let (ast, parse_error) = expr_parser().parse_recovery(Stream::from_iter( len..len + 1, tokens.into_iter(), )); - return (ast, parse_error) + (ast, parse_error) } #[cfg(test)] diff --git a/crates/typecheck/src/lib.rs b/crates/typecheck/src/lib.rs index 8105a5f..e2c2e12 100644 --- a/crates/typecheck/src/lib.rs +++ b/crates/typecheck/src/lib.rs @@ -29,7 +29,7 @@ pub struct TypecheckError { pub span: std::ops::Range, } -pub fn check(irs: &Vec) -> Result<(), Vec> { +pub fn check(irs: &[IR]) -> Result<(), Vec> { let mut errors = Vec::new(); for ir in irs { match &ir.kind { diff --git a/test.hz b/test.hz deleted file mode 100644 index 7a7089d..0000000 --- a/test.hz +++ /dev/null @@ -1,3 +0,0 @@ -fun main : int = do - "Hello, World" |> @write(); -end;