diff --git a/codegen/src/builder.rs b/codegen/src/builder.rs index 3abfe49..b8f3692 100644 --- a/codegen/src/builder.rs +++ b/codegen/src/builder.rs @@ -34,7 +34,7 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> { Node::Expression(n) => { let expression_builder = ExpressionBuilder::new(self.llvm); expression_builder.build_expression(n) - }, + } _ => panic!("Unknown node"), } } diff --git a/codegen/src/expression.rs b/codegen/src/expression.rs index 7ba0f87..d9d4197 100644 --- a/codegen/src/expression.rs +++ b/codegen/src/expression.rs @@ -21,7 +21,9 @@ impl<'ev> ExpressionValue<'ev> { pub fn as_r_value(&self, llvm: &Llvm<'ev>, name: Option<&str>) -> BasicValueEnum<'ev> { match self { - ExpressionValue::LValue(pointer) => llvm.load_pointer(pointer, name.as_deref().unwrap_or("")), + ExpressionValue::LValue(pointer) => { + llvm.load_pointer(pointer, name.as_deref().unwrap_or("")) + } ExpressionValue::RValue(value) => *value, } } @@ -101,7 +103,10 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> { self.llvm.i32_type().const_int(0, false), "not", ), - TokenType::Minus => self.llvm.builder.build_int_neg(right.into_int_value(), "neg"), + TokenType::Minus => self + .llvm + .builder + .build_int_neg(right.into_int_value(), "neg"), _ => panic!("Unknown operator"), }; @@ -131,20 +136,24 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> { TokenType::Minus => self.llvm.builder.build_int_sub(left, right, "sub"), TokenType::Asterisk => self.llvm.builder.build_int_mul(left, right, "mul"), TokenType::Slash => self.llvm.builder.build_int_unsigned_div(left, right, "div"), - TokenType::Lt => { - self.llvm.builder - .build_int_compare(inkwell::IntPredicate::SLT, left, right, "less_than") - } + TokenType::Lt => self.llvm.builder.build_int_compare( + inkwell::IntPredicate::SLT, + left, + right, + "less_than", + ), TokenType::Gt => self.llvm.builder.build_int_compare( inkwell::IntPredicate::SGT, left, right, "greater_than", ), - TokenType::Eq => { - self.llvm.builder - .build_int_compare(inkwell::IntPredicate::EQ, left, right, "equal_to") - } + TokenType::Eq => self.llvm.builder.build_int_compare( + inkwell::IntPredicate::EQ, + left, + right, + "equal_to", + ), TokenType::NotEq => self.llvm.builder.build_int_compare( inkwell::IntPredicate::NE, left, @@ -156,4 +165,4 @@ impl<'ink, 'b> ExpressionBuilder<'ink, 'b> { BasicValueEnum::IntValue(result) } -} \ No newline at end of file +} diff --git a/codegen/src/identifier.rs b/codegen/src/identifier.rs index 2b35bd3..a7f83e5 100644 --- a/codegen/src/identifier.rs +++ b/codegen/src/identifier.rs @@ -10,7 +10,11 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> { Some(value) => self .llvm .builder - .build_load(self.llvm.i32_type(), *value, identifier.token.value.as_str()) + .build_load( + self.llvm.i32_type(), + *value, + identifier.token.value.as_str(), + ) .into_int_value(), None => panic!("Unknown identifier"), }; diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 7073ed1..742b027 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -1,7 +1,7 @@ #![deny(elided_lifetimes_in_paths)] use anyhow::Error; -use inkwell::{context::Context, OptimizationLevel, types::IntType}; +use inkwell::{context::Context, types::IntType, OptimizationLevel}; use llvm::Llvm; pub mod builder; diff --git a/codegen/src/statement.rs b/codegen/src/statement.rs index 53b1b55..ed20b44 100644 --- a/codegen/src/statement.rs +++ b/codegen/src/statement.rs @@ -37,7 +37,7 @@ impl<'ink, 'b> RecursiveBuilder<'ink, 'b> { Statement::Expr(expression) => { let expression_builder = ExpressionBuilder::new(self.llvm); expression_builder.build_expression(expression) - }, + } Statement::Return(_return_statement) => todo!(), _ => panic!("Unknown statement"), } diff --git a/codegen/tests/symbol_table_tests.rs b/codegen/tests/symbol_table_tests.rs index c4d3903..545a482 100644 --- a/codegen/tests/symbol_table_tests.rs +++ b/codegen/tests/symbol_table_tests.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use anyhow::Error; -use codegen::symbol_table::{SymbolTable, SymbolScope, Symbol}; +use codegen::symbol_table::{Symbol, SymbolScope, SymbolTable}; #[test] fn test_define() -> Result<(), Error> { diff --git a/llvm/src/lib.rs b/llvm/src/lib.rs index 4872cad..5956903 100644 --- a/llvm/src/lib.rs +++ b/llvm/src/lib.rs @@ -3,12 +3,14 @@ use inkwell::{ builder::Builder, context::Context, execution_engine::{ExecutionEngine, JitFunction}, - module::Module, values::{PointerValue, BasicValueEnum, GlobalValue}, types::BasicTypeEnum, + module::Module, + types::BasicTypeEnum, + values::{BasicValueEnum, GlobalValue, PointerValue}, }; type MainFn = unsafe extern "C" fn() -> i32; -pub trait GlobalValueExt { +pub trait GlobalValueExt { fn make_constant(self) -> Self; fn make_external(self) -> Self; fn make_private(self) -> Self; @@ -46,11 +48,7 @@ pub struct Llvm<'ctx> { impl<'ctx> Llvm<'ctx> { /// LLVM constructor - pub fn new( - builder: Builder<'ctx>, - context: &'ctx Context, - module: Module<'ctx>, - ) -> Llvm<'ctx> { + pub fn new(builder: Builder<'ctx>, context: &'ctx Context, module: Module<'ctx>) -> Llvm<'ctx> { Llvm { builder, context, diff --git a/source/src/lib.rs b/source/src/lib.rs index 34454c4..ea30619 100644 --- a/source/src/lib.rs +++ b/source/src/lib.rs @@ -10,4 +10,4 @@ pub fn create_source_code(source: &str) -> Source { path: None, contents: source.to_string(), } -} \ No newline at end of file +}