From 54353c667640aa33891983cd68aa3744e24b6037 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 10 Nov 2022 12:16:23 +0800 Subject: [PATCH] Fix no_function build. --- src/api/call_fn.rs | 2 +- src/api/eval.rs | 2 +- src/api/run.rs | 2 +- src/eval/eval_context.rs | 4 ++-- src/func/call.rs | 30 +++++++++++++++--------------- src/optimizer.rs | 10 +++++++--- src/types/fn_ptr.rs | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index f7e5bfee..06d8af04 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -253,7 +253,7 @@ impl Engine { let orig_lib_len = global.lib.len(); #[cfg(not(feature = "no_function"))] - if !ast.functions().is_empty() { + if ast.has_functions() { global.lib.push(ast.functions().clone()); } diff --git a/src/api/eval.rs b/src/api/eval.rs index 111e2828..82011f4c 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -210,7 +210,7 @@ impl Engine { let orig_lib_len = global.lib.len(); #[cfg(not(feature = "no_function"))] - if !ast.functions().is_empty() { + if ast.has_functions() { global.lib.push(ast.functions().clone()); } diff --git a/src/api/run.rs b/src/api/run.rs index 08206088..3c4d823a 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -116,7 +116,7 @@ impl Engine { global.source = ast.source_raw().cloned(); #[cfg(not(feature = "no_function"))] - if !ast.functions().is_empty() { + if ast.has_functions() { global.lib.push(ast.functions().clone()); } #[cfg(not(feature = "no_module"))] diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index 8a4b3df6..d9d73c25 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -1,7 +1,7 @@ //! Evaluation context. use super::{Caches, GlobalRuntimeState}; -use crate::{Dynamic, Engine, Module, Scope, SharedModule}; +use crate::{Dynamic, Engine, Module, Scope}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -109,7 +109,7 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> { #[cfg(feature = "internals")] #[inline(always)] #[must_use] - pub fn namespaces(&self) -> &[SharedModule] { + pub fn namespaces(&self) -> &[crate::SharedModule] { &self.global.lib } /// The current bound `this` pointer, if any. diff --git a/src/func/call.rs b/src/func/call.rs index 58f4d656..9de11db3 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -543,7 +543,7 @@ impl Engine { fn_name: &str, op_token: Option<&Token>, hashes: FnCallHashes, - mut args: &mut FnCallArgs, + mut _args: &mut FnCallArgs, is_ref_mut: bool, _is_method_call: bool, pos: Position, @@ -558,7 +558,7 @@ impl Engine { // Check for data race. #[cfg(not(feature = "no_closure"))] - ensure_no_data_race(fn_name, args, is_ref_mut)?; + ensure_no_data_race(fn_name, _args, is_ref_mut)?; global.level += 1; let global = &mut *RestoreOnDrop::lock(global, move |g| g.level -= 1); @@ -567,18 +567,18 @@ impl Engine { if hashes.is_native_only() { match fn_name { // Handle type_of() - KEYWORD_TYPE_OF if args.len() == 1 => { - let typ = self.map_type_name(args[0].type_name()).to_string().into(); + KEYWORD_TYPE_OF if _args.len() == 1 => { + let typ = self.map_type_name(_args[0].type_name()).to_string().into(); return Ok((typ, false)); } // Handle is_def_fn() #[cfg(not(feature = "no_function"))] crate::engine::KEYWORD_IS_DEF_FN - if args.len() == 2 && args[0].is_fnptr() && args[1].is_int() => + if _args.len() == 2 && _args[0].is_fnptr() && _args[1].is_int() => { - let fn_name = args[0].read_lock::().expect("`FnPtr`"); - let num_params = args[1].as_int().expect("`INT`"); + let fn_name = _args[0].read_lock::().expect("`FnPtr`"); + let num_params = _args[1].as_int().expect("`INT`"); return Ok(( if num_params < 0 || num_params > crate::MAX_USIZE_INT { @@ -595,15 +595,15 @@ impl Engine { // Handle is_shared() #[cfg(not(feature = "no_closure"))] - crate::engine::KEYWORD_IS_SHARED if args.len() == 1 => { + crate::engine::KEYWORD_IS_SHARED if _args.len() == 1 => { return no_method_err(fn_name, pos) } - KEYWORD_FN_PTR | KEYWORD_EVAL | KEYWORD_IS_DEF_VAR if args.len() == 1 => { + KEYWORD_FN_PTR | KEYWORD_EVAL | KEYWORD_IS_DEF_VAR if _args.len() == 1 => { return no_method_err(fn_name, pos) } - KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY if !args.is_empty() => { + KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY if !_args.is_empty() => { return no_method_err(fn_name, pos) } @@ -644,7 +644,7 @@ impl Engine { return if _is_method_call { // Method call of script function - map first argument to `this` - let (first_arg, rest_args) = args.split_first_mut().unwrap(); + let (first_arg, rest_args) = _args.split_first_mut().unwrap(); self.call_script_fn( global, caches, scope, first_arg, func, rest_args, true, pos, @@ -654,13 +654,13 @@ impl Engine { let backup = &mut ArgBackup::new(); // The first argument is a reference? - let swap = is_ref_mut && !args.is_empty(); + let swap = is_ref_mut && !_args.is_empty(); if swap { - backup.change_first_arg_to_copy(args); + backup.change_first_arg_to_copy(_args); } - let args = &mut *RestoreOnDrop::lock_if(swap, &mut args, move |a| { + let args = &mut *RestoreOnDrop::lock_if(swap, &mut _args, move |a| { backup.restore_first_arg(a) }); @@ -676,7 +676,7 @@ impl Engine { let hash = hashes.native(); self.exec_native_fn_call( - global, caches, fn_name, op_token, hash, args, is_ref_mut, pos, + global, caches, fn_name, op_token, hash, _args, is_ref_mut, pos, ) } diff --git a/src/optimizer.rs b/src/optimizer.rs index 789a7bea..d903c836 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -71,15 +71,19 @@ impl<'a> OptimizerState<'a> { #[cfg(not(feature = "no_function"))] lib: &'a [crate::SharedModule], optimization_level: OptimizationLevel, ) -> Self { - let mut global = GlobalRuntimeState::new(engine); - global.lib = lib.iter().cloned().collect(); + let mut _global = GlobalRuntimeState::new(engine); + + #[cfg(not(feature = "no_function"))] + { + _global.lib = lib.iter().cloned().collect(); + } Self { changed: false, variables: StaticVec::new_const(), propagate_constants: true, engine, - global, + global: _global, caches: Caches::new(), optimization_level, } diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 7d11ecd7..c193749e 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -154,7 +154,7 @@ impl FnPtr { let global = &mut GlobalRuntimeState::new(engine); #[cfg(not(feature = "no_function"))] - if !_ast.functions().is_empty() { + if _ast.has_functions() { global.lib.push(_ast.functions().clone()); }