starlark/eval/bc/
native_function.rs1use allocative::Allocative;
19use dupe::Dupe;
20
21use crate::eval::Arguments;
22use crate::eval::Evaluator;
23use crate::values::function::NativeFunc;
24use crate::values::function::NativeFunction;
25use crate::values::FrozenRef;
26use crate::values::FrozenValueTyped;
27use crate::values::Value;
28
29#[derive(Copy, Clone, Dupe, Allocative)]
31pub(crate) struct BcNativeFunction {
32 fun: FrozenValueTyped<'static, NativeFunction>,
33 imp: FrozenRef<'static, dyn NativeFunc>,
35}
36
37impl BcNativeFunction {
38 pub(crate) fn new(fun: FrozenValueTyped<'static, NativeFunction>) -> BcNativeFunction {
39 let imp = fun.as_frozen_ref().map(|f| &*f.function);
40 BcNativeFunction { fun, imp }
41 }
42
43 #[inline]
44 pub(crate) fn fun(&self) -> FrozenValueTyped<'static, NativeFunction> {
45 self.fun
46 }
47
48 #[inline]
49 pub(crate) fn to_value<'v>(&self) -> Value<'v> {
50 self.fun.to_value()
51 }
52
53 #[inline]
54 pub(crate) fn invoke<'v>(
55 &self,
56 args: &Arguments<'v, '_>,
57 eval: &mut Evaluator<'v, '_, '_>,
58 ) -> crate::Result<Value<'v>> {
59 self.imp.invoke(eval, args)
60 }
61}