From 2c55c248fbe2d3f8f4d1a7d36160f08ef0742da4 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 11 Dec 2022 17:18:14 +0800 Subject: [PATCH] Fix builds. --- src/func/native.rs | 8 +++++ src/packages/array_basic.rs | 67 +++++++++++++++++++++---------------- src/types/fn_ptr.rs | 4 +-- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/func/native.rs b/src/func/native.rs index 8066a876..ed4c5117 100644 --- a/src/func/native.rs +++ b/src/func/native.rs @@ -271,6 +271,14 @@ impl<'a> NativeCallContext<'a> { pub const fn global_runtime_state(&self) -> &GlobalRuntimeState { self.global } + /// _(internals)_ The current [`GlobalRuntimeState`], if any. + #[cfg(not(feature = "internals"))] + #[inline(always)] + #[must_use] + #[allow(dead_code)] + pub(crate) const fn global_runtime_state(&self) -> &GlobalRuntimeState { + self.global + } /// Get an iterator over the namespaces containing definitions of all script-defined functions /// in reverse order (i.e. parent namespaces are iterated after child namespaces). /// diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index a490b8de..ba0d7ca7 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -35,36 +35,39 @@ fn make_dual_arity_fn_ptr_call( items: [Dynamic; N], number: usize, ) -> RhaiResult { - let arity = fn_ptr.fn_def().map(|f| f.params.len()).unwrap_or(0); + #[cfg(not(feature = "no_function"))] + { + let arity = fn_ptr.fn_def().map(|f| f.params.len()).unwrap_or(0); - if arity == N { - fn_ptr.call_raw(&ctx, None, items) - } else if arity == N + 1 { - let mut items2 = crate::StaticVec::new_const(); - items2.extend(IntoIterator::into_iter(items)); - items2.push((number as INT).into()); - fn_ptr.call_raw(&ctx, None, items2) - } else { - fn_ptr - .call_raw(&ctx, None, items.clone()) - .or_else(|err| match *err { - ERR::ErrorFunctionNotFound(sig, ..) if sig.starts_with(fn_ptr.fn_name()) => { - let mut items2 = crate::StaticVec::new_const(); - items2.extend(IntoIterator::into_iter(items)); - items2.push((number as INT).into()); - fn_ptr.call_raw(&ctx, None, items2) - } - _ => Err(err), - }) - .map_err(|err| { - Box::new(ERR::ErrorInFunctionCall( - fn_name.to_string(), - ctx.source().unwrap_or("").to_string(), - err, - Position::NONE, - )) - }) + if arity == N { + return fn_ptr.call_raw(&ctx, None, items); + } else if arity == N + 1 { + let mut items2 = crate::StaticVec::new_const(); + items2.extend(IntoIterator::into_iter(items)); + items2.push((number as INT).into()); + return fn_ptr.call_raw(&ctx, None, items2); + } } + + fn_ptr + .call_raw(&ctx, None, items.clone()) + .or_else(|err| match *err { + ERR::ErrorFunctionNotFound(sig, ..) if sig.starts_with(fn_ptr.fn_name()) => { + let mut items2 = crate::StaticVec::new_const(); + items2.extend(IntoIterator::into_iter(items)); + items2.push((number as INT).into()); + fn_ptr.call_raw(&ctx, None, items2) + } + _ => Err(err), + }) + .map_err(|err| { + Box::new(ERR::ErrorInFunctionCall( + fn_name.to_string(), + ctx.source().unwrap_or("").to_string(), + err, + Position::NONE, + )) + }) } #[export_module] @@ -1590,7 +1593,13 @@ pub mod array_functions { .rev() .enumerate() .try_fold(initial, |result, (i, item)| { - make_dual_arity_fn_ptr_call("reduce_rev", &reducer, &ctx, [result, item.clone()], array.len() - 1 - i) + make_dual_arity_fn_ptr_call( + "reduce_rev", + &reducer, + &ctx, + [result, item.clone()], + array.len() - 1 - i, + ) }) } /// Reduce an array by iterating through all elements, in _reverse_ order, diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 870b914e..5c71bf62 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -1,6 +1,6 @@ //! The `FnPtr` type. -use crate::eval::{Caches, GlobalRuntimeState}; +use crate::eval::GlobalRuntimeState; use crate::tokenizer::is_valid_function_name; use crate::types::dynamic::Variant; use crate::{ @@ -282,7 +282,7 @@ impl FnPtr { let global = &mut context.global_runtime_state().clone(); global.level += 1; - let caches = &mut Caches::new(); + let caches = &mut crate::eval::Caches::new(); let mut null_ptr = Dynamic::NULL; return context.engine().call_script_fn(