use std::any::Any;
use std::sync::Arc;
use sim_kernel::{Args, Callable, ClassRef, Cx, Object, ObjectCompat, Result, Symbol, Value};
use crate::generic::GenericFunction;
impl Object for GenericFunction {
fn display(&self, _cx: &mut Cx) -> Result<String> {
Ok(format!("#<generic {}>", self.name()))
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl ObjectCompat for GenericFunction {
fn class(&self, cx: &mut Cx) -> Result<ClassRef> {
cx.resolve_class(&Symbol::qualified("core", "Function"))
}
fn as_callable(&self) -> Option<&dyn Callable> {
Some(self)
}
}
impl Callable for GenericFunction {
fn call(&self, cx: &mut Cx, args: Args) -> Result<Value> {
let values = args.into_vec();
GenericFunction::call(self, cx, values.as_slice())
}
}
pub fn generic_function_value(cx: &mut Cx, generic: GenericFunction) -> Result<Value> {
cx.factory().opaque(Arc::new(generic))
}