Fix feature flags.
This commit is contained in:
parent
5ea08d2b50
commit
ae11dbbefe
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -4,7 +4,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- closures
|
||||
pull_request: {}
|
||||
|
||||
jobs:
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rhai"
|
||||
version = "0.19.0"
|
||||
version = "0.18.1"
|
||||
edition = "2018"
|
||||
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"]
|
||||
description = "Embedded scripting for Rust"
|
||||
@ -23,7 +23,6 @@ smallvec = { version = "1.4.1", default-features = false }
|
||||
[features]
|
||||
#default = ["unchecked", "sync", "no_optimize", "no_float", "only_i32", "no_index", "no_object", "no_function", "no_module"]
|
||||
default = []
|
||||
plugins = [] # custom plugins support
|
||||
unchecked = [] # unchecked arithmetic
|
||||
sync = [] # restrict to only types that implement Send + Sync
|
||||
no_optimize = [] # no script optimizer
|
||||
|
@ -1,11 +1,7 @@
|
||||
Rhai Release Notes
|
||||
==================
|
||||
|
||||
Version 0.19.0
|
||||
==============
|
||||
|
||||
|
||||
Version 0.18.0
|
||||
Version 0.18.1
|
||||
==============
|
||||
|
||||
This version adds:
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.19.0",
|
||||
"version": "0.18.1",
|
||||
"repoHome": "https://github.com/jonathandturner/rhai/blob/master",
|
||||
"repoTree": "https://github.com/jonathandturner/rhai/tree/master",
|
||||
"rootUrl": "",
|
||||
|
@ -410,7 +410,7 @@ impl fmt::Display for Dynamic {
|
||||
}
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(feature = "sync")]
|
||||
Union::Shared(cell) => fmt::Display::fmt(*cell.read_lock().unwrap(), f),
|
||||
Union::Shared(cell) => fmt::Display::fmt(&*cell.read().unwrap(), f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,7 +448,7 @@ impl fmt::Debug for Dynamic {
|
||||
}
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(feature = "sync")]
|
||||
Union::Shared(cell) => fmt::Display::fmt(*cell.read_lock().unwrap(), f),
|
||||
Union::Shared(cell) => fmt::Debug::fmt(&*cell.read().unwrap(), f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
src/api.rs
15
src/api.rs
@ -3,10 +3,9 @@
|
||||
use crate::any::{Dynamic, Variant};
|
||||
use crate::engine::{Engine, Imports, State};
|
||||
use crate::error::ParseError;
|
||||
use crate::fn_call::ensure_no_data_race;
|
||||
use crate::fn_native::{IteratorFn, SendSync};
|
||||
use crate::module::{FuncReturn, Module};
|
||||
use crate::optimize::{optimize_into_ast, OptimizationLevel};
|
||||
use crate::optimize::OptimizationLevel;
|
||||
use crate::parser::AST;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::scope::Scope;
|
||||
@ -24,14 +23,22 @@ use crate::{
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::{engine::get_script_function_by_signature, fn_args::FuncArgs, utils::StaticVec};
|
||||
use crate::{
|
||||
engine::get_script_function_by_signature, fn_args::FuncArgs, fn_call::ensure_no_data_race,
|
||||
utils::StaticVec,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
use crate::optimize::optimize_into_ast;
|
||||
|
||||
use crate::stdlib::{
|
||||
any::{type_name, TypeId},
|
||||
boxed::Box,
|
||||
mem,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
use crate::stdlib::mem;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::stdlib::{fs::File, io::prelude::*, path::PathBuf};
|
||||
|
@ -34,6 +34,7 @@ use crate::engine::{FN_IDX_GET, FN_IDX_SET};
|
||||
use crate::engine::{Map, Target, FN_GET, FN_SET};
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::scope::Entry as ScopeEntry;
|
||||
|
||||
use crate::stdlib::{
|
||||
@ -48,6 +49,7 @@ use crate::stdlib::{
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::stdlib::{collections::HashSet, string::String};
|
||||
|
||||
/// Extract the property name from a getter function name.
|
||||
@ -140,6 +142,7 @@ impl Drop for ArgBackup<'_> {
|
||||
|
||||
// Add captured variables into scope
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
fn add_captured_variables_into_scope<'s>(
|
||||
externals: &HashSet<String>,
|
||||
captured: Scope<'s>,
|
||||
@ -449,11 +452,11 @@ impl Engine {
|
||||
hash_script: u64,
|
||||
args: &mut FnCallArgs,
|
||||
is_ref: bool,
|
||||
is_method: bool,
|
||||
_is_method: bool,
|
||||
pub_only: bool,
|
||||
_capture: Option<Scope>,
|
||||
def_val: Option<bool>,
|
||||
level: usize,
|
||||
_level: usize,
|
||||
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
||||
// Check for data race.
|
||||
if cfg!(not(feature = "no_closure")) {
|
||||
@ -510,7 +513,7 @@ impl Engine {
|
||||
add_captured_variables_into_scope(&func.externals, captured, scope);
|
||||
}
|
||||
|
||||
let result = if is_method {
|
||||
let result = if _is_method {
|
||||
// Method call of script function - map first argument to `this`
|
||||
let (first, rest) = args.split_at_mut(1);
|
||||
self.call_script_fn(
|
||||
@ -522,7 +525,7 @@ impl Engine {
|
||||
fn_name,
|
||||
func,
|
||||
rest,
|
||||
level,
|
||||
_level,
|
||||
)?
|
||||
} else {
|
||||
// Normal call of script function - map first argument to `this`
|
||||
@ -531,7 +534,7 @@ impl Engine {
|
||||
backup.change_first_arg_to_copy(is_ref, args);
|
||||
|
||||
let result = self.call_script_fn(
|
||||
scope, mods, state, lib, &mut None, fn_name, func, args, level,
|
||||
scope, mods, state, lib, &mut None, fn_name, func, args, _level,
|
||||
);
|
||||
|
||||
// Restore the original reference
|
||||
|
@ -1,21 +1,20 @@
|
||||
//! Module defining interfaces to native-Rust functions.
|
||||
|
||||
use crate::any::Dynamic;
|
||||
use crate::calc_fn_hash;
|
||||
use crate::engine::Engine;
|
||||
use crate::module::Module;
|
||||
use crate::parser::FnAccess;
|
||||
use crate::parser::{FnAccess, ScriptFnDef};
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::{is_valid_identifier, Position};
|
||||
use crate::utils::ImmutableString;
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::{module::FuncReturn, parser::ScriptFnDef, utils::StaticVec};
|
||||
use crate::{calc_fn_hash, module::FuncReturn, utils::StaticVec};
|
||||
|
||||
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, iter::empty, string::String, vec::Vec};
|
||||
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, string::String, vec::Vec};
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::stdlib::mem;
|
||||
use crate::stdlib::{iter::empty, mem};
|
||||
|
||||
#[cfg(not(feature = "sync"))]
|
||||
use crate::stdlib::rc::Rc;
|
||||
@ -293,10 +292,11 @@ impl CallableFunction {
|
||||
}
|
||||
}
|
||||
/// Is this a Rhai-scripted function?
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn is_script(&self) -> bool {
|
||||
match self {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(_) => true,
|
||||
|
||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => false,
|
||||
}
|
||||
}
|
||||
@ -314,6 +314,8 @@ impl CallableFunction {
|
||||
pub fn access(&self) -> FnAccess {
|
||||
match self {
|
||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => FnAccess::Public,
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(f) => f.access,
|
||||
}
|
||||
}
|
||||
@ -348,10 +350,11 @@ impl CallableFunction {
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the `CallableFunction` is not `Script`.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn get_fn_def(&self) -> &ScriptFnDef {
|
||||
match self {
|
||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => unreachable!(),
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(f) => f,
|
||||
}
|
||||
}
|
||||
@ -385,16 +388,22 @@ impl From<IteratorFn> for CallableFunction {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
impl From<ScriptFnDef> for CallableFunction {
|
||||
fn from(func: ScriptFnDef) -> Self {
|
||||
Self::Script(func.into())
|
||||
fn from(_func: ScriptFnDef) -> Self {
|
||||
#[cfg(feature = "no_function")]
|
||||
unreachable!();
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(_func.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
impl From<Shared<ScriptFnDef>> for CallableFunction {
|
||||
fn from(func: Shared<ScriptFnDef>) -> Self {
|
||||
Self::Script(func)
|
||||
fn from(_func: Shared<ScriptFnDef>) -> Self {
|
||||
#[cfg(feature = "no_function")]
|
||||
unreachable!();
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(_func)
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ use crate::any::{Dynamic, Variant};
|
||||
use crate::calc_fn_hash;
|
||||
use crate::engine::Engine;
|
||||
use crate::fn_native::{CallableFunction as Func, FnCallArgs, IteratorFn, SendSync};
|
||||
use crate::parser::{FnAccess, FnAccess::Public};
|
||||
use crate::parser::{FnAccess, FnAccess::Public, ScriptFnDef};
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::{Position, Token};
|
||||
use crate::utils::{StaticVec, StraightHasherBuilder};
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::{fn_native::Shared, parser::ScriptFnDef};
|
||||
use crate::fn_native::Shared;
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
use crate::{
|
||||
@ -258,7 +258,6 @@ impl Module {
|
||||
/// Set a script-defined function into the module.
|
||||
///
|
||||
/// If there is an existing function of the same name and number of arguments, it is replaced.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub(crate) fn set_script_fn(&mut self, fn_def: ScriptFnDef) -> &mut Self {
|
||||
// None + function name + number of arguments.
|
||||
let hash_script = calc_fn_hash(empty(), &fn_def.name, fn_def.params.len(), empty());
|
||||
@ -1003,7 +1002,6 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Get an iterator to the functions in the module.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub(crate) fn iter_fn(
|
||||
&self,
|
||||
) -> impl Iterator<Item = &(String, FnAccess, StaticVec<TypeId>, Func)> {
|
||||
|
@ -7,13 +7,10 @@ use crate::engine::{
|
||||
};
|
||||
use crate::fn_native::FnPtr;
|
||||
use crate::module::Module;
|
||||
use crate::parser::{map_dynamic_to_expr, Expr, ScriptFnDef, Stmt, AST};
|
||||
use crate::parser::{map_dynamic_to_expr, Expr, ReturnType, ScriptFnDef, Stmt, AST};
|
||||
use crate::scope::{Entry as ScopeEntry, EntryType as ScopeEntryType, Scope};
|
||||
use crate::utils::StaticVec;
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::parser::ReturnType;
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
use crate::parser::CustomExpr;
|
||||
|
||||
@ -46,10 +43,12 @@ impl OptimizationLevel {
|
||||
self == Self::None
|
||||
}
|
||||
/// Is the `OptimizationLevel` Simple.
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
pub fn is_simple(self) -> bool {
|
||||
self == Self::Simple
|
||||
}
|
||||
/// Is the `OptimizationLevel` Full.
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
pub fn is_full(self) -> bool {
|
||||
self == Self::Full
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
use crate::any::{Dynamic, Union};
|
||||
use crate::calc_fn_hash;
|
||||
use crate::engine::{
|
||||
Engine, KEYWORD_FN_PTR_CURRY, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT,
|
||||
};
|
||||
use crate::engine::{Engine, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT};
|
||||
use crate::error::{LexError, ParseError, ParseErrorType};
|
||||
use crate::fn_native::{FnPtr, Shared};
|
||||
use crate::module::{Module, ModuleRef};
|
||||
@ -15,7 +13,7 @@ use crate::token::{is_keyword_function, is_valid_identifier, Position, Token, To
|
||||
use crate::utils::{StaticVec, StraightHasherBuilder};
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
use crate::engine::FN_ANONYMOUS;
|
||||
use crate::engine::{FN_ANONYMOUS, KEYWORD_FN_PTR_CURRY};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use crate::engine::{make_getter, make_setter};
|
||||
@ -3135,6 +3133,7 @@ fn parse_fn(
|
||||
}
|
||||
|
||||
/// Creates a curried expression from a list of external variables
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
fn make_curry_from_externals(
|
||||
fn_expr: Expr,
|
||||
externals: StaticVec<(String, Position)>,
|
||||
|
@ -1,13 +1,15 @@
|
||||
//! Configuration settings for `Engine`.
|
||||
|
||||
use crate::engine::Engine;
|
||||
use crate::optimize::OptimizationLevel;
|
||||
use crate::packages::PackageLibrary;
|
||||
use crate::token::{is_valid_identifier, Token};
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
use crate::module::ModuleResolver;
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
use crate::optimize::OptimizationLevel;
|
||||
|
||||
use crate::stdlib::{format, string::String};
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
|
@ -680,6 +680,7 @@ impl Token {
|
||||
}
|
||||
|
||||
/// Convert a token into a function name, if possible.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub(crate) fn into_function_name_for_override(self) -> Result<String, Self> {
|
||||
match self {
|
||||
Self::Reserved(s) if can_override_keyword(&s) => Ok(s),
|
||||
@ -1442,6 +1443,7 @@ pub fn is_keyword_function(name: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Can this keyword be overridden as a function?
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[inline(always)]
|
||||
pub fn can_override_keyword(name: &str) -> bool {
|
||||
match name {
|
||||
|
@ -83,6 +83,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[cfg(not(feature = "sync"))]
|
||||
fn test_closures_data_race() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user