Skip to content

Commit 805cec7

Browse files
committed
steel-core, steel-parser: remove dependency on num crate
just use the needed dependencies directly
1 parent 0dd1eab commit 805cec7

File tree

14 files changed

+56
-76
lines changed

14 files changed

+56
-76
lines changed

Cargo.lock

Lines changed: 7 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/steel-core/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ chrono = { version = "0.4.23", default-features = false, features = ["std", "clo
4141
weak-table = "0.3.2"
4242
# TODO: Consider whether rand needs to be here
4343
rand = "0.9.0"
44-
# TODO: Consider only depending on the sub crate
45-
num = "0.4.0"
44+
num-bigint = "0.4.6"
45+
num-rational = "0.4.2"
46+
num-traits = "0.2.19"
47+
num-integer = "0.1.46"
4648
radix_fmt = "1.0.0"
4749

4850
# For structs

crates/steel-core/src/compiler/program.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use crate::{
1919
rvals::IntoSteelVal,
2020
};
2121

22-
use num::{BigInt, BigRational, Rational32};
22+
use num_bigint::BigInt;
23+
use num_rational::{BigRational, Rational32};
2324
use serde::{Deserialize, Serialize};
2425
use std::{collections::HashMap, convert::TryInto, time::SystemTime};
2526
use steel_parser::tokens::{IntLiteral, NumberLiteral, RealLiteral};

crates/steel-core/src/parser/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::rvals::{IntoSteelVal, SteelComplex, SteelString};
22
use crate::{parser::tokens::TokenType::*, rvals::FromSteelVal};
33

4-
use num::BigRational;
4+
use num_rational::BigRational;
55
use std::borrow::Cow;
66
use std::str;
77
use std::sync::{Arc, Mutex};

crates/steel-core/src/primitives.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub use fs::{fs_module, fs_module_sandbox};
5151
pub use io::IoFunctions;
5252
pub use lists::UnRecoverableResult;
5353
pub use meta_ops::MetaOperations;
54-
use num::{BigInt, BigRational, Rational32, ToPrimitive};
54+
use num_bigint::BigInt;
55+
use num_rational::{BigRational, Rational32};
56+
use num_traits::ToPrimitive;
5557
pub use numbers::{add_primitive, divide_primitive, multiply_primitive, subtract_primitive};
5658
pub use ports::port_module;
5759
use std::convert::TryFrom;

crates/steel-core/src/primitives/numbers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::rvals::{IntoSteelVal, Result, SteelComplex, SteelVal};
22
use crate::{steelerr, stop};
3-
use num::Zero;
4-
use num::{
5-
pow::Pow, BigInt, BigRational, CheckedAdd, CheckedMul, Integer, Rational32, Signed, ToPrimitive,
6-
};
3+
use num_bigint::BigInt;
4+
use num_integer::Integer;
5+
use num_rational::{BigRational, Rational32};
6+
use num_traits::{pow::Pow, CheckedAdd, CheckedMul, Signed, ToPrimitive, Zero};
77
use std::ops::Neg;
88

99
/// Checks if the given value is a number
@@ -957,8 +957,8 @@ fn expt(left: &SteelVal, right: &SteelVal) -> Result<SteelVal> {
957957

958958
let expt = BigInt::from(*l).pow(r.magnitude());
959959
match r.sign() {
960-
num::bigint::Sign::Plus | num::bigint::Sign::NoSign => expt.into_steelval(),
961-
num::bigint::Sign::Minus => {
960+
num_bigint::Sign::Plus | num_bigint::Sign::NoSign => expt.into_steelval(),
961+
num_bigint::Sign::Minus => {
962962
BigRational::new_raw(BigInt::from(1), expt).into_steelval()
963963
}
964964
}
@@ -1003,8 +1003,8 @@ fn expt(left: &SteelVal, right: &SteelVal) -> Result<SteelVal> {
10031003
(SteelVal::BigNum(l), SteelVal::BigNum(r)) => {
10041004
let expt = l.as_ref().clone().pow(r.magnitude());
10051005
match r.sign() {
1006-
num::bigint::Sign::NoSign | num::bigint::Sign::Plus => expt.into_steelval(),
1007-
num::bigint::Sign::Minus => {
1006+
num_bigint::Sign::NoSign | num_bigint::Sign::Plus => expt.into_steelval(),
1007+
num_bigint::Sign::Minus => {
10081008
BigRational::new_raw(BigInt::from(1), expt).into_steelval()
10091009
}
10101010
}
@@ -1412,7 +1412,7 @@ fn exact_integer_sqrt(number: &SteelVal) -> Result<SteelVal> {
14121412

14131413
fn exact_integer_impl<'a, N>(target: &'a N) -> (N, N)
14141414
where
1415-
N: num::integer::Roots + Clone,
1415+
N: num_integer::Roots + Clone,
14161416
&'a N: std::ops::Mul<&'a N, Output = N>,
14171417
N: std::ops::Sub<N, Output = N>,
14181418
{
@@ -1862,7 +1862,7 @@ mod num_op_tests {
18621862
)
18631863
.unwrap()
18641864
.to_string(),
1865-
BigRational(Gc::new(num::BigRational::new(
1865+
BigRational(Gc::new(num_rational::BigRational::new(
18661866
BigInt::from(1),
18671867
BigInt::from_str("18446744073709551616").unwrap()
18681868
)))
@@ -2014,7 +2014,7 @@ mod num_op_tests {
20142014
)
20152015
.is_err());
20162016
assert!(exact_integer_sqrt(
2017-
&num::BigRational::new(
2017+
&num_rational::BigRational::new(
20182018
BigInt::from_str("-10000000000000000000000000000000000001").unwrap(),
20192019
BigInt::from_str("2").unwrap()
20202020
)

crates/steel-core/src/primitives/strings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::rvals::{RestArgsIter, Result, SteelByteVector, SteelString, SteelVal}
55
use crate::steel_vm::builtin::BuiltInModule;
66
use crate::{stop, Vector};
77

8-
use num::{BigInt, Num};
8+
use num_bigint::BigInt;
9+
use num_traits::Num;
910
use steel_derive::{function, native};
1011

1112
/// Strings in Steel are immutable, fixed length arrays of characters. They are heap allocated, and

crates/steel-core/src/primitives/time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn current_milliseconds() -> SteelVal {
109109
let ms = n.as_millis();
110110
match isize::try_from(ms) {
111111
Ok(inner) => SteelVal::IntV(inner),
112-
_ => SteelVal::BigNum(Gc::new(num::BigInt::from(ms))),
112+
_ => SteelVal::BigNum(Gc::new(num_bigint::BigInt::from(ms))),
113113
}
114114
}
115115
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
@@ -128,7 +128,7 @@ fn current_seconds() -> SteelVal {
128128
let ms = n.as_secs();
129129
match isize::try_from(ms) {
130130
Ok(inner) => SteelVal::IntV(inner),
131-
_ => SteelVal::BigNum(Gc::new(num::BigInt::from(ms))),
131+
_ => SteelVal::BigNum(Gc::new(num_bigint::BigInt::from(ms))),
132132
}
133133
}
134134
Err(_) => panic!("SystemTime before UNIX EPOCH!"),

crates/steel-core/src/rvals.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ use futures_util::future::Shared;
7777
use futures_util::FutureExt;
7878

7979
use crate::values::lists::List;
80-
use num::{
81-
bigint::ToBigInt, BigInt, BigRational, FromPrimitive, Rational32, Signed, ToPrimitive, Zero,
82-
};
80+
use num_bigint::{BigInt, ToBigInt};
81+
use num_rational::{BigRational, Rational32};
82+
use num_traits::{FromPrimitive, Signed, ToPrimitive, Zero};
8383
use steel_parser::tokens::{IntLiteral, RealLiteral};
8484

8585
use self::cycles::{CycleDetector, IterativeDropHandler};
@@ -2117,7 +2117,7 @@ fn integer_float_equality(int: isize, float: f64) -> bool {
21172117
}
21182118
}
21192119

2120-
fn bignum_float_equality(bigint: &Gc<num::BigInt>, float: f64) -> bool {
2120+
fn bignum_float_equality(bigint: &Gc<BigInt>, float: f64) -> bool {
21212121
if float.fract() == 0.0 {
21222122
if let Some(promoted) = bigint.to_f64() {
21232123
promoted == float
@@ -2188,13 +2188,13 @@ impl PartialOrd for SteelVal {
21882188
// the common ground
21892189
#[cfg(target_pointer_width = "32")]
21902190
{
2191-
let x_rational = num::Rational32::new_raw(*x as i32, 1);
2191+
let x_rational = num_rational::Rational32::new_raw(*x as i32, 1);
21922192
x_rational.partial_cmp(y)
21932193
}
21942194
#[cfg(target_pointer_width = "64")]
21952195
{
2196-
let x_rational = num::Rational64::new_raw(*x as i64, 1);
2197-
x_rational.partial_cmp(&num::Rational64::new_raw(
2196+
let x_rational = num_rational::Rational64::new_raw(*x as i64, 1);
2197+
x_rational.partial_cmp(&num_rational::Rational64::new_raw(
21982198
*y.numer() as i64,
21992199
*y.denom() as i64,
22002200
))
@@ -2240,13 +2240,13 @@ impl PartialOrd for SteelVal {
22402240
// Same as before, but opposite direction
22412241
#[cfg(target_pointer_width = "32")]
22422242
{
2243-
let y_rational = num::Rational32::new_raw(*y as i32, 1);
2243+
let y_rational = num_rational::Rational32::new_raw(*y as i32, 1);
22442244
x.partial_cmp(&y_rational)
22452245
}
22462246
#[cfg(target_pointer_width = "64")]
22472247
{
2248-
let y_rational = num::Rational64::new_raw(*y as i64, 1);
2249-
num::Rational64::new_raw(*x.numer() as i64, *x.denom() as i64)
2248+
let y_rational = num_rational::Rational64::new_raw(*y as i64, 1);
2249+
num_rational::Rational64::new_raw(*x.numer() as i64, *x.denom() as i64)
22502250
.partial_cmp(&y_rational)
22512251
}
22522252
}

crates/steel-core/src/rvals/cycles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::gc::shared::{MutableContainer, ShareableMut};
22
use crate::steel_vm::{builtin::get_function_name, vm::Continuation, vm::ContinuationMark};
33
use crate::values::lists::Pair;
4-
use num::BigInt;
4+
use num_bigint::BigInt;
55
use std::{cell::Cell, collections::VecDeque};
66

77
use super::*;

0 commit comments

Comments
 (0)