From 73df96244dca8b12fb9d02f5047ee55a40ed20ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Adri=C3=A1n=20Arroyo=20Calle?= Date: Wed, 1 Mar 2023 22:10:26 +0100 Subject: [PATCH] Fill more cases --- src/ffi.rs | 2 ++ src/machine/system_calls.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index afc52339..a48ed62e 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -306,6 +306,7 @@ impl ForeignFunctionTable { Ok(Value::Int(i64::try_from(*n).map_err(|_| FFIError::ValueDontFit)?)) }, libffi::raw::FFI_TYPE_SINT64 => call_and_return!(i64), + libffi::raw::FFI_TYPE_POINTER => call_and_return!(*mut c_void), libffi::raw::FFI_TYPE_FLOAT => { let mut n: Box = Box::new(0.0); libffi::raw::ffi_call( @@ -380,6 +381,7 @@ impl ForeignFunctionTable { field_ptr = field_ptr.add(std::mem::size_of::()); }, libffi::raw::FFI_TYPE_SINT64 => read_and_push_int!(i64), + libffi::raw::FFI_TYPE_POINTER => read_and_push_int!(i64), libffi::raw::FFI_TYPE_STRUCT => { let substruct = struct_type.atom_fields[i].as_str(); let struct_type = self.structs.get(substruct).ok_or(FFIError::StructNotFound)?; diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 1c367a80..39311276 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -4310,12 +4310,17 @@ impl Machine { Ok(result) => { match result { Value::Int(n) => self.machine_st.unify_fixnum(Fixnum::build_with(n), return_value), + Value::Float(n) => { + let n = float_alloc!(n, self.machine_st.arena); + self.machine_st.unify_f64(n, return_value) + }, Value::Struct(name, args) => { let struct_value = self.build_struct(&name, args); unify!(self.machine_st, return_value, struct_value); } - _ => { - unreachable!(); + Value::CString(cstr) => { + let cstr = self.machine_st.atom_tbl.build_with(cstr.to_str().unwrap()); + self.machine_st.unify_complete_string(cstr, return_value); } } return Ok(()); @@ -4340,10 +4345,10 @@ impl Machine { let cells: Vec<_> = args.into_iter() .map(|val| { match val { - Value::Int(n) => fixnum_as_cell!(Fixnum::build_with(n)), - Value::CString(cstr) => atom_as_cell!(self.machine_st.atom_tbl.build_with(&cstr.into_string().unwrap())), - Value::Struct(name, struct_args) => self.build_struct(&name, struct_args), - _ => unreachable!() + Value::Int(n) => fixnum_as_cell!(Fixnum::build_with(n)), + Value::Float(n) => HeapCellValue::from(float_alloc!(n, self.machine_st.arena)), + Value::CString(cstr) => atom_as_cell!(self.machine_st.atom_tbl.build_with(&cstr.into_string().unwrap())), + Value::Struct(name, struct_args) => self.build_struct(&name, struct_args), } }).collect(); -- 2.54.0