Merge branch 'master' into plugins

This commit is contained in:
Stephen Chung 2020-07-23 18:46:25 +08:00
commit 1c58bdb2a1
13 changed files with 1204 additions and 1125 deletions

View File

@ -3,7 +3,7 @@
use crate::any::{Dynamic, Variant};
use crate::engine::{make_getter, make_setter, Engine, Imports, State, FN_IDX_GET, FN_IDX_SET};
use crate::error::ParseError;
use crate::fn_call::FuncArgs;
use crate::fn_args::FuncArgs;
use crate::fn_native::{IteratorFn, SendSync};
use crate::fn_register::RegisterFn;
use crate::module::{FuncReturn, Module};

File diff suppressed because it is too large Load Diff

45
src/fn_args.rs Normal file
View File

@ -0,0 +1,45 @@
//! Helper module which defines `FuncArgs` to make function calling easier.
#![allow(non_snake_case)]
use crate::any::{Dynamic, Variant};
use crate::utils::StaticVec;
/// Trait that represents arguments to a function call.
/// Any data type that can be converted into a `Vec<Dynamic>` can be used
/// as arguments to a function call.
pub trait FuncArgs {
/// Convert to a `StaticVec<Dynamic>` of the function call arguments.
fn into_vec(self) -> StaticVec<Dynamic>;
}
/// Macro to implement `FuncArgs` for tuples of standard types (each can be
/// converted into `Dynamic`).
macro_rules! impl_args {
($($p:ident),*) => {
impl<$($p: Variant + Clone),*> FuncArgs for ($($p,)*)
{
fn into_vec(self) -> StaticVec<Dynamic> {
let ($($p,)*) = self;
#[allow(unused_mut)]
let mut v = StaticVec::new();
$(v.push($p.into_dynamic());)*
v
}
}
impl_args!(@pop $($p),*);
};
(@pop) => {
};
(@pop $head:ident) => {
impl_args!();
};
(@pop $head:ident $(, $tail:ident)+) => {
impl_args!($($tail),*);
};
}
impl_args!(A, B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
//! Module which defines the function registration mechanism.
#![cfg(not(feature = "no_function"))]
#![allow(non_snake_case)]

View File

@ -1,4 +1,5 @@
//! Module containing interfaces with native-Rust functions.
//! Module defining interfaces to native-Rust functions.
use crate::any::Dynamic;
use crate::engine::Engine;
use crate::module::{FuncReturn, Module};

View File

@ -1,4 +1,5 @@
//! Module which defines the function registration mechanism.
#![allow(non_snake_case)]
use crate::any::{Dynamic, Variant};

View File

@ -77,6 +77,7 @@ mod any;
mod api;
mod engine;
mod error;
mod fn_args;
mod fn_call;
mod fn_func;
mod fn_native;

View File

@ -1,3 +1,5 @@
//! Module implementing the AST optimizer.
use crate::any::Dynamic;
use crate::calc_fn_hash;
use crate::engine::{

View File

@ -1,3 +1,5 @@
//! Configuration settings for `Engine`.
use crate::engine::Engine;
use crate::module::ModuleResolver;
use crate::optimize::OptimizationLevel;

View File

@ -1,4 +1,5 @@
//! Module containing implementation for custom syntax.
//! Module implementing custom syntax for `Engine`.
use crate::any::Dynamic;
use crate::engine::{Engine, Imports, State, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT};
use crate::error::{LexError, ParseError};
@ -188,4 +189,26 @@ impl Engine {
Ok(self)
}
/// Evaluate an expression tree.
///
/// ## WARNING - Low Level API
///
/// This function is very low level. It evaluates an expression from an AST.
pub fn eval_expression_tree(
&self,
context: &mut EvalContext,
scope: &mut Scope,
expr: &Expression,
) -> Result<Dynamic, Box<EvalAltResult>> {
self.eval_expr(
scope,
context.mods,
context.state,
context.lib,
context.this_ptr,
expr.expr(),
context.level,
)
}
}

View File

@ -1,4 +1,4 @@
//! A module containing all unsafe code.
//! A helper module containing unsafe utility functions.
use crate::any::Variant;
use crate::engine::State;

View File

@ -15,7 +15,7 @@ use crate::stdlib::{
iter::FromIterator,
mem,
mem::MaybeUninit,
ops::{Add, AddAssign, Deref, Drop, Index, IndexMut},
ops::{Add, AddAssign, Deref, DerefMut, Drop, Index, IndexMut},
str::FromStr,
string::{String, ToString},
vec::Vec,
@ -572,6 +572,19 @@ impl<T> AsMut<[T]> for StaticVec<T> {
}
}
impl<T> Deref for StaticVec<T> {
type Target = [T];
fn deref(&self) -> &Self::Target {
self.as_ref()
}
}
impl<T> DerefMut for StaticVec<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.as_mut()
}
}
impl<T> Index<usize> for StaticVec<T> {
type Output = T;