use std::sync::Arc;
use sim_kernel::{Cx, Result, Shape, Symbol, Value};
use sim_lib_dispatch::{DispatchMethod, GenericFunction, MethodBody, MethodRole};
pub struct JuliaFunction {
generic: GenericFunction,
}
impl JuliaFunction {
pub fn new(name: Symbol) -> Self {
Self {
generic: GenericFunction::new(name),
}
}
pub fn add_method(
&mut self,
method: Symbol,
argument_shapes: Vec<Arc<dyn Shape>>,
body: MethodBody,
) -> Result<()> {
self.generic.add_method(DispatchMethod::new(
method,
MethodRole::Primary,
argument_shapes,
body,
))
}
pub fn dispatch_order(&self, cx: &mut Cx, args: &[Value]) -> Result<Vec<Symbol>> {
self.generic.dispatch_order(cx, args)
}
pub fn call(&self, cx: &mut Cx, args: &[Value]) -> Result<Value> {
self.generic
.call_for_profile(cx, &crate::julia_profile_symbol(), args)
}
}