From 679bce15c4a4a572f488d6407a35be950661e88d Mon Sep 17 00:00:00 2001 From: limuy Date: Sun, 21 Apr 2024 00:14:48 +0800 Subject: [PATCH] fix(main):clippy --- README.md | 2 +- docs/usage.md | 2 +- libcore/src/types/trcbool.rs | 6 +++--- libcore/src/types/trcfloat.rs | 24 ++++++++++----------- libcore/src/types/trcint.rs | 40 +++++++++++++++++------------------ libcore/src/types/trcstr.rs | 2 +- src/base/ctrc.rs | 4 ++-- src/compiler.rs | 7 +++--- src/compiler/ast.rs | 4 +--- src/compiler/linker.rs | 2 +- src/compiler/manager.rs | 5 +---- src/compiler/token.rs | 6 +++--- src/tools/dis.rs | 2 -- src/tvm.rs | 2 -- 14 files changed, 49 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index d946230e..c618fddc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Trc is a easy-learn programming language. It can be fast,safe and effective. | Platform | Status | -| :------- | :---------------------------------------------------------------------------------------------------- | +|:---------|:------------------------------------------------------------------------------------------------------| | Linux | ![Linux Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_linux.yml) | | Winodows | ![Windows Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_windows.yml) | | Macos | ![Macos Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_macos.yml) | diff --git a/docs/usage.md b/docs/usage.md index 6250c648..67b9d414 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -33,7 +33,7 @@ Tip3:The form like 001 is supported The next is the string value. To make you to write strings more easily: | Way | Explain | -| :---------------- | :-------------------------------------------- | +|:------------------|:----------------------------------------------| | "hello world" | commom value | | 'h' | A way to store character | | """hello world""" | this method is for code across multiple lines | diff --git a/libcore/src/types/trcbool.rs b/libcore/src/types/trcbool.rs index ae316fa7..3549020e 100644 --- a/libcore/src/types/trcbool.rs +++ b/libcore/src/types/trcbool.rs @@ -42,9 +42,9 @@ impl TrcBool { fn override_export() -> HashMap { collection_literals::hash![ - OverrideOperations::And => OverrideWrapper::new(crate::codegen::Opcode::AndBool, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Or => OverrideWrapper::new(crate::codegen::Opcode::OrBool, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Not => OverrideWrapper::new(crate::codegen::Opcode::NotBool, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)) + OverrideOperations::And => OverrideWrapper::new(crate::codegen::Opcode::AndBool, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Or => OverrideWrapper::new(crate::codegen::Opcode::OrBool, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Not => OverrideWrapper::new(crate::codegen::Opcode::NotBool, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)) ] } } diff --git a/libcore/src/types/trcfloat.rs b/libcore/src/types/trcfloat.rs index af012cbb..55f70449 100644 --- a/libcore/src/types/trcfloat.rs +++ b/libcore/src/types/trcfloat.rs @@ -27,18 +27,18 @@ impl TrcFloat { fn override_export() -> HashMap { collection_literals::hash![ - OverrideOperations::Add => OverrideWrapper::new(Opcode::AddFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Sub => OverrideWrapper::new(Opcode::SubFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Mul => OverrideWrapper::new(Opcode::MulFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Div => OverrideWrapper::new(Opcode::DivFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::ExactDiv => OverrideWrapper::new(Opcode::ExtraDivFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcInt::export_info()), false)), - OverrideOperations::Equal => OverrideWrapper::new(Opcode::EqFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::NotEqual => OverrideWrapper::new(Opcode::NeFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::Less => OverrideWrapper::new(Opcode::LtFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::LessEqual => OverrideWrapper::new(Opcode::LeFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::Greater => OverrideWrapper::new(Opcode::GtFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::GreaterEqual => OverrideWrapper::new(Opcode::GeFloat, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::SelfNegative => OverrideWrapper::new(Opcode::SelfNegativeFloat, IOType::new(vec![], TypeAllowNull::Some(Self::export_info()), false)) + OverrideOperations::Add => OverrideWrapper::new(Opcode::AddFloat, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Sub => OverrideWrapper::new(Opcode::SubFloat, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Mul => OverrideWrapper::new(Opcode::MulFloat, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Div => OverrideWrapper::new(Opcode::DivFloat, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::ExactDiv => OverrideWrapper::new(Opcode::ExtraDivFloat, IOType::new(vec![Self::export_info()], Some(TrcInt::export_info()), false)), + OverrideOperations::Equal => OverrideWrapper::new(Opcode::EqFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::NotEqual => OverrideWrapper::new(Opcode::NeFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::Less => OverrideWrapper::new(Opcode::LtFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::LessEqual => OverrideWrapper::new(Opcode::LeFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::Greater => OverrideWrapper::new(Opcode::GtFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::GreaterEqual => OverrideWrapper::new(Opcode::GeFloat, IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::SelfNegative => OverrideWrapper::new(Opcode::SelfNegativeFloat, IOType::new(vec![], Some(Self::export_info()), false)) ] } } diff --git a/libcore/src/types/trcint.rs b/libcore/src/types/trcint.rs index ab5ecf78..f0a04629 100644 --- a/libcore/src/types/trcint.rs +++ b/libcore/src/types/trcint.rs @@ -25,26 +25,26 @@ impl TrcInt { } fn override_export() -> HashMap { - collection_literals::hash![OverrideOperations::Add => OverrideWrapper::new(Opcode::AddInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Sub => OverrideWrapper::new(Opcode::SubInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Mul => OverrideWrapper::new(Opcode::MulInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Div => OverrideWrapper::new(Opcode::DivInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcFloat::export_info()), false)), - OverrideOperations::Mod => OverrideWrapper::new(Opcode::ModInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Power => OverrideWrapper::new(Opcode::PowerInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::BitAnd => OverrideWrapper::new(Opcode::BitAndInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::BitOr => OverrideWrapper::new(Opcode::BitOrInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Xor => OverrideWrapper::new(Opcode::XorInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::ExactDiv => OverrideWrapper::new(Opcode::ExactDivInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::BitLeftShift => OverrideWrapper::new(Opcode::BitLeftShiftInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::BitRightShift => OverrideWrapper::new(Opcode::BitRightShiftInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::BitNot => OverrideWrapper::new(Opcode::BitNotInt,IOType::new(vec![], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::SelfNegative => OverrideWrapper::new(Opcode::SelfNegativeInt,IOType::new(vec![], TypeAllowNull::Some(Self::export_info()), false)), - OverrideOperations::Equal => OverrideWrapper::new(Opcode::EqInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::NotEqual => OverrideWrapper::new(Opcode::NeInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::Less => OverrideWrapper::new(Opcode::LtInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::LessEqual => OverrideWrapper::new(Opcode::LeInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::Greater => OverrideWrapper::new(Opcode::GtInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)), - OverrideOperations::GreaterEqual => OverrideWrapper::new(Opcode::GeInt,IOType::new(vec![Self::export_info()], TypeAllowNull::Some(TrcBool::export_info()), false)) + collection_literals::hash![OverrideOperations::Add => OverrideWrapper::new(Opcode::AddInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Sub => OverrideWrapper::new(Opcode::SubInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Mul => OverrideWrapper::new(Opcode::MulInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Div => OverrideWrapper::new(Opcode::DivInt,IOType::new(vec![Self::export_info()], Some(TrcFloat::export_info()), false)), + OverrideOperations::Mod => OverrideWrapper::new(Opcode::ModInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Power => OverrideWrapper::new(Opcode::PowerInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::BitAnd => OverrideWrapper::new(Opcode::BitAndInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::BitOr => OverrideWrapper::new(Opcode::BitOrInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::Xor => OverrideWrapper::new(Opcode::XorInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::ExactDiv => OverrideWrapper::new(Opcode::ExactDivInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::BitLeftShift => OverrideWrapper::new(Opcode::BitLeftShiftInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::BitRightShift => OverrideWrapper::new(Opcode::BitRightShiftInt,IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)), + OverrideOperations::BitNot => OverrideWrapper::new(Opcode::BitNotInt,IOType::new(vec![], Some(Self::export_info()), false)), + OverrideOperations::SelfNegative => OverrideWrapper::new(Opcode::SelfNegativeInt,IOType::new(vec![], Some(Self::export_info()), false)), + OverrideOperations::Equal => OverrideWrapper::new(Opcode::EqInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::NotEqual => OverrideWrapper::new(Opcode::NeInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::Less => OverrideWrapper::new(Opcode::LtInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::LessEqual => OverrideWrapper::new(Opcode::LeInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::Greater => OverrideWrapper::new(Opcode::GtInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)), + OverrideOperations::GreaterEqual => OverrideWrapper::new(Opcode::GeInt,IOType::new(vec![Self::export_info()], Some(TrcBool::export_info()), false)) ] } } diff --git a/libcore/src/types/trcstr.rs b/libcore/src/types/trcstr.rs index aa3598f3..7787f9c8 100644 --- a/libcore/src/types/trcstr.rs +++ b/libcore/src/types/trcstr.rs @@ -45,7 +45,7 @@ impl TrcStr { fn override_export() -> HashMap { collection_literals::hash![ - OverrideOperations::Add => OverrideWrapper::new(Opcode::AddStr, IOType::new(vec![Self::export_info()], TypeAllowNull::Some(Self::export_info()), false)) + OverrideOperations::Add => OverrideWrapper::new(Opcode::AddStr, IOType::new(vec![Self::export_info()], Some(Self::export_info()), false)) ] } diff --git a/src/base/ctrc.rs b/src/base/ctrc.rs index f738ef98..bb7f19bd 100644 --- a/src/base/ctrc.rs +++ b/src/base/ctrc.rs @@ -36,7 +36,7 @@ where >::Error: Send + Sync + std::fmt::Debug, { let tmp: LenSize = convert_to_lensize(len); - f.write_all(&(tmp).to_le_bytes())?; + f.write_all(&tmp.to_le_bytes())?; Ok(()) } @@ -67,7 +67,7 @@ fn write_bytecodes(f: &mut BufWriter, data: &StaticData) -> anyhow: // 先写入个数 write_integer(f, data.inst.len())?; for i in &data.inst { - write_integer(f, i.opcode as libcore::OpcodeTy)?; + write_integer(f, i.opcode as OpcodeTy)?; let opnums = i.opcode.get_opcode_arg_nums(); if opnums > 0 { write_integer(f, i.operand.0)?; diff --git a/src/compiler.rs b/src/compiler.rs index 791f4b09..1ece2c3a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -169,10 +169,9 @@ fn convert_str_to_float(s: String) -> f64 { impl ValuePool { fn new() -> Self { - let ret = Self { + Self { ..Default::default() - }; - ret + } } gen_getter_setter!( @@ -190,7 +189,7 @@ impl ValuePool { pub fn extend_pool(&mut self, data: &StaticData) { for i in &data.constpool.floatpool { - self.add_float((i).to_string()); + self.add_float(i.to_string()); } for i in &data.constpool.stringpool { // TODO::improve copy performance diff --git a/src/compiler/ast.rs b/src/compiler/ast.rs index 3a8c5389..f6ad9b84 100644 --- a/src/compiler/ast.rs +++ b/src/compiler/ast.rs @@ -13,9 +13,7 @@ use crate::{ use collection_literals::collection; use libcore::*; use rust_i18n::t; -use std::{ - cell::RefCell, collections::HashSet, env::vars_os, mem::swap, path::PathBuf, rc::Rc, usize, -}; +use std::{cell::RefCell, collections::HashSet, mem::swap, path::PathBuf, rc::Rc, usize}; #[derive(Default)] struct Cache { diff --git a/src/compiler/linker.rs b/src/compiler/linker.rs index e41effa6..224ff254 100644 --- a/src/compiler/linker.rs +++ b/src/compiler/linker.rs @@ -1,7 +1,7 @@ //! link different modules use crate::compiler::ValuePool; use libcore::*; -use std::{collections::HashSet, usize}; +use std::collections::HashSet; pub fn link<'a>(data_iter: impl Iterator) -> StaticData { let mut data = StaticData::new(); diff --git a/src/compiler/manager.rs b/src/compiler/manager.rs index d2654ff8..45b1a2b1 100644 --- a/src/compiler/manager.rs +++ b/src/compiler/manager.rs @@ -104,7 +104,4 @@ impl Default for ModuleManager { } #[cfg(test)] -mod tests { - use super::*; - use crate::compiler::ast::ModuleUnit; -} +mod tests {} diff --git a/src/compiler/token.rs b/src/compiler/token.rs index ba4ee6b0..7b16b64c 100644 --- a/src/compiler/token.rs +++ b/src/compiler/token.rs @@ -762,7 +762,7 @@ impl TokenLex { if v.0.is_empty() { zero_num += 1; } else { - s = (v.0.pop().unwrap()).to_string() + &s; + s = v.0.pop().unwrap().to_string() + &s; } } if v.0.is_empty() { @@ -968,12 +968,12 @@ mod tests { /// check const pool fn check_pool(v: Vec, pool_be_checked: &Pool) where - T: Eq + Hash + Clone + Display + Debug + std::convert::From, + T: Eq + Hash + Clone + Display + Debug + From, U: Eq + Hash + Clone + Display + Debug + Into, { let mut testpool: HashSet = HashSet::new(); for i in &v { - testpool.insert(((*i).clone()).into()); + testpool.insert((*i).clone().into()); } assert_eq!(testpool.len(), pool_be_checked.len()); for i in &testpool { diff --git a/src/tools/dis.rs b/src/tools/dis.rs index 3d422904..1f571742 100644 --- a/src/tools/dis.rs +++ b/src/tools/dis.rs @@ -1,5 +1,3 @@ -use std::usize; - use libcore::*; use crate::base::ctrc::load_from_reader_without_magic; diff --git a/src/tvm.rs b/src/tvm.rs index a66c8d27..ba384c60 100644 --- a/src/tvm.rs +++ b/src/tvm.rs @@ -1,8 +1,6 @@ mod def; mod function; -use std::usize; - use self::function::Frame; use crate::cfg; use libcore::*;