Merge branch 'master' into plugins
This commit is contained in:
commit
1c58bdb2a1
@ -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};
|
||||
|
1115
src/engine.rs
1115
src/engine.rs
File diff suppressed because it is too large
Load Diff
45
src/fn_args.rs
Normal file
45
src/fn_args.rs
Normal 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);
|
1115
src/fn_call.rs
1115
src/fn_call.rs
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
//! Module which defines the function registration mechanism.
|
||||
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
|
@ -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};
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Module which defines the function registration mechanism.
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::any::{Dynamic, Variant};
|
||||
|
@ -77,6 +77,7 @@ mod any;
|
||||
mod api;
|
||||
mod engine;
|
||||
mod error;
|
||||
mod fn_args;
|
||||
mod fn_call;
|
||||
mod fn_func;
|
||||
mod fn_native;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Module implementing the AST optimizer.
|
||||
|
||||
use crate::any::Dynamic;
|
||||
use crate::calc_fn_hash;
|
||||
use crate::engine::{
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Configuration settings for `Engine`.
|
||||
|
||||
use crate::engine::Engine;
|
||||
use crate::module::ModuleResolver;
|
||||
use crate::optimize::OptimizationLevel;
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
15
src/utils.rs
15
src/utils.rs
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user