Hard code constant checking.

This commit is contained in:
Stephen Chung
2022-12-03 16:20:13 +08:00
parent ffc8a7f85c
commit 55922b5c20
16 changed files with 474 additions and 374 deletions

View File

@@ -14,10 +14,10 @@ use std::prelude::v1::*;
#[non_exhaustive]
pub enum CallableFunction {
/// A pure native Rust function with all arguments passed by value.
Pure(Shared<FnAny>),
Pure(Shared<FnAny>, bool),
/// A native Rust object method with the first argument passed by reference,
/// and the rest passed by value.
Method(Shared<FnAny>),
Method(Shared<FnAny>, bool),
/// An iterator function.
Iterator(Shared<IteratorFn>),
/// A plugin function,
@@ -136,6 +136,17 @@ impl CallableFunction {
Self::Script(..) => false,
}
}
/// Is there a [`NativeCallContext`] parameter?
#[inline]
#[must_use]
pub fn has_context(&self) -> bool {
match self {
Self::Pure(.., ctx) | Self::Method(.., ctx) => *ctx,
Self::Plugin(..) | Self::Iterator(..) => false,
#[cfg(not(feature = "no_function"))]
Self::Script(..) => false,
}
}
/// Get the access mode.
#[inline]
#[must_use]
@@ -156,7 +167,7 @@ impl CallableFunction {
#[must_use]
pub fn get_native_fn(&self) -> Option<&Shared<FnAny>> {
match self {
Self::Pure(f) | Self::Method(f) => Some(f),
Self::Pure(f, ..) | Self::Method(f, ..) => Some(f),
Self::Iterator(..) | Self::Plugin(..) => None,
#[cfg(not(feature = "no_function"))]