fixes
This commit is contained in:
parent
622893ebf0
commit
781e8ba3a3
13 changed files with 20 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
use core::fmt;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::chunk::{Arg24, Catch, Chunk, Instruction as I};
|
use crate::chunk::{Arg24, Catch, Chunk, Instruction as I};
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
symbol::{Symbol, SYM_MSG, SYM_TRACE, SYM_TYPE},
|
symbol::{Symbol, SYM_MSG, SYM_TRACE, SYM_TYPE},
|
||||||
value::Value,
|
value::Value,
|
||||||
};
|
};
|
||||||
use std::{fmt::Display, rc::Rc};
|
use std::{error::Error, fmt::Display, rc::Rc};
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Exception>;
|
pub type Result<T> = std::result::Result<T, Exception>;
|
||||||
|
|
||||||
|
@ -114,6 +114,8 @@ impl Display for Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error for Exception {}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! exception {
|
macro_rules! exception {
|
||||||
($exc_ty:expr, $($t:tt)*) => {
|
($exc_ty:expr, $($t:tt)*) => {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use core::{f64, panic};
|
|
||||||
use std::{borrow::Cow, cmp::Ordering, fmt, hash::Hash, mem::ManuallyDrop, ops, rc::Rc};
|
use std::{borrow::Cow, cmp::Ordering, fmt, hash::Hash, mem::ManuallyDrop, ops, rc::Rc};
|
||||||
|
|
||||||
use num::{
|
use num::{
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use core::panic;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
parser::ast::{CatchBlock, Expr, ExprKind, LValue, LValueKind, ListItem, TableItem},
|
parser::ast::{CatchBlock, Expr, ExprKind, LValue, LValueKind, ListItem, TableItem},
|
||||||
value::Value,
|
value::Value,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use core::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ops::{BinaryOp, UnaryOp},
|
ops::{BinaryOp, UnaryOp},
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use core::fmt;
|
use std::{fmt, num::ParseFloatError};
|
||||||
use std::num::ParseFloatError;
|
|
||||||
|
|
||||||
use num::{bigint::ParseBigIntError, Num};
|
use num::{bigint::ParseBigIntError, Num};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use core::fmt;
|
use std::fmt;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use num::{bigint::Sign, BigInt};
|
use num::{bigint::Sign, BigInt};
|
||||||
|
|
|
@ -16,6 +16,7 @@ regex = { version = "1.11", optional = true }
|
||||||
rand = { version = "0.8", optional = true }
|
rand = { version = "0.8", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["rand", "regex"]
|
default = ["rand", "regex", "file"]
|
||||||
rand = ["dep:rand", "dep:num-bigint"]
|
rand = ["dep:rand", "dep:num-bigint"]
|
||||||
regex = ["dep:regex"]
|
regex = ["dep:regex"]
|
||||||
|
file = []
|
||||||
|
|
|
@ -678,6 +678,7 @@ fn spawn_inner(fname: &str, proc: &mut Command, opts: Value) -> Result<Value> {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => throw!(*SYM_IO_ERROR, "{e}"),
|
Err(e) => throw!(*SYM_IO_ERROR, "{e}"),
|
||||||
};
|
};
|
||||||
|
#[expect(clippy::mutable_key_type)]
|
||||||
let mut table = HashMap::new();
|
let mut table = HashMap::new();
|
||||||
if let Some(stdin) = child.stdin.take() {
|
if let Some(stdin) = child.stdin.take() {
|
||||||
let bf = match BufFile::from_raw_fd(stdin.into_raw_fd(), true) {
|
let bf = match BufFile::from_raw_fd(stdin.into_raw_fd(), true) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
io::{BufRead, Write},
|
io::{BufRead, Write},
|
||||||
os::unix::ffi::OsStrExt,
|
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
@ -127,7 +126,7 @@ pub fn env(_: &mut Vm, args: Vec<Value>) -> Result<Value> {
|
||||||
}
|
}
|
||||||
let val = std::env::var_os(key.to_os_str());
|
let val = std::env::var_os(key.to_os_str());
|
||||||
match val {
|
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),
|
None => Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -619,6 +619,7 @@ pub fn list(vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
|
||||||
pub fn table(vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
|
pub fn table(vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
|
||||||
let [_, iter] = unpack_args!(args);
|
let [_, iter] = unpack_args!(args);
|
||||||
let iter = iter.to_iter_function()?;
|
let iter = iter.to_iter_function()?;
|
||||||
|
#[expect(clippy::mutable_key_type)]
|
||||||
let mut result = HashMap::new();
|
let mut result = HashMap::new();
|
||||||
while let Some(value) = vmcalliter!(vm; iter.clone())? {
|
while let Some(value) = vmcalliter!(vm; iter.clone())? {
|
||||||
let Value::List(l) = value else {
|
let Value::List(l) = value else {
|
||||||
|
@ -851,6 +852,7 @@ pub fn count(vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
|
||||||
let [_, iter] = unpack_args!(args);
|
let [_, iter] = unpack_args!(args);
|
||||||
let iter = iter.to_iter_function()?;
|
let iter = iter.to_iter_function()?;
|
||||||
|
|
||||||
|
#[expect(clippy::mutable_key_type)]
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
|
|
||||||
while let Some(v) = vmcalliter!(vm; iter.clone())? {
|
while let Some(v) = vmcalliter!(vm; iter.clone())? {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#![allow(clippy::mutable_key_type)]
|
|
||||||
|
|
||||||
use talc_lang::{
|
use talc_lang::{
|
||||||
symbol::{symbol, Symbol},
|
symbol::{symbol, Symbol},
|
||||||
vm::Vm,
|
vm::Vm,
|
||||||
|
@ -7,7 +5,6 @@ use talc_lang::{
|
||||||
|
|
||||||
pub mod collection;
|
pub mod collection;
|
||||||
pub mod exception;
|
pub mod exception;
|
||||||
pub mod file;
|
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod ints;
|
pub mod ints;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
@ -16,6 +13,8 @@ pub mod math;
|
||||||
pub mod string;
|
pub mod string;
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
|
||||||
|
#[cfg(feature = "file")]
|
||||||
|
pub mod file;
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub mod random;
|
pub mod random;
|
||||||
#[cfg(feature = "regex")]
|
#[cfg(feature = "regex")]
|
||||||
|
@ -24,7 +23,6 @@ pub mod regex;
|
||||||
pub fn load_all(vm: &mut Vm) {
|
pub fn load_all(vm: &mut Vm) {
|
||||||
collection::load(vm);
|
collection::load(vm);
|
||||||
exception::load(vm);
|
exception::load(vm);
|
||||||
file::load(vm);
|
|
||||||
format::load(vm);
|
format::load(vm);
|
||||||
io::load(vm);
|
io::load(vm);
|
||||||
iter::load(vm);
|
iter::load(vm);
|
||||||
|
@ -33,6 +31,8 @@ pub fn load_all(vm: &mut Vm) {
|
||||||
string::load(vm);
|
string::load(vm);
|
||||||
value::load(vm);
|
value::load(vm);
|
||||||
|
|
||||||
|
#[cfg(feature = "file")]
|
||||||
|
file::load(vm);
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
random::load(vm);
|
random::load(vm);
|
||||||
#[cfg(feature = "regex")]
|
#[cfg(feature = "regex")]
|
||||||
|
|
|
@ -130,11 +130,14 @@ pub fn copy_inner(value: Value) -> Result<Value> {
|
||||||
Ok(v?.into())
|
Ok(v?.into())
|
||||||
}
|
}
|
||||||
Value::Table(t) => {
|
Value::Table(t) => {
|
||||||
|
#[expect(clippy::mutable_key_type)]
|
||||||
let t = Rc::unwrap_or_clone(t).take();
|
let t = Rc::unwrap_or_clone(t).take();
|
||||||
|
|
||||||
let v: Result<HashMap<HashValue, Value>> = t
|
let v: Result<HashMap<HashValue, Value>> = t
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| copy_inner(v).map(|v| (k, v)))
|
.map(|(k, v)| copy_inner(v).map(|v| (k, v)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(v?.into())
|
Ok(v?.into())
|
||||||
}
|
}
|
||||||
Value::Native(ref n) => match n.copy_value()? {
|
Value::Native(ref n) => match n.copy_value()? {
|
||||||
|
|
Loading…
Add table
Reference in a new issue