use som_core::ast;
use crate::class::Class;
use crate::primitives::PrimitiveFn;
use crate::universe::Universe;
use crate::{SOMRef, SOMWeakRef};
#[derive(Clone)]
pub enum MethodKind {
Defined(ast::MethodDef),
Primitive(PrimitiveFn),
NotImplemented(String),
}
impl MethodKind {
pub fn is_primitive(&self) -> bool {
matches!(self, Self::Primitive(_))
}
}
#[derive(Clone)]
pub struct Method {
pub kind: MethodKind,
pub holder: SOMWeakRef<Class>,
pub signature: String,
}
impl Method {
pub fn class(&self, universe: &Universe) -> SOMRef<Class> {
if self.is_primitive() {
universe.primitive_class()
} else {
universe.method_class()
}
}
pub fn kind(&self) -> &MethodKind {
&self.kind
}
pub fn holder(&self) -> &SOMWeakRef<Class> {
&self.holder
}
pub fn signature(&self) -> &str {
self.signature.as_str()
}
pub fn is_primitive(&self) -> bool {
self.kind.is_primitive()
}
}