Skip to content

Commit

Permalink
fix(main):clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Apr 20, 2024
1 parent ef50b51 commit 679bce1
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
6 changes: 3 additions & 3 deletions libcore/src/types/trcbool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl TrcBool {

fn override_export() -> HashMap<OverrideOperations, OverrideWrapper> {
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))
]
}
}
24 changes: 12 additions & 12 deletions libcore/src/types/trcfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ impl TrcFloat {

fn override_export() -> HashMap<OverrideOperations, OverrideWrapper> {
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))
]
}
}
Expand Down
40 changes: 20 additions & 20 deletions libcore/src/types/trcint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ impl TrcInt {
}

fn override_export() -> HashMap<OverrideOperations, OverrideWrapper> {
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))
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion libcore/src/types/trcstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl TrcStr {

fn override_export() -> HashMap<OverrideOperations, OverrideWrapper> {
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))
]
}

Expand Down
4 changes: 2 additions & 2 deletions src/base/ctrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
<U as TryInto<u64>>::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(())
}

Expand Down Expand Up @@ -67,7 +67,7 @@ fn write_bytecodes<T: Write>(f: &mut BufWriter<T>, 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)?;
Expand Down
7 changes: 3 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/linker.rs
Original file line number Diff line number Diff line change
@@ -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<Item = &'a mut StaticData>) -> StaticData {
let mut data = StaticData::new();
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,4 @@ impl Default for ModuleManager {
}

#[cfg(test)]
mod tests {
use super::*;
use crate::compiler::ast::ModuleUnit;
}
mod tests {}
6 changes: 3 additions & 3 deletions src/compiler/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -968,12 +968,12 @@ mod tests {
/// check const pool
fn check_pool<T, U>(v: Vec<U>, pool_be_checked: &Pool<T>)
where
T: Eq + Hash + Clone + Display + Debug + std::convert::From<U>,
T: Eq + Hash + Clone + Display + Debug + From<U>,
U: Eq + Hash + Clone + Display + Debug + Into<T>,
{
let mut testpool: HashSet<T> = 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 {
Expand Down
2 changes: 0 additions & 2 deletions src/tools/dis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::usize;

use libcore::*;

use crate::base::ctrc::load_from_reader_without_magic;
Expand Down
2 changes: 0 additions & 2 deletions src/tvm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod def;
mod function;

use std::usize;

use self::function::Frame;
use crate::cfg;
use libcore::*;
Expand Down

0 comments on commit 679bce1

Please sign in to comment.