use allocative::Allocative;
use dupe::Dupe;
use crate::eval::Arguments;
use crate::eval::Evaluator;
use crate::values::function::NativeFunc;
use crate::values::function::NativeFunction;
use crate::values::FrozenRef;
use crate::values::FrozenValueTyped;
use crate::values::Value;
#[derive(Copy, Clone, Dupe, Allocative)]
pub(crate) struct BcNativeFunction {
fun: FrozenValueTyped<'static, NativeFunction>,
imp: FrozenRef<'static, dyn NativeFunc>,
}
impl BcNativeFunction {
pub(crate) fn new(fun: FrozenValueTyped<'static, NativeFunction>) -> BcNativeFunction {
let imp = fun.as_frozen_ref().map(|f| &*f.function);
BcNativeFunction { fun, imp }
}
#[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)
}
}