]> Repositorios git - scryer-prolog.git/commitdiff
fix {i,u}64 in ffi
authorBennet Bleßmann <[email protected]>
Wed, 22 Jan 2025 19:32:44 +0000 (20:32 +0100)
committerBennet Bleßmann <[email protected]>
Fri, 1 Aug 2025 16:37:48 +0000 (18:37 +0200)
src/machine/system_calls.rs
tests/scryer/ffi.rs

index 307ca648ded9ba39e18c932ddb18f945d8e41c89..b6191f292fd7622c926941beb043eff39a0c486f 100644 (file)
@@ -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)
index 9897bb7828f9c28b0f7f11321b46c1681a66b511..b8cad1f99164563aaac131d4a2caee50db612caa 100644 (file)
@@ -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
     );