diff --git a/analysis/src/ir/custom.rs b/analysis/src/ir/custom.rs index 9216ecf..b56a211 100644 --- a/analysis/src/ir/custom.rs +++ b/analysis/src/ir/custom.rs @@ -1,22 +1,22 @@ pub mod help { use crate::ir::{ConstValue, Operand, Register}; - pub trait AsOperand { - fn as_operand(self) -> Operand; + pub trait ToOperand { + fn to_operand(self) -> Operand; } - pub fn op(o: impl AsOperand) -> Operand { - o.as_operand() + pub fn op(o: impl ToOperand) -> Operand { + o.to_operand() } - impl AsOperand for Register { - fn as_operand(self) -> Operand { + impl ToOperand for Register { + fn to_operand(self) -> Operand { Operand::Reg(self) } } - impl AsOperand for u64 { - fn as_operand(self) -> Operand { + impl ToOperand for u64 { + fn to_operand(self) -> Operand { Operand::Const(ConstValue::u64(self)) } } diff --git a/analysis/src/ir/info.rs b/analysis/src/ir/info.rs index ab63aa1..61cabf2 100644 --- a/analysis/src/ir/info.rs +++ b/analysis/src/ir/info.rs @@ -3,7 +3,7 @@ use rustc_hash::FxHashSet; use super::{BbIdx, Branch, Func, Location, Operand}; use crate::ir::visit::Visitor; -pub fn traverse_postorder<'a>(func: &'a Func<'_>) -> Vec { +pub fn traverse_postorder(func: &Func<'_>) -> Vec { // the final traversial, backwards. // the starting bb has to be visited last. let mut traversal = vec![BbIdx(0)]; diff --git a/analysis/src/lower.rs b/analysis/src/lower.rs index 14596c8..fd136b5 100644 --- a/analysis/src/lower.rs +++ b/analysis/src/lower.rs @@ -42,7 +42,7 @@ pub fn lower_translation_unit<'cx>( }; let def_id = lcx.next_def_id(); - let func = lower_func(&lcx, body, def_span, ident.0, ret_ty, params)?; + let func = lower_func(lcx, body, def_span, ident.0, ret_ty, params)?; let args = &*lcx .arena @@ -450,7 +450,7 @@ fn lower_func<'cx>( def_span, ret_ty, lcx, - params.len().try_into().unwrap(), + params.len(), ), lcx, }; diff --git a/analysis/src/lower/builder.rs b/analysis/src/lower/builder.rs index c24e3ba..455a390 100644 --- a/analysis/src/lower/builder.rs +++ b/analysis/src/lower/builder.rs @@ -105,7 +105,7 @@ impl<'a, 'cx> FuncBuilder<'a, 'cx> { } pub fn load(&mut self, tyl: TyLayout<'cx>, ptr: Operand, span: Span) -> Register { - let reg = self.new_reg(None, tyl.clone()); + let reg = self.new_reg(None, tyl); let stmt = StatementKind::Load { result: reg, ptr, diff --git a/analysis/src/lower/typeck.rs b/analysis/src/lower/typeck.rs index a96d0c6..e95c343 100644 --- a/analysis/src/lower/typeck.rs +++ b/analysis/src/lower/typeck.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use parser::{ ast::{IntSign, IntTy, IntTyKind}, Error, Span, @@ -61,15 +63,18 @@ impl<'a, 'cx> FnLoweringCtxt<'a, 'cx> { } else if (lhs_sign.unsigned() && rhs_prom_int.0.unsigned()) || (lhs_sign.signed() && rhs_sign.signed()) { - if lhs_kind > rhs_kind { - rhs_coerce.extend(self.coerce(rhs_prom, lhs_prom)?); - lhs - } else if lhs_kind < rhs_kind { - lhs_coerce.extend(self.coerce(lhs_prom, rhs_prom)?); - rhs - } else { - unreachable!("integers must have different rank here") + match lhs_kind.cmp(&rhs_kind) { + Ordering::Greater => { + rhs_coerce.extend(self.coerce(rhs_prom, lhs_prom)?); + lhs + } + Ordering::Less => { + lhs_coerce.extend(self.coerce(lhs_prom, rhs_prom)?); + rhs + } + Ordering::Equal => unreachable!("integers must have different rank here"), } + // Otherwise, if the operand that has unsigned integer type has rank greater or // equal to the rank of the type of the other operand, then the operand with // signed integer type is converted to the type of the operand with unsigned diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index d70d298..3163b19 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -20,7 +20,7 @@ pub fn generate<'cx>(lcx: &'cx LoweringCx<'cx>, ir: &Ir<'cx>) -> Result<()> { let text = obj.add_section(Vec::new(), b".text".to_vec(), object::SectionKind::Text); - for (_def_id, func) in &ir.funcs { + for func in ir.funcs.values() { let code = x86_64::generate_func(lcx, func)?; let offset = obj.append_section_data(text, &code, 8); @@ -59,7 +59,7 @@ pub fn generate<'cx>(lcx: &'cx LoweringCx<'cx>, ir: &Ir<'cx>) -> Result<()> { .map_err(|err| Error::new_without_span(format!("failed to spawn `cc`: {err}")))?; if !output.status.success() { - return Err(Error::new_without_span(format!("linking with `cc` failed"))); + return Err(Error::new_without_span("linking with `cc` failed")); } else { // std::fs::remove_file("main.o").map_err(|err| { // analysis::Error::new_without_span(format!( diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 59ecdf6..04a6140 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -542,7 +542,7 @@ where let cond = self.expr()?; let _paren_span = expect!(self, Tok::Punct(P::ParenClose)); let then = self.compount_or_single_statement()?; - let otherwise = if let Some(_) = eat!(self, Tok::Kw(Kw::Else)) { + let otherwise = if eat!(self, Tok::Kw(Kw::Else)).is_some() { Some(self.compount_or_single_statement()?) } else { None