prepare for publishing to crates.io (#1335)
This commit is contained in:
507
Cargo.lock
generated
507
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
30
Cargo.toml
30
Cargo.toml
@@ -9,16 +9,9 @@ repository = "https://github.com/mthom/scryer-prolog"
|
||||
license = "BSD-3-Clause"
|
||||
keywords = ["prolog", "prolog-interpreter", "prolog-system"]
|
||||
categories = ["command-line-utilities"]
|
||||
build = "build.rs"
|
||||
build = "build/main.rs"
|
||||
rust-version = "1.57"
|
||||
|
||||
[workspace]
|
||||
members = ["crates/num-rug-adapter",
|
||||
"crates/static-string-indexing",
|
||||
"crates/instructions-template",
|
||||
"crates/to-syn-value",
|
||||
"crates/to-syn-value_derive"]
|
||||
|
||||
[features]
|
||||
num = ["num-rug-adapter"]
|
||||
# no default features to make num tests work
|
||||
@@ -28,9 +21,14 @@ default = ["rug"]
|
||||
|
||||
[build-dependencies]
|
||||
indexmap = "1.0.2"
|
||||
static-string-indexing = { path = "./crates/static-string-indexing" }
|
||||
instructions-template = { path = "./crates/instructions-template" }
|
||||
proc-macro2 = "*"
|
||||
proc-macro2 = "1.0.36"
|
||||
quote = "1.0.15"
|
||||
strum = "0.23"
|
||||
strum_macros = "0.23"
|
||||
syn = { version = "1.0.88", features = ['full', 'visit', 'extra-traits'] }
|
||||
to-syn-value = "0.1.0"
|
||||
to-syn-value_derive = "0.1.0"
|
||||
walkdir = "2"
|
||||
|
||||
[dependencies]
|
||||
cpu-time = "1.0.0"
|
||||
@@ -44,9 +42,9 @@ indexmap = "1.0.2"
|
||||
lazy_static = "1.4.0"
|
||||
lexical = "5.2.2"
|
||||
libc = "0.2.62"
|
||||
modular-bitfield = { git = "https://github.com/mthom/modular-bitfield" } # modular-bitfield = "0.11.2"
|
||||
modular-bitfield = "0.11.2"
|
||||
nix = "0.15.0"
|
||||
num-rug-adapter = { optional = true, path = "./crates/num-rug-adapter" }
|
||||
num-rug-adapter = { version = "0.1.6", optional = true }
|
||||
ordered-float = "2.1.1"
|
||||
phf = { version = "0.9", features = ["macros"] }
|
||||
ref_thread_local = "0.0.0"
|
||||
@@ -62,7 +60,7 @@ chrono = "0.4.11"
|
||||
select = "0.4.3"
|
||||
roxmltree = "0.11.0"
|
||||
base64 = "0.12.3"
|
||||
smallvec = "*"
|
||||
smallvec = "1.8.0"
|
||||
sodiumoxide = "0.2.6"
|
||||
static_assertions = "1.1.0"
|
||||
slice-deque = "0.3.0"
|
||||
@@ -72,5 +70,9 @@ assert_cmd = "1.0.3"
|
||||
predicates-core = "1.0.2"
|
||||
serial_test = "0.5.1"
|
||||
|
||||
[patch.crates-io]
|
||||
modular-bitfield = { git = "https://github.com/mthom/modular-bitfield" }
|
||||
num-rug-adapter = { git = "https://github.com/mthom/num-rug-adapter" }
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# Scryer Prolog
|
||||
|
||||
Scryer Prolog aims to become to ISO Prolog what GHC is to Haskell: an open
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
mod static_string_indexing;
|
||||
mod instructions_template;
|
||||
|
||||
use static_string_indexing::index_static_strings;
|
||||
use instructions_template::generate_instructions_rs;
|
||||
|
||||
129
crates/instructions-template/Cargo.lock
generated
129
crates/instructions-template/Cargo.lock
generated
@@ -1,129 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instructions-template"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "392a54546fda6b7cc663379d0e6ce8b324cf88aecc5a499838e1be9781bdce2e"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "to-syn-value"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"syn",
|
||||
"to-syn-value_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "to-syn-value_derive"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
@@ -1,14 +0,0 @@
|
||||
[package]
|
||||
name = "instructions-template"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
indexmap = "*"
|
||||
proc-macro2 = "*"
|
||||
quote = "*"
|
||||
strum = "0.23"
|
||||
strum_macros = "0.23"
|
||||
syn = { version = "*", features = ['full', 'visit', 'extra-traits'] }
|
||||
to-syn-value = { path = "../to-syn-value" }
|
||||
to-syn-value_derive = { path = "../to-syn-value_derive" }
|
||||
@@ -1,18 +0,0 @@
|
||||
[package]
|
||||
name = "num-rug-adapter"
|
||||
version = "0.1.5"
|
||||
authors = ["Marco A L Barbosa <malbarbo@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "An adapter to use num crate where rug is needed."
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/malbarbo/num-rug-adapter"
|
||||
keywords = ["mathematics", "numerics", "bignum"]
|
||||
categories = ["api-bindings", "science"]
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
num-bigint = "0.2"
|
||||
num-integer = "0.1.41"
|
||||
num-rational = "0.2"
|
||||
num-traits = "0.2"
|
||||
@@ -1,888 +0,0 @@
|
||||
use num_bigint::{BigInt, ParseBigIntError};
|
||||
use num_integer::Integer as _;
|
||||
use num_rational::BigRational;
|
||||
use num_traits::{FromPrimitive, Num, Signed, ToPrimitive};
|
||||
use num_traits::identities::One;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::ops::*;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Integer(BigInt);
|
||||
|
||||
impl Integer {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Integer(BigInt::default())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_str_radix(s: &str, radix: u32) -> Result<Self, ParseBigIntError> {
|
||||
BigInt::from_str_radix(s, radix).map(Integer)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_u8(&self) -> Option<u8> {
|
||||
self.0.to_u8()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_u32(&self) -> Option<u32> {
|
||||
self.0.to_u32()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_u64(&self) -> Option<u64> {
|
||||
self.0.to_u64()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_usize(&self) -> Option<usize> {
|
||||
self.0.to_usize()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_i32(&self) -> Option<i32> {
|
||||
self.0.to_i32()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_isize(&self) -> Option<isize> {
|
||||
self.0.to_isize()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_f64(&self) -> f64 {
|
||||
self.0.to_f64().unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn abs(&self) -> Self {
|
||||
Integer(self.0.abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn abs_ref(&self) -> Self {
|
||||
Integer(self.0.abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn div_rem(&self, other: Self) -> (Self, Self) {
|
||||
let (a, b) = num_integer::Integer::div_rem(&self.0, &other.0);
|
||||
(Integer(a), Integer(b))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn div_rem_ref(&self, other: &Self) -> (Self, Self) {
|
||||
let (a, b) = num_integer::Integer::div_rem(&self.0, &other.0);
|
||||
(Integer(a), Integer(b))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn div_rem_floor(&self, other: Self) -> (Self, Self) {
|
||||
let (a, b) = num_integer::Integer::div_mod_floor(&self.0, &other.0);
|
||||
(Integer(a), Integer(b))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn div_rem_floor_ref(&self, other: &Self) -> (Self, Self) {
|
||||
let (a, b) = num_integer::Integer::div_mod_floor(&self.0, &other.0);
|
||||
(Integer(a), Integer(b))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mod_u(&self, modulo: u32) -> u32 {
|
||||
(self.0.abs() % modulo).to_u32().unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_odd(&self) -> bool {
|
||||
num_integer::Integer::is_odd(&self.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_f64(v: f64) -> Option<Self> {
|
||||
BigInt::from_f64(v).map(Integer)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gcd_ref(&self, other: &Self) -> Self {
|
||||
Integer(num_integer::Integer::gcd(&self.0, &other.0))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gcd(&self, other: &Self) -> Self {
|
||||
Integer(num_integer::Integer::gcd(&self.0, &other.0))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn count_ones(&self) -> Option<u32> {
|
||||
Some(self.0.to_u32_digits().1.iter().map(|&d| d.count_ones()).sum())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Integer> for Integer {
|
||||
#[inline]
|
||||
fn from(s: &Integer) -> Self {
|
||||
s.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for Integer {
|
||||
#[inline]
|
||||
fn from(s: i32) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<isize> for Integer {
|
||||
#[inline]
|
||||
fn from(s: isize) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u8> for Integer {
|
||||
#[inline]
|
||||
fn from(s: u8) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Integer {
|
||||
#[inline]
|
||||
fn from(s: u32) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Integer {
|
||||
#[inline]
|
||||
fn from(s: u64) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for Integer {
|
||||
#[inline]
|
||||
fn from(s: usize) -> Self {
|
||||
Integer(BigInt::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0 * other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<u32> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, other: u32) -> Self::Output {
|
||||
Integer(self.0 * other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
fn mul(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0 * &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign<&Integer> for Integer {
|
||||
#[inline]
|
||||
fn mul_assign(&mut self, other: &Integer) {
|
||||
self.0 *= &other.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: Integer) -> Self::Output {
|
||||
Integer(&self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0 + &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<&Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: &Integer) -> Self::Output {
|
||||
Integer(&self.0 + &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign<i64> for Integer {
|
||||
#[inline]
|
||||
fn add_assign(&mut self, other: i64) {
|
||||
self.0 += other;
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign<&Integer> for Integer {
|
||||
#[inline]
|
||||
fn add_assign(&mut self, other: &Integer) {
|
||||
self.0 += &other.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl Div for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: Integer) -> Integer {
|
||||
Integer(self.0 / other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: &Integer) -> Integer {
|
||||
Integer(self.0 / &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: Integer) -> Integer {
|
||||
Integer(&self.0 / &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Shr<u32> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn shr(self, rhs: u32) -> Self::Output {
|
||||
Integer(self.0 >> rhs as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Shr<u32> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn shr(self, rhs: u32) -> Self::Output {
|
||||
Integer(&self.0 >> rhs as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl ShrAssign<u32> for Integer {
|
||||
#[inline]
|
||||
fn shr_assign(&mut self, rhs: u32) {
|
||||
self.0 >>= rhs as usize;
|
||||
}
|
||||
}
|
||||
|
||||
impl Shl<u32> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn shl(self, rhs: u32) -> Self::Output {
|
||||
Integer(self.0 << rhs as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Shl<u32> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn shl(self, rhs: u32) -> Self::Output {
|
||||
Integer(&self.0 << rhs as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Not for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn not(self) -> Self::Output {
|
||||
Integer(!self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Not for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn not(self) -> Self::Output {
|
||||
Integer(!&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0.mod_floor(&other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0.mod_floor(&other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem<&Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0.mod_floor(&other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0.mod_floor(&other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0 & &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0 & &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, other: Integer) -> Self::Output {
|
||||
Integer(&self.0 & other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, other: &Integer) -> Self::Output {
|
||||
Integer(&self.0 & &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0 | other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0 | &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, other: Integer) -> Self::Output {
|
||||
Integer(&self.0 | other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, other: &Integer) -> Self::Output {
|
||||
Integer(&self.0 | &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitXor for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitxor(self, other: Integer) -> Self::Output {
|
||||
Integer(self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitXor<&Integer> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitxor(self, other: &Integer) -> Self::Output {
|
||||
Integer(self.0 ^ &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitXor<Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitxor(self, other: Integer) -> Self::Output {
|
||||
Integer(&self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitXor<&Integer> for &Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn bitxor(self, other: &Integer) -> Self::Output {
|
||||
Integer(&self.0 ^ &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<i32> for Integer {
|
||||
#[inline]
|
||||
fn eq(&self, other: &i32) -> bool {
|
||||
self.0 == BigInt::from(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<i64> for Integer {
|
||||
#[inline]
|
||||
fn eq(&self, other: &i64) -> bool {
|
||||
self.0 == BigInt::from(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<isize> for Integer {
|
||||
#[inline]
|
||||
fn eq(&self, other: &isize) -> bool {
|
||||
self.0 == BigInt::from(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<usize> for Integer {
|
||||
#[inline]
|
||||
fn eq(&self, other: &usize) -> bool {
|
||||
self.0 == BigInt::from(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Integer> for isize {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Integer) -> bool {
|
||||
other.0 == BigInt::from(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<i32> for Integer {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &i32) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<i64> for Integer {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &i64) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<isize> for Integer {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &isize) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<usize> for Integer {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &usize) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Integer {
|
||||
type Err = <BigInt as FromStr>::Err;
|
||||
|
||||
#[inline]
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Integer(s.parse()?))
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
#[inline]
|
||||
fn neg(self) -> Self {
|
||||
Integer(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Integer {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
// Rational
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Rational(BigRational);
|
||||
|
||||
impl Rational {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Rational(BigRational::from(BigInt::default()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_f64(v: f64) -> Option<Self> {
|
||||
BigRational::from_f64(v).map(Rational)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_f64(&self) -> f64 {
|
||||
self.0.numer().to_f64().unwrap() / self.0.denom().to_f64().unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn numer(&self) -> &Integer {
|
||||
unsafe { ::std::mem::transmute(self.0.numer()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn denom(&self) -> &Integer {
|
||||
unsafe { ::std::mem::transmute(self.0.denom()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn abs(self) -> Self {
|
||||
Rational(self.0.abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn abs_ref(&self) -> Self {
|
||||
Rational(self.0.abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn fract_floor_ref(&self) -> &Self {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<isize> for Rational {
|
||||
#[inline]
|
||||
fn from(s: isize) -> Self {
|
||||
Rational(BigRational::new_raw(BigInt::from(s), One::one()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Integer> for Rational {
|
||||
#[inline]
|
||||
fn from(s: &Integer) -> Self {
|
||||
Rational::from(s.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Rational> for Rational {
|
||||
#[inline]
|
||||
fn from(s: &Rational) -> Self {
|
||||
s.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Integer> for Rational {
|
||||
#[inline]
|
||||
fn from(i: Integer) -> Self {
|
||||
Rational(BigRational::from(i.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: Rational) -> Self::Output {
|
||||
Rational(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<&Rational> for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: &Rational) -> Self::Output {
|
||||
Rational(self.0 + &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<i32> for Rational {
|
||||
#[inline]
|
||||
fn eq(&self, other: &i32) -> bool {
|
||||
self.0 == BigRational::from(BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<i64> for Rational {
|
||||
#[inline]
|
||||
fn eq(&self, other: &i64) -> bool {
|
||||
self.0 == BigRational::from(BigInt::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<isize> for Rational {
|
||||
#[inline]
|
||||
fn eq(&self, other: &isize) -> bool {
|
||||
self == &Rational::from(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Rational> for isize {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Rational) -> bool {
|
||||
other == &Rational::from(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<isize> for Rational {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &isize) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigRational::from(BigInt::from(*other)))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<i64> for Rational {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &i64) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigRational::from(BigInt::from(*other)))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd<i32> for Rational {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &i32) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&BigRational::from(BigInt::from(*other)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn neg(self) -> Self {
|
||||
Rational(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, other: Rational) -> Self::Output {
|
||||
Rational(self.0 * other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<&Rational> for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
fn mul(self, other: &Rational) -> Self::Output {
|
||||
Rational(self.0 * &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div for Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: Rational) -> Self::Output {
|
||||
Rational(self.0 / other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<&Rational> for &Rational {
|
||||
type Output = Rational;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: &Rational) -> Self::Output {
|
||||
Rational(&self.0 / &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Rational {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Assign<Src = Self> {
|
||||
fn assign(&mut self, src: Src);
|
||||
}
|
||||
|
||||
impl Assign<&Rational> for (&mut Rational, &mut Integer) {
|
||||
fn assign(&mut self, _src: &Rational) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod ops {
|
||||
use super::{Integer, Rational};
|
||||
|
||||
pub trait Pow<Rhs> {
|
||||
type Output;
|
||||
fn pow(self, rhs: Rhs) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Pow<u32> for Integer {
|
||||
type Output = Integer;
|
||||
|
||||
fn pow(self, rhs: u32) -> Self::Output {
|
||||
Integer(num_traits::Pow::pow(&self.0, rhs))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PowAssign<Rhs> {
|
||||
fn pow_assign(&mut self, rhs: Rhs);
|
||||
}
|
||||
|
||||
impl PowAssign<u32> for Integer {
|
||||
fn pow_assign(&mut self, rhs: u32) {
|
||||
// FIXME: make it efficient
|
||||
self.0 = num_traits::Pow::pow(&self.0, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NegAssign {
|
||||
fn neg_assign(&mut self);
|
||||
}
|
||||
|
||||
impl NegAssign for Integer {
|
||||
fn neg_assign(&mut self) {
|
||||
self.0 = -std::mem::replace(self, Integer::new()).0;
|
||||
}
|
||||
}
|
||||
|
||||
impl NegAssign for Rational {
|
||||
#[inline]
|
||||
fn neg_assign(&mut self) {
|
||||
self.0 = -std::mem::replace(self, Rational::new()).0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod rand {
|
||||
use super::Integer;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct RandState<'a>{
|
||||
_marker: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
impl<'a> RandState<'a> {
|
||||
pub fn new() -> Self {
|
||||
unsafe { libc::srand(libc::time(std::ptr::null_mut()) as _) };
|
||||
RandState { _marker: PhantomData }
|
||||
}
|
||||
|
||||
pub fn borrow_mut(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn bits(&mut self, bits: u32) -> u32 {
|
||||
assert!(bits <= 32);
|
||||
(unsafe { libc::rand() } as u32) & (u32::max_value() >> (32 - bits))
|
||||
}
|
||||
|
||||
pub fn seed(&mut self, seed: &Integer) {
|
||||
unsafe { libc::srand(seed.to_f64() as _)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::ops::NegAssign;
|
||||
|
||||
#[test]
|
||||
fn bits() {
|
||||
let mut rand = rand::RandState::new();
|
||||
for bits in 1..32 {
|
||||
for _ in 0..100 {
|
||||
let r = rand.bits(bits);
|
||||
let max = 1 << bits;
|
||||
assert!(max > r, "{} > {}", max, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neg_rational() {
|
||||
let mut x = Rational::from_f64(5.0).unwrap();
|
||||
let x_neg = Rational::from_f64(-5.0).unwrap();
|
||||
x.neg_assign();
|
||||
assert_eq!(x, x_neg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neg_integer() {
|
||||
let mut x = Integer::from(5);
|
||||
let x_neg = Integer::from(-5);
|
||||
x.neg_assign();
|
||||
assert_eq!(x, x_neg);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
[package]
|
||||
name = "static-string-indexing"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "*"
|
||||
syn = { version = "*", features = ['full', 'visit', 'extra-traits'] }
|
||||
indexmap = "*"
|
||||
walkdir = "2"
|
||||
quote = "*"
|
||||
@@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "to-syn-value"
|
||||
version = "0.1.0"
|
||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "*", features = ['full', 'visit', 'extra-traits'] }
|
||||
to-syn-value_derive = { path = "../to-syn-value_derive" }
|
||||
@@ -1,3 +0,0 @@
|
||||
pub trait ToDeriveInput {
|
||||
fn to_derive_input() -> syn::DeriveInput;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
[package]
|
||||
name = "to-syn-value_derive"
|
||||
version = "0.1.0"
|
||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "*"
|
||||
syn = { version = "*", features = ['full', 'visit', 'extra-traits'] }
|
||||
quote = "*"
|
||||
@@ -1,20 +0,0 @@
|
||||
use syn::*;
|
||||
use quote::*;
|
||||
|
||||
#[proc_macro_derive(ToDeriveInput)]
|
||||
pub fn derive_to_derive_input(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let derive_input = parse_macro_input!(input as DeriveInput);
|
||||
let ty_name = derive_input.ident.clone();
|
||||
|
||||
quote! {
|
||||
use to_syn_value::*;
|
||||
|
||||
impl ToDeriveInput for #ty_name {
|
||||
fn to_derive_input() -> syn::DeriveInput {
|
||||
syn::parse_quote! {
|
||||
#derive_input
|
||||
}
|
||||
}
|
||||
}
|
||||
}.into()
|
||||
}
|
||||
Reference in New Issue
Block a user