From 3037c65f687c1d88f3b4a3ec44aa7a208279d99d Mon Sep 17 00:00:00 2001 From: Shautvast Date: Fri, 5 Dec 2025 20:45:42 +0100 Subject: [PATCH] clippys --- src/builtins/globals.rs | 6 ++-- src/builtins/list.rs | 22 --------------- src/builtins/mod.rs | 2 +- src/builtins/string.rs | 2 +- src/compiler/assembly_pass.rs | 3 +- src/compiler/ast_pass.rs | 2 +- src/compiler/mod.rs | 2 +- src/main.rs | 2 +- src/symbol_builder.rs | 53 ++++++++++++++++++++--------------- src/vm.rs | 8 +----- 10 files changed, 41 insertions(+), 61 deletions(-) diff --git a/src/builtins/globals.rs b/src/builtins/globals.rs index a000b6f..371feb6 100644 --- a/src/builtins/globals.rs +++ b/src/builtins/globals.rs @@ -1,4 +1,4 @@ -use std::cell::{Ref, RefMut}; +use std::cell::{RefMut}; use crate::builtins::{FunctionMap, Signature, add}; use crate::compiler::tokens::TokenType::{DateTime, StringType, Void}; use crate::errors::RuntimeError; @@ -31,7 +31,7 @@ fn print(_self_val: RefMut, args: Vec) -> Result, _args: Vec) -> Result { - Ok(Value::DateTime(Box::new(chrono::DateTime::from( + Ok(Value::DateTime(Box::new( chrono::Utc::now(), - )))) + ))) } diff --git a/src/builtins/list.rs b/src/builtins/list.rs index 18f812a..42f4a93 100644 --- a/src/builtins/list.rs +++ b/src/builtins/list.rs @@ -8,28 +8,6 @@ use std::cell::RefMut; use std::collections::HashMap; use std::ops::{Deref, DerefMut}; -macro_rules! mut_list_fn { - (mut $list:ident, mut $args:ident => $body:expr) => { - |self_val: RefMut, mut $args: Vec| -> Result { - match self_val { - Value::List(mut $list) => $body, - _ => Err(expected_a_list()), - } - } - }; -} - -macro_rules! list_fn { - ($list:ident, $args:ident => $body:expr) => { - |self_val: Ref, $args: Vec| -> Result { - match self_val { - Value::List($list) => $body, - _ => Err(expected_a_list()), - } - } - }; -} - pub(crate) fn list_functions() -> FunctionMap { let mut list_functions: FunctionMap = HashMap::new(); let functions = &mut list_functions; diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 0800959..f82a76d 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -2,7 +2,7 @@ mod string; mod list; pub(crate) mod globals; -use std::cell::{Ref, RefCell, RefMut}; +use std::cell::{RefCell, RefMut}; use crate::builtins::string::string_functions; use crate::errors::{CompilerError, RuntimeError}; use crate::compiler::tokens::TokenType; diff --git a/src/builtins/string.rs b/src/builtins/string.rs index ea2bc08..46a51fa 100644 --- a/src/builtins/string.rs +++ b/src/builtins/string.rs @@ -1,4 +1,4 @@ -use std::cell::{Ref, RefMut}; +use std::cell::{RefMut}; use crate::builtins::{FunctionMap, Parameter, Signature, add, expected}; use crate::errors::RuntimeError; use crate::compiler::tokens::TokenType::{StringType, U64}; diff --git a/src/compiler/assembly_pass.rs b/src/compiler/assembly_pass.rs index 758898b..ff722a7 100644 --- a/src/compiler/assembly_pass.rs +++ b/src/compiler/assembly_pass.rs @@ -3,7 +3,7 @@ use crate::builtins::lookup; use crate::compiler::assembly_pass::Op::{ Add, And, Assign, BitAnd, BitOr, BitXor, Call, CallBuiltin, Constant, DefList, DefMap, Divide, Dup, Equal, Get, Goto, GotoIf, GotoIfNot, Greater, GreaterEqual, Less, LessEqual, ListGet, - Multiply, Negate, Not, NotEqual, Or, Pop, Print, Return, Shr, Subtract, + Multiply, Negate, Not, NotEqual, Or, Pop, Return, Shr, Subtract, }; use crate::compiler::ast_pass::Expression::{IfElseExpression, IfExpression, NamedParameter}; use crate::compiler::ast_pass::{Expression, Function, Parameter, Statement}; @@ -529,7 +529,6 @@ pub enum Op { Multiply, Divide, Negate, - Print, Return, Call(usize, usize), And, diff --git a/src/compiler/ast_pass.rs b/src/compiler/ast_pass.rs index 71fe8c7..7243962 100644 --- a/src/compiler/ast_pass.rs +++ b/src/compiler/ast_pass.rs @@ -7,7 +7,7 @@ use crate::compiler::tokens::TokenType::{ Bang, Bool, Char, Colon, DateTime, Dot, Else, Eof, Eol, Equal, False, FloatingPoint, Fn, For, Greater, GreaterEqual, GreaterGreater, Identifier, If, In, Indent, Integer, LeftBrace, LeftBracket, LeftParen, Less, LessEqual, LessLess, Let, ListType, MapType, Minus, Object, Plus, - Print, Range, RightBrace, RightBracket, RightParen, SingleRightArrow, Slash, Star, StringType, + Range, RightBrace, RightBracket, RightParen, SingleRightArrow, Slash, Star, StringType, True, U32, U64, Unknown, }; use crate::compiler::tokens::{Token, TokenType}; diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index 2472755..4613571 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::fs; use walkdir::WalkDir; -use crate::{compiler, symbol_builder, AsmRegistry, TIPI_EXT}; +use crate::{symbol_builder, AsmRegistry, TIPI_EXT}; use crate::compiler::assembly_pass::AsmChunk; use crate::errors::TipiLangError; use crate::errors::TipiLangError::Platform; diff --git a/src/main.rs b/src/main.rs index 4afdb75..02541e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use std::fs; use std::sync::Arc; use tipi_lang::compiler::assembly_pass::AsmChunk; -use tipi_lang::compiler::{compile, compile_sourcedir, map_underlying, run}; +use tipi_lang::compiler::{compile_sourcedir, map_underlying, run}; use tipi_lang::errors::TipiLangError; use tipi_lang::vm::interpret_async; diff --git a/src/symbol_builder.rs b/src/symbol_builder.rs index 06d72e8..8d9c0b2 100644 --- a/src/symbol_builder.rs +++ b/src/symbol_builder.rs @@ -1,13 +1,16 @@ -use crate::compiler::ast_pass::{Expression, Parameter, Statement}; use crate::builtins::lookup; -use crate::errors::CompilerError; -use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable}; -use crate::compiler::tokens::TokenType::{Bool, DateTime, F32, F64, FloatingPoint, Greater, GreaterEqual, I32, I64, Integer, Less, LessEqual, ListType, MapType, Minus, ObjectType, Plus, SignedInteger, StringType, U32, U64, Unknown, UnsignedInteger, Void}; +use crate::compiler::ast_pass::{Expression, Parameter, Statement}; +use crate::compiler::tokens::TokenType::{ + Bool, DateTime, F32, F64, FloatingPoint, Greater, GreaterEqual, I32, I64, Integer, Less, + LessEqual, ListType, MapType, Minus, ObjectType, Plus, SignedInteger, StringType, U32, U64, + Unknown, UnsignedInteger, Void, +}; use crate::compiler::tokens::{Token, TokenType}; +use crate::errors::CompilerError; +use crate::errors::CompilerError::IncompatibleTypes; use log::debug; use std::collections::HashMap; use std::ops::Deref; -use crate::compiler::assembly_pass::Op::Assign; pub enum Symbol { Function { @@ -57,17 +60,14 @@ pub fn build(path: &str, ast: &[Statement], symbols: &mut HashMap { - match expression{ - Expression::LetExpression { name, var_type, initializer } => { - let key = make_qname(path, name); - symbols.entry(key).or_insert_with(|| Symbol::Variable { - name: name.lexeme.to_string(), - var_type: var_type.clone(), - }); - } - _ =>{} - } + Statement::ExpressionStmt { + expression: Expression::LetExpression { name, var_type, .. }, + } => { + let key = make_qname(path, name); + symbols.entry(key).or_insert_with(|| Symbol::Variable { + name: name.lexeme.to_string(), + var_type: var_type.clone(), + }); } _ => {} } @@ -118,7 +118,10 @@ pub fn calculate_type( }) } -pub fn infer_type(expr: &Expression, symbols: &HashMap) -> Result { +pub fn infer_type( + expr: &Expression, + symbols: &HashMap, +) -> Result { match expr { Expression::Binary { left, @@ -219,8 +222,12 @@ pub fn infer_type(expr: &Expression, symbols: &HashMap) -> Resul Expression::MapGet { .. } => Ok(Unknown), Expression::FieldGet { .. } => Ok(Unknown), Expression::Range { lower, .. } => infer_type(lower, symbols), - Expression::IfExpression { .. } => Ok(Unknown), - Expression::IfElseExpression { then_branch, else_branch, .. } => { + Expression::IfExpression { .. } => Ok(Unknown), + Expression::IfElseExpression { + then_branch, + else_branch, + .. + } => { let mut then_type = Void; for statement in then_branch { if let Statement::ExpressionStmt { expression } = statement { @@ -234,12 +241,14 @@ pub fn infer_type(expr: &Expression, symbols: &HashMap) -> Resul else_type = infer_type(expression, symbols)? } } - if then_type != else_type{ - Err(CompilerError::IfElseBranchesDoNotMatch(then_type, else_type)) + if then_type != else_type { + Err(CompilerError::IfElseBranchesDoNotMatch( + then_type, else_type, + )) } else { Ok(then_type) } - }, + } Expression::LetExpression { .. } => Ok(Void), Expression::ForStatement { .. } => Ok(Void), } diff --git a/src/vm.rs b/src/vm.rs index 45bfcbb..27d4a86 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -5,11 +5,10 @@ use crate::compiler::tokens::TokenType; use crate::errors::{RuntimeError, ValueError}; use crate::value::{Object, Value}; use arc_swap::Guard; -use std::cell::{RefCell, RefMut}; +use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; use std::sync::Arc; -use tracing::debug; pub async fn interpret_async( registry: Guard>>, @@ -130,11 +129,6 @@ impl Vm { Op::Less => binary_op(self, |a, b| Ok(Value::Bool(a < b))), Op::LessEqual => binary_op(self, |a, b| Ok(Value::Bool(a <= b))), Op::NotEqual => binary_op(self, |a, b| Ok(Value::Bool(a != b))), - Op::Print => { - debug!("print {:?}", self.stack); - let v = self.pop().borrow().clone(); - println!("{}", v); - } Op::DefList(len) => { let mut list = vec![]; for _ in 0..*len {