Fix no_function build.
This commit is contained in:
parent
c4ec93080e
commit
6a53c446d3
@ -5,13 +5,13 @@ use crate::calc_fn_hash;
|
|||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::fn_native::{CallableFunction as Func, FnCallArgs, IteratorFn, SendSync};
|
use crate::fn_native::{CallableFunction as Func, FnCallArgs, IteratorFn, SendSync};
|
||||||
use crate::fn_register::by_value as cast_arg;
|
use crate::fn_register::by_value as cast_arg;
|
||||||
use crate::parser::{FnAccess, FnAccess::Public, ScriptFnDef};
|
use crate::parser::{FnAccess, FnAccess::Public};
|
||||||
use crate::result::EvalAltResult;
|
use crate::result::EvalAltResult;
|
||||||
use crate::token::{Position, Token};
|
use crate::token::{Position, Token};
|
||||||
use crate::utils::{ImmutableString, StaticVec, StraightHasherBuilder};
|
use crate::utils::{ImmutableString, StaticVec, StraightHasherBuilder};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
use crate::fn_native::Shared;
|
use crate::{fn_native::Shared, parser::ScriptFnDef};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -262,6 +262,7 @@ impl Module {
|
|||||||
/// Set a script-defined function into the 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.
|
/// 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) -> u64 {
|
pub(crate) fn set_script_fn(&mut self, fn_def: ScriptFnDef) -> u64 {
|
||||||
// None + function name + number of arguments.
|
// None + function name + number of arguments.
|
||||||
let num_params = fn_def.params.len();
|
let num_params = fn_def.params.len();
|
||||||
@ -494,6 +495,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set a raw function but with a signature that is a scripted function, but the implementation is in Rust.
|
/// Set a raw function but with a signature that is a scripted function, but the implementation is in Rust.
|
||||||
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub(crate) fn set_raw_fn_as_scripted(
|
pub(crate) fn set_raw_fn_as_scripted(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<String>,
|
name: impl Into<String>,
|
||||||
@ -1235,7 +1237,7 @@ impl Module {
|
|||||||
variables.push((hash_var, value.clone()));
|
variables.push((hash_var, value.clone()));
|
||||||
}
|
}
|
||||||
// Index all Rust functions
|
// Index all Rust functions
|
||||||
for (&hash, (name, access, num_args, params, func)) in module.functions.iter() {
|
for (&_hash, (name, access, _num_args, params, func)) in module.functions.iter() {
|
||||||
match access {
|
match access {
|
||||||
// Private functions are not exported
|
// Private functions are not exported
|
||||||
FnAccess::Private => continue,
|
FnAccess::Private => continue,
|
||||||
@ -1245,10 +1247,10 @@ impl Module {
|
|||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if params.is_none() {
|
if params.is_none() {
|
||||||
let hash_qualified_script = if qualifiers.is_empty() {
|
let hash_qualified_script = if qualifiers.is_empty() {
|
||||||
hash
|
_hash
|
||||||
} else {
|
} else {
|
||||||
// Qualifiers + function name + number of arguments.
|
// Qualifiers + function name + number of arguments.
|
||||||
calc_fn_hash(qualifiers.iter().map(|&v| v), &name, *num_args, empty())
|
calc_fn_hash(qualifiers.iter().map(|&v| v), &name, *_num_args, empty())
|
||||||
};
|
};
|
||||||
functions.push((hash_qualified_script, func.clone()));
|
functions.push((hash_qualified_script, func.clone()));
|
||||||
continue;
|
continue;
|
||||||
@ -1730,15 +1732,16 @@ mod file {
|
|||||||
|
|
||||||
let ast = c.get(&file_path).unwrap();
|
let ast = c.get(&file_path).unwrap();
|
||||||
|
|
||||||
let mut module = Module::eval_ast_as_new(Scope::new(), ast, engine)?;
|
let mut _module = Module::eval_ast_as_new(Scope::new(), ast, engine)?;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_function"))]
|
||||||
ast.iter_functions(|access, name, num_args| match access {
|
ast.iter_functions(|access, name, num_args| match access {
|
||||||
FnAccess::Private => (),
|
FnAccess::Private => (),
|
||||||
FnAccess::Public => {
|
FnAccess::Public => {
|
||||||
let fn_name = name.to_string();
|
let fn_name = name.to_string();
|
||||||
let ast_lib = ast.lib().clone();
|
let ast_lib = ast.lib().clone();
|
||||||
|
|
||||||
module.set_raw_fn_as_scripted(
|
_module.set_raw_fn_as_scripted(
|
||||||
name,
|
name,
|
||||||
num_args,
|
num_args,
|
||||||
move |engine: &Engine, _, args: &mut [&mut Dynamic]| {
|
move |engine: &Engine, _, args: &mut [&mut Dynamic]| {
|
||||||
@ -1754,7 +1757,7 @@ mod file {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(module)
|
Ok(_module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,13 @@ use crate::engine::{
|
|||||||
};
|
};
|
||||||
use crate::fn_native::FnPtr;
|
use crate::fn_native::FnPtr;
|
||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
use crate::parser::{map_dynamic_to_expr, Expr, ReturnType, ScriptFnDef, Stmt, AST};
|
use crate::parser::{map_dynamic_to_expr, Expr, ScriptFnDef, Stmt, AST};
|
||||||
use crate::scope::{Entry as ScopeEntry, EntryType as ScopeEntryType, Scope};
|
use crate::scope::{Entry as ScopeEntry, EntryType as ScopeEntryType, Scope};
|
||||||
use crate::utils::StaticVec;
|
use crate::utils::StaticVec;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
use crate::parser::ReturnType;
|
||||||
|
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
use crate::parser::CustomExpr;
|
use crate::parser::CustomExpr;
|
||||||
|
|
||||||
@ -749,7 +752,8 @@ pub fn optimize_into_ast(
|
|||||||
level
|
level
|
||||||
};
|
};
|
||||||
|
|
||||||
let lib = if cfg!(not(feature = "no_function")) {
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
let lib = {
|
||||||
let mut module = Module::new();
|
let mut module = Module::new();
|
||||||
|
|
||||||
if !level.is_none() {
|
if !level.is_none() {
|
||||||
@ -811,10 +815,11 @@ pub fn optimize_into_ast(
|
|||||||
}
|
}
|
||||||
|
|
||||||
module
|
module
|
||||||
} else {
|
|
||||||
Default::default()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "no_function")]
|
||||||
|
let lib = Default::default();
|
||||||
|
|
||||||
AST::new(
|
AST::new(
|
||||||
match level {
|
match level {
|
||||||
OptimizationLevel::None => statements,
|
OptimizationLevel::None => statements,
|
||||||
|
Loading…
Reference in New Issue
Block a user