Restructure code base.

This commit is contained in:
Stephen Chung 2021-11-13 22:36:23 +08:00
parent 38884ede46
commit 64b889fb95
36 changed files with 154 additions and 140 deletions

5
src/api/mod.rs Normal file
View File

@ -0,0 +1,5 @@
//! Module defining the public API of the Rhai engine.
pub mod deprecated;
pub mod public;
pub mod settings;

View File

@ -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::engine::{EvalContext, EvalState, Imports};
use crate::fn_call::FnCallArgs; use crate::func::{call::FnCallArgs, native::SendSync, register::RegisterNativeFunction};
use crate::fn_native::SendSync; use crate::parser::ParseState;
use crate::fn_register::RegisterNativeFunction; use crate::types::dynamic::Variant;
use crate::parse::ParseState;
use crate::{ use crate::{
scope::Scope, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, Identifier, Module, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, Identifier, Module, NativeCallContext,
NativeCallContext, ParseError, Position, RhaiResult, Shared, AST, ParseError, Position, RhaiResult, Scope, Shared, AST,
}; };
use std::any::{type_name, TypeId}; use std::any::{type_name, TypeId};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
@ -937,12 +935,12 @@ impl Engine {
name: impl AsRef<str> + Into<Identifier>, name: impl AsRef<str> + Into<Identifier>,
module: Shared<Module>, 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 !name.as_ref().contains(separator.as_ref()) {
if !module.is_indexed() { if !module.is_indexed() {
// Index the module (making a clone copy if necessary) if it is not 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(); module.build_index();
root.insert(name.into(), module.into()); root.insert(name.into(), module.into());
} else { } else {
@ -960,7 +958,7 @@ impl Engine {
root.insert(sub_module.into(), m.into()); root.insert(sub_module.into(), m.into());
} else { } else {
let m = root.remove(sub_module).expect("contains sub-module"); 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); register_static_module_raw(m.sub_modules_mut(), remainder, module);
m.build_index(); m.build_index();
root.insert(sub_module.into(), m.into()); root.insert(sub_module.into(), m.into());
@ -1053,7 +1051,7 @@ impl Engine {
) -> Result<AST, Box<EvalAltResult>> { ) -> Result<AST, Box<EvalAltResult>> {
use crate::{ use crate::{
ast::{ASTNode, Expr, Stmt}, ast::{ASTNode, Expr, Stmt},
fn_native::shared_take_or_clone, func::native::shared_take_or_clone,
module::resolvers::StaticModuleResolver, module::resolvers::StaticModuleResolver,
}; };
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -1349,7 +1347,7 @@ impl Engine {
json: impl AsRef<str>, json: impl AsRef<str>,
has_null: bool, has_null: bool,
) -> Result<Map, Box<EvalAltResult>> { ) -> Result<Map, Box<EvalAltResult>> {
use crate::token::Token; use crate::tokenizer::Token;
fn parse_json_inner( fn parse_json_inner(
engine: &Engine, engine: &Engine,
@ -2026,7 +2024,7 @@ impl Engine {
// Check for data race. // Check for data race.
#[cfg(not(feature = "no_closure"))] #[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( self.call_script_fn(
scope, scope,
@ -2084,7 +2082,7 @@ impl Engine {
let statements = std::mem::take(ast.statements_mut()); 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. /// _(metadata)_ Generate a list of all registered functions.
/// Exported under the `metadata` feature only. /// Exported under the `metadata` feature only.
@ -2184,14 +2182,14 @@ impl Engine {
/// > `Fn(token: Token, pos: Position, state: &TokenizeState) -> Token` /// > `Fn(token: Token, pos: Position, state: &TokenizeState) -> Token`
/// ///
/// where: /// where:
/// * [`token`][crate::token::Token]: current token parsed /// * [`token`][crate::tokenizer::Token]: current token parsed
/// * [`pos`][`Position`]: location of the token /// * [`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 /// ## Raising errors
/// ///
/// It is possible to raise a parsing error by returning /// 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 /// # Example
/// ///
@ -2225,7 +2223,11 @@ impl Engine {
#[inline(always)] #[inline(always)]
pub fn on_parse_token( pub fn on_parse_token(
&mut self, &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 + SendSync
+ 'static, + 'static,
) -> &mut Self { ) -> &mut Self {

View File

@ -1,6 +1,6 @@
//! Configuration settings for [`Engine`]. //! Configuration settings for [`Engine`].
use crate::token::Token; use crate::tokenizer::Token;
use crate::Engine; use crate::Engine;
use crate::{engine::Precedence, Identifier}; use crate::{engine::Precedence, Identifier};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]

View File

@ -1,10 +1,10 @@
//! Module defining the AST (abstract syntax tree). //! Module defining the AST (abstract syntax tree).
use crate::calc_fn_hash; use crate::calc_fn_hash;
use crate::dynamic::Union; use crate::func::native::shared_make_mut;
use crate::fn_native::shared_make_mut;
use crate::module::NamespaceRef; use crate::module::NamespaceRef;
use crate::token::Token; use crate::tokenizer::Token;
use crate::types::dynamic::Union;
use crate::{ use crate::{
Dynamic, FnNamespace, Identifier, ImmutableString, Module, Position, Shared, StaticVec, INT, Dynamic, FnNamespace, Identifier, ImmutableString, Module, Position, Shared, StaticVec, INT,
}; };

View File

@ -1,11 +1,11 @@
//! Module implementing custom syntax for [`Engine`]. //! Module implementing custom syntax for [`Engine`].
use crate::ast::Expr; use crate::ast::Expr;
use crate::dynamic::Variant;
use crate::engine::EvalContext; use crate::engine::EvalContext;
use crate::fn_native::SendSync; use crate::func::native::SendSync;
use crate::r#unsafe::unsafe_try_cast; 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::{ use crate::{
Engine, Identifier, ImmutableString, LexError, ParseError, Position, RhaiResult, Shared, Engine, Identifier, ImmutableString, LexError, ParseError, Position, RhaiResult, Shared,
StaticVec, INT, StaticVec, INT,

View File

@ -2,16 +2,18 @@
use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*};
use crate::custom_syntax::CustomSyntax; use crate::custom_syntax::CustomSyntax;
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant}; use crate::func::{
use crate::fn_hash::get_hasher; hashing::get_hasher,
use crate::fn_native::{ native::{
CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback, CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback,
OnVarCallback, OnVarCallback,
},
}; };
use crate::module::NamespaceRef; use crate::module::NamespaceRef;
use crate::packages::{Package, StandardPackage}; use crate::packages::{Package, StandardPackage};
use crate::r#unsafe::unsafe_cast_var_name_to_lifetime; 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::{ use crate::{
Dynamic, EvalAltResult, Identifier, ImmutableString, Module, Position, RhaiResult, Scope, Dynamic, EvalAltResult, Identifier, ImmutableString, Module, Position, RhaiResult, Scope,
Shared, StaticVec, INT, Shared, StaticVec, INT,
@ -214,7 +216,7 @@ impl Imports {
&'a mut self, &'a mut self,
) -> Option<impl DerefMut<Target = BTreeMap<Identifier, Dynamic>> + 'a> { ) -> Option<impl DerefMut<Target = BTreeMap<Identifier, Dynamic>> + 'a> {
if let Some(ref global_constants) = self.global_constants { 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 { } else {
None None
} }
@ -228,7 +230,7 @@ impl Imports {
self.global_constants = Some(dict.into()); 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); .insert(name.into(), value);
} }
/// Get the pre-calculated index getter hash. /// 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. /// The target is a mutable reference to a Shared `Dynamic` value.
/// It holds both the access guard and the original shared value. /// It holds both the access guard and the original shared value.
#[cfg(not(feature = "no_closure"))] #[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). /// The target is a temporary `Dynamic` value (i.e. the mutation can cause no side effects).
TempValue(Dynamic), TempValue(Dynamic),
/// The target is a bit inside an [`INT`][crate::INT]. /// The target is a bit inside an [`INT`][crate::INT].
@ -1004,7 +1011,7 @@ pub struct Engine {
pub(crate) debug: Option<OnDebugCallback>, pub(crate) debug: Option<OnDebugCallback>,
/// Callback closure for progress reporting. /// Callback closure for progress reporting.
#[cfg(not(feature = "unchecked"))] #[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. /// Optimize the AST after compilation.
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
@ -3081,7 +3088,7 @@ impl Engine {
if let Some(name) = export.as_ref().map(|x| x.name.clone()) { if let Some(name) = export.as_ref().map(|x| x.name.clone()) {
if !module.is_indexed() { if !module.is_indexed() {
// Index the module (making a clone copy if necessary) if it is not 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(); module.build_index();
mods.push(name, module); mods.push(name, module);
} else { } else {
@ -3139,7 +3146,7 @@ impl Engine {
fn check_return_value(&self, mut result: RhaiResult) -> RhaiResult { fn check_return_value(&self, mut result: RhaiResult) -> RhaiResult {
if let Ok(ref mut r) = result { if let Ok(ref mut r) = result {
// Concentrate all empty strings into one instance to save memory // 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.is_empty() {
if !s.ptr_eq(&self.empty_string) { if !s.ptr_eq(&self.empty_string) {
*s = self.const_empty_string(); *s = self.const_empty_string();

View File

@ -3,7 +3,7 @@
#![cfg(not(feature = "no_function"))] #![cfg(not(feature = "no_function"))]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::Dynamic; use crate::Dynamic;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -1,9 +1,8 @@
//! Built-in implementations for common operators. //! Built-in implementations for common operators.
use super::call::FnCallArgs;
use crate::engine::OP_CONTAINS; use crate::engine::OP_CONTAINS;
use crate::fn_call::FnCallArgs; use crate::{Dynamic, ImmutableString, NativeCallContext, RhaiResult, INT};
use crate::fn_native::NativeCallContext;
use crate::{Dynamic, ImmutableString, RhaiResult, INT};
use std::any::TypeId; use std::any::TypeId;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -1,21 +1,19 @@
//! Implement function-calling mechanism for [`Engine`]. //! 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::ast::FnCallHashes;
use crate::engine::{ use crate::engine::{
EvalState, FnResolutionCacheEntry, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, 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, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_TYPE_OF,
MAX_DYNAMIC_PARAMETERS, 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::module::NamespaceRef;
use crate::token::Token; use crate::tokenizer::Token;
use crate::{ use crate::{
ast::{Expr, Stmt}, ast::{Expr, Stmt},
calc_fn_hash, calc_fn_params_hash, combine_hashes, calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, EvalAltResult, FnPtr,
fn_native::CallableFunction, Identifier, ImmutableString, Module, ParseErrorType, Position, RhaiResult, Scope, StaticVec,
Dynamic, Engine, EvalAltResult, FnPtr, Identifier, ImmutableString, Module, ParseErrorType,
Position, RhaiResult, Scope, StaticVec,
}; };
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -3,7 +3,7 @@
#![cfg(not(feature = "no_function"))] #![cfg(not(feature = "no_function"))]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::{Engine, EvalAltResult, ParseError, Scope, SmartString, AST}; use crate::{Engine, EvalAltResult, ParseError, Scope, SmartString, AST};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

10
src/func/mod.rs Normal file
View 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;

View File

@ -1,10 +1,10 @@
//! Module defining interfaces to native-Rust functions. //! Module defining interfaces to native-Rust functions.
use super::call::FnCallArgs;
use crate::ast::{FnAccess, FnCallHashes}; use crate::ast::{FnAccess, FnCallHashes};
use crate::engine::{EvalState, Imports}; use crate::engine::{EvalState, Imports};
use crate::fn_call::FnCallArgs;
use crate::plugin::PluginFunction; use crate::plugin::PluginFunction;
use crate::token::{Token, TokenizeState}; use crate::tokenizer::{Token, TokenizeState};
use crate::{ use crate::{
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, Module, Position, RhaiResult, calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, Module, Position, RhaiResult,
}; };

View File

@ -1,7 +1,7 @@
//! Module defining macros for developing _plugins_. //! Module defining macros for developing _plugins_.
use crate::fn_call::FnCallArgs; use super::call::FnCallArgs;
pub use crate::fn_native::CallableFunction; pub use super::native::CallableFunction;
pub use crate::{ pub use crate::{
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
NativeCallContext, Position, NativeCallContext, Position,

View File

@ -2,11 +2,11 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::dynamic::{DynamicWriteLock, Variant}; use crate::func::call::FnCallArgs;
use crate::fn_call::FnCallArgs; use crate::func::native::{CallableFunction, FnAny, SendSync};
use crate::fn_native::{CallableFunction, FnAny, SendSync};
use crate::r#unsafe::unsafe_try_cast; 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}; use crate::{Dynamic, EvalAltResult, NativeCallContext};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -69,33 +69,19 @@ use std::prelude::v1::*;
// Internal modules // Internal modules
mod api;
mod ast; mod ast;
mod custom_syntax; mod custom_syntax;
mod deprecated;
mod dynamic;
mod engine; mod engine;
mod engine_api; mod func;
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 module; mod module;
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
mod optimize; mod optimizer;
pub mod packages; pub mod packages;
mod parse; mod parser;
pub mod plugin;
mod scope;
mod tests; mod tests;
mod token; mod tokenizer;
mod types;
mod r#unsafe; mod r#unsafe;
type RhaiResult = Result<Dynamic, Box<EvalAltResult>>; type RhaiResult = Result<Dynamic, Box<EvalAltResult>>;
@ -132,17 +118,18 @@ pub type FLOAT = f32;
pub use ast::{FnAccess, AST}; pub use ast::{FnAccess, AST};
pub use custom_syntax::Expression; pub use custom_syntax::Expression;
pub use dynamic::Dynamic;
pub use engine::{Engine, EvalContext, OP_CONTAINS, OP_EQUALS}; pub use engine::{Engine, EvalContext, OP_CONTAINS, OP_EQUALS};
pub use error::EvalAltResult; pub use func::{native::NativeCallContext, register::RegisterNativeFunction};
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 module::{FnNamespace, Module}; pub use module::{FnNamespace, Module};
pub use scope::Scope; pub use tokenizer::Position;
pub use token::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 /// 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. /// 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; pub type Identifier = ImmutableString;
/// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag. /// 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. /// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
pub use fn_native::Locked; 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, calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
combine_hashes, combine_hashes,
}; };
pub use rhai_codegen::*; pub use rhai_codegen::*;
#[cfg(not(feature = "no_function"))] pub use func::plugin;
pub use fn_func::Func;
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use fn_args::FuncArgs; pub use func::{args::FuncArgs, func::Func};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use ast::ScriptFnMetadata; pub use ast::ScriptFnMetadata;
@ -211,28 +197,28 @@ pub use module::resolvers as module_resolvers;
pub mod serde; pub mod serde;
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
pub use optimize::OptimizationLevel; pub use optimizer::OptimizationLevel;
// Expose internal data structures.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated = "this type is volatile and may change"] #[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")] #[cfg(feature = "internals")]
#[deprecated = "this function is volatile and may change"] #[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")] #[cfg(feature = "internals")]
#[deprecated = "this type is volatile and may change"] #[deprecated = "this type is volatile and may change"]
pub use token::{ pub use tokenizer::{
InputStream, MultiInputsStream, Token, TokenIterator, TokenizeState, TokenizerControl, InputStream, MultiInputsStream, Token, TokenIterator, TokenizeState, TokenizerControl,
TokenizerControlBlock, TokenizerControlBlock,
}; };
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated = "this type is volatile and may change"] #[deprecated = "this type is volatile and may change"]
pub use parse::{IdentifierBuilder, ParseState}; pub use parser::{IdentifierBuilder, ParseState};
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated = "this type is volatile and may change"] #[deprecated = "this type is volatile and may change"]

View File

@ -1,12 +1,14 @@
//! Module defining external-loaded modules for Rhai. //! Module defining external-loaded modules for Rhai.
use crate::ast::{FnAccess, Ident}; use crate::ast::{FnAccess, Ident};
use crate::dynamic::Variant; use crate::func::{
use crate::fn_call::FnCallArgs; call::FnCallArgs,
use crate::fn_native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync}; native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync},
use crate::fn_register::RegisterNativeFunction; register::RegisterNativeFunction,
use crate::parse::IdentifierBuilder; };
use crate::token::Token; use crate::parser::IdentifierBuilder;
use crate::tokenizer::Token;
use crate::types::dynamic::Variant;
use crate::{ use crate::{
calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, EvalAltResult, calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, EvalAltResult,
Identifier, ImmutableString, NativeCallContext, Shared, StaticVec, Identifier, ImmutableString, NativeCallContext, Shared, StaticVec,

View File

@ -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}; use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Scope, Shared};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]

View File

@ -1,4 +1,4 @@
use crate::fn_native::SendSync; use crate::func::native::SendSync;
use crate::{Engine, EvalAltResult, Module, Position, Shared, AST}; use crate::{Engine, EvalAltResult, Module, Position, Shared, AST};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -1,13 +1,13 @@
//! Module implementing the [`AST`] optimizer. //! Module implementing the [`AST`] optimizer.
use crate::ast::{Expr, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; use crate::ast::{Expr, OpAssignment, Stmt, AST_OPTION_FLAGS::*};
use crate::dynamic::AccessMode;
use crate::engine::{ use crate::engine::{
EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF, 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::func::builtin::get_builtin_binary_op_fn;
use crate::fn_hash::get_hasher; use crate::func::hashing::get_hasher;
use crate::token::Token; use crate::tokenizer::Token;
use crate::types::dynamic::AccessMode;
use crate::{ use crate::{
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString, calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString,
Module, Position, Scope, StaticVec, AST, Module, Position, Scope, StaticVec, AST,
@ -1157,7 +1157,7 @@ pub fn optimize_into_ast(
_functions _functions
.into_iter() .into_iter()
.map(|fn_def| { .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 // Optimize the function body
let body = mem::take(fn_def.body.deref_mut()); let body = mem::take(fn_def.body.deref_mut());

View File

@ -112,7 +112,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
let ns = format!( let ns = format!(
"{}{}{}", "{}{}{}",
namespace, namespace,
crate::token::Token::DoubleColon.literal_syntax(), crate::tokenizer::Token::DoubleColon.literal_syntax(),
ns ns
); );
scan_module(list, dict, ns.into(), m.as_ref()) scan_module(list, dict, ns.into(), m.as_ref())

View File

@ -1,4 +1,4 @@
use crate::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::{def_package, EvalAltResult, INT}; use crate::{def_package, EvalAltResult, INT};
use std::iter::{ExactSizeIterator, FusedIterator}; use std::iter::{ExactSizeIterator, FusedIterator};
use std::ops::Range; use std::ops::Range;

View File

@ -1,6 +1,6 @@
use crate::def_package; use crate::def_package;
use crate::dynamic::Tag;
use crate::plugin::*; use crate::plugin::*;
use crate::types::dynamic::Tag;
use crate::{Dynamic, EvalAltResult, INT}; use crate::{Dynamic, EvalAltResult, INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -6,10 +6,7 @@ use crate::{def_package, Position, INT};
use std::prelude::v1::*; use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
use crate::FLOAT; use crate::{EvalAltResult, FLOAT};
#[cfg(not(feature = "no_float"))]
use crate::error::EvalAltResult;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]

View File

@ -5,14 +5,14 @@ use crate::ast::{
StmtBlock, AST_OPTION_FLAGS::*, StmtBlock, AST_OPTION_FLAGS::*,
}; };
use crate::custom_syntax::{markers::*, CustomSyntax}; use crate::custom_syntax::{markers::*, CustomSyntax};
use crate::dynamic::AccessMode;
use crate::engine::{Precedence, KEYWORD_THIS, OP_CONTAINS}; 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::module::NamespaceRef;
use crate::token::{ use crate::tokenizer::{
is_keyword_function, is_valid_function_name, is_valid_identifier, Token, TokenStream, is_keyword_function, is_valid_function_name, is_valid_identifier, Token, TokenStream,
TokenizerControl, TokenizerControl,
}; };
use crate::types::dynamic::AccessMode;
use crate::{ use crate::{
calc_fn_hash, calc_qualified_fn_hash, calc_qualified_var_hash, Engine, Identifier, calc_fn_hash, calc_qualified_fn_hash, calc_qualified_var_hash, Engine, Identifier,
ImmutableString, LexError, ParseError, ParseErrorType, Position, Scope, Shared, StaticVec, AST, ImmutableString, LexError, ParseError, ParseErrorType, Position, Scope, Shared, StaticVec, AST,
@ -2745,7 +2745,7 @@ fn parse_stmt(
comments_pos = *pos; comments_pos = *pos;
} }
if !crate::token::is_doc_comment(comment) { if !crate::tokenizer::is_doc_comment(comment) {
unreachable!("expecting doc-comment, but gets {:?}", comment); unreachable!("expecting doc-comment, but gets {:?}", comment);
} }
@ -3278,7 +3278,7 @@ impl Engine {
statements.push(Stmt::Expr(expr)); statements.push(Stmt::Expr(expr));
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
return Ok(crate::optimize::optimize_into_ast( return Ok(crate::optimizer::optimize_into_ast(
self, self,
_scope, _scope,
statements, statements,
@ -3363,7 +3363,7 @@ impl Engine {
let (statements, _lib) = self.parse_global_level(input, state)?; let (statements, _lib) = self.parse_global_level(input, state)?;
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
return Ok(crate::optimize::optimize_into_ast( return Ok(crate::optimizer::optimize_into_ast(
self, self,
_scope, _scope,
statements, statements,

View File

@ -1,7 +1,7 @@
//! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`]. //! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`].
use super::str::StringSliceDeserializer; use super::str::StringSliceDeserializer;
use crate::dynamic::Union; use crate::types::dynamic::Union;
use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position}; use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position};
use serde::de::{DeserializeSeed, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor}; use serde::de::{DeserializeSeed, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor};
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};

View File

@ -1,6 +1,6 @@
//! Implementations of [`serde::Serialize`]. //! Implementations of [`serde::Serialize`].
use crate::dynamic::Union; use crate::types::dynamic::Union;
use crate::{Dynamic, ImmutableString}; use crate::{Dynamic, ImmutableString};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
@ -10,7 +10,7 @@ use std::prelude::v1::*;
use serde::ser::SerializeMap; use serde::ser::SerializeMap;
#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_std"))]
use crate::dynamic::Variant; use crate::types::dynamic::Variant;
impl Serialize for Dynamic { impl Serialize for Dynamic {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {

View File

@ -4,7 +4,7 @@ use crate::engine::{
Precedence, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, 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, 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}; use crate::{Engine, LexError, StaticVec, INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -1,6 +1,6 @@
//! Helper module which defines the [`Any`] trait to to allow dynamic value handling. //! 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::r#unsafe::{unsafe_cast_box, unsafe_try_cast};
use crate::{FnPtr, ImmutableString, INT}; use crate::{FnPtr, ImmutableString, INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
@ -38,7 +38,7 @@ use instant::Instant;
const CHECKED: &str = "data type was checked"; const CHECKED: &str = "data type was checked";
mod private { mod private {
use crate::fn_native::SendSync; use crate::func::native::SendSync;
use std::any::Any; use std::any::Any;
/// A sealed trait that prevents other crates from implementing [`Variant`]. /// A sealed trait that prevents other crates from implementing [`Variant`].
@ -287,7 +287,7 @@ enum DynamicWriteLockInner<'d, T: Clone> {
/// ///
/// Not available under `no_closure`. /// Not available under `no_closure`.
#[cfg(not(feature = "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> { impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
@ -1472,7 +1472,7 @@ impl Dynamic {
pub fn flatten(self) -> Self { pub fn flatten(self) -> Self {
match self.0 { match self.0 {
#[cfg(not(feature = "no_closure"))] #[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"))] #[cfg(not(feature = "sync"))]
|cell| cell.borrow().clone(), |cell| cell.borrow().clone(),
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
@ -1497,7 +1497,7 @@ impl Dynamic {
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
Union::Shared(_, _, _) => match std::mem::take(self).0 { Union::Shared(_, _, _) => match std::mem::take(self).0 {
Union::Shared(cell, _, _) => { 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"))] #[cfg(not(feature = "sync"))]
|cell| cell.borrow().clone(), |cell| cell.borrow().clone(),
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
@ -1590,7 +1590,7 @@ impl Dynamic {
match self.0 { match self.0 {
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, _, _) => { 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>() if (*value).type_id() != TypeId::of::<T>()
&& TypeId::of::<Dynamic>() != TypeId::of::<T>() && TypeId::of::<Dynamic>() != TypeId::of::<T>()

View File

@ -1,6 +1,6 @@
//! The `FnPtr` type. //! The `FnPtr` type.
use crate::token::is_valid_identifier; use crate::tokenizer::is_valid_identifier;
use crate::{ use crate::{
Dynamic, EvalAltResult, Identifier, NativeCallContext, Position, RhaiResult, StaticVec, Dynamic, EvalAltResult, Identifier, NativeCallContext, Position, RhaiResult, StaticVec,
}; };

View File

@ -1,6 +1,6 @@
//! The `ImmutableString` type. //! 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}; use crate::{Shared, SmartString};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

8
src/types/mod.rs Normal file
View 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;

View File

@ -1,6 +1,6 @@
//! Module that defines the [`Scope`] type representing a function call-stack scope. //! 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 crate::{Dynamic, Identifier, StaticVec};
use std::iter::FromIterator; use std::iter::FromIterator;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]