Restructure code base.
This commit is contained in:
parent
38884ede46
commit
64b889fb95
5
src/api/mod.rs
Normal file
5
src/api/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
//! Module defining the public API of the Rhai engine.
|
||||
|
||||
pub mod deprecated;
|
||||
pub mod public;
|
||||
pub mod settings;
|
@ -1,14 +1,12 @@
|
||||
//! Module that defines the extern API of [`Engine`].
|
||||
//! Module that defines the public API of [`Engine`].
|
||||
|
||||
use crate::dynamic::Variant;
|
||||
use crate::engine::{EvalContext, EvalState, Imports};
|
||||
use crate::fn_call::FnCallArgs;
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::fn_register::RegisterNativeFunction;
|
||||
use crate::parse::ParseState;
|
||||
use crate::func::{call::FnCallArgs, native::SendSync, register::RegisterNativeFunction};
|
||||
use crate::parser::ParseState;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{
|
||||
scope::Scope, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, Identifier, Module,
|
||||
NativeCallContext, ParseError, Position, RhaiResult, Shared, AST,
|
||||
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, Identifier, Module, NativeCallContext,
|
||||
ParseError, Position, RhaiResult, Scope, Shared, AST,
|
||||
};
|
||||
use std::any::{type_name, TypeId};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -937,12 +935,12 @@ impl Engine {
|
||||
name: impl AsRef<str> + Into<Identifier>,
|
||||
module: Shared<Module>,
|
||||
) {
|
||||
let separator = crate::token::Token::DoubleColon.syntax();
|
||||
let separator = crate::tokenizer::Token::DoubleColon.syntax();
|
||||
|
||||
if !name.as_ref().contains(separator.as_ref()) {
|
||||
if !module.is_indexed() {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::fn_native::shared_take_or_clone(module);
|
||||
let mut module = crate::func::native::shared_take_or_clone(module);
|
||||
module.build_index();
|
||||
root.insert(name.into(), module.into());
|
||||
} else {
|
||||
@ -960,7 +958,7 @@ impl Engine {
|
||||
root.insert(sub_module.into(), m.into());
|
||||
} else {
|
||||
let m = root.remove(sub_module).expect("contains sub-module");
|
||||
let mut m = crate::fn_native::shared_take_or_clone(m);
|
||||
let mut m = crate::func::native::shared_take_or_clone(m);
|
||||
register_static_module_raw(m.sub_modules_mut(), remainder, module);
|
||||
m.build_index();
|
||||
root.insert(sub_module.into(), m.into());
|
||||
@ -1053,7 +1051,7 @@ impl Engine {
|
||||
) -> Result<AST, Box<EvalAltResult>> {
|
||||
use crate::{
|
||||
ast::{ASTNode, Expr, Stmt},
|
||||
fn_native::shared_take_or_clone,
|
||||
func::native::shared_take_or_clone,
|
||||
module::resolvers::StaticModuleResolver,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
@ -1349,7 +1347,7 @@ impl Engine {
|
||||
json: impl AsRef<str>,
|
||||
has_null: bool,
|
||||
) -> Result<Map, Box<EvalAltResult>> {
|
||||
use crate::token::Token;
|
||||
use crate::tokenizer::Token;
|
||||
|
||||
fn parse_json_inner(
|
||||
engine: &Engine,
|
||||
@ -2026,7 +2024,7 @@ impl Engine {
|
||||
|
||||
// Check for data race.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
crate::fn_call::ensure_no_data_race(name, args, false)?;
|
||||
crate::func::call::ensure_no_data_race(name, args, false)?;
|
||||
|
||||
self.call_script_fn(
|
||||
scope,
|
||||
@ -2084,7 +2082,7 @@ impl Engine {
|
||||
|
||||
let statements = std::mem::take(ast.statements_mut());
|
||||
|
||||
crate::optimize::optimize_into_ast(self, scope, statements, lib, optimization_level)
|
||||
crate::optimizer::optimize_into_ast(self, scope, statements, lib, optimization_level)
|
||||
}
|
||||
/// _(metadata)_ Generate a list of all registered functions.
|
||||
/// Exported under the `metadata` feature only.
|
||||
@ -2184,14 +2182,14 @@ impl Engine {
|
||||
/// > `Fn(token: Token, pos: Position, state: &TokenizeState) -> Token`
|
||||
///
|
||||
/// where:
|
||||
/// * [`token`][crate::token::Token]: current token parsed
|
||||
/// * [`token`][crate::tokenizer::Token]: current token parsed
|
||||
/// * [`pos`][`Position`]: location of the token
|
||||
/// * [`state`][crate::token::TokenizeState]: current state of the tokenizer
|
||||
/// * [`state`][crate::tokenizer::TokenizeState]: current state of the tokenizer
|
||||
///
|
||||
/// ## Raising errors
|
||||
///
|
||||
/// It is possible to raise a parsing error by returning
|
||||
/// [`Token::LexError`][crate::token::Token::LexError] as the mapped token.
|
||||
/// [`Token::LexError`][crate::tokenizer::Token::LexError] as the mapped token.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@ -2225,7 +2223,11 @@ impl Engine {
|
||||
#[inline(always)]
|
||||
pub fn on_parse_token(
|
||||
&mut self,
|
||||
callback: impl Fn(crate::token::Token, Position, &crate::token::TokenizeState) -> crate::token::Token
|
||||
callback: impl Fn(
|
||||
crate::tokenizer::Token,
|
||||
Position,
|
||||
&crate::tokenizer::TokenizeState,
|
||||
) -> crate::tokenizer::Token
|
||||
+ SendSync
|
||||
+ 'static,
|
||||
) -> &mut Self {
|
@ -1,6 +1,6 @@
|
||||
//! Configuration settings for [`Engine`].
|
||||
|
||||
use crate::token::Token;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::Engine;
|
||||
use crate::{engine::Precedence, Identifier};
|
||||
#[cfg(feature = "no_std")]
|
@ -1,10 +1,10 @@
|
||||
//! Module defining the AST (abstract syntax tree).
|
||||
|
||||
use crate::calc_fn_hash;
|
||||
use crate::dynamic::Union;
|
||||
use crate::fn_native::shared_make_mut;
|
||||
use crate::func::native::shared_make_mut;
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::token::Token;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::types::dynamic::Union;
|
||||
use crate::{
|
||||
Dynamic, FnNamespace, Identifier, ImmutableString, Module, Position, Shared, StaticVec, INT,
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
//! Module implementing custom syntax for [`Engine`].
|
||||
|
||||
use crate::ast::Expr;
|
||||
use crate::dynamic::Variant;
|
||||
use crate::engine::EvalContext;
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::func::native::SendSync;
|
||||
use crate::r#unsafe::unsafe_try_cast;
|
||||
use crate::token::{is_valid_identifier, Token};
|
||||
use crate::tokenizer::{is_valid_identifier, Token};
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{
|
||||
Engine, Identifier, ImmutableString, LexError, ParseError, Position, RhaiResult, Shared,
|
||||
StaticVec, INT,
|
||||
|
@ -2,16 +2,18 @@
|
||||
|
||||
use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*};
|
||||
use crate::custom_syntax::CustomSyntax;
|
||||
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant};
|
||||
use crate::fn_hash::get_hasher;
|
||||
use crate::fn_native::{
|
||||
CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback,
|
||||
OnVarCallback,
|
||||
use crate::func::{
|
||||
hashing::get_hasher,
|
||||
native::{
|
||||
CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback,
|
||||
OnVarCallback,
|
||||
},
|
||||
};
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::packages::{Package, StandardPackage};
|
||||
use crate::r#unsafe::unsafe_cast_var_name_to_lifetime;
|
||||
use crate::token::Token;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::types::dynamic::{map_std_type_name, AccessMode, Union, Variant};
|
||||
use crate::{
|
||||
Dynamic, EvalAltResult, Identifier, ImmutableString, Module, Position, RhaiResult, Scope,
|
||||
Shared, StaticVec, INT,
|
||||
@ -214,7 +216,7 @@ impl Imports {
|
||||
&'a mut self,
|
||||
) -> Option<impl DerefMut<Target = BTreeMap<Identifier, Dynamic>> + 'a> {
|
||||
if let Some(ref global_constants) = self.global_constants {
|
||||
Some(crate::fn_native::shared_write_lock(global_constants))
|
||||
Some(crate::func::native::shared_write_lock(global_constants))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -228,7 +230,7 @@ impl Imports {
|
||||
self.global_constants = Some(dict.into());
|
||||
}
|
||||
|
||||
crate::fn_native::shared_write_lock(self.global_constants.as_mut().expect("`Some`"))
|
||||
crate::func::native::shared_write_lock(self.global_constants.as_mut().expect("`Some`"))
|
||||
.insert(name.into(), value);
|
||||
}
|
||||
/// Get the pre-calculated index getter hash.
|
||||
@ -470,7 +472,12 @@ pub enum Target<'a> {
|
||||
/// The target is a mutable reference to a Shared `Dynamic` value.
|
||||
/// It holds both the access guard and the original shared value.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
LockGuard((crate::dynamic::DynamicWriteLock<'a, Dynamic>, Dynamic)),
|
||||
LockGuard(
|
||||
(
|
||||
crate::types::dynamic::DynamicWriteLock<'a, Dynamic>,
|
||||
Dynamic,
|
||||
),
|
||||
),
|
||||
/// The target is a temporary `Dynamic` value (i.e. the mutation can cause no side effects).
|
||||
TempValue(Dynamic),
|
||||
/// The target is a bit inside an [`INT`][crate::INT].
|
||||
@ -1004,7 +1011,7 @@ pub struct Engine {
|
||||
pub(crate) debug: Option<OnDebugCallback>,
|
||||
/// Callback closure for progress reporting.
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) progress: Option<crate::fn_native::OnProgressCallback>,
|
||||
pub(crate) progress: Option<crate::func::native::OnProgressCallback>,
|
||||
|
||||
/// Optimize the AST after compilation.
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
@ -3081,7 +3088,7 @@ impl Engine {
|
||||
if let Some(name) = export.as_ref().map(|x| x.name.clone()) {
|
||||
if !module.is_indexed() {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::fn_native::shared_take_or_clone(module);
|
||||
let mut module = crate::func::native::shared_take_or_clone(module);
|
||||
module.build_index();
|
||||
mods.push(name, module);
|
||||
} else {
|
||||
@ -3139,7 +3146,7 @@ impl Engine {
|
||||
fn check_return_value(&self, mut result: RhaiResult) -> RhaiResult {
|
||||
if let Ok(ref mut r) = result {
|
||||
// Concentrate all empty strings into one instance to save memory
|
||||
if let Dynamic(crate::dynamic::Union::Str(s, _, _)) = r {
|
||||
if let Dynamic(crate::types::dynamic::Union::Str(s, _, _)) = r {
|
||||
if s.is_empty() {
|
||||
if !s.ptr_eq(&self.empty_string) {
|
||||
*s = self.const_empty_string();
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::dynamic::Variant;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::Dynamic;
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
@ -1,9 +1,8 @@
|
||||
//! Built-in implementations for common operators.
|
||||
|
||||
use super::call::FnCallArgs;
|
||||
use crate::engine::OP_CONTAINS;
|
||||
use crate::fn_call::FnCallArgs;
|
||||
use crate::fn_native::NativeCallContext;
|
||||
use crate::{Dynamic, ImmutableString, RhaiResult, INT};
|
||||
use crate::{Dynamic, ImmutableString, NativeCallContext, RhaiResult, INT};
|
||||
use std::any::TypeId;
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
@ -1,21 +1,19 @@
|
||||
//! Implement function-calling mechanism for [`Engine`].
|
||||
|
||||
use super::builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn};
|
||||
use super::native::{CallableFunction, FnAny};
|
||||
use crate::ast::FnCallHashes;
|
||||
use crate::engine::{
|
||||
EvalState, FnResolutionCacheEntry, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR,
|
||||
KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_TYPE_OF,
|
||||
MAX_DYNAMIC_PARAMETERS,
|
||||
};
|
||||
use crate::fn_builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn};
|
||||
use crate::fn_native::FnAny;
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::token::Token;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::{
|
||||
ast::{Expr, Stmt},
|
||||
calc_fn_hash, calc_fn_params_hash, combine_hashes,
|
||||
fn_native::CallableFunction,
|
||||
Dynamic, Engine, EvalAltResult, FnPtr, Identifier, ImmutableString, Module, ParseErrorType,
|
||||
Position, RhaiResult, Scope, StaticVec,
|
||||
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, EvalAltResult, FnPtr,
|
||||
Identifier, ImmutableString, Module, ParseErrorType, Position, RhaiResult, Scope, StaticVec,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
@ -3,7 +3,7 @@
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::dynamic::Variant;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{Engine, EvalAltResult, ParseError, Scope, SmartString, AST};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
10
src/func/mod.rs
Normal file
10
src/func/mod.rs
Normal file
@ -0,0 +1,10 @@
|
||||
//! Module defining mechanisms to handle function calls in Rhai.
|
||||
|
||||
pub mod args;
|
||||
pub mod builtin;
|
||||
pub mod call;
|
||||
pub mod func;
|
||||
pub mod hashing;
|
||||
pub mod native;
|
||||
pub mod plugin;
|
||||
pub mod register;
|
@ -1,10 +1,10 @@
|
||||
//! Module defining interfaces to native-Rust functions.
|
||||
|
||||
use super::call::FnCallArgs;
|
||||
use crate::ast::{FnAccess, FnCallHashes};
|
||||
use crate::engine::{EvalState, Imports};
|
||||
use crate::fn_call::FnCallArgs;
|
||||
use crate::plugin::PluginFunction;
|
||||
use crate::token::{Token, TokenizeState};
|
||||
use crate::tokenizer::{Token, TokenizeState};
|
||||
use crate::{
|
||||
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, Module, Position, RhaiResult,
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
//! Module defining macros for developing _plugins_.
|
||||
|
||||
use crate::fn_call::FnCallArgs;
|
||||
pub use crate::fn_native::CallableFunction;
|
||||
use super::call::FnCallArgs;
|
||||
pub use super::native::CallableFunction;
|
||||
pub use crate::{
|
||||
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
|
||||
NativeCallContext, Position,
|
@ -2,11 +2,11 @@
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::dynamic::{DynamicWriteLock, Variant};
|
||||
use crate::fn_call::FnCallArgs;
|
||||
use crate::fn_native::{CallableFunction, FnAny, SendSync};
|
||||
use crate::func::call::FnCallArgs;
|
||||
use crate::func::native::{CallableFunction, FnAny, SendSync};
|
||||
use crate::r#unsafe::unsafe_try_cast;
|
||||
use crate::token::Position;
|
||||
use crate::tokenizer::Position;
|
||||
use crate::types::dynamic::{DynamicWriteLock, Variant};
|
||||
use crate::{Dynamic, EvalAltResult, NativeCallContext};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
72
src/lib.rs
72
src/lib.rs
@ -69,33 +69,19 @@ use std::prelude::v1::*;
|
||||
|
||||
// Internal modules
|
||||
|
||||
mod api;
|
||||
mod ast;
|
||||
mod custom_syntax;
|
||||
mod deprecated;
|
||||
mod dynamic;
|
||||
mod engine;
|
||||
mod engine_api;
|
||||
mod engine_settings;
|
||||
mod error;
|
||||
mod error_parsing;
|
||||
mod fn_args;
|
||||
mod fn_builtin;
|
||||
mod fn_call;
|
||||
mod fn_func;
|
||||
mod fn_hash;
|
||||
mod fn_native;
|
||||
mod fn_ptr;
|
||||
mod fn_register;
|
||||
mod immutable_string;
|
||||
mod func;
|
||||
mod module;
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
mod optimize;
|
||||
mod optimizer;
|
||||
pub mod packages;
|
||||
mod parse;
|
||||
pub mod plugin;
|
||||
mod scope;
|
||||
mod parser;
|
||||
mod tests;
|
||||
mod token;
|
||||
mod tokenizer;
|
||||
mod types;
|
||||
mod r#unsafe;
|
||||
|
||||
type RhaiResult = Result<Dynamic, Box<EvalAltResult>>;
|
||||
@ -132,17 +118,18 @@ pub type FLOAT = f32;
|
||||
|
||||
pub use ast::{FnAccess, AST};
|
||||
pub use custom_syntax::Expression;
|
||||
pub use dynamic::Dynamic;
|
||||
pub use engine::{Engine, EvalContext, OP_CONTAINS, OP_EQUALS};
|
||||
pub use error::EvalAltResult;
|
||||
pub use error_parsing::{LexError, ParseError, ParseErrorType};
|
||||
pub use fn_native::NativeCallContext;
|
||||
pub use fn_ptr::FnPtr;
|
||||
pub use fn_register::RegisterNativeFunction;
|
||||
pub use immutable_string::ImmutableString;
|
||||
pub use func::{native::NativeCallContext, register::RegisterNativeFunction};
|
||||
pub use module::{FnNamespace, Module};
|
||||
pub use scope::Scope;
|
||||
pub use token::Position;
|
||||
pub use tokenizer::Position;
|
||||
pub use types::{
|
||||
dynamic::Dynamic,
|
||||
error::EvalAltResult,
|
||||
fn_ptr::FnPtr,
|
||||
immutable_string::ImmutableString,
|
||||
parse_error::{LexError, ParseError, ParseErrorType},
|
||||
scope::Scope,
|
||||
};
|
||||
|
||||
/// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most
|
||||
/// identifiers are ASCII and short, fewer than 23 characters, so they can be stored inline.
|
||||
@ -169,23 +156,22 @@ pub type Identifier = SmartString;
|
||||
pub type Identifier = ImmutableString;
|
||||
|
||||
/// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag.
|
||||
pub use fn_native::Shared;
|
||||
pub use func::native::Shared;
|
||||
|
||||
//// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
|
||||
pub use fn_native::Locked;
|
||||
/// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
|
||||
pub use func::native::Locked;
|
||||
|
||||
pub(crate) use fn_hash::{
|
||||
pub(crate) use func::hashing::{
|
||||
calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
|
||||
combine_hashes,
|
||||
};
|
||||
|
||||
pub use rhai_codegen::*;
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use fn_func::Func;
|
||||
pub use func::plugin;
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use fn_args::FuncArgs;
|
||||
pub use func::{args::FuncArgs, func::Func};
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use ast::ScriptFnMetadata;
|
||||
@ -211,28 +197,28 @@ pub use module::resolvers as module_resolvers;
|
||||
pub mod serde;
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
pub use optimize::OptimizationLevel;
|
||||
pub use optimizer::OptimizationLevel;
|
||||
|
||||
// Expose internal data structures.
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "this type is volatile and may change"]
|
||||
pub use dynamic::{AccessMode, DynamicReadLock, DynamicWriteLock, Variant};
|
||||
pub use types::dynamic::{AccessMode, DynamicReadLock, DynamicWriteLock, Variant};
|
||||
|
||||
// Expose internal data structures.
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "this function is volatile and may change"]
|
||||
pub use token::{get_next_token, parse_string_literal};
|
||||
pub use tokenizer::{get_next_token, parse_string_literal};
|
||||
|
||||
// Expose internal data structures.
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "this type is volatile and may change"]
|
||||
pub use token::{
|
||||
pub use tokenizer::{
|
||||
InputStream, MultiInputsStream, Token, TokenIterator, TokenizeState, TokenizerControl,
|
||||
TokenizerControlBlock,
|
||||
};
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "this type is volatile and may change"]
|
||||
pub use parse::{IdentifierBuilder, ParseState};
|
||||
pub use parser::{IdentifierBuilder, ParseState};
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "this type is volatile and may change"]
|
||||
|
@ -1,12 +1,14 @@
|
||||
//! Module defining external-loaded modules for Rhai.
|
||||
|
||||
use crate::ast::{FnAccess, Ident};
|
||||
use crate::dynamic::Variant;
|
||||
use crate::fn_call::FnCallArgs;
|
||||
use crate::fn_native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync};
|
||||
use crate::fn_register::RegisterNativeFunction;
|
||||
use crate::parse::IdentifierBuilder;
|
||||
use crate::token::Token;
|
||||
use crate::func::{
|
||||
call::FnCallArgs,
|
||||
native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync},
|
||||
register::RegisterNativeFunction,
|
||||
};
|
||||
use crate::parser::IdentifierBuilder;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{
|
||||
calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, EvalAltResult,
|
||||
Identifier, ImmutableString, NativeCallContext, Shared, StaticVec,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::fn_native::shared_write_lock;
|
||||
use crate::func::native::shared_write_lock;
|
||||
use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Scope, Shared};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::func::native::SendSync;
|
||||
use crate::{Engine, EvalAltResult, Module, Position, Shared, AST};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
@ -1,13 +1,13 @@
|
||||
//! Module implementing the [`AST`] optimizer.
|
||||
|
||||
use crate::ast::{Expr, OpAssignment, Stmt, AST_OPTION_FLAGS::*};
|
||||
use crate::dynamic::AccessMode;
|
||||
use crate::engine::{
|
||||
EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF,
|
||||
};
|
||||
use crate::fn_builtin::get_builtin_binary_op_fn;
|
||||
use crate::fn_hash::get_hasher;
|
||||
use crate::token::Token;
|
||||
use crate::func::builtin::get_builtin_binary_op_fn;
|
||||
use crate::func::hashing::get_hasher;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::types::dynamic::AccessMode;
|
||||
use crate::{
|
||||
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString,
|
||||
Module, Position, Scope, StaticVec, AST,
|
||||
@ -1157,7 +1157,7 @@ pub fn optimize_into_ast(
|
||||
_functions
|
||||
.into_iter()
|
||||
.map(|fn_def| {
|
||||
let mut fn_def = crate::fn_native::shared_take_or_clone(fn_def);
|
||||
let mut fn_def = crate::func::native::shared_take_or_clone(fn_def);
|
||||
|
||||
// Optimize the function body
|
||||
let body = mem::take(fn_def.body.deref_mut());
|
@ -112,7 +112,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
let ns = format!(
|
||||
"{}{}{}",
|
||||
namespace,
|
||||
crate::token::Token::DoubleColon.literal_syntax(),
|
||||
crate::tokenizer::Token::DoubleColon.literal_syntax(),
|
||||
ns
|
||||
);
|
||||
scan_module(list, dict, ns.into(), m.as_ref())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::dynamic::Variant;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{def_package, EvalAltResult, INT};
|
||||
use std::iter::{ExactSizeIterator, FusedIterator};
|
||||
use std::ops::Range;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::def_package;
|
||||
use crate::dynamic::Tag;
|
||||
use crate::plugin::*;
|
||||
use crate::types::dynamic::Tag;
|
||||
use crate::{Dynamic, EvalAltResult, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
@ -6,10 +6,7 @@ use crate::{def_package, Position, INT};
|
||||
use std::prelude::v1::*;
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use crate::FLOAT;
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use crate::error::EvalAltResult;
|
||||
use crate::{EvalAltResult, FLOAT};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
|
@ -5,14 +5,14 @@ use crate::ast::{
|
||||
StmtBlock, AST_OPTION_FLAGS::*,
|
||||
};
|
||||
use crate::custom_syntax::{markers::*, CustomSyntax};
|
||||
use crate::dynamic::AccessMode;
|
||||
use crate::engine::{Precedence, KEYWORD_THIS, OP_CONTAINS};
|
||||
use crate::fn_hash::get_hasher;
|
||||
use crate::func::hashing::get_hasher;
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::token::{
|
||||
use crate::tokenizer::{
|
||||
is_keyword_function, is_valid_function_name, is_valid_identifier, Token, TokenStream,
|
||||
TokenizerControl,
|
||||
};
|
||||
use crate::types::dynamic::AccessMode;
|
||||
use crate::{
|
||||
calc_fn_hash, calc_qualified_fn_hash, calc_qualified_var_hash, Engine, Identifier,
|
||||
ImmutableString, LexError, ParseError, ParseErrorType, Position, Scope, Shared, StaticVec, AST,
|
||||
@ -2745,7 +2745,7 @@ fn parse_stmt(
|
||||
comments_pos = *pos;
|
||||
}
|
||||
|
||||
if !crate::token::is_doc_comment(comment) {
|
||||
if !crate::tokenizer::is_doc_comment(comment) {
|
||||
unreachable!("expecting doc-comment, but gets {:?}", comment);
|
||||
}
|
||||
|
||||
@ -3278,7 +3278,7 @@ impl Engine {
|
||||
statements.push(Stmt::Expr(expr));
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
return Ok(crate::optimize::optimize_into_ast(
|
||||
return Ok(crate::optimizer::optimize_into_ast(
|
||||
self,
|
||||
_scope,
|
||||
statements,
|
||||
@ -3363,7 +3363,7 @@ impl Engine {
|
||||
let (statements, _lib) = self.parse_global_level(input, state)?;
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
return Ok(crate::optimize::optimize_into_ast(
|
||||
return Ok(crate::optimizer::optimize_into_ast(
|
||||
self,
|
||||
_scope,
|
||||
statements,
|
@ -1,7 +1,7 @@
|
||||
//! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`].
|
||||
|
||||
use super::str::StringSliceDeserializer;
|
||||
use crate::dynamic::Union;
|
||||
use crate::types::dynamic::Union;
|
||||
use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position};
|
||||
use serde::de::{DeserializeSeed, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Implementations of [`serde::Serialize`].
|
||||
|
||||
use crate::dynamic::Union;
|
||||
use crate::types::dynamic::Union;
|
||||
use crate::{Dynamic, ImmutableString};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -10,7 +10,7 @@ use std::prelude::v1::*;
|
||||
use serde::ser::SerializeMap;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use crate::dynamic::Variant;
|
||||
use crate::types::dynamic::Variant;
|
||||
|
||||
impl Serialize for Dynamic {
|
||||
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
|
||||
|
@ -4,7 +4,7 @@ use crate::engine::{
|
||||
Precedence, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL,
|
||||
KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF,
|
||||
};
|
||||
use crate::fn_native::OnParseTokenCallback;
|
||||
use crate::func::native::OnParseTokenCallback;
|
||||
use crate::{Engine, LexError, StaticVec, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
@ -1,6 +1,6 @@
|
||||
//! Helper module which defines the [`Any`] trait to to allow dynamic value handling.
|
||||
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::func::native::SendSync;
|
||||
use crate::r#unsafe::{unsafe_cast_box, unsafe_try_cast};
|
||||
use crate::{FnPtr, ImmutableString, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -38,7 +38,7 @@ use instant::Instant;
|
||||
const CHECKED: &str = "data type was checked";
|
||||
|
||||
mod private {
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::func::native::SendSync;
|
||||
use std::any::Any;
|
||||
|
||||
/// A sealed trait that prevents other crates from implementing [`Variant`].
|
||||
@ -287,7 +287,7 @@ enum DynamicWriteLockInner<'d, T: Clone> {
|
||||
///
|
||||
/// Not available under `no_closure`.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Guard(crate::fn_native::LockGuard<'d, Dynamic>),
|
||||
Guard(crate::func::native::LockGuard<'d, Dynamic>),
|
||||
}
|
||||
|
||||
impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
||||
@ -1472,7 +1472,7 @@ impl Dynamic {
|
||||
pub fn flatten(self) -> Self {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(cell, _, _) => crate::fn_native::shared_try_take(cell).map_or_else(
|
||||
Union::Shared(cell, _, _) => crate::func::native::shared_try_take(cell).map_or_else(
|
||||
#[cfg(not(feature = "sync"))]
|
||||
|cell| cell.borrow().clone(),
|
||||
#[cfg(feature = "sync")]
|
||||
@ -1497,7 +1497,7 @@ impl Dynamic {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(_, _, _) => match std::mem::take(self).0 {
|
||||
Union::Shared(cell, _, _) => {
|
||||
*self = crate::fn_native::shared_try_take(cell).map_or_else(
|
||||
*self = crate::func::native::shared_try_take(cell).map_or_else(
|
||||
#[cfg(not(feature = "sync"))]
|
||||
|cell| cell.borrow().clone(),
|
||||
#[cfg(feature = "sync")]
|
||||
@ -1590,7 +1590,7 @@ impl Dynamic {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, _, _) => {
|
||||
let value = crate::fn_native::shared_write_lock(cell);
|
||||
let value = crate::func::native::shared_write_lock(cell);
|
||||
|
||||
if (*value).type_id() != TypeId::of::<T>()
|
||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
@ -1,6 +1,6 @@
|
||||
//! The `FnPtr` type.
|
||||
|
||||
use crate::token::is_valid_identifier;
|
||||
use crate::tokenizer::is_valid_identifier;
|
||||
use crate::{
|
||||
Dynamic, EvalAltResult, Identifier, NativeCallContext, Position, RhaiResult, StaticVec,
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
//! The `ImmutableString` type.
|
||||
|
||||
use crate::fn_native::{shared_make_mut, shared_take};
|
||||
use crate::func::native::{shared_make_mut, shared_take};
|
||||
use crate::{Shared, SmartString};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
8
src/types/mod.rs
Normal file
8
src/types/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
//! Module defining Rhai data types.
|
||||
|
||||
pub mod dynamic;
|
||||
pub mod error;
|
||||
pub mod fn_ptr;
|
||||
pub mod immutable_string;
|
||||
pub mod parse_error;
|
||||
pub mod scope;
|
@ -1,6 +1,6 @@
|
||||
//! Module that defines the [`Scope`] type representing a function call-stack scope.
|
||||
|
||||
use crate::dynamic::{AccessMode, Variant};
|
||||
use super::dynamic::{AccessMode, Variant};
|
||||
use crate::{Dynamic, Identifier, StaticVec};
|
||||
use std::iter::FromIterator;
|
||||
#[cfg(feature = "no_std")]
|
Loading…
Reference in New Issue
Block a user