From 614850ab1d745f62f098d877b74ba7d34a33d85a Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 1 Feb 2024 09:31:04 -0700 Subject: [PATCH] fmt --- build/instructions_template.rs | 42 +++++++++++++++++----------------- src/ffi.rs | 31 +++++++++++++------------ src/machine/lib_machine.rs | 2 +- src/machine/machine_errors.rs | 20 ---------------- src/parser/char_reader.rs | 2 +- src/rcu.rs | 2 +- 6 files changed, 40 insertions(+), 59 deletions(-) diff --git a/build/instructions_template.rs b/build/instructions_template.rs index 1840341b..7e3f4f22 100644 --- a/build/instructions_template.rs +++ b/build/instructions_template.rs @@ -1155,27 +1155,27 @@ fn generate_instruction_preface() -> TokenStream { impl Instruction { #[inline] pub fn registers(&self) -> Vec { - match self { - &Instruction::GetConstant(_, _, r) => vec![r], - &Instruction::GetList(_, r) => vec![r], - &Instruction::GetPartialString(_, _, r, _) => vec![r], - &Instruction::GetStructure(_, _, _, r) => vec![r], - &Instruction::GetVariable(r, t) => vec![r, temp_v!(t)], - &Instruction::GetValue(r, t) => vec![r, temp_v!(t)], - &Instruction::UnifyLocalValue(r) => vec![r], - &Instruction::UnifyVariable(r) => vec![r], - &Instruction::PutConstant(_, _, r) => vec![r], - &Instruction::PutList(_, r) => vec![r], - &Instruction::PutPartialString(_, _, r, _) => vec![r], - &Instruction::PutStructure(_, _, r) => vec![r], - &Instruction::PutValue(r, t) => vec![r, temp_v!(t)], - &Instruction::PutVariable(r, t) => vec![r, temp_v!(t)], - &Instruction::SetLocalValue(r) => vec![r], - &Instruction::SetVariable(r) => vec![r], - &Instruction::SetValue(r) => vec![r], - &Instruction::GetLevel(r) => vec![r], - &Instruction::GetPrevLevel(r) => vec![r], - &Instruction::GetCutPoint(r) => vec![r], + match *self { + Instruction::GetConstant(_, _, r) => vec![r], + Instruction::GetList(_, r) => vec![r], + Instruction::GetPartialString(_, _, r, _) => vec![r], + Instruction::GetStructure(_, _, _, r) => vec![r], + Instruction::GetVariable(r, t) => vec![r, temp_v!(t)], + Instruction::GetValue(r, t) => vec![r, temp_v!(t)], + Instruction::UnifyLocalValue(r) => vec![r], + Instruction::UnifyVariable(r) => vec![r], + Instruction::PutConstant(_, _, r) => vec![r], + Instruction::PutList(_, r) => vec![r], + Instruction::PutPartialString(_, _, r, _) => vec![r], + Instruction::PutStructure(_, _, r) => vec![r], + Instruction::PutValue(r, t) => vec![r, temp_v!(t)], + Instruction::PutVariable(r, t) => vec![r, temp_v!(t)], + Instruction::SetLocalValue(r) => vec![r], + Instruction::SetVariable(r) => vec![r], + Instruction::SetValue(r) => vec![r], + Instruction::GetLevel(r) => vec![r], + Instruction::GetPrevLevel(r) => vec![r], + Instruction::GetCutPoint(r) => vec![r], _ => vec![], } } diff --git a/src/ffi.rs b/src/ffi.rs index 64879e58..a8ffd744 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -27,6 +27,7 @@ use std::collections::HashMap; use std::convert::TryFrom; use std::error::Error; use std::ffi::{c_void, CString}; +use std::ptr::addr_of_mut; use libffi::low::type_tag::STRUCT; use libffi::low::{ffi_abi_FFI_DEFAULT_ABI, ffi_cif, ffi_type, prep_cif, types, CodePtr}; @@ -90,20 +91,20 @@ impl ForeignFunctionTable { fn map_type_ffi(&mut self, source: &Atom) -> *mut ffi_type { unsafe { match source { - atom!("sint64") => &mut types::sint64, - atom!("sint32") => &mut types::sint32, - atom!("sint16") => &mut types::sint16, - atom!("sint8") => &mut types::sint8, - atom!("uint64") => &mut types::uint64, - atom!("uint32") => &mut types::uint32, - atom!("uint16") => &mut types::uint16, - atom!("uint8") => &mut types::uint8, - atom!("bool") => &mut types::sint8, - atom!("void") => &mut types::void, - atom!("cstr") => &mut types::pointer, - atom!("ptr") => &mut types::pointer, - atom!("f32") => &mut types::float, - atom!("f64") => &mut types::double, + atom!("sint64") => addr_of_mut!(types::sint64), + atom!("sint32") => addr_of_mut!(types::sint32), + atom!("sint16") => addr_of_mut!(types::sint16), + atom!("sint8") => addr_of_mut!(types::sint8), + atom!("uint64") => addr_of_mut!(types::uint64), + atom!("uint32") => addr_of_mut!(types::uint32), + atom!("uint16") => addr_of_mut!(types::uint16), + atom!("uint8") => addr_of_mut!(types::uint8), + atom!("bool") => addr_of_mut!(types::sint8), + atom!("void") => addr_of_mut!(types::void), + atom!("cstr") => addr_of_mut!(types::pointer), + atom!("ptr") => addr_of_mut!(types::pointer), + atom!("f32") => addr_of_mut!(types::float), + atom!("f64") => addr_of_mut!(types::double), struct_name => match self.structs.get_mut(&*struct_name.as_str()) { Some(ref mut struct_type) => &mut struct_type.ffi_type, None => unreachable!(), @@ -161,7 +162,7 @@ impl ForeignFunctionTable { } fn build_pointer_args( - args: &mut Vec, + args: &mut [Value], type_args: &[*mut ffi_type], structs_table: &mut HashMap, ) -> Result { diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index 9b218f51..0bebfdc3 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -607,6 +607,6 @@ mod tests { assert_eq!( result, Err(String::from("error existence_error procedure / non_existent_predicate 3 / non_existent_predicate 3")) - ); + ); } } diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index c2cbb405..5860fb5d 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -1022,19 +1022,6 @@ pub enum SessionError { QueryCannotBeDefinedAsFact, } -#[derive(Debug)] -pub(crate) enum EvalSession { - // EntrySuccess, - Error(SessionError), -} - -impl From for EvalSession { - #[inline] - fn from(err: SessionError) -> Self { - EvalSession::Error(err) - } -} - impl From for SessionError { #[inline] fn from(err: std::io::Error) -> SessionError { @@ -1055,10 +1042,3 @@ impl From for SessionError { SessionError::CompilationError(err) } } - -impl From for EvalSession { - #[inline] - fn from(err: ParserError) -> Self { - EvalSession::from(SessionError::from(err)) - } -} diff --git a/src/parser/char_reader.rs b/src/parser/char_reader.rs index aa1813a9..9febf0fd 100644 --- a/src/parser/char_reader.rs +++ b/src/parser/char_reader.rs @@ -229,7 +229,7 @@ impl CharRead for CharReader { match self.inner.read(word_slice) { Err(e) => return Some(Err(e)), - Ok(nread) if nread == 0 => return Some(Err(bad_bytes_error(&self.buf))), + Ok(0) => return Some(Err(bad_bytes_error(&self.buf))), Ok(nread) => { self.buf.extend_from_slice(&word_slice[0..nread]); } diff --git a/src/rcu.rs b/src/rcu.rs index 5c7c3201..a3e8d2ab 100644 --- a/src/rcu.rs +++ b/src/rcu.rs @@ -22,7 +22,7 @@ thread_local! { // odd value means the current thread is about to access the active_epoch of an Rcu // a thread has a single epoch counter for all Rcu it accesses, // as a thread can only access one Rcu at a time - static THREAD_EPOCH_COUNTER: OnceCell> = OnceCell::new(); + static THREAD_EPOCH_COUNTER: OnceCell> = const { OnceCell::new() }; } pub struct Rcu { -- 2.54.0