Reformat code files.
This commit is contained in:
parent
eb49a4b40a
commit
fce2c62f02
65
src/ast.rs
65
src/ast.rs
@ -12,17 +12,10 @@ use crate::INT;
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use crate::FLOAT;
|
use crate::FLOAT;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
|
||||||
use crate::engine::Array;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
|
||||||
use crate::engine::Map;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
use crate::engine::Imports;
|
use crate::engine::Imports;
|
||||||
|
|
||||||
use crate::stdlib::{
|
use crate::stdlib::{
|
||||||
any::TypeId,
|
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@ -141,14 +134,12 @@ impl AST {
|
|||||||
pub fn new(statements: Vec<Stmt>, lib: Module) -> Self {
|
pub fn new(statements: Vec<Stmt>, lib: Module) -> Self {
|
||||||
Self(statements, lib)
|
Self(statements, lib)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the statements.
|
/// Get the statements.
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn statements(&self) -> &[Stmt] {
|
pub(crate) fn statements(&self) -> &[Stmt] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// _[INTERNALS]_ Get the statements.
|
/// _[INTERNALS]_ Get the statements.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
@ -157,21 +148,18 @@ impl AST {
|
|||||||
pub fn statements(&self) -> &[Stmt] {
|
pub fn statements(&self) -> &[Stmt] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to the statements.
|
/// Get a mutable reference to the statements.
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn statements_mut(&mut self) -> &mut Vec<Stmt> {
|
pub(crate) fn statements_mut(&mut self) -> &mut Vec<Stmt> {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the internal `Module` containing all script-defined functions.
|
/// Get the internal `Module` containing all script-defined functions.
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn lib(&self) -> &Module {
|
pub(crate) fn lib(&self) -> &Module {
|
||||||
&self.1
|
&self.1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// _[INTERNALS]_ Get the internal `Module` containing all script-defined functions.
|
/// _[INTERNALS]_ Get the internal `Module` containing all script-defined functions.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
@ -180,7 +168,6 @@ impl AST {
|
|||||||
pub fn lib(&self) -> &Module {
|
pub fn lib(&self) -> &Module {
|
||||||
&self.1
|
&self.1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clone the `AST`'s functions into a new `AST`.
|
/// Clone the `AST`'s functions into a new `AST`.
|
||||||
/// No statements are cloned.
|
/// No statements are cloned.
|
||||||
///
|
///
|
||||||
@ -190,7 +177,6 @@ impl AST {
|
|||||||
pub fn clone_functions_only(&self) -> Self {
|
pub fn clone_functions_only(&self) -> Self {
|
||||||
self.clone_functions_only_filtered(|_, _, _| true)
|
self.clone_functions_only_filtered(|_, _, _| true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clone the `AST`'s functions into a new `AST` based on a filter predicate.
|
/// Clone the `AST`'s functions into a new `AST` based on a filter predicate.
|
||||||
/// No statements are cloned.
|
/// No statements are cloned.
|
||||||
///
|
///
|
||||||
@ -205,14 +191,12 @@ impl AST {
|
|||||||
functions.merge_filtered(&self.1, &mut filter);
|
functions.merge_filtered(&self.1, &mut filter);
|
||||||
Self(Default::default(), functions)
|
Self(Default::default(), functions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clone the `AST`'s script statements into a new `AST`.
|
/// Clone the `AST`'s script statements into a new `AST`.
|
||||||
/// No functions are cloned.
|
/// No functions are cloned.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn clone_statements_only(&self) -> Self {
|
pub fn clone_statements_only(&self) -> Self {
|
||||||
Self(self.0.clone(), Default::default())
|
Self(self.0.clone(), Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge two `AST` into one. Both `AST`'s are untouched and a new, merged, version
|
/// Merge two `AST` into one. Both `AST`'s are untouched and a new, merged, version
|
||||||
/// is returned.
|
/// is returned.
|
||||||
///
|
///
|
||||||
@ -266,7 +250,6 @@ impl AST {
|
|||||||
pub fn merge(&self, other: &Self) -> Self {
|
pub fn merge(&self, other: &Self) -> Self {
|
||||||
self.merge_filtered(other, |_, _, _| true)
|
self.merge_filtered(other, |_, _, _| true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combine one `AST` with another. The second `AST` is consumed.
|
/// Combine one `AST` with another. The second `AST` is consumed.
|
||||||
///
|
///
|
||||||
/// Statements in the second `AST` are simply appended to the end of the first _without any processing_.
|
/// Statements in the second `AST` are simply appended to the end of the first _without any processing_.
|
||||||
@ -319,7 +302,6 @@ impl AST {
|
|||||||
pub fn combine(&mut self, other: Self) -> &mut Self {
|
pub fn combine(&mut self, other: Self) -> &mut Self {
|
||||||
self.combine_filtered(other, |_, _, _| true)
|
self.combine_filtered(other, |_, _, _| true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge two `AST` into one. Both `AST`'s are untouched and a new, merged, version
|
/// Merge two `AST` into one. Both `AST`'s are untouched and a new, merged, version
|
||||||
/// is returned.
|
/// is returned.
|
||||||
///
|
///
|
||||||
@ -395,7 +377,6 @@ impl AST {
|
|||||||
|
|
||||||
Self::new(ast, functions)
|
Self::new(ast, functions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combine one `AST` with another. The second `AST` is consumed.
|
/// Combine one `AST` with another. The second `AST` is consumed.
|
||||||
///
|
///
|
||||||
/// Statements in the second `AST` are simply appended to the end of the first _without any processing_.
|
/// Statements in the second `AST` are simply appended to the end of the first _without any processing_.
|
||||||
@ -457,7 +438,6 @@ impl AST {
|
|||||||
functions.merge_filtered(&other.1, &mut filter);
|
functions.merge_filtered(&other.1, &mut filter);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filter out the functions, retaining only some based on a filter predicate.
|
/// Filter out the functions, retaining only some based on a filter predicate.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -486,7 +466,6 @@ impl AST {
|
|||||||
pub fn retain_functions(&mut self, filter: impl FnMut(FnAccess, &str, usize) -> bool) {
|
pub fn retain_functions(&mut self, filter: impl FnMut(FnAccess, &str, usize) -> bool) {
|
||||||
self.1.retain_functions(filter);
|
self.1.retain_functions(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate through all functions
|
/// Iterate through all functions
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -495,14 +474,12 @@ impl AST {
|
|||||||
) -> impl Iterator<Item = (FnAccess, &str, usize, Shared<ScriptFnDef>)> + 'a {
|
) -> impl Iterator<Item = (FnAccess, &str, usize, Shared<ScriptFnDef>)> + 'a {
|
||||||
self.1.iter_script_fn()
|
self.1.iter_script_fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all function definitions in the `AST`.
|
/// Clear all function definitions in the `AST`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn clear_functions(&mut self) {
|
pub fn clear_functions(&mut self) {
|
||||||
self.1 = Default::default();
|
self.1 = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all statements in the `AST`, leaving only function definitions.
|
/// Clear all statements in the `AST`, leaving only function definitions.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn clear_statements(&mut self) {
|
pub fn clear_statements(&mut self) {
|
||||||
@ -656,7 +633,6 @@ impl Stmt {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `Position` of this statement.
|
/// Get the `Position` of this statement.
|
||||||
pub fn position(&self) -> Position {
|
pub fn position(&self) -> Position {
|
||||||
match self {
|
match self {
|
||||||
@ -685,7 +661,6 @@ impl Stmt {
|
|||||||
Self::Share(x) => x.pos,
|
Self::Share(x) => x.pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override the `Position` of this statement.
|
/// Override the `Position` of this statement.
|
||||||
pub fn set_position(&mut self, new_pos: Position) -> &mut Self {
|
pub fn set_position(&mut self, new_pos: Position) -> &mut Self {
|
||||||
match self {
|
match self {
|
||||||
@ -718,7 +693,6 @@ impl Stmt {
|
|||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this statement self-terminated (i.e. no need for a semicolon terminator)?
|
/// Is this statement self-terminated (i.e. no need for a semicolon terminator)?
|
||||||
pub fn is_self_terminated(&self) -> bool {
|
pub fn is_self_terminated(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -747,7 +721,6 @@ impl Stmt {
|
|||||||
Self::Share(_) => false,
|
Self::Share(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this statement _pure_?
|
/// Is this statement _pure_?
|
||||||
pub fn is_pure(&self) -> bool {
|
pub fn is_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -861,6 +834,8 @@ pub struct FnCallExpr {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
/// Dynamic constant.
|
/// Dynamic constant.
|
||||||
|
/// Used to hold either an Array or Map literal for quick cloning.
|
||||||
|
/// All other primitive data types should use the appropriate variants for better speed.
|
||||||
DynamicConstant(Box<Dynamic>, Position),
|
DynamicConstant(Box<Dynamic>, Position),
|
||||||
/// Integer constant.
|
/// Integer constant.
|
||||||
IntegerConstant(INT, Position),
|
IntegerConstant(INT, Position),
|
||||||
@ -924,35 +899,6 @@ impl Default for Expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Expr {
|
impl Expr {
|
||||||
/// Get the type of an expression.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the expression's result type is not constant.
|
|
||||||
pub fn get_type_id(&self) -> Option<TypeId> {
|
|
||||||
Some(match self {
|
|
||||||
Self::Expr(x) => return x.get_type_id(),
|
|
||||||
|
|
||||||
Self::DynamicConstant(x, _) => x.type_id(),
|
|
||||||
Self::IntegerConstant(_, _) => TypeId::of::<INT>(),
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
|
||||||
Self::FloatConstant(_, _) => TypeId::of::<FLOAT>(),
|
|
||||||
Self::CharConstant(_, _) => TypeId::of::<char>(),
|
|
||||||
Self::StringConstant(_, _) => TypeId::of::<ImmutableString>(),
|
|
||||||
Self::FnPointer(_, _) => TypeId::of::<FnPtr>(),
|
|
||||||
Self::True(_) | Self::False(_) | Self::In(_, _) | Self::And(_, _) | Self::Or(_, _) => {
|
|
||||||
TypeId::of::<bool>()
|
|
||||||
}
|
|
||||||
Self::Unit(_) => TypeId::of::<()>(),
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
|
||||||
Self::Array(_, _) => TypeId::of::<Array>(),
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
|
||||||
Self::Map(_, _) => TypeId::of::<Map>(),
|
|
||||||
|
|
||||||
_ => return None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the `Dynamic` value of a constant expression.
|
/// Get the `Dynamic` value of a constant expression.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the expression is not constant.
|
/// Returns `None` if the expression is not constant.
|
||||||
@ -991,7 +937,6 @@ impl Expr {
|
|||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the expression a simple variable access?
|
/// Is the expression a simple variable access?
|
||||||
pub(crate) fn get_variable_access(&self, non_qualified: bool) -> Option<&str> {
|
pub(crate) fn get_variable_access(&self, non_qualified: bool) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
@ -999,7 +944,6 @@ impl Expr {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `Position` of the expression.
|
/// Get the `Position` of the expression.
|
||||||
pub fn position(&self) -> Position {
|
pub fn position(&self) -> Position {
|
||||||
match self {
|
match self {
|
||||||
@ -1030,7 +974,6 @@ impl Expr {
|
|||||||
Self::Custom(_, pos) => *pos,
|
Self::Custom(_, pos) => *pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override the `Position` of the expression.
|
/// Override the `Position` of the expression.
|
||||||
pub fn set_position(&mut self, new_pos: Position) -> &mut Self {
|
pub fn set_position(&mut self, new_pos: Position) -> &mut Self {
|
||||||
match self {
|
match self {
|
||||||
@ -1061,7 +1004,6 @@ impl Expr {
|
|||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the expression pure?
|
/// Is the expression pure?
|
||||||
///
|
///
|
||||||
/// A pure expression has no side effects.
|
/// A pure expression has no side effects.
|
||||||
@ -1084,7 +1026,6 @@ impl Expr {
|
|||||||
_ => self.is_constant(),
|
_ => self.is_constant(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the expression the unit `()` literal?
|
/// Is the expression the unit `()` literal?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_unit(&self) -> bool {
|
pub fn is_unit(&self) -> bool {
|
||||||
@ -1093,7 +1034,6 @@ impl Expr {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the expression a constant?
|
/// Is the expression a constant?
|
||||||
pub fn is_constant(&self) -> bool {
|
pub fn is_constant(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -1127,7 +1067,6 @@ impl Expr {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is a particular token allowed as a postfix operator to this expression?
|
/// Is a particular token allowed as a postfix operator to this expression?
|
||||||
pub fn is_valid_postfix(&self, token: &Token) -> bool {
|
pub fn is_valid_postfix(&self, token: &Token) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
@ -263,7 +263,6 @@ impl Dynamic {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does this `Dynamic` hold a shared data type
|
/// Does this `Dynamic` hold a shared data type
|
||||||
/// instead of one of the supported system primitive types?
|
/// instead of one of the supported system primitive types?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -274,7 +273,6 @@ impl Dynamic {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the value held by this `Dynamic` a particular type?
|
/// Is the value held by this `Dynamic` a particular type?
|
||||||
///
|
///
|
||||||
/// If the `Dynamic` is a Shared variant checking is performed on
|
/// If the `Dynamic` is a Shared variant checking is performed on
|
||||||
@ -289,7 +287,6 @@ impl Dynamic {
|
|||||||
|
|
||||||
self.type_id() == target_type_id
|
self.type_id() == target_type_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the TypeId of the value held by this `Dynamic`.
|
/// Get the TypeId of the value held by this `Dynamic`.
|
||||||
///
|
///
|
||||||
/// # Panics or Deadlocks When Value is Shared
|
/// # Panics or Deadlocks When Value is Shared
|
||||||
@ -323,7 +320,6 @@ impl Dynamic {
|
|||||||
Union::Shared(cell) => (*cell.read().unwrap()).type_id(),
|
Union::Shared(cell) => (*cell.read().unwrap()).type_id(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the name of the type of the value held by this `Dynamic`.
|
/// Get the name of the type of the value held by this `Dynamic`.
|
||||||
///
|
///
|
||||||
/// # Panics or Deadlocks When Value is Shared
|
/// # Panics or Deadlocks When Value is Shared
|
||||||
|
@ -84,7 +84,6 @@ impl Engine {
|
|||||||
self.global_module.set_raw_fn(name, arg_types, func);
|
self.global_module.set_raw_fn(name, arg_types, func);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a custom type for use with the `Engine`.
|
/// Register a custom type for use with the `Engine`.
|
||||||
/// The type must implement `Clone`.
|
/// The type must implement `Clone`.
|
||||||
///
|
///
|
||||||
@ -126,7 +125,6 @@ impl Engine {
|
|||||||
pub fn register_type<T: Variant + Clone>(&mut self) -> &mut Self {
|
pub fn register_type<T: Variant + Clone>(&mut self) -> &mut Self {
|
||||||
self.register_type_with_name::<T>(type_name::<T>())
|
self.register_type_with_name::<T>(type_name::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a custom type for use with the `Engine`, with a pretty-print name
|
/// Register a custom type for use with the `Engine`, with a pretty-print name
|
||||||
/// for the `type_of` function. The type must implement `Clone`.
|
/// for the `type_of` function. The type must implement `Clone`.
|
||||||
///
|
///
|
||||||
@ -177,7 +175,6 @@ impl Engine {
|
|||||||
self.type_names.insert(type_name::<T>().into(), name.into());
|
self.type_names.insert(type_name::<T>().into(), name.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register an iterator adapter for an iterable type with the `Engine`.
|
/// Register an iterator adapter for an iterable type with the `Engine`.
|
||||||
/// This is an advanced feature.
|
/// This is an advanced feature.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -189,7 +186,6 @@ impl Engine {
|
|||||||
self.global_module.set_iterable::<T>();
|
self.global_module.set_iterable::<T>();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a getter function for a member of a registered type with the `Engine`.
|
/// Register a getter function for a member of a registered type with the `Engine`.
|
||||||
///
|
///
|
||||||
/// The function signature must start with `&mut self` and not `&self`.
|
/// The function signature must start with `&mut self` and not `&self`.
|
||||||
@ -238,7 +234,6 @@ impl Engine {
|
|||||||
{
|
{
|
||||||
self.register_fn(&make_getter(name), callback)
|
self.register_fn(&make_getter(name), callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a getter function for a member of a registered type with the `Engine`.
|
/// Register a getter function for a member of a registered type with the `Engine`.
|
||||||
/// Returns `Result<Dynamic, Box<EvalAltResult>>`.
|
/// Returns `Result<Dynamic, Box<EvalAltResult>>`.
|
||||||
///
|
///
|
||||||
@ -286,7 +281,6 @@ impl Engine {
|
|||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.register_result_fn(&make_getter(name), callback)
|
self.register_result_fn(&make_getter(name), callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a setter function for a member of a registered type with the `Engine`.
|
/// Register a setter function for a member of a registered type with the `Engine`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -336,7 +330,6 @@ impl Engine {
|
|||||||
{
|
{
|
||||||
self.register_fn(&make_setter(name), callback)
|
self.register_fn(&make_setter(name), callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a setter function for a member of a registered type with the `Engine`.
|
/// Register a setter function for a member of a registered type with the `Engine`.
|
||||||
/// Returns `Result<(), Box<EvalAltResult>>`.
|
/// Returns `Result<(), Box<EvalAltResult>>`.
|
||||||
///
|
///
|
||||||
@ -392,7 +385,6 @@ impl Engine {
|
|||||||
callback(obj, value).map(Into::into)
|
callback(obj, value).map(Into::into)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Short-hand for registering both getter and setter functions
|
/// Short-hand for registering both getter and setter functions
|
||||||
/// of a registered type with the `Engine`.
|
/// of a registered type with the `Engine`.
|
||||||
///
|
///
|
||||||
@ -445,7 +437,6 @@ impl Engine {
|
|||||||
{
|
{
|
||||||
self.register_get(name, get_fn).register_set(name, set_fn)
|
self.register_get(name, get_fn).register_set(name, set_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register an index getter for a custom type with the `Engine`.
|
/// Register an index getter for a custom type with the `Engine`.
|
||||||
///
|
///
|
||||||
/// The function signature must start with `&mut self` and not `&self`.
|
/// The function signature must start with `&mut self` and not `&self`.
|
||||||
@ -514,7 +505,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.register_fn(FN_IDX_GET, callback)
|
self.register_fn(FN_IDX_GET, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register an index getter for a custom type with the `Engine`.
|
/// Register an index getter for a custom type with the `Engine`.
|
||||||
/// Returns `Result<Dynamic, Box<EvalAltResult>>`.
|
/// Returns `Result<Dynamic, Box<EvalAltResult>>`.
|
||||||
///
|
///
|
||||||
@ -585,7 +575,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.register_result_fn(FN_IDX_GET, callback)
|
self.register_result_fn(FN_IDX_GET, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register an index setter for a custom type with the `Engine`.
|
/// Register an index setter for a custom type with the `Engine`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
@ -654,7 +643,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.register_fn(FN_IDX_SET, callback)
|
self.register_fn(FN_IDX_SET, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register an index setter for a custom type with the `Engine`.
|
/// Register an index setter for a custom type with the `Engine`.
|
||||||
/// Returns `Result<(), Box<EvalAltResult>>`.
|
/// Returns `Result<(), Box<EvalAltResult>>`.
|
||||||
///
|
///
|
||||||
@ -729,7 +717,6 @@ impl Engine {
|
|||||||
callback(obj, index, value).map(Into::into)
|
callback(obj, index, value).map(Into::into)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Short-hand for register both index getter and setter functions for a custom type with the `Engine`.
|
/// Short-hand for register both index getter and setter functions for a custom type with the `Engine`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
@ -785,7 +772,6 @@ impl Engine {
|
|||||||
self.register_indexer_get(getter)
|
self.register_indexer_get(getter)
|
||||||
.register_indexer_set(setter)
|
.register_indexer_set(setter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a string into an `AST`, which can be used later for evaluation.
|
/// Compile a string into an `AST`, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -809,7 +795,6 @@ impl Engine {
|
|||||||
pub fn compile(&self, script: &str) -> Result<AST, ParseError> {
|
pub fn compile(&self, script: &str) -> Result<AST, ParseError> {
|
||||||
self.compile_with_scope(&Default::default(), script)
|
self.compile_with_scope(&Default::default(), script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a string into an `AST` using own scope, which can be used later for evaluation.
|
/// Compile a string into an `AST` using own scope, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
/// The scope is useful for passing constants into the script for optimization
|
/// The scope is useful for passing constants into the script for optimization
|
||||||
@ -852,7 +837,6 @@ impl Engine {
|
|||||||
pub fn compile_with_scope(&self, scope: &Scope, script: &str) -> Result<AST, ParseError> {
|
pub fn compile_with_scope(&self, scope: &Scope, script: &str) -> Result<AST, ParseError> {
|
||||||
self.compile_scripts_with_scope(scope, &[script])
|
self.compile_scripts_with_scope(scope, &[script])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When passed a list of strings, first join the strings into one large script,
|
/// When passed a list of strings, first join the strings into one large script,
|
||||||
/// and then compile them into an `AST` using own scope, which can be used later for evaluation.
|
/// and then compile them into an `AST` using own scope, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
@ -907,7 +891,6 @@ impl Engine {
|
|||||||
) -> Result<AST, ParseError> {
|
) -> Result<AST, ParseError> {
|
||||||
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level)
|
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Join a list of strings and compile into an `AST` using own scope at a specific optimization level.
|
/// Join a list of strings and compile into an `AST` using own scope at a specific optimization level.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn compile_with_scope_and_optimization_level(
|
pub(crate) fn compile_with_scope_and_optimization_level(
|
||||||
@ -920,7 +903,6 @@ impl Engine {
|
|||||||
let stream = self.lex(scripts, None);
|
let stream = self.lex(scripts, None);
|
||||||
self.parse(hash, &mut stream.peekable(), scope, optimization_level)
|
self.parse(hash, &mut stream.peekable(), scope, optimization_level)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the contents of a file into a string.
|
/// Read the contents of a file into a string.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@ -944,7 +926,6 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(contents)
|
Ok(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a script file into an `AST`, which can be used later for evaluation.
|
/// Compile a script file into an `AST`, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -971,7 +952,6 @@ impl Engine {
|
|||||||
pub fn compile_file(&self, path: PathBuf) -> Result<AST, Box<EvalAltResult>> {
|
pub fn compile_file(&self, path: PathBuf) -> Result<AST, Box<EvalAltResult>> {
|
||||||
self.compile_file_with_scope(&Default::default(), path)
|
self.compile_file_with_scope(&Default::default(), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a script file into an `AST` using own scope, which can be used later for evaluation.
|
/// Compile a script file into an `AST` using own scope, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
/// The scope is useful for passing constants into the script for optimization
|
/// The scope is useful for passing constants into the script for optimization
|
||||||
@ -1013,7 +993,6 @@ impl Engine {
|
|||||||
) -> Result<AST, Box<EvalAltResult>> {
|
) -> Result<AST, Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?))
|
Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a JSON string into a map.
|
/// Parse a JSON string into a map.
|
||||||
///
|
///
|
||||||
/// The JSON string must be an object hash. It cannot be a simple JavaScript primitive.
|
/// The JSON string must be an object hash. It cannot be a simple JavaScript primitive.
|
||||||
@ -1098,7 +1077,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.eval_ast_with_scope(&mut scope, &ast)
|
self.eval_ast_with_scope(&mut scope, &ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a string containing an expression into an `AST`,
|
/// Compile a string containing an expression into an `AST`,
|
||||||
/// which can be used later for evaluation.
|
/// which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
@ -1123,7 +1101,6 @@ impl Engine {
|
|||||||
pub fn compile_expression(&self, script: &str) -> Result<AST, ParseError> {
|
pub fn compile_expression(&self, script: &str) -> Result<AST, ParseError> {
|
||||||
self.compile_expression_with_scope(&Default::default(), script)
|
self.compile_expression_with_scope(&Default::default(), script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a string containing an expression into an `AST` using own scope,
|
/// Compile a string containing an expression into an `AST` using own scope,
|
||||||
/// which can be used later for evaluation.
|
/// which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
@ -1176,7 +1153,6 @@ impl Engine {
|
|||||||
let mut peekable = stream.peekable();
|
let mut peekable = stream.peekable();
|
||||||
self.parse_global_expr(hash, &mut peekable, scope, self.optimization_level)
|
self.parse_global_expr(hash, &mut peekable, scope, self.optimization_level)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a script file.
|
/// Evaluate a script file.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1198,7 +1174,6 @@ impl Engine {
|
|||||||
pub fn eval_file<T: Variant + Clone>(&self, path: PathBuf) -> Result<T, Box<EvalAltResult>> {
|
pub fn eval_file<T: Variant + Clone>(&self, path: PathBuf) -> Result<T, Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| self.eval::<T>(&contents))
|
Self::read_file(path).and_then(|contents| self.eval::<T>(&contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a script file with own scope.
|
/// Evaluate a script file with own scope.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1228,7 +1203,6 @@ impl Engine {
|
|||||||
) -> Result<T, Box<EvalAltResult>> {
|
) -> Result<T, Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| self.eval_with_scope::<T>(scope, &contents))
|
Self::read_file(path).and_then(|contents| self.eval_with_scope::<T>(scope, &contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string.
|
/// Evaluate a string.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1247,7 +1221,6 @@ impl Engine {
|
|||||||
pub fn eval<T: Variant + Clone>(&self, script: &str) -> Result<T, Box<EvalAltResult>> {
|
pub fn eval<T: Variant + Clone>(&self, script: &str) -> Result<T, Box<EvalAltResult>> {
|
||||||
self.eval_with_scope(&mut Default::default(), script)
|
self.eval_with_scope(&mut Default::default(), script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string with own scope.
|
/// Evaluate a string with own scope.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1283,7 +1256,6 @@ impl Engine {
|
|||||||
)?;
|
)?;
|
||||||
self.eval_ast_with_scope(scope, &ast)
|
self.eval_ast_with_scope(scope, &ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string containing an expression.
|
/// Evaluate a string containing an expression.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1305,7 +1277,6 @@ impl Engine {
|
|||||||
) -> Result<T, Box<EvalAltResult>> {
|
) -> Result<T, Box<EvalAltResult>> {
|
||||||
self.eval_expression_with_scope(&mut Default::default(), script)
|
self.eval_expression_with_scope(&mut Default::default(), script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string containing an expression with own scope.
|
/// Evaluate a string containing an expression with own scope.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1340,7 +1311,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.eval_ast_with_scope(scope, &ast)
|
self.eval_ast_with_scope(scope, &ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an `AST`.
|
/// Evaluate an `AST`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1363,7 +1333,6 @@ impl Engine {
|
|||||||
pub fn eval_ast<T: Variant + Clone>(&self, ast: &AST) -> Result<T, Box<EvalAltResult>> {
|
pub fn eval_ast<T: Variant + Clone>(&self, ast: &AST) -> Result<T, Box<EvalAltResult>> {
|
||||||
self.eval_ast_with_scope(&mut Default::default(), ast)
|
self.eval_ast_with_scope(&mut Default::default(), ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an `AST` with own scope.
|
/// Evaluate an `AST` with own scope.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1413,7 +1382,6 @@ impl Engine {
|
|||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an `AST` with own scope.
|
/// Evaluate an `AST` with own scope.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn eval_ast_with_scope_raw<'a>(
|
pub(crate) fn eval_ast_with_scope_raw<'a>(
|
||||||
@ -1424,7 +1392,6 @@ impl Engine {
|
|||||||
) -> Result<(Dynamic, u64), Box<EvalAltResult>> {
|
) -> Result<(Dynamic, u64), Box<EvalAltResult>> {
|
||||||
self.eval_statements_raw(scope, mods, ast.statements(), &[ast.lib()])
|
self.eval_statements_raw(scope, mods, ast.statements(), &[ast.lib()])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a file, but throw away the result and only return error (if any).
|
/// Evaluate a file, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
@ -1433,7 +1400,6 @@ impl Engine {
|
|||||||
pub fn consume_file(&self, path: PathBuf) -> Result<(), Box<EvalAltResult>> {
|
pub fn consume_file(&self, path: PathBuf) -> Result<(), Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| self.consume(&contents))
|
Self::read_file(path).and_then(|contents| self.consume(&contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a file with own scope, but throw away the result and only return error (if any).
|
/// Evaluate a file with own scope, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
@ -1446,14 +1412,12 @@ impl Engine {
|
|||||||
) -> Result<(), Box<EvalAltResult>> {
|
) -> Result<(), Box<EvalAltResult>> {
|
||||||
Self::read_file(path).and_then(|contents| self.consume_with_scope(scope, &contents))
|
Self::read_file(path).and_then(|contents| self.consume_with_scope(scope, &contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string, but throw away the result and only return error (if any).
|
/// Evaluate a string, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn consume(&self, script: &str) -> Result<(), Box<EvalAltResult>> {
|
pub fn consume(&self, script: &str) -> Result<(), Box<EvalAltResult>> {
|
||||||
self.consume_with_scope(&mut Default::default(), script)
|
self.consume_with_scope(&mut Default::default(), script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string with own scope, but throw away the result and only return error (if any).
|
/// Evaluate a string with own scope, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1468,14 +1432,12 @@ impl Engine {
|
|||||||
let ast = self.parse(hash, &mut stream.peekable(), scope, self.optimization_level)?;
|
let ast = self.parse(hash, &mut stream.peekable(), scope, self.optimization_level)?;
|
||||||
self.consume_ast_with_scope(scope, &ast)
|
self.consume_ast_with_scope(scope, &ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an AST, but throw away the result and only return error (if any).
|
/// Evaluate an AST, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn consume_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
pub fn consume_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
||||||
self.consume_ast_with_scope(&mut Default::default(), ast)
|
self.consume_ast_with_scope(&mut Default::default(), ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an `AST` with own scope, but throw away the result and only return error (if any).
|
/// Evaluate an `AST` with own scope, but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -1488,7 +1450,6 @@ impl Engine {
|
|||||||
self.eval_statements_raw(scope, &mut mods, ast.statements(), &[ast.lib()])
|
self.eval_statements_raw(scope, &mut mods, ast.statements(), &[ast.lib()])
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call a script function defined in an `AST` with multiple arguments.
|
/// Call a script function defined in an `AST` with multiple arguments.
|
||||||
/// Arguments are passed as a tuple.
|
/// Arguments are passed as a tuple.
|
||||||
///
|
///
|
||||||
@ -1551,7 +1512,6 @@ impl Engine {
|
|||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call a script function defined in an `AST` with multiple `Dynamic` arguments
|
/// Call a script function defined in an `AST` with multiple `Dynamic` arguments
|
||||||
/// and optionally a value for binding to the 'this' pointer.
|
/// and optionally a value for binding to the 'this' pointer.
|
||||||
///
|
///
|
||||||
@ -1615,7 +1575,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.call_fn_dynamic_raw(scope, &[lib.as_ref()], name, &mut this_ptr, args.as_mut())
|
self.call_fn_dynamic_raw(scope, &[lib.as_ref()], name, &mut this_ptr, args.as_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call a script function defined in an `AST` with multiple `Dynamic` arguments.
|
/// Call a script function defined in an `AST` with multiple `Dynamic` arguments.
|
||||||
///
|
///
|
||||||
/// ## WARNING
|
/// ## WARNING
|
||||||
@ -1649,7 +1608,6 @@ impl Engine {
|
|||||||
|
|
||||||
self.call_script_fn(scope, &mut mods, &mut state, lib, this_ptr, fn_def, args, 0)
|
self.call_script_fn(scope, &mut mods, &mut state, lib, this_ptr, fn_def, args, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optimize the `AST` with constants defined in an external Scope.
|
/// Optimize the `AST` with constants defined in an external Scope.
|
||||||
/// An optimized copy of the `AST` is returned while the original `AST` is consumed.
|
/// An optimized copy of the `AST` is returned while the original `AST` is consumed.
|
||||||
///
|
///
|
||||||
@ -1683,7 +1641,6 @@ impl Engine {
|
|||||||
let stmt = mem::take(ast.statements_mut());
|
let stmt = mem::take(ast.statements_mut());
|
||||||
optimize_into_ast(self, scope, stmt, lib, optimization_level)
|
optimize_into_ast(self, scope, stmt, lib, optimization_level)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provide a callback that will be invoked before each variable access.
|
/// Provide a callback that will be invoked before each variable access.
|
||||||
///
|
///
|
||||||
/// ## Return Value of Callback
|
/// ## Return Value of Callback
|
||||||
@ -1726,7 +1683,6 @@ impl Engine {
|
|||||||
self.resolve_var = Some(Box::new(callback));
|
self.resolve_var = Some(Box::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a callback for script evaluation progress.
|
/// Register a callback for script evaluation progress.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1769,7 +1725,6 @@ impl Engine {
|
|||||||
self.progress = Some(Box::new(callback));
|
self.progress = Some(Box::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override default action of `print` (print to stdout using `println!`)
|
/// Override default action of `print` (print to stdout using `println!`)
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1799,7 +1754,6 @@ impl Engine {
|
|||||||
self.print = Box::new(callback);
|
self.print = Box::new(callback);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override default action of `debug` (print to stdout using `println!`)
|
/// Override default action of `debug` (print to stdout using `println!`)
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
@ -27,7 +27,6 @@ impl Engine {
|
|||||||
self.packages.push(package.into());
|
self.packages.push(package.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Control whether and how the `Engine` will optimize an AST after compilation.
|
/// Control whether and how the `Engine` will optimize an AST after compilation.
|
||||||
///
|
///
|
||||||
/// Not available under the `no_optimize` feature.
|
/// Not available under the `no_optimize` feature.
|
||||||
@ -37,7 +36,6 @@ impl Engine {
|
|||||||
self.optimization_level = optimization_level;
|
self.optimization_level = optimization_level;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current optimization level.
|
/// The current optimization level.
|
||||||
/// It controls whether and how the `Engine` will optimize an AST after compilation.
|
/// It controls whether and how the `Engine` will optimize an AST after compilation.
|
||||||
///
|
///
|
||||||
@ -47,7 +45,6 @@ impl Engine {
|
|||||||
pub fn optimization_level(&self) -> OptimizationLevel {
|
pub fn optimization_level(&self) -> OptimizationLevel {
|
||||||
self.optimization_level
|
self.optimization_level
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum levels of function calls allowed for a script in order to avoid
|
/// Set the maximum levels of function calls allowed for a script in order to avoid
|
||||||
/// infinite recursion and stack overflows.
|
/// infinite recursion and stack overflows.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
@ -56,14 +53,12 @@ impl Engine {
|
|||||||
self.limits.max_call_stack_depth = levels;
|
self.limits.max_call_stack_depth = levels;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum levels of function calls allowed for a script.
|
/// The maximum levels of function calls allowed for a script.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn max_call_levels(&self) -> usize {
|
pub fn max_call_levels(&self) -> usize {
|
||||||
self.limits.max_call_stack_depth
|
self.limits.max_call_stack_depth
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum number of operations allowed for a script to run to avoid
|
/// Set the maximum number of operations allowed for a script to run to avoid
|
||||||
/// consuming too much resources (0 for unlimited).
|
/// consuming too much resources (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
@ -76,14 +71,12 @@ impl Engine {
|
|||||||
};
|
};
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum number of operations allowed for a script to run (0 for unlimited).
|
/// The maximum number of operations allowed for a script to run (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn max_operations(&self) -> u64 {
|
pub fn max_operations(&self) -> u64 {
|
||||||
self.limits.max_operations
|
self.limits.max_operations
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum number of imported modules allowed for a script.
|
/// Set the maximum number of imported modules allowed for a script.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -92,7 +85,6 @@ impl Engine {
|
|||||||
self.limits.max_modules = modules;
|
self.limits.max_modules = modules;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum number of imported modules allowed for a script.
|
/// The maximum number of imported modules allowed for a script.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -100,7 +92,6 @@ impl Engine {
|
|||||||
pub fn max_modules(&self) -> usize {
|
pub fn max_modules(&self) -> usize {
|
||||||
self.limits.max_modules
|
self.limits.max_modules
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the depth limits for expressions (0 for unlimited).
|
/// Set the depth limits for expressions (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -124,14 +115,12 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The depth limit for expressions (0 for unlimited).
|
/// The depth limit for expressions (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn max_expr_depth(&self) -> usize {
|
pub fn max_expr_depth(&self) -> usize {
|
||||||
self.limits.max_expr_depth
|
self.limits.max_expr_depth
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The depth limit for expressions in functions (0 for unlimited).
|
/// The depth limit for expressions in functions (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
@ -139,7 +128,6 @@ impl Engine {
|
|||||||
pub fn max_function_expr_depth(&self) -> usize {
|
pub fn max_function_expr_depth(&self) -> usize {
|
||||||
self.limits.max_function_expr_depth
|
self.limits.max_function_expr_depth
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum length of strings (0 for unlimited).
|
/// Set the maximum length of strings (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -147,14 +135,12 @@ impl Engine {
|
|||||||
self.limits.max_string_size = if max_size == usize::MAX { 0 } else { max_size };
|
self.limits.max_string_size = if max_size == usize::MAX { 0 } else { max_size };
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum length of strings (0 for unlimited).
|
/// The maximum length of strings (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn max_string_size(&self) -> usize {
|
pub fn max_string_size(&self) -> usize {
|
||||||
self.limits.max_string_size
|
self.limits.max_string_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum length of arrays (0 for unlimited).
|
/// Set the maximum length of arrays (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -163,7 +149,6 @@ impl Engine {
|
|||||||
self.limits.max_array_size = if max_size == usize::MAX { 0 } else { max_size };
|
self.limits.max_array_size = if max_size == usize::MAX { 0 } else { max_size };
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum length of arrays (0 for unlimited).
|
/// The maximum length of arrays (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -171,7 +156,6 @@ impl Engine {
|
|||||||
pub fn max_array_size(&self) -> usize {
|
pub fn max_array_size(&self) -> usize {
|
||||||
self.limits.max_array_size
|
self.limits.max_array_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum length of object maps (0 for unlimited).
|
/// Set the maximum length of object maps (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
@ -180,7 +164,6 @@ impl Engine {
|
|||||||
self.limits.max_map_size = if max_size == usize::MAX { 0 } else { max_size };
|
self.limits.max_map_size = if max_size == usize::MAX { 0 } else { max_size };
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum length of object maps (0 for unlimited).
|
/// The maximum length of object maps (0 for unlimited).
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
@ -188,7 +171,6 @@ impl Engine {
|
|||||||
pub fn max_map_size(&self) -> usize {
|
pub fn max_map_size(&self) -> usize {
|
||||||
self.limits.max_map_size
|
self.limits.max_map_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the module resolution service used by the `Engine`.
|
/// Set the module resolution service used by the `Engine`.
|
||||||
///
|
///
|
||||||
/// Not available under the `no_module` feature.
|
/// Not available under the `no_module` feature.
|
||||||
@ -201,7 +183,6 @@ impl Engine {
|
|||||||
self.module_resolver = resolver.map(|f| Box::new(f) as Box<dyn ModuleResolver>);
|
self.module_resolver = resolver.map(|f| Box::new(f) as Box<dyn ModuleResolver>);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable a particular keyword or operator in the language.
|
/// Disable a particular keyword or operator in the language.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
@ -243,7 +224,6 @@ impl Engine {
|
|||||||
self.disabled_symbols.insert(symbol.into());
|
self.disabled_symbols.insert(symbol.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a custom operator into the language.
|
/// Register a custom operator into the language.
|
||||||
///
|
///
|
||||||
/// The operator must be a valid identifier (i.e. it cannot be a symbol).
|
/// The operator must be a valid identifier (i.e. it cannot be a symbol).
|
||||||
|
@ -303,7 +303,6 @@ impl EvalAltResult {
|
|||||||
Self::LoopBreak(_, _) | Self::Return(_, _) => unreachable!(),
|
Self::LoopBreak(_, _) | Self::Return(_, _) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this error a system exception?
|
/// Is this error a system exception?
|
||||||
pub fn is_system_exception(&self) -> bool {
|
pub fn is_system_exception(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -322,7 +321,6 @@ impl EvalAltResult {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `Position` of this error.
|
/// Get the `Position` of this error.
|
||||||
pub fn position(&self) -> Position {
|
pub fn position(&self) -> Position {
|
||||||
match self {
|
match self {
|
||||||
@ -356,7 +354,6 @@ impl EvalAltResult {
|
|||||||
| Self::Return(_, pos) => *pos,
|
| Self::Return(_, pos) => *pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override the `Position` of this error.
|
/// Override the `Position` of this error.
|
||||||
pub fn set_position(&mut self, new_position: Position) {
|
pub fn set_position(&mut self, new_position: Position) {
|
||||||
match self {
|
match self {
|
||||||
@ -390,7 +387,6 @@ impl EvalAltResult {
|
|||||||
| Self::Return(_, pos) => *pos = new_position,
|
| Self::Return(_, pos) => *pos = new_position,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume the current `EvalAltResult` and return a new one with the specified `Position`
|
/// Consume the current `EvalAltResult` and return a new one with the specified `Position`
|
||||||
/// if the current position is `Position::None`.
|
/// if the current position is `Position::None`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -193,7 +193,6 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a custom syntax with the `Engine`.
|
/// Register a custom syntax with the `Engine`.
|
||||||
///
|
///
|
||||||
/// ## WARNING - Low Level API
|
/// ## WARNING - Low Level API
|
||||||
|
Loading…
Reference in New Issue
Block a user