From 781e8ba3a3caa6067b35d700b4f72352332cab53 Mon Sep 17 00:00:00 2001 From: trimill Date: Mon, 6 Jan 2025 00:15:50 -0500 Subject: [PATCH] fixes --- talc-lang/src/compiler.rs | 2 +- talc-lang/src/exception.rs | 4 +++- talc-lang/src/number/int.rs | 1 - talc-lang/src/optimize.rs | 2 -- talc-lang/src/parser/ast.rs | 2 +- talc-lang/src/parser/util.rs | 3 +-- talc-lang/src/serial/mod.rs | 2 +- talc-std/Cargo.toml | 3 ++- talc-std/src/file.rs | 1 + talc-std/src/io.rs | 3 +-- talc-std/src/iter.rs | 2 ++ talc-std/src/lib.rs | 8 ++++---- talc-std/src/value.rs | 3 +++ 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/talc-lang/src/compiler.rs b/talc-lang/src/compiler.rs index 964117c..6c35553 100644 --- a/talc-lang/src/compiler.rs +++ b/talc-lang/src/compiler.rs @@ -1,5 +1,5 @@ -use core::fmt; use std::collections::HashMap; +use std::fmt; use std::rc::Rc; use crate::chunk::{Arg24, Catch, Chunk, Instruction as I}; diff --git a/talc-lang/src/exception.rs b/talc-lang/src/exception.rs index 0d00612..ae7c535 100644 --- a/talc-lang/src/exception.rs +++ b/talc-lang/src/exception.rs @@ -3,7 +3,7 @@ use crate::{ symbol::{Symbol, SYM_MSG, SYM_TRACE, SYM_TYPE}, value::Value, }; -use std::{fmt::Display, rc::Rc}; +use std::{error::Error, fmt::Display, rc::Rc}; pub type Result = std::result::Result; @@ -114,6 +114,8 @@ impl Display for Exception { } } +impl Error for Exception {} + #[macro_export] macro_rules! exception { ($exc_ty:expr, $($t:tt)*) => { diff --git a/talc-lang/src/number/int.rs b/talc-lang/src/number/int.rs index a8e41a2..ff40254 100644 --- a/talc-lang/src/number/int.rs +++ b/talc-lang/src/number/int.rs @@ -1,4 +1,3 @@ -use core::{f64, panic}; use std::{borrow::Cow, cmp::Ordering, fmt, hash::Hash, mem::ManuallyDrop, ops, rc::Rc}; use num::{ diff --git a/talc-lang/src/optimize.rs b/talc-lang/src/optimize.rs index 996db69..19549fd 100644 --- a/talc-lang/src/optimize.rs +++ b/talc-lang/src/optimize.rs @@ -1,5 +1,3 @@ -use core::panic; - use crate::{ parser::ast::{CatchBlock, Expr, ExprKind, LValue, LValueKind, ListItem, TableItem}, value::Value, diff --git a/talc-lang/src/parser/ast.rs b/talc-lang/src/parser/ast.rs index d48fc6d..2d5d893 100644 --- a/talc-lang/src/parser/ast.rs +++ b/talc-lang/src/parser/ast.rs @@ -1,4 +1,4 @@ -use core::fmt; +use std::fmt; use crate::{ ops::{BinaryOp, UnaryOp}, diff --git a/talc-lang/src/parser/util.rs b/talc-lang/src/parser/util.rs index ce2dccd..e3ff1ea 100644 --- a/talc-lang/src/parser/util.rs +++ b/talc-lang/src/parser/util.rs @@ -1,5 +1,4 @@ -use core::fmt; -use std::num::ParseFloatError; +use std::{fmt, num::ParseFloatError}; use num::{bigint::ParseBigIntError, Num}; diff --git a/talc-lang/src/serial/mod.rs b/talc-lang/src/serial/mod.rs index 6255875..f420675 100644 --- a/talc-lang/src/serial/mod.rs +++ b/talc-lang/src/serial/mod.rs @@ -1,4 +1,4 @@ -use core::fmt; +use std::fmt; use std::io::{self, Write}; use num::{bigint::Sign, BigInt}; diff --git a/talc-std/Cargo.toml b/talc-std/Cargo.toml index d8a06a7..b9377bd 100644 --- a/talc-std/Cargo.toml +++ b/talc-std/Cargo.toml @@ -16,6 +16,7 @@ regex = { version = "1.11", optional = true } rand = { version = "0.8", optional = true } [features] -default = ["rand", "regex"] +default = ["rand", "regex", "file"] rand = ["dep:rand", "dep:num-bigint"] regex = ["dep:regex"] +file = [] diff --git a/talc-std/src/file.rs b/talc-std/src/file.rs index a3342ef..64eb057 100644 --- a/talc-std/src/file.rs +++ b/talc-std/src/file.rs @@ -678,6 +678,7 @@ fn spawn_inner(fname: &str, proc: &mut Command, opts: Value) -> Result { Ok(c) => c, Err(e) => throw!(*SYM_IO_ERROR, "{e}"), }; + #[expect(clippy::mutable_key_type)] let mut table = HashMap::new(); if let Some(stdin) = child.stdin.take() { let bf = match BufFile::from_raw_fd(stdin.into_raw_fd(), true) { diff --git a/talc-std/src/io.rs b/talc-std/src/io.rs index 8fd7e2a..d3893e0 100644 --- a/talc-std/src/io.rs +++ b/talc-std/src/io.rs @@ -1,6 +1,5 @@ use std::{ io::{BufRead, Write}, - os::unix::ffi::OsStrExt, sync::Mutex, time::{SystemTime, UNIX_EPOCH}, }; @@ -127,7 +126,7 @@ pub fn env(_: &mut Vm, args: Vec) -> Result { } let val = std::env::var_os(key.to_os_str()); match val { - Some(val) => Ok(LString::from(val.as_bytes()).into()), + Some(val) => Ok(LString::from(val.as_encoded_bytes()).into()), None => Ok(Value::Nil), } } diff --git a/talc-std/src/iter.rs b/talc-std/src/iter.rs index 59617f2..2dda07b 100644 --- a/talc-std/src/iter.rs +++ b/talc-std/src/iter.rs @@ -619,6 +619,7 @@ pub fn list(vm: &mut Vm, args: Vec) -> Result { pub fn table(vm: &mut Vm, args: Vec) -> Result { let [_, iter] = unpack_args!(args); let iter = iter.to_iter_function()?; + #[expect(clippy::mutable_key_type)] let mut result = HashMap::new(); while let Some(value) = vmcalliter!(vm; iter.clone())? { let Value::List(l) = value else { @@ -851,6 +852,7 @@ pub fn count(vm: &mut Vm, args: Vec) -> Result { let [_, iter] = unpack_args!(args); let iter = iter.to_iter_function()?; + #[expect(clippy::mutable_key_type)] let mut map = HashMap::new(); while let Some(v) = vmcalliter!(vm; iter.clone())? { diff --git a/talc-std/src/lib.rs b/talc-std/src/lib.rs index 8b0c876..387cc9d 100644 --- a/talc-std/src/lib.rs +++ b/talc-std/src/lib.rs @@ -1,5 +1,3 @@ -#![allow(clippy::mutable_key_type)] - use talc_lang::{ symbol::{symbol, Symbol}, vm::Vm, @@ -7,7 +5,6 @@ use talc_lang::{ pub mod collection; pub mod exception; -pub mod file; pub mod format; pub mod ints; pub mod io; @@ -16,6 +13,8 @@ pub mod math; pub mod string; pub mod value; +#[cfg(feature = "file")] +pub mod file; #[cfg(feature = "rand")] pub mod random; #[cfg(feature = "regex")] @@ -24,7 +23,6 @@ pub mod regex; pub fn load_all(vm: &mut Vm) { collection::load(vm); exception::load(vm); - file::load(vm); format::load(vm); io::load(vm); iter::load(vm); @@ -33,6 +31,8 @@ pub fn load_all(vm: &mut Vm) { string::load(vm); value::load(vm); + #[cfg(feature = "file")] + file::load(vm); #[cfg(feature = "rand")] random::load(vm); #[cfg(feature = "regex")] diff --git a/talc-std/src/value.rs b/talc-std/src/value.rs index b6ce95f..b2154cc 100644 --- a/talc-std/src/value.rs +++ b/talc-std/src/value.rs @@ -130,11 +130,14 @@ pub fn copy_inner(value: Value) -> Result { Ok(v?.into()) } Value::Table(t) => { + #[expect(clippy::mutable_key_type)] let t = Rc::unwrap_or_clone(t).take(); + let v: Result> = t .into_iter() .map(|(k, v)| copy_inner(v).map(|v| (k, v))) .collect(); + Ok(v?.into()) } Value::Native(ref n) => match n.copy_value()? {