Change some #[inline(always)] to [#inline].
This commit is contained in:
parent
4d25fd0192
commit
e0673a2f1a
27
src/ast.rs
27
src/ast.rs
@ -78,7 +78,6 @@ pub struct ScriptFnDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ScriptFnDef {
|
impl fmt::Display for ScriptFnDef {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
@ -129,7 +128,6 @@ pub struct ScriptFnMetadata<'a> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
impl fmt::Display for ScriptFnMetadata<'_> {
|
impl fmt::Display for ScriptFnMetadata<'_> {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
@ -150,7 +148,7 @@ impl fmt::Display for ScriptFnMetadata<'_> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
impl<'a> Into<ScriptFnMetadata<'a>> for &'a ScriptFnDef {
|
impl<'a> Into<ScriptFnMetadata<'a>> for &'a ScriptFnDef {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn into(self) -> ScriptFnMetadata<'a> {
|
fn into(self) -> ScriptFnMetadata<'a> {
|
||||||
ScriptFnMetadata {
|
ScriptFnMetadata {
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
@ -215,7 +213,7 @@ impl Default for AST {
|
|||||||
|
|
||||||
impl AST {
|
impl AST {
|
||||||
/// Create a new [`AST`].
|
/// Create a new [`AST`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
statements: impl IntoIterator<Item = Stmt>,
|
statements: impl IntoIterator<Item = Stmt>,
|
||||||
@ -258,7 +256,7 @@ impl AST {
|
|||||||
self.source.as_ref()
|
self.source.as_ref()
|
||||||
}
|
}
|
||||||
/// Set the source.
|
/// Set the source.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_source(&mut self, source: impl Into<Identifier>) -> &mut Self {
|
pub fn set_source(&mut self, source: impl Into<Identifier>) -> &mut Self {
|
||||||
let source = source.into();
|
let source = source.into();
|
||||||
Shared::get_mut(&mut self.functions)
|
Shared::get_mut(&mut self.functions)
|
||||||
@ -386,7 +384,7 @@ impl AST {
|
|||||||
///
|
///
|
||||||
/// This operation is cheap because functions are shared.
|
/// This operation is cheap because functions are shared.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn clone_functions_only_filtered(
|
pub fn clone_functions_only_filtered(
|
||||||
&self,
|
&self,
|
||||||
@ -657,7 +655,7 @@ impl AST {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn combine_filtered(
|
pub fn combine_filtered(
|
||||||
&mut self,
|
&mut self,
|
||||||
other: Self,
|
other: Self,
|
||||||
@ -696,7 +694,7 @@ impl AST {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn retain_functions(
|
pub fn retain_functions(
|
||||||
&mut self,
|
&mut self,
|
||||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
||||||
@ -748,7 +746,7 @@ impl AST {
|
|||||||
/// Return `false` from the callback to terminate the walk.
|
/// Return `false` from the callback to terminate the walk.
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
|
pub(crate) fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
|
||||||
let path = &mut Default::default();
|
let path = &mut Default::default();
|
||||||
|
|
||||||
@ -770,7 +768,7 @@ impl AST {
|
|||||||
/// Return `false` from the callback to terminate the walk.
|
/// Return `false` from the callback to terminate the walk.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
|
pub fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
|
||||||
let path = &mut Default::default();
|
let path = &mut Default::default();
|
||||||
|
|
||||||
@ -835,7 +833,6 @@ pub struct Ident {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Ident {
|
impl fmt::Debug for Ident {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{:?}", self.name)?;
|
write!(f, "{:?}", self.name)?;
|
||||||
self.pos.debug_print(f)
|
self.pos.debug_print(f)
|
||||||
@ -939,7 +936,6 @@ impl DerefMut for StmtBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for StmtBlock {
|
impl fmt::Debug for StmtBlock {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.write_str("Block")?;
|
f.write_str("Block")?;
|
||||||
fmt::Debug::fmt(&self.0, f)?;
|
fmt::Debug::fmt(&self.0, f)?;
|
||||||
@ -1027,7 +1023,7 @@ impl Default for Stmt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<Stmt> for StmtBlock {
|
impl From<Stmt> for StmtBlock {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from(stmt: Stmt) -> Self {
|
fn from(stmt: Stmt) -> Self {
|
||||||
match stmt {
|
match stmt {
|
||||||
Stmt::Block(mut block, pos) => Self(block.iter_mut().map(mem::take).collect(), pos),
|
Stmt::Block(mut block, pos) => Self(block.iter_mut().map(mem::take).collect(), pos),
|
||||||
@ -1226,7 +1222,7 @@ impl Stmt {
|
|||||||
///
|
///
|
||||||
/// Only variable declarations (i.e. `let` and `const`) and `import`/`export` statements
|
/// Only variable declarations (i.e. `let` and `const`) and `import`/`export` statements
|
||||||
/// are internally pure.
|
/// are internally pure.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_internally_pure(&self) -> bool {
|
pub fn is_internally_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -1245,7 +1241,7 @@ impl Stmt {
|
|||||||
/// Currently this is only true for `return`, `throw`, `break` and `continue`.
|
/// Currently this is only true for `return`, `throw`, `break` and `continue`.
|
||||||
///
|
///
|
||||||
/// All statements following this statement will essentially be dead code.
|
/// All statements following this statement will essentially be dead code.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_control_flow_break(&self) -> bool {
|
pub const fn is_control_flow_break(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -1634,7 +1630,6 @@ impl<F: Float + fmt::Debug> fmt::Debug for FloatWrapper<F> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
impl<F: Float + fmt::Display + fmt::LowerExp + From<f32>> fmt::Display for FloatWrapper<F> {
|
impl<F: Float + fmt::Display + fmt::LowerExp + From<f32>> fmt::Display for FloatWrapper<F> {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let abs = self.0.abs();
|
let abs = self.0.abs();
|
||||||
if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into()
|
if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into()
|
||||||
|
@ -405,13 +405,11 @@ impl Dynamic {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is<T: Any + Clone>(&self) -> bool {
|
pub fn is<T: Any + Clone>(&self) -> bool {
|
||||||
let mut target_type_id = TypeId::of::<T>();
|
if TypeId::of::<T>() == TypeId::of::<String>() {
|
||||||
|
self.type_id() == TypeId::of::<ImmutableString>()
|
||||||
if target_type_id == TypeId::of::<String>() {
|
} else {
|
||||||
target_type_id = TypeId::of::<ImmutableString>();
|
self.type_id() == TypeId::of::<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
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`].
|
||||||
///
|
///
|
||||||
@ -577,7 +575,7 @@ impl Hash for Dynamic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Map the name of a standard type into a friendly form.
|
/// Map the name of a standard type into a friendly form.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn map_std_type_name(name: &str) -> &str {
|
pub(crate) fn map_std_type_name(name: &str) -> &str {
|
||||||
if name == type_name::<String>() {
|
if name == type_name::<String>() {
|
||||||
@ -1321,7 +1319,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(x.cast::<u32>(), 42);
|
/// assert_eq!(x.cast::<u32>(), 42);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn cast<T: Any + Clone>(self) -> T {
|
pub fn cast<T: Any + Clone>(self) -> T {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
@ -1481,7 +1479,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1).
|
/// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1).
|
||||||
/// Otherwise, this call panics if the data is currently borrowed for write.
|
/// Otherwise, this call panics if the data is currently borrowed for write.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn read_lock<T: Any + Clone>(&self) -> Option<DynamicReadLock<T>> {
|
pub fn read_lock<T: Any + Clone>(&self) -> Option<DynamicReadLock<T>> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
@ -1515,7 +1513,7 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1).
|
/// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1).
|
||||||
/// Otherwise, this call panics if the data is currently borrowed for write.
|
/// Otherwise, this call panics if the data is currently borrowed for write.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn write_lock<T: Any + Clone>(&mut self) -> Option<DynamicWriteLock<T>> {
|
pub fn write_lock<T: Any + Clone>(&mut self) -> Option<DynamicWriteLock<T>> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
@ -1836,7 +1834,7 @@ impl Dynamic {
|
|||||||
}
|
}
|
||||||
/// Convert the [`Dynamic`] into an [`ImmutableString`] and return it.
|
/// Convert the [`Dynamic`] into an [`ImmutableString`] and return it.
|
||||||
/// Returns the name of the actual type if the cast fails.
|
/// Returns the name of the actual type if the cast fails.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn as_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
pub fn as_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
|
@ -67,7 +67,10 @@ impl Imports {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Default::default()
|
Self {
|
||||||
|
keys: StaticVec::new(),
|
||||||
|
modules: StaticVec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Get the length of this stack of imported [modules][Module].
|
/// Get the length of this stack of imported [modules][Module].
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -376,7 +379,7 @@ pub enum Target<'a> {
|
|||||||
impl<'a> Target<'a> {
|
impl<'a> Target<'a> {
|
||||||
/// Is the `Target` a reference pointing to other data?
|
/// Is the `Target` a reference pointing to other data?
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_ref(&self) -> bool {
|
pub const fn is_ref(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -391,7 +394,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is the `Target` a temp value?
|
/// Is the `Target` a temp value?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_temp_value(&self) -> bool {
|
pub const fn is_temp_value(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -407,7 +410,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
/// Is the `Target` a shared value?
|
/// Is the `Target` a shared value?
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_shared(&self) -> bool {
|
pub fn is_shared(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -423,7 +426,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
/// Is the `Target` a specific type?
|
/// Is the `Target` a specific type?
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is<T: Variant + Clone>(&self) -> bool {
|
pub fn is<T: Variant + Clone>(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -438,7 +441,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the value of the `Target` as a `Dynamic`, cloning a referenced value if necessary.
|
/// Get the value of the `Target` as a `Dynamic`, cloning a referenced value if necessary.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn take_or_clone(self) -> Dynamic {
|
pub fn take_or_clone(self) -> Dynamic {
|
||||||
match self {
|
match self {
|
||||||
@ -469,7 +472,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
/// Propagate a changed value back to the original source.
|
/// Propagate a changed value back to the original source.
|
||||||
/// This has no effect except for string indexing.
|
/// This has no effect except for string indexing.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn propagate_changed_value(&mut self) -> Result<(), Box<EvalAltResult>> {
|
pub fn propagate_changed_value(&mut self) -> Result<(), Box<EvalAltResult>> {
|
||||||
match self {
|
match self {
|
||||||
@ -534,7 +537,7 @@ impl<'a> Target<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a mut Dynamic> for Target<'a> {
|
impl<'a> From<&'a mut Dynamic> for Target<'a> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn from(value: &'a mut Dynamic) -> Self {
|
fn from(value: &'a mut Dynamic) -> Self {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
if value.is_shared() {
|
if value.is_shared() {
|
||||||
@ -555,7 +558,7 @@ impl<'a> From<&'a mut Dynamic> for Target<'a> {
|
|||||||
impl Deref for Target<'_> {
|
impl Deref for Target<'_> {
|
||||||
type Target = Dynamic;
|
type Target = Dynamic;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn deref(&self) -> &Dynamic {
|
fn deref(&self) -> &Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(r) => *r,
|
Self::RefMut(r) => *r,
|
||||||
@ -578,7 +581,7 @@ impl AsRef<Dynamic> for Target<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Target<'_> {
|
impl DerefMut for Target<'_> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Dynamic {
|
fn deref_mut(&mut self) -> &mut Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(r) => *r,
|
Self::RefMut(r) => *r,
|
||||||
@ -947,7 +950,7 @@ impl Default for Engine {
|
|||||||
|
|
||||||
/// Make getter function
|
/// Make getter function
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn make_getter(id: &str) -> String {
|
pub fn make_getter(id: &str) -> String {
|
||||||
format!("{}{}", FN_GET, id)
|
format!("{}{}", FN_GET, id)
|
||||||
@ -955,7 +958,7 @@ pub fn make_getter(id: &str) -> String {
|
|||||||
|
|
||||||
/// Make setter function
|
/// Make setter function
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn make_setter(id: &str) -> String {
|
pub fn make_setter(id: &str) -> String {
|
||||||
format!("{}{}", FN_SET, id)
|
format!("{}{}", FN_SET, id)
|
||||||
@ -970,7 +973,7 @@ pub fn is_anonymous_fn(fn_name: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Print to `stdout`
|
/// Print to `stdout`
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn print_to_stdout(s: &str) {
|
fn print_to_stdout(s: &str) {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
@ -979,7 +982,7 @@ fn print_to_stdout(s: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Debug to `stdout`
|
/// Debug to `stdout`
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn debug_to_stdout(s: &str, source: Option<&str>, pos: Position) {
|
fn debug_to_stdout(s: &str, source: Option<&str>, pos: Position) {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
@ -1021,7 +1024,7 @@ impl Engine {
|
|||||||
/// Create a new [`Engine`] with minimal built-in functions.
|
/// Create a new [`Engine`] with minimal built-in functions.
|
||||||
///
|
///
|
||||||
/// Use [`register_global_module`][Engine::register_global_module] to add packages of functions.
|
/// Use [`register_global_module`][Engine::register_global_module] to add packages of functions.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new_raw() -> Self {
|
pub fn new_raw() -> Self {
|
||||||
let mut engine = Self {
|
let mut engine = Self {
|
||||||
|
@ -329,8 +329,7 @@ impl Engine {
|
|||||||
name: &str,
|
name: &str,
|
||||||
get_fn: impl Fn(&mut T) -> V + SendSync + 'static,
|
get_fn: impl Fn(&mut T) -> V + SendSync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
use crate::engine::make_getter;
|
self.register_fn(&crate::engine::make_getter(name), get_fn)
|
||||||
self.register_fn(&make_getter(name), get_fn)
|
|
||||||
}
|
}
|
||||||
/// 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`].
|
||||||
///
|
///
|
||||||
@ -378,8 +377,7 @@ impl Engine {
|
|||||||
name: &str,
|
name: &str,
|
||||||
get_fn: impl Fn(&mut T) -> Result<V, Box<EvalAltResult>> + SendSync + 'static,
|
get_fn: impl Fn(&mut T) -> Result<V, Box<EvalAltResult>> + SendSync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
use crate::engine::make_getter;
|
self.register_result_fn(&crate::engine::make_getter(name), get_fn)
|
||||||
self.register_result_fn(&make_getter(name), get_fn)
|
|
||||||
}
|
}
|
||||||
/// 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`].
|
||||||
///
|
///
|
||||||
@ -426,8 +424,7 @@ impl Engine {
|
|||||||
name: &str,
|
name: &str,
|
||||||
set_fn: impl Fn(&mut T, V) + SendSync + 'static,
|
set_fn: impl Fn(&mut T, V) + SendSync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
use crate::engine::make_setter;
|
self.register_fn(&crate::engine::make_setter(name), set_fn)
|
||||||
self.register_fn(&make_setter(name), set_fn)
|
|
||||||
}
|
}
|
||||||
/// 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`].
|
||||||
///
|
///
|
||||||
@ -477,8 +474,7 @@ impl Engine {
|
|||||||
name: &str,
|
name: &str,
|
||||||
set_fn: impl Fn(&mut T, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static,
|
set_fn: impl Fn(&mut T, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
use crate::engine::make_setter;
|
self.register_result_fn(&crate::engine::make_setter(name), set_fn)
|
||||||
self.register_result_fn(&make_setter(name), set_fn)
|
|
||||||
}
|
}
|
||||||
/// 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`].
|
||||||
@ -1189,7 +1185,7 @@ impl Engine {
|
|||||||
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]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn compile_with_scope_and_optimization_level(
|
pub(crate) fn compile_with_scope_and_optimization_level(
|
||||||
&self,
|
&self,
|
||||||
@ -1476,7 +1472,7 @@ impl Engine {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn compile_expression_with_scope(
|
pub fn compile_expression_with_scope(
|
||||||
&self,
|
&self,
|
||||||
@ -1644,7 +1640,7 @@ impl Engine {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn eval_expression_with_scope<T: Variant + Clone>(
|
pub fn eval_expression_with_scope<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
@ -1717,7 +1713,7 @@ impl Engine {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn eval_ast_with_scope<T: Variant + Clone>(
|
pub fn eval_ast_with_scope<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
@ -1740,7 +1736,7 @@ impl Engine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
/// Evaluate an [`AST`] with own scope.
|
/// Evaluate an [`AST`] with own scope.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn eval_ast_with_scope_raw<'a>(
|
pub(crate) fn eval_ast_with_scope_raw<'a>(
|
||||||
&self,
|
&self,
|
||||||
@ -1797,7 +1793,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
/// 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(always)]
|
#[inline]
|
||||||
pub fn consume_with_scope(
|
pub fn consume_with_scope(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
@ -1824,7 +1820,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
/// 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]
|
||||||
pub fn consume_ast_with_scope(
|
pub fn consume_ast_with_scope(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
@ -1889,7 +1885,7 @@ impl Engine {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn call_fn<T: Variant + Clone>(
|
pub fn call_fn<T: Variant + Clone>(
|
||||||
&self,
|
&self,
|
||||||
@ -1970,7 +1966,7 @@ impl Engine {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn call_fn_dynamic(
|
pub fn call_fn_dynamic(
|
||||||
&self,
|
&self,
|
||||||
@ -1995,7 +1991,7 @@ impl Engine {
|
|||||||
/// Do not use the arguments after this call. If they are needed afterwards,
|
/// Do not use the arguments after this call. If they are needed afterwards,
|
||||||
/// clone them _before_ calling this function.
|
/// clone them _before_ calling this function.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn call_fn_dynamic_raw(
|
pub(crate) fn call_fn_dynamic_raw(
|
||||||
&self,
|
&self,
|
||||||
@ -2052,7 +2048,7 @@ impl Engine {
|
|||||||
/// (i.e. with [`Scope::push_constant`]).
|
/// (i.e. with [`Scope::push_constant`]).
|
||||||
/// Then, the [`AST`] is cloned and the copy re-optimized before running.
|
/// Then, the [`AST`] is cloned and the copy re-optimized before running.
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn optimize_ast(
|
pub fn optimize_ast(
|
||||||
&self,
|
&self,
|
||||||
@ -2087,6 +2083,7 @@ impl Engine {
|
|||||||
/// 2) Functions in registered sub-modules
|
/// 2) Functions in registered sub-modules
|
||||||
/// 3) Functions in packages (optional)
|
/// 3) Functions in packages (optional)
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn gen_fn_signatures(&self, include_packages: bool) -> Vec<String> {
|
pub fn gen_fn_signatures(&self, include_packages: bool) -> Vec<String> {
|
||||||
let mut signatures: Vec<_> = Default::default();
|
let mut signatures: Vec<_> = Default::default();
|
||||||
|
@ -39,7 +39,6 @@ pub enum LexError {
|
|||||||
impl Error for LexError {}
|
impl Error for LexError {}
|
||||||
|
|
||||||
impl fmt::Display for LexError {
|
impl fmt::Display for LexError {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::UnexpectedInput(s) => write!(f, "Unexpected '{}'", s),
|
Self::UnexpectedInput(s) => write!(f, "Unexpected '{}'", s),
|
||||||
@ -283,7 +282,6 @@ pub struct ParseError(pub Box<ParseErrorType>, pub Position);
|
|||||||
impl Error for ParseError {}
|
impl Error for ParseError {}
|
||||||
|
|
||||||
impl fmt::Display for ParseError {
|
impl fmt::Display for ParseError {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.0, f)?;
|
fmt::Display::fmt(&self.0, f)?;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use rust_decimal::Decimal;
|
|||||||
const BUILTIN: &str = "never fails because this is built-in code and the type is already checked";
|
const BUILTIN: &str = "never fails because this is built-in code and the type is already checked";
|
||||||
|
|
||||||
/// Is the type a numeric type?
|
/// Is the type a numeric type?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn is_numeric(type_id: TypeId) -> bool {
|
fn is_numeric(type_id: TypeId) -> bool {
|
||||||
let result = type_id == TypeId::of::<u8>()
|
let result = type_id == TypeId::of::<u8>()
|
||||||
@ -206,7 +206,6 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
|
|
||||||
// char op string
|
// char op string
|
||||||
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
||||||
#[inline(always)]
|
|
||||||
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
||||||
let x = args[0].as_char().expect(BUILTIN);
|
let x = args[0].as_char().expect(BUILTIN);
|
||||||
let y = &*args[1].read_lock::<ImmutableString>().expect(BUILTIN);
|
let y = &*args[1].read_lock::<ImmutableString>().expect(BUILTIN);
|
||||||
@ -233,7 +232,6 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
}
|
}
|
||||||
// string op char
|
// string op char
|
||||||
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
||||||
#[inline(always)]
|
|
||||||
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
||||||
let x = &*args[0].read_lock::<ImmutableString>().expect(BUILTIN);
|
let x = &*args[0].read_lock::<ImmutableString>().expect(BUILTIN);
|
||||||
let y = args[1].as_char().expect(BUILTIN);
|
let y = args[1].as_char().expect(BUILTIN);
|
||||||
|
@ -100,7 +100,7 @@ impl Drop for ArgBackup<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn ensure_no_data_race(
|
pub fn ensure_no_data_race(
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
@ -157,7 +157,6 @@ impl Engine {
|
|||||||
/// 3) Global modules - packages
|
/// 3) Global modules - packages
|
||||||
/// 4) Imported modules - functions marked with global namespace
|
/// 4) Imported modules - functions marked with global namespace
|
||||||
/// 5) Global sub-modules - functions marked with global namespace
|
/// 5) Global sub-modules - functions marked with global namespace
|
||||||
#[inline(always)]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn resolve_fn<'s>(
|
fn resolve_fn<'s>(
|
||||||
&self,
|
&self,
|
||||||
@ -447,7 +446,6 @@ impl Engine {
|
|||||||
pos: Position,
|
pos: Position,
|
||||||
level: usize,
|
level: usize,
|
||||||
) -> RhaiResult {
|
) -> RhaiResult {
|
||||||
#[inline(always)]
|
|
||||||
fn make_error(
|
fn make_error(
|
||||||
name: String,
|
name: String,
|
||||||
fn_def: &crate::ast::ScriptFnDef,
|
fn_def: &crate::ast::ScriptFnDef,
|
||||||
@ -564,7 +562,6 @@ impl Engine {
|
|||||||
|
|
||||||
// Does a scripted function exist?
|
// Does a scripted function exist?
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn has_script_fn(
|
pub(crate) fn has_script_fn(
|
||||||
&self,
|
&self,
|
||||||
@ -619,7 +616,6 @@ impl Engine {
|
|||||||
_capture_scope: Option<Scope>,
|
_capture_scope: Option<Scope>,
|
||||||
_level: usize,
|
_level: usize,
|
||||||
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
||||||
#[inline(always)]
|
|
||||||
fn no_method_err(name: &str, pos: Position) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
fn no_method_err(name: &str, pos: Position) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
||||||
let msg = format!("'{0}' should not be called this way. Try {0}(...);", name);
|
let msg = format!("'{0}' should not be called this way. Try {0}(...);", name);
|
||||||
EvalAltResult::ErrorRuntime(msg.into(), pos).into()
|
EvalAltResult::ErrorRuntime(msg.into(), pos).into()
|
||||||
@ -782,7 +778,7 @@ impl Engine {
|
|||||||
|
|
||||||
/// Evaluate a list of statements with no `this` pointer.
|
/// Evaluate a list of statements with no `this` pointer.
|
||||||
/// This is commonly used to evaluate a list of statements in an [`AST`] or a script function body.
|
/// This is commonly used to evaluate a list of statements in an [`AST`] or a script function body.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn eval_global_statements(
|
pub(crate) fn eval_global_statements(
|
||||||
&self,
|
&self,
|
||||||
@ -1018,7 +1014,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an argument.
|
/// Evaluate an argument.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_arg_value(
|
pub(crate) fn get_arg_value(
|
||||||
&self,
|
&self,
|
||||||
|
@ -21,7 +21,7 @@ impl Hasher for StraightHasher {
|
|||||||
fn finish(&self) -> u64 {
|
fn finish(&self) -> u64 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn write(&mut self, bytes: &[u8]) {
|
fn write(&mut self, bytes: &[u8]) {
|
||||||
assert_eq!(bytes.len(), 8, "StraightHasher can only hash u64 values");
|
assert_eq!(bytes.len(), 8, "StraightHasher can only hash u64 values");
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
///
|
///
|
||||||
/// If `is_method` is [`true`], the first argument is assumed to be passed
|
/// If `is_method` is [`true`], the first argument is assumed to be passed
|
||||||
/// by reference and is not consumed.
|
/// by reference and is not consumed.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn call_fn_dynamic_raw(
|
pub fn call_fn_dynamic_raw(
|
||||||
&self,
|
&self,
|
||||||
@ -338,7 +338,6 @@ pub enum CallableFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for CallableFunction {
|
impl fmt::Debug for CallableFunction {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => write!(f, "NativePureFunction"),
|
Self::Pure(_) => write!(f, "NativePureFunction"),
|
||||||
@ -353,7 +352,6 @@ impl fmt::Debug for CallableFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CallableFunction {
|
impl fmt::Display for CallableFunction {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => write!(f, "NativePureFunction"),
|
Self::Pure(_) => write!(f, "NativePureFunction"),
|
||||||
@ -369,7 +367,7 @@ impl fmt::Display for CallableFunction {
|
|||||||
|
|
||||||
impl CallableFunction {
|
impl CallableFunction {
|
||||||
/// Is this a pure native Rust function?
|
/// Is this a pure native Rust function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_pure(&self) -> bool {
|
pub fn is_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -383,7 +381,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a native Rust method function?
|
/// Is this a native Rust method function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_method(&self) -> bool {
|
pub fn is_method(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -397,7 +395,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this an iterator function?
|
/// Is this an iterator function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_iter(&self) -> bool {
|
pub const fn is_iter(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -409,7 +407,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a Rhai-scripted function?
|
/// Is this a Rhai-scripted function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_script(&self) -> bool {
|
pub const fn is_script(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -420,7 +418,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a plugin function?
|
/// Is this a plugin function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_plugin_fn(&self) -> bool {
|
pub const fn is_plugin_fn(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -432,7 +430,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a native Rust function?
|
/// Is this a native Rust function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_native(&self) -> bool {
|
pub const fn is_native(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -445,7 +443,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the access mode.
|
/// Get the access mode.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn access(&self) -> FnAccess {
|
pub fn access(&self) -> FnAccess {
|
||||||
match self {
|
match self {
|
||||||
@ -457,7 +455,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get a shared reference to a native Rust function.
|
/// Get a shared reference to a native Rust function.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_native_fn(&self) -> Option<&Shared<FnAny>> {
|
pub fn get_native_fn(&self) -> Option<&Shared<FnAny>> {
|
||||||
match self {
|
match self {
|
||||||
@ -472,7 +470,7 @@ impl CallableFunction {
|
|||||||
///
|
///
|
||||||
/// Not available under `no_function`.
|
/// Not available under `no_function`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn get_script_fn_def(&self) -> Option<&Shared<crate::ast::ScriptFnDef>> {
|
pub const fn get_script_fn_def(&self) -> Option<&Shared<crate::ast::ScriptFnDef>> {
|
||||||
match self {
|
match self {
|
||||||
@ -481,7 +479,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get a reference to an iterator function.
|
/// Get a reference to an iterator function.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_iter_fn(&self) -> Option<IteratorFn> {
|
pub fn get_iter_fn(&self) -> Option<IteratorFn> {
|
||||||
match self {
|
match self {
|
||||||
@ -493,7 +491,7 @@ impl CallableFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get a shared reference to a plugin function.
|
/// Get a shared reference to a plugin function.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_plugin_fn<'s>(&'s self) -> Option<&Shared<FnPlugin>> {
|
pub fn get_plugin_fn<'s>(&'s self) -> Option<&Shared<FnPlugin>> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -96,7 +96,7 @@ impl FnPtr {
|
|||||||
/// This is to avoid unnecessarily cloning the arguments.
|
/// This is to avoid unnecessarily cloning the arguments.
|
||||||
/// Do not use the arguments after this call. If they are needed afterwards,
|
/// Do not use the arguments after this call. If they are needed afterwards,
|
||||||
/// clone them _before_ calling this function.
|
/// clone them _before_ calling this function.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn call_dynamic(
|
pub fn call_dynamic(
|
||||||
&self,
|
&self,
|
||||||
@ -127,7 +127,6 @@ impl FnPtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for FnPtr {
|
impl fmt::Display for FnPtr {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Fn({})", self.0)
|
write!(f, "Fn({})", self.0)
|
||||||
}
|
}
|
||||||
@ -136,7 +135,7 @@ impl fmt::Display for FnPtr {
|
|||||||
impl TryFrom<Identifier> for FnPtr {
|
impl TryFrom<Identifier> for FnPtr {
|
||||||
type Error = Box<EvalAltResult>;
|
type Error = Box<EvalAltResult>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn try_from(value: Identifier) -> Result<Self, Self::Error> {
|
fn try_from(value: Identifier) -> Result<Self, Self::Error> {
|
||||||
if is_valid_identifier(value.chars()) {
|
if is_valid_identifier(value.chars()) {
|
||||||
Ok(Self(value, Default::default()))
|
Ok(Self(value, Default::default()))
|
||||||
|
@ -88,7 +88,7 @@ pub trait RegisterNativeFunction<Args, Result> {
|
|||||||
fn return_type_name() -> &'static str;
|
fn return_type_name() -> &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn is_setter(_fn_name: &str) -> bool {
|
fn is_setter(_fn_name: &str) -> bool {
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
@ -322,7 +322,7 @@ impl Add<String> for &ImmutableString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AddAssign<String> for ImmutableString {
|
impl AddAssign<String> for ImmutableString {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: String) {
|
fn add_assign(&mut self, rhs: String) {
|
||||||
if !rhs.is_empty() {
|
if !rhs.is_empty() {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
|
@ -112,7 +112,7 @@ impl FuncInfo {
|
|||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn calc_native_fn_hash<'a>(
|
fn calc_native_fn_hash<'a>(
|
||||||
modules: impl Iterator<Item = &'a str>,
|
modules: impl Iterator<Item = &'a str>,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
@ -324,7 +324,7 @@ impl Module {
|
|||||||
/// let module = Module::new();
|
/// let module = Module::new();
|
||||||
/// assert!(module.is_empty());
|
/// assert!(module.is_empty());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.functions.is_empty()
|
self.functions.is_empty()
|
||||||
@ -437,7 +437,7 @@ impl Module {
|
|||||||
/// module.set_var("answer", 42_i64);
|
/// module.set_var("answer", 42_i64);
|
||||||
/// assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
|
/// assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_var(
|
pub fn set_var(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<Identifier>,
|
name: impl Into<Identifier>,
|
||||||
@ -519,7 +519,7 @@ impl Module {
|
|||||||
/// By taking a mutable reference, it is assumed that some sub-modules will be modified.
|
/// By taking a mutable reference, it is assumed that some sub-modules will be modified.
|
||||||
/// Thus the [`Module`] is automatically set to be non-indexed.
|
/// Thus the [`Module`] is automatically set to be non-indexed.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn sub_modules_mut(&mut self) -> &mut BTreeMap<Identifier, Shared<Module>> {
|
pub(crate) fn sub_modules_mut(&mut self) -> &mut BTreeMap<Identifier, Shared<Module>> {
|
||||||
// We must assume that the user has changed the sub-modules
|
// We must assume that the user has changed the sub-modules
|
||||||
@ -580,7 +580,7 @@ impl Module {
|
|||||||
/// module.set_sub_module("question", sub_module);
|
/// module.set_sub_module("question", sub_module);
|
||||||
/// assert!(module.get_sub_module("question").is_some());
|
/// assert!(module.get_sub_module("question").is_some());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_sub_module(
|
pub fn set_sub_module(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<Identifier>,
|
name: impl Into<Identifier>,
|
||||||
@ -624,7 +624,7 @@ impl Module {
|
|||||||
/// The _last entry_ in the list should be the _return type_ of the function.
|
/// The _last entry_ in the list should be the _return type_ of the function.
|
||||||
/// In other words, the number of entries should be one larger than the number of parameters.
|
/// In other words, the number of entries should be one larger than the number of parameters.
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn update_fn_metadata(&mut self, hash_fn: u64, arg_names: &[&str]) -> &mut Self {
|
pub fn update_fn_metadata(&mut self, hash_fn: u64, arg_names: &[&str]) -> &mut Self {
|
||||||
let param_names = arg_names
|
let param_names = arg_names
|
||||||
.iter()
|
.iter()
|
||||||
@ -641,7 +641,7 @@ impl Module {
|
|||||||
/// Update the namespace of a registered function.
|
/// Update the namespace of a registered function.
|
||||||
///
|
///
|
||||||
/// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call.
|
/// The [`u64`] hash is returned by the [`set_native_fn`][Module::set_native_fn] call.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn update_fn_namespace(&mut self, hash_fn: u64, namespace: FnNamespace) -> &mut Self {
|
pub fn update_fn_namespace(&mut self, hash_fn: u64, namespace: FnNamespace) -> &mut Self {
|
||||||
if let Some(f) = self.functions.get_mut(&hash_fn) {
|
if let Some(f) = self.functions.get_mut(&hash_fn) {
|
||||||
f.namespace = namespace;
|
f.namespace = namespace;
|
||||||
@ -652,7 +652,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remap type ID.
|
/// Remap type ID.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn map_type(map: bool, type_id: TypeId) -> TypeId {
|
fn map_type(map: bool, type_id: TypeId) -> TypeId {
|
||||||
if !map {
|
if !map {
|
||||||
@ -1611,7 +1611,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set a type iterator into the [`Module`].
|
/// Set a type iterator into the [`Module`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_iter(&mut self, type_id: TypeId, func: IteratorFn) -> &mut Self {
|
pub fn set_iter(&mut self, type_id: TypeId, func: IteratorFn) -> &mut Self {
|
||||||
if self.indexed {
|
if self.indexed {
|
||||||
self.all_type_iterators.insert(type_id, func.clone());
|
self.all_type_iterators.insert(type_id, func.clone());
|
||||||
@ -1678,7 +1678,6 @@ pub struct NamespaceRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for NamespaceRef {
|
impl fmt::Debug for NamespaceRef {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
if let Some(index) = self.index {
|
if let Some(index) = self.index {
|
||||||
write!(f, "{} -> ", index)?;
|
write!(f, "{} -> ", index)?;
|
||||||
@ -1696,7 +1695,6 @@ impl fmt::Debug for NamespaceRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NamespaceRef {
|
impl fmt::Display for NamespaceRef {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
for Ident { name, .. } in self.path.iter() {
|
for Ident { name, .. } in self.path.iter() {
|
||||||
write!(f, "{}{}", name, Token::DoubleColon.syntax())?;
|
write!(f, "{}{}", name, Token::DoubleColon.syntax())?;
|
||||||
@ -1735,7 +1733,10 @@ impl NamespaceRef {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(&self) -> Self {
|
pub fn new(&self) -> Self {
|
||||||
Default::default()
|
Self {
|
||||||
|
index: None,
|
||||||
|
path: StaticVec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Get the [`Scope`][crate::Scope] index offset.
|
/// Get the [`Scope`][crate::Scope] index offset.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -200,7 +200,7 @@ impl FileModuleResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Is a particular path cached?
|
/// Is a particular path cached?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_cached(&self, path: &str, source_path: Option<&str>) -> bool {
|
pub fn is_cached(&self, path: &str, source_path: Option<&str>) -> bool {
|
||||||
if !self.cache_enabled {
|
if !self.cache_enabled {
|
||||||
@ -227,7 +227,7 @@ impl FileModuleResolver {
|
|||||||
/// Remove the specified path from internal cache.
|
/// Remove the specified path from internal cache.
|
||||||
///
|
///
|
||||||
/// The next time this path is resolved, the script file will be loaded once again.
|
/// The next time this path is resolved, the script file will be loaded once again.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn clear_cache_for_path(
|
pub fn clear_cache_for_path(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -252,7 +252,6 @@ impl FileModuleResolver {
|
|||||||
}
|
}
|
||||||
/// Construct a full file path.
|
/// Construct a full file path.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[must_use]
|
|
||||||
fn get_file_path(&self, path: &str, source_path: Option<&str>) -> PathBuf {
|
fn get_file_path(&self, path: &str, source_path: Option<&str>) -> PathBuf {
|
||||||
let path = Path::new(path);
|
let path = Path::new(path);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin
|
|||||||
|
|
||||||
// Register print and debug
|
// Register print and debug
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn print_with_func(
|
pub fn print_with_func(
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
ctx: &NativeCallContext,
|
ctx: &NativeCallContext,
|
||||||
|
@ -59,7 +59,7 @@ pub struct IdentifierBuilder(
|
|||||||
|
|
||||||
impl IdentifierBuilder {
|
impl IdentifierBuilder {
|
||||||
/// Get an identifier from a text string.
|
/// Get an identifier from a text string.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get(&mut self, text: impl AsRef<str> + Into<Identifier>) -> Identifier {
|
pub fn get(&mut self, text: impl AsRef<str> + Into<Identifier>) -> Identifier {
|
||||||
#[cfg(not(feature = "no_smartstring"))]
|
#[cfg(not(feature = "no_smartstring"))]
|
||||||
@ -141,7 +141,7 @@ impl<'e> ParseState<'e> {
|
|||||||
/// i.e. the top element of [`ParseState`]'s variables stack is offset 1.
|
/// i.e. the top element of [`ParseState`]'s variables stack is offset 1.
|
||||||
///
|
///
|
||||||
/// Return `None` when the variable name is not found in the `stack`.
|
/// Return `None` when the variable name is not found in the `stack`.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn access_var(&mut self, name: &str, _pos: Position) -> Option<NonZeroUsize> {
|
pub fn access_var(&mut self, name: &str, _pos: Position) -> Option<NonZeroUsize> {
|
||||||
let mut barrier = false;
|
let mut barrier = false;
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ impl ParseSettings {
|
|||||||
}
|
}
|
||||||
/// Make sure that the current level of expression nesting is within the maximum limit.
|
/// Make sure that the current level of expression nesting is within the maximum limit.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn ensure_level_within_max_limit(
|
pub fn ensure_level_within_max_limit(
|
||||||
&self,
|
&self,
|
||||||
@ -261,7 +261,7 @@ impl Expr {
|
|||||||
/// Convert a [`Variable`][Expr::Variable] into a [`Property`][Expr::Property].
|
/// Convert a [`Variable`][Expr::Variable] into a [`Property`][Expr::Property].
|
||||||
/// All other variants are untouched.
|
/// All other variants are untouched.
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn into_property(self, state: &mut ParseState) -> Self {
|
fn into_property(self, state: &mut ParseState) -> Self {
|
||||||
match self {
|
match self {
|
||||||
|
23
src/scope.rs
23
src/scope.rs
@ -49,7 +49,7 @@ const SCOPE_ENTRIES_INLINED: usize = 8;
|
|||||||
// look up a variable. Variable lookup is usually via direct indexing, by-passing the name altogether.
|
// look up a variable. Variable lookup is usually via direct indexing, by-passing the name altogether.
|
||||||
//
|
//
|
||||||
// Since [`Dynamic`] is reasonably small, packing it tightly improves cache locality when variables are accessed.
|
// Since [`Dynamic`] is reasonably small, packing it tightly improves cache locality when variables are accessed.
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash, Default)]
|
||||||
pub struct Scope<'a> {
|
pub struct Scope<'a> {
|
||||||
/// Current value of the entry.
|
/// Current value of the entry.
|
||||||
values: smallvec::SmallVec<[Dynamic; SCOPE_ENTRIES_INLINED]>,
|
values: smallvec::SmallVec<[Dynamic; SCOPE_ENTRIES_INLINED]>,
|
||||||
@ -59,13 +59,6 @@ pub struct Scope<'a> {
|
|||||||
>,
|
>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Scope<'_> {
|
|
||||||
#[inline(always)]
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> IntoIterator for Scope<'a> {
|
impl<'a> IntoIterator for Scope<'a> {
|
||||||
type Item = (Cow<'a, str>, Dynamic);
|
type Item = (Cow<'a, str>, Dynamic);
|
||||||
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
|
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
|
||||||
@ -97,10 +90,7 @@ impl<'a> Scope<'a> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Default::default()
|
||||||
values: Default::default(),
|
|
||||||
names: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Empty the [`Scope`].
|
/// Empty the [`Scope`].
|
||||||
///
|
///
|
||||||
@ -246,7 +236,7 @@ impl<'a> Scope<'a> {
|
|||||||
self.push_dynamic_value(name, AccessMode::ReadOnly, value)
|
self.push_dynamic_value(name, AccessMode::ReadOnly, value)
|
||||||
}
|
}
|
||||||
/// Add (push) a new entry with a [`Dynamic`] value to the [`Scope`].
|
/// Add (push) a new entry with a [`Dynamic`] value to the [`Scope`].
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn push_dynamic_value(
|
pub(crate) fn push_dynamic_value(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<Cow<'a, str>>,
|
name: impl Into<Cow<'a, str>>,
|
||||||
@ -371,7 +361,7 @@ impl<'a> Scope<'a> {
|
|||||||
/// my_scope.set_value("x", 0_i64);
|
/// my_scope.set_value("x", 0_i64);
|
||||||
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 0);
|
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 0);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn set_value(&mut self, name: &'a str, value: impl Variant + Clone) -> &mut Self {
|
pub fn set_value(&mut self, name: &'a str, value: impl Variant + Clone) -> &mut Self {
|
||||||
match self.get_index(name) {
|
match self.get_index(name) {
|
||||||
None => {
|
None => {
|
||||||
@ -408,6 +398,7 @@ impl<'a> Scope<'a> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 123);
|
/// assert_eq!(my_scope.get_value::<i64>("x").unwrap(), 123);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_mut(&mut self, name: &str) -> Option<&mut Dynamic> {
|
pub fn get_mut(&mut self, name: &str) -> Option<&mut Dynamic> {
|
||||||
self.get_index(name)
|
self.get_index(name)
|
||||||
@ -434,7 +425,7 @@ impl<'a> Scope<'a> {
|
|||||||
///
|
///
|
||||||
/// Panics if the index is out of bounds.
|
/// Panics if the index is out of bounds.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub(crate) fn add_entry_alias(&mut self, index: usize, alias: Identifier) -> &mut Self {
|
pub(crate) fn add_entry_alias(&mut self, index: usize, alias: Identifier) -> &mut Self {
|
||||||
let (_, aliases) = self
|
let (_, aliases) = self
|
||||||
.names
|
.names
|
||||||
@ -456,7 +447,7 @@ impl<'a> Scope<'a> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn clone_visible(&self) -> Self {
|
pub(crate) fn clone_visible(&self) -> Self {
|
||||||
let mut entries: Self = Default::default();
|
let mut entries = Self::new();
|
||||||
|
|
||||||
self.names
|
self.names
|
||||||
.iter()
|
.iter()
|
||||||
|
16
src/token.rs
16
src/token.rs
@ -211,7 +211,6 @@ impl Default for Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Position {
|
impl fmt::Display for Position {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
if self.is_none() {
|
if self.is_none() {
|
||||||
write!(f, "none")?;
|
write!(f, "none")?;
|
||||||
@ -227,7 +226,6 @@ impl fmt::Display for Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Position {
|
impl fmt::Debug for Position {
|
||||||
#[inline(always)]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
write!(f, "{}:{}", self.line, self.pos)?;
|
write!(f, "{}:{}", self.line, self.pos)?;
|
||||||
@ -772,10 +770,8 @@ impl Token {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_eof(&self) -> bool {
|
pub const fn is_eof(&self) -> bool {
|
||||||
use Token::*;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
EOF => true,
|
Self::EOF => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -917,6 +913,7 @@ impl Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Is this token an active standard keyword?
|
/// Is this token an active standard keyword?
|
||||||
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_keyword(&self) -> bool {
|
pub const fn is_keyword(&self) -> bool {
|
||||||
use Token::*;
|
use Token::*;
|
||||||
@ -947,6 +944,7 @@ impl Token {
|
|||||||
|
|
||||||
/// Convert a token into a function name, if possible.
|
/// Convert a token into a function name, if possible.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn into_function_name_for_override(self) -> Result<String, Self> {
|
pub(crate) fn into_function_name_for_override(self) -> Result<String, Self> {
|
||||||
match self {
|
match self {
|
||||||
@ -1304,7 +1302,7 @@ fn scan_block_comment(
|
|||||||
/// # Volatile API
|
/// # Volatile API
|
||||||
///
|
///
|
||||||
/// This function is volatile and may change.
|
/// This function is volatile and may change.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_next_token(
|
pub fn get_next_token(
|
||||||
stream: &mut impl InputStream,
|
stream: &mut impl InputStream,
|
||||||
@ -1986,7 +1984,7 @@ fn get_identifier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Is this keyword allowed as a function?
|
/// Is this keyword allowed as a function?
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_keyword_function(name: &str) -> bool {
|
pub fn is_keyword_function(name: &str) -> bool {
|
||||||
match name {
|
match name {
|
||||||
@ -2062,7 +2060,7 @@ pub struct MultiInputsStream<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InputStream for MultiInputsStream<'_> {
|
impl InputStream for MultiInputsStream<'_> {
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn unget(&mut self, ch: char) {
|
fn unget(&mut self, ch: char) {
|
||||||
if self.buf.is_some() {
|
if self.buf.is_some() {
|
||||||
panic!("cannot unget two characters in a row");
|
panic!("cannot unget two characters in a row");
|
||||||
@ -2252,7 +2250,7 @@ impl Engine {
|
|||||||
self.lex_raw(input, Some(map))
|
self.lex_raw(input, Some(map))
|
||||||
}
|
}
|
||||||
/// Tokenize an input text stream with an optional mapping function.
|
/// Tokenize an input text stream with an optional mapping function.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn lex_raw<'a>(
|
pub(crate) fn lex_raw<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
Loading…
Reference in New Issue
Block a user