Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ffi tests & fix ffi #2786

Draft
wants to merge 23 commits into
base: rebis-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
- { os: ubuntu-22.04, rust-version: nightly, target: 'wasm32-unknown-unknown', publish: true, args: '--no-default-features' , test-args: '--no-run --no-default-features', use_swap: true }
# Cargo.toml rust-version
- { os: ubuntu-22.04, rust-version: "1.77", target: 'x86_64-unknown-linux-gnu'}
# rust versions
- { os: ubuntu-22.04, rust-version: beta, target: 'x86_64-unknown-linux-gnu'}
- { os: ubuntu-22.04, rust-version: nightly, target: 'x86_64-unknown-linux-gnu', miri: true, components: "miri"}
defaults:
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ js-sys = "0.3"
ouroboros = "0.18"

[dev-dependencies]
current_platform = "0.2.0"
maplit = "1.0.2"
predicates-core = "1.0.8"
serial_test = "3.1.1"
Expand Down
22 changes: 7 additions & 15 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ mod tests {
_ => { unreachable!() }
);

let fixnum_b_cell = fixnum_as_cell!(Fixnum::build_with(1 << 54));
let fixnum_b_cell = fixnum_as_cell!(Fixnum::build_with_unchecked(1 << 54));

assert_eq!(fixnum_b_cell.get_tag(), HeapCellValueTag::Fixnum);

Expand All @@ -1121,36 +1121,28 @@ mod tests {
None => unreachable!(),
}

if Fixnum::build_with_checked(1 << 56).is_ok() {
unreachable!()
}
Fixnum::build_with_checked(1i64 << 56).unwrap_err();

if Fixnum::build_with_checked(i64::MAX).is_ok() {
unreachable!()
}
Fixnum::build_with_checked(i64::MAX).unwrap_err();

if Fixnum::build_with_checked(i64::MIN).is_ok() {
unreachable!()
}
Fixnum::build_with_checked(i64::MIN).unwrap_err();

match Fixnum::build_with_checked(-1) {
Ok(n) => assert_eq!(n.get_num(), -1),
_ => unreachable!(),
}

match Fixnum::build_with_checked((1 << 55) - 1) {
match Fixnum::build_with_checked((1i64 << 55) - 1) {
Ok(n) => assert_eq!(n.get_num(), (1 << 55) - 1),
_ => unreachable!(),
}

match Fixnum::build_with_checked(-(1 << 55)) {
match Fixnum::build_with_checked(-(1i64 << 55)) {
Ok(n) => assert_eq!(n.get_num(), -(1 << 55)),
_ => unreachable!(),
}

if Fixnum::build_with_checked(-(1 << 55) - 1).is_ok() {
unreachable!()
}
Fixnum::build_with_checked(-(1i64 << 55) - 1).unwrap_err();

match Fixnum::build_with_checked(-1) {
Ok(n) => assert_eq!(-n, Fixnum::build_with(1)),
Expand Down
11 changes: 6 additions & 5 deletions src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::machine::machine_errors::*;

use dashu::base::Abs;
use dashu::base::BitTest;
use dashu::integer::IBig;
use num_order::NumOrd;
use ordered_float::{Float, OrderedFloat};

Expand Down Expand Up @@ -305,9 +306,9 @@ impl<'a> ArithmeticEvaluator<'a> {
pub(crate) fn rnd_i(n: &'_ Number, arena: &mut Arena) -> Result<Number, EvalError> {
match n {
&Number::Integer(i) => {
let result = (&*i).try_into();
if let Ok(value) = result {
Ok(fixnum!(Number, value, arena))
let i: &IBig = &i;
if let Ok(value) = Fixnum::build_with_checked(i) {
Ok(Number::Fixnum(value))
} else {
Ok(*n)
}
Expand All @@ -333,8 +334,8 @@ pub(crate) fn rnd_i(n: &'_ Number, arena: &mut Arena) -> Result<Number, EvalErro
Number::Rational(ref r) => {
let floor = r.floor();

if let Ok(value) = (&floor).try_into() {
Ok(fixnum!(Number, value, arena))
if let Ok(value) = Fixnum::build_with_checked(&floor) {
Ok(Number::Fixnum(value))
} else {
Ok(Number::Integer(arena_alloc!(floor, arena)))
}
Expand Down
Loading
Loading