Fix feature builds.

This commit is contained in:
Stephen Chung 2021-11-27 23:20:05 +08:00
parent e918e61e95
commit 4fc088a0f1
10 changed files with 23 additions and 34 deletions

View File

@ -1,8 +1,12 @@
//! Module that defines the `call_fn` API of [`Engine`]. //! Module that defines the `call_fn` API of [`Engine`].
#![cfg(not(feature = "no_function"))]
use crate::engine::{EvalState, Imports}; use crate::engine::{EvalState, Imports};
use crate::func::call::ensure_no_data_race;
use crate::types::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::{Dynamic, Engine, EvalAltResult, Position, RhaiResult, Scope, AST}; use crate::{
Dynamic, Engine, EvalAltResult, FuncArgs, Position, RhaiResult, Scope, StaticVec, AST,
};
use std::any::type_name; use std::any::type_name;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -50,16 +54,15 @@ impl Engine {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[cfg(not(feature = "no_function"))]
#[inline] #[inline]
pub fn call_fn<T: Variant + Clone>( pub fn call_fn<T: Variant + Clone>(
&self, &self,
scope: &mut Scope, scope: &mut Scope,
ast: &AST, ast: &AST,
name: impl AsRef<str>, name: impl AsRef<str>,
args: impl crate::FuncArgs, args: impl FuncArgs,
) -> Result<T, Box<EvalAltResult>> { ) -> Result<T, Box<EvalAltResult>> {
let mut arg_values = crate::StaticVec::new_const(); let mut arg_values = StaticVec::new_const();
args.parse(&mut arg_values); args.parse(&mut arg_values);
let result = self.call_fn_raw(scope, ast, true, true, name, None, arg_values)?; let result = self.call_fn_raw(scope, ast, true, true, name, None, arg_values)?;
@ -135,7 +138,6 @@ impl Engine {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[cfg(not(feature = "no_function"))]
#[inline] #[inline]
pub fn call_fn_raw( pub fn call_fn_raw(
&self, &self,
@ -165,7 +167,7 @@ impl Engine {
let name = name.as_ref(); let name = name.as_ref();
let mut this_ptr = this_ptr; let mut this_ptr = this_ptr;
let mut arg_values = arg_values; let mut arg_values = arg_values;
let mut args: crate::StaticVec<_> = arg_values.as_mut().iter_mut().collect(); let mut args: StaticVec<_> = arg_values.as_mut().iter_mut().collect();
let fn_def = ast let fn_def = ast
.lib() .lib()
@ -174,7 +176,7 @@ impl Engine {
// Check for data race. // Check for data race.
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
crate::func::call::ensure_no_data_race(name, &mut args, false)?; ensure_no_data_race(name, &mut args, false)?;
let result = self.call_script_fn( let result = self.call_script_fn(
scope, scope,

View File

@ -6,15 +6,12 @@ pub mod run;
pub mod compile; pub mod compile;
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
pub mod files; pub mod files;
pub mod register; pub mod register;
pub mod call_fn; pub mod call_fn;
#[cfg(not(feature = "unchecked"))]
pub mod limits; pub mod limits;
pub mod events; pub mod events;

View File

@ -1,6 +1,5 @@
//! Helper module which defines [`FuncArgs`] to make function calling easier. //! Helper module which defines [`FuncArgs`] to make function calling easier.
#![cfg(not(feature = "no_function"))]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::types::dynamic::Variant; use crate::types::dynamic::Variant;

View File

@ -1,17 +1,14 @@
//! Module defining mechanisms to handle function calls in Rhai. //! Module defining mechanisms to handle function calls in Rhai.
#[cfg(not(feature = "no_function"))]
pub mod args; pub mod args;
pub mod builtin; pub mod builtin;
pub mod call; pub mod call;
#[cfg(not(feature = "no_function"))]
pub mod func; pub mod func;
pub mod hashing; pub mod hashing;
pub mod native; pub mod native;
pub mod plugin; pub mod plugin;
pub mod register; pub mod register;
#[cfg(not(feature = "no_function"))]
pub use args::FuncArgs; pub use args::FuncArgs;
pub use builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn}; pub use builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn};
pub use call::FnCallArgs; pub use call::FnCallArgs;

View File

@ -75,7 +75,6 @@ mod custom_syntax;
mod engine; mod engine;
mod func; mod func;
mod module; mod module;
#[cfg(not(feature = "no_optimize"))]
mod optimizer; mod optimizer;
pub mod packages; pub mod packages;
mod parser; mod parser;
@ -150,10 +149,10 @@ pub(crate) use func::{
pub use rhai_codegen::*; pub use rhai_codegen::*;
pub use func::plugin; pub use func::{plugin, FuncArgs};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use func::{Func, FuncArgs}; pub use func::Func;
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use ast::ScriptFnMetadata; pub use ast::ScriptFnMetadata;

View File

@ -1,8 +1,9 @@
#![cfg(not(feature = "no_std"))]
#![cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
use crate::func::native::shared_write_lock; use crate::func::native::shared_write_lock;
use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Scope, Shared}; use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Scope, Shared};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
io::Error as IoError, io::Error as IoError,

View File

@ -9,8 +9,6 @@ pub use dummy::DummyModuleResolver;
mod collection; mod collection;
pub use collection::ModuleResolversCollection; pub use collection::ModuleResolversCollection;
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
mod file; mod file;
#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_std"))]

View File

@ -1,16 +1,18 @@
//! Module implementing the [`AST`] optimizer. //! Module implementing the [`AST`] optimizer.
#![cfg(not(feature = "no_optimize"))]
use crate::ast::{Expr, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; use crate::ast::{Expr, OpAssignment, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*};
use crate::engine::{ use crate::engine::{
EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF, EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF,
}; };
use crate::func::builtin::get_builtin_binary_op_fn; use crate::func::builtin::get_builtin_binary_op_fn;
use crate::func::hashing::get_hasher; use crate::func::hashing::get_hasher;
use crate::func::native::shared_take_or_clone;
use crate::tokenizer::Token; use crate::tokenizer::Token;
use crate::types::dynamic::AccessMode; use crate::types::dynamic::AccessMode;
use crate::{ use crate::{
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString, calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString,
Module, Position, Scope, StaticVec, AST, Module, Position, Scope, Shared, StaticVec, AST,
}; };
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -1122,7 +1124,7 @@ pub fn optimize_into_ast(
engine: &Engine, engine: &Engine,
scope: &Scope, scope: &Scope,
statements: StaticVec<Stmt>, statements: StaticVec<Stmt>,
functions: StaticVec<crate::Shared<crate::ast::ScriptFnDef>>, functions: StaticVec<Shared<ScriptFnDef>>,
optimization_level: OptimizationLevel, optimization_level: OptimizationLevel,
) -> AST { ) -> AST {
let level = if cfg!(feature = "no_optimize") { let level = if cfg!(feature = "no_optimize") {
@ -1144,14 +1146,14 @@ pub fn optimize_into_ast(
_functions _functions
.iter() .iter()
.map(|fn_def| crate::ast::ScriptFnDef { .map(|fn_def| ScriptFnDef {
name: fn_def.name.clone(), name: fn_def.name.clone(),
access: fn_def.access, access: fn_def.access,
body: crate::ast::StmtBlock::NONE, body: StmtBlock::NONE,
params: fn_def.params.clone(), params: fn_def.params.clone(),
lib: None, lib: None,
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
mods: crate::engine::Imports::new(), mods: Imports::new(),
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
comments: None, comments: None,
@ -1165,7 +1167,7 @@ pub fn optimize_into_ast(
_functions _functions
.into_iter() .into_iter()
.map(|fn_def| { .map(|fn_def| {
let mut fn_def = crate::func::native::shared_take_or_clone(fn_def); let mut fn_def = shared_take_or_clone(fn_def);
// Optimize the function body // Optimize the function body
let body = mem::take(fn_def.body.deref_mut()); let body = mem::take(fn_def.body.deref_mut());

View File

@ -3,22 +3,18 @@
use crate::{Module, Shared}; use crate::{Module, Shared};
pub(crate) mod arithmetic; pub(crate) mod arithmetic;
#[cfg(not(feature = "no_index"))]
mod array_basic; mod array_basic;
#[cfg(not(feature = "no_index"))]
mod blob_basic; mod blob_basic;
mod fn_basic; mod fn_basic;
mod iter_basic; mod iter_basic;
mod lang_core; mod lang_core;
mod logic; mod logic;
#[cfg(not(feature = "no_object"))]
mod map_basic; mod map_basic;
mod math_basic; mod math_basic;
mod pkg_core; mod pkg_core;
mod pkg_std; mod pkg_std;
mod string_basic; mod string_basic;
mod string_more; mod string_more;
#[cfg(not(feature = "no_std"))]
mod time_basic; mod time_basic;
pub use arithmetic::ArithmeticPackage; pub use arithmetic::ArithmeticPackage;

View File

@ -3,8 +3,6 @@
use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT}; use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT};
use crate::plugin::*; use crate::plugin::*;
use crate::{def_package, Dynamic, EvalAltResult, INT}; use crate::{def_package, Dynamic, EvalAltResult, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
use crate::FLOAT; use crate::FLOAT;