From 5d09449c95857bb7e37e1c3ed8c4ee6036f40d2f Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 4 Jul 2023 11:22:07 -0600 Subject: [PATCH 1/9] widen CharReader buffer (#1859) --- src/parser/char_reader.rs | 8 ++++---- src/parser/lexer.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/parser/char_reader.rs b/src/parser/char_reader.rs index a2a7c2e2..8a74db37 100644 --- a/src/parser/char_reader.rs +++ b/src/parser/char_reader.rs @@ -20,7 +20,7 @@ use std::str; pub struct CharReader { inner: R, - buf: SmallVec<[u8;4]>, + buf: SmallVec<[u8;32]>, pos: usize, } @@ -121,7 +121,7 @@ impl CharReader { self.buf.clear(); - let mut word = [0u8;4]; + let mut word = [0u8; std::mem::size_of::()]; let nread = self.inner.read(&mut word)?; self.buf.extend_from_slice(&word[..nread]); @@ -234,10 +234,10 @@ impl CharRead for CharReader { #[inline(always)] fn put_back_char(&mut self, c: char) { let src_len = self.buf.len() - self.pos; - debug_assert!(src_len <= 4); + debug_assert!(src_len <= self.buf.capacity()); let c_len = c.len_utf8(); - let mut shifted_slice = [0u8; 4]; + let mut shifted_slice = [0u8; 32]; shifted_slice[0..src_len].copy_from_slice(&self.buf[self.pos .. self.buf.len()]); diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 7f5d73ed..3fbddc1d 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -988,6 +988,17 @@ impl<'a, R: CharRead> Lexer<'a, R> { return Ok(Token::End); } + Ok(c) if c == '\\' => { + self.skip_char(c); + + if self.lookahead_char().ok() == Some('n') { + self.skip_char('n'); + return Ok(Token::End); + } else { + self.return_char(c); + self.return_char('.'); + } + } Err(ParserError::UnexpectedEOF) => { return Ok(Token::End); } From cf345d817499caf989f41f4c1374b546199e09dc Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 17 Jul 2023 20:40:41 +0530 Subject: [PATCH 2/9] wip dashu move --- Cargo.lock | 104 ++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/arena.rs | 28 ++++++-- src/arithmetic.rs | 11 ++-- src/forms.rs | 14 ++-- src/heap_print.rs | 16 ++--- src/machine/arithmetic_ops.rs | 8 +-- src/machine/disjuncts.rs | 4 +- src/machine/heap.rs | 2 +- src/machine/loader.rs | 2 +- src/machine/machine_state.rs | 2 +- src/machine/machine_state_impl.rs | 2 +- src/machine/mod.rs | 2 +- src/machine/system_calls.rs | 2 +- src/parser/ast.rs | 2 +- src/parser/lexer.rs | 2 +- src/parser/mod.rs | 1 + 17 files changed, 165 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51a8fa49..46731842 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,6 +313,79 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dashu" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51a1b5a00793e3ac2239993ef582603764bcb333a4d04c2a0944639a7e916c85" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "dashu-macros", + "dashu-ratio", +] + +[[package]] +name = "dashu-base" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2585452b8ecf7c874045dba02a7914b7e5b2e3cdd5e152573413aa290197aa" + +[[package]] +name = "dashu-float" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a168f338914fab603c31a371207c8b3245ab5ff5e9a0f4fd64a9b5f8a972d1f" +dependencies = [ + "dashu-base", + "dashu-int", + "num-traits", + "rand", + "static_assertions", +] + +[[package]] +name = "dashu-int" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a1009a3ce0c4c64e977c5e7dd8c475278750e145cbb8956d1e28832f557975" +dependencies = [ + "cfg-if", + "dashu-base", + "num-order", + "num-traits", + "rand", + "static_assertions", +] + +[[package]] +name = "dashu-macros" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fc2425b6724a7d5bfc8e57044e231803b5fc3a7283d6efbff34bfab6ebe014" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "dashu-ratio", + "proc-macro2", + "quote", +] + +[[package]] +name = "dashu-ratio" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b57c839e72af6be14e5c55630ffc9429c9970aed48f7db449b2399467336b4" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "num-traits", + "rand", +] + [[package]] name = "derive_deref" version = "1.1.1" @@ -1153,6 +1226,36 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-modular" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a5fe11d4135c3bcdf3a95b18b194afa9608a5f6ff034f5d857bc9a27fb0119" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-order" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e81e321057a0370997b13e6638bba6bd7f6f426e1f8e9a2562490a28eb23e1bc" +dependencies = [ + "num-modular", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1669,6 +1772,7 @@ dependencies = [ "crossterm", "crrl", "ctrlc", + "dashu", "derive_deref", "dirs-next", "divrem", diff --git a/Cargo.toml b/Cargo.toml index 99218c71..ac9c98b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,7 @@ futures = "0.3" libffi = "3.1.0" libloading = "0.7" derive_deref = "1.1.1" +dashu = "0.3.0" [dev-dependencies] assert_cmd = "1.0.3" diff --git a/src/arena.rs b/src/arena.rs index b055c8db..fbbcd72a 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -6,7 +6,7 @@ use crate::raw_block::*; use crate::read::*; use ordered_float::OrderedFloat; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use std::alloc; use std::fmt; @@ -252,6 +252,26 @@ impl TypedArenaPtr { self.0.as_ptr() } + #[inline] + pub fn to_i64(&self) -> Option { + self.to_i64() + } + + #[inline] + pub fn to_u32(&self) -> Option { + self.to_u32() + } + + #[inline] + pub fn to_usize(&self) -> Option { + self.to_usize() + } + + #[inline] + pub fn to_isize(&self) -> Option { + self.to_isize() + } + #[inline] pub fn header_ptr(&self) -> *const ArenaHeader { let mut ptr = self.as_ptr() as *const u8 as usize; @@ -788,7 +808,7 @@ mod tests { use crate::machine::partial_string::*; use ordered_float::OrderedFloat; - use crate::parser::rug::{Integer, Rational}; + use crate::parser::dashu::{Integer, Rational}; #[test] fn float_ptr_cast() { @@ -889,7 +909,7 @@ mod tests { // rational - let big_rat = 2 * Rational::from(1u64 << 63); + let big_rat = Rational::from(2) * Rational::from(1u64 << 63); let big_rat_ptr: TypedArenaPtr = arena_alloc!(big_rat, &mut wam.machine_st.arena); assert!(!big_rat_ptr.as_ptr().is_null()); @@ -915,7 +935,7 @@ mod tests { (HeapCellValueTag::Cons, cons_ptr) => { match_untyped_arena_ptr!(cons_ptr, (ArenaHeaderTag::Rational, n) => { - assert_eq!(&*n, &(2 * Rational::from(1u64 << 63))); + assert_eq!(&*n, &(Rational::from(2) * Rational::from(1u64 << 63))); } _ => unreachable!() ) diff --git a/src/arithmetic.rs b/src/arithmetic.rs index 7f15a7f1..1a3bdf48 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -10,7 +10,8 @@ use crate::types::*; use crate::parser::ast::*; use crate::parser::rug::ops::PowAssign; -use crate::parser::rug::{Assign, Integer, Rational}; +use crate::parser::rug::{Assign}; +use crate::parser::dashu::{Integer, Rational}; use crate::machine::machine_errors::*; @@ -377,12 +378,12 @@ pub(crate) fn rnd_i<'a>(n: &'a Number, arena: &mut Arena) -> Number { if I64_MIN_TO_F <= f && f <= I64_MAX_TO_F { fixnum!(Number, f.into_inner() as i64, arena) } else { - Number::Integer(arena_alloc!(Integer::from_f64(f.into_inner()).unwrap(), arena)) + Number::Integer(arena_alloc!(Integer::from(f.into_inner()).unwrap(), arena)) } } &Number::Rational(ref r) => { let r_ref = r.fract_floor_ref(); - let (mut fract, mut floor) = (Rational::new(), Integer::new()); + let (mut fract, mut floor) = (Rational::from(0), Integer::from(0)); (&mut fract, &mut floor).assign(r_ref); if let Some(floor) = floor.to_i64() { @@ -405,9 +406,9 @@ impl From for Integer { pub(crate) fn rnd_f(n: &Number) -> f64 { match n { &Number::Fixnum(n) => n.get_num() as f64, - &Number::Integer(ref n) => n.to_f64(), + &Number::Integer(ref n) => n.to_f64().value(), &Number::Float(OrderedFloat(f)) => f, - &Number::Rational(ref r) => r.to_f64(), + &Number::Rational(ref r) => r.to_f64().value(), } } diff --git a/src/forms.rs b/src/forms.rs index 627fb4b2..6cc5315f 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -8,7 +8,7 @@ use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; use crate::parser::ast::*; use crate::parser::parser::CompositeOpDesc; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use crate::types::*; use fxhash::FxBuildHasher; @@ -765,9 +765,9 @@ impl Number { pub(crate) fn is_positive(&self) -> bool { match self { &Number::Fixnum(n) => n.get_num() > 0, - &Number::Integer(ref n) => &**n > &0, + &Number::Integer(ref n) => &**n > &Integer::from(0), &Number::Float(f) => f.is_sign_positive(), - &Number::Rational(ref r) => &**r > &0, + &Number::Rational(ref r) => &**r > &Rational::from(0), } } @@ -775,9 +775,9 @@ impl Number { pub(crate) fn is_negative(&self) -> bool { match self { &Number::Fixnum(n) => n.get_num() < 0, - &Number::Integer(ref n) => &**n < &0, + &Number::Integer(ref n) => &**n < &Integer::from(0), &Number::Float(OrderedFloat(f)) => f.is_sign_negative() && OrderedFloat(f) != -0f64, - &Number::Rational(ref r) => &**r < &0, + &Number::Rational(ref r) => &**r < &Rational::from(0), } } @@ -785,9 +785,9 @@ impl Number { pub(crate) fn is_zero(&self) -> bool { match self { &Number::Fixnum(n) => n.get_num() == 0, - &Number::Integer(ref n) => &**n == &0, + &Number::Integer(ref n) => &**n == &Integer::from(0), &Number::Float(f) => f == OrderedFloat(0f64) || f == OrderedFloat(-0f64), - &Number::Rational(ref r) => &**r == &0, + &Number::Rational(ref r) => &**r == &Rational::from(0), } } diff --git a/src/heap_print.rs b/src/heap_print.rs index 4e7781b7..cf2c293c 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -1,7 +1,7 @@ use crate::arena::*; use crate::atom_table::*; use crate::parser::ast::*; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use crate::{ alpha_numeric_char, capital_letter_char, cut_char, decimal_digit_char, graphic_token_char, is_fx, is_infix, is_postfix, is_prefix, is_xf, is_xfx, is_xfy, is_yfx, semicolon_char, @@ -196,7 +196,7 @@ impl NumberFocus { fn is_negative(&self) -> bool { match self { NumberFocus::Unfocused(n) => n.is_negative(), - NumberFocus::Denominator(r) | NumberFocus::Numerator(r) => **r < 0, + NumberFocus::Denominator(r) | NumberFocus::Numerator(r) => **r < Rational::from(0), } } } @@ -400,8 +400,8 @@ fn negated_op_needs_bracketing( && iter.leftmost_leaf_has_property(op_dir, |addr| match Number::try_from(addr) { Ok(Number::Fixnum(n)) => n.get_num() > 0, Ok(Number::Float(f)) => f > OrderedFloat(0f64), - Ok(Number::Integer(n)) => &*n > &0, - Ok(Number::Rational(n)) => &*n > &0, + Ok(Number::Integer(n)) => &*n > &Integer::from(0), + Ok(Number::Rational(n)) => &*n > &Rational::from(0), _ => false, }) } else { @@ -514,7 +514,7 @@ pub(crate) fn numbervar(offset: &Integer, addr: HeapCellValue) -> Option let j = n.div_rem_floor(Integer::from(26)); let j = <(Integer, Integer)>::from(j).0; - if j == 0 { + if j == Integer::from(0) { CHAR_CODES[i].to_string() } else { format!("{}{}", CHAR_CODES[i], j) @@ -530,7 +530,7 @@ pub(crate) fn numbervar(offset: &Integer, addr: HeapCellValue) -> Option } } Ok(Number::Integer(n)) => { - if &*n >= &0 { + if &*n >= &Integer::from(0) { Some(numbervar(Integer::from(offset + &*n))) } else { None @@ -1307,10 +1307,10 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { if self.numbervars && arity == 1 && name == atom!("$VAR") { !self.iter.immediate_leaf_has_property(|addr| { match Number::try_from(addr) { - Ok(Number::Integer(n)) => &*n >= &0, + Ok(Number::Integer(n)) => &*n >= &Integer::from(0), Ok(Number::Fixnum(n)) => n.get_num() >= 0, Ok(Number::Float(f)) => f >= OrderedFloat(0f64), - Ok(Number::Rational(r)) => &*r >= &0, + Ok(Number::Rational(r)) => &*r >= &Integer::from(0), _ => false, } }) && needs_bracketing(op_desc, op) diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index f5aa982f..0c948bf6 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -8,7 +8,7 @@ use crate::heap_iter::*; use crate::machine::machine_errors::*; use crate::machine::machine_state::*; use crate::parser::ast::*; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use crate::types::*; use crate::fixnum; @@ -338,7 +338,7 @@ pub(crate) fn int_pow(n1: Number, n2: Number, arena: &mut Arena) -> Result { let n1_i = n1.get_num(); - if !(n1_i == 1 || n1_i == 0 || n1_i == -1) && &*n2 < &0 { + if !(n1_i == 1 || n1_i == 0 || n1_i == -1) && &*n2 < &Integer::from(0) { let n = Number::Fixnum(n1); Err(numerical_type_error(ValidType::Float, n, stub_gen)) } else { @@ -349,7 +349,7 @@ pub(crate) fn int_pow(n1: Number, n2: Number, arena: &mut Arena) -> Result { let n2_i = n2.get_num(); - if !(&*n1 == &1 || &*n1 == &0 || &*n1 == &-1) && n2_i < 0 { + if !(&*n1 == &Integer::from(1) || &*n1 == &Integer::from(0) || &*n1 == &Integer::from(-1)) && n2_i < 0 { let n = Number::Integer(n1); Err(numerical_type_error(ValidType::Float, n, stub_gen)) } else { @@ -358,7 +358,7 @@ pub(crate) fn int_pow(n1: Number, n2: Number, arena: &mut Arena) -> Result { - if !(&*n1 == &1 || &*n1 == &0 || &*n1 == &-1) && &*n2 < &0 { + if !(&*n1 == &Integer::from(1) || &*n1 == &Integer::from(0) || &*n1 == &Integer::from(-1)) && &*n2 < &Integer::from(0) { let n = Number::Integer(n1); Err(numerical_type_error(ValidType::Float, n, stub_gen)) } else { diff --git a/src/machine/disjuncts.rs b/src/machine/disjuncts.rs index f2a66851..33d24a06 100644 --- a/src/machine/disjuncts.rs +++ b/src/machine/disjuncts.rs @@ -6,7 +6,7 @@ use crate::machine::loader::*; use crate::machine::machine_errors::CompilationError; use crate::machine::preprocessor::*; use crate::parser::ast::*; -use crate::parser::rug::Rational; +use crate::parser::dashu::{Rational, Integer}; use crate::variable_records::*; use indexmap::{IndexMap, IndexSet}; @@ -236,7 +236,7 @@ fn merge_branch_seq>(branches: Iter) -> Branch branch_info.chunks.extend(branch.chunks.drain(..)); } - branch_info.branch_num.delta *= 2; + branch_info.branch_num.delta = branch_info.branch_num.delta * Integer::from(2); branch_info.branch_num.branch_num -= &branch_info.branch_num.delta; branch_info diff --git a/src/machine/heap.rs b/src/machine/heap.rs index 59e63009..1cdfeb74 100644 --- a/src/machine/heap.rs +++ b/src/machine/heap.rs @@ -6,7 +6,7 @@ use crate::machine::partial_string::*; use crate::parser::ast::*; use crate::types::*; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use std::convert::TryFrom; diff --git a/src/machine/loader.rs b/src/machine/loader.rs index 5a309197..d5b3a15f 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -1644,7 +1644,7 @@ impl Machine { .store(self.machine_st.deref(self.machine_st.registers[3])); let arity = match Number::try_from(arity) { - Ok(Number::Integer(n)) if &*n >= &0 && &*n <= &MAX_ARITY => Ok(n.to_usize().unwrap()), + Ok(Number::Integer(n)) if &*n >= &Integer::from(0) && &*n <= &Integer::from(MAX_ARITY) => Ok(n.to_usize().unwrap()), Ok(Number::Fixnum(n)) if n.get_num() >= 0 && n.get_num() <= MAX_ARITY as i64 => { Ok(usize::try_from(n.get_num()).unwrap()) } diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index 78b1a7f5..768e4492 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -14,7 +14,7 @@ use crate::machine::streams::*; use crate::parser::ast::*; use crate::types::*; -use crate::parser::rug::Integer; +use crate::parser::dashu::Integer; use indexmap::IndexMap; diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index b4dc3fea..f0f27fcd 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -13,7 +13,7 @@ use crate::machine::partial_string::*; use crate::machine::stack::*; use crate::machine::unify::*; use crate::parser::ast::*; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use indexmap::IndexSet; diff --git a/src/machine/mod.rs b/src/machine/mod.rs index ddf64d34..a212b9ea 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -41,7 +41,7 @@ use crate::machine::machine_state::*; use crate::machine::stack::*; use crate::machine::streams::*; use crate::parser::ast::*; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use crate::types::*; use indexmap::IndexMap; diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 4c9c0f2f..84f86cec 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -24,7 +24,7 @@ use crate::machine::preprocessor::to_op_decl; use crate::machine::stack::*; use crate::machine::streams::*; use crate::parser::char_reader::*; -use crate::parser::rug::Integer; +use crate::parser::dashu::Integer; use crate::parser::rug::rand::RandState; use crate::read::*; use crate::types::*; diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 272d5b7e..73f5b4e5 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -12,7 +12,7 @@ use std::ops::{Deref, Neg}; use std::rc::Rc; use std::vec::Vec; -use crate::parser::rug::{Integer, Rational}; +use crate::parser::dashu::{Integer, Rational}; use fxhash::FxBuildHasher; use indexmap::IndexMap; diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 3fbddc1d..92b78050 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -5,7 +5,7 @@ use crate::atom_table::*; pub use crate::machine::machine_state::*; use crate::parser::ast::*; use crate::parser::char_reader::*; -use crate::parser::rug::Integer; +use crate::parser::dashu::Integer; use std::convert::TryFrom; use std::fmt; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index fa7b8859..dccaa49b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3,6 +3,7 @@ pub use num_rug_adapter as rug; #[cfg(feature = "rug")] pub use rug; +pub use dashu; // #[macro_use] // extern crate lazy_static; From b4e7000eb20212b4065cfb47da73a28949cb1c78 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Fri, 21 Jul 2023 14:21:32 +0530 Subject: [PATCH 3/9] Fixed missing functionality in dashu with their methods still has some issue with move --- Cargo.lock | 241 ++++++++++++++++++++++++++---- Cargo.toml | 10 +- src/arithmetic.rs | 33 ++-- src/heap_print.rs | 10 +- src/machine/arithmetic_ops.rs | 43 +++--- src/machine/disjuncts.rs | 3 +- src/machine/dispatch.rs | 4 +- src/machine/machine_state_impl.rs | 4 +- src/machine/mod.rs | 2 +- src/machine/system_calls.rs | 54 +++++-- src/parser/mod.rs | 1 + src/parser/parser.rs | 20 ++- 12 files changed, 328 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46731842..a5faf337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "bit-set" version = "0.5.3" @@ -316,8 +322,6 @@ dependencies = [ [[package]] name = "dashu" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51a1b5a00793e3ac2239993ef582603764bcb333a4d04c2a0944639a7e916c85" dependencies = [ "dashu-base", "dashu-float", @@ -329,41 +333,33 @@ dependencies = [ [[package]] name = "dashu-base" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2585452b8ecf7c874045dba02a7914b7e5b2e3cdd5e152573413aa290197aa" [[package]] name = "dashu-float" version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a168f338914fab603c31a371207c8b3245ab5ff5e9a0f4fd64a9b5f8a972d1f" dependencies = [ "dashu-base", "dashu-int", + "num-order", "num-traits", - "rand", "static_assertions", ] [[package]] name = "dashu-int" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a1009a3ce0c4c64e977c5e7dd8c475278750e145cbb8956d1e28832f557975" dependencies = [ "cfg-if", "dashu-base", + "num-modular 0.6.0", "num-order", "num-traits", - "rand", "static_assertions", ] [[package]] name = "dashu-macros" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6fc2425b6724a7d5bfc8e57044e231803b5fc3a7283d6efbff34bfab6ebe014" dependencies = [ "dashu-base", "dashu-float", @@ -376,14 +372,12 @@ dependencies = [ [[package]] name = "dashu-ratio" version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4b57c839e72af6be14e5c55630ffc9429c9970aed48f7db449b2399467336b4" dependencies = [ "dashu-base", "dashu-float", "dashu-int", + "num-order", "num-traits", - "rand", ] [[package]] @@ -471,6 +465,15 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -549,6 +552,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + [[package]] name = "funty" version = "2.0.0" @@ -718,8 +730,6 @@ dependencies = [ [[package]] name = "gmp-mpfr-sys" version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13eabc29d16e4a621b495e3919c71ebb7caaed24380955671e7d417370fea95d" dependencies = [ "libc", "windows-sys 0.42.0", @@ -821,6 +831,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ef12f041acdd397010e5fb6433270c147d3b8b2d0a840cd7fff8e531dca5c8" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body 1.0.0-rc.2", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -845,7 +878,7 @@ dependencies = [ "futures-util", "h2", "http", - "http-body", + "http-body 0.4.5", "httparse", "httpdate", "itoa", @@ -893,6 +926,16 @@ dependencies = [ "cc", ] +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -923,6 +966,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + [[package]] name = "itertools" version = "0.10.5" @@ -994,8 +1043,6 @@ checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" [[package]] name = "libffi" version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce826c243048e3d5cec441799724de52e2d42f820468431fc3fceee2341871e2" dependencies = [ "libc", "libffi-sys", @@ -1004,8 +1051,6 @@ dependencies = [ [[package]] name = "libffi-sys" version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36115160c57e8529781b4183c2bb51fdc1f6d6d1ed345591d84be7703befb3c" dependencies = [ "cc", ] @@ -1107,6 +1152,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "mio" version = "0.7.14" @@ -1246,13 +1297,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-modular" +version = "0.6.0" + [[package]] name = "num-order" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e81e321057a0370997b13e6638bba6bd7f6f426e1f8e9a2562490a28eb23e1bc" dependencies = [ - "num-modular", + "num-modular 0.5.1", "num-traits", ] @@ -1388,6 +1443,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + [[package]] name = "phf" version = "0.9.0" @@ -1638,6 +1699,43 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +[[package]] +name = "reqwest" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +dependencies = [ + "base64 0.21.2", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body 0.4.5", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -1676,8 +1774,6 @@ dependencies = [ [[package]] name = "rug" version = "1.19.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555e8b44763d034526db899c88cd56ccc4486cd38b444c8aa0e79d4e70ae5a34" dependencies = [ "az", "gmp-mpfr-sys", @@ -1763,10 +1859,11 @@ name = "scryer-prolog" version = "0.9.1" dependencies = [ "assert_cmd", - "base64", + "base64 0.12.3", "bit-set", "bitvec", "blake2 0.8.1", + "bytes", "chrono", "cpu-time", "crossterm", @@ -1780,6 +1877,7 @@ dependencies = [ "fxhash", "git-version", "hostname", + "http-body-util", "hyper", "hyper-tls", "indexmap", @@ -1795,7 +1893,9 @@ dependencies = [ "predicates-core", "proc-macro2", "quote", + "rand", "ref_thread_local", + "reqwest", "ring", "ripemd160", "roxmltree", @@ -1853,9 +1953,32 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.164" +version = "1.0.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "3b88756493a5bd5e5395d53baa70b194b05764ab85b59e43e4b8f4e1192fa9b1" + +[[package]] +name = "serde_json" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] [[package]] name = "serial_test" @@ -2147,6 +2270,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "to-syn-value" version = "0.1.0" @@ -2260,12 +2398,27 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.10.1" @@ -2284,6 +2437,17 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "utf-8" version = "0.7.6" @@ -2373,6 +2537,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -2575,6 +2751,15 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index ac9c98b6..8a50c342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ ctrlc = "3.2.2" ordered-float = "2.6.0" phf = { version = "0.9", features = ["macros"] } ref_thread_local = "0.0.0" -rug = { version = "1.15.0", optional = true } +rug = { path = "../rug", optional = true } rustyline = "9.0.0" ring = "0.16.13" ripemd160 = "0.8.0" @@ -65,10 +65,14 @@ hyper = { version = "0.14", features = ["full"] } hyper-tls = "0.5.0" tokio = { version = "1.24.2", features = ["full"] } futures = "0.3" -libffi = "3.1.0" libloading = "0.7" derive_deref = "1.1.1" -dashu = "0.3.0" +http-body-util = "0.1.0-rc.2" +bytes = "1" +reqwest = { version = "0.11.18", features = ["blocking"] } +dashu = { path = "../dashu" } +libffi = { path = "../libffi-rs/libffi-rs" } +rand = "0.8.5" [dev-dependencies] assert_cmd = "1.0.3" diff --git a/src/arithmetic.rs b/src/arithmetic.rs index 1a3bdf48..cfdc5b08 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -9,12 +9,11 @@ use crate::targets::QueryInstruction; use crate::types::*; use crate::parser::ast::*; -use crate::parser::rug::ops::PowAssign; -use crate::parser::rug::{Assign}; use crate::parser::dashu::{Integer, Rational}; use crate::machine::machine_errors::*; +use dashu::base::Abs; use ordered_float::*; use std::cell::Cell; @@ -378,13 +377,11 @@ pub(crate) fn rnd_i<'a>(n: &'a Number, arena: &mut Arena) -> Number { if I64_MIN_TO_F <= f && f <= I64_MAX_TO_F { fixnum!(Number, f.into_inner() as i64, arena) } else { - Number::Integer(arena_alloc!(Integer::from(f.into_inner()).unwrap(), arena)) + Number::Integer(arena_alloc!(Integer::from(f.0 as i64), arena)) } } &Number::Rational(ref r) => { - let r_ref = r.fract_floor_ref(); - let (mut fract, mut floor) = (Rational::from(0), Integer::from(0)); - (&mut fract, &mut floor).assign(r_ref); + let (mut fract, mut floor) = (r.fract(), r.floor()); if let Some(floor) = floor.to_i64() { fixnum!(Number, floor, arena) @@ -439,12 +436,12 @@ pub(crate) fn float_fn_to_f(n: i64) -> Result { #[inline] pub(crate) fn float_i_to_f(n: &Integer) -> Result { - classify_float(n.to_f64()) + classify_float(n.to_f64().value()) } #[inline] pub(crate) fn float_r_to_f(r: &Rational) -> Result { - classify_float(r.to_f64()) + classify_float(r.to_f64().value()) } #[inline] @@ -543,8 +540,8 @@ impl PartialEq for Number { (&Number::Fixnum(n1), &Number::Float(n2)) => OrderedFloat(n1.get_num() as f64).eq(&n2), (&Number::Float(n1), &Number::Fixnum(n2)) => n1.eq(&OrderedFloat(n2.get_num() as f64)), (&Number::Integer(ref n1), &Number::Integer(ref n2)) => n1.eq(n2), - (&Number::Integer(ref n1), Number::Float(n2)) => OrderedFloat(n1.to_f64()).eq(n2), - (&Number::Float(n1), &Number::Integer(ref n2)) => n1.eq(&OrderedFloat(n2.to_f64())), + (&Number::Integer(ref n1), Number::Float(n2)) => OrderedFloat(n1.to_f64().value()).eq(n2), + (&Number::Float(n1), &Number::Integer(ref n2)) => n1.eq(&OrderedFloat(n2.to_f64().value())), (&Number::Integer(ref n1), &Number::Rational(ref n2)) => { #[cfg(feature = "num")] { @@ -565,8 +562,8 @@ impl PartialEq for Number { &**n1 == &**n2 } } - (&Number::Rational(ref n1), &Number::Float(n2)) => OrderedFloat(n1.to_f64()).eq(&n2), - (&Number::Float(n1), &Number::Rational(ref n2)) => n1.eq(&OrderedFloat(n2.to_f64())), + (&Number::Rational(ref n1), &Number::Float(n2)) => OrderedFloat(n1.to_f64().value()).eq(&n2), + (&Number::Float(n1), &Number::Rational(ref n2)) => n1.eq(&OrderedFloat(n2.to_f64().value())), (&Number::Float(f1), &Number::Float(f2)) => f1.eq(&f2), (&Number::Rational(ref r1), &Number::Rational(ref r2)) => r1.eq(&r2), } @@ -634,8 +631,8 @@ impl Ord for Number { (&Number::Fixnum(n1), &Number::Float(n2)) => OrderedFloat(n1.get_num() as f64).cmp(&n2), (&Number::Float(n1), &Number::Fixnum(n2)) => n1.cmp(&OrderedFloat(n2.get_num() as f64)), (&Number::Integer(n1), &Number::Integer(n2)) => (*n1).cmp(&*n2), - (&Number::Integer(n1), Number::Float(n2)) => OrderedFloat(n1.to_f64()).cmp(n2), - (&Number::Float(n1), &Number::Integer(ref n2)) => n1.cmp(&OrderedFloat(n2.to_f64())), + (&Number::Integer(n1), Number::Float(n2)) => OrderedFloat(n1.to_f64().value()).cmp(n2), + (&Number::Float(n1), &Number::Integer(ref n2)) => n1.cmp(&OrderedFloat(n2.to_f64().value())), (&Number::Integer(n1), &Number::Rational(n2)) => { #[cfg(feature = "num")] { @@ -656,8 +653,8 @@ impl Ord for Number { (&*n1).partial_cmp(&*n2).unwrap_or(Ordering::Less) } } - (&Number::Rational(n1), &Number::Float(n2)) => OrderedFloat(n1.to_f64()).cmp(&n2), - (&Number::Float(n1), &Number::Rational(n2)) => n1.cmp(&OrderedFloat(n2.to_f64())), + (&Number::Rational(n1), &Number::Float(n2)) => OrderedFloat(n1.to_f64().value()).cmp(&n2), + (&Number::Float(n1), &Number::Rational(n2)) => n1.cmp(&OrderedFloat(n2.to_f64().value())), (&Number::Float(f1), &Number::Float(f2)) => f1.cmp(&f2), (&Number::Rational(r1), &Number::Rational(r2)) => (*r1).cmp(&*r2), } @@ -698,7 +695,7 @@ impl TryFrom for Number { // Computes n ^ power. Ignores the sign of power. pub(crate) fn binary_pow(mut n: Integer, power: &Integer) -> Integer { - let mut power = Integer::from(power.abs_ref()); + let mut power = Integer::from(power.abs()); if power == 0 { return Integer::from(1); @@ -711,7 +708,7 @@ pub(crate) fn binary_pow(mut n: Integer, power: &Integer) -> Integer { oddand *= &n; } - n.pow_assign(2); + n = n.pow(2); power >>= 1; } diff --git a/src/heap_print.rs b/src/heap_print.rs index cf2c293c..783b7f01 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -18,6 +18,8 @@ use crate::machine::stack::*; use crate::machine::streams::*; use crate::types::*; +use dashu::base::DivRem; +use dashu::base::DivRemEuclid; use ordered_float::OrderedFloat; use indexmap::IndexMap; @@ -510,8 +512,8 @@ pub(crate) fn numbervar(offset: &Integer, addr: HeapCellValue) -> Option 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ]; - let i = n.mod_u(26) as usize; - let j = n.div_rem_floor(Integer::from(26)); + let i = n.div_rem_euclid(Integer::from(26)).1.to_f32().value() as usize; + let j = n.div_rem(Integer::from(26)); let j = <(Integer, Integer)>::from(j).0; if j == Integer::from(0) { @@ -969,14 +971,14 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { } }, NumberFocus::Denominator(r) => { - let output_str = format!("{}", r.denom()); + let output_str = format!("{}", r.denominator()); push_space_if_amb!(self, &output_str, { append_str!(self, &output_str); }); } NumberFocus::Numerator(r) => { - let output_str = format!("{}", r.numer()); + let output_str = format!("{}", r.numerator()); push_space_if_amb!(self, &output_str, { append_str!(self, &output_str); diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index 0c948bf6..153ca0c3 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -1,3 +1,6 @@ +use dashu::base::Abs; +use dashu::base::Gcd; +use dashu::integer::IBig; use divrem::*; use crate::arena::*; @@ -159,7 +162,7 @@ pub(crate) fn add(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Integer::from(&*n1) + &*n2, arena)) // add_i + Ok(Number::arena_from(&*n1 + &*n2, arena)) // add_i } (Number::Integer(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Integer(n1)) => { @@ -167,7 +170,7 @@ pub(crate) fn add(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(&*n1) + &*n2, arena)) + Ok(Number::arena_from(&*n1 + &*n2, arena)) } (Number::Rational(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Rational(n1)) => { @@ -177,7 +180,7 @@ pub(crate) fn add(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(&*r1) + &*r2, arena)) + Ok(Number::arena_from(&*r1 + &*r2, arena)) } } } @@ -191,9 +194,9 @@ pub(crate) fn neg(n: Number, arena: &mut Arena) -> Number { Number::arena_from(-Integer::from(n.get_num()), arena) } } - Number::Integer(n) => Number::arena_from(-Integer::from(&*n), arena), + Number::Integer(n) => Number::arena_from(-Integer::from(*n.clone()), arena), Number::Float(OrderedFloat(f)) => Number::Float(OrderedFloat(-f)), - Number::Rational(r) => Number::arena_from(-Rational::from(&*r), arena), + Number::Rational(r) => Number::arena_from(-Rational::from(*r), arena), } } @@ -203,12 +206,13 @@ pub(crate) fn abs(n: Number, arena: &mut Arena) -> Number { if let Some(n) = n.get_num().checked_abs() { fixnum!(Number, n, arena) } else { - Number::arena_from(Integer::from(n.get_num()).abs(), arena) + let arena_int = Integer::from(n.get_num()); + Number::arena_from(arena_int.abs(), arena) } } - Number::Integer(n) => Number::arena_from(Integer::from(n.abs_ref()), arena), + Number::Integer(n) => Number::arena_from(Integer::from(n.abs()), arena), Number::Float(f) => Number::Float(f.abs()), - Number::Rational(r) => Number::arena_from(Rational::from(r.abs_ref()), arena), + Number::Rational(r) => Number::arena_from(Rational::from(r.abs()), arena), } } @@ -247,7 +251,7 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Integer::from(&*n1) * &*n2, arena)) // mul_i + Ok(Number::arena_from(Integer::from(*n1) * &*n2, arena)) // mul_i } (Number::Integer(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Integer(n1)) => { @@ -255,7 +259,7 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(&*n1) * &*n2, arena)) + Ok(Number::arena_from(Rational::from(*n1) * &*n2, arena)) } (Number::Rational(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Rational(n1)) => { @@ -265,7 +269,7 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(&*r1) * &*r2, arena)) + Ok(Number::arena_from(Rational::from(*r1) * &*r2, arena)) } } } @@ -521,7 +525,7 @@ pub fn rational_from_number( match n { Number::Fixnum(n) => Ok(arena_alloc!(Rational::from(n.get_num()), arena)), Number::Rational(r) => Ok(r), - Number::Float(OrderedFloat(f)) => match Rational::from_f64(f) { + Number::Float(OrderedFloat(f)) => match Rational::simplest_from_f64(f) { Some(r) => Ok(arena_alloc!(r, arena)), None => Err(Box::new(move |machine_st| { let instantiation_error = machine_st.instantiation_error(); @@ -530,7 +534,7 @@ pub fn rational_from_number( machine_st.error_form(instantiation_error, stub) })), }, - Number::Integer(n) => Ok(arena_alloc!(Rational::from(&*n), arena)), + Number::Integer(n) => Ok(arena_alloc!(Rational::from(*n), arena)), } } @@ -590,7 +594,7 @@ pub(crate) fn idiv(n1: Number, n2: Number, arena: &mut Arena) -> Result::from(n1.div_rem_ref(&*n2)).0, + <(Integer, Integer)>::from(n1.div_rem_floor_ref(&*n2)).0, arena, )) } @@ -696,7 +700,7 @@ pub(crate) fn shl(n1: Number, n2: Number, arena: &mut Arena) -> Result Ok(Number::arena_from(n1 << n2, arena)), + Some(n2) => Ok(Number::arena_from(n1.to_u64().unwrap() << n2, arena)), _ => { Ok(Number::arena_from(n1 << usize::max_value(), arena)) } @@ -709,7 +713,7 @@ pub(crate) fn shl(n1: Number, n2: Number, arena: &mut Arena) -> Result match n2.to_u32() { - Some(n2) => Ok(Number::arena_from(Integer::from(&*n1 << n2), arena)), + Some(n2) => Ok(Number::arena_from(Integer::from(n1.to_u64().unwrap() << n2), arena)), _ => { Ok(Number::arena_from(Integer::from(&*n1 << usize::max_value()),arena)) } @@ -926,18 +930,19 @@ pub(crate) fn gcd(n1: Number, n2: Number, arena: &mut Arena) -> Result { let n1 = Integer::from(n1.get_num()); - Ok(Number::arena_from(Integer::from(n2.gcd_ref(&n1)), arena)) + Ok(Number::arena_from(Integer::from(n2.gcd(&n1)), arena)) } (Number::Integer(n1), Number::Integer(n2)) => { - Ok(Number::arena_from(Integer::from(n1.gcd_ref(&n2)), arena)) + Ok(Number::arena_from(Integer::from(n1.gcd(&Integer::from(n2.to_isize().unwrap()))) as IBig, arena)) } (Number::Float(f), _) | (_, Number::Float(f)) => { let n = Number::Float(f); diff --git a/src/machine/disjuncts.rs b/src/machine/disjuncts.rs index 33d24a06..17eaaa47 100644 --- a/src/machine/disjuncts.rs +++ b/src/machine/disjuncts.rs @@ -6,9 +6,10 @@ use crate::machine::loader::*; use crate::machine::machine_errors::CompilationError; use crate::machine::preprocessor::*; use crate::parser::ast::*; -use crate::parser::dashu::{Rational, Integer}; +use crate::parser::dashu::Rational; use crate::variable_records::*; +use dashu::Integer; use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 8029bb70..b1f71422 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -2540,7 +2540,7 @@ impl Machine { self.machine_st.p += 1; } Ok(Number::Rational(n)) => { - if n.denom() == &1 { + if n.denominator().is_one() { self.machine_st.p += 1; } else { self.machine_st.backtrack(); @@ -2559,7 +2559,7 @@ impl Machine { self.machine_st.p = self.machine_st.cp; } Ok(Number::Rational(n)) => { - if n.denom() == &1 { + if n.denominator().is_one() { self.machine_st.p = self.machine_st.cp; } else { self.machine_st.backtrack(); diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index f0f27fcd..30f2c57e 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -1387,7 +1387,7 @@ impl MachineState { Ok(Number::Float(_)) => { return type_error(arity); } - Ok(Number::Rational(n)) if n.denom() != &1 => { + Ok(Number::Rational(n)) if !n.denominator().is_one() => { return type_error(arity); } Ok(n) if n > MAX_ARITY => { @@ -1400,7 +1400,7 @@ impl MachineState { let err = self.domain_error(DomainErrorType::NotLessThanZero, n); return Err(self.error_form(err, stub_gen())); } - Ok(Number::Rational(n)) => n.numer().to_i64().unwrap(), + Ok(Number::Rational(n)) => n.numerator().to_i64().unwrap(), Ok(Number::Fixnum(n)) => n.get_num(), Ok(Number::Integer(n)) => n.to_i64().unwrap(), Err(_) => { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index a212b9ea..fb9cdf0e 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -905,4 +905,4 @@ impl Machine { } } } -} +} \ No newline at end of file diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 84f86cec..8f2523a7 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -1,6 +1,7 @@ use crate::parser::ast::*; use crate::parser::parser::*; +use dashu::integer::UBig; use lazy_static::lazy_static; use crate::arena::*; @@ -28,6 +29,8 @@ use crate::parser::dashu::Integer; use crate::parser::rug::rand::RandState; use crate::read::*; use crate::types::*; +use rand::{Rng, SeedableRng}; +use rand::rngs::StdRng; use ordered_float::OrderedFloat; @@ -36,10 +39,12 @@ use indexmap::IndexSet; use ref_thread_local::{RefThreadLocal, ref_thread_local}; +use std::borrow::BorrowMut; use std::cell::Cell; use std::cmp::Ordering; use std::collections::BTreeSet; -use std::convert::{TryFrom, Infallible}; +use std::convert::Infallible; +use std::convert::TryFrom; use std::env; use std::ffi::CString; use std::fs; @@ -2727,7 +2732,7 @@ impl Machine { // n has already been confirmed as an integer, and // internally, Rational is assumed reduced, so its denominator // must be 1. - r.numer().to_string() + r.numerator().to_string() } _ => { unreachable!() @@ -2756,7 +2761,7 @@ impl Machine { // n has already been confirmed as an integer, and // internally, Rational is assumed reduced, so its // denominator must be 1. - r.numer().to_string() + r.numerator().to_string() } _ => { unreachable!() @@ -4103,10 +4108,25 @@ impl Machine { } #[inline(always)] - pub(crate) fn maybe(&mut self) { + pub(crate) fn maybe(&mut self) { + fn generate_random_bits(num_bits: usize) -> u64 { + let mut rng = rand::thread_rng(); + let rand = rng.borrow_mut(); + let mut random_bits: u64 = 0; + + for _ in 0..num_bits { + random_bits <<= 1; + + if rand.gen_bool(0.5) { + random_bits |= 1; + } + } + + random_bits + } + let result = { - let mut rand = RANDOM_STATE.borrow_mut(); - rand.bits(1) == 0 + generate_random_bits(1) == 0 }; self.machine_st.fail = result; @@ -5189,7 +5209,7 @@ impl Machine { // n has already been confirmed as an integer, and // internally, Rational is assumed reduced, so its // denominator must be 1. - r.numer().to_i32().unwrap() + r.numerator().to_i32().unwrap() } _ => { unreachable!() @@ -5804,12 +5824,20 @@ impl Machine { #[inline(always)] pub(crate) fn set_seed(&mut self) { let seed = self.deref_register(1); - let mut rand = RANDOM_STATE.borrow_mut(); + match Number::try_from(seed) { - Ok(Number::Fixnum(n)) => rand.seed(&Integer::from(n)), - Ok(Number::Integer(n)) => rand.seed(&*n), - Ok(Number::Rational(n)) if n.denom() == &1 => rand.seed(n.numer()), + Ok(Number::Fixnum(n)) => { + let _: StdRng = SeedableRng::seed_from_u64(Integer::from(n).to_u64().unwrap()); + }, + Ok(Number::Integer(n)) => { + let _: StdRng = SeedableRng::seed_from_u64(n.to_u64().unwrap()); + }, + Ok(Number::Rational(n)) => { + if n.denominator() == &UBig::from(1 as u32) { + let _: StdRng = SeedableRng::seed_from_u64(n.numerator().to_u64().unwrap()); + } + }, _ => { self.machine_st.fail = true; } @@ -5823,7 +5851,7 @@ impl Machine { let time = match Number::try_from(time) { Ok(Number::Float(n)) => n.into_inner(), Ok(Number::Fixnum(n)) => n.get_num() as f64, - Ok(Number::Integer(n)) => n.to_f64(), + Ok(Number::Integer(n)) => n.to_f64().value(), _ => { unreachable!() } @@ -7469,7 +7497,7 @@ impl Machine { Number::Fixnum(Fixnum::build_with(n.get_num().count_ones() as i64)) } Ok(Number::Integer(n)) => { - Number::arena_from(n.count_ones().unwrap(), &mut self.machine_st.arena) + Number::arena_from(n.count_ones(), &mut self.machine_st.arena) } _ => { unreachable!() diff --git a/src/parser/mod.rs b/src/parser/mod.rs index dccaa49b..e7d0cec0 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3,6 +3,7 @@ pub use num_rug_adapter as rug; #[cfg(feature = "rug")] pub use rug; + pub use dashu; // #[macro_use] diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 5bb600da..20f53e5b 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,13 +1,16 @@ +use dashu::Integer; +use dashu::Rational; + use crate::arena::*; use crate::atom_table::*; use crate::parser::ast::*; use crate::parser::char_reader::*; use crate::parser::lexer::*; -use crate::parser::rug::ops::NegAssign; use std::cell::Cell; use std::mem; +use std::ops::Neg; #[derive(Debug, Clone, Copy, PartialEq)] enum TokenType { @@ -955,9 +958,14 @@ impl<'a, R: CharRead> Parser<'a, R> { } fn shift_token(&mut self, token: Token, op_dir: &CompositeOpDir) -> Result<(), ParserError> { - fn negate_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { - (&mut t).neg_assign(); - t + fn negate_int_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { + let mut data = t.neg(); + TypedArenaPtr::new(&mut data) + } + + fn negate_rat_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { + let mut data = t.neg(); + TypedArenaPtr::new(&mut data) } match token { @@ -965,10 +973,10 @@ impl<'a, R: CharRead> Parser<'a, R> { self.negate_number(n, |n| -n, |n, _| Literal::Fixnum(n)) } Token::Literal(Literal::Integer(n)) => { - self.negate_number(n, negate_rc, |n, _| Literal::Integer(n)) + self.negate_number(n, negate_int_rc, |n, _| Literal::Integer(n)) } Token::Literal(Literal::Rational(n)) => { - self.negate_number(n, negate_rc, |r, _| Literal::Rational(r)) + self.negate_number(n, negate_rat_rc, |r, _| Literal::Rational(r)) } Token::Literal(Literal::Float(n)) => self.negate_number( **n.as_ptr(), From b1963864d2d66f9245e90d6efd2af4d7a0ab3e50 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 21 Jul 2023 17:07:40 +0200 Subject: [PATCH 4/9] Explicitly dereference pointer to avoid calling neg() on reference --- src/parser/parser.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 20f53e5b..5d637e02 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -959,12 +959,14 @@ impl<'a, R: CharRead> Parser<'a, R> { fn shift_token(&mut self, token: Token, op_dir: &CompositeOpDir) -> Result<(), ParserError> { fn negate_int_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { - let mut data = t.neg(); + let i: Integer = (*t).clone(); + let mut data = i.neg(); TypedArenaPtr::new(&mut data) } - fn negate_rat_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { - let mut data = t.neg(); + fn negate_rat_rc(t: TypedArenaPtr) -> TypedArenaPtr { + let r: Rational = (*t).clone(); + let mut data = r.neg(); TypedArenaPtr::new(&mut data) } From c89217903aff4aab72a8f2a5d7293685f73aab53 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 24 Jul 2023 10:12:14 +0530 Subject: [PATCH 5/9] fix all the move errors --- src/heap_print.rs | 5 ++++- src/machine/arithmetic_ops.rs | 41 ++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/heap_print.rs b/src/heap_print.rs index 783b7f01..45fb9bf6 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -23,6 +23,7 @@ use dashu::base::DivRemEuclid; use ordered_float::OrderedFloat; use indexmap::IndexMap; +use tokio::io::Interest; use std::cell::Cell; use std::convert::TryFrom; @@ -512,8 +513,10 @@ pub(crate) fn numbervar(offset: &Integer, addr: HeapCellValue) -> Option 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ]; + let n_clone: Integer = n.clone(); + let i = n.div_rem_euclid(Integer::from(26)).1.to_f32().value() as usize; - let j = n.div_rem(Integer::from(26)); + let j = n_clone.div_rem(Integer::from(26)); let j = <(Integer, Integer)>::from(j).0; if j == Integer::from(0) { diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index 153ca0c3..1859d1d7 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -194,9 +194,16 @@ pub(crate) fn neg(n: Number, arena: &mut Arena) -> Number { Number::arena_from(-Integer::from(n.get_num()), arena) } } - Number::Integer(n) => Number::arena_from(-Integer::from(*n.clone()), arena), + + Number::Integer(n) => { + let n_clone: Integer = (*n).clone(); + Number::arena_from(-Integer::from(n_clone), arena) + }, Number::Float(OrderedFloat(f)) => Number::Float(OrderedFloat(-f)), - Number::Rational(r) => Number::arena_from(-Rational::from(*r), arena), + Number::Rational(r) => { + let r_clone: Rational = (*r).clone(); + Number::arena_from(-Rational::from(r_clone), arena) + }, } } @@ -210,9 +217,15 @@ pub(crate) fn abs(n: Number, arena: &mut Arena) -> Number { Number::arena_from(arena_int.abs(), arena) } } - Number::Integer(n) => Number::arena_from(Integer::from(n.abs()), arena), + Number::Integer(n) => { + let n_clone: Integer = (*n).clone(); + Number::arena_from(Integer::from(n_clone.abs()), arena) + }, Number::Float(f) => Number::Float(f.abs()), - Number::Rational(r) => Number::arena_from(Rational::from(r.abs()), arena), + Number::Rational(r) => { + let r_clone: Rational = (*r).clone(); + Number::arena_from(Rational::from(r_clone.abs()), arena) + }, } } @@ -251,7 +264,8 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Integer::from(*n1) * &*n2, arena)) // mul_i + let n1_clone: Integer = (*n1).clone(); + Ok(Number::arena_from(Integer::from(n1_clone) * &*n2, arena)) // mul_i } (Number::Integer(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Integer(n1)) => { @@ -259,7 +273,8 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(*n1) * &*n2, arena)) + let n1_clone: Integer = (*n1).clone(); + Ok(Number::arena_from(Rational::from(n1_clone) * &*n2, arena)) } (Number::Rational(n1), Number::Float(OrderedFloat(n2))) | (Number::Float(OrderedFloat(n2)), Number::Rational(n1)) => { @@ -269,7 +284,8 @@ pub(crate) fn mul(lhs: Number, rhs: Number, arena: &mut Arena) -> Result { - Ok(Number::arena_from(Rational::from(*r1) * &*r2, arena)) + let r1_clone: Rational = (*r1).clone(); + Ok(Number::arena_from(Rational::from(r1_clone) * &*r2, arena)) } } } @@ -534,7 +550,10 @@ pub fn rational_from_number( machine_st.error_form(instantiation_error, stub) })), }, - Number::Integer(n) => Ok(arena_alloc!(Rational::from(*n), arena)), + Number::Integer(n) => { + let n_clone: Integer = (*n).clone(); + Ok(arena_alloc!(Rational::from(n_clone), arena)) + }, } } @@ -939,10 +958,12 @@ pub(crate) fn gcd(n1: Number, n2: Number, arena: &mut Arena) -> Result { let n1 = Integer::from(n1.get_num()); - Ok(Number::arena_from(Integer::from(n2.gcd(&n1)), arena)) + let n2_clone: Integer = (*n2).clone(); + Ok(Number::arena_from(Integer::from(n2_clone.gcd(&n1)), arena)) } (Number::Integer(n1), Number::Integer(n2)) => { - Ok(Number::arena_from(Integer::from(n1.gcd(&Integer::from(n2.to_isize().unwrap()))) as IBig, arena)) + let n1_clone: Integer = (*n1).clone(); + Ok(Number::arena_from(Integer::from(n1_clone.gcd(&Integer::from(n2.to_isize().unwrap()))) as IBig, arena)) } (Number::Float(f), _) | (_, Number::Float(f)) => { let n = Number::Float(f); From 0e17d6acd7c075ecd7195eaa65825dfa00e76e97 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 24 Jul 2023 10:12:22 +0530 Subject: [PATCH 6/9] remove rug completely --- Cargo.lock | 24 ------------------------ Cargo.toml | 2 -- src/machine/system_calls.rs | 5 ----- src/parser/mod.rs | 6 ------ 4 files changed, 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5faf337..ec3941ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,12 +43,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "az" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" - [[package]] name = "base64" version = "0.12.3" @@ -727,14 +721,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "gmp-mpfr-sys" -version = "1.5.3" -dependencies = [ - "libc", - "windows-sys 0.42.0", -] - [[package]] name = "h2" version = "0.3.19" @@ -1771,15 +1757,6 @@ dependencies = [ "xmlparser", ] -[[package]] -name = "rug" -version = "1.19.2" -dependencies = [ - "az", - "gmp-mpfr-sys", - "libc", -] - [[package]] name = "rustix" version = "0.37.20" @@ -1899,7 +1876,6 @@ dependencies = [ "ring", "ripemd160", "roxmltree", - "rug", "rustyline", "ryu", "select", diff --git a/Cargo.toml b/Cargo.toml index 8a50c342..76b0aa62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ build = "build/main.rs" rust-version = "1.63" [features] -default = ["rug"] [build-dependencies] indexmap = "1.0.2" @@ -45,7 +44,6 @@ ctrlc = "3.2.2" ordered-float = "2.6.0" phf = { version = "0.9", features = ["macros"] } ref_thread_local = "0.0.0" -rug = { path = "../rug", optional = true } rustyline = "9.0.0" ring = "0.16.13" ripemd160 = "0.8.0" diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 8f2523a7..7ee4c311 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -26,7 +26,6 @@ use crate::machine::stack::*; use crate::machine::streams::*; use crate::parser::char_reader::*; use crate::parser::dashu::Integer; -use crate::parser::rug::rand::RandState; use crate::read::*; use crate::types::*; use rand::{Rng, SeedableRng}; @@ -93,10 +92,6 @@ use hyper_tls::HttpsConnector; use tokio::sync::Mutex; use tokio::sync::mpsc::channel; -ref_thread_local! { - pub(crate) static managed RANDOM_STATE: RandState<'static> = RandState::new(); -} - pub(crate) fn get_key() -> KeyEvent { let key; enable_raw_mode().expect("failed to enable raw mode"); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index e7d0cec0..ef6a8e0a 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,9 +1,3 @@ -#[cfg(feature = "num-rug-adapter")] -pub use num_rug_adapter as rug; - -#[cfg(feature = "rug")] -pub use rug; - pub use dashu; // #[macro_use] From 1dcc1ca5244fba27f8c86e81f2d3e7e280077c12 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 24 Jul 2023 12:19:41 +0530 Subject: [PATCH 7/9] Fixed stackoverflow error --- src/arena.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/arena.rs b/src/arena.rs index fbbcd72a..3d321c5a 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -252,26 +252,6 @@ impl TypedArenaPtr { self.0.as_ptr() } - #[inline] - pub fn to_i64(&self) -> Option { - self.to_i64() - } - - #[inline] - pub fn to_u32(&self) -> Option { - self.to_u32() - } - - #[inline] - pub fn to_usize(&self) -> Option { - self.to_usize() - } - - #[inline] - pub fn to_isize(&self) -> Option { - self.to_isize() - } - #[inline] pub fn header_ptr(&self) -> *const ArenaHeader { let mut ptr = self.as_ptr() as *const u8 as usize; From 7248425a7631f4d7edc35237a38a79f451943738 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 24 Jul 2023 12:41:56 +0530 Subject: [PATCH 8/9] Fixed warnings --- src/arithmetic.rs | 2 +- src/heap_print.rs | 1 - src/machine/system_calls.rs | 2 +- src/parser/ast.rs | 2 +- src/parser/parser.rs | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/arithmetic.rs b/src/arithmetic.rs index cfdc5b08..b48f43aa 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -381,7 +381,7 @@ pub(crate) fn rnd_i<'a>(n: &'a Number, arena: &mut Arena) -> Number { } } &Number::Rational(ref r) => { - let (mut fract, mut floor) = (r.fract(), r.floor()); + let (_, floor) = (r.fract(), r.floor()); if let Some(floor) = floor.to_i64() { fixnum!(Number, floor, arena) diff --git a/src/heap_print.rs b/src/heap_print.rs index 45fb9bf6..8d185e5f 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -23,7 +23,6 @@ use dashu::base::DivRemEuclid; use ordered_float::OrderedFloat; use indexmap::IndexMap; -use tokio::io::Interest; use std::cell::Cell; use std::convert::TryFrom; diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 7ee4c311..fb54d361 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -36,7 +36,7 @@ use ordered_float::OrderedFloat; use fxhash::{FxBuildHasher, FxHasher}; use indexmap::IndexSet; -use ref_thread_local::{RefThreadLocal, ref_thread_local}; +pub(crate) use ref_thread_local::RefThreadLocal; use std::borrow::BorrowMut; use std::cell::Cell; diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 73f5b4e5..6846aa72 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -7,7 +7,7 @@ use crate::types::HeapCellValueTag; use std::cell::{Cell, Ref, RefCell, RefMut}; use std::fmt; use std::hash::{Hash, Hasher}; -use std::io::{Error as IOError}; +use std::io::Error as IOError; use std::ops::{Deref, Neg}; use std::rc::Rc; use std::vec::Vec; diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 5d637e02..f427f18a 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -958,7 +958,7 @@ impl<'a, R: CharRead> Parser<'a, R> { } fn shift_token(&mut self, token: Token, op_dir: &CompositeOpDir) -> Result<(), ParserError> { - fn negate_int_rc(mut t: TypedArenaPtr) -> TypedArenaPtr { + fn negate_int_rc(t: TypedArenaPtr) -> TypedArenaPtr { let i: Integer = (*t).clone(); let mut data = i.neg(); TypedArenaPtr::new(&mut data) From 40b6890c5402fc79a10136c23024a42e11af3c66 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 24 Jul 2023 19:11:41 +0530 Subject: [PATCH 9/9] updated cargo to use git --- Cargo.lock | 9 +++++++++ Cargo.toml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec3941ae..66246593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,6 +316,7 @@ dependencies = [ [[package]] name = "dashu" version = "0.3.1" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" dependencies = [ "dashu-base", "dashu-float", @@ -327,10 +328,12 @@ dependencies = [ [[package]] name = "dashu-base" version = "0.3.1" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" [[package]] name = "dashu-float" version = "0.3.2" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" dependencies = [ "dashu-base", "dashu-int", @@ -342,6 +345,7 @@ dependencies = [ [[package]] name = "dashu-int" version = "0.3.1" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" dependencies = [ "cfg-if", "dashu-base", @@ -354,6 +358,7 @@ dependencies = [ [[package]] name = "dashu-macros" version = "0.3.1" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" dependencies = [ "dashu-base", "dashu-float", @@ -366,6 +371,7 @@ dependencies = [ [[package]] name = "dashu-ratio" version = "0.3.2" +source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" dependencies = [ "dashu-base", "dashu-float", @@ -1029,6 +1035,7 @@ checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" [[package]] name = "libffi" version = "3.2.0" +source = "git+https://github.com/coasys/libffi-rs.git?branch=windows-space#f6e9e50efde0aa4e940dd6f709a59bb426875362" dependencies = [ "libc", "libffi-sys", @@ -1037,6 +1044,7 @@ dependencies = [ [[package]] name = "libffi-sys" version = "2.3.0" +source = "git+https://github.com/coasys/libffi-rs.git?branch=windows-space#f6e9e50efde0aa4e940dd6f709a59bb426875362" dependencies = [ "cc", ] @@ -1286,6 +1294,7 @@ dependencies = [ [[package]] name = "num-modular" version = "0.6.0" +source = "git+https://github.com/coasys/num-modular.git#87d6dc30600207445e07c2cc84e0a47ff58f0aca" [[package]] name = "num-order" diff --git a/Cargo.toml b/Cargo.toml index 76b0aa62..58d13d0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,8 +68,8 @@ derive_deref = "1.1.1" http-body-util = "0.1.0-rc.2" bytes = "1" reqwest = { version = "0.11.18", features = ["blocking"] } -dashu = { path = "../dashu" } -libffi = { path = "../libffi-rs/libffi-rs" } +dashu = { git = "https://github.com/coasys/dashu.git" } +libffi = { git = "https://github.com/coasys/libffi-rs.git", branch = "windows-space" } rand = "0.8.5" [dev-dependencies]