fix {i,u}64 in ffi
This commit is contained in:
committed by
Bennet Bleßmann
parent
d2502b0520
commit
620459ea1e
@@ -5002,6 +5002,8 @@ impl Machine {
|
|||||||
#[cfg(feature = "ffi")]
|
#[cfg(feature = "ffi")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn foreign_call(&mut self) -> CallResult {
|
pub(crate) fn foreign_call(&mut self) -> CallResult {
|
||||||
|
use dashu::integer::IBig;
|
||||||
|
|
||||||
let function_name = self.deref_register(1);
|
let function_name = self.deref_register(1);
|
||||||
let args_reg = self.deref_register(2);
|
let args_reg = self.deref_register(2);
|
||||||
let return_value = self.deref_register(3);
|
let return_value = self.deref_register(3);
|
||||||
@@ -5051,12 +5053,18 @@ impl Machine {
|
|||||||
{
|
{
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
match result {
|
match result {
|
||||||
Value::Int(n) => self.machine_st.unify_fixnum(
|
Value::Int(n) => {
|
||||||
Fixnum::build_with_checked(n).unwrap_or_else(|_| {
|
if let Ok(fixnum) = Fixnum::build_with_checked(n) {
|
||||||
todo!("handle integer values that don't fit in fixnum")
|
self.machine_st.unify_fixnum(fixnum, return_value)
|
||||||
}),
|
} else {
|
||||||
return_value,
|
let bigint = IBig::from(n);
|
||||||
),
|
let bigint = arena_alloc!(
|
||||||
|
bigint.clone(),
|
||||||
|
&mut self.machine_st.arena
|
||||||
|
);
|
||||||
|
self.machine_st.unify_big_int(bigint, return_value)
|
||||||
|
}
|
||||||
|
}
|
||||||
Value::Float(n) => {
|
Value::Float(n) => {
|
||||||
let n = float_alloc!(n, self.machine_st.arena);
|
let n = float_alloc!(n, self.machine_st.arena);
|
||||||
self.machine_st.unify_f64(n, return_value)
|
self.machine_st.unify_f64(n, return_value)
|
||||||
|
|||||||
@@ -164,19 +164,15 @@ fn ffi_return_values() {
|
|||||||
std::env::set_var("ffi_return_values_LIB", dynlib_path);
|
std::env::set_var("ffi_return_values_LIB", dynlib_path);
|
||||||
|
|
||||||
let expected = format!(
|
let expected = format!(
|
||||||
"i8- {},u8-{},i16- {},u16-{},i32- {},u32-{},i64-{},u64- {},f32-{},f64-{}",
|
"i8- {},u8-{},i16- {},u16-{},i32- {},u32-{},i64- {},u64-{},f32-{},f64-{}",
|
||||||
-42,
|
-42,
|
||||||
73,
|
73,
|
||||||
-0xBEE,
|
-0xBEE,
|
||||||
0xC0DE,
|
0xC0DE,
|
||||||
-0xBEEFBEE,
|
-0xBEEFBEE,
|
||||||
0xC0DEB000u32,
|
0xC0DEB000u32,
|
||||||
// actual: 00010001 00000100 00010001 10100011 11110010 00010101 00000000
|
-0xBEEFBEE5C0DEB00i64,
|
||||||
// expected: 11110100 00010001 00000100 00010001 10100011 11110010 00010101 00000000
|
0xBEEFBEE5C0DEB00u64,
|
||||||
4789548415587584u64, // -0xBEEFBEE5C0DEB00i64,
|
|
||||||
// actual: 11111111 11101110 11111011 11101110 01011100 00001101 11101011 00000000
|
|
||||||
// expected: 1011 11101110 11111011 11101110 01011100 00001101 11101011 00000000
|
|
||||||
-4789548415587584i64, // 0xBEEFBEE5C0DEB00u64,
|
|
||||||
std::f32::consts::PI as f64,
|
std::f32::consts::PI as f64,
|
||||||
std::f64::consts::TAU
|
std::f64::consts::TAU
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user