#[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);
{
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)
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
);