]> Repositorios git - scryer-prolog.git/commitdiff
Fill more cases
authorAdrián Arroyo Calle <[email protected]>
Wed, 1 Mar 2023 21:10:26 +0000 (22:10 +0100)
committerAdrián Arroyo Calle <[email protected]>
Wed, 1 Mar 2023 21:13:04 +0000 (22:13 +0100)
src/ffi.rs
src/machine/system_calls.rs

index afc52339451c7c4073a2da03e05c5d8220eaa7b5..a48ed62ead3061ce56c5419b63f9c375625471f2 100644 (file)
@@ -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<f32> = Box::new(0.0);
                    libffi::raw::ffi_call(
@@ -380,6 +381,7 @@ impl ForeignFunctionTable {
                        field_ptr = field_ptr.add(std::mem::size_of::<u64>());
                    },
                    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)?;
index 1c367a80ce55b4461166b2b70e1b6c0fd1802a6b..3931127613163976fa81d2f62a9907b25674c226 100644 (file)
@@ -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();