Skip to content

Commit

Permalink
fix(clippy):fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Mar 31, 2024
1 parent a6aae26 commit d039183
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 50 deletions.
4 changes: 2 additions & 2 deletions derive/src/def_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn lex_arrow(
}
left_push.push(
syn::parse(left_name.clone())
.expect(&format!("left push break, left name {}", left_name)),
.unwrap_or_else(|_| panic!("left push break, left name {}", left_name)),
);
right_push.push(syn::parse(right_name).expect("right push break"));
}
Expand All @@ -70,7 +70,7 @@ pub fn check_next_iter(iter: &mut IntoIter, check_str: &str) {
/// # Panics
///
/// Panics if the structure is not like `[a,b,c]`.
fn lex_group(mut iter: &mut IntoIter, container: &mut Vec<syn::Ident>) {
fn lex_group(iter: &mut IntoIter, container: &mut Vec<syn::Ident>) {
if let TokenTree::Group(x, ..) = iter.next().unwrap() {
// println!("{}", x);
let iter = x.stream().into_iter();
Expand Down
6 changes: 1 addition & 5 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ pub fn trc_const(_: TokenStream, input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as syn::ItemConst);
// 将const a = c;改成 const a = stringify!(c);
input.ty = parse_str("&str").unwrap();
input.expr = parse_str(&format!(
"stringify!({})",
input.expr.to_token_stream().to_string(),
))
.unwrap();
input.expr = parse_str(&format!("stringify!({})", input.expr.to_token_stream(),)).unwrap();
quote!(#input).into()
}
13 changes: 3 additions & 10 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ impl Display for Float {

type Pool<T> = HashMap<T, usize>;

#[derive(Default)]
pub struct ValuePool {
const_ints: Pool<i64>,
const_strings: Pool<String>,
const_floats: Pool<Float>,
name_pool: Pool<String>,
const_big_int: Pool<String>,
_const_big_int: Pool<String>,
id_int: Vec<i64>,
id_float: Vec<Float>,
id_str: Vec<String>,
Expand Down Expand Up @@ -166,15 +167,7 @@ macro_rules! gen_add_funcs {
impl ValuePool {
fn new() -> Self {
let mut ret = Self {
const_ints: HashMap::new(),
const_floats: HashMap::new(),
const_strings: HashMap::new(),
name_pool: HashMap::new(),
const_big_int: HashMap::new(),
id_int: vec![],
id_float: vec![],
id_str: vec![],
id_name: vec![],
..Default::default()
};
ret.add_int(0);
ret.add_int(1);
Expand Down
33 changes: 17 additions & 16 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
mod ast_base;
mod lexprocess;

use crate::base::{
codegen::{Opcode, StaticData, VmStackType, ARG_WRONG, NO_ARG},
error::*,
func,
stdlib::{get_stdlib, ArgsNameTy, IOType, RustFunction, BOOL, CHAR, FLOAT, INT, STR},
use crate::{
base::{
codegen::{Opcode, StaticData, VmStackType, ARG_WRONG, NO_ARG},
error::*,
func,
stdlib::{get_stdlib, ArgsNameTy, IOType, RustFunction, BOOL, CHAR, FLOAT, INT, STR},
},
compiler::token::TokenType::RightBigBrace,
};
use crate::compiler::token::TokenType::RightBigBrace;
use rust_i18n::t;
use std::{borrow::BorrowMut, mem::swap};
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, mem::swap, rc::Rc};

use super::{
scope::*,
Expand Down Expand Up @@ -124,7 +125,7 @@ impl<'a> AstBuilder<'a> {
}
let root_scope = Rc::new(RefCell::new(SymScope::new(None)));
// 为root scope添加prelude
let optimize = token_lexer.compiler_data.option.optimize;
let _optimize = token_lexer.compiler_data.option.optimize;
root_scope
.as_ref()
.borrow_mut()
Expand Down Expand Up @@ -488,7 +489,7 @@ impl<'a> AstBuilder<'a> {
// 定义类
match self.self_scope.as_ref().borrow().get_class(idx) {
None => {}
Some(v) => return Ok(()),
Some(_v) => return Ok(()),
}
}
TokenType::Dot => {
Expand Down Expand Up @@ -546,7 +547,7 @@ impl<'a> AstBuilder<'a> {
.borrow()
.get_class(self.process_info.pop_last_ty().unwrap())
.unwrap();
let oride = class_obj.get_override_func(optoken.clone());
let oride = class_obj.get_override_func(optoken);
match oride {
Some(v) => {
let tmp = v.io.check_argvs(vec![]);
Expand Down Expand Up @@ -851,7 +852,7 @@ impl<'a> AstBuilder<'a> {
}
import_item_name = format!("{}{}", c, import_item_name);
}
let mut items = path.split(".");
let mut items = path.split('.');
// 删除std
items.next();
let now = match get_stdlib().get_module(items) {
Expand Down Expand Up @@ -888,10 +889,10 @@ impl<'a> AstBuilder<'a> {
Some(module) => {
let tmp = self.token_lexer.add_id_token(&import_item_name);
let module_sym_idx: ScopeAllocIdTy = self.insert_sym_with_error(tmp)?;
self.import_module_sym(&module);
self.import_module_sym(module);
match self.self_scope.as_ref().borrow_mut().import_native_module(
module_sym_idx,
&module,
module,
&self.token_lexer.const_pool,
) {
Err(e) => {
Expand Down Expand Up @@ -945,7 +946,7 @@ impl<'a> AstBuilder<'a> {
/// 生成新建变量的指令
fn new_var(&mut self, name: ConstPoolIndexTy, varty: ScopeAllocClassId) -> AstError<()> {
let sym_idx = self.insert_sym_with_error(name)?;
let (var_sym, var_addr) =
let (_var_sym, var_addr) =
self.self_scope
.as_ref()
.borrow_mut()
Expand Down Expand Up @@ -1210,7 +1211,7 @@ impl<'a> AstBuilder<'a> {
let tmp = self.self_scope.clone();
// 解析参数
self.self_scope = Rc::new(RefCell::new(SymScope::new(Some(tmp.clone()))));
self.self_scope.as_ref().borrow_mut().func_io = Some(io.return_type.clone());
self.self_scope.as_ref().borrow_mut().func_io = Some(io.return_type);
debug_assert_eq!(io.argvs_type.len(), func_obj.args_names.len());
for (argty, argname) in io
.argvs_type
Expand Down
18 changes: 8 additions & 10 deletions src/compiler/llvm_convent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ use crate::base::codegen::StaticData;
// LLVMInt32TypeInContext, LLVMModuleCreateWithName,
// };

pub fn convert(tvm_data: StaticData) {
unsafe {
// let context = LLVMContextCreate();
// let module = LLVMModuleCreateWithName(b"main\0".as_ptr() as *const i8);
// let builder = LLVMCreateBuilderInContext(context);
// let i32_ty = LLVMInt32TypeInContext(context);
// // 创建main函数
// let main_ty = LLVMFunctionType(i32_ty, null_mut(), 0, 0);
// let main_func = LLVMAddFunction(module, b"main\0".as_ptr() as *const _, main_ty);
}
pub fn convert(_tvm_data: StaticData) {
// let context = LLVMContextCreate();
// let module = LLVMModuleCreateWithName(b"main\0".as_ptr() as *const i8);
// let builder = LLVMCreateBuilderInContext(context);
// let i32_ty = LLVMInt32TypeInContext(context);
// // 创建main函数
// let main_ty = LLVMFunctionType(i32_ty, null_mut(), 0, 0);
// let main_func = LLVMAddFunction(module, b"main\0".as_ptr() as *const _, main_ty);
}
8 changes: 4 additions & 4 deletions src/compiler/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::base::{
OverrideWrapper, Stdlib, STD_CLASS_TABLE,
},
};
use std::{borrow::BorrowMut, cell::RefCell, collections::HashMap, fmt::Display, rc::Rc, usize};
use std::{cell::RefCell, collections::HashMap, fmt::Display, rc::Rc};

pub type ScopeAllocIdTy = usize;
pub type TypeAllowNull = Option<TyIdxTy>;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl ClassInterface for CustomType {
&self.origin_name
}

fn get_override_func(&self, oper_token: super::token::TokenType) -> Option<&OverrideWrapper> {
fn get_override_func(&self, _oper_token: super::token::TokenType) -> Option<&OverrideWrapper> {
None
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ impl SymScope {
let idx = module_scope
.as_ref()
.borrow_mut()
.insert_sym_with_error(const_pool.name_pool[i.0], &i.0)?;
.insert_sym_with_error(const_pool.name_pool[i.0], i.0)?;
module_scope
.as_ref()
.borrow_mut()
Expand All @@ -241,7 +241,7 @@ impl SymScope {
let idx = module_scope
.as_ref()
.borrow_mut()
.insert_sym_with_error(const_pool.name_pool[i.0], &i.0)?;
.insert_sym_with_error(const_pool.name_pool[i.0], i.0)?;
module_scope
.as_ref()
.borrow_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a> TokenLex<'a> {
}
let tmp = get_keywords().get(&retname);
match tmp {
Some(val) => Token::new((*val).clone(), None),
Some(val) => Token::new(*val, None),
None => {
if retname == "true" {
return Ok(Token::new(TokenType::BoolValue, Some(1)));
Expand Down
3 changes: 1 addition & 2 deletions src/tools/update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{error::Error, fmt::Display};

static GITHUB_API_URL: &str = "http://185.106.176.199/trc_version";
static _GITHUB_API_URL: &str = "http://185.106.176.199/trc_version";

pub fn check_version() -> Result<(), Box<dyn Error>> {
Ok(())
Expand All @@ -15,7 +15,6 @@ impl Display for UpdateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
"Only support Linux.Users on other platforms should update program by hand"
)
}
Expand Down

0 comments on commit d039183

Please sign in to comment.