From: Bennet Bleßmann Date: Wed, 22 Jan 2025 19:32:44 +0000 (+0100) Subject: fix {i,u}64 in ffi X-Git-Tag: v0.10.0~29^2~15 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=620459ea1e0570091699295399e8cb1db99001bb;p=scryer-prolog.git fix {i,u}64 in ffi --- diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 307ca648..b6191f29 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -5002,6 +5002,8 @@ impl Machine { #[cfg(feature = "ffi")] #[inline(always)] pub(crate) fn foreign_call(&mut self) -> CallResult { + use dashu::integer::IBig; + let function_name = self.deref_register(1); let args_reg = self.deref_register(2); let return_value = self.deref_register(3); @@ -5051,12 +5053,18 @@ impl Machine { { Ok(result) => { match result { - Value::Int(n) => self.machine_st.unify_fixnum( - Fixnum::build_with_checked(n).unwrap_or_else(|_| { - todo!("handle integer values that don't fit in fixnum") - }), - return_value, - ), + Value::Int(n) => { + if let Ok(fixnum) = Fixnum::build_with_checked(n) { + self.machine_st.unify_fixnum(fixnum, return_value) + } else { + 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) => { let n = float_alloc!(n, self.machine_st.arena); self.machine_st.unify_f64(n, return_value) diff --git a/tests/scryer/ffi.rs b/tests/scryer/ffi.rs index 9897bb78..b8cad1f9 100644 --- a/tests/scryer/ffi.rs +++ b/tests/scryer/ffi.rs @@ -164,19 +164,15 @@ fn ffi_return_values() { std::env::set_var("ffi_return_values_LIB", dynlib_path); let expected = format!( - "i8- {},u8-{},i16- {},u16-{},i32- {},u32-{},i64-{},u64- {},f32-{},f64-{}", + "i8- {},u8-{},i16- {},u16-{},i32- {},u32-{},i64- {},u64-{},f32-{},f64-{}", -42, 73, -0xBEE, 0xC0DE, -0xBEEFBEE, 0xC0DEB000u32, - // actual: 00010001 00000100 00010001 10100011 11110010 00010101 00000000 - // expected: 11110100 00010001 00000100 00010001 10100011 11110010 00010101 00000000 - 4789548415587584u64, // -0xBEEFBEE5C0DEB00i64, - // actual: 11111111 11101110 11111011 11101110 01011100 00001101 11101011 00000000 - // expected: 1011 11101110 11111011 11101110 01011100 00001101 11101011 00000000 - -4789548415587584i64, // 0xBEEFBEE5C0DEB00u64, + -0xBEEFBEE5C0DEB00i64, + 0xBEEFBEE5C0DEB00u64, std::f32::consts::PI as f64, std::f64::consts::TAU );