sim_lib_dispatch/
runtime.rs1use std::any::Any;
13use std::sync::Arc;
14
15use sim_kernel::{Args, Callable, ClassRef, Cx, Object, ObjectCompat, Result, Symbol, Value};
16
17use crate::generic::GenericFunction;
18
19impl Object for GenericFunction {
20 fn display(&self, _cx: &mut Cx) -> Result<String> {
21 Ok(format!("#<generic {}>", self.name()))
22 }
23
24 fn as_any(&self) -> &dyn Any {
25 self
26 }
27}
28
29impl ObjectCompat for GenericFunction {
30 fn class(&self, cx: &mut Cx) -> Result<ClassRef> {
31 cx.resolve_class(&Symbol::qualified("core", "Function"))
32 }
33
34 fn as_callable(&self) -> Option<&dyn Callable> {
35 Some(self)
36 }
37}
38
39impl Callable for GenericFunction {
40 fn call(&self, cx: &mut Cx, args: Args) -> Result<Value> {
41 let values = args.into_vec();
42 GenericFunction::call(self, cx, values.as_slice())
44 }
45}
46
47pub fn generic_function_value(cx: &mut Cx, generic: GenericFunction) -> Result<Value> {
49 cx.factory().opaque(Arc::new(generic))
50}