use allocative::Allocative;
use dupe::Dupe;
use crate::eval::Arguments;
use crate::eval::Evaluator;
use crate::values::FrozenValueTyped;
use crate::values::Value;
use crate::values::function::NativeFunc;
use crate::values::function::NativeFunction;
#[derive(Copy, Clone, Dupe, Allocative)]
pub(crate) struct BcNativeFunction {
fun: FrozenValueTyped<'static, NativeFunction>,
imp: &'static NativeFunc,
}
impl BcNativeFunction {
pub(crate) fn new(fun: FrozenValueTyped<'static, NativeFunction>) -> BcNativeFunction {
BcNativeFunction {
fun,
imp: &fun.as_ref().function,
}
}
#[inline]
pub(crate) fn fun(&self) -> FrozenValueTyped<'static, NativeFunction> {
self.fun
}
#[inline]
pub(crate) fn to_value<'v>(&self) -> Value<'v> {
self.fun.to_value()
}
#[inline]
pub(crate) fn invoke<'v>(
&self,
args: &Arguments<'v, '_>,
eval: &mut Evaluator<'v, '_, '_>,
) -> crate::Result<Value<'v>> {
self.imp.invoke(eval, args)
}
}